Skip to content

Commit

Permalink
issue #1103 - Create ClinGen liftover failure record
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed Aug 14, 2024
1 parent 29aa584 commit 7829d58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion snpdb/liftover.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,22 @@ def _liftover_using_dest_variant_coordinate(allele, dest_genome_build: GenomeBui

conversion_tool = None
g_hgvs = None
clingen_failure_message = None
if allele.clingen_allele:
try:
g_hgvs = allele.clingen_allele.get_g_hgvs(dest_genome_build)
conversion_tool = AlleleConversionTool.CLINGEN_ALLELE_REGISTRY
except ValueError: # Various contig errors all subclass from this
pass
clingen_failure_message = f"{allele.clingen_allele} did not contain g.HGVS for {dest_genome_build}"
else:
clingen_failure_message = f"No ClinGenAllele for variant"

# Store the fact that we couldn't use ClinGen
if clingen_failure_message:
lr = LiftoverRun.get_clingen_auto_fail_liftover_run(dest_genome_build)
AlleleLiftover.objects.create(liftover=lr, allele=allele, status=ProcessingStatus.ERROR,
error={"message": clingen_failure_message})

if g_hgvs is None:
if settings.LIFTOVER_DBSNP_ENABLED:
va = allele.variantallele_set.all().first()
Expand Down
19 changes: 19 additions & 0 deletions snpdb/models/models_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from library.django_utils.django_partition import RelatedModelsPartitionModel
from library.genomics import format_chrom
from library.genomics.vcf_enums import VCFSymbolicAllele
from library.guardian_utils import admin_bot
from library.preview_request import PreviewModelMixin, PreviewKeyValue
from library.utils import FormerTuple, sha256sum_str
from snpdb.models import Wiki
Expand Down Expand Up @@ -909,6 +910,24 @@ class LiftoverRun(TimeStampedModel):
related_name="liftover_source_genome_build")
genome_build = models.ForeignKey(GenomeBuild, on_delete=CASCADE) # destination

@staticmethod
def get_clingen_auto_fail_liftover_run(genome_build: GenomeBuild) -> 'LiftoverRun':
""" We can know straight away we're going to fail a ClinGen run (missing ClinGenAllele, no data for the build)
but would still like to record the failure - so put them all in 1 LiftoverRun per build """
kwargs = {
"user": admin_bot(),
"genome_build": genome_build,
"conversion_tool": AlleleConversionTool.CLINGEN_ALLELE_REGISTRY,
}
# There should have been 1 created in 'one_off_legacy_populate_allele_liftover'
lr = LiftoverRun.objects.filter(**kwargs).order_by("pk").first()
if not lr:
# Otherwise create it
lr = LiftoverRun.objects.create(**kwargs)
return lr



def get_absolute_url(self):
return reverse("view_liftover_run", kwargs={"liftover_run_id": self.pk})

Expand Down

0 comments on commit 7829d58

Please sign in to comment.