Skip to content

Commit

Permalink
feat: add reading frame to assayed fusions (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored Jul 17, 2024
1 parent 630a2af commit 14eb1fe
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/fusor/examples/bcr_abl1.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}
}
],
"r_frame_preserved": true,
"reading_frame_preserved": true,
"critical_functional_domains": [
{
"type": "FunctionalDomain",
Expand Down
2 changes: 1 addition & 1 deletion src/fusor/examples/bcr_abl1_expanded.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"element_genomic_end": null
}
],
"r_frame_preserved": true,
"reading_frame_preserved": true,
"critical_functional_domains": [
{
"type": "FunctionalDomain",
Expand Down
14 changes: 8 additions & 6 deletions src/fusor/fusor.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def fusion(self, fusion_type: FusionType | None = None, **kwargs) -> Fusion:
categorical_attributes = any(
[
"critical_functional_domains" in kwargs,
"r_frame_preserved" in kwargs,
self._contains_element_type(
kwargs, StructuralElementType.MULTIPLE_POSSIBLE_GENES_ELEMENT
),
Expand Down Expand Up @@ -165,23 +164,22 @@ def categorical_fusion(
structural_elements: CategoricalFusionElements,
regulatory_element: RegulatoryElement | None = None,
critical_functional_domains: list[FunctionalDomain] | None = None,
r_frame_preserved: bool | None = None,
reading_frame_preserved: bool | None = None,
) -> CategoricalFusion:
"""Construct a categorical fusion object
:param structural_elements: elements constituting the fusion
:param regulatory_element: affected regulatory element
:param critical_functional_domains: lost or preserved functional domains
:param r_frame_preserved: ``True`` if reading frame is preserved. ``False``
otherwise
:param reading_frame_preserved: ``True`` if reading frame is preserved.
``False`` otherwise
:return: CategoricalFusion if construction successful
:raise: FUSORParametersException if given incorrect fusion properties
"""
try:
fusion = CategoricalFusion(
structural_elements=structural_elements,
critical_functional_domains=critical_functional_domains,
r_frame_preserved=r_frame_preserved,
reading_frame_preserved=reading_frame_preserved,
regulatory_element=regulatory_element,
)
except ValidationError as e:
Expand All @@ -194,12 +192,15 @@ def assayed_fusion(
causative_event: CausativeEvent | None = None,
assay: Assay | None = None,
regulatory_element: RegulatoryElement | None = None,
reading_frame_preserved: bool | None = None,
) -> AssayedFusion:
"""Construct an assayed fusion object
:param structural_elements: elements constituting the fusion
:param causative_event: event causing the fusion
:param assay: how knowledge of the fusion was obtained
:param regulatory_element: affected regulatory elements
:param reading_frame_preserved: ``True`` if reading frame is preserved.
``False`` otherwise
:return: Tuple containing optional AssayedFusion if construction successful,
and any relevant validation warnings
"""
Expand All @@ -209,6 +210,7 @@ def assayed_fusion(
regulatory_element=regulatory_element,
causative_event=causative_event,
assay=assay,
reading_frame_preserved=reading_frame_preserved,
)
except ValidationError as e:
raise FUSORParametersException(str(e)) from e
Expand Down
4 changes: 2 additions & 2 deletions src/fusor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class AbstractFusion(BaseModel, ABC):
"""Define Fusion class"""

type: FusionType
reading_frame_preserved: StrictBool | None = None
regulatory_element: RegulatoryElement | None = None
structural_elements: list[BaseStructuralElement]

Expand Down Expand Up @@ -714,15 +715,14 @@ class CategoricalFusion(AbstractFusion):
"""

type: Literal[FUSORTypes.CATEGORICAL_FUSION] = FUSORTypes.CATEGORICAL_FUSION
r_frame_preserved: StrictBool | None = None
critical_functional_domains: list[FunctionalDomain] | None = None
structural_elements: CategoricalFusionElements

model_config = ConfigDict(
json_schema_extra={
"example": {
"type": "CategoricalFusion",
"r_frame_preserved": True,
"reading_frame_preserved": True,
"critical_functional_domains": [
{
"type": "FunctionalDomain",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def fusion_example():
"""Create test fixture for a fake fusion without additional property expansion."""
return {
"type": "CategoricalFusion",
"r_frame_preserved": True,
"reading_frame_preserved": True,
"critical_functional_domains": [
{
"type": "FunctionalDomain",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fusor.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def fusion_ensg_sequence_id(templated_sequence_element_ensg):
templated_sequence_element_ensg,
{"type": "MultiplePossibleGenesElement"},
],
"r_frame_preserved": True,
"reading_frame_preserved": True,
"regulatory_element": None,
}
return CategoricalFusion(**params)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def test_fusion(
"""Test that Fusion object initializes correctly"""
# test valid object
fusion = CategoricalFusion(
r_frame_preserved=True,
reading_frame_preserved=True,
critical_functional_domains=[functional_domains[0]],
structural_elements=[transcript_segments[1], transcript_segments[2]],
regulatory_element=regulatory_elements[0],
Expand Down

0 comments on commit 14eb1fe

Please sign in to comment.