使用Biopython解析psiblast输出

2024-10-03 09:19:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是在命令行上运行了psiblast,并将结果保存在我的_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迭代中获取所有命中率


Tags: 命令行inoutputparsexmlresultrecordhandle
1条回答
网友
1楼 · 发布于 2024-10-03 09:19:37

我将假设您正在尝试解析当前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)

我还注意到,您可能正在使用Python2.7,因为print语句中缺少大括号。如果可能的话,您真的应该使用Python3+。自2020年起,Biopython将放弃对Python 2.7的支持

相关问题 更多 >