Open
Conversation
…'t have to add a dimension at the end for scalar operations
… fix norm func for r2_ij
…lematic in practice
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3426 +/- ##
==========================================
- Coverage 91.92% 91.79% -0.13%
==========================================
Files 37 37
Lines 32153 32352 +199
Branches 5143 5144 +1
==========================================
+ Hits 29556 29699 +143
- Misses 2264 2320 +56
Partials 333 333
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
lkirk
commented
Mar 10, 2026
| PyObject *summary_func; | ||
| PyObject *norm_func; | ||
| } two_locus_general_stat_params; | ||
|
|
Contributor
Author
There was a problem hiding this comment.
I see that the CPython code coverage is split from the rest of the python tests. I can't test this directly without a small multiallelic test case in test_python_c.py.
| out: | ||
| return ret; | ||
| } | ||
|
|
Contributor
Author
There was a problem hiding this comment.
This function now serves as an inner wrapper. The the general stat accepts the summary function params so that the CPython code can pass them directly. All of the specialized stats functions call this function.
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.
Description
This is the last of the required components for the LD matrix methods. I wanted feedback on the API before I add documentation, but this method is complete and tested. The final things to do are to leak check the cpython code and add some documentation.
This feature enables a user to implement their own two-locus count statistic in python, similar to
ts.sample_count_stat. User functions take two arguments, the first is a matrix of haplotype counts and the second is a vector of sample set sizes. For instance, this is how we would implementDwith this api:Since this API supports multiallelic sites, the user can also pass a normalisation function to control how the data is normalised across multiple alleles. The normalisation function is only run when computing over multiallelic sites. I've set the default to be$1/(n_A n_B)$ , which is simply the arithmetic mean of the alleles in a given pair of sites. This will suffice in the majority of cases (the only outlier is $r^2$ , for which there is already a python API). We also support computing statistics between sample sets.
The user would use the above summary function like this:
Where
1specifies the length of the output array, we always require 1 dimension -- same as thets.sample_count_statfunction.PR Checklist: