Debian Codegraph @

debian/patches/fix-haploid-genotype-phasing.patch

raw
1 Description: Fix phasing reported for haploid genotypes
2 The phase of a genotype is read from the second allele slot of the
3 sample, which is wrong for haploid (ploidy-1) records where that slot
4 actually holds the next sample's first allele. Read the phase from the
5 sample's own last allele instead. This matters since htslib >= 1.22
6 treats haploid genotypes as implicitly phased, so the wrong slot now
7 carries a set phase bit where it used to be clear.
8 Forwarded: no
9 Author: Andreas Tille <[email protected]>
10 Last-Update: 2026-09-21
11
12 --- a/cyvcf2/cyvcf2.pyx
13 +++ b/cyvcf2/cyvcf2.pyx
14 @@ -1221,7 +1221,7 @@ cdef class Genotypes(object):
15 """
16 a boolean indicating that the ith sample is phased.
17 """
18 - return (self._raw[i * self.ploidy + 1] & 1) == 1
19 + return (self._raw[i * self.ploidy + self.ploidy - 1] & 1) == 1
20
21 def alleles(self, int i):
22 cdef list result = []
23 @@ -1259,7 +1259,7 @@ cdef class Genotypes(object):
24 to_return[ind, allele] = fill
25 else:
26 to_return[ind, allele] = (raw >> 1) - 1
27 - to_return[ind, self.ploidy] = (self._raw[ind * self.ploidy + 1] & 1) == 1
28 + to_return[ind, self.ploidy] = (self._raw[ind * self.ploidy + self.ploidy - 1] & 1) == 1
29
30 return to_return
31
32 @@ -1603,7 +1603,7 @@ cdef class Variant(object):
33 break
34 self._genotypes[i].append(bcf_gt_allele(gts[k + j]))
35 self._genotypes[i].append(
36 - bool(bcf_gt_is_phased(gts[k+1 if k+1 < ndst else k])))
37 + bool(bcf_gt_is_phased(gts[k + nret - 1])))
38
39 stdlib.free(gts)
40 return self._genotypes