@@ -283,16 +283,19 @@ def counts(self) -> typing.Counter[str | None]:
283283 possible :attr:`allele <Variant.alleles>` at this site: i.e. the number of
284284 samples possessing that allele among the set of samples specified when creating
285285 this Variant (by default, this is all the sample nodes in the tree sequence).
286- Missing data is represented by an allelic state of ``None``.
286+ Missing data is represented by an allelic state of ``None``. The order of
287+ alleles in the Counter is the same as the order of alleles in the
288+ :attr:`alleles <Variant.alleles>` tuple.
287289
288290 :return: A counter of the number of samples associated with each allele.
289291 """
290292 counts = collections .Counter ()
291293 if self .alleles [- 1 ] is None :
292294 # we have to treat the last element of the genotypes array as special
293- counts [None ] = np .sum (self .genotypes == tskit .MISSING_DATA )
294295 for i , allele in enumerate (self .alleles [:- 1 ]):
295296 counts [allele ] = np .sum (self .genotypes == i )
297+ # Add the count of missing data as the last item
298+ counts [None ] = np .sum (self .genotypes == tskit .MISSING_DATA )
296299 else :
297300 bincounts = np .bincount (self .genotypes , minlength = self .num_alleles )
298301 for i , allele in enumerate (self .alleles ):
@@ -308,6 +311,8 @@ def frequencies(self, remove_missing=None) -> dict[str, float]:
308311 sample nodes in the tree sequence). Note, therefore, that if a restricted set
309312 of samples was specified on creation, the allele frequencies returned here
310313 will *not* be the global allele frequencies in the whole tree sequence.
314+ The order of alleles in the returned dictionary is the same as the order
315+ of alleles in the :attr:`alleles <Variant.alleles>` tuple.
311316
312317 :param bool remove_missing: If True, only samples with non-missing data will
313318 be counted in the total number of samples used to calculate the frequency,
0 commit comments