[Biopython-dev] Blast Parser error

Peter biopython-dev at maubp.freeserve.co.uk
Wed Nov 23 17:11:36 EST 2005


Matteo wrote:
> this is the simple code:
> 
> blast_db   = os.path.join(os.getcwd(), FASTA_FILE)
> blast_file = os.path.join(os.getcwd(), QUERY_FILE)
> blast_exe  = os.path.join(os.getcwd(), 'blastall.exe')
> blast_out, error_info = NCBIStandalone.blastall(blast_exe, 'blastn', blast_db, blast_file)
> save_file = open('my_blast.out', 'w')
> blast_results = blast_out.read()
> save_file.write(blast_results)
> save_file.close()
> blast_out = open('my_blast.out', 'r')
> blastparser = NCBIStandalone.BlastParser()
> alignrecord = blastparser.parse(blast_out)
> [...]
>
...
 > At the end of the program the output "my_blast.out" is blank!
 > I tried to launching blastall from the command line and THEN
 > parsing the output with biopython, in this way it works!

At Frederic Sohm's suggestion (off list?):

Matteo wrote:
> If I put a "print error_info" I get something like:
> <open file 'C:\PATH\TO\PROGRAM\blastall.exe -p blastn -d 
> C:\PATH\TO\PROGRAM\refsets.fasta -i C:\PATH\TO\PROGRAM\query.fasta', 
> mode 'r' at 0x00AF6AD0>

Could you post the actual message with the real "PATH TO PROGRAM" 
included?  I'm wondering if this is a problem with spaces in 
paths/filenames.

Also in your example script, you are explicitly creating a file and 
saving the blast output to it.  It is possible that you need to wait a 
second or two on windows for the file to be properly closed, before you 
can open it and parse it (just an guess!)

When I used NCBIStandalone.BlastParser (which worked for me on both 
Linux and Windows) I followed the cookbook approach, which doesn't 
create a temp file in this way.

What happens if you try this:

blast_db   = os.path.join(os.getcwd(), FASTA_FILE)
blast_file = os.path.join(os.getcwd(), QUERY_FILE)
blast_exe  = os.path.join(os.getcwd(), 'blastall.exe')
blast_out, error_info = NCBIStandalone.blastall(blast_exe, \
                              'blastn', blast_db, blast_file)
# save_file = open('my_blast.out', 'w')
# blast_results = blast_out.read()
# save_file.write(blast_results)
# save_file.close()
# blast_out = open('my_blast.out', 'r')
blastparser = NCBIStandalone.BlastParser()
alignrecord = blastparser.parse(blast_out)
[...]

You don't get to keep a copy of the raw blast output though.

I would try this for you now, but I'm on a Linux box at the moment.

Peter



More information about the Biopython-dev mailing list