diff --git a/genes/hgvs/biocommons_hgvs/hgvs_converter_biocommons.py b/genes/hgvs/biocommons_hgvs/hgvs_converter_biocommons.py index 318199dfd..f9caf1290 100644 --- a/genes/hgvs/biocommons_hgvs/hgvs_converter_biocommons.py +++ b/genes/hgvs/biocommons_hgvs/hgvs_converter_biocommons.py @@ -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 @@ -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 diff --git a/genes/hgvs/hgvs_converter.py b/genes/hgvs/hgvs_converter.py index deccf663d..014ec9eb2 100644 --- a/genes/hgvs/hgvs_converter.py +++ b/genes/hgvs/hgvs_converter.py @@ -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 @@ -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") diff --git a/snpdb/signals/variant_search.py b/snpdb/signals/variant_search.py index 102df41ab..23eaa8128 100644 --- a/snpdb/signals/variant_search.py +++ b/snpdb/signals/variant_search.py @@ -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 @@ -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: