Skip to content

Commit

Permalink
issue #814 - T2T - handle looking up contig if build not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed Dec 5, 2024
1 parent 8859ebb commit f99cb81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
12 changes: 9 additions & 3 deletions snpdb/models/models_genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re
from functools import cached_property, reduce
from typing import Optional
from typing import Optional, Iterable

from django.conf import settings
from django.db import models
Expand Down Expand Up @@ -357,10 +357,16 @@ class ContigNotInBuildError(ValueError):
def get_absolute_url(self):
return reverse("view_contig", kwargs={"contig_accession": self.refseq_accession})

def get_genome_builds(self, require_annotation=True) -> Iterable[GenomeBuild]:
if require_annotation:
builds = GenomeBuild.builds_with_annotation()
else:
builds = GenomeBuild.objects.all()
return builds.filter(genomebuildcontig__contig=self, enabled=True).order_by("name")

@property
def genome_builds(self):
builds = GenomeBuild.builds_with_annotation()
return builds.filter(genomebuildcontig__contig=self, enabled=True).order_by("name")
return self.get_genome_builds(require_annotation=True)

@staticmethod
def get_q(accession: str, case_sensitive=True) -> Q:
Expand Down
29 changes: 19 additions & 10 deletions snpdb/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,16 +1648,25 @@ def view_genome_build(request, genome_build_name):
def view_contig(request, contig_accession):
q = Contig.get_q(contig_accession)
contig = get_object_or_404(Contig, q)
builds = list(contig.genome_builds)
genome_build = builds[0]
# If multiple builds (eg MT), we'll use user default if they have it, doesn't really matter
if len(builds) > 1:
try:
user_settings = UserSettings.get_for_user(request.user)
if user_settings.default_genome_build in builds:
genome_build = user_settings.default_genome_build
except:
pass
# Prefer builds with annotation
builds_with_annotation = list(contig.get_genome_builds(require_annotation=True))
if builds_with_annotation:
builds = builds_with_annotation
else:
builds = list(contig.get_genome_builds(require_annotation=False))

if builds:
# If multiple builds (eg MT), we'll use user default if they have it, doesn't really matter
genome_build = builds[0]
if len(builds) > 1:
try:
user_settings = UserSettings.get_for_user(request.user)
if user_settings.default_genome_build in builds:
genome_build = user_settings.default_genome_build
except:
pass
else:
genome_build = None

context = {
"contig": contig,
Expand Down

0 comments on commit f99cb81

Please sign in to comment.