Commit 0ff4864f authored by Mihai's avatar Mihai
Browse files

Add support for NCBI E-utilities API key

parent 97a6309c
...@@ -47,6 +47,8 @@ class Retriever(object): ...@@ -47,6 +47,8 @@ class Retriever(object):
if not os.path.isdir(settings.CACHE_DIR): if not os.path.isdir(settings.CACHE_DIR):
os.mkdir(settings.CACHE_DIR) os.mkdir(settings.CACHE_DIR)
Entrez.email = settings.EMAIL Entrez.email = settings.EMAIL
if hasattr(settings, 'ENTREZ_API_KEY'):
Entrez.api_key = settings.ENTREZ_API_KEY
self.file_type = None self.file_type = None
def _name_to_file(self, name): def _name_to_file(self, name):
......
...@@ -77,6 +77,8 @@ def _get_link_from_ncbi(source_db, target_db, match_link_name, ...@@ -77,6 +77,8 @@ def _get_link_from_ncbi(source_db, target_db, match_link_name,
# below, so we cannot move to `accession.version` here. This is fine for # below, so we cannot move to `accession.version` here. This is fine for
# now, but should be reconsidered at some point. # now, but should be reconsidered at some point.
Entrez.email = settings.EMAIL Entrez.email = settings.EMAIL
if hasattr(settings, 'ENTREZ_API_KEY'):
Entrez.api_key = settings.ENTREZ_API_KEY
# If we are currently strictly matching on version, we can try again if # If we are currently strictly matching on version, we can try again if
# no result is found. Otherwise, we just report failure. # no result is found. Otherwise, we just report failure.
...@@ -343,6 +345,8 @@ def _get_snp_from_ncbi(rsid): ...@@ -343,6 +345,8 @@ def _get_snp_from_ncbi(rsid):
:return: response_text(str) :return: response_text(str)
""" """
Entrez.email = settings.EMAIL Entrez.email = settings.EMAIL
if hasattr(settings, 'ENTREZ_API_KEY'):
Entrez.api_key = settings.ENTREZ_API_KEY
try: try:
response = Entrez.efetch(db='snp', id=rsid[2:], retmode='xml') response = Entrez.efetch(db='snp', id=rsid[2:], retmode='xml')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment