Skip to content

Commit 07c98db

Browse files
committed
Rework HWE inputs
1 parent 6160f06 commit 07c98db

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

sgkit/stats/hwe.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def hardy_weinberg_test(
129129
genotype_counts: Optional[Hashable] = None,
130130
call_genotype: Hashable = variables.call_genotype,
131131
call_genotype_mask: Hashable = variables.call_genotype_mask,
132-
merge: bool = True,
132+
ploidy: Optional[int] = None,
133+
alleles: Optional[int] = None,
134+
merge: bool = True
133135
) -> Dataset:
134136
"""Exact test for HWE as described in Wigginton et al. 2005 [1].
135137
@@ -150,6 +152,12 @@ def hardy_weinberg_test(
150152
call_genotype_mask
151153
Input variable name holding call_genotype_mask.
152154
Defined by :data:`sgkit.variables.call_genotype_mask_spec`
155+
ploidy
156+
Genotype ploidy, defaults to ``ploidy`` dimension of genotype
157+
call array (:data:`sgkit.variables.call_genotype_spec`) if present.
158+
If that variable is not present, then this value must be set.
159+
Currently HWE calculations are only supported for diploid datasets,
160+
i.e. ``ploidy`` must equal 2.
153161
merge
154162
If True (the default), merge the input dataset and the computed
155163
output variables into a single dataset, otherwise return only
@@ -179,7 +187,12 @@ def hardy_weinberg_test(
179187
NotImplementedError
180188
If maximum number of alleles in provided dataset != 2
181189
"""
182-
if ds.dims["ploidy"] != 2:
190+
ploidy = ploidy or ds.dims.get("ploidy")
191+
if not ploidy:
192+
raise ValueError(
193+
"`ploidy` parameter must be set when not present as array dimension."
194+
)
195+
if ploidy != 2:
183196
raise NotImplementedError("HWE test only implemented for diploid genotypes")
184197
if ds.dims["alleles"] != 2:
185198
raise NotImplementedError("HWE test only implemented for biallelic genotypes")

0 commit comments

Comments
 (0)