Fix genetic_relatedness to allow single sample set with self-comparisons #3235
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.
Description
This PR fixes issue #3055 where
genetic_relatedness
would fail when computing self-comparisons with a single sample set. As @petrelharp pointed out there is no reason this shouldn't be allowed for certain statistics, includinggenetic_relatedness
The Problem
Previously, calling
genetic_relatedness
with a single sample set and indexes referring to that set would raise an error:This occurred because the underlying C API validates that at least k=2 sample sets are provided for k-way statistics, even when the indexes only reference a subset of those sets.
This PR
The fix adds an
allow_self_comparisons
parameter to the internal__k_way_sample_set_stat
method, which is only set toTrue
forgenetic_relatedness
. When enabled:This ensures that:
genetic_relatedness
behavior is changedFurther, this PR sets the stage for allowing for other appropriate k-way stats to be computed with self comparisons by setting a flag.
Testing
Added comprehensive tests for all three computation modes (site, branch, node) to verify:
All existing tests continue to pass, but @petrelharp this would benefit from you specifically looking over what I've done to be sure you're okay with the way I've implemented
allow_self_comparisons
Fixes #3055
PR Checklist:
I'm not sure if I should touch the changelogs here?