Skip to content

Commit 108b37f

Browse files
committed
Fix python tests
1 parent 094f301 commit 108b37f

4 files changed

Lines changed: 37 additions & 28 deletions

File tree

python/tests/test_genotypes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def test_silent_mutations(self):
342342
site = tables.sites.add_row(position=0, ancestral_state="0")
343343
tables.mutations.add_row(site=site, node=u, derived_state="1")
344344
tables.mutations.add_row(site=site, node=sample, derived_state="1")
345+
tables.compute_mutation_parents()
345346
ts_new = tables.tree_sequence()
346347
assert all([v.genotypes[sample] == 1 for v in ts_new.variants()])
347348

@@ -927,8 +928,9 @@ def test_silent_mutations(self):
927928
tables.sites.clear()
928929
tables.mutations.clear()
929930
site = tables.sites.add_row(position=0, ancestral_state="0")
930-
tables.mutations.add_row(site=site, node=u, derived_state="1")
931931
tables.mutations.add_row(site=site, node=tree.root, derived_state="1")
932+
tables.mutations.add_row(site=site, node=u, derived_state="1")
933+
tables.compute_mutation_parents()
932934
ts_new = tables.tree_sequence()
933935
all(h == 1 for h in ts_new.haplotypes())
934936

python/tests/test_highlevel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,8 @@ def test_k_mutations(self, k):
29722972
tables.nodes.add_row(1, 0) # will not have any mutations => missing
29732973
for j in range(k):
29742974
tables.mutations.add_row(site=0, node=0, derived_state=str(j))
2975+
tables.build_index()
2976+
tables.compute_mutation_parents()
29752977
ts = tables.tree_sequence()
29762978
variant = next(ts.variants())
29772979
assert variant.has_missing_data

python/tests/test_tables.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,8 @@ def test_sort_mutations_time(self):
27922792
"""\
27932793
id is_sample time
27942794
0 1 -6
2795+
1 1 -6
2796+
2 1 -6
27952797
"""
27962798
)
27972799
edges = io.StringIO(
@@ -2811,14 +2813,14 @@ def test_sort_mutations_time(self):
28112813
"""\
28122814
site node time derived_state parent
28132815
2 0 4 a -1
2814-
2 0 -5 b -1
2815-
2 0 6 c -1
2816+
2 1 -5 b -1
2817+
2 2 6 c -1
28162818
1 0 0.5 d -1
2817-
1 0 0.5 e -1
2818-
1 0 0.5 f -1
2819+
1 1 0.5 e -1
2820+
1 2 0.5 f -1
28192821
0 0 1 g -1
2820-
0 0 2 h -1
2821-
0 0 3 i -1
2822+
0 1 2 h -1
2823+
0 2 3 i -1
28222824
"""
28232825
)
28242826
ts = tskit.load_text(
@@ -2836,7 +2838,7 @@ def test_sort_mutations_time(self):
28362838
assert len(sites) == 3
28372839
assert len(mutations) == 9
28382840
assert list(mutations.site) == [0, 0, 0, 1, 1, 1, 2, 2, 2]
2839-
assert list(mutations.node) == [0, 0, 0, 0, 0, 0, 0, 0, 0]
2841+
assert list(mutations.node) == [2, 1, 0, 0, 1, 2, 2, 0, 1]
28402842
# Nans are not equal so swap in -1
28412843
times = mutations.time
28422844
times[np.isnan(times)] = -1
@@ -2928,6 +2930,8 @@ def test_unsorted_times(self):
29282930
"""\
29292931
id is_sample time
29302932
0 1 0
2933+
1 1 0
2934+
2 1 0
29312935
"""
29322936
)
29332937
edges = io.StringIO(
@@ -2945,8 +2949,8 @@ def test_unsorted_times(self):
29452949
"""\
29462950
site node time derived_state parent
29472951
0 0 1 0 -1
2948-
0 0 2 0 -1
2949-
0 0 3 0 -1
2952+
0 1 2 0 -1
2953+
0 2 3 0 -1
29502954
"""
29512955
)
29522956
ts = tskit.load_text(

python/tests/test_topology.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,9 +1659,9 @@ def test_single_binary_tree_keep_roots_mutations(self):
16591659
0 0.1 0
16601660
"""
16611661
mutations_before = """\
1662-
site node derived_state
1663-
0 3 2
1664-
0 4 1
1662+
site node derived_state parent
1663+
0 4 1 -1
1664+
0 3 2 0
16651665
"""
16661666

16671667
# We sample 0 and 2
@@ -1682,9 +1682,9 @@ def test_single_binary_tree_keep_roots_mutations(self):
16821682
0 0.1 0
16831683
"""
16841684
mutations_after = """\
1685-
site node derived_state
1686-
0 2 2
1687-
0 2 1
1685+
site node derived_state parent
1686+
0 2 1 -1
1687+
0 2 2 0
16881688
"""
16891689
self.verify_simplify(
16901690
samples=[0, 1],
@@ -1716,10 +1716,10 @@ def test_place_mutations_with_and_without_roots(self):
17161716
0 1.0 0
17171717
"""
17181718
mutations_before = """\
1719-
site node derived_state time
1720-
0 0 2 0
1721-
0 1 1 1
1722-
0 2 3 2
1719+
site node derived_state time parent
1720+
0 2 3 2 -1
1721+
0 1 1 1 0
1722+
0 0 2 0 1
17231723
"""
17241724
# expected result without keep_input_roots
17251725
nodes_after = """\
@@ -1730,10 +1730,10 @@ def test_place_mutations_with_and_without_roots(self):
17301730
left right parent child
17311731
"""
17321732
mutations_after = """\
1733-
site node derived_state time
1734-
0 0 2 0
1735-
0 0 1 1
1736-
0 0 3 2
1733+
site node derived_state time parent
1734+
0 0 3 2 -1
1735+
0 0 1 1 0
1736+
0 0 2 0 1
17371737
"""
17381738
# expected result with keep_input_roots
17391739
nodes_after_keep = """\
@@ -1746,10 +1746,10 @@ def test_place_mutations_with_and_without_roots(self):
17461746
0 2 1 0
17471747
"""
17481748
mutations_after_keep = """\
1749-
site node derived_state time
1750-
0 0 2 0
1751-
0 0 1 1
1752-
0 1 3 2
1749+
site node derived_state time parent
1750+
0 1 3 2 -1
1751+
0 0 1 1 0
1752+
0 0 2 0 1
17531753
"""
17541754
self.verify_simplify(
17551755
samples=[0],
@@ -3778,6 +3778,7 @@ def test_small_tree_back_mutations(self):
37783778
tables.mutations.add_row(site=0, node=7, derived_state="1")
37793779
tables.mutations.add_row(site=0, node=5, derived_state="0")
37803780
tables.mutations.add_row(site=0, node=1, derived_state="1")
3781+
tables.compute_mutation_parents()
37813782
ts = tables.tree_sequence()
37823783
assert ts.num_sites == 1
37833784
assert ts.num_mutations == 3

0 commit comments

Comments
 (0)