@@ -129,7 +129,9 @@ def hardy_weinberg_test(
129
129
genotype_counts : Optional [Hashable ] = None ,
130
130
call_genotype : Hashable = variables .call_genotype ,
131
131
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
133
135
) -> Dataset :
134
136
"""Exact test for HWE as described in Wigginton et al. 2005 [1].
135
137
@@ -150,6 +152,12 @@ def hardy_weinberg_test(
150
152
call_genotype_mask
151
153
Input variable name holding call_genotype_mask.
152
154
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.
153
161
merge
154
162
If True (the default), merge the input dataset and the computed
155
163
output variables into a single dataset, otherwise return only
@@ -179,7 +187,12 @@ def hardy_weinberg_test(
179
187
NotImplementedError
180
188
If maximum number of alleles in provided dataset != 2
181
189
"""
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 :
183
196
raise NotImplementedError ("HWE test only implemented for diploid genotypes" )
184
197
if ds .dims ["alleles" ] != 2 :
185
198
raise NotImplementedError ("HWE test only implemented for biallelic genotypes" )
0 commit comments