Skip to content

Commit 7c76e12

Browse files
committed
update is_non_additive check to support mixed column types
1 parent c7da8bd commit 7c76e12

File tree

1 file changed

+10
-8
lines changed
  • pgscatalog.core/src/pgscatalog/core/lib

1 file changed

+10
-8
lines changed

pgscatalog.core/src/pgscatalog/core/lib/models.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,15 @@ def is_complex(self) -> bool:
302302
@computed_field
303303
@cached_property
304304
def is_non_additive(self) -> bool:
305-
# simple check: do any of the weight dosage columns have data?
306-
for x in self.non_additive_columns:
307-
if getattr(self, x) is not None:
308-
return True
309-
return False
305+
if self.effect_weight is not None:
306+
# if there's an effect weight value, we can work with it
307+
non_additive = False
308+
else:
309+
# dosage columns are trickier
310+
non_additive = any(
311+
getattr(self, col) is not None for col in self.non_additive_columns
312+
)
313+
return non_additive
310314

311315
@computed_field
312316
@cached_property
@@ -355,8 +359,6 @@ def check_effect_weights(self) -> Self:
355359
):
356360
case None, None, None, None:
357361
raise ValueError("All effect weight fields are missing")
358-
case str(), str(), str(), str():
359-
raise ValueError("Additive and non-additive fields are present")
360362
case None, zero, one, two if any(x is None for x in (zero, one, two)):
361363
raise ValueError("Dosage missing effect weight")
362364
case _:
@@ -417,7 +419,7 @@ class ScoreVariant(CatalogScoreVariant):
417419
>>> harmonised_variant.is_harmonised
418420
True
419421
420-
>>> variant_nonadditive = ScoreVariant(**{"rsID": None, "chr_name": "1", "chr_position": 1, "effect_allele": "A", "effect_weight": 0.5, "dosage_0_weight": 0, "dosage_1_weight": 1, "row_nr": 0, "accession": "test"})
422+
>>> variant_nonadditive = ScoreVariant(**{"rsID": None, "chr_name": "1", "chr_position": 1, "effect_allele": "A", "dosage_0_weight": 0, "dosage_1_weight": 1, "dosage_2_weight": 0, "row_nr": 0, "accession": "test"})
421423
>>> variant_nonadditive.is_non_additive
422424
True
423425
>>> variant_nonadditive.is_complex

0 commit comments

Comments
 (0)