How about something like this?
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]
I'm not familiar with biopython, but the docs[1] say that alignments
is a list of Alignment
objects. This example takes a slice of the first four elements in the list. If there are fewer than four it will just take whatever is there.
[1] - http://biopython.org/DIST/docs/api/Bio.Blast.Record.Blast-class.html