Skip to content

Commit

Permalink
fix sorting bug pedigrees
Browse files Browse the repository at this point in the history
  • Loading branch information
GertjanBisschop authored and mergify[bot] committed Dec 6, 2023
1 parent 873c2cc commit c6e9573
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/msprime.c
Original file line number Diff line number Diff line change
Expand Up @@ -5348,7 +5348,8 @@ msp_finalise_tables(msp_t *self)
}
ret = tsk_table_collection_build_index(self->tables, 0);
if (ret == TSK_ERR_EDGES_NOT_SORTED_PARENT_TIME
|| ret == TSK_ERR_EDGES_NONCONTIGUOUS_PARENTS) {
|| ret == TSK_ERR_EDGES_NONCONTIGUOUS_PARENTS
|| ret == TSK_ERR_EDGES_NOT_SORTED_CHILD) {
/* There are rare cases when we are simulating from awkward initial
* states where the tables we produce in the simulation are not
* correctly sorted. The simplest course of action here to just let it
Expand Down
32 changes: 32 additions & 0 deletions tests/test_pedigree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,38 @@ def test_deep_pedigree_2(self):
):
self.verify_pedigree_unary(ts, initial_state)

def test_deep_pedigree_sorting_requirements(self):
"""
Produces TSK_ERR_EDGES_NOT_SORTED_CHILD error if
this error is not addressed in msp_finalise_tables
"""
N = 10
end_time = 1000
sequence_length = 100
recombination_rate = 0.0001
additional_nodes = (
msprime.NodeType.RECOMBINANT
| msprime.NodeType.PASS_THROUGH
| msprime.NodeType.COMMON_ANCESTOR
)
random_seed = 17351
pedigree = msprime.pedigrees.sim_pedigree(
population_size=N,
end_time=end_time,
direction="forward",
random_seed=random_seed,
)
pedigree.sequence_length = sequence_length
ts_ped = msprime.sim_ancestry(
initial_state=pedigree,
recombination_rate=recombination_rate,
model="fixed_pedigree",
additional_nodes=additional_nodes,
coalescing_segments_only=False,
random_seed=random_seed,
)
self.verify_pedigree_unary(ts_ped, pedigree)


class TestPedigreeBuilder:
def test_is_sample_default(self):
Expand Down

0 comments on commit c6e9573

Please sign in to comment.