Skip to content

Commit

Permalink
fix: return result for protein/cdna with no mane data found
Browse files Browse the repository at this point in the history
- Also creates an enum for vrs sequence location accession status. This
  will be replaced by TranscriptPriority enum in cool-seq-tool once it
is updated
  • Loading branch information
korikuzma committed Sep 1, 2023
1 parent 2cc74a6 commit 8469a7d
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 26 deletions.
6 changes: 5 additions & 1 deletion tests/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,6 @@ async def test_valid_queries(test_handler):
assert await test_handler.normalize("CCND1 Y44D")

resp = await test_handler.normalize("NC_000002.12:g.73448098_73448100delCTC")
assert resp
assert resp.variation_descriptor.variation.state.sequence == "CTC"
assert (
resp.variation_descriptor.variation.id
Expand All @@ -1582,6 +1581,11 @@ async def test_valid_queries(test_handler):
resp = await test_handler.normalize(q)
assert resp.variation_descriptor, q

# Test where Mane data not found
resp = await test_handler.normalize("ALK p.A1280V")
assert resp.variation_descriptor.variation
assert resp.warnings == ["Unable to find MANE representation"]


@pytest.mark.asyncio
async def test_no_matches(test_handler):
Expand Down
14 changes: 13 additions & 1 deletion variation/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cool_seq_tool.data_sources import SeqRepoAccess, TranscriptMappings, UTADatabase
from ga4gh.vrsatile.pydantic.vrs_models import CopyChange
from ga4gh.vrsatile.pydantic.vrsatile_models import MoleculeContext
from gene.query import QueryHandler as GeneQueryHandler

from variation.classify import Classify
Expand All @@ -19,6 +20,7 @@
from variation.schemas.translation_response_schema import (
AC_PRIORITY_LABELS,
TranslationResult,
VrsSeqLocAcStatus,
)
from variation.to_vrsatile import ToVRSATILE
from variation.tokenize import Tokenize
Expand Down Expand Up @@ -65,7 +67,7 @@ def __init__(

@staticmethod
def _get_priority_translation_result(
translations: List[TranslationResult], ac_status: str
translations: List[TranslationResult], ac_status: VrsSeqLocAcStatus
) -> Optional[TranslationResult]:
"""Get prioritized translation result. Tries to find translation results with
the same `vrs_seq_loc_ac_status` as `ac_status`. If more than one translation
Expand Down Expand Up @@ -251,6 +253,16 @@ async def normalize(
translations, ac_status
)
if translation_result:
if (
translation_result.vrs_seq_loc_ac_status
== VrsSeqLocAcStatus.NA
):
molecule_context = (
translation_result.validation_result.classification.molecule_context
)
if molecule_context != MoleculeContext.GENOMIC:
# Only supports protein/cDNA at the moment
warnings.append("Unable to find MANE representation")
break

# Get variation descriptor information
Expand Down
33 changes: 22 additions & 11 deletions variation/schemas/translation_response_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for Translation Response Schema."""
from enum import Enum
from typing import Dict, Optional

from cool_seq_tool.schemas import TranscriptPriorityLabel
Expand All @@ -7,21 +8,31 @@
from variation.schemas.validation_response_schema import ValidationResult


class VrsSeqLocAcStatus(str, Enum):
"""Create enum for VRS SequenceLocation accession status.
Order when defining matters.
First has highest priority, last has lowest priority
Once issue-191 is resolved in cool-seq-tool, we should use the
TranscriptPriorityLabel enum
"""

MANE_SELECT = TranscriptPriorityLabel.MANESelect.value
MANE_PLUS_CLINICAL = TranscriptPriorityLabel.MANEPlusClinical.value
LONGEST_COMPATIBLE_REMAINING = (
TranscriptPriorityLabel.LongestCompatibleRemaining.value
)
GRCH38 = "GRCh38" # will change to lowercase in cool-seq-tool issue-191
NA = "na"


AC_PRIORITY_LABELS = [m for m in VrsSeqLocAcStatus.__members__.values()]


class TranslationResult(BaseModel):
"""Translation Result"""

vrs_variation: Optional[Dict]
vrs_seq_loc_ac: Optional[StrictStr]
vrs_seq_loc_ac_status: StrictStr = "na"
vrs_seq_loc_ac_status: VrsSeqLocAcStatus = VrsSeqLocAcStatus.NA
og_ac: Optional[StrictStr]
validation_result: ValidationResult


# Define accession priority. First has highest priority, last has lowest priority
AC_PRIORITY_LABELS = [
TranscriptPriorityLabel.MANESelect.value,
TranscriptPriorityLabel.MANEPlusClinical.value,
TranscriptPriorityLabel.LongestCompatibleRemaining.value,
"GRCh38",
"na",
]
7 changes: 5 additions & 2 deletions variation/translators/genomic_del_dup_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
from variation.schemas.normalize_response_schema import HGVSDupDelModeOption
from variation.schemas.service_schema import ClinVarAssembly
from variation.schemas.token_response_schema import AltType
from variation.schemas.translation_response_schema import TranslationResult
from variation.schemas.translation_response_schema import (
TranslationResult,
VrsSeqLocAcStatus,
)
from variation.schemas.validation_response_schema import ValidationResult
from variation.translators.translator import Translator
from variation.utils import get_assembly
Expand Down Expand Up @@ -107,7 +110,7 @@ async def translate(

grch38_data = None
vrs_variation = None
vrs_seq_loc_ac_status = "na"
vrs_seq_loc_ac_status = VrsSeqLocAcStatus.NA

if do_liftover or endpoint_name == Endpoint.NORMALIZE:
errors = []
Expand Down
7 changes: 5 additions & 2 deletions variation/translators/genomic_delins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
)
from variation.schemas.normalize_response_schema import HGVSDupDelModeOption
from variation.schemas.token_response_schema import AltType
from variation.schemas.translation_response_schema import TranslationResult
from variation.schemas.translation_response_schema import (
TranslationResult,
VrsSeqLocAcStatus,
)
from variation.schemas.validation_response_schema import ValidationResult
from variation.translators.translator import Translator

Expand Down Expand Up @@ -54,7 +57,7 @@ async def translate(
classification: GenomicDelInsClassification = validation_result.classification
vrs_allele = None
vrs_seq_loc_ac = None
vrs_seq_loc_ac_status = "na"
vrs_seq_loc_ac_status = VrsSeqLocAcStatus.NA

if endpoint_name == Endpoint.NORMALIZE:
gene = (
Expand Down
7 changes: 5 additions & 2 deletions variation/translators/genomic_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
)
from variation.schemas.normalize_response_schema import HGVSDupDelModeOption
from variation.schemas.token_response_schema import AltType
from variation.schemas.translation_response_schema import TranslationResult
from variation.schemas.translation_response_schema import (
TranslationResult,
VrsSeqLocAcStatus,
)
from variation.schemas.validation_response_schema import ValidationResult
from variation.translators.translator import Translator

Expand Down Expand Up @@ -57,7 +60,7 @@ async def translate(
)
vrs_allele = None
vrs_seq_loc_ac = None
vrs_seq_loc_ac_status = "na"
vrs_seq_loc_ac_status = VrsSeqLocAcStatus.NA

if endpoint_name == Endpoint.NORMALIZE:
gene = (
Expand Down
7 changes: 5 additions & 2 deletions variation/translators/genomic_reference_agree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
)
from variation.schemas.normalize_response_schema import HGVSDupDelModeOption
from variation.schemas.token_response_schema import AltType
from variation.schemas.translation_response_schema import TranslationResult
from variation.schemas.translation_response_schema import (
TranslationResult,
VrsSeqLocAcStatus,
)
from variation.schemas.validation_response_schema import ValidationResult
from variation.translators.translator import Translator

Expand Down Expand Up @@ -56,7 +59,7 @@ async def translate(
)
vrs_allele = None
vrs_seq_loc_ac = None
vrs_seq_loc_ac_status = "na"
vrs_seq_loc_ac_status = VrsSeqLocAcStatus.NA

if endpoint_name == Endpoint.NORMALIZE:
gene = (
Expand Down
7 changes: 5 additions & 2 deletions variation/translators/genomic_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
)
from variation.schemas.normalize_response_schema import HGVSDupDelModeOption
from variation.schemas.token_response_schema import AltType
from variation.schemas.translation_response_schema import TranslationResult
from variation.schemas.translation_response_schema import (
TranslationResult,
VrsSeqLocAcStatus,
)
from variation.schemas.validation_response_schema import ValidationResult
from variation.translators.translator import Translator

Expand Down Expand Up @@ -59,7 +62,7 @@ async def translate(
)
vrs_allele = None
vrs_seq_loc_ac = None
vrs_seq_loc_ac_status = "na"
vrs_seq_loc_ac_status = VrsSeqLocAcStatus.NA

if endpoint_name == Endpoint.NORMALIZE:
gene = (
Expand Down
10 changes: 7 additions & 3 deletions variation/translators/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from variation.schemas.classification_response_schema import ClassificationType
from variation.schemas.normalize_response_schema import HGVSDupDelModeOption
from variation.schemas.token_response_schema import AltType, GeneToken
from variation.schemas.translation_response_schema import TranslationResult
from variation.schemas.translation_response_schema import (
TranslationResult,
VrsSeqLocAcStatus,
)
from variation.schemas.validation_response_schema import ValidationResult
from variation.validators.genomic_base import GenomicBase
from variation.vrs_representation import VRSRepresentation
Expand Down Expand Up @@ -179,7 +182,7 @@ async def get_p_or_cdna_translation_result(
"""
vrs_allele = None
vrs_seq_loc_ac = None
vrs_seq_loc_ac_status = "na"
vrs_seq_loc_ac_status = VrsSeqLocAcStatus.NA

if endpoint_name == Endpoint.NORMALIZE:
mane = await self.mane_transcript.get_mane_transcript(
Expand All @@ -205,7 +208,8 @@ async def get_p_or_cdna_translation_result(
cds_start=mane.get("coding_start_site", None),
alt=alt,
)
else:

if not vrs_allele:
vrs_seq_loc_ac = validation_result.accession
vrs_allele = self.vrs.to_vrs_allele(
vrs_seq_loc_ac,
Expand Down

0 comments on commit 8469a7d

Please sign in to comment.