[BioPython] parse Balst results

Yves Bastide Yves.Bastide at irisa.fr
Thu Mar 27 16:25:16 EST 2003


Yann Moalic wrote:
> Hi,
> I just want to know if it's possible to extract a sequence from a blast 
> result and put the sequence in a text file.

Which sequence are you interested in, the query (your sequence) or the 
subject (the database match)?

Anyway, both are easy (example from the tutorial's cookbook):

from Bio.Blast import NCBIStandalone # equivalently: NCBIWWW

blast_results = open(my_blast_results , 'r')
b_parser = NCBIStandalone.BlastParser()
b_record = b_parser.parse(b_results)

for alignment in b_record.alignments:
     for hsp in alignment.hsps:
         if hsp.expect < E_VALUE_THRESH:
             print '****Alignment****'
             print 'sequence:', alignment.title
             print 'length:', alignment.length
             print 'e value:', hsp.expect
             print hsp.query[0:75] + '...'
             print hsp.match[0:75] + '...'
             print hsp.sbjct[0:75] + '...'


As you see, each alignment (match between your query and a subject) 
contains HSPs, whith the corresponding part of the query and the 
subject. And other attributes: start positions on the query and subject, 
score, expect value, etc.

The source (Bio/Blast/Record.py) is a very good, er, source.

> Thanks.
> 

yves



More information about the BioPython mailing list