[Biopython-dev] Catching more error conditions in Bio.Entrez

Peter biopython at maubp.freeserve.co.uk
Wed Jul 2 11:34:32 UTC 2008


>> This seems to happen for any invalid identifier.  Are you happy for me
>> to check for this as an error too?  Are there any valid reasons to get
>> back an empty dataset like this?
>
> If the ability to use history is added, then an empty dataset could be
> a valid return after an empty search.  ...

Bio.Entrez has always supported the history, its just up to the user
to take advantage of it. I've included an example in the tutorial to
explain how to do this, cut and pasted below:

from Bio import Entrez
search_handle = Entrez.esearch(db="nucleotide",term="Opuntia and rpl16",
                               usehistory="y", email="history.user at example.com")
search_results = Entrez.read(search_handle)
search_handle.close()

gi_list = search_results["IdList"]
count = int(search_results["Count"])
assert count == len(gi_list)

session_cookie = search_results["WebEnv"]
query_key = search_results["QueryKey"]

#Now use the history session cookie and query key to download the
results in batchs
batch_size = 3
out_handle = open("orchid_rpl16.fasta", "w")
for start in range(0,count,batch_size) :
    end = min(count, start+batch_size)
    print "Going to download record %i to %i" % (start+1, end)
    fetch_handle = Entrez.efetch(db="nucleotide", rettype="fasta",
                                 retstart=start, retmax=batch_size,
                                 webenv=session_cookie, query_key=query_key,
                                 email="history.user at example.com")
    data = fetch_handle.read()
    fetch_handle.close()
    out_handle.write(data)
out_handle.close()

Feedback on the tutorial or the example is of course welcome.

> For id-based-searches, I'm not sure I would raise an error for an empty
> set being returned anyway.
>
> Just my $0.02.

I was wondering about this kind of thing... maybe some more testing of
these kinds of examples would be in order.

Peter



More information about the Biopython-dev mailing list