예제 #1
0
 def verify(self, ts, samples, populations):
     tab = slime.get_ancestry_table(ts,
                                    populations=populations,
                                    samples=samples)
     # Loop through the rows of the ancestral branch table.
     for row in range(0, tab.num_rows):
         current_sample = tab.child[row]
         current_left = tab.left[row]
         current_right = tab.right[row]
         current_pop = ts.tables.nodes.population[current_sample]
         if current_pop in populations:
             self.assertEqual(tab.population[row], current_pop)
         else:
             for tree in ts.trees():
                 if tree.interval[0] >= current_right:
                     break
                 while tree.interval[1] <= current_left:
                     tree.next()
                 # Check that that most recent node from a relevant population has the
                 # same population ID as listed in the ancestor table.
                 par = tree.get_parent(current_sample)
                 ancestor_pop = ts.tables.nodes.population[par]
                 while ancestor_pop not in populations:
                     par = tree.get_parent(par)
                     ancestor_pop = ts.tables.nodes.population[par]
                 self.assertEqual(tab.population[row], ancestor_pop)
예제 #2
0
 def test_some_samples_have_relevant_population_labels(self):
     # Tree sequence  | Population
     #     4          | 2
     #    / \         |
     #   /   3        | 1
     #  /   / \       |
     # 0   1   2      | 0, 1, 2
     nodes = io.StringIO("""\
     id      is_sample   population      time
     0       1       0               0.00000000000000
     1       1       1               0.00000000000000
     2       1       2               0.00000000000000
     3       0       1               1.00000000000000
     4       0       2               2.00000000000000
     """)
     edges = io.StringIO("""\
     id      left            right           parent  child
     0       0.00000000      1.00000000      3       1,2
     1       0.00000000      1.00000000      4       0,3
     """)
     ts = tskit.load_text(nodes=nodes, edges=edges, strict=False)
     tab = slime.get_ancestry_table(ts, populations=[1, 2])
     self.assertEqual(list(tab.left), [0, 0, 0])
     self.assertEqual(list(tab.right), [1, 1, 1])
     self.assertEqual(list(tab.population), [2, 1, 2])
     self.assertEqual(list(tab.child), [0, 1, 2])
예제 #3
0
 def test_multiple_trees_some_missing_segments(self):
     ts = tskit.load_text(nodes=self.nodes1,
                          edges=self.edges1,
                          strict=False)
     tab = slime.get_ancestry_table(ts, [1, 2])
     self.assertEqual(list(tab.left), [0, .5, 0, .5, .5, .5, 0])
     self.assertEqual(list(tab.right), [.5, 1, .5, 1, 1, 1, .5])
     self.assertEqual(list(tab.population), [1, 2, 1, 2, 2, 2, 1])
     self.assertEqual(list(tab.child), [0, 0, 1, 1, 2, 3, 4])
예제 #4
0
 def test_multiple_trees_edges_are_squashed(self):
     ts = tskit.load_text(nodes=self.nodes1,
                          edges=self.edges1,
                          strict=False)
     tab = slime.get_ancestry_table(ts, [3])
     self.assertEqual(list(tab.left), [0, 0, 0, 0, 0])
     self.assertEqual(list(tab.right), [1, 1, 1, 1, 1])
     self.assertEqual(list(tab.population), [3, 3, 3, 3, 3])
     self.assertEqual(list(tab.child), [0, 1, 2, 3, 4])
예제 #5
0
 def test_one_population(self):
     ts = tskit.load_text(nodes=self.nodes0,
                          edges=self.edges0,
                          strict=False)
     tab = slime.get_ancestry_table(ts, [1, 3])
     self.assertEqual(list(tab.left), [0, 0])
     self.assertEqual(list(tab.right), [1, 1])
     self.assertEqual(list(tab.population), [1, 1])
     self.assertEqual(list(tab.child), [1, 2])
예제 #6
0
 def test_no_ancestors(self):
     ts = tskit.load_text(nodes=self.nodes0,
                          edges=self.edges0,
                          strict=False)
     with self.assertRaises(ValueError):
         slime.get_ancestry_table(ts, samples=[0], populations=[3])
예제 #7
0
 def test_no_rows(self):
     ts = tskit.load_text(nodes=self.nodes0,
                          edges=self.edges0,
                          strict=False)
     tab = slime.get_ancestry_table(ts, samples=[0], populations=[1])
     self.assertEqual(tab.num_rows, 0)
예제 #8
0
 def test_simple_case(self):
     tab = slime.get_ancestry_table(self.ts_ex, list(self.populations_ex))