From e778beefb13fb00ddc4a2b1a3641ab8c56e38b56 Mon Sep 17 00:00:00 2001 From: tcezard Date: Mon, 11 Dec 2023 15:17:11 +0000 Subject: [PATCH] Allow to broker to private projects --- bin/add_ext_reference.py | 5 +++-- eva_submission/eload_utils.py | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/add_ext_reference.py b/bin/add_ext_reference.py index a6518cc..6e72c2d 100755 --- a/bin/add_ext_reference.py +++ b/bin/add_ext_reference.py @@ -25,7 +25,8 @@ from ebi_eva_internal_pyutils.pg_utils import get_all_results_for_query, execute_query from retry import retry -from eva_submission.eload_utils import check_project_exists_in_evapro, check_existing_project_in_ena +from eva_submission.eload_utils import check_project_exists_in_evapro, \ + check_existing_public_project_in_ena from eva_submission.submission_config import load_config logger = log_cfg.get_logger(__name__) @@ -110,7 +111,7 @@ def main(): if not check_project_exists_in_evapro(args.project_accession): logger.error(f'{args.project_accession} does not exist in EVAPRO') return 1 - if not check_existing_project_in_ena(args.project_accession): + if not check_existing_public_project_in_ena(args.project_accession): logger.error(f'{args.project_accession} does not exist or is not public in ENA') return 1 if _curie_exist(args.source_database + ":" + args.identifier): diff --git a/eva_submission/eload_utils.py b/eva_submission/eload_utils.py index d771887..d185a53 100644 --- a/eva_submission/eload_utils.py +++ b/eva_submission/eload_utils.py @@ -158,8 +158,12 @@ def check_project_format(project_accession): return re.match(r'^PRJ(EB|NA)', project_accession) -@retry(tries=4, delay=2, backoff=1.2, jitter=(1, 3)) def check_existing_project_in_ena(project_accession): + return check_existing_public_project_in_ena(project_accession) or \ + check_existing_private_project_in_ena(project_accession) + + +def check_existing_public_project_in_ena(project_accession): """ Check if a project accession exists and is public in ENA :param project_accession: @@ -172,6 +176,21 @@ def check_existing_project_in_ena(project_accession): return True +def check_existing_private_project_in_ena(project_accession): + """ + Check if a project accession exists and is private in ENA + :param project_accession: + :return: + """ + try: + response = requests.get(f'https://www.ebi.ac.uk/ena/submit/drop-box/cli/reference/project/{project_accession}', + auth=HTTPBasicAuth(cfg.query('ena', 'username'), cfg.query('ena', 'password'))) + response.raise_for_status() + except requests.exceptions.HTTPError: + return False + return True + + # Create the databases if they do not exists. Then shard them. collections_shard_key_map = { "variants_2_0": (["chr", "start"], False),