Skip to content

Restrict FrequencySpectrum to biallelic sites instead of pooling multiallelic ones - #451

Open
nspope wants to merge 2 commits into
mainfrom
fix/372-fs-reference-absent-biallelic-2
Open

nspope wants to merge 2 commits into
mainfrom
fix/372-fs-reference-absent-biallelic-2

Conversation

@nspope

@nspope nspope commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Closes #372

A multiallelic (3+ extant allele) site is now dropped from FrequencySpectrum, with a BiallelicOnlyWarning giving the count, the same way patterson_d and the GenotypeMatrix loaders already handle multiallelic sites, rather than being folded into the spectrum and approximated. On the sites it keeps -- including a reference-absent two-allele site, where allele 0 itself does not appear in the sample -- every estimator now matches the scalar functions exactly; pi and watterson used to double-count such a site's two present alleles as if both were derived relative to a reference that was not there.

The rationale is that Achaz's variance framework, for which FrequencySpectrum is the vehicle, assumes infinite sites and thus biallelic data. Docs are edited to make the restriction clear.

…g pi on multiallelic ones

A multiallelic (3+-allele) site is now dropped from FrequencySpectrum,
with a BiallelicOnlyWarning giving the count, the same way patterson_d
and the GenotypeMatrix loaders already handle multiallelic sites,
rather than being folded into the spectrum and approximated. On the
sites it keeps -- including a reference-absent two-allele site, where
allele 0 itself does not appear in the sample -- every estimator now
matches the scalar functions exactly; pi and watterson used to
double-count such a site's two present alleles as if both were derived
relative to a reference that was not there. Docs are edited
to make the restriction clear.
… count

Both used sfs_by_n, the uncollapsed per-allele histogram, which counts
a reference-absent two-allele site twice (once per nonzero allele
column). suggest_projection_n divided that inflated cumulative by
n_segregating, which is collapsed-based, so it could reach
retain_fraction too early and suggest a target_n that drops more real
data than asked for. project()'s dropped count (used only in its
warning message) had the same mismatch against its own
collapsed-based n_segregating. Both now read _sfs_by_n_collapsed.
@nspope
nspope force-pushed the fix/372-fs-reference-absent-biallelic-2 branch from c329139 to 7aefefb Compare November 20, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FrequencySpectrum pi and Watterson are 2x the scalar at a two-allele site without the reference allele

1 participant