[BioPython] WWW Blast

Eirik Sønneland eirik.sonneland at student.umb.no
Tue Feb 15 04:47:38 EST 2005


I am new to biopython and trying to implement the BLAST example in the 
Cookbook(WWW Blast and parsing results). Can't figure out the error 
message(my code and error message attached). Is there anyone who knows 
how to solve this/what is wrong in the cookbook?

Code:

from Bio import Fasta

file_for_blast = open('Fastaformat.txt', 'r')
f_iterator = Fasta.Iterator(file_for_blast)

f_record = f_iterator.next()

from Bio.Blast import NCBIWWW
b_results = NCBIWWW.blast('blastn', 'nr', f_record)

## save the results for later

save_file = open('my_blast.txt', 'w')
blast_results =b_results.read()
save_file.write(blast_results)
save_file.close()

import cStringIO
string_result_handle = cStringIO.StringIO(blast_results)

blast_results = open('my_blast.txt', 'r')

b_parser = NCBIWWW.BlastParser()

b_record = b_parser.parse(string_result_handle)

this gives the error message:

Traceback (most recent call last):
  File "C:\Python24\MyWorkspace.py", line 51, in -toplevel-
    b_record = b_parser.parse(string_result_handle)
  File "C:\Python24\Lib\site-packages\Bio\Blast\NCBIWWW.py", line 47, in 
parse
    self._scanner.feed(handle, self._consumer)
  File "C:\Python24\Lib\site-packages\Bio\Blast\NCBIWWW.py", line 96, in 
feed
    has_re=re.compile(r'<b>.?BLAST'))
  File "C:\Python24\Lib\site-packages\Bio\ParserSupport.py", line 335, 
in read_and_call_until
    line = safe_readline(uhandle)
  File "C:\Python24\Lib\site-packages\Bio\ParserSupport.py", line 411, 
in safe_readline
    raise SyntaxError, "Unexpected end of stream."
SyntaxError: Unexpected end of stream.

Advice will be higly appreciated!
Cheers,
Eirik


More information about the BioPython mailing list