Fix minor inconsistency in ancestor inference algorithm - #1194
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Duncan-JR
marked this pull request as draft
September 8, 2026 08:09
Member
|
Well spotted. I agree that we don't need to backport this. |
Duncan-JR
force-pushed
the
fix_anc_gen
branch
from
September 8, 2026 09:49
ea9e0cb to
dcd7e98
Compare
Duncan-JR
marked this pull request as ready for review
September 8, 2026 09:53
Duncan-JR
force-pushed
the
fix_anc_gen
branch
from
September 8, 2026 09:58
dcd7e98 to
0bd9107
Compare
Contributor
Author
Great. It's ready for review: I also updated the Python testing code to use the same control flow. |
jeromekelleher
approved these changes
Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.1PYPI 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.