diff --git a/pyproject.toml b/pyproject.toml index 81b62fa..99baa9e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dependencies = [ "ga4gh.vrs ~=0.8.1", "biocommons.seqrepo", "gene-normalizer ~=0.1.40-dev1", - "cool-seq-tool ~=0.5.0", + "cool-seq-tool ~=0.5.1", ] dynamic=["version"] diff --git a/src/fusor/fusor.py b/src/fusor/fusor.py index 9bb4976..9d00a6a 100644 --- a/src/fusor/fusor.py +++ b/src/fusor/fusor.py @@ -6,7 +6,7 @@ from bioutils.accessions import coerce_namespace from cool_seq_tool.app import CoolSeqTool -from cool_seq_tool.schemas import ResidueMode +from cool_seq_tool.schemas import ResidueMode, Strand from ga4gh.core import ga4gh_identify from ga4gh.vrs import models from ga4gh.vrsatile.pydantic.vrs_models import ( @@ -42,7 +42,6 @@ MultiplePossibleGenesElement, RegulatoryClass, RegulatoryElement, - Strand, StructuralElementType, TemplatedSequenceElement, TranscriptSegmentElement, diff --git a/src/fusor/models.py b/src/fusor/models.py index 351e50c..0069ca6 100644 --- a/src/fusor/models.py +++ b/src/fusor/models.py @@ -4,6 +4,7 @@ from enum import Enum from typing import Any, Literal +from cool_seq_tool.schemas import Strand from ga4gh.vrsatile.pydantic import return_value from ga4gh.vrsatile.pydantic.vrsatile_models import ( CURIE, @@ -248,13 +249,6 @@ def validate_sequence(cls, v): ) -class Strand(str, Enum): - """Define possible values for strand""" - - POSITIVE = "+" - NEGATIVE = "-" - - class TemplatedSequenceElement(BaseStructuralElement): """Define Templated Sequence Element class. A templated sequence is a contiguous genomic sequence found in the gene @@ -286,7 +280,7 @@ class TemplatedSequenceElement(BaseStructuralElement): }, "label": "chr12:44908821-44908822(+)", }, - "strand": "+", + "strand": 1, } }, ) diff --git a/src/fusor/nomenclature.py b/src/fusor/nomenclature.py index ca755bc..1928e73 100644 --- a/src/fusor/nomenclature.py +++ b/src/fusor/nomenclature.py @@ -1,6 +1,7 @@ """Provide helper methods for fusion nomenclature generation.""" from biocommons.seqrepo.seqrepo import SeqRepo +from cool_seq_tool.schemas import Strand from ga4gh.vrsatile.pydantic.vrs_models import SequenceLocation from fusor.exceptions import IDTranslationException @@ -98,6 +99,7 @@ def templated_seq_nomenclature(element: TemplatedSequenceElement, sr: SeqRepo) - :raises ValueError: if location isn't a SequenceLocation or if unable to retrieve region or location """ + strand_value = "+" if element.strand == Strand.POSITIVE else "-" if element.region and element.region.location: location = element.region.location if isinstance(location, SequenceLocation): @@ -111,7 +113,7 @@ def templated_seq_nomenclature(element: TemplatedSequenceElement, sr: SeqRepo) - ] except IDTranslationException as e: raise ValueError from e - return f"{refseq_id.split(':')[1]}(chr {chrom}):g.{start}_{end}({element.strand.value})" + return f"{refseq_id.split(':')[1]}(chr {chrom}):g.{start}_{end}({strand_value})" raise ValueError raise ValueError diff --git a/tests/conftest.py b/tests/conftest.py index 432392a..4b98ad1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -546,7 +546,7 @@ def exhaustive_example(alk_gene_descriptor, braf_gene_descriptor): }, }, }, - "strand": "+", + "strand": 1, }, {"type": "MultiplePossibleGenesElement"}, ], @@ -668,7 +668,7 @@ def fusion_example(): }, }, }, - "strand": "+", + "strand": 1, }, {"type": "MultiplePossibleGenesElement"}, ], diff --git a/tests/test_fusor.py b/tests/test_fusor.py index d1b1e12..b1a6ef0 100644 --- a/tests/test_fusor.py +++ b/tests/test_fusor.py @@ -3,6 +3,7 @@ import copy import pytest +from cool_seq_tool.schemas import Strand from ga4gh.vrsatile.pydantic.vrsatile_models import GeneDescriptor, LocationDescriptor from fusor.exceptions import FUSORParametersException @@ -186,7 +187,7 @@ def templated_sequence_element(): }, }, }, - "strand": "+", + "strand": 1, } return TemplatedSequenceElement(**params) @@ -209,7 +210,7 @@ def templated_sequence_element_ensg(): }, }, }, - "strand": "-", + "strand": -1, } return TemplatedSequenceElement(**params) @@ -234,7 +235,7 @@ def templated_sequence_element_custom_id(): }, }, }, - "strand": "+", + "strand": 1, } return TemplatedSequenceElement(**params) @@ -808,12 +809,12 @@ def test_templated_sequence_element( ): """Test that templated sequence element works correctly""" tsg = fusor_instance.templated_sequence_element( - 100, 150, "NC_000001.11", "+", residue_mode="residue" + 100, 150, "NC_000001.11", Strand.POSITIVE, residue_mode="residue" ) assert tsg.model_dump() == templated_sequence_element.model_dump() tsg = fusor_instance.templated_sequence_element( - 99, 150, "NC_000001.11", "+", residue_mode="inter-residue" + 99, 150, "NC_000001.11", Strand.POSITIVE, residue_mode="inter-residue" ) assert tsg.model_dump() == templated_sequence_element.model_dump() @@ -826,14 +827,14 @@ def test_templated_sequence_element( 100, 150, "NC_000001.11", - "+", + Strand.POSITIVE, add_location_id=True, seq_id_target_namespace="ga4gh", ) assert tsg.model_dump() == expected tsg = fusor_instance.templated_sequence_element( - 140719329, 140719400, "ENSG00000157764", "-" + 140719329, 140719400, "ENSG00000157764", Strand.NEGATIVE ) assert tsg.model_dump() == templated_sequence_element_ensg.model_dump() @@ -841,7 +842,11 @@ def test_templated_sequence_element( # adds "ensembl" namespace but unable to translate to ga4gh digest ID expected = copy.deepcopy(templated_sequence_element_ensg.model_dump()) tsg = fusor_instance.templated_sequence_element( - 140719329, 140719400, "ENSG00000157764", "-", seq_id_target_namespace="ga4gh" + 140719329, + 140719400, + "ENSG00000157764", + Strand.NEGATIVE, + seq_id_target_namespace="ga4gh", ) assert tsg.model_dump() == expected @@ -852,7 +857,7 @@ def test_templated_sequence_element( 200, 300, "custom_ID__1", - "+", + Strand.POSITIVE, residue_mode="inter-residue", seq_id_target_namespace="ga4gh", ) diff --git a/tests/test_models.py b/tests/test_models.py index e335875..6a9de00 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -3,6 +3,7 @@ import copy import pytest +from cool_seq_tool.schemas import Strand from pydantic import ValidationError from fusor.models import ( @@ -231,12 +232,12 @@ def templated_sequence_elements(location_descriptors): return [ { "type": "TemplatedSequenceElement", - "strand": "+", + "strand": 1, "region": location_descriptors[5], }, { "type": "TemplatedSequenceElement", - "strand": "-", + "strand": -1, "region": location_descriptors[4], }, ] @@ -552,7 +553,7 @@ def assert_genomic_region_test_element(test): expected values. """ assert test.type == "TemplatedSequenceElement" - assert test.strand.value == "+" + assert test.strand == Strand.POSITIVE assert test.region.id == "chr12:p12.1-p12.2" assert test.region.type == "LocationDescriptor" assert test.region.location.species_id == "taxonomy:9606" @@ -585,7 +586,7 @@ def assert_genomic_region_test_element(test): # test enum validation with pytest.raises(ValidationError) as exc_info: assert TemplatedSequenceElement( - type="GeneElement", region=location_descriptors[0], strand="+" + type="GeneElement", region=location_descriptors[0], strand=Strand.POSITIVE ) msg = "Input should be " check_validation_error(exc_info, msg)