[BioPython] How can I get a more explicite error

Peter biopython at maubp.freeserve.co.uk
Thu Mar 19 06:52:30 EDT 2009


On Wed, Mar 18, 2009 at 9:20 PM, Brad Chapman <chapmanb at 50mail.com> wrote:
> The result_handle.read() line is pulling the entire large BLAST result
> file into memory as a string. You will run out of memory with huge files,
> leading to the errors you are seeing.

I think Brad is probably right about the memory issue - is certainly
something to be careful of.  Instead of this:

blast_results = result_handle.read()
my_results=sys.argv[1]+".xml"
save_file = open(my_results, "w")
save_file.write(blast_results)
save_file.close()

You could try keeping only one line in memory:

my_results=sys.argv[1]+".xml"
save_file = open(my_results, "w")
for line in result_handle :
    save_file.write(line)
save_file.close()

Or, we should get round to fixing Bug 2654 which would let you tell
the BLAST tool to save the file itself, which would be much more
elegant.  Do you want to add yourself as a CC to this bug, so you'll
automatically be informed of any updates:
http://bugzilla.open-bio.org/show_bug.cgi?id=2654

Peter


More information about the BioPython mailing list