Skip to content

Commit

Permalink
wip: update to vrs 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
katiestahl committed Jul 17, 2024
1 parent e8f6417 commit d611a55
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 52 deletions.
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ description = "Computable object representation and validation for gene fusions"
license = {file = "LICENSE"}
dependencies = [
"pydantic == 2.*",
"ga4gh.vrsatile.pydantic ~=0.2.0",
"ga4gh.vrs ~=0.8.1",
"ga4gh.vrs ~=2.0.0a8",
"biocommons.seqrepo",
"gene-normalizer ~=0.1.40-dev1",
"gene-normalizer ~=0.4.0",
"cool-seq-tool ~=0.5.0",
]
dynamic=["version"]
Expand Down
54 changes: 15 additions & 39 deletions src/fusor/fusor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@
from cool_seq_tool.schemas import ResidueMode
from ga4gh.core import ga4gh_identify
from ga4gh.vrs import models
from ga4gh.vrsatile.pydantic.vrs_models import (
CURIE,
Number,
SequenceInterval,
SequenceLocation,
VRSTypes,
)
from ga4gh.vrsatile.pydantic.vrsatile_models import GeneDescriptor, LocationDescriptor
from ga4gh.vrs.models import SequenceLocation
from gene.database import AbstractDatabase as GeneDatabase
from gene.database import create_db
from gene.query import QueryHandler
from gene.schemas import CURIE
from pydantic import ValidationError

from fusor.exceptions import FUSORParametersException, IDTranslationException
Expand Down Expand Up @@ -542,27 +536,18 @@ def _location_descriptor(
start: int,
end: int,
sequence_id: str,
label: str | None = None,
seq_id_target_namespace: str | None = None,
use_location_id: bool = False,
) -> LocationDescriptor:
) -> SequenceLocation:
"""Create location descriptor
:param int start: Start position
:param int end: End position
:param str sequence_id: Accession for sequence
:param str label: label for location. If `None`, `sequence_id` will be used as
Location Descriptor's `id` Else, label will be used as Location
Descriptor's `id`.
:param str seq_id_target_namespace: If want to use digest for `sequence_id`,
set this to the namespace you want the digest for. Otherwise, leave as
`None`.
:param bool use_location_id: Takes precedence over `label` or `sequence_id`
becoming Location Descriptor's id. `True` if use ga4gh digest as Location
Descriptor's id. `False`, use default of `label` > `sequence_id`
"""
seq_id_input = sequence_id


try:
sequence_id = coerce_namespace(sequence_id)
except ValueError:
Expand All @@ -583,23 +568,12 @@ def _location_descriptor(
else:
sequence_id = seq_id

location = SequenceLocation(
return SequenceLocation(
sequence_id=sequence_id,
interval=SequenceInterval(start=Number(value=start), end=Number(value=end)),
start=start,
end=end,
)

if use_location_id:
_id = self._location_id(location.model_dump())
else:
quote_id = quote(label) if label else quote(seq_id_input)
_id = f"fusor.location_descriptor:{quote_id}"

location_descr = LocationDescriptor(id=_id, location=location)

if label:
location_descr.label = label
return location_descr

def add_additional_fields(
self,
fusion: Fusion,
Expand Down Expand Up @@ -654,7 +628,7 @@ def add_location_id(self, fusion: Fusion) -> Fusion:
]:
if element_genomic:
location = element_genomic.location
if location.type == VRSTypes.SEQUENCE_LOCATION.value:
if location.type == SequenceLocation:
location_id = self._location_id(location.model_dump())
element_genomic.location_id = location_id
if isinstance(fusion, CategoricalFusion) and fusion.critical_functional_domains:
Expand All @@ -666,7 +640,7 @@ def add_location_id(self, fusion: Fusion) -> Fusion:
element = fusion.regulatory_element
if element.feature_location:
location = element.feature_location
if location.type == VRSTypes.SEQUENCE_LOCATION.value:
if location.type == SequenceLocation:
location_id = self._location_id(location.model_dump())
element.feature_location.location_id = location_id
return fusion
Expand All @@ -692,7 +666,7 @@ def add_translated_sequence_id(
for element in fusion.structural_elements:
if isinstance(element, TemplatedSequenceElement):
location = element.region.location
if location.type == VRSTypes.SEQUENCE_LOCATION.value:
if location.type == SequenceLocation:
try:
new_id = translate_identifier(
self.seqrepo, location.sequence_id, target_namespace
Expand All @@ -708,7 +682,7 @@ def add_translated_sequence_id(
]:
if loc_descr:
location = loc_descr.location
if location.type == VRSTypes.SEQUENCE_LOCATION.value:
if location.type == SequenceLocation:
try:
new_id = translate_identifier(
self.seqrepo, location.sequence_id, target_namespace
Expand Down Expand Up @@ -777,10 +751,12 @@ def _normalized_gene_descriptor(
"""
gene_norm_resp = self.gene_normalizer.normalize(query)
if gene_norm_resp.match_type:
gene_descr = gene_norm_resp.gene_descriptor
gene_descr = gene_norm_resp.gene
if use_minimal_gene_descr:
gene_descr = GeneDescriptor(
id=gene_descr.id, gene_id=gene_descr.gene_id, label=gene_descr.label
id=gene_descr.id,
gene_id=gene_norm_resp.normalized_id,
label=gene_descr.label,
)
return gene_descr, None
return None, f"gene-normalizer unable to normalize {query}"
Expand Down
7 changes: 0 additions & 7 deletions src/fusor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
from enum import Enum
from typing import Any, Literal

from ga4gh.vrsatile.pydantic import return_value
from ga4gh.vrsatile.pydantic.vrsatile_models import (
CURIE,
GeneDescriptor,
LocationDescriptor,
SequenceDescriptor,
)
from pydantic import (
BaseModel,
ConfigDict,
Expand Down
1 change: 0 additions & 1 deletion src/fusor/nomenclature.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Provide helper methods for fusion nomenclature generation."""

from biocommons.seqrepo.seqrepo import SeqRepo
from ga4gh.vrsatile.pydantic.vrs_models import SequenceLocation

from fusor.exceptions import IDTranslationException
from fusor.models import (
Expand Down
1 change: 0 additions & 1 deletion src/fusor/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging

from biocommons.seqrepo.seqrepo import SeqRepo
from ga4gh.vrsatile.pydantic.vrs_models import CURIE

from fusor.exceptions import IDTranslationException

Expand Down
1 change: 0 additions & 1 deletion tests/test_fusor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import copy

import pytest
from ga4gh.vrsatile.pydantic.vrsatile_models import GeneDescriptor, LocationDescriptor

from fusor.exceptions import FUSORParametersException
from fusor.models import (
Expand Down

0 comments on commit d611a55

Please sign in to comment.