From 6e43bceeda004fe0dc3238213942d7c0abcaba6d Mon Sep 17 00:00:00 2001 From: mikerobeson Date: Mon, 9 Sep 2024 11:58:38 -0500 Subject: [PATCH] set _entrez_delay based on api_key --- rescript/ncbi.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rescript/ncbi.py b/rescript/ncbi.py index f850bc3..4815ec6 100644 --- a/rescript/ncbi.py +++ b/rescript/ncbi.py @@ -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') @@ -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') @@ -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') @@ -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: @@ -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')