Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ga4gh/va_spec/base/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,21 @@ def _get_base_criterion_from_code(cls, evidence_outcome_code: str) -> CriterionT
def _validate_method_type_evidence_outcome(
cls,
method_type: str,
evidence_outcome_code: str,
evidence_outcome_code: str | None,
) -> None:
"""Validate that ``evidenceOutcome`` is compatible with a method type.

:param method_type: Method type value from ``specifiedBy.methodType``.
:param evidence_outcome_code: Evidence outcome to validate.
:raises ValueError: If the evidence outcome criterion is invalid or is
not valid for the specified method type.
:return: None.
not valid for the specified method type, or if method type is invalid
"""
parsed_method_type = cls.MethodType(method_type)
allowed_criteria = cls.ALLOWED_CRITERIA_BY_METHOD_TYPE[parsed_method_type]

if not evidence_outcome_code:
return

criterion = cls._get_base_criterion_from_code(evidence_outcome_code)

if criterion not in allowed_criteria:
Expand Down
10 changes: 8 additions & 2 deletions src/ga4gh/va_spec/ccv_2022/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,16 @@ def validate_model(self) -> Self:
``directionOfEvidenceProvided`` is neutral
"""
self._validate_direction_of_evidence_provided()
self._validate_evidence_outcome(SYSTEM, CCV_CODE_PATTERN, is_required=True)
self._validate_evidence_outcome(SYSTEM, CCV_CODE_PATTERN, is_required=False)
self._validate_criterion_specified_by()

evidence_outcome = (
self.evidenceOutcome.primaryCoding.code.root
if self.evidenceOutcome
else None
)
self._validate_method_type_evidence_outcome(
self.specifiedBy.methodType, self.evidenceOutcome.primaryCoding.code.root
self.specifiedBy.methodType, evidence_outcome
)
return self

Expand Down
33 changes: 33 additions & 0 deletions tests/validation/test_va_spec_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ExperimentalVariantFunctionalImpactStudyResult,
)
from ga4gh.va_spec.base.core import (
Direction,
EvidenceLine,
Method,
Statement,
Expand Down Expand Up @@ -611,6 +612,38 @@ def test_variant_onco_el():
VariantOncogenicityEvidenceLine(**invalid_params)


def test_variant_onco_el_no_evidence_outcome():
"""Test that VariantOncogenicityEvidenceLine validates without evidence
outcome
"""
valid = VariantOncogenicityEvidenceLine(
type="EvidenceLine",
specifiedBy={
"type": "Method",
"reportedIn": {
"type": "Document",
"pmid": "35101336",
"name": "ClinGen/CGC/VICC Guidelines for Oncogenicity, 2022",
},
"methodType": "functional_assay",
},
directionOfEvidenceProvided=Direction.NEUTRAL,
scoreOfEvidenceProvided=0,
evidenceOutcome=None,
)

assert valid

invalid = valid.model_dump()
invalid["specifiedBy"]["methodType"] = "dummy"

with pytest.raises(
ValueError,
match="'dummy' is not a valid VariantOncogenicityEvidenceLine.MethodType",
):
VariantOncogenicityEvidenceLine.model_validate(invalid)


def test_aac_statement():
"""Test that AMP/ASCO/CAP statement model validators work correctly"""
prop = {
Expand Down
Loading