Skip to content

Commit

Permalink
Merge pull request #410 from fyvon/feature/release_skip_EFO
Browse files Browse the repository at this point in the history
Added option to skip EFO traits ontology rebuilding during release post-processing
  • Loading branch information
fyvon authored Feb 4, 2025
2 parents 0ecd2c4 + 3887636 commit 333a6e2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
45 changes: 45 additions & 0 deletions release/scripts/OnlyUpdateEFOAssociations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.db import transaction
from catalog.models import EFOTrait_Ontology, Score, Release


class OnlyUpdateEFOAssociations:
"""This class updates the EFO trait associations of the given scores without rebuilding
the whole EFO ontology as UpdateEFO does. This might be useful when one or several
EFO traits went obsolete, although we don't want to reflect this change yet in the PGS Catalog."""

def get_current_release_scores(self):
"""Retrieve the scores of the ongoing release, assuming this process is executed
as part of the release post-processing."""
latest_release = Release.objects.latest('date')
return Score.objects.filter(date_released=latest_release.date)

def add_score_efo_trait_associations(self, score):
"""Add EFO trait associations to the given score."""
efo_traits = score.trait_efo.all()
for efo_trait in efo_traits:
try:
efo_trait_ontology = EFOTrait_Ontology.objects.get(id=efo_trait.id)
efo_trait_ontology.scores_direct_associations.add(score)
efo_trait_ontology.save()
for efo_trait_parent in efo_trait_ontology.parent_traits.all():
efo_trait_parent.scores_child_associations.add(score)
efo_trait_parent.save()
except EFOTrait_Ontology.DoesNotExist as e:
print(f'ERROR: {efo_trait.id} is a new trait, UpdateEFO cannot be bypassed.')
raise e

def add_efo_trait_associations(self):
"""Main function."""
latest_scores = self.get_current_release_scores()
with transaction.atomic():
try:
for score in latest_scores:
self.add_score_efo_trait_associations(score)
except Exception as e:
transaction.rollback()
raise e


def run():
only_update_efo_associations = OnlyUpdateEFOAssociations()
only_update_efo_associations.add_efo_trait_associations()
20 changes: 16 additions & 4 deletions release/scripts/run_post_processing_script.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import sys, os.path, shutil, glob
from django.db.models import Count
from catalog.models import *
from release.scripts.RemoveDataForRelease import NonReleasedDataToRemove
from release.scripts.OnlyUpdateEFOAssociations import OnlyUpdateEFOAssociations
from release.scripts.UpdateScoreAncestry import UpdateScoreAncestry
from release.scripts.UpdateScoreEvaluated import UpdateScoreEvaluated
from release.scripts.UpdateReleasedCohorts import UpdateReleasedCohorts
from release.scripts.UpdateEFO import UpdateEFO

def run():

def run(*args):
"""
Main method executed by the Django command:
`python manage.py runscript run_post_processing_script`
Expand All @@ -30,8 +31,12 @@ def run():
# Update the cohorts (update the Cohort "released" field)
update_released_cohorts()

# Update the trait information and ontology
update_efo()
if 'update_efo_associations_only' in args:
# Simply update trait associations without rebuilding the ontology
update_efo_associations_only()
else:
# Update the trait information and ontology
update_efo()

# Display the list of new EFO traits in the catalog
display_new_efo()
Expand Down Expand Up @@ -76,6 +81,13 @@ def update_efo():
update_efo.launch_efo_updates()


def update_efo_associations_only():
""" Skipping EFO rebuilding, just adding scores and traits associations """
report_header("kipping EFO rebuilding, just adding scores and traits associations.")
update_efo_associations = OnlyUpdateEFOAssociations()
update_efo_associations.add_efo_trait_associations()


def display_new_efo():
""" Display the list of new Traits added with the new release """
new_release = Release.objects.latest('date').date
Expand Down

0 comments on commit 333a6e2

Please sign in to comment.