From 5a3d046cc9e47ea5b6ae3dd980a8d9ad63a77623 Mon Sep 17 00:00:00 2001 From: Brent Pedersen Date: Tue, 15 Mar 2022 11:08:36 +0100 Subject: [PATCH] closes #236 --- CHANGES.md | 3 +++ cyvcf2/__init__.py | 2 +- cyvcf2/cyvcf2.pyx | 4 ++-- cyvcf2/tests/test_reader.py | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a0415cb..a600215 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +# v0.30.15 ++ fix num_unknown when gts012=True (#236) + # v0.30.14 + use warnings instead of sys.stderr (#229 from @grahamgower) + use libdeflate in wheel build (#231 from @grahamgower) diff --git a/cyvcf2/__init__.py b/cyvcf2/__init__.py index 497aa08..2f0119d 100644 --- a/cyvcf2/__init__.py +++ b/cyvcf2/__init__.py @@ -2,4 +2,4 @@ par_het) Reader = VCFReader = VCF -__version__ = "0.30.14" +__version__ = "0.30.15" diff --git a/cyvcf2/cyvcf2.pyx b/cyvcf2/cyvcf2.pyx index 9baa6bf..ba49a38 100644 --- a/cyvcf2/cyvcf2.pyx +++ b/cyvcf2/cyvcf2.pyx @@ -1274,9 +1274,9 @@ cdef class Variant(object): if self._gt_types == NULL: self.gt_types cdef int n = 0, i = 0 + cdef int unknown = 3 if self.vcf.gts012 else 2 for i in range(self.vcf.n_samples): - if self._gt_types[i] == 2: - n+=1 + n += (self._gt_types[i] == unknown) return n property FORMAT: diff --git a/cyvcf2/tests/test_reader.py b/cyvcf2/tests/test_reader.py index 3d8e81e..8d41af7 100644 --- a/cyvcf2/tests/test_reader.py +++ b/cyvcf2/tests/test_reader.py @@ -1302,3 +1302,17 @@ def test_genotypes(): a = v.genotype.array()[0] # only 0'th item print("i:", i, " a:", v.genotype.array()[0], " exp:", exp_array[i]) assert (a == exp_array[i]).all(), " error with array" + +def test_issue236(): + + + for strict_gt in (False, True): + res = [[], []] + + for gts in (False, True): + vcf = VCF(os.path.join(HERE, "test-genotypes.vcf"), gts012=gts, strict_gt=strict_gt) + for v in vcf: + res[int(gts)].append(v.num_unknown) + + assert res[0] == res[1] + assert len(res[0]) > 0