Skip to content

Commit 0ca7f3c

Browse files
authored
feat: update va spec models to 1.0.1 (#35)
close #34 * Make ConditionSet nestable to represent complex relationships
1 parent 91023b4 commit 0ca7f3c

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

src/ga4gh/va_spec/base/domain_entities.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
"""VA Spec Shared Domain Entity Data Structures"""
22

3+
from __future__ import annotations
4+
35
from ga4gh.core.models import BaseModelForbidExtra, Element, MappableConcept
46
from ga4gh.va_spec.base.enums import MembershipOperator
57
from pydantic import ConfigDict, Field, RootModel
68

79

810
class ConditionSet(Element, BaseModelForbidExtra):
9-
"""A set of conditions (diseases, phenotypes, traits).
10-
A set of two or more conditions that co-occur in the same patient/subject, or are
11-
manifest individually in a different subset of participants in a research study.
11+
"""A set of conditions (diseases, phenotypes, traits) that occur together or are
12+
related, depending on the membership operator, and may manifest together in the
13+
same patient or individually in a different subset of participants in a research
14+
study.
1215
"""
1316

1417
model_config = ConfigDict(use_enum_values=True)
1518

16-
conditions: list[MappableConcept] = Field(
19+
conditions: list[MappableConcept | ConditionSet] = Field(
1720
...,
1821
min_length=2,
19-
description="A list of conditions (diseases, phenotypes, traits) that are co-occurring.",
22+
description="A list of conditions (diseases, phenotypes, traits) that are co-occurring or related, depending on the membership operator.",
2023
)
2124
membershipOperator: MembershipOperator = Field(
2225
...,

submodules/va_spec

Submodule va_spec updated 75 files

tests/validation/test_va_spec_models.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ExperimentalVariantFunctionalImpactStudyResult,
1919
)
2020
from ga4gh.va_spec.base.core import EvidenceLine, Method, StudyGroup, StudyResult
21+
from ga4gh.va_spec.base.domain_entities import ConditionSet
2122
from ga4gh.va_spec.ccv_2022.models import (
2223
VariantOncogenicityEvidenceLine,
2324
VariantOncogenicityStudyStatement,
@@ -49,6 +50,86 @@ def caf():
4950
)
5051

5152

53+
def test_condition_set():
54+
"""Ensure ConditionSet model works as expected"""
55+
condition_set_dict = {
56+
"membershipOperator": "AND",
57+
"conditions": [
58+
{
59+
"conceptType": "Disease",
60+
"id": "civic.did:3387",
61+
"mappings": [
62+
{
63+
"coding": {
64+
"code": "DOID:0081279",
65+
"system": "https://disease-ontology.org/?id=",
66+
},
67+
"relation": "exactMatch",
68+
}
69+
],
70+
"name": "Diffuse Astrocytoma, MYB- Or MYBL1-altered",
71+
},
72+
{
73+
"conditions": [
74+
{
75+
"conceptType": "Phenotype",
76+
"id": "civic.phenotype:8121",
77+
"mappings": [
78+
{
79+
"coding": {
80+
"code": "HP:0011463",
81+
"system": "https://hpo.jax.org/browse/term/",
82+
},
83+
"relation": "exactMatch",
84+
}
85+
],
86+
"name": "Childhood onset",
87+
},
88+
{
89+
"conceptType": "Phenotype",
90+
"id": "civic.phenotype:2656",
91+
"mappings": [
92+
{
93+
"coding": {
94+
"code": "HP:0003621",
95+
"id": "HP:0003621",
96+
"system": "https://hpo.jax.org/browse/term/",
97+
},
98+
"relation": "exactMatch",
99+
}
100+
],
101+
"name": "Juvenile onset",
102+
},
103+
{
104+
"conceptType": "Phenotype",
105+
"id": "civic.phenotype:2643",
106+
"mappings": [
107+
{
108+
"coding": {
109+
"code": "HP:0003581",
110+
"system": "https://hpo.jax.org/browse/term/",
111+
},
112+
"relation": "exactMatch",
113+
}
114+
],
115+
"name": "Adult onset",
116+
},
117+
],
118+
"membershipOperator": "OR",
119+
},
120+
],
121+
}
122+
assert ConditionSet(**condition_set_dict)
123+
124+
invalid_params = deepcopy(condition_set_dict)
125+
invalid_params["conditions"].pop()
126+
127+
with pytest.raises(
128+
ValidationError, match="List should have at least 2 items after validation"
129+
):
130+
ConditionSet(**invalid_params)
131+
132+
52133
def test_agent():
53134
"""Ensure Agent model works as expected"""
54135
agent = Agent(name="Joe")

0 commit comments

Comments
 (0)