Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 763d6289e1351f2d34257ce697a3ccb7 > files > 496

biopython-doc-1.47-2mdv2008.1.x86_64.rpm

<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Bio.EUtils.ThinClient</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="Bio-module.html">Package&nbsp;Bio</a> ::
        <a href="Bio.EUtils-module.html">Package&nbsp;EUtils</a> ::
        Module&nbsp;ThinClient
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="Bio.EUtils.ThinClient-module.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module ThinClient</h1><p class="nomargin-top"><span class="codelink"><a href="Bio.EUtils.ThinClient-pysrc.html">source&nbsp;code</a></span></p>
<pre class="literalblock">
Low-level interface to NCBI's EUtils for Entrez search and retrieval.

For higher-level interfaces, see DBIdsClient (which works with a set
of database identifiers) and HistoryClient (which does a much better
job of handling history).

There are five classes of services:
  ESearch - search a database
  EPost - upload a list of indicies for further use
  ESummary - get document summaries for a given set of records
  EFetch - get the records translated to a given format
  ELink - find related records in other databases

You can find more information about them at
  http://www.ncbi.nlm.nih.gov/entrez/query/static/eutils_help.html
but that document isn't very useful.  Perhaps the following is better.

EUtils offers a structured way to query Entrez, get the results in
various formats, and get information about related documents.  The way
to start off is create an EUtils object.

&gt;&gt;&gt; from Bio import EUtils
&gt;&gt;&gt; from Bio.EUtils.ThinClient import ThinClient
&gt;&gt;&gt; eutils = ThinClient.ThinClient()
&gt;&gt;&gt; 

You can search Entrez with the &quot;esearch&quot; method.  This does a query on
the server, which generates a list of identifiers for records that
matched the query.  However, not all the identifiers are returned.
You can request only a subset of the matches (using the 'retstart' and
'retmax') terms.  This is useful because searches like 'cancer' can
have over 1.4 million matches.  Most people would rather change the
query or look at more details about the first few hits than wait to
download all the identifiers before doing anything else.

The esearch method, and indeed all these methods, returns a
'urllib.addinfourl' which is an HTTP socket connection that has
already parsed the HTTP header and is ready to read the data from the
server.

For example, here's a query and how to use it

  Search in PubMed for the term cancer for the entrez date from the
  last 60 days and retrieve the first 10 IDs and translations using
  the history parameter.

&gt;&gt;&gt; infile = eutils.esearch(&quot;cancer&quot;,
...                         daterange = EUtils.WithinNDays(60, &quot;edat&quot;),
...                         retmax = 10)
&gt;&gt;&gt;
&gt;&gt;&gt; print infile.read()
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE eSearchResult PUBLIC &quot;-//NLM//DTD eSearchResult, 11 May 2002//EN&quot; &quot;http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSearch_020511.dtd&quot;&gt;
&lt;eSearchResult&gt;
        &lt;Count&gt;7228&lt;/Count&gt;
        &lt;RetMax&gt;10&lt;/RetMax&gt;
        &lt;RetStart&gt;0&lt;/RetStart&gt;
        &lt;IdList&gt;
                &lt;Id&gt;12503096&lt;/Id&gt;
                &lt;Id&gt;12503075&lt;/Id&gt;
                &lt;Id&gt;12503073&lt;/Id&gt;
                &lt;Id&gt;12503033&lt;/Id&gt;
                &lt;Id&gt;12503030&lt;/Id&gt;
                &lt;Id&gt;12503028&lt;/Id&gt;
                &lt;Id&gt;12502932&lt;/Id&gt;
                &lt;Id&gt;12502925&lt;/Id&gt;
                &lt;Id&gt;12502881&lt;/Id&gt;
                &lt;Id&gt;12502872&lt;/Id&gt;
        &lt;/IdList&gt;
        &lt;TranslationSet&gt;
                &lt;Translation&gt;
                        &lt;From&gt;cancer%5BAll+Fields%5D&lt;/From&gt;
                        &lt;To&gt;(%22neoplasms%22%5BMeSH+Terms%5D+OR+cancer%5BText+Word%5D)&lt;/To&gt;
                &lt;/Translation&gt;
        &lt;/TranslationSet&gt;
        &lt;TranslationStack&gt;
                &lt;TermSet&gt;
                        &lt;Term&gt;&quot;neoplasms&quot;[MeSH Terms]&lt;/Term&gt;
                        &lt;Field&gt;MeSH Terms&lt;/Field&gt;
                        &lt;Count&gt;1407151&lt;/Count&gt;
                        &lt;Explode&gt;Y&lt;/Explode&gt;
                &lt;/TermSet&gt;
                &lt;TermSet&gt;
                        &lt;Term&gt;cancer[Text Word]&lt;/Term&gt;
                        &lt;Field&gt;Text Word&lt;/Field&gt;
                        &lt;Count&gt;382919&lt;/Count&gt;
                        &lt;Explode&gt;Y&lt;/Explode&gt;
                &lt;/TermSet&gt;
                &lt;OP&gt;OR&lt;/OP&gt;
                &lt;TermSet&gt;
                        &lt;Term&gt;2002/10/30[edat]&lt;/Term&gt;
                        &lt;Field&gt;edat&lt;/Field&gt;
                        &lt;Count&gt;-1&lt;/Count&gt;
                        &lt;Explode&gt;Y&lt;/Explode&gt;
                &lt;/TermSet&gt;
                &lt;TermSet&gt;
                        &lt;Term&gt;2002/12/29[edat]&lt;/Term&gt;
                        &lt;Field&gt;edat&lt;/Field&gt;
                        &lt;Count&gt;-1&lt;/Count&gt;
                        &lt;Explode&gt;Y&lt;/Explode&gt;
                &lt;/TermSet&gt;
                &lt;OP&gt;RANGE&lt;/OP&gt;
                &lt;OP&gt;AND&lt;/OP&gt;
        &lt;/TranslationStack&gt;
&lt;/eSearchResult&gt;

&gt;&gt;&gt;

You get a raw XML input stream which you can process in many ways.
(The appropriate DTDs are included in the subdirectory &quot;DTDs&quot; and see
also the included POM reading code.)

    WARNING! As of this writing (2002/12/3) NCBI returns their
    XML encoded as Latin-1 but their processing instruction says
    it is UTF-8 because they leave out the &quot;encoding&quot; attribute.
    Until they fix it you will need to recode the input stream
    before processing it with XML tools, like this

        import codecs
        infile = codecs.EncodedFile(infile, &quot;utf-8&quot;, &quot;iso-8859-1&quot;)


The XML fields are mostly understandable:
  Count -- the total number of matches from this search
  RetMax -- the number of &lt;ID&gt; values returned in this subset
  RetStart -- the start position of this subset in the list of
      all matches

  IDList and ID -- the identifiers in this subset

  TranslationSet / Translation -- if the search field is not
      explicitly specified (&quot;qualified&quot;), then the server will
      apply a set of hueristics to improve the query.  Eg, in
      this case &quot;cancer&quot; is first parsed as
        cancer[All Fields]
      then turned into the query
        &quot;neoplasms&quot;[MeSH Terms] OR cancer[Text Word]

      Note that these terms are URL escaped.
      For details on how the translation is done, see
http://www.ncbi.nlm.nih.gov/entrez/query/static/help/pmhelp.html#AutomaticTermMapping

  TranslationStack -- The (possibly 'improved' query) fully
      parsed out and converted into a postfix (RPN) notation.
      The above example is written in the Entrez query language as

        (&quot;neoplasms&quot;[MeSH Terms] OR cancer[Text Word]) AND
                     2002/10/30:2002/12/29[edat]
      Note that these terms are *not* URL escaped.  Nothing like
      a bit of inconsistency for the soul.

      The &quot;Count&quot; field shows how many matches were found for each
      term of the expression.  I don't know what &quot;Explode&quot; does.


Let's get more information about the first record, which has an id of
12503096.  There are two ways to query for information, one uses a set
of identifiers and the other uses the history.  I'll talk about the
history one in a bit.  To use a set of identifiers you need to make a
DBIds object containing the that list.

&gt;&gt;&gt; dbids = EUtils.DBIds(&quot;pubmed&quot;, [&quot;12503096&quot;])
&gt;&gt;&gt;

Now get the summary using dbids

&gt;&gt;&gt; infile = eutils.esummary_using_dbids(dbids)
&gt;&gt;&gt; print infile.read()
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE eSummaryResult PUBLIC &quot;-//NLM//DTD eSummaryResult, 11 May 2002//EN&quot; &quot;http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSummary_020511.dtd&quot;&gt;
&lt;eSummaryResult&gt;
&lt;DocSum&gt;
        &lt;Id&gt;12503096&lt;/Id&gt;
        &lt;Item Name=&quot;PubDate&quot; Type=&quot;Date&quot;&gt;2003 Jan 30&lt;/Item&gt;
        &lt;Item Name=&quot;Source&quot; Type=&quot;String&quot;&gt;Am J Med Genet&lt;/Item&gt;
        &lt;Item Name=&quot;Authors&quot; Type=&quot;String&quot;&gt;Coyne JC, Kruus L, Racioppo M, Calzone KA, Armstrong K&lt;/Item&gt;
        &lt;Item Name=&quot;Title&quot; Type=&quot;String&quot;&gt;What do ratings of cancer-specific distress mean among women at high risk of breast and ovarian cancer?&lt;/Item&gt;
        &lt;Item Name=&quot;Volume&quot; Type=&quot;String&quot;&gt;116&lt;/Item&gt;
        &lt;Item Name=&quot;Pages&quot; Type=&quot;String&quot;&gt;222-8&lt;/Item&gt;
        &lt;Item Name=&quot;EntrezDate&quot; Type=&quot;Date&quot;&gt;2002/12/28 04:00&lt;/Item&gt;
        &lt;Item Name=&quot;PubMedId&quot; Type=&quot;Integer&quot;&gt;12503096&lt;/Item&gt;
        &lt;Item Name=&quot;MedlineId&quot; Type=&quot;Integer&quot;&gt;22390532&lt;/Item&gt;
        &lt;Item Name=&quot;Lang&quot; Type=&quot;String&quot;&gt;English&lt;/Item&gt;
        &lt;Item Name=&quot;PubType&quot; Type=&quot;String&quot;&gt;&lt;/Item&gt;
        &lt;Item Name=&quot;RecordStatus&quot; Type=&quot;String&quot;&gt;PubMed - in process&lt;/Item&gt;
        &lt;Item Name=&quot;Issue&quot; Type=&quot;String&quot;&gt;3&lt;/Item&gt;
        &lt;Item Name=&quot;SO&quot; Type=&quot;String&quot;&gt;2003 Jan 30;116(3):222-8&lt;/Item&gt;
        &lt;Item Name=&quot;DOI&quot; Type=&quot;String&quot;&gt;10.1002/ajmg.a.10844&lt;/Item&gt;
        &lt;Item Name=&quot;JTA&quot; Type=&quot;String&quot;&gt;3L4&lt;/Item&gt;
        &lt;Item Name=&quot;ISSN&quot; Type=&quot;String&quot;&gt;0148-7299&lt;/Item&gt;
        &lt;Item Name=&quot;PubId&quot; Type=&quot;String&quot;&gt;&lt;/Item&gt;
        &lt;Item Name=&quot;PubStatus&quot; Type=&quot;Integer&quot;&gt;4&lt;/Item&gt;
        &lt;Item Name=&quot;Status&quot; Type=&quot;Integer&quot;&gt;5&lt;/Item&gt;
        &lt;Item Name=&quot;HasAbstract&quot; Type=&quot;Integer&quot;&gt;1&lt;/Item&gt;
        &lt;Item Name=&quot;ArticleIds&quot; Type=&quot;List&quot;&gt;
                &lt;Item Name=&quot;PubMedId&quot; Type=&quot;String&quot;&gt;12503096&lt;/Item&gt;
                &lt;Item Name=&quot;DOI&quot; Type=&quot;String&quot;&gt;10.1002/ajmg.a.10844&lt;/Item&gt;
                &lt;Item Name=&quot;MedlineUID&quot; Type=&quot;String&quot;&gt;22390532&lt;/Item&gt;
        &lt;/Item&gt;
&lt;/DocSum&gt;
&lt;/eSummaryResult&gt;
&gt;&gt;&gt;

This is just a summary.  To get the full details, including an
abstract (if available) use the 'efetch' method.  I'll only print a
bit to convince you it has an abstract.

&gt;&gt;&gt; s = eutils.efetch_using_dbids(dbids).read()
&gt;&gt;&gt; print s[587:860]
&lt;ArticleTitle&gt;What do ratings of cancer-specific distress mean among women at high risk of breast and ovarian cancer?&lt;/ArticleTitle&gt;
&lt;Pagination&gt;
&lt;MedlinePgn&gt;222-8&lt;/MedlinePgn&gt;
&lt;/Pagination&gt;
&lt;Abstract&gt;
&lt;AbstractText&gt;Women recruited from a hereditary cancer registry provided
&gt;&gt;&gt;

Suppose instead you want the data in a text format.  Different
databases have different text formats.  For example, PubMed has a
&quot;docsum&quot; format which gives just the summary of a document and
&quot;medline&quot; format as needed for a citation database.  To get these, use
a &quot;text&quot; &quot;retmode&quot; (&quot;return mode&quot;) and select the appropriate
&quot;rettype&quot; (&quot;return type&quot;).

Here are examples of those two return types

&gt;&gt;&gt; print eutils.efetch_using_dbids(dbids, &quot;text&quot;, &quot;docsum&quot;).read()[:497]
1:  Coyne JC, Kruus L, Racioppo M, Calzone KA, Armstrong K.
What do ratings of cancer-specific distress mean among women at high risk of breast and ovarian cancer?
Am J Med Genet. 2003 Jan 30;116(3):222-8.
PMID: 12503096 [PubMed - in process]
&gt;&gt;&gt; print eutils.efetch_using_dbids(dbids, &quot;text&quot;, &quot;medline&quot;).read()[:369]
UI  - 22390532
PMID- 12503096
DA  - 20021227
IS  - 0148-7299
VI  - 116
IP  - 3
DP  - 2003 Jan 30
TI  - What do ratings of cancer-specific distress mean among women at high risk
      of breast and ovarian cancer?
PG  - 222-8
AB  - Women recruited from a hereditary cancer registry provided ratings of
      distress associated with different aspects of high-risk status
&gt;&gt;&gt; 

It's also possible to get a list of records related to a given
article.  This is done through the &quot;elink&quot; method.  For example,
here's how to get the list of PubMed articles related to the above
PubMed record.  (Again, truncated because otherwise there is a lot of
data.)

&gt;&gt;&gt; print eutils.elink_using_dbids(dbids).read()[:590]
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE eLinkResult PUBLIC &quot;-//NLM//DTD eLinkResult, 11 May 2002//EN&quot; &quot;http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eLink_020511.dtd&quot;&gt;
&lt;eLinkResult&gt;
&lt;LinkSet&gt;
        &lt;DbFrom&gt;pubmed&lt;/DbFrom&gt;
        &lt;IdList&gt;
                &lt;Id&gt;12503096&lt;/Id&gt;
        &lt;/IdList&gt;
        &lt;LinkSetDb&gt;
                &lt;DbTo&gt;pubmed&lt;/DbTo&gt;
                &lt;LinkName&gt;pubmed_pubmed&lt;/LinkName&gt;
                &lt;Link&gt;
                        &lt;Id&gt;12503096&lt;/Id&gt;
                        &lt;Score&gt;2147483647&lt;/Score&gt;
                &lt;/Link&gt;
                &lt;Link&gt;
                        &lt;Id&gt;11536413&lt;/Id&gt;
                        &lt;Score&gt;30817790&lt;/Score&gt;
                &lt;/Link&gt;
                &lt;Link&gt;
                        &lt;Id&gt;11340606&lt;/Id&gt;
                        &lt;Score&gt;29939219&lt;/Score&gt;
                &lt;/Link&gt;
                &lt;Link&gt;
                        &lt;Id&gt;10805955&lt;/Id&gt;
                        &lt;Score&gt;29584451&lt;/Score&gt;
                &lt;/Link&gt;
&gt;&gt;&gt;

For a change of pace, let's work with the protein database to learn
how to work with history.  Suppose I want to do a multiple sequene
alignment of bacteriorhodopsin with all of its neighbors, where
&quot;neighbors&quot; is defined by NCBI.  There are good programs for this -- I
just need to get the records in the right format, like FASTA.

The bacteriorhodopsin I'm interested in is BAA75200, which is
GI:4579714, so I'll start by asking for its neighbors.

&gt;&gt;&gt; results = eutils.elink_using_dbids(
...             EUtils.DBIds(&quot;protein&quot;, [&quot;4579714&quot;]),
...             db = &quot;protein&quot;).read()
&gt;&gt;&gt; print results[:454]
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE eLinkResult PUBLIC &quot;-//NLM//DTD eLinkResult, 11 May 2002//EN&quot; &quot;http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eLink_020511.dtd&quot;&gt;
&lt;eLinkResult&gt;
&lt;LinkSet&gt;
        &lt;DbFrom&gt;protein&lt;/DbFrom&gt;
        &lt;IdList&gt;
                &lt;Id&gt;4579714&lt;/Id&gt;
        &lt;/IdList&gt;
        &lt;LinkSetDb&gt;
                &lt;DbTo&gt;protein&lt;/DbTo&gt;
                &lt;LinkName&gt;protein_protein&lt;/LinkName&gt;
                &lt;Link&gt;
                        &lt;Id&gt;4579714&lt;/Id&gt;
                        &lt;Score&gt;2147483647&lt;/Score&gt;
                &lt;/Link&gt;
                &lt;Link&gt;
                        &lt;Id&gt;11277596&lt;/Id&gt;
                        &lt;Score&gt;1279&lt;/Score&gt;
                &lt;/Link&gt;
&gt;&gt;&gt;

Let's get all the &lt;Id&gt; fields.  (While the following isn't a good way
to parse XML, it is easy to understand and works well enough for this
example.)  Note that I remove the first &lt;Id&gt; because that's from the
query and not from the results.

&gt;&gt;&gt; import re
&gt;&gt;&gt; ids = re.findall(r&quot;&lt;Id&gt;(\d+)&lt;/Id&gt;&quot;, results)
&gt;&gt;&gt; ids = ids[1:]
&gt;&gt;&gt; len(ids)
222
&gt;&gt;&gt; dbids = EUtils.DBIds(&quot;protein&quot;, ids)
&gt;&gt;&gt; 

That's a lot of records.  I could use 'efetch_using_dbids' but there's
a problem with that.  Efetch uses the HTTP GET protocol to pass
information to the EUtils server.  (&quot;GET&quot; is what's used when you type
a URL in the browser.)  Each id takes about 9 characters, so the URL
would be over 2,000 characters long.  This may not work on some
systems, for example, some proxies do not support long URLs.  (Search
for &quot;very long URLs&quot; for examples.)

Instead, we'll upload the list to the server then fetch the FASTA
version using the history.

The first step is to upload the data.  We want to put that into the
history so we set 'usehistory' to true.  There's no existing history
so the webenv string is None.


&gt;&gt;&gt; print eutils.epost(dbids, usehistory = 1, webenv = None).read()
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE ePostResult PUBLIC &quot;-//NLM//DTD ePostResult, 11 May 2002//EN&quot; &quot;http://www.ncbi.nlm.nih.gov/entrez/query/DTD/ePost_020511.dtd&quot;&gt;
&lt;ePostResult&gt;
        &lt;QueryKey&gt;1&lt;/QueryKey&gt;
        &lt;WebEnv&gt;%7BPgTHRHFBsJfC%3C%5C%5C%5B%3EAfJCKQ%5Ey%60%3CGkH%5DH%5E%3DJHGBKAJ%3F%40CbCiG%3FE%3C&lt;/WebEnv&gt;
&lt;/ePostResult&gt;

&gt;&gt;&gt;

This says that the identifiers were saved as query #1, which will be
used later on as the &quot;query_key&quot; field.  The WebEnv is a cookie (or
token) used to tell the server where to find that query.  The WebEnv
changes after every history-enabled ESearch or EPost so you'll need to
parse the output from those to get the new WebEnv field.  You'll also
need to unquote it since it is URL-escaped.

Also, you will need to pass in the name of the database used for the
query in order to access the history.  Why?  I don't know -- I figure
the WebEnv and query_key should be enough to get the database name.

&gt;&gt;&gt; import urllib
&gt;&gt;&gt; webenv = urllib.unquote(&quot;%7BPgTHRHFBsJfC%3C%5C%5C%5B%3EAfJCKQ%5Ey%60%3CGkH%5DH%5E%3DJHGBKAJ%3F%40CbCiG%3FE%3C&quot;)
&gt;&gt;&gt; print webenv
{PgTHRHFBsJfC&lt;\[&gt;AfJCKQ^y`&lt;GkH]H^=JHGBKAJ?@CbCiG?E&lt;
&gt;&gt;&gt;

Okay, now to get the data in FASTA format.  Notice that I need the
'retmax' in order to include all the records in the result.  (The
default is 20 records.)

&gt;&gt;&gt; fasta = eutils.efetch_using_history(&quot;protein&quot;, webenv, query_key = &quot;1&quot;,
...                                     retmode = &quot;text&quot;, rettype = &quot;fasta&quot;,
...                                     retmax = len(dbids)).read()
&gt;&gt;&gt; fasta.count(&quot;&gt;&quot;)
222
&gt;&gt;&gt; print fasta[:694]
&gt;gi|14194475|sp|O93742|BACH_HALSD Halorhodopsin (HR)
MMETAADALASGTVPLEMTQTQIFEAIQGDTLLASSLWINIALAGLSILLFVYMGRNLEDPRAQLIFVAT
LMVPLVSISSYTGLVSGLTVSFLEMPAGHALAGQEVLTPWGRYLTWALSTPMILVALGLLAGSNATKLFT
AVTADIGMCVTGLAAALTTSSYLLRWVWYVISCAFFVVVLYVLLAEWAEDAEVAGTAEIFNTLKLLTVVL
WLGYPIFWALGAEGLAVLDVAVTSWAYSGMDIVAKYLFAFLLLRWVVDNERTVAGMAAGLGAPLARCAPA
DD
&gt;gi|14194474|sp|O93741|BACH_HALS4 Halorhodopsin (HR)
MRSRTYHDQSVCGPYGSQRTDCDRDTDAGSDTDVHGAQVATQIRTDTLLHSSLWVNIALAGLSILVFLYM
ARTVRANRARLIVGATLMIPLVSLSSYLGLVTGLTAGPIEMPAAHALAGEDVLSQWGRYLTWTLSTPMIL
LALGWLAEVDTADLFVVIAADIGMCLTGLAAALTTSSYAFRWAFYLVSTAFFVVVLYALLAKWPTNAEAA
GTGDIFGTLRWLTVILWLGYPILWALGVEGFALVDSVGLTSWGYSLLDIGAKYLFAALLLRWVANNERTI
AVGQRSGRGAIGDPVED
&gt;&gt;&gt; 

To round things out, here's a query which refines the previous query.
I want to get all records from the first search which also have the
word &quot;Structure&quot; in them.  (My background was originally structural
biophysics, whaddya expect?  :)

&gt;&gt;&gt; print eutils.search(&quot;#1 AND structure&quot;, db = &quot;protein&quot;, usehistory = 1,
...                     webenv = webenv).read()
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE eSearchResult PUBLIC &quot;-//NLM//DTD eSearchResult, 11 May 2002//EN&quot; &quot;http://www.ncbi.nlm.nih.gov/entrez/query/DTD/eSearch_020511.dtd&quot;&gt;
&lt;eSearchResult&gt;
        &lt;Count&gt;67&lt;/Count&gt;
        &lt;RetMax&gt;20&lt;/RetMax&gt;
        &lt;RetStart&gt;0&lt;/RetStart&gt;
        &lt;QueryKey&gt;2&lt;/QueryKey&gt;
        &lt;WebEnv&gt;UdvMf%3F%60G%3DIE%60bG%3DGec%3E%3D%3Cbc_%5DgBAf%3EAi_e%5EAJcHgDi%3CIqGdE%7BmC%3C&lt;/WebEnv&gt;
        &lt;IdList&gt;
                &lt;Id&gt;461608&lt;/Id&gt;
                &lt;Id&gt;114808&lt;/Id&gt;
                &lt;Id&gt;1364150&lt;/Id&gt;
                &lt;Id&gt;1363466&lt;/Id&gt;
                &lt;Id&gt;1083906&lt;/Id&gt;
                &lt;Id&gt;99232&lt;/Id&gt;
                &lt;Id&gt;99212&lt;/Id&gt;
                &lt;Id&gt;81076&lt;/Id&gt;
                &lt;Id&gt;114811&lt;/Id&gt;
                &lt;Id&gt;24158915&lt;/Id&gt;
                &lt;Id&gt;24158914&lt;/Id&gt;
                &lt;Id&gt;24158913&lt;/Id&gt;
                &lt;Id&gt;1168615&lt;/Id&gt;
                &lt;Id&gt;114812&lt;/Id&gt;
                &lt;Id&gt;114809&lt;/Id&gt;
                &lt;Id&gt;17942995&lt;/Id&gt;
                &lt;Id&gt;17942994&lt;/Id&gt;
                &lt;Id&gt;17942993&lt;/Id&gt;
                &lt;Id&gt;20151159&lt;/Id&gt;
                &lt;Id&gt;20150922&lt;/Id&gt;
        &lt;/IdList&gt;
        &lt;TranslationSet&gt;
        &lt;/TranslationSet&gt;
        &lt;TranslationStack&gt;
                &lt;TermSet&gt;
                        &lt;Term&gt;#1&lt;/Term&gt;
                        &lt;Field&gt;All Fields&lt;/Field&gt;
                        &lt;Count&gt;222&lt;/Count&gt;
                        &lt;Explode&gt;Y&lt;/Explode&gt;
                &lt;/TermSet&gt;
                &lt;TermSet&gt;
                        &lt;Term&gt;structure[All Fields]&lt;/Term&gt;
                        &lt;Field&gt;All Fields&lt;/Field&gt;
                        &lt;Count&gt;142002&lt;/Count&gt;
                        &lt;Explode&gt;Y&lt;/Explode&gt;
                &lt;/TermSet&gt;
                &lt;OP&gt;AND&lt;/OP&gt;
        &lt;/TranslationStack&gt;
&lt;/eSearchResult&gt;

&gt;&gt;&gt; 

One last thing about history.  It doesn't last very long -- perhaps an
hour or so.  (Untested.)  You may be able to toss it some keep-alive
signal every once in a while.  Or you may want to keep 

The known 'db' fields and primary IDs (if known) are
  genome -- GI number
  nucleotide -- GI number
  omim  -- MIM number
  popset -- GI number
  protein -- GI number
  pubmed  -- PMID
  sequences (not available; this will combine all sequence databases)
  structure -- MMDB ID
  taxonomy -- TAXID

The 'field' parameter is different for different databases.  The
fields for PubMed are listed at

http://www.ncbi.nlm.nih.gov/entrez/query/static/help/pmhelp.html#SearchFieldDescriptionsandTags

  Affiliation -- AD
  All Fields -- All
  Author -- AU
  EC/RN Number -- RN
  Entrez Date -- EDAT  (also valid for 'datetype')
  Filter -- FILTER
  Issue -- IP
  Journal Title -- TA
  Language -- LA
  MeSH Date -- MHDA  (also valid for 'datetype')
  MeSH Major Topic -- MAJR
  MeSH Subheadings -- SH
  MeSH Terms -- MH
  Pagination -- PG
  Personal Name as Subject -- PS
  Publication Date -- DP  (also valid for 'datetype')
  Publication Type -- PT
  Secondary Source ID -- SI
  Subset -- SB
  Substance Name -- NM
  Text Words -- TW
  Title -- TI
  Title/Abstract -- TIAB
  Unique Identifiers -- UID
  Volume -- VI

The fields marked as 'datetype' can also be used for date searches.
Date searches can be done in the query (for example, as

   1990/01/01:1999/12/31[edat]

or by passing a WithinNDays or DateRange field to the 'date' parameter
of the search.


Please pay attention to the usage limits!  The are listed at
  http://www.ncbi.nlm.nih.gov/entrez/query/static/eutils_help.html

At the time of this writing they are:
    * Run retrieval scripts on weekends or between 9 PM and 5 AM ET
            weekdays for any series of more than 100 requests.
    * Make no more than one request every 3 seconds.
    * Only 5000 PubMed records may be retrieved in a single day.

    * NCBI's Disclaimer and Copyright notice must be evident to users
      of your service.  NLM does not hold the copyright on the PubMed
      abstracts the journal publishers do.  NLM provides no legal
      advice concerning distribution of copyrighted materials, consult
      your legal counsel.

(Their disclaimer is at
       http://www.ncbi.nlm.nih.gov/About/disclaimer.html )

</pre>

<!-- ==================== CLASSES ==================== -->
<a name="section-Classes"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Classes</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Classes"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="Bio.EUtils.ThinClient.ThinClient-class.html" class="summary-name">ThinClient</a><br />
      Client-side interface to the EUtils services
    </td>
  </tr>
</table>
<!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Functions</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Functions"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="_dbids_to_id_string"></a><span class="summary-sig-name">_dbids_to_id_string</span>(<span class="summary-sig-arg">dbids</span>)</span><br />
      Internal function: convert a list of ids to a comma-seperated string</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="Bio.EUtils.ThinClient-pysrc.html#_dbids_to_id_string">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Variables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="DUMP_URL"></a><span class="summary-name">DUMP_URL</span> = <code title="0">0</code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="DUMP_RESULT"></a><span class="summary-name">DUMP_RESULT</span> = <code title="0">0</code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="TOOL"></a><span class="summary-name">TOOL</span> = <code title="'EUtils_Python_client'"><code class="variable-quote">'</code><code class="variable-string">EUtils_Python_client</code><code class="variable-quote">'</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="EMAIL"></a><span class="summary-name">EMAIL</span> = <code title="'biopython-dev@biopython.org'"><code class="variable-quote">'</code><code class="variable-string">biopython-dev@biopython.org</code><code class="variable-quote">'</code></code>
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="_open_previous"></a><span class="summary-name">_open_previous</span> = <code title="1221485138.85">1221485138.85</code>
    </td>
  </tr>
</table>
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Mon Sep 15 09:26:23 2008
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>