Skip to content

Commit 3c480fb

Browse files
committed
Add python changelog and tests
1 parent 376f04e commit 3c480fb

3 files changed

Lines changed: 108 additions & 1 deletion

File tree

c/CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
**Breaking changes**
66

77
- ``tsk_treeseq_init`` now requires that mutation parents in the table collection
8-
are correct and consistent with the topology of the tree at the mutation site.
8+
are correct and consistent with the topology of the tree at each mutation site.
99
Returns ``TSK_ERR_BAD_MUTATION_PARENT`` if this is not the case, or
1010
``TSK_ERR_MUTATION_PARENT_AFTER_CHILD`` if the mutations are not in an order
1111
compatible with the correct mutation parent.

python/CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
[0.6.5] - 2025-0X-XX
33
--------------------
44

5+
**Breaking Changes**
6+
7+
- For a tree seqeunce to be valid mutation parents in the table collection
8+
must be correct and consistent with the topology of the tree at each mutation site.
9+
``TableCollection.tree_sequence()`` will raise a ``_tskit.LibraryError`` if this
10+
is not the case.
11+
(:user:`benjeffery`, :issue:`2729`, :issue:`2732`, :pr:`3212`).
12+
13+
514
**Features**
615

716
- ``TreeSequence.map_to_vcf_model`` now also returns the transformed positions and

python/tests/test_highlevel.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,104 @@ def test_impute_unknown_mutations_time(self, ts):
26922692
):
26932693
ts.impute_unknown_mutations_time(method="foobar")
26942694

2695+
@pytest.mark.parametrize(
2696+
"mutations, error",
2697+
[
2698+
([], None),
2699+
(
2700+
[{"node": 0, "parent": -1}, {"node": 1, "parent": -1}],
2701+
None,
2702+
), # On parallel branches, no parents
2703+
(
2704+
[
2705+
{"node": 4, "parent": -1},
2706+
{"node": 0, "parent": 0},
2707+
{"node": 1, "parent": 0},
2708+
],
2709+
None,
2710+
), # On parallel branches, legal parent
2711+
(
2712+
[{"node": 0, "parent": -1}, {"node": 0, "parent": 0}],
2713+
None,
2714+
), # On same node
2715+
(
2716+
[{"node": 0, "parent": -1}, {"node": 0, "parent": -1}],
2717+
"not consistent with the topology",
2718+
), # On same node without parents
2719+
(
2720+
[
2721+
{"node": 3, "parent": -1},
2722+
{"node": 0, "parent": 0},
2723+
{"node": 1, "parent": 0},
2724+
],
2725+
"not consistent with the topology",
2726+
), # On parallel branches, parent on parallel branches
2727+
(
2728+
[
2729+
{"node": 5, "parent": -1},
2730+
{"node": 0, "parent": 0},
2731+
{"node": 1, "parent": 0},
2732+
],
2733+
"not consistent with the topology",
2734+
), # On parallel branches, parent high on parallel
2735+
(
2736+
[
2737+
{"node": 3, "parent": -1},
2738+
{"node": 0, "parent": 0},
2739+
{"node": 7, "parent": 0},
2740+
],
2741+
"not consistent with the topology",
2742+
), # On parallel branches, parent on different root
2743+
(
2744+
[
2745+
{"node": 0, "parent": -1},
2746+
{"node": 1, "parent": 0},
2747+
],
2748+
"not consistent with the topology",
2749+
), # parent on parallel branch
2750+
(
2751+
[
2752+
{"node": 6, "parent": -1},
2753+
{"node": 6, "parent": 0},
2754+
],
2755+
None,
2756+
), # parent above root
2757+
(
2758+
[
2759+
{"node": 6, "parent": -1},
2760+
{"node": 6, "parent": -1},
2761+
],
2762+
"not consistent with the topology",
2763+
), # parent above root, no parents
2764+
],
2765+
)
2766+
def test_mutation_parent_errors(self, mutations, error):
2767+
tables = tskit.TableCollection(sequence_length=1)
2768+
tables.nodes.add_row(time=0, flags=tskit.NODE_IS_SAMPLE)
2769+
tables.nodes.add_row(time=0, flags=tskit.NODE_IS_SAMPLE)
2770+
tables.nodes.add_row(time=0, flags=tskit.NODE_IS_SAMPLE)
2771+
tables.nodes.add_row(time=0, flags=tskit.NODE_IS_SAMPLE)
2772+
tables.nodes.add_row(time=1)
2773+
tables.nodes.add_row(time=1)
2774+
tables.nodes.add_row(time=2)
2775+
tables.nodes.add_row(time=3)
2776+
tables.edges.add_row(left=0, right=1, parent=4, child=0)
2777+
tables.edges.add_row(left=0, right=1, parent=4, child=1)
2778+
tables.edges.add_row(left=0, right=1, parent=5, child=2)
2779+
tables.edges.add_row(left=0, right=1, parent=5, child=3)
2780+
tables.edges.add_row(left=0, right=1, parent=6, child=4)
2781+
tables.edges.add_row(left=0, right=1, parent=6, child=5)
2782+
tables.sites.add_row(position=0.5, ancestral_state="A")
2783+
2784+
for mut in mutations:
2785+
tables.mutations.add_row(**{"derived_state": "G", "site": 0, **mut})
2786+
2787+
if error is not None:
2788+
with pytest.raises(_tskit.LibraryError, match=error):
2789+
tables.tree_sequence()
2790+
else:
2791+
tables.tree_sequence()
2792+
26952793

26962794
class TestSimplify:
26972795
# This class was factored out of the old TestHighlevel class 2022-12-13,

0 commit comments

Comments
 (0)