NCBI NR文件下載和批量md5檢驗(yàn)

【1】 Aspera下載NCBI數(shù)據(jù)

單個文件下載命令:

ascp -i "C:\Users\Administrator\AppData\Local\Programs\Aspera\Aspera Connect\etc\asperaweb_id_dsa.openssh" -k 1 -T -l 200m anonftp@ftp-trace.ncbi.nlm.nih.gov:/sra/sra-instant/reads/ByRun/sra/SRR/SRR121/SRR1218151/SRR1218151.sra E:\aspera

多個文件下載命令:

ascp -QT -k1 -l 200m -i "C:\Users\Administrator\AppData\Local\Programs\Aspera\Aspera Connect\etc\asperaweb_id_dsa.putty" --mode=recv --host=ftp-trace.ncbi.nlm.nih.gov --user=anonftp --file-list=E:\aspera\filelist.txt H:\NCBI
  • 下載文件列表存放在文件E:\aspera\filelist.txt
  • windows CMD路徑中如果有空格Aspera Connect,全路徑用雙引號包起來

硬件所限,只能下載處理好的BLAST db文件nr.00.tar.gz~nr.113.tar.gz,共有文件114個
無標(biāo)題.png

【2】批量校驗(yàn)

100多個大文件,每個都有獨(dú)立的md5校驗(yàn)碼,手動校驗(yàn)太費(fèi)勁。也沒找到其他批量校驗(yàn)工具,就自己寫了個python腳本(新手上路,代碼不是很python)。代碼如下:

#!/usr/bin/env python           
#coding : utf-8 

import hashlib
import linecache
#import os #本來想通過OS調(diào)用外部md5程序,路徑搞不定,放棄了
import subprocess #subprocess調(diào)用測試成功,下面注釋掉的第二部分

count = 0
wrong_c = 0
fail_list = [] 
for i in range(0,113):
    m = hashlib.md5()
    if i<10:
        filename1 = "I:\\NCBI\\nr.0"+str(i)+".tar.gz"
        filename2 = "I:\\NCBI\\nr.0"+str(i)+".tar.gz.md5"
    else:
        filename1 = "I:\\NCBI\\nr."+str(i)+".tar.gz"
        filename2 = "I:\\NCBI\\nr."+str(i)+".tar.gz.md5"
    with open(filename1,'rb') as f:
        for line in f:
            m.update(line)
    real_md5 = m.hexdigest() #print(m.hexdigest()) #47a6b079cc33a4f312786b46e61e0305
    print(filename1 + " is verifying.......")
    print(real_md5)
    """
    md5_cmd = "D:\\md5\\md5.exe -n" + filename1
    rs = os.popen(md5_cmd).read()
    os_md5 = rs.strip().lower()
    print(os_md5)
    """
    '''
    obj = subprocess.Popen(['D:\\md5\\md5.exe','-n',filename1], shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE ,stderr=subprocess.PIPE)
    raw_md5 = obj.stdout.read()
    str_md5 = raw_md5.strip().decode("utf-8").lower()
    print(str_md5)
    '''
    the_line = linecache.getline(filename2, 1)
    ori_md5 = the_line.split(" ")[0].strip()
    print(ori_md5)
    if real_md5 == ori_md5:
        count += 1
        print("The file nr."+str(i)+".tar.gz is OK!")
    else:
        wrong_c += 1
        fail_list.append("nr."+str(i)+".tar.gz")
        print("The file nr."+str(i)+".tar.gz has been damaged!")
    sum_files = count + wrong_c
    print("Validation of %d files in total, %d passed, %d failed!" %         (sum_files, count, wrong_c))
if not fail_list:
    print("Go on analyzing with all the files!")
else:
    print("Failed files include:")
    print(",".join(str(i) for i in fail_list))
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容