[Biopython] Parsing Blast results in XML format

Jon Bråte jon.brate at bio.uio.no
Thu Nov 5 19:30:14 EST 2009


Dear all,

I have a Blast output file in xml format generated by qBlast done  
through biopython. The Blast was performed with 22 query sequences and  
50 hits were returned for each query. The result is in one single xml  
file. I want to extract all the sequence IDs for all the hits (22x50)  
and I have been checking out the BioPython cookbook page 53.

I am using this code, but I am only getting the 50 hits for the 1st  
query sequence:
from Bio.Blast import NCBIXM
blast_records = NCBIXML.parse(result_handle)
blast_record = blast_records.next()

save_file = open("/Users/jonbra/Desktop/my_fasta_seq.fasta", 'w')

for alignment in blast_record.alignments:
     for hsp in alignment.hsps:
             save_file.write('>%s\n' % (alignment.title,))
save_file.close()
Can anyone help me to retrieve all the hits for all the query sequences?

Best wishes

Jon Bråte

-------------------------------------------------------------
Jon Bråte
PhD student

Microbial Evolution Research Group (MERG)
Department of Biology
University of Oslo
P.b. 1066 Blindern
N-0316 Oslo
Norway
Phone: +47 22855083




More information about the Biopython mailing list