def test_from_single_locus_decapitated(self): ts = msprime.simulate(10, random_seed=5) from_ts = tsutil.decapitate(ts, ts.num_edges // 2) start_time = from_ts.tables.nodes.time.max() final_ts = msprime.simulate( from_ts=from_ts, start_time=start_time, random_seed=2) self.verify_from_tables(from_ts, final_ts, start_time) self.verify_simulation_completed(final_ts)
def test_decapitated_mutations(self): ts = msprime.simulate(10, random_seed=5, mutation_rate=10) from_ts = tsutil.decapitate(ts, ts.num_edges // 2) self.assertGreater(from_ts.num_mutations, 0) start_time = from_ts.tables.nodes.time.max() final_ts = msprime.simulate( from_ts=from_ts, start_time=start_time, random_seed=2) self.verify_from_tables(from_ts, final_ts, start_time) self.verify_simulation_completed(final_ts)
def test_from_multi_locus_old_recombination(self): ts = msprime.simulate(10, recombination_rate=2, random_seed=5) self.assertGreater(ts.num_trees, 1) from_ts = tsutil.decapitate(ts, ts.num_edges // 2) start_time = from_ts.tables.nodes.time.max() final_ts = msprime.simulate( from_ts=from_ts, start_time=start_time, random_seed=2, recombination_rate=2) self.verify_from_tables(from_ts, final_ts, start_time) self.verify_simulation_completed(final_ts)
def test_from_multi_locus_old_recombination(self): ts = msprime.simulate(10, recombination_rate=2, random_seed=5) self.assertGreater(ts.num_trees, 1) from_ts = tsutil.decapitate(ts, ts.num_edges // 2) start_time = from_ts.tables.nodes.time.max() final_ts = msprime.simulate(from_ts=from_ts, start_time=start_time, random_seed=2, recombination_rate=2) self.verify_from_tables(from_ts, final_ts, start_time) self.verify_simulation_completed(final_ts)
def get_example_base(self, num_populations=1, length=1): N = num_populations population_configurations = [ msprime.PopulationConfiguration() for _ in range(N)] migration_matrix = np.ones((N, N)) np.fill_diagonal(migration_matrix, 0) ts = msprime.simulate( samples=[msprime.Sample(0, 0) for _ in range(10)], length=length, random_seed=155, population_configurations=population_configurations, migration_matrix=migration_matrix) return tsutil.decapitate(ts, ts.num_edges // 2)
def get_example_base(self, num_populations=1, length=1): N = num_populations population_configurations = [ msprime.PopulationConfiguration() for _ in range(N) ] migration_matrix = np.ones((N, N)) np.fill_diagonal(migration_matrix, 0) ts = msprime.simulate( samples=[msprime.Sample(0, 0) for _ in range(10)], length=length, random_seed=155, population_configurations=population_configurations, migration_matrix=migration_matrix) return tsutil.decapitate(ts, ts.num_edges // 2)
def get_mutations_over_roots_tree(self): ts = msprime.simulate(15, random_seed=1) ts = tsutil.decapitate(ts, 20) tables = ts.dump_tables() delta = 1.0 / (ts.num_nodes + 1) x = 0 for node in range(ts.num_nodes): site_id = tables.sites.add_row(x, ancestral_state="0") x += delta tables.mutations.add_row(site_id, node=node, derived_state="1") ts = tables.tree_sequence() tree = ts.first() assert any( tree.parent(mut.node) == tskit.NULL for mut in tree.mutations()) return tree
def get_mutations_over_roots_tree(self): ts = msprime.simulate(15, random_seed=1) ts = tsutil.decapitate(ts, 20) tables = ts.tables sites = msprime.SiteTable() mutations = msprime.MutationTable() delta = 1.0 / (ts.num_nodes + 1) x = 0 for node in range(ts.num_nodes): site_id = sites.add_row(x, ancestral_state="0") x += delta mutations.add_row(site_id, node=node, derived_state="1") ts = msprime.load_tables( nodes=tables.nodes, edges=tables.edges, sites=sites, mutations=mutations) tree = ts.first() assert any( tree.parent(mut.node) == msprime.NULL_NODE for mut in tree.mutations()) return tree
def test_from_two_populations_decapitated(self): from_ts = msprime.simulate( recombination_rate=2, random_seed=5, population_configurations=[ msprime.PopulationConfiguration(5), msprime.PopulationConfiguration(5)], migration_matrix=[[0, 1], [1, 0]]) from_ts = tsutil.decapitate(from_ts, from_ts.num_edges // 3) self.assertTrue(any(tree.num_roots > 1 for tree in from_ts.trees())) self.assertGreater(from_ts.num_trees, 1) start_time = from_ts.tables.nodes.time.max() final_ts = msprime.simulate( from_ts=from_ts, start_time=start_time, random_seed=2, recombination_rate=2, population_configurations=[ msprime.PopulationConfiguration(), msprime.PopulationConfiguration()], migration_matrix=[[0, 1], [1, 0]]) self.verify_from_tables(from_ts, final_ts, start_time) self.verify_simulation_completed(final_ts)
def test_many_populations(self): for N in range(1, 6): population_configurations = [ msprime.PopulationConfiguration() for _ in range(N)] migration_matrix = np.ones((N, N)) np.fill_diagonal(migration_matrix, 0) from_ts = msprime.simulate( samples=[msprime.Sample(0, 0) for _ in range(10)], recombination_rate=2, random_seed=15, population_configurations=population_configurations, migration_matrix=migration_matrix) from_ts = tsutil.decapitate(from_ts, from_ts.num_edges // 3) self.assertTrue(any(tree.num_roots > 1 for tree in from_ts.trees())) self.assertGreater(from_ts.num_trees, 1) start_time = from_ts.tables.nodes.time.max() final_ts = msprime.simulate( from_ts=from_ts, start_time=start_time, random_seed=8, recombination_rate=2, population_configurations=population_configurations, migration_matrix=migration_matrix) self.verify_from_tables(from_ts, final_ts, start_time) self.verify_simulation_completed(final_ts)
def test_from_two_populations_decapitated(self): from_ts = msprime.simulate(recombination_rate=2, random_seed=5, population_configurations=[ msprime.PopulationConfiguration(5), msprime.PopulationConfiguration(5) ], migration_matrix=[[0, 1], [1, 0]]) from_ts = tsutil.decapitate(from_ts, from_ts.num_edges // 3) self.assertTrue(any(tree.num_roots > 1 for tree in from_ts.trees())) self.assertGreater(from_ts.num_trees, 1) start_time = from_ts.tables.nodes.time.max() final_ts = msprime.simulate(from_ts=from_ts, start_time=start_time, random_seed=2, recombination_rate=2, population_configurations=[ msprime.PopulationConfiguration(), msprime.PopulationConfiguration() ], migration_matrix=[[0, 1], [1, 0]]) self.verify_from_tables(from_ts, final_ts, start_time) self.verify_simulation_completed(final_ts)
def test_jukes_cantor_n50_multiroot(self): ts = msprime.simulate(50, random_seed=1) ts = tsutil.decapitate(ts, ts.num_edges // 2) ts = tsutil.jukes_cantor(ts, 5, 2, seed=2) self.verify(ts)
def test_jukes_cantor_n15_multiroot(self): ts = msprime.simulate(15, random_seed=1) ts = tsutil.decapitate(ts, ts.num_edges // 3) ts = tsutil.jukes_cantor(ts, 15, 2, seed=3) self.verify(ts)
def test_infinite_sites_n20_multiroot(self): ts = msprime.simulate(20, mutation_rate=3, random_seed=3) self.verify(tsutil.decapitate(ts, ts.num_edges // 2))