0
这是我写的脚本。BLAST使用python subprocess.call有关alignment.def,不知道什么是错
两个问题。首先,我们需要打印形成XML hit_id,hit_len和hit_def的爆炸结果。前两个很容易。但是hit.def与def相同。如何避免它?
其次,我们需要在linux上运行程序。该程序应该接受两个序列,一个是蛋白质,一个是使用可选参数的核酸。但我无法实现这个功能。
时
$ python my_program.py protein.fa tem.txt prot
最后一个是参数选项它应该工作。我不为什么蟒蛇只是不接受它,因为我写
f=sys.argv[3]
f1=str(sys.argv[3])
if f1 is 'prot':
function(filename,protflag=True)
的Python总是选择“其他”
# IMPORT
import sys
import subprocess
################################################################################
# FUNCTIONS
#execute BLAST, vailable type are protein and nuclien
def run_blast(filename,protflag=True):
"""execute BLAST, vailable type are prot or na"""
if protflag:
subprocess.call(['blastp','-query','filename','-db','nr','-outfmt','5','-out','prot.xml'])
else :
subprocess.call(['blastn','-query','filename','-db','nt','-outfmt','5','-out','na.xml'])
def read_XML(filename):
"""return hit_id length hit_def"""
from Bio.Blast import NCBIXML
name=str(filename)
record=NCBIXML.read(open(name))
for i in range(0,len(record.alignments)):
hit=record.alignments[i]
print 'hit_id'+hit.id+'\n'+'length'+hit.len+'\n'+'hit_def'+hit.def+'\n'#here is the problem .def
################################################################################
# MAIN
# write a function for the "main method"
def main(filename=sys.argv[1],protflag=True):
"""excuate BLAST with file then return the hit_id, length and hit_def"""
f=sys.argv[3]
f1=str(f)
if f is 'prot':
run_blast(filename,True)
read_XML("prot.xml")
elif f is 'na':
run_blast(filename,False)
read_XML("prot.xml")
else:
print 'only prot and na available'
if __name__ == '__main__':
# defaults to reading the system, see above :)
main()
感谢的人!我会尝试!对第一个问题有什么想法? – 2014-10-23 20:12:45
我不是Bio上的专家,但我不认为碰撞是因为对象具有def功能。如果我没有记错,你可以打电话给hit.description来获得记录的描述。 – koukouviou 2014-10-24 20:23:32