Skip to content

Commit

Permalink
add population scripts and tests for dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
KateSakharova committed Nov 17, 2023
1 parent fcd9b45 commit 8f51143
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions emgapi/management/commands/populate_metagenomics_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ def add_arguments(self, parser):
help="Do a full check of DB",
)

def generate_metadata(self, mgya, run_accession, status):
return {
"confidence": "full",
"endPoint": f"https://www.ebi.ac.uk/metagenomics/analyses/{mgya}",
"method": ["other_metadata"],
"sourceID": mgya,
"sequenceID": run_accession,
"status": status,
"brokerID": settings.MGNIFY_BROKER,
}

def handle(self, *args, **options):
self.study_accession = options.get("study")
self.dry_run = options.get("dry_run")
Expand All @@ -88,15 +99,8 @@ def handle(self, *args, **options):
removals = removals.filter(pipeline__pipeline_id=self.pipeline_version)
logging.info(f"Processing {len(new_analyses)} new analyses")
for ajob in new_analyses:
metadata = {
"confidence": "full",
"endPoint": f"https://www.ebi.ac.uk/metagenomics/analyses/{ajob.accession}",
"method": ["other_metadata"],
"sourceID": ajob.accession,
"sequenceID": ajob.run,
"status": "public" if not ajob.is_private else "private",
"brokerID": settings.MGNIFY_BROKER,
}
metadata = self.generate_metadata(mgya=ajob.accession, run_accession=ajob.run,
status="public" if not ajob.is_private else "private")
registryID, metadata_match = ME.check_analysis(source_id=ajob.accession, metadata=metadata)
if not registryID:
logging.debug(f"Add new {ajob}")
Expand All @@ -111,17 +115,8 @@ def handle(self, *args, **options):
else:
if not metadata_match:
logging.debug(f"Patch existing {ajob}")
data = {
"confidence": "full",
"endPoint": f"https://www.ebi.ac.uk/metagenomics/analyses/{ajob.accession}",
"method": ["other_metadata"],
"sourceID": ajob.accession,
"sequenceID": ajob.run,
"status": "public" if not ajob.is_private else "private",
"brokerID": settings.MGNIFY_BROKER,
}
if not self.dry_run:
if ME.patch_analysis(registry_id=registryID, data=data):
if ME.patch_analysis(registry_id=registryID, data=metadata):
logging.info(f"Analysis {ajob} updated successfully")
else:
logging.info(f"Analysis {ajob} update failed")
Expand All @@ -132,7 +127,9 @@ def handle(self, *args, **options):

logging.info(f"Processing {len(removals)} analyses to remove")
for ajob in removals:
registryID, _ = ME.check_analysis(source_id=ajob.accession)
metadata = self.generate_metadata(mgya=ajob.accession, run_accession=ajob.run,
status="public" if not ajob.is_private else "private")
registryID, _ = ME.check_analysis(source_id=ajob.accession, metadata=metadata)
if registryID:
if not self.dry_run:
if ME.delete_analysis(registryID):
Expand Down

0 comments on commit 8f51143

Please sign in to comment.