-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time windows in statistics #2948
Draft
petrelharp
wants to merge
19
commits into
tskit-dev:main
Choose a base branch
from
petrelharp:time_windows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
aeda4dc
example test for time windows
petrelharp 0a30696
a little more flailing at beginning tests
petrelharp 1a988c0
first simple test for AFS in branch mode with time windows
tforest 18ffda0
AFS non-naive version with time windows + Some tests
tforest c6f9562
Improve AFS branch mode
tforest 7a3149f
fix AFS tests
tforest 71da7ad
Fix naive branch general stat
tforest 2a44909
intermediate changes to C AFS implementation with time windows
tforest 4460db9
tw afs C implementation
tforest bbec6a9
Better dimension drop with time windows
tforest da5f205
AFS branch mode with time windows to review
tforest 6b3ab4f
Adapting some tests with new time_windows parameter
tforest f2d857b
time_windows addition after code rebase
tforest b8f4ba5
Fix some tests failing because of time_windows
tforest c9f6c06
Remove unused parameters in afs function
tforest 59ea266
Fixing a memory issue in tsk_treeseq_update_branch_afs
tforest 96ac0ce
Fixing some time_windows issues with AFS
tforest 26a7f09
Adjusting some stats tests using time_windows
tforest 8a8c05b
Adjusting some tests trying to pass codecov
tforest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
*/ | ||
|
||
#include "testlib.h" | ||
#include <math.h> | ||
#include <tskit/stats.h> | ||
|
||
#include <unistd.h> | ||
|
@@ -865,6 +866,84 @@ verify_one_way_stat_func_errors(tsk_treeseq_t *ts, one_way_sample_stat_method *m | |
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_WINDOWS); | ||
} | ||
|
||
// Temporary definition for time_windows in tsk_treeseq_allele_frequency_spectrum | ||
typedef int one_way_sample_stat_method_tw(const tsk_treeseq_t *self, | ||
tsk_size_t num_sample_sets, const tsk_size_t *sample_set_sizes, | ||
const tsk_id_t *sample_sets, tsk_size_t num_windows, const double *windows, | ||
tsk_size_t num_time_windows, const double *time_windows, tsk_flags_t options, | ||
double *result); | ||
|
||
// Temporary duplicate for time-windows-having methods | ||
static void | ||
verify_one_way_stat_func_errors_tw( | ||
tsk_treeseq_t *ts, one_way_sample_stat_method_tw *method) | ||
{ | ||
int ret; | ||
tsk_id_t num_nodes = (tsk_id_t) tsk_treeseq_get_num_nodes(ts); | ||
tsk_id_t samples[] = { 0, 1, 2, 3 }; | ||
tsk_size_t sample_set_sizes = 4; | ||
double windows[] = { 0, 0, 0 }; | ||
double time_windows[] = { -1, 0.5, INFINITY }; | ||
double result; | ||
|
||
ret = method(ts, 0, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_INSUFFICIENT_SAMPLE_SETS); | ||
|
||
samples[0] = TSK_NULL; | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_NODE_OUT_OF_BOUNDS); | ||
samples[0] = -10; | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_NODE_OUT_OF_BOUNDS); | ||
samples[0] = num_nodes; | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_NODE_OUT_OF_BOUNDS); | ||
samples[0] = num_nodes + 1; | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_NODE_OUT_OF_BOUNDS); | ||
|
||
samples[0] = num_nodes - 1; | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_SAMPLES); | ||
|
||
samples[0] = 1; | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_DUPLICATE_SAMPLE); | ||
|
||
samples[0] = 0; | ||
sample_set_sizes = 0; | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, NULL, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_EMPTY_SAMPLE_SET); | ||
|
||
sample_set_sizes = 4; | ||
/* Window errors */ | ||
ret = method(ts, 1, &sample_set_sizes, samples, 0, windows, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_NUM_WINDOWS); | ||
|
||
ret = method(ts, 1, &sample_set_sizes, samples, 2, windows, 0, NULL, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_WINDOWS); | ||
|
||
/* Time window errors */ | ||
ret = method( | ||
ts, 1, &sample_set_sizes, samples, 0, NULL, 0, time_windows, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_TIME_WINDOWS_DIM); | ||
|
||
ret = method( | ||
ts, 1, &sample_set_sizes, samples, 0, NULL, 2, time_windows, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_TIME_WINDOWS); | ||
|
||
time_windows[0] = 0.1; | ||
ret = method( | ||
ts, 1, &sample_set_sizes, samples, 0, NULL, 2, time_windows, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_TIME_WINDOWS); | ||
|
||
time_windows[0] = 0; | ||
time_windows[1] = 0; | ||
ret = method( | ||
ts, 1, &sample_set_sizes, samples, 0, NULL, 2, time_windows, 0, &result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_TIME_WINDOWS); | ||
} | ||
|
||
static void | ||
verify_two_way_stat_func_errors( | ||
tsk_treeseq_t *ts, general_sample_stat_method *method, tsk_flags_t options) | ||
|
@@ -1203,23 +1282,24 @@ verify_afs(tsk_treeseq_t *ts) | |
sample_set_sizes[0] = n - 2; | ||
sample_set_sizes[1] = 2; | ||
ret = tsk_treeseq_allele_frequency_spectrum( | ||
ts, 2, sample_set_sizes, samples, 0, NULL, 0, result); | ||
ts, 2, sample_set_sizes, samples, 0, NULL, 0, NULL, 0, result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uh-oh, are these tabs? |
||
CU_ASSERT_EQUAL_FATAL(ret, 0); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum( | ||
ts, 2, sample_set_sizes, samples, 0, NULL, TSK_STAT_POLARISED, result); | ||
ts, 2, sample_set_sizes, samples, 0, NULL, 0, NULL, TSK_STAT_POLARISED, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, 0); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum(ts, 2, sample_set_sizes, samples, 0, | ||
NULL, TSK_STAT_POLARISED | TSK_STAT_SPAN_NORMALISE, result); | ||
NULL, 0, NULL, TSK_STAT_POLARISED | TSK_STAT_SPAN_NORMALISE, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, 0); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum(ts, 2, sample_set_sizes, samples, 0, | ||
NULL, TSK_STAT_BRANCH | TSK_STAT_POLARISED | TSK_STAT_SPAN_NORMALISE, result); | ||
NULL, 0, NULL, TSK_STAT_BRANCH | TSK_STAT_POLARISED | TSK_STAT_SPAN_NORMALISE, | ||
result); | ||
CU_ASSERT_EQUAL_FATAL(ret, 0); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum(ts, 2, sample_set_sizes, samples, 0, | ||
NULL, TSK_STAT_BRANCH | TSK_STAT_SPAN_NORMALISE, result); | ||
NULL, 0, NULL, TSK_STAT_BRANCH | TSK_STAT_SPAN_NORMALISE, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, 0); | ||
|
||
free(result); | ||
|
@@ -2413,21 +2493,26 @@ test_paper_ex_afs_errors(void) | |
tsk_size_t sample_set_sizes[] = { 2, 2 }; | ||
tsk_id_t samples[] = { 0, 1, 2, 3 }; | ||
double result[10]; /* not thinking too hard about the actual value needed */ | ||
double time_windows[] = { 0, 1 }; | ||
int ret; | ||
|
||
tsk_treeseq_from_text(&ts, 10, paper_ex_nodes, paper_ex_edges, NULL, paper_ex_sites, | ||
paper_ex_mutations, paper_ex_individuals, NULL, 0); | ||
|
||
verify_one_way_stat_func_errors(&ts, tsk_treeseq_allele_frequency_spectrum); | ||
verify_one_way_stat_func_errors_tw(&ts, tsk_treeseq_allele_frequency_spectrum); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum( | ||
&ts, 2, sample_set_sizes, samples, 0, NULL, TSK_STAT_NODE, result); | ||
&ts, 2, sample_set_sizes, samples, 0, NULL, 0, NULL, TSK_STAT_NODE, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_UNSUPPORTED_STAT_MODE); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum(&ts, 2, sample_set_sizes, samples, 0, | ||
NULL, TSK_STAT_BRANCH | TSK_STAT_SITE, result); | ||
NULL, 0, NULL, TSK_STAT_BRANCH | TSK_STAT_SITE, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_MULTIPLE_STAT_MODES); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum(&ts, 2, sample_set_sizes, samples, 0, | ||
NULL, 1, time_windows, TSK_STAT_SITE, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_UNSUPPORTED_STAT_MODE); | ||
|
||
tsk_treeseq_free(&ts); | ||
} | ||
|
||
|
@@ -2445,14 +2530,14 @@ test_paper_ex_afs(void) | |
/* we have two singletons and one tripleton */ | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum( | ||
&ts, 1, sample_set_sizes, samples, 0, NULL, 0, result); | ||
&ts, 1, sample_set_sizes, samples, 0, NULL, 0, NULL, 0, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, 0); | ||
CU_ASSERT_EQUAL_FATAL(result[0], 0); | ||
CU_ASSERT_EQUAL_FATAL(result[1], 3.0); | ||
CU_ASSERT_EQUAL_FATAL(result[2], 0); | ||
|
||
ret = tsk_treeseq_allele_frequency_spectrum( | ||
&ts, 1, sample_set_sizes, samples, 0, NULL, TSK_STAT_POLARISED, result); | ||
&ts, 1, sample_set_sizes, samples, 0, NULL, 0, NULL, TSK_STAT_POLARISED, result); | ||
CU_ASSERT_EQUAL_FATAL(ret, 0); | ||
CU_ASSERT_EQUAL_FATAL(result[0], 0); | ||
CU_ASSERT_EQUAL_FATAL(result[1], 2.0); | ||
|
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also have time window errors here?