Skip to content

Commit

Permalink
categorical variation -> categorical variant
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma committed Nov 14, 2024
1 parent 4b01496 commit 126c19a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions src/metakb/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,21 @@ def _add_variation(tx: ManagedTransaction, variation_in: dict) -> None:
tx.run(query, **v)


def _add_categorical_variation(
def _add_categorical_variant(
tx: ManagedTransaction,
categorical_variation_in: dict,
categorical_variant_in: dict,
ids_in_studies: set[str],
) -> None:
"""Add categorical variation objects to DB.
"""Add categorical variant objects to DB.
:param tx: Transaction object provided to transaction functions
:param categorical_variation_in: Categorical variation CDM object
:param categorical_variant_in: Categorical variant CDM object
:param ids_in_studies: IDs found in studies
"""
if categorical_variation_in["id"] not in ids_in_studies:
if categorical_variant_in["id"] not in ids_in_studies:
return

cv = categorical_variation_in.copy()
cv = categorical_variant_in.copy()

mp_nonnull_keys = [
_create_parameterized_query(
Expand Down Expand Up @@ -476,7 +476,7 @@ def add_transformed_data(driver: Driver, data: dict) -> None:
loaded_study_count = 0

for cv in data.get("categorical_variants", []):
session.execute_write(_add_categorical_variation, cv, ids_in_studies)
session.execute_write(_add_categorical_variant, cv, ids_in_studies)

for doc in data.get("documents", []):
session.execute_write(_add_document, doc, ids_in_studies)
Expand Down
14 changes: 7 additions & 7 deletions src/metakb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PaginationParamError(Exception):

class VariationRelation(str, Enum):
"""Constrain possible values for the relationship between variations and
categorical variations.
categorical variants.
"""

HAS_MEMBERS = "HAS_MEMBERS"
Expand Down Expand Up @@ -575,11 +575,11 @@ def _get_disease(self, node: dict) -> Disease:
return Disease(**node)

def _get_variations(self, cv_id: str, relation: VariationRelation) -> list[dict]:
"""Get list of variations associated to categorical variation
"""Get list of variations associated to categorical variant
:param cv_id: ID for categorical variation
:param relation: Relation type for categorical variation and variation
:return: List of variations with `relation` to categorical variation. If
:param cv_id: ID for categorical variant
:param relation: Relation type for categorical variant and variation
:return: List of variations with `relation` to categorical variant. If
VariationRelation.HAS_MEMBERS, returns at least one variation. Otherwise,
returns exactly one variation
"""
Expand Down Expand Up @@ -615,10 +615,10 @@ def _get_variations(self, cv_id: str, relation: VariationRelation) -> list[dict]
return variations

def _get_cat_var(self, node: dict) -> CategoricalVariant:
"""Get categorical variation data from a node with relationship ``HAS_VARIANT``
"""Get categorical variant data from a node with relationship ``HAS_VARIANT``
:param node: Variant node data. This will be mutated.
:return: Categorical Variation data
:return: Categorical Variant data
"""
node["mappings"] = _deserialize_field(node, "mappings")

Expand Down
6 changes: 3 additions & 3 deletions src/metakb/transformers/civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async def transform(self, harvested_data: CivicHarvestedData) -> None:
for mp in molecular_profiles
if f"civic.vid:{mp['variant_ids'][0]}" in able_to_normalize_vids
]
self._add_protein_consequences(mps, mp_id_to_v_id_mapping)
self._add_categorical_variants(mps, mp_id_to_v_id_mapping)

# Add variant therapeutic response study data. Will update `studies`
self._add_variant_therapeutic_response_studies(
Expand Down Expand Up @@ -366,10 +366,10 @@ def _get_predicate(
predicate = TherapeuticResponsePredicate.RESISTANCE
return predicate

def _add_protein_consequences(
def _add_categorical_variants(
self, molecular_profiles: list[dict], mp_id_to_v_id_mapping: dict
) -> None:
"""Create Protein Sequence Consequence objects for all supported MP records.
"""Create Categorical Variant objects for all supported MP records.
Mutates instance variables ``able_to_normalize['categorical_variants']`` and
``processed_data.categorical_variants``.
Expand Down
6 changes: 3 additions & 3 deletions src/metakb/transformers/moa.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def transform(self, harvested_data: MoaHarvestedData) -> None:
# Add gene, variant, and source data to ``processed_data`` instance variable
# (``genes``, ``variations``, and ``documents``)
self._add_genes(harvested_data.genes)
await self._add_protein_consequences(harvested_data.variants)
await self._add_categorical_variants(harvested_data.variants)
self._add_documents(harvested_data.sources)

# Add variant therapeutic response study data. Will update `studies`
Expand Down Expand Up @@ -215,8 +215,8 @@ async def _add_variant_therapeutic_response_studies(
)
self.processed_data.studies.append(statement)

async def _add_protein_consequences(self, variants: list[dict]) -> None:
"""Create Protein Sequence Consequence objects for all MOA variant records.
async def _add_categorical_variants(self, variants: list[dict]) -> None:
"""Create Categorical Variant objects for all MOA variant records.
Mutates instance variables ``able_to_normalize['variations']`` and
``processed_data.variations``, if the variation-normalizer can successfully
normalize the variant
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/database/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,14 @@ def test_variation_rules(
assert v["expression_hgvs_p"] == expected_p


def test_categorical_variation_rules(
def test_categorical_variant_rules(
check_unique_property,
check_relation_count,
check_node_labels,
get_node_by_id,
civic_mpid12,
):
"""Verify property and relationship rules for Categorical Variation nodes."""
"""Verify property and relationship rules for Categorical Variant nodes."""
check_unique_property("CategoricalVariant", "id")
check_relation_count(
"CategoricalVariant", "Variation", "HAS_DEFINING_CONTEXT", max_rels=1
Expand Down

0 comments on commit 126c19a

Please sign in to comment.