Skip to content

Support multiple alleles and mutations per site - #1200

Merged
jeromekelleher merged 3 commits into
tskit-dev:mainfrom
jeromekelleher:hmm-multi-alleles
Oct 16, 2026
Merged

jeromekelleher merged 3 commits into
tskit-dev:mainfrom
jeromekelleher:hmm-multi-alleles

Conversation

@jeromekelleher

Copy link
Copy Markdown
Member

Closes #1186

Port the multi-allele support from the tsls copy of the HMM engine.
matcher_indexes_alloc now takes optional per-site ancestral state and
per-mutation derived state arrays (defaulting to 0 and 1), and sites
may carry multiple mutations, with later mutations in tskit order
taking precedence. The Python MatcherIndexes wrapper gains an alleles
argument that encodes states via the new encode_alleles function.
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.64%. Comparing base (53d7363) to head (664d4ee).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1200      +/-   ##
==========================================
+ Coverage   91.55%   91.64%   +0.09%     
==========================================
  Files          16       16              
  Lines        4651     4716      +65     
  Branches      740      751      +11     
==========================================
+ Hits         4258     4322      +64     
+ Misses        281      280       -1     
- Partials      112      114       +2     
Flag Coverage Δ
C 82.61% <92.85%> (+0.24%) ⬆️
c-python 72.72% <93.47%> (+0.99%) ⬆️
python-tests 92.05% <97.72%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Python API 92.15% <97.72%> (+0.05%) ⬆️
Python C interface 89.82% <93.75%> (+0.21%) ⬆️
C library 91.15% <100.00%> (+0.16%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Matcher now takes the AlleleMapper and encodes each mutation's derived
state in the reference tree sequence to its per-site allele code, so the
HMM sees the correct allele for multiallelic sites and for back
mutations to the ancestral state. Previously every mutation was treated
as derived state 1.

Genotype roundtrip checks now include multiallelic inference sites, with
new JC69 simulations including samples matched in two groups.
infer_ancestors previously collapsed all derived alleles to code 1, so
ancestors at multiallelic sites represented "not ancestral" and were
labelled with the first derived allele, and sites whose ancestral
allele was absent from the data were silently dropped. It now raises a
ValueError naming the site when any ancestor-source genotype is not 0,
1 or missing. Sites with an unknown ancestral allele are skipped with a
log message.

Multiallelic data remains supported at the matching stage, where
samples not used for ancestor generation can carry other alleles. Tests
cover the error cases and these matching scenarios (separate sources,
sample subsets of one store, simulated data); simulation helpers now
default to biallelic mutations.
@jeromekelleher
jeromekelleher merged commit cb5017e into tskit-dev:main Oct 16, 2026
13 checks passed
@jeromekelleher
jeromekelleher deleted the hmm-multi-alleles branch October 16, 2026 12:44
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.

Reimplement support for sites with multiple mutations

1 participant