Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion c/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
[0.99.16] - 2022-0X-XX
----------------------

- Make dumping of tables and tree seqences to disk a zero-copy operation.
**Breaking changes**

- Change the type of genotypes to ``int32_t``, removing the TSK_16_BIT_GENOTYPES flag option.
(:user:`benjeffery`, :issue:`463`, :pr:`2108`)

**Features**

- Make dumping of tables and tree sequences to disk a zero-copy operation.
(:user:`benjeffery`, :issue:`2111`, :pr:`2124`)

----------------------
Expand Down
370 changes: 123 additions & 247 deletions c/tests/test_genotypes.c

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions c/tests/test_haplotype_matching.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tsk_ls_hmm_next_probability_test(tsk_ls_hmm_t *TSK_UNUSED(self),
}

static int
run_test_hmm(tsk_ls_hmm_t *hmm, int8_t *haplotype, tsk_compressed_matrix_t *output)
run_test_hmm(tsk_ls_hmm_t *hmm, int32_t *haplotype, tsk_compressed_matrix_t *output)
{
int ret = 0;

Expand Down Expand Up @@ -79,7 +79,7 @@ test_single_tree_missing_alleles(void)

double rho[] = { 0, 0.25, 0.25 };
double mu[] = { 0.125, 0.125, 0.125 };
int8_t h[] = { 0, 0, 0, 0 };
int32_t h[] = { 0, 0, 0, 0 };

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL,
single_tree_ex_sites, single_tree_ex_mutations, NULL, NULL, 0);
Expand Down Expand Up @@ -108,7 +108,7 @@ test_single_tree_exact_match(void)

double rho[] = { 0.0, 0.25, 0.25 };
double mu[] = { 0, 0, 0 };
int8_t h[] = { 1, 1, 1 };
int32_t h[] = { 1, 1, 1 };
tsk_id_t path[3];
double decoded_compressed_matrix[12];
unsigned int precision;
Expand Down Expand Up @@ -167,7 +167,7 @@ test_single_tree_missing_haplotype_data(void)

double rho[] = { 0.0, 0.25, 0.25 };
double mu[] = { 0, 0, 0 };
int8_t h[] = { 1, TSK_MISSING_DATA, 1 };
int32_t h[] = { 1, TSK_MISSING_DATA, 1 };
tsk_id_t path[3];
double decoded_compressed_matrix[12];

Expand Down Expand Up @@ -211,7 +211,7 @@ test_single_tree_match_impossible(void)
double rho[] = { 0.0, 0.25, 0.25 };
double mu[] = { 0, 0, 0 };
/* This haplotype can't happen with a mutation rate of 0 */
int8_t h[] = { 0, 0, 0 };
int32_t h[] = { 0, 0, 0 };

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL,
single_tree_ex_sites, single_tree_ex_mutations, NULL, NULL, 0);
Expand Down Expand Up @@ -247,7 +247,7 @@ test_single_tree_errors(void)

double rho[] = { 0.0, 0.25, 0.25 };
double mu[] = { 0, 0, 0 };
int8_t h[] = { 0, 0, 0 };
int32_t h[] = { 0, 0, 0 };

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL,
single_tree_ex_sites, single_tree_ex_mutations, NULL, NULL, 0);
Expand Down Expand Up @@ -309,7 +309,7 @@ test_single_tree_compressed_matrix(void)

double rho[] = { 0.0, 0.25, 0.25 };
double mu[] = { 0.1, 0.1, 0.1 };
int8_t h[] = { 0, 0, 0 };
int32_t h[] = { 0, 0, 0 };

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL,
single_tree_ex_sites, single_tree_ex_mutations, NULL, NULL, 0);
Expand Down Expand Up @@ -374,7 +374,7 @@ test_single_tree_viterbi_matrix(void)
tsk_ls_hmm_t ls_hmm;
double rho[] = { 0.0, 0.25, 0.25 };
double mu[] = { 0, 0, 0 };
int8_t h[] = { 1, 1, 1 };
int32_t h[] = { 1, 1, 1 };
tsk_id_t path[3];
tsk_value_transition_t T[2];
int j;
Expand Down Expand Up @@ -448,7 +448,7 @@ test_multi_tree_exact_match(void)

double rho[] = { 0.0, 0.25, 0.25 };
double mu[] = { 0, 0, 0 };
int8_t h[] = { 1, 1, 1 };
int32_t h[] = { 1, 1, 1 };
tsk_id_t path[3];
double decoded_compressed_matrix[12];
unsigned int precision;
Expand Down Expand Up @@ -530,7 +530,7 @@ test_caterpillar_tree_many_values(void)
tsk_ls_hmm_t ls_hmm;
tsk_compressed_matrix_t matrix;
double unused[] = { 0, 0, 0, 0, 0 };
int8_t h[] = { 0, 0, 0, 0, 0 };
int32_t h[] = { 0, 0, 0, 0, 0 };
tsk_size_t n[] = {
8,
16,
Expand Down
64 changes: 32 additions & 32 deletions c/tests/test_trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ verify_simplify_genotypes(tsk_treeseq_t *ts, tsk_treeseq_t *subset,
tsk_vargen_t vargen, subset_vargen;
tsk_variant_t *variant, *subset_variant;
tsk_size_t j, k;
int8_t a1, a2;
int32_t a1, a2;
const tsk_id_t *sample_index_map;

sample_index_map = tsk_treeseq_get_sample_index_map(ts);
Expand All @@ -511,8 +511,8 @@ verify_simplify_genotypes(tsk_treeseq_t *ts, tsk_treeseq_t *subset,
CU_ASSERT_EQUAL(variant->site->position, subset_variant->site->position);
for (k = 0; k < num_samples; k++) {
CU_ASSERT_FATAL(sample_index_map[samples[k]] < (tsk_id_t) ts->num_samples);
a1 = variant->genotypes.i8[sample_index_map[samples[k]]];
a2 = subset_variant->genotypes.i8[k];
a1 = variant->genotypes[sample_index_map[samples[k]]];
a2 = subset_variant->genotypes[k];
/* printf("a1 = %d, a2 = %d\n", a1, a2); */
/* printf("k = %d original node = %d " */
/* "original_index = %d a1=%.*s a2=%.*s\n", */
Expand Down Expand Up @@ -1330,29 +1330,29 @@ test_simplest_non_sample_leaf_records(void)
CU_ASSERT_EQUAL_FATAL(ret, 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[0], "0", 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[1], "1", 1);
CU_ASSERT_EQUAL(var->genotypes.i8[0], 1);
CU_ASSERT_EQUAL(var->genotypes.i8[1], 0);
CU_ASSERT_EQUAL(var->genotypes[0], 1);
CU_ASSERT_EQUAL(var->genotypes[1], 0);

ret = tsk_vargen_next(&vargen, &var);
CU_ASSERT_EQUAL_FATAL(ret, 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[0], "0", 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[1], "1", 1);
CU_ASSERT_EQUAL(var->genotypes.i8[0], 0);
CU_ASSERT_EQUAL(var->genotypes.i8[1], 1);
CU_ASSERT_EQUAL(var->genotypes[0], 0);
CU_ASSERT_EQUAL(var->genotypes[1], 1);

ret = tsk_vargen_next(&vargen, &var);
CU_ASSERT_EQUAL_FATAL(ret, 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[0], "0", 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[1], "1", 1);
CU_ASSERT_EQUAL(var->genotypes.i8[0], 0);
CU_ASSERT_EQUAL(var->genotypes.i8[1], 0);
CU_ASSERT_EQUAL(var->genotypes[0], 0);
CU_ASSERT_EQUAL(var->genotypes[1], 0);

ret = tsk_vargen_next(&vargen, &var);
CU_ASSERT_EQUAL_FATAL(ret, 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[0], "0", 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[1], "1", 1);
CU_ASSERT_EQUAL(var->genotypes.i8[0], 0);
CU_ASSERT_EQUAL(var->genotypes.i8[1], 0);
CU_ASSERT_EQUAL(var->genotypes[0], 0);
CU_ASSERT_EQUAL(var->genotypes[1], 0);

ret = tsk_vargen_next(&vargen, &var);
CU_ASSERT_EQUAL_FATAL(ret, 0);
Expand Down Expand Up @@ -1659,9 +1659,9 @@ test_simplest_back_mutations(void)
CU_ASSERT_EQUAL(var->num_alleles, 2);
CU_ASSERT_NSTRING_EQUAL(var->alleles[0], "0", 1);
CU_ASSERT_NSTRING_EQUAL(var->alleles[1], "1", 1);
CU_ASSERT_EQUAL(var->genotypes.i8[0], 0);
CU_ASSERT_EQUAL(var->genotypes.i8[1], 1);
CU_ASSERT_EQUAL(var->genotypes.i8[2], 0);
CU_ASSERT_EQUAL(var->genotypes[0], 0);
CU_ASSERT_EQUAL(var->genotypes[1], 1);
CU_ASSERT_EQUAL(var->genotypes[2], 0);
CU_ASSERT_EQUAL(var->site->id, 0);
CU_ASSERT_EQUAL(var->site->mutations_length, 2);
tsk_vargen_free(&vargen);
Expand Down Expand Up @@ -3069,10 +3069,10 @@ test_simplest_map_mutations(void)
const char *edges = "0 1 2 0,1\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 0 };
int32_t genotypes[] = { 0, 0 };
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -3151,10 +3151,10 @@ test_simplest_nonbinary_map_mutations(void)
const char *edges = "0 1 4 0,1,2,3\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 0, 0, 0 };
int32_t genotypes[] = { 0, 0, 0, 0 };
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -3197,10 +3197,10 @@ test_simplest_unary_map_mutations(void)
"0 1 4 2,3\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 0 };
int32_t genotypes[] = { 0, 0 };
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -3241,10 +3241,10 @@ test_simplest_non_sample_leaf_map_mutations(void)
const char *edges = "0 1 2 0,1,3,4\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 0 };
int32_t genotypes[] = { 0, 0 };
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -3283,10 +3283,10 @@ test_simplest_internal_sample_map_mutations(void)
const char *edges = "0 1 2 0,1\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 0, 0 };
int32_t genotypes[] = { 0, 0, 0 };
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -3340,10 +3340,10 @@ test_simplest_multiple_root_map_mutations(void)
"0 1 5 2,3\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 0, 0, 0 };
int32_t genotypes[] = { 0, 0, 0, 0 };
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -3397,10 +3397,10 @@ test_simplest_chained_map_mutations(void)
"0 1 4 2,3\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 0, 0, 0 };
int32_t genotypes[] = { 0, 0, 0, 0 };
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -4543,11 +4543,11 @@ test_single_tree_map_mutations(void)
{
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 1, 1, 1 };
int32_t genotypes[] = { 0, 1, 1, 1 };
int ret = 0;
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state, j;
int32_t ancestral_state, j;

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL, NULL,
NULL, NULL, NULL, 0);
Expand Down Expand Up @@ -4689,11 +4689,11 @@ test_single_tree_map_mutations_internal_samples(void)
"0.00000000 1.00000000 8 7\n";
tsk_treeseq_t ts;
tsk_tree_t t;
int8_t genotypes[] = { 0, 2, 2, 1, 0 };
int32_t genotypes[] = { 0, 2, 2, 1, 0 };
int ret = 0;
tsk_size_t num_transitions;
tsk_state_transition_t *transitions;
int8_t ancestral_state;
int32_t ancestral_state;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
CU_ASSERT_EQUAL(tsk_treeseq_get_num_samples(&ts), 5);
Expand Down
Loading