Skip to content

Commit

Permalink
Allow to broker to private projects
Browse files Browse the repository at this point in the history
  • Loading branch information
tcezard committed Dec 11, 2023
1 parent 923822b commit e778bee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bin/add_ext_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand Down
21 changes: 20 additions & 1 deletion eva_submission/eload_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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),
Expand Down

0 comments on commit e778bee

Please sign in to comment.