Skip to content

Commit

Permalink
increase cov
Browse files Browse the repository at this point in the history
  • Loading branch information
GertjanBisschop committed May 11, 2023
1 parent ffba07a commit 51b4381
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
flag as well as record edges for coalescing nodes along non-coalescing segments. ({issue}`2128`, {issue}`2132`, {pr}`2162`,
{user}`GertjanBisschop`)

- Enable `additional_nodes` and `coalescing_segments_only` flags for `DTWF` and `FIXED_PEDIDGREE` models ({issue}`2129`, {issue}`2133`, {issue}`2167`, {pr}`2176`,
{user}`GertjanBisschop`)

## [1.2.0] - 2022-05-18

**New features**
Expand Down
89 changes: 72 additions & 17 deletions lib/tests/test_ancestry.c
Original file line number Diff line number Diff line change
Expand Up @@ -3740,41 +3740,94 @@ test_dtwf_additional_nodes(void)
tsk_size_t num_edges, num_edges_simple;
gsl_rng *rng = safe_rng_alloc();
tsk_table_collection_t tables;
uint32_t additional_nodes[4]
= { MSP_NODE_IS_PASS_THROUGH, MSP_NODE_IS_PASS_THROUGH | MSP_NODE_IS_RE_EVENT,
MSP_NODE_IS_RE_EVENT | MSP_NODE_IS_CA_EVENT,
MSP_NODE_IS_PASS_THROUGH | MSP_NODE_IS_RE_EVENT | MSP_NODE_IS_CA_EVENT };

for (int i = 0; i < 4; i++) {
ret = build_sim(&msp, &tables, rng, 100, 1, NULL, n);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_initialise(&msp);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_recombination_rate(&msp, 1);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = msp_set_simulation_model_dtwf(&msp);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_population_configuration(&msp, 0, n, 0, true);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_additional_nodes(&msp, additional_nodes[i]);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_coalescing_segments_only(&msp, false);
CU_ASSERT_EQUAL(ret, 0);
model_name = msp_get_model_name(&msp);
CU_ASSERT_STRING_EQUAL(model_name, "dtwf");

ret = msp_run(&msp, DBL_MAX, UINT32_MAX);
CU_ASSERT_EQUAL(ret, 0);
msp_verify(&msp, 0);
ret = msp_finalise_tables(&msp);
CU_ASSERT_EQUAL_FATAL(ret, 0);

// verify whether there is at least one unary node
num_edges = tables.edges.num_rows;
ret = tsk_table_collection_simplify(&tables, NULL, 0, 0, NULL);
CU_ASSERT_EQUAL_FATAL(ret, 0);
num_edges_simple = tables.edges.num_rows;
CU_ASSERT_TRUE(num_edges_simple < num_edges);

ret = msp_free(&msp);
CU_ASSERT_EQUAL(ret, 0);
tsk_table_collection_free(&tables);
}
gsl_rng_free(rng);
}

static void
test_dtwf_historical_samples_additional_nodes(void)
{
int ret;
msp_t msp;
gsl_rng *rng = safe_rng_alloc();
sample_t samples[] = { { 0, 0 }, { 0, 1.1 }, { 0, 1.2 } };
tsk_node_table_t *nodes;
uint32_t n = 3;
tsk_table_collection_t tables;
uint32_t additional_nodes
= MSP_NODE_IS_PASS_THROUGH | MSP_NODE_IS_RE_EVENT | MSP_NODE_IS_CA_EVENT;

ret = build_sim(&msp, &tables, rng, 100, 1, NULL, n);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_initialise(&msp);
gsl_rng_set(rng, 5);

ret = build_sim(&msp, &tables, rng, 100, 1, samples, n);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_recombination_rate(&msp, 1);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = msp_set_simulation_model_dtwf(&msp);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_population_configuration(&msp, 0, n, 0, true);
ret = msp_set_population_configuration(&msp, 0, 100, 0, true);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_recombination_rate(&msp, 0.1);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = msp_set_additional_nodes(&msp, additional_nodes);
CU_ASSERT_EQUAL(ret, 0);
ret = msp_set_coalescing_segments_only(&msp, false);
CU_ASSERT_EQUAL(ret, 0);
model_name = msp_get_model_name(&msp);
CU_ASSERT_STRING_EQUAL(model_name, "dtwf");

ret = msp_run(&msp, DBL_MAX, UINT32_MAX);
ret = msp_initialise(&msp);
CU_ASSERT_EQUAL(ret, 0);

msp_print_state(&msp, _devnull);
ret = msp_run(&msp, DBL_MAX, ULONG_MAX);
CU_ASSERT_EQUAL(ret, 0);
msp_verify(&msp, 0);
ret = msp_finalise_tables(&msp);
CU_ASSERT_EQUAL_FATAL(ret, 0);
msp_print_state(&msp, _devnull);

// verify whether there is at least one unary node
num_edges = tables.edges.num_rows;
ret = tsk_table_collection_simplify(&tables, NULL, 0, 0, NULL);
CU_ASSERT_EQUAL_FATAL(ret, 0);
num_edges_simple = tables.edges.num_rows;
CU_ASSERT_TRUE(num_edges_simple < num_edges);
nodes = &msp.tables->nodes;
CU_ASSERT_EQUAL(nodes->flags[0], TSK_NODE_IS_SAMPLE);
CU_ASSERT_EQUAL(nodes->flags[1], TSK_NODE_IS_SAMPLE);
CU_ASSERT_EQUAL(nodes->flags[2], TSK_NODE_IS_SAMPLE);

ret = msp_free(&msp);
CU_ASSERT_EQUAL(ret, 0);

gsl_rng_free(rng);
tsk_table_collection_free(&tables);
}
Expand Down Expand Up @@ -3867,6 +3920,8 @@ main(int argc, char **argv)
{ "test_additional_nodes_mig", test_additional_nodes_mig },
{ "test_additional_nodes_re_ca_gc", test_additional_nodes_re_ca_gc },
{ "test_dtwf_additional_nodes", test_dtwf_additional_nodes },
{ "test_dtwf_historical_samples_additional_nodes",
test_dtwf_historical_samples_additional_nodes },
CU_TEST_INFO_NULL,
};

Expand Down
10 changes: 10 additions & 0 deletions lib/tests/test_pedigrees.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ test_very_deep_n2(void)
verify_pedigree(0.1, 1, n, very_deep_n2_parents, very_deep_n2_time, NULL, NULL, 0);
verify_pedigree(0.1, 1, n, very_deep_n2_parents, very_deep_n2_time, NULL, NULL,
additional_nodes);
additional_nodes = MSP_NODE_IS_PASS_THROUGH | MSP_NODE_IS_CA_EVENT;
verify_pedigree(0.1, 1, n, very_deep_n2_parents, very_deep_n2_time, NULL, NULL,
additional_nodes);
additional_nodes = MSP_NODE_IS_PASS_THROUGH | MSP_NODE_IS_RE_EVENT;
verify_pedigree(0.1, 1, n, very_deep_n2_parents, very_deep_n2_time, NULL, NULL,
additional_nodes);
additional_nodes
= MSP_NODE_IS_PASS_THROUGH | MSP_NODE_IS_CA_EVENT | MSP_NODE_IS_RE_EVENT;
verify_pedigree(0.1, 1, n, very_deep_n2_parents, very_deep_n2_time, NULL, NULL,
additional_nodes);
}

static void
Expand Down
13 changes: 10 additions & 3 deletions tests/test_ancestry.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,12 @@ def test_dtwf_full_arg(self):
)

def test_dtwf_store_additional_nodes(self):
node_values = [msprime.NODE_IS_CA_EVENT | msprime.NODE_IS_PASS_THROUGH, None]
node_values[-1] = node_values[0] | msprime.NODE_IS_RE_EVENT
node_values = [
msprime.NODE_IS_RE_EVENT | msprime.NODE_IS_PASS_THROUGH,
msprime.NODE_IS_CA_EVENT | msprime.NODE_IS_PASS_THROUGH,
None,
]
node_values[-1] = node_values[0] | node_values[1]
for node_value in node_values:
additional_nodes = msprime.NodeType(node_value)
sim = ancestry._parse_sim_ancestry(
Expand All @@ -771,7 +775,10 @@ def test_dtwf_store_additional_nodes(self):
coalescing_segments_only=False,
)
ts = self.verify_dtwf(sim, additional_nodes)
self.verify_dtwf_pass_through(ts)
if (additional_nodes.value & msprime.NODE_IS_PASS_THROUGH) and (
additional_nodes.value & msprime.NODE_IS_CA_EVENT
):
self.verify_dtwf_pass_through(ts)


class TestSimulator:
Expand Down
54 changes: 30 additions & 24 deletions tests/test_pedigree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ def verify_pedigree_recombination(self, tables):
else:
assert num_parents == 1

def verify_binary_pedigree(self, sim, additional_nodes):
def verify_pedigree(self, sim, additional_nodes):
sim.run()
output_tables = tskit.TableCollection.fromdict(sim.tables.asdict())
ts = output_tables.tree_sequence()
Expand Down Expand Up @@ -1217,7 +1217,7 @@ def test_pedigree_unary(self):
initial_state=initial_state,
random_seed=1234,
)
ts = self.verify_binary_pedigree(sim, additional_nodes)
ts = self.verify_pedigree(sim, additional_nodes)
self.verify_pedigree_unary(ts, initial_state)

def test_pedigree_unary_simple(self):
Expand Down Expand Up @@ -1267,31 +1267,37 @@ def test_deep_pedigree(self):
initial_state=initial_state,
random_seed=1234,
)
ts = self.verify_binary_pedigree(sim, additional_nodes)
ts = self.verify_pedigree(sim, additional_nodes)
self.verify_pedigree_unary(ts, initial_state)

def test_deep_pedigree_2(self):
node_value = (
msprime.NODE_IS_PASS_THROUGH
| msprime.NODE_IS_RE_EVENT
| msprime.NODE_IS_CA_EVENT
)
additional_nodes = msprime.NodeType(node_value)
initial_state = simulate_pedigree(
num_founders=10,
num_children_prob=[0, 0, 0.7, 0.3],
num_generations=6, # Takes a long time if this is increased
sequence_length=100,
)
ts = msprime.ancestry.sim_ancestry(
recombination_rate=0.1,
model="fixed_pedigree",
additional_nodes=additional_nodes,
coalescing_segments_only=False,
initial_state=initial_state,
random_seed=52,
)
self.verify_pedigree_unary(ts, initial_state)
node_values = [
msprime.NODE_IS_PASS_THROUGH | msprime.NODE_IS_CA_EVENT,
msprime.NODE_IS_PASS_THROUGH | msprime.NODE_IS_RE_EVENT,
None,
]
node_values[-1] = node_values[0] | node_values[1]
for node_value in node_values:
additional_nodes = msprime.NodeType(node_value)
initial_state = simulate_pedigree(
num_founders=10,
num_children_prob=[0, 0, 0.7, 0.3],
num_generations=6, # Takes a long time if this is increased
sequence_length=100,
)
sim = msprime.ancestry._parse_sim_ancestry(
recombination_rate=1e-2,
model="fixed_pedigree",
additional_nodes=additional_nodes,
coalescing_segments_only=False,
initial_state=initial_state,
random_seed=52,
)
ts = self.verify_pedigree(sim, additional_nodes)
if (additional_nodes.value & msprime.NODE_IS_PASS_THROUGH) and (
additional_nodes.value & msprime.NODE_IS_CA_EVENT
):
self.verify_pedigree_unary(ts, initial_state)


class TestPedigreeBuilder:
Expand Down

0 comments on commit 51b4381

Please sign in to comment.