Skip to content

Commit

Permalink
issue #1113 - Simplify HGVS errors in search - make sure some user ca…
Browse files Browse the repository at this point in the history
…used errors come through
  • Loading branch information
davmlaw committed Aug 14, 2024
1 parent 6cf4813 commit 4f8d48f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
24 changes: 17 additions & 7 deletions genes/hgvs/biocommons_hgvs/hgvs_converter_biocommons.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ def _parser_hgvs(hgvs_string: str) -> SequenceVariant:
provided_span_length = int(provided_span_length)

parser = ParserSingleton.parser()
sequence_variant = parser.parse_hgvs_variant(hgvs_string)
try:
sequence_variant = parser.parse_hgvs_variant(hgvs_string)
except HGVSError as hgvs_error:
klass = BioCommonsHGVSConverter._get_exception_class(hgvs_error)
raise klass(hgvs_error) from hgvs_error

if provided_span_length is not None:
if sequence_variant.posedit.edit.type == 'inv':
# HGVS is 0 based
Expand Down Expand Up @@ -196,13 +201,18 @@ def variant_coordinate_to_c_hgvs(self, vc: VariantCoordinate, transcript_version
return BioCommonsHGVSVariant(var_c)

def hgvs_to_variant_coordinate_and_reference_match(self, hgvs_string: str, transcript_version=None) -> tuple[VariantCoordinate, HgvsMatchRefAllele]:
var_g, matches_reference = self._hgvs_to_g_hgvs(hgvs_string)
try:
(chrom, position, ref, alt, typ) = self.babelfish.hgvs_to_vcf(var_g)
if alt == '.':
alt = ref
except HGVSDataNotAvailableError:
raise Contig.ContigNotInBuildError()
var_g, matches_reference = self._hgvs_to_g_hgvs(hgvs_string)
try:
(chrom, position, ref, alt, typ) = self.babelfish.hgvs_to_vcf(var_g)
if alt == '.':
alt = ref
except HGVSDataNotAvailableError:
raise Contig.ContigNotInBuildError()
except HGVSError as hgvs_error:
klass = self._get_exception_class(hgvs_error)
raise klass(hgvs_error) from hgvs_error

vc = VariantCoordinate.from_explicit_no_svlen(chrom, position, ref=ref, alt=alt)
return vc.as_internal_symbolic(self.genome_build), matches_reference

Expand Down
6 changes: 3 additions & 3 deletions genes/hgvs/hgvs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from enum import Enum

from genes.hgvs import HGVSVariant, HGVSException
from genes.hgvs import HGVSVariant, HGVSException, HGVSNomenclatureException
from snpdb.models import GenomeBuild, VariantCoordinate


Expand Down Expand Up @@ -69,9 +69,9 @@ def _hgvs_string_validation(hgvs_string: str):

if "ins" in hgvs_string:
if re.match(r".*ins\d+$", hgvs_string):
raise HGVSException("Insertions require inserted sequence, not an integer length")
raise HGVSNomenclatureException("Insertions require inserted sequence, not an integer length")
if re.match(".*ins$", hgvs_string):
raise HGVSException("Insertions require inserted sequence")
raise HGVSNomenclatureException("Insertions require inserted sequence")



Expand Down
9 changes: 6 additions & 3 deletions snpdb/signals/variant_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from genes.hgvs import HGVSMatcher, HGVSException, VariantResolvingError, HGVSImplementationException, \
HGVSNomenclatureException
from genes.hgvs.hgvs_converter import HgvsMatchRefAllele
from genes.models import MissingTranscript, MANE, TranscriptVersion
from genes.models import MissingTranscript, MANE, TranscriptVersion, BadTranscript
from genes.models_enums import AnnotationConsortium
from library.enums.log_level import LogLevel
from library.genomics import format_chrom
Expand Down Expand Up @@ -503,10 +503,13 @@ def search_hgvs(search_input: SearchInputInstance) -> Iterable[SearchResult]:
visible_variants=search_input.get_visible_variants(genome_build),
classify=search_input.classify)
results = list(results) # read iterator to trigger exceptions
except HGVSNomenclatureException as e:
# We want to return errors with the HGVS but not show implementation details...
except (HGVSNomenclatureException, BadTranscript) as e:
# Show errors about HGVS the user can fix
error_message = str(e)
except (Exception, HGVSImplementationException) as e:
# Hide implementation details (user can't fix)
# log_traceback()
# logging.info("HGVS exception type(%s): %s", type(e), str(e))
if search_input.user.is_superuser:
error_message = str(e)
else:
Expand Down

0 comments on commit 4f8d48f

Please sign in to comment.