Skip to content

Commit ef423f3

Browse files
committed
use types
1 parent 7e69de4 commit ef423f3

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/anyvlm/storage/mappers.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ga4gh.va_spec.base import CohortAlleleFrequencyStudyResult, StudyGroup
88

99
from anyvlm.storage import orm
10+
from anyvlm.utils.types import AncillaryResults, QualityMeasures
1011

1112
V = TypeVar("V") # VA-Spec entity type
1213
D = TypeVar("D") # DB entity type
@@ -49,12 +50,12 @@ def from_db_entity(
4950
focusAlleleCount=ac,
5051
locusAlleleCount=an,
5152
focusAlleleFrequency=round(ac / an, 9),
52-
qualityMeasures={"qcFilters": db_entity.filter},
53-
ancillaryResults={
54-
"homozygotes": homozygotes,
55-
"heterozygotes": heterozygotes,
56-
"hemizygotes": hemizygotes,
57-
},
53+
qualityMeasures=QualityMeasures(qcFilters=db_entity.filter).model_dump(),
54+
ancillaryResults=AncillaryResults(
55+
homozygotes=homozygotes,
56+
heterozygotes=heterozygotes,
57+
hemizygotes=hemizygotes,
58+
).model_dump(),
5859
cohort=StudyGroup(name=db_entity.cohort),
5960
)
6061

@@ -66,7 +67,8 @@ def to_db_entity(
6667
:param va_model: VA-Spec Cohort Allele Frequency Study Result instance
6768
:return: ORM Allele Frequency Data instance
6869
"""
69-
ancillary_results = va_model.ancillaryResults
70+
ancillary_results = AncillaryResults(**va_model.ancillaryResults)
71+
filter_ = QualityMeasures(**va_model.qualityMeasures)
7072
focus_allele = va_model.focusAllele
7173

7274
if isinstance(focus_allele, iriReference):
@@ -77,9 +79,9 @@ def to_db_entity(
7779
return orm.AlleleFrequencyData(
7880
vrs_id=vrs_id,
7981
an=va_model.locusAlleleCount,
80-
ac_het=ancillary_results["heterozygotes"],
81-
ac_hom=ancillary_results["homozygotes"],
82-
ac_hemi=ancillary_results["hemizygotes"],
83-
filter=va_model.qualityMeasures["qcFilters"],
82+
ac_het=ancillary_results.heterozygotes,
83+
ac_hom=ancillary_results.homozygotes,
84+
ac_hemi=ancillary_results.hemizygotes,
85+
filter=filter_.qcFilters,
8486
cohort=va_model.cohort.name,
8587
)

src/anyvlm/utils/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class AncillaryResults(BaseModel):
99
homozygotes: int
1010
heterozygotes: int
1111
hemizygotes: int
12-
consequence: str
1312

1413

1514
class QualityMeasures(BaseModel):

tests/integration/functions/test_get_caf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def alleles_to_add(alleles: dict):
2121
return [
2222
value["variation"]
2323
for value in alleles.values()
24-
if value["location"]["sequenceReference"]["refgetAccession"] == REFGET_AC
24+
if value["variation"]["location"]["sequenceReference"]["refgetAccession"]
25+
== REFGET_AC
2526
]
2627

2728

0 commit comments

Comments
 (0)