[BioPython] parsing the blastoutput and printing the alingment

Peter biopython at maubp.freeserve.co.uk
Wed Jun 14 21:48:20 UTC 2006


Muthuraman, Manickam wrote:
> I am new to python 
> 
> I am getting error in parsing blastoutput more over the same problem
 > was been addressed by Michiel De Hoon but i could not clear...
> 
> blast_out=open('my_blast.out','r')
> from Bio.Blast import NCBIStandalone
> from Bio.Blast import NCBIXML
> b_parser=NCBIXML.BlastParser()
> b_iterator1=NCBIStandalone.Iterator(blast_out,b_parser)
> for alignment in b_iterator1.alignments:
>     for hsp in alignment.hsps:
>         print 'seq:',alignment.title
 >

Your example code is wrong.  The iterator object will return blast 
record objects (which have an alignments property).

Try something like this:

blast_out=open('my_blast.out','r')
from Bio.Blast import NCBIStandalone
from Bio.Blast import NCBIXML
b_parser=NCBIXML.BlastParser()
b_iterator=NCBIStandalone.Iterator(blast_out,b_parser)
for b_record in b_iterator:
     for alignment in b_record.alignments:
         for hsp in alignment.hsps:
             print 'seq:',alignment.title


Or for a full and tested example, try this :

http://bugzilla.open-bio.org/attachment.cgi?id=293&action=view

Peter




More information about the Biopython mailing list