将gbk格式文件转换成fasta格式文件
flag=0fasta = open ('/mnt/f/biopython/AY810830.fasta','w')with open ('/mnt/f/biopython/AY810830.gbk','r') as f: for line in f: if line[0:9] =='ACCESSION': fasta.writelines('>'+line.split()[1]+'\n') elif line[0:6] =='ORIGIN': flag = 1 elif flag == 1: s = line.split() if s != []: print(s) seq=''.join(s[1:]) fasta.writelines(seq.upper()+'\n') fasta.close()
将多个fasta序列中提取含有'Homo sapiens'的序列
fasta_file=open('multi.fasta','r') out_file=open('human.fasta','w') seq = ''for line in fasta_file: if line[0]=='>' and seq =='': header = line elif line[0] != '>': seq=seq+line elif line[0] =='>' and seq !='': if "Homo sapiens" in header: out_file.write(header+seq) seq = '' header = lineif "Homo sapiens" in header : out_file.write(header+seq) out_file.close()
作者:tianzhanlan
链接:https://www.jianshu.com/p/492a6e4a1b19
點擊查看更多內(nèi)容
為 TA 點贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦