[BioPython] parsing the blastoutput and printing the alingment

Muthuraman, Manickam manickam.muthuraman at wur.nl
Thu Jun 15 07:51:36 EDT 2006


Dear Michiel

I tried your suggestion as well but i am getting error. I could even understand where i am making mistake.


[manickam at bioinfo python]$ cat blas.py
from Bio import Fasta
file_for_blast=open('/home/manickam/Documents/m_cold.fasta','r')
f_iterator=Fasta.Iterator(file_for_blast)
f_record=f_iterator.next()
from Bio.Blast import NCBIWWW
result_handle=NCBIWWW.qblast('blastp','nr',f_record)
save_file=open('/home/manickam/my_blast.out','w')
blast_results=result_handle.read()
save_file.write(blast_results)
save_file.close()
blast_out=open('/home/manickam/my_blast.out','r')
from Bio.Blast import NCBIXML
from Bio.Blast import NCBIStandalone
b_parser=NCBIXML.BlastParser()
b_iterator=NCBIStandalone.Iterator(blast_out,b_parser)
b_record = b_iterator.next()
for alignment in b_record.alignments:
    print "inside 2 loop"
    for hsp in alignment.hsps:
        print "inside 1 loop"
        print 'seq:',alignment.title
blast_out.close()

[manickam at bioinfo python]$ python blas.py
/usr/lib/python2.4/site-packages/Bio/Blast/NCBIWWW.py:1064: UserWarning: qblast works only with blastn and blastp for now.
  warnings.warn("qblast works only with blastn and blastp for now.")
Traceback (most recent call last):
  File "blas.py", line 16, in ?
    b_record = b_iterator.next()
  File "/usr/lib/python2.4/site-packages/Bio/Blast/NCBIStandalone.py", line 1385, in next
    return self._parser.parse(File.StringHandle(data))
  File "/usr/lib/python2.4/site-packages/Bio/Blast/NCBIXML.py", line 112, in parse
    self._parser.parse(handler)
  File "/usr/lib/python2.4/xml/sax/expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.4/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.4/xml/sax/expatreader.py", line 211, in feed
    self._err_handler.fatalError(exc)
  File "/usr/lib/python2.4/xml/sax/handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:4: not well-formed (invalid token)
[manickam at bioinfo python]$                              





More information about the BioPython mailing list