[med-svn] [Git][med-team/cyvcf2][master] Fix phasing reported for haploid genotypes (libhts >= 1.22)
Andreas Tille (@tille)
gitlab at salsa.debian.org
Mon Sep 21 10:19:53 BST 2026
Andreas Tille pushed to branch master at Debian Med / cyvcf2
Commits:
61c0b784 by Andreas Tille at 2026-09-21T11:16:50+02:00
Fix phasing reported for haploid genotypes (libhts >= 1.22)
Read the genotype phase from the sample's last allele slot instead of
the second one, which is wrong for ploidy-1 records. Fixes the failing
test_genotypes test with libhts 1.24.
- - - - -
2 changed files:
- + debian/patches/fix-haploid-genotype-phasing.patch
- debian/patches/series
Changes:
=====================================
debian/patches/fix-haploid-genotype-phasing.patch
=====================================
@@ -0,0 +1,40 @@
+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 <tille at debian.org>
+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
=====================================
debian/patches/series
=====================================
@@ -1,2 +1,3 @@
#add_htslib_link_dependency.patch
i386.patch
+fix-haploid-genotype-phasing.patch
View it on GitLab: https://salsa.debian.org/med-team/cyvcf2/-/commit/61c0b7842a90a27ae99e295ba89edf8b86122d55
--
View it on GitLab: https://salsa.debian.org/med-team/cyvcf2/-/commit/61c0b7842a90a27ae99e295ba89edf8b86122d55
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20260921/dbbb3731/attachment-0001.htm>
More information about the debian-med-commit
mailing list