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:
|
| PyObject *summary_func; | ||
| PyObject *norm_func; | ||
| } two_locus_general_stat_params; | ||
|
|
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; | ||
| } | ||
|
|
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.
|
Thank you for opening this, @lkirk. I'm excited to see this implemented! Do we need to do any testing to demonstrate that there are no memory leaks or anything like that, which wouldn't be included in the test suite? I know it could be found in the tests, but it may be helpful to spell out here how the API would work for a two- or more-way stat? Would it be: |
|
Yes, this needs leak checking and documentation, which I can add. I mostly wanted to make sure the user interface made sense first.
The
|
|
Hi, @lkirk! This looks pretty straightforward. To have a careful opinion about the API, I think I need to see a reasonably careful docstring? For instance, what exactly are the arguments to |
| [ | ||
| ( | ||
| ts := [ | ||
| p for p in get_example_tree_sequences() if p.id == "n=100_m=32_rho=0.5" |
There was a problem hiding this comment.
Does this runs the risk of not being run at all if there is no such example tree sequence?
| ], | ||
| ) | ||
| def test_general_one_way_two_locus_stat_multiallelic(stat): | ||
| (ts,) = {t.id: t for t in get_example_tree_sequences()}["all_fields"].values |
There was a problem hiding this comment.
insert some things like assert ts.num_sites > 0 and probably something asserting that this one is actually multiallelic here
| (ts, "pi2_unbiased"), | ||
| ], | ||
| ) | ||
| def test_general_two_locus_site_stat(ts, stat): |
There was a problem hiding this comment.
I think insert some asserts here that ts has the required properties for being a good test.
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: