Skip to content

Commit

Permalink
issue #1102 Searching for hg18 coordinates gives empty result and no …
Browse files Browse the repository at this point in the history
…warning message
  • Loading branch information
davmlaw committed Dec 11, 2024
1 parent ed7bb94 commit 5e0eebd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
12 changes: 6 additions & 6 deletions snpdb/models/models_genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,12 @@ def builds_with_annotation() -> QuerySet['GenomeBuild']:
for build_name, values in settings.ANNOTATION.items():
if values.get("enabled"):
enabled_annotation.append(build_name)
return GenomeBuild.objects.filter(name__in=enabled_annotation).order_by('name')
return GenomeBuild.objects.filter(enabled=True, name__in=enabled_annotation).order_by('name')

@staticmethod
@timed_cache(ttl=60)
def builds_with_annotation_cached() -> list['GenomeBuild']:
enabled_annotation = []
for build_name, values in settings.ANNOTATION.items():
if values.get("enabled"):
enabled_annotation.append(build_name)
return list(GenomeBuild.objects.filter(name__in=enabled_annotation))
return list(GenomeBuild.builds_with_annotation())

@staticmethod
def builds_with_annotation_priority(priority: 'GenomeBuild') -> list['GenomeBuild']:
Expand Down Expand Up @@ -282,6 +278,10 @@ def get_build_with_patch(self, annotation_version=None) -> str:

return annotation_version.variant_annotation_version.assembly

@staticmethod
def get_known_builds_comma_separated_string() -> str:
return ", ".join(GenomeBuild.objects.all().order_by("name").values_list("name", flat=True))

def __str__(self):
return self.name

Expand Down
17 changes: 15 additions & 2 deletions snpdb/signals/genomics_search.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import re

from django.conf import settings
from django.db.models import Q

from library.enums.log_level import LogLevel
from snpdb.models import GenomeBuild, Contig
from snpdb.search import search_receiver, SearchInputInstance, SearchExample
from snpdb.search import search_receiver, SearchInputInstance, SearchExample, SearchMessageOverall


@search_receiver(
Expand Down Expand Up @@ -31,4 +33,15 @@ def genome_build_search(search_input: SearchInputInstance):
)
def contig_search(search_input: SearchInputInstance):
q = Contig.get_q(search_input.search_string, case_sensitive=False)
yield Contig.objects.filter(q, genomebuildcontig__genome_build__in=search_input.genome_builds)
all_contigs = Contig.objects.filter(q)
q_search_build = Q(genomebuildcontig__genome_build__in=search_input.genome_builds)
yield all_contigs.filter(q_search_build)
if other_contig := all_contigs.exclude(q_search_build).first():
contig_builds = other_contig.genomebuildcontig_set.all()
build_names = ", ".join(contig_builds.order_by("genome_build__name").values_list("genome_build__name", flat=True))
msg = f"contig={other_contig.refseq_accession} is from builds {build_names} which are not enabled/annotated."
yield SearchMessageOverall(msg, severity=LogLevel.WARNING)
elif re.match(r"^NC_\d+.\d$", search_input.search_string):
known_builds = GenomeBuild.get_known_builds_comma_separated_string()
msg = f"contig={search_input.search_string} not in known_builds: {known_builds}"
yield SearchMessageOverall(msg, severity=LogLevel.WARNING)
24 changes: 22 additions & 2 deletions snpdb/signals/variant_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,29 @@ def _search_hgvs(hgvs_string: str, user: User, genome_build: GenomeBuild, visibl
# reference_message.append(SearchMessage(f'Using reference "{ref_base}" from our build', LogLevel.INFO))
pass

except (MissingTranscript, Contig.ContigNotInBuildError):
# contig triggered from g.HGVS from another genome build - can't do anything just return no results
except MissingTranscript:
pass
except Contig.ContigNotInBuildError as e:
# HGVS is valid but g.HGVS contig from a different genome build than this one
# we don't want to throw an error for 37 contig not in 38 (if both enabled)
# but we do want to throw one if the contig is completely unrecognised
hgvs_variant = hgvs_matcher.create_hgvs_variant(hgvs_string)
contig_accession = hgvs_variant.transcript
if contig := Contig.objects.filter(refseq_accession=contig_accession).first():
# Contig is known to system
contig_builds = contig.genomebuildcontig_set.all()
search_builds = GenomeBuild.builds_with_annotation()
if contig_builds.filter(genome_build__in=search_builds).exists():
pass # skip silently - will get in other build
else:
build_names = ", ".join(contig_builds.order_by("genome_build__name").values_list("genome_build__name", flat=True))
msg = f"{contig_accession=} is from builds {build_names} which are not enabled/annotated."
yield SearchMessageOverall(msg, severity=LogLevel.WARNING)
else:
known_builds = GenomeBuild.get_known_builds_comma_separated_string()
msg = f"{contig_accession=} not in known_builds: {known_builds}"
yield SearchMessageOverall(msg, severity=LogLevel.WARNING)

except (ValueError, NotImplementedError) as hgvs_error:
if gene_symbol_str := hgvs_matcher.get_gene_symbol_if_no_transcript(hgvs_string):
has_results = False
Expand Down

0 comments on commit 5e0eebd

Please sign in to comment.