Skip to content

Commit

Permalink
Test nonsuccinct case
Browse files Browse the repository at this point in the history
  • Loading branch information
nspope committed Apr 3, 2024
1 parent 4754e3f commit 2a70d13
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions python/tests/test_coalrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@ def naive_pair_coalescence_counts(ts, sample_set_0, sample_set_1):
return output


def convert_to_nonsuccinct(ts):
"""
Give the edges and internal nodes in each tree distinct IDs
"""
tables = tskit.TableCollection(sequence_length=ts.sequence_length)
for _ in range(ts.num_populations):
tables.populations.add_row()
nodes_count = 0
for n in ts.samples():
tables.nodes.add_row(
time=ts.nodes_time[n],
flags=ts.nodes_flags[n],
population=ts.nodes_population[n],
)
nodes_count += 1
for t in ts.trees():
nodes_map = {n: n for n in ts.samples()}
for n in t.nodes():
if t.num_samples(n) > 1:
tables.nodes.add_row(
time=ts.nodes_time[n],
flags=ts.nodes_flags[n],
population=ts.nodes_population[n],
)
nodes_map[n] = nodes_count
nodes_count += 1
for n in t.nodes():
if t.edge(n) != tskit.NULL:
tables.edges.add_row(
parent=nodes_map[t.parent(n)],
child=nodes_map[n],
left=t.interval.left,
right=t.interval.right,
)
tables.sort()
ts_unroll = tables.tree_sequence()
assert nodes_count == ts_unroll.num_nodes
return ts_unroll


class TestCoalescingPairsOneTree:
"""
Test against worked example (single tree)
Expand Down Expand Up @@ -473,6 +513,15 @@ def test_windows_inside_trees(self):
self._check_total_pairs(ts, windows)
self._check_subset_pairs(ts, windows)

def test_nonsuccinct_sequence(self):
"""
test case where each tree has distinct nodes
"""
ts = convert_to_nonsuccinct(self.example_ts())
windows = np.linspace(0, ts.sequence_length, 9)
self._check_total_pairs(ts, windows)
self._check_subset_pairs(ts, windows)

def test_span_normalise(self):
ts = self.example_ts()
windows = np.array([0.0, 0.33, 1.0]) * ts.sequence_length
Expand Down

0 comments on commit 2a70d13

Please sign in to comment.