Repository: biopython/biopython

Issue:
Entrez egquery example doctest breaking
Our doctest:

```pycon
>>> from Bio import Entrez
>>> Entrez.email = "Your.Name.Here@example.org"
>>> handle = Entrez.egquery(term="biopython")
>>> record = Entrez.read(handle)
>>> handle.close()
>>> for row in record["eGQueryResult"]:
...     if "pmc" in row["DbName"]:
...         print(int(row["Count"]) > 60)
True
```

is failing with ``urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>``

This appears to be a general problem with EGQuery, consider the example given on https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.EGQuery which is: https://eutils.ncbi.nlm.nih.gov/entrez/eutils/egquery.fcgi?term=asthma

Right now in Firefox this redirects to https://ext-http-eutils.linkerd.ncbi.nlm.nih.gov/gquery?term=asthma&retmode=xml and gives "Server Not Found".

i.e. This looks like an NCBI problem, not a Biopython error.


Discussion:
Workaround https://ncbi.nlm.nih.gov/gquery?term=asthma&retmode=xml (no leading www or eutils subdomain).

I have emailed the NCBI Entrez Utilities team: Case #: CAS-1295533-Y0X6Q5 
This seems to have broken egquery, possible to have a hotfix to the new url?
This is an NCBI issue, they clearly document the domain used should be https://eutils.ncbi.nlm.nih.gov and it ought to be a relatively simple redirection fix on their side.

I would encourage you to ask the NCBI to help the prioritize this - you can cite my case number and/or this issue if you like.
I'm afraid the NCBI are looking at withdrawing EGQuery - and I would expect something official documenting this in due course. For Biopython, we will have to deprecate and remove the EGQuery wrapper (leaving this issue open to track that).

If you need guidance on what to use instead, please do contact the NCBI.

Resolving patch:
diff --git a/Bio/Entrez/__init__.py b/Bio/Entrez/__init__.py
--- a/Bio/Entrez/__init__.py
+++ b/Bio/Entrez/__init__.py
@@ -19,7 +19,7 @@
 
 This module provides a number of functions like ``efetch`` (short for
 Entrez Fetch) which will return the data as a handle object. This is
-a standard interface used in Python for reading data from a file, or
+a standad interface used in Python for reading data from a file, or
 in this case a remote network connection, and provides methods like
 ``.read()`` or offers iteration over the contents line by line. See
 also "What the heck is a handle?" in the Biopython Tutorial and
@@ -134,6 +134,7 @@
 from urllib.parse import urlencode
 from urllib.request import urlopen, Request
 
+from Bio import BiopythonDeprecationWarning
 from Bio._utils import function_with_previous
 
 email = None
@@ -342,10 +343,11 @@ def esummary(**keywds):
 
 
 def egquery(**keywds):
-    """Provide Entrez database counts for a global search.
+    """Provide Entrez database counts for a global search (DEPRECATED).
 
-    EGQuery provides Entrez database counts in XML for a single search
-    using Global Query.
+    EGQuery provided Entrez database counts in XML for a single search
+    using Global Query. However, the NCBI are no longer maintaining this
+    function and suggest using esearch on each database of interest.
 
     See the online documentation for an explanation of the parameters:
     http://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.EGQuery
@@ -367,6 +369,12 @@ def egquery(**keywds):
     :returns: Handle to the results, by default in XML format.
     :raises urllib.error.URLError: If there's a network error.
     """
+    warnings.warn(
+        "The Bio.Entrez.egquery function is deprecated and will be removed "
+        "in a future release of Biopython because the underlying NCBI EGQuery "
+        "API is no longer maintained.",
+        BiopythonDeprecationWarning,
+    )
     cgi = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/egquery.fcgi"
     variables = {}
     variables.update(keywds)


Test patch:
diff --git a/Tests/test_Entrez_online.py b/Tests/test_Entrez_online.py
--- a/Tests/test_Entrez_online.py
+++ b/Tests/test_Entrez_online.py
@@ -180,22 +180,6 @@ def test_epost(self):
         stream = Entrez.epost("nuccore", id=["160418", "160351"])
         stream.close()
 
-    def test_egquery(self):
-        """Test Entrez.egquery.
-
-        which searches in all Entrez databases for a single text query.
-        """
-        stream = Entrez.egquery(term="biopython")
-        record = Entrez.read(stream)
-        stream.close()
-
-        done = False
-        for row in record["eGQueryResult"]:
-            if "pmc" in row["DbName"]:
-                self.assertGreater(int(row["Count"]), 60)
-                done = True
-        self.assertTrue(done)
-
     def test_espell(self):
         """Test misspellings with Entrez.espell."""
         stream = Entrez.espell(term="biopythooon")