Description: Fix phasing reported for haploid genotypes The phase of a genotype is read from the second allele slot of the sample, which is wrong for haploid (ploidy-1) records where that slot actually holds the next sample's first allele. Read the phase from the sample's own last allele instead. This matters since htslib >= 1.22 treats haploid genotypes as implicitly phased, so the wrong slot now carries a set phase bit where it used to be clear. Forwarded: no Author: Andreas Tille Last-Update: 2026-09-21 --- a/cyvcf2/cyvcf2.pyx +++ b/cyvcf2/cyvcf2.pyx @@ -1221,7 +1221,7 @@ cdef class Genotypes(object): """ a boolean indicating that the ith sample is phased. """ - return (self._raw[i * self.ploidy + 1] & 1) == 1 + return (self._raw[i * self.ploidy + self.ploidy - 1] & 1) == 1 def alleles(self, int i): cdef list result = [] @@ -1259,7 +1259,7 @@ cdef class Genotypes(object): to_return[ind, allele] = fill else: to_return[ind, allele] = (raw >> 1) - 1 - to_return[ind, self.ploidy] = (self._raw[ind * self.ploidy + 1] & 1) == 1 + to_return[ind, self.ploidy] = (self._raw[ind * self.ploidy + self.ploidy - 1] & 1) == 1 return to_return @@ -1603,7 +1603,7 @@ cdef class Variant(object): break self._genotypes[i].append(bcf_gt_allele(gts[k + j])) self._genotypes[i].append( - bool(bcf_gt_is_phased(gts[k+1 if k+1 < ndst else k]))) + bool(bcf_gt_is_phased(gts[k + nret - 1]))) stdlib.free(gts) return self._genotypes