Skip to content

Commit

Permalink
set _entrez_delay based on api_key
Browse files Browse the repository at this point in the history
  • Loading branch information
mikerobeson committed Sep 9, 2024
1 parent 5a3cebc commit 6e43bce
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rescript/ncbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def get_ncbi_data(
raise ValueError('Query or accession_ids must be supplied')
if api_key:
_entrez_params['api_key'] = api_key
global _entrez_delay
_entrez_delay = 0.1

seqs, taxa = _get_ncbi_data(query, accession_ids, ranks, rank_propagation,
logging_level, n_jobs, 'nuccore')
Expand All @@ -105,6 +107,8 @@ def get_ncbi_data_protein(
raise ValueError('Query or accession_ids must be supplied')
if api_key:
_entrez_params['api_key'] = api_key
global _entrez_delay
_entrez_delay = 0.1

seqs, taxa = _get_ncbi_data(query, accession_ids, ranks, rank_propagation,
logging_level, n_jobs, 'protein')
Expand Down Expand Up @@ -221,6 +225,7 @@ def request(params):
epost, data=data, params=_entrez_params, timeout=10,
stream=True)
print('\nRequesting the following epost url: ', r.url)
print('With a delay of ', entrez_delay, ' seconds.')
finally:
request_lock.release()
logger.debug('request lock released')
Expand Down Expand Up @@ -248,6 +253,7 @@ def request(params):
time.sleep(entrez_delay)
r = requests.get(esearch, params=params, timeout=10)
print('\nRequesting the following esearch url: ', r.url)
print('With a delay of ', entrez_delay, ' seconds.')
r.raise_for_status()
webenv = parse(r.content)['eSearchResult']
if 'WebEnv' not in webenv:
Expand All @@ -274,6 +280,7 @@ def request():
try:
r = requests.get(efetch, params=params, timeout=10, stream=True)
print('\nRequesting the following efetch url: ', r.url)
print('With a delay of ', entrez_delay, ' seconds.')
finally:
request_lock.release()
logger.debug('request lock released')
Expand Down

0 comments on commit 6e43bce

Please sign in to comment.