[BioPython] said Your XML file was empty in parsing blast records but can see the results in the saved xml file
Hongwu Ma
hma2 at staffmail.ed.ac.uk
Thu Nov 13 08:55:12 EST 2008
Thanks, Peter. I tried to reopen the xml file and it was working. I also
tried to parse the result before reading as below:
...
blast_records = NCBIXML.parse(result_handle)
bres=result_handle.read()
...
I found I still got the problem, a good xml file but empty
blast_records. Why the later read() function affect the parse before it?
> 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
>
>
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the BioPython
mailing list