python文本处理---fasta文件提取指定ID的序列

Posted 爬行的乌龟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python文本处理---fasta文件提取指定ID的序列相关的知识,希望对你有一定的参考价值。

利用python脚本,提取指定ID名称的序列

#!/usr/bin/python3
#-*- coding:utf-8 -*-
#提取指定ID的序列

import sys
args=sys.argv
fr=open(args[1], r)
fw=open(./out.fasta, w)
dict={}
for line in fr:
    if line.startswith(>):
        name=line.split()[0]
        dict[name]=‘‘
    else:
        dict[name]+=line.replace(\n,‘‘)
fr.close()
for ID in dict.keys():
    if ID ==args[2]:
        fw.write(ID)
        fw.write(\n)
        fw.write(dict[ID])
fw.write(‘\n‘)
fw.write(str((dict[ID].count(‘G‘)+dict[ID].count(‘C‘))/len(dict[ID]))) #计算指定序列中的GC含量 fw.close()

用法:python3 filename ‘ID_name‘
输出的结果保存在文件:out.fasta中





以上是关于python文本处理---fasta文件提取指定ID的序列的主要内容,如果未能解决你的问题,请参考以下文章