How to use msprime - 10 common examples

To help you get started, we’ve selected a few msprime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tskit-dev / msprime / tests / test_simulate_from.py View on Github external
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)
github tskit-dev / msprime / tests / test_zero_waiting_time.py View on Github external
def _ancient_sample_test(self,
            num_modern=1000, anc_pop=0, anc_num=1, anc_time=200,
            split_time_anc=400, Ne0=10000, Ne1=10000, length=1000):
        samples = [msp.Sample(population=0, time=0)]*num_modern
        samples.extend(
            [msp.Sample(population=anc_pop, time=anc_time)]*(2*anc_num))
        pop_config = [msp.PopulationConfiguration(
            initial_size=Ne0), msp.PopulationConfiguration(initial_size=Ne1)]
        divergence = [msp.MassMigration(
            time=split_time_anc, source=1, destination=0, proportion=1.0)]
        seed = 94320219
        sims = msp.simulate(
            samples=samples, Ne=Ne0, population_configurations=pop_config,
            demographic_events=divergence, length=length,
            random_seed=seed)
        return sims
github tskit-dev / msprime / tests / test_topology.py View on Github external
def test_many_trees(self):
        ts = msprime.simulate(5, recombination_rate=4, random_seed=self.random_seed)
        self.assertGreater(ts.num_trees, 2)
        self.verify_single_childified(ts)
        self.verify_multiroot_internal_samples(ts)
github tskit-dev / msprime / tskit_tests / test_stats.py View on Github external
def test_two_populations_high_migration(self):
        ts = msprime.simulate(
            population_configurations=[
                msprime.PopulationConfiguration(8),
                msprime.PopulationConfiguration(8)],
            migration_matrix=[[0, 1], [1, 0]],
            recombination_rate=3,
            random_seed=5)
        self.assertGreater(ts.num_trees, 1)
        self.verify(ts, [ts.samples(0), ts.samples(1)])
github tskit-dev / msprime / tests / test_topology.py View on Github external
def test_single_tree_recurrent_mutations(self):
        ts = msprime.simulate(6, random_seed=10)
        for mutations_per_branch in [1, 2, 3]:
            ts = tsutil.insert_branch_mutations(ts, mutations_per_branch)
            for num_samples in range(1, ts.num_samples):
                for samples in itertools.combinations(ts.samples(), num_samples):
                    self.verify_simplify_haplotypes(ts, samples)
github tskit-dev / pyslim / tests / __init__.py View on Github external
msprime.MassMigration(
            time=5, source=1, destination=0, proportion=1.0)
        ]
        for n in [2, 10, 20]:
            for mutrate in [0.0]:
                for recrate in [0.0, 0.01]:
                    yield msprime.simulate(n, mutation_rate=mutrate,
                                           recombination_rate=recrate,
                                           length=200)
                    population_configurations =[
                        msprime.PopulationConfiguration(
                        sample_size=n, initial_size=100),
                        msprime.PopulationConfiguration(
                        sample_size=n, initial_size=100)
                    ]
                    yield msprime.simulate(
                        population_configurations=population_configurations,
                        demographic_events=demographic_events,
                        recombination_rate=recrate,
                        mutation_rate=mutrate,
                        length=250)
github tskit-dev / msprime / tskit_tests / test_newick.py View on Github external
def get_binary_example(self):
        ts = msprime.simulate(
            sample_size=25, recombination_rate=5, random_seed=self.random_seed)
        return ts
github tskit-dev / tsinfer / tests / test_provenance.py View on Github external
def test_ancestors_file(self):
        ts = msprime.simulate(10, mutation_rate=1, random_seed=1)
        self.assertGreater(ts.num_sites, 1)
        sample_data = tsinfer.SampleData.from_tree_sequence(ts)
        ancestor_data = tsinfer.generate_ancestors(sample_data)
        self.validate_file(ancestor_data)
github tskit-dev / msprime / tests / test_provenance.py View on Github external
def test_simplify(self):
        ts = msprime.simulate(5, random_seed=1)
        ts = ts.simplify()
        prov = json.loads(ts.provenance(1).record)
        tskit.validate_provenance(prov)
        self.assertEqual(prov["parameters"]["command"], "simplify")
github tskit-dev / msprime / tests / test_models.py View on Github external
def test_wf_hudson_different_specifications(self):
        Ne = 100
        t = 100
        ts1 = msprime.simulate(
            sample_size=10,
            model=msprime.DiscreteTimeWrightFisher(Ne),
            recombination_rate=0.1,
            demographic_events=[
                msprime.SimulationModelChange(t, msprime.StandardCoalescent(Ne))],
            random_seed=2)
        ts2 = msprime.simulate(
            sample_size=10, recombination_rate=0.1,
            Ne=Ne, model="dtwf",
            demographic_events=[msprime.SimulationModelChange(t, "hudson")],
            random_seed=2)
        ts3 = msprime.simulate(
            sample_size=10, recombination_rate=0.1,
            Ne=Ne, model="dtwf",
            demographic_events=[msprime.SimulationModelChange(t)],
            random_seed=2)
        t1 = ts1.dump_tables()
        t2 = ts2.dump_tables()
        t3 = ts3.dump_tables()
        t1.provenances.clear()
        t2.provenances.clear()
        t3.provenances.clear()
        self.assertEqual(t1, t2)
        self.assertEqual(t1, t3)