[Biopython] Entrez.read(handle) AND handle.read() on the same handle?

Peter Cock p.j.a.cock at googlemail.com
Tue Feb 1 23:20:07 UTC 2011


On Tue, Feb 1, 2011 at 11:02 PM, richard k belew <rik at cogsci.ucsd.edu> wrote:
> there must be a simple way to do this, but i've
> not figured it out:
>
> i want to sniff at aspects of a record (using the
> dictionary returned by Entrez.read(handle)) and then
> cache the XML version (returned by handle.read()),
> only if it meets certain criteria.  and without
> doing two separate efetch's!
>
> has anyone else bumped into this pattern?
>
>        rik

The simplest solution is to use StringIO (or cStringIO) and
cache it all in memory, then parse it:

from StringIO import StringIO
raw_data = efetch(...).read()
record = Entrez.read(String(raw_data))

Peter




More information about the Biopython mailing list