How to use the msprime.SimulationModelChange function in msprime

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_models.py View on Github external
def test_many_models(self):
        Ne = 10000
        ts = msprime.simulate(
            Ne=Ne,
            sample_size=10,
            recombination_rate=0.1,
            demographic_events=[
                msprime.SimulationModelChange(10, msprime.StandardCoalescent(Ne)),
                msprime.SimulationModelChange(20, msprime.SmcApproxCoalescent(Ne)),
                msprime.SimulationModelChange(30, msprime.SmcPrimeApproxCoalescent(Ne)),
                msprime.SimulationModelChange(
                    40, msprime.DiscreteTimeWrightFisher(100)),
                msprime.SimulationModelChange(
                    50, msprime.BetaCoalescent(reference_size=10)),
                msprime.SimulationModelChange(60, msprime.StandardCoalescent(0.1))],
            random_seed=10)
        for tree in ts.trees():
            self.assertEqual(tree.num_roots, 1)
github tskit-dev / msprime / tests / test_models.py View on Github external
def test_wf_hudson_single_locus(self):
        Ne = 100
        t = 10
        ts = msprime.simulate(
            sample_size=10,
            model=msprime.DiscreteTimeWrightFisher(Ne),
            demographic_events=[
                msprime.SimulationModelChange(t, msprime.StandardCoalescent(Ne))],
            random_seed=2)
        tree = ts.first()
        self.assertEqual(tree.num_roots, 1)
        times = ts.tables.nodes.time
        dtwf_times = times[np.logical_and(times > 0, times < t)]
        self.assertGreater(dtwf_times.shape[0], 0)
        self.assertTrue(np.all(dtwf_times == np.floor(dtwf_times)))
        coalescent_times = times[times > t]
        self.assertGreater(coalescent_times.shape[0], 0)
github tskit-dev / msprime / tests / test_demography.py View on Github external
def test_bad_simulation_model(self):
        for model in [[], {}]:
            des = [msprime.SimulationModelChange(time=0, model=model)]
            with self.assertRaises(TypeError):
                msprime.simulate(10, demographic_events=des)
github tskit-dev / msprime / tests / test_models.py View on Github external
def test_sweep_start_time_complete(self):
        sweep_model = msprime.SweepGenicSelection(
            reference_size=0.25, position=0.5, start_frequency=0.6,
            end_frequency=0.7, alpha=0.9, dt=0.001)
        t_start = 0.1
        ts = msprime.simulate(
            10, Ne=0.25,
            recombination_rate=2,
            demographic_events=[
                msprime.SimulationModelChange(t_start, sweep_model)],
            num_labels=2, random_seed=2)
        self.assertTrue(all(tree.num_roots == 1 for tree in ts.trees()))
github tskit-dev / msprime / tests / test_models.py View on Github external
def test_wf_hudson_back_and_forth(self):
        Ne = 100
        t1 = 100
        t2 = 200
        ts = msprime.simulate(
            sample_size=10,
            model=msprime.DiscreteTimeWrightFisher(Ne),
            recombination_rate=0.1,
            demographic_events=[
                msprime.SimulationModelChange(t1, msprime.StandardCoalescent(Ne)),
                msprime.SimulationModelChange(t2, msprime.DiscreteTimeWrightFisher(Ne))],
            random_seed=2)
        tree = ts.first()
        self.assertEqual(tree.num_roots, 1)
        times = ts.tables.nodes.time
        dtwf_times = times[np.logical_and(times > 0, times < t1, times > t2)]
        self.assertGreater(dtwf_times.shape[0], 0)
        self.assertTrue(np.all(dtwf_times == np.floor(dtwf_times)))
        coalescent_times = times[np.logical_and(times > t1, times < t2)]
        self.assertGreater(coalescent_times.shape[0], 0)
        self.assertTrue(np.all(coalescent_times != np.floor(coalescent_times)))
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)
github tskit-dev / msprime / tests / test_models.py View on Github external
def test_many_models(self):
        Ne = 10000
        ts = msprime.simulate(
            Ne=Ne,
            sample_size=10,
            recombination_rate=0.1,
            demographic_events=[
                msprime.SimulationModelChange(10, msprime.StandardCoalescent(Ne)),
                msprime.SimulationModelChange(20, msprime.SmcApproxCoalescent(Ne)),
                msprime.SimulationModelChange(30, msprime.SmcPrimeApproxCoalescent(Ne)),
                msprime.SimulationModelChange(
                    40, msprime.DiscreteTimeWrightFisher(100)),
                msprime.SimulationModelChange(
                    50, msprime.BetaCoalescent(reference_size=10)),
                msprime.SimulationModelChange(60, msprime.StandardCoalescent(0.1))],
            random_seed=10)
        for tree in ts.trees():
            self.assertEqual(tree.num_roots, 1)
github tskit-dev / msprime / tests / test_models.py View on Github external
def test_many_models(self):
        Ne = 10000
        ts = msprime.simulate(
            Ne=Ne,
            sample_size=10,
            recombination_rate=0.1,
            demographic_events=[
                msprime.SimulationModelChange(10, msprime.StandardCoalescent(Ne)),
                msprime.SimulationModelChange(20, msprime.SmcApproxCoalescent(Ne)),
                msprime.SimulationModelChange(30, msprime.SmcPrimeApproxCoalescent(Ne)),
                msprime.SimulationModelChange(
                    40, msprime.DiscreteTimeWrightFisher(100)),
                msprime.SimulationModelChange(
                    50, msprime.BetaCoalescent(reference_size=10)),
                msprime.SimulationModelChange(60, msprime.StandardCoalescent(0.1))],
            random_seed=10)
        for tree in ts.trees():
            self.assertEqual(tree.num_roots, 1)
github tskit-dev / msprime / docs / examples.py View on Github external
def hybrid_sim_example():
    ts = msprime.simulate(
        sample_size=10, Ne=1000, model="dtwf", random_seed=2,
        demographic_events=[
            msprime.SimulationModelChange(time=100, model="hudson")])
    print(ts.tables.nodes)