[BioPython] said Your XML file was empty in parsing blast records but can see the results in the saved xml file
Peter
biopython at maubp.freeserve.co.uk
Thu Nov 13 07:09:24 EST 2008
On Thu, Nov 13, 2008 at 11:18 AM, Hongwu Ma <hma2 at staffmail.ed.ac.uk> wrote:
> Sometimes when I parse the blast records in biopython using the following
> program I get the error "Your XML file was empty" but there are actually
> some results in the saved xml files. Anyone know what is the problem?
> Thanks in advance.
> Hongwu
>
> ...
> bres=result_handle.read()
> save_file = open(myfolder+file[:3]+'orfre.xml', "w")
> save_file.write(bres)
> save_file.close()
> blast_records = NCBIXML.parse(result_handle)
> for blast_record in blast_records:
> ...
When you do result_handle.read() it reads in all the data in the
handle - leaving it empty (pointing at the end of the file). When the
parser tries to read more data from the handle there isn't any, which
is why the parser says the file seems to be empty. You'll have to
"reset" the handle to the beginning.
One way would be to open the file you just wrote to disk:
...
save_file.close()
result_handle = open(...)
blast_records = NCBIXML.parse(result_handle)
...
Peter
More information about the BioPython
mailing list