我只是在命令行上运行psiblast,并将结果保存在my_output.xml中。我现在正尝试使用Biopython解析xml文件,以便可以遍历每个psiblast回合中生成的结果,但这给了我一些问题。这是我的代码:
from Bio.Blast import NCBIXML
result_handle = open('my_output.xml', 'r')
blast_records = NCBIXML.parse(result_handle)
for blast_record in blast_records:
print blast_record.rounds
我得到的错误是:
Traceback (most recent call last):
File "parse_psiblast_output.py", line 10, in <module>
print blast_record.rounds
AttributeError: 'Blast' object has no attribute 'rounds'
我想做的是:对于每个查询序列,请从该查询的最终psiblast迭代中获取所有匹配。
我将假设您尝试解析当前NCBI Blast +软件包的输出,而不是任何旧版Blast软件包(现在已经过时了)的解析。
考虑到这一点,您应该使用Bio.SearchIO
模块。
from Bio import SearchIO
blast_records = SearchIO.parse('my_output.xml', 'blast-xml')
for blast_record in blast_records:
print(blast_record.hits)
[我还注意到,由于print
语句上没有大括号,您可能正在使用Python 2.7。如果可能的话,您确实应该使用Python 3+。自2020年起,Biopython将不再支持Python 2.7。