Skip to content

Commit aad51dc

Browse files
committed
add cohort
1 parent 1f45c1b commit aad51dc

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

src/anyvlm/storage/base_storage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class StorageError(Exception):
99
"""Base AnyLM storage error."""
1010

1111

12+
class IncompleteVAObjectError(StorageError):
13+
"""Raise if provided VA object is missing fully-materialized properties required for storage"""
14+
15+
1216
class Storage(ABC):
1317
"""Abstract base class for interacting with storage backends."""
1418

src/anyvlm/storage/mapper_registry.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ def from_db_entity(self, db_entity): # noqa: ANN201, ANN001
3434
mapper = self.get_mapper(type(db_entity))
3535
return mapper.from_db_entity(db_entity)
3636

37-
def to_db_entity(self, anyvlm_entity) -> orm.Base: # noqa: ANN001
37+
def to_db_entity(self, va_model) -> orm.Base: # noqa: ANN001
3838
"""Convert any VA-Spec model to its corresponding DB entity."""
39-
db_type = self.va_model_to_db_mapping.get(type(anyvlm_entity))
39+
db_type = self.va_model_to_db_mapping.get(type(va_model))
4040
if db_type is None:
41-
raise ValueError(
42-
f"No DB entity type mapped for VRS model: {type(anyvlm_entity)}"
43-
)
41+
raise ValueError(f"No DB entity type mapped for VA model: {type(va_model)}")
4442

4543
mapper = self.get_mapper(db_type)
46-
return mapper.to_db_entity(anyvlm_entity)
44+
return mapper.to_db_entity(va_model)
4745

4846

4947
# Global registry instance

src/anyvlm/storage/mappers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def to_db_entity(self, va_model: V) -> D:
2424
"""Convert VA-Spec model to DB entity."""
2525

2626

27-
class AlleleFrequencyMapper(BaseMapper):
27+
class AlleleFrequencyMapper(
28+
BaseMapper[CohortAlleleFrequencyStudyResult, orm.AlleleFrequencyData]
29+
):
2830
"""Maps between Allele Frequency Entities"""
2931

3032
def from_db_entity(
@@ -53,7 +55,7 @@ def from_db_entity(
5355
"heterozygotes": heterozygotes,
5456
"hemizygotes": hemizygotes,
5557
},
56-
cohort=StudyGroup(name="rare disease"),
58+
cohort=StudyGroup(name=db_entity.cohort),
5759
)
5860

5961
def to_db_entity(
@@ -79,4 +81,5 @@ def to_db_entity(
7981
ac_hom=ancillary_results["homozygotes"],
8082
ac_hemi=ancillary_results["hemizygotes"],
8183
filter=va_model.qualityMeasures["qcFilters"],
84+
cohort=va_model.cohort.name,
8285
)

src/anyvlm/storage/orm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __tablename__(self) -> str:
4141
return "allele_frequency_data"
4242

4343
vrs_id: Mapped[str] = mapped_column(String, primary_key=True)
44+
cohort: Mapped[str] = mapped_column(String, index=True)
4445
an: Mapped[int] = mapped_column(Integer)
4546
ac_het: Mapped[int] = mapped_column(Integer)
4647
ac_hom: Mapped[int] = mapped_column(Integer)

tests/unit/storage/test_postgres_unit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def insert_and_verify_one_row():
4040
db_record = rows[0]
4141

4242
assert db_record.vrs_id == "ga4gh:VA.J3Hi64dkKFKdnKIwB2419Qz3STDB2sJq"
43+
assert db_record.cohort == "rare disease"
4344
assert db_record.an == 6164
4445
assert db_record.ac_het == 1
4546
assert db_record.ac_hom == 0

0 commit comments

Comments
 (0)