我想从一个包含tblastn搜索结果的大型XML文件中提取前四名,该文件在我的本地核苷酸数据库中搜索了多个蛋白质查询。但是,问题是,我的when设置有一些查询,结果不到四次命中,所以当我运行这段代码时:
> from Bio.Blast import NCBIXML
with open('/home/edson/ungulate/tblastn_result_test_xml') as tblastn_file:
> tblastn_records = NCBIXML.parse(tblastn_file)
for tblastn_record in tblastn_records:
> if tblastn_record.alignments:
> print tblastn_record.alignments[0].title
> print tblastn_record.alignments[0].hsps[0]
> print tblastn_record.alignments[1].title
> print tblastn_record.alignments[1].hsps[0]
> print tblastn_record.alignments[2].title
> print tblastn_record.alignments[2].hsps[0]
> print tblastn_record.alignments[3].title
> print tblastn_record.alignments[3].hsps[0]它运行,但在一些运行后,它说:
Traceback (most recent call last): File
"/home/edson/tblastn_parser_test.py", line 8, in <module>
print tblastn_record.alignments[0].title IndexError: list index out of range那么,我如何修改这个脚本来打印前四对齐的结果呢?期待得到回应,任何帮助都将不胜感激。
发布于 2013-12-16 14:29:27
像这样的怎么样?
from Bio.Blast import NCBIXML
with open('/home/edson/ungulate/tblastn_result_test_xml') as tblastn_file:
tblastn_records = NCBIXML.parse(tblastn_file)
for tblastn_record in tblastn_records:
for alignment in record.alignments[:4]:
print alignment.title
print alignment.hsps[0]我不熟悉生物工程,但是docs1说alignments是Alignment对象的列表。此示例获取列表中前四个元素的一部分。如果不到四个,它就会拿走所有的东西。
1- http://biopython.org/DIST/docs/api/Bio.Blast.Record.Blast-class.html
https://stackoverflow.com/questions/20613035
复制相似问题