Repository navigation
Description
Two things from the plan on #439 were left out of the two PRs that implemented it (#448 and #449). Recording them here so they are not lost when #439 closes.
1. An option to keep sites with no known ancestral allele
Today a recode (ancestral= on the loaders, or HaplotypeMatrix.polarize) drops every site whose ancestral allele is unknown and emits an UnknownAncestralWarning with the count. The accessible mask and the span stay as they were.
That is the right default for the derived-state statistics, but it costs something for everything else. A site with unknown ancestral state is still a perfectly good site for pi, FST or the folded SFS, and dropping it lowers per-base values by about the share of sites dropped (the warning says so). On some data that share is large.
What a "keep" option needs:
- A per-site record on the matrix of which sites are polarized, carried through subsets the way the accessible mask index is.
- The derived-state statistics skip the unmarked sites; everything else uses all of them. That touches the scalar functions, the scatter and fused kernels, and the streaming paths, so it is a real piece of work and not a flag.
- A rule for the denominators: a per-base
theta_hover the polarized sites should divide by the bases that could have been polarized, not by all accessible bases. - A decision on what
polarizedmeans for such a matrix. Probably: the flag staysTrueand the per-site record says where.
A cheaper intermediate, if the full version is too much: let the caller ask for the dropped sites to come off the accessible mask as well, so per-base statistics on the polarized matrix are at least self-consistent.
2. A polarized flag on GenotypeMatrix
HaplotypeMatrix and its stream now carry polarized, and the derived-state statistics warn without it. GenotypeMatrix has no such flag, and its loaders do not take ancestral=.
One genotype statistic reads the derived state: daf_histogram on a GenotypeMatrix counts the allele that the dosage counts, with no warning. I did not find another, but I only looked at what the swap experiment in tests/test_unpolarized_warning.py reaches, and that experiment runs on haplotype matrices.
What it needs:
ancestral=onGenotypeMatrix.from_vcfandfrom_zarr. The recode has to happen on the raw(n_variants, n_samples, ploidy)block before the dosage count, with the sameswap_ancestralkernel; flipping to2 - dosageafterwards is only right at biallelic sites. Note that the dosage counts the highest present allele above 0, so check what a recoded site with no copy of code 0 gives.- The flag on
GenotypeMatrixandStreamingGenotypeMatrix, kept through subsets, saved byto_zarr, and carried byGenotypeMatrix.from_haplotype_matrix(which today drops it;to_haplotype_matrixgivesFalse). - The same swap experiment on genotype matrices, to find every statistic that should warn rather than trusting the one I know about.
Smaller items in the same area
from_vcfreads at most three ALT alleles per site (the reader's default), so a fourth or later ALT as the ancestral state counts as unknown.- Per-allele fields other than
allele(AC,AF) are not reordered by a recode. - A handful of statistics depend on code 0 only at sites with three or more alleles and do not warn (
mu_sfs,eta1_star,minus_eta1_star,FrequencySpectrumwith thepiweight). The docs name them; whether they should warn is open. - The windowed
local_pca_jackknifevalues differed between the two multiallelic test matrices in that experiment while plainlocal_pcadid not. Not explained yet.
Activity