예제 #1
0
 def verify(self, ts):
     tsp = self.infer(ts,
                      "P",
                      path_compression=self.path_compression_enabled)
     tsc = self.infer(ts,
                      "C",
                      path_compression=self.path_compression_enabled)
     self.assertEqual(ts.num_sites, tsp.num_sites)
     self.assertEqual(ts.num_sites, tsc.num_sites)
     self.assertEqual(tsc.num_samples, tsp.num_samples)
     if self.path_compression_enabled:
         # With path compression we have to check the tree metrics.
         p_breakpoints, distance = tsinfer.compare(ts, tsp)
         self.assertTrue(np.all(distance == 0))
         c_breakpoints, distance = tsinfer.compare(ts, tsc)
         self.assertTrue(np.all(distance == 0))
         self.assertTrue(np.all(p_breakpoints == c_breakpoints))
     else:
         # Without path compression we're guaranteed to return precisely the
         # same tree sequences.
         tables_p = tsp.dump_tables()
         tables_c = tsc.dump_tables()
         self.assertEqual(tables_p.nodes, tables_c.nodes)
         self.assertEqual(tables_p.edges, tables_c.edges)
         self.assertEqual(tables_p.sites, tables_c.sites)
         self.assertEqual(tables_p.mutations, tables_c.mutations)
예제 #2
0
 def test_single_tree(self):
     n = 15
     for seed in range(1, 10):
         ts1 = msprime.simulate(n, random_seed=seed)
         ts2 = msprime.simulate(n, random_seed=seed + 1)
         bp, distance = tsinfer.compare(ts1, ts2)
         self.assertEqual(list(bp), [0, 1])
         self.assertEqual(distance.shape, (1, ))
예제 #3
0
 def test_single_tree(self):
     n = 15
     for seed in range(1, 10):
         ts1 = msprime.simulate(n, random_seed=seed)
         ts2 = msprime.simulate(n, random_seed=seed + 1)
         bp, distance = tsinfer.compare(ts1, ts2)
         assert list(bp) == [0, 1]
         assert distance.shape == (1, )
예제 #4
0
 def test_sample_20_smc_path_compression(self):
     base_ts = get_smc_simulation(20, L=5, recombination_rate=10, seed=111)
     self.assertGreater(base_ts.num_trees, 5)
     ts, inferred_ts = tsinfer.run_perfect_inference(base_ts, path_compression=True)
     # We can't just compare tables when doing path compression because
     # we'll find different ways of expressing the same trees.
     breakpoints, distances = tsinfer.compare(ts, inferred_ts)
     self.assertTrue(np.all(distances == 0))
예제 #5
0
 def test_single_tree_many_trees(self):
     n = 5
     for seed in range(1, 10):
         ts1 = msprime.simulate(n, recombination_rate=5, random_seed=seed)
         ts2 = msprime.simulate(n, random_seed=seed + 1)
         self.assertGreater(ts1.num_trees, 1)
         bp, distance = tsinfer.compare(ts1, ts2)
         self.assertEqual(list(bp), list(ts1.breakpoints()))
         self.assertEqual(distance.shape, (ts1.num_trees, ))
예제 #6
0
 def test_same_ts(self):
     n = 15
     for seed in range(1, 10):
         ts = msprime.simulate(n, recombination_rate=10, random_seed=seed)
         self.assertGreater(ts.num_trees, 1)
         bp, distance = tsinfer.compare(ts, ts)
         self.assertEqual(list(bp), list(ts.breakpoints()))
         self.assertEqual(distance.shape, (bp.shape[0] - 1, ))
         self.assertTrue(np.all(distance == 0))
예제 #7
0
 def test_single_tree_many_trees(self):
     n = 5
     for seed in range(1, 10):
         ts1 = msprime.simulate(n, recombination_rate=5, random_seed=seed)
         ts2 = msprime.simulate(n, random_seed=seed + 1)
         assert ts1.num_trees > 1
         bp, distance = tsinfer.compare(ts1, ts2)
         assert list(bp) == list(ts1.breakpoints())
         assert distance.shape == (ts1.num_trees, )
예제 #8
0
 def test_same_ts(self):
     n = 15
     for seed in range(1, 10):
         ts = msprime.simulate(n, recombination_rate=10, random_seed=seed)
         assert ts.num_trees > 1
         bp, distance = tsinfer.compare(ts, ts)
         assert list(bp) == list(ts.breakpoints())
         assert distance.shape == (bp.shape[0] - 1, )
         assert np.all(distance == 0)
예제 #9
0
 def test_small_use_ts_path_compression(self):
     base_ts = msprime.simulate(5, recombination_rate=10, random_seed=112)
     self.assertGreater(base_ts.num_trees, 1)
     for engine in [tsinfer.PY_ENGINE, tsinfer.C_ENGINE]:
         ts, inferred_ts = tsinfer.run_perfect_inference(
             base_ts, use_ts=True, path_compression=True, engine=engine)
         # We can't just compare tables when doing path compression because
         # we'll find different ways of expressing the same trees.
         breakpoints, distances = tsinfer.compare(ts, inferred_ts)
         self.assertTrue(np.all(distances == 0))
예제 #10
0
 def test_small_smc_path_compression(self):
     base_ts = get_smc_simulation(5, L=1, recombination_rate=10, seed=111)
     assert base_ts.num_trees > 1
     for engine in [tsinfer.PY_ENGINE, tsinfer.C_ENGINE]:
         ts, inferred_ts = tsinfer.run_perfect_inference(
             base_ts, engine=engine, path_compression=True)
         # We can't just compare tables when doing path compression because
         # we'll find different ways of expressing the same trees.
         breakpoints, distances = tsinfer.compare(ts, inferred_ts)
         assert np.all(distances == 0)