Skip to content

Fix minor inconsistency in ancestor inference algorithm - #1194

Merged
jeromekelleher merged 1 commit into
tskit-dev:mainfrom
Duncan-JR:fix_anc_gen
Sep 8, 2026
Merged

jeromekelleher merged 1 commit into
tskit-dev:mainfrom
Duncan-JR:fix_anc_gen

Conversation

@Duncan-JR

Copy link
Copy Markdown
Contributor

I recently noticed a minor issue with the changes I made to the ancestor inference algorithm in #1012. When extending the ancestral haplotype we iterate over the inference sites and do four things:

  1. Fill in the ancestral haplotype using the consensus.
  2. Remove samples from the sample set if they don't match consensus at this site AND were marked for removal at the previous informative site.
  3. Mark samples for removal if the site is informative (see below) and they disagree with consensus.
  4. Repack the sample set.

Prior to my change, all four steps only happened at sites older than the focal site with at least one non-missing allele. My change makes Step 3 happen on a wider set of informative sites (where derived_count > ones). However, I inadvertently made Steps 2 and 4 happen at every inference site, when they should logically happen under the same conditions of Step 3.

My oversight may have a slight computational cost but I don't think it harms the correctness of the algorithm, because the disagree flags are set and reset at the correct sites. The effect it has is subtle - instead of only removing a sample if it disagrees with the consensus at two consecutive informative sites, it may sometimes arbtirarily get removed after only one informative site disagreement.

This PR reorganises the control flow to ensure the Steps 2 and 4 happen only at informative, non-missing sites. I tested the effect of the change with my ancestor validation pipeline, using a stdpopsim Out-of-Africa simulation of 3000 individuals over 10 mbp with simulated genotype errors. Only 8,820 (3.1%) of the 285,552 ancestors had differed in span due to the changes; these affected ancestors were an average of 16 kbp longer in the PR branch.

This issue also effects the 0.5.1 PYPI release too but I don't think it warrants a hotfix, since it is highly unlikely to have any noticeable effect in inference results or computation time. My vote is to just incorporate into the 1.0 release.

@codecov

codecov Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.57%. Comparing base (9242074) to head (0bd9107).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1194      +/-   ##
==========================================
+ Coverage   91.50%   91.57%   +0.06%     
==========================================
  Files          16       16              
  Lines        4650     4651       +1     
  Branches      739      740       +1     
==========================================
+ Hits         4255     4259       +4     
+ Misses        285      281       -4     
- Partials      110      111       +1     
Flag Coverage Δ
C 82.36% <89.47%> (+0.68%) ⬆️
c-python 71.73% <84.21%> (+0.01%) ⬆️
python-tests 91.99% <ø> (ø)

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

Components Coverage Δ
Python API 92.13% <ø> (ø)
Python C interface 89.60% <ø> (ø)
C library 90.99% <94.73%> (+0.23%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Duncan-JR
Duncan-JR marked this pull request as draft September 8, 2026 08:09
@jeromekelleher

Copy link
Copy Markdown
Member

Well spotted. I agree that we don't need to backport this.

@Duncan-JR
Duncan-JR marked this pull request as ready for review September 8, 2026 09:53
@Duncan-JR

Copy link
Copy Markdown
Contributor Author

Well spotted. I agree that we don't need to backport this.

Great. It's ready for review: I also updated the Python testing code to use the same control flow.

@jeromekelleher
jeromekelleher added this pull request to the merge queue Sep 8, 2026
Merged via the queue into tskit-dev:main with commit 53d7363 Sep 8, 2026
13 checks passed
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.

2 participants