Exemplo n.º 1
0
 def test_beta_coalescent_parameters(self):
     N = 1000
     dbl_max = sys.float_info.max
     for alpha in [1.01, 1.5, 1.99]:
         model = msprime.BetaCoalescent(N, alpha)
         self.assertEqual(model.population_size, N)
         self.assertEqual(model.alpha, alpha)
         self.assertEqual(model.truncation_point, dbl_max)
         d = model.get_ll_representation()
         self.assertEqual(
             d, {
                 "name": "beta",
                 "population_size": N,
                 "alpha": alpha,
                 "truncation_point": dbl_max
             })
     alpha = 1.5
     for truncation_point in [0, 3, 1e6]:
         model = msprime.BetaCoalescent(N, alpha, truncation_point)
         self.assertEqual(model.population_size, N)
         self.assertEqual(model.alpha, alpha)
         self.assertEqual(model.truncation_point, truncation_point)
         d = model.get_ll_representation()
         self.assertEqual(
             d, {
                 "name": "beta",
                 "population_size": N,
                 "alpha": alpha,
                 "truncation_point": truncation_point
             })
Exemplo n.º 2
0
 def test_beta_coalescent_parameters(self):
     for alpha in [1.01, 1.5, 1.99]:
         model = msprime.BetaCoalescent(alpha)
         self.assertEqual(model.alpha, alpha)
         self.assertEqual(model.truncation_point, 1)
         d = model.get_ll_representation()
         self.assertEqual(
             d,
             {
                 "name": "beta",
                 "alpha": alpha,
                 "truncation_point": 1
             },
         )
     alpha = 1.5
     for truncation_point in [0.01, 0.5, 1]:
         model = msprime.BetaCoalescent(alpha, truncation_point)
         self.assertEqual(model.alpha, alpha)
         self.assertEqual(model.truncation_point, truncation_point)
         d = model.get_ll_representation()
         self.assertEqual(
             d,
             {
                 "name": "beta",
                 "alpha": alpha,
                 "truncation_point": truncation_point
             },
         )
Exemplo n.º 3
0
 def test_beta_coalescent_parameters(self):
     for alpha in [1.01, 1.5, 1.99]:
         model = msprime.BetaCoalescent(alpha=alpha, truncation_point=1)
         assert model.alpha == alpha
         assert model.truncation_point == 1
         d = model._as_lowlevel()
         assert d == {
             "name": "beta",
             "duration": None,
             "alpha": alpha,
             "truncation_point": 1,
         }
     alpha = 1.5
     for truncation_point in [0.01, 0.5, 1]:
         model = msprime.BetaCoalescent(alpha=alpha,
                                        truncation_point=truncation_point)
         assert model.alpha == alpha
         assert model.truncation_point == truncation_point
         d = model._as_lowlevel()
         assert d == {
             "name": "beta",
             "alpha": alpha,
             "truncation_point": truncation_point,
             "duration": None,
         }
Exemplo n.º 4
0
 def test_many_models_simulate(self):
     Ne = 10000
     ts = msprime.simulate(
         Ne=Ne,
         sample_size=10,
         # Use the old-style SimulationModelChange
         model=[
             "hudson",
             msprime.SimulationModelChange(10,
                                           msprime.StandardCoalescent()),
             msprime.SimulationModelChange(20,
                                           msprime.SmcApproxCoalescent()),
             msprime.SimulationModelChange(
                 30, msprime.SmcPrimeApproxCoalescent()),
             msprime.SimulationModelChange(
                 40, msprime.DiscreteTimeWrightFisher()),
             msprime.SimulationModelChange(
                 50, msprime.BetaCoalescent(alpha=1.1)),
             msprime.SimulationModelChange(60,
                                           msprime.StandardCoalescent()),
         ],
         random_seed=10,
     )
     for tree in ts.trees():
         assert tree.num_roots == 1
Exemplo n.º 5
0
 def test_beta_coalescent(self):
     model = msprime.BetaCoalescent(population_size=5,
                                    alpha=1.5,
                                    truncation_point=10)
     ts = msprime.simulate(sample_size=10, model=model)
     # TODO real tests
     self.assertTrue(ts is not None)
Exemplo n.º 6
0
 def test_multiple_mergers(self):
     for model in [msprime.BetaCoalescent(10), msprime.DiracCoalescent(10)]:
         self.assertRaises(_msprime.LibraryError,
                           msprime.simulate,
                           10,
                           model=model,
                           record_full_arg=True)
Exemplo n.º 7
0
 def test_many_models(self):
     Ne = 10000
     ts = msprime.simulate(
         Ne=Ne,
         sample_size=10,
         recombination_rate=0.1,
         model=[
             "hudson",
             msprime.SimulationModelChange(10,
                                           msprime.StandardCoalescent()),
             msprime.SimulationModelChange(20,
                                           msprime.SmcApproxCoalescent()),
             msprime.SimulationModelChange(
                 30, msprime.SmcPrimeApproxCoalescent()),
             msprime.SimulationModelChange(
                 40, msprime.DiscreteTimeWrightFisher()),
             msprime.SimulationModelChange(
                 50,
                 msprime.BetaCoalescent(alpha=1.1, truncation_point=1),
             ),
             msprime.SimulationModelChange(60,
                                           msprime.StandardCoalescent()),
         ],
         random_seed=10,
     )
     for tree in ts.trees():
         self.assertEqual(tree.num_roots, 1)
Exemplo n.º 8
0
    def test_beta_coalescent(self):
        model = msprime.BetaCoalescent(alpha=1, truncation_point=2)
        assert model.duration is None
        assert model.alpha == 1
        assert model.truncation_point == 2

        model = msprime.BetaCoalescent(alpha=2, truncation_point=1, duration=3)
        assert model.duration == 3
        assert model.alpha == 2
        assert model.truncation_point == 1

        model = msprime.BetaCoalescent()
        assert model.duration is None
        assert model.alpha is None

        with pytest.raises(TypeError, match="takes 1 positional"):
            msprime.BetaCoalescent(1)
Exemplo n.º 9
0
 def test_beta_coalescent_parameters(self):
     for alpha in [1.01, 1.5, 1.99]:
         model = msprime.BetaCoalescent(alpha, truncation_point=1)
         assert model.alpha == alpha
         assert model.truncation_point == 1
         d = model.get_ll_representation()
         assert d == {"name": "beta", "alpha": alpha, "truncation_point": 1}
     alpha = 1.5
     for truncation_point in [0.01, 0.5, 1]:
         model = msprime.BetaCoalescent(alpha, truncation_point)
         assert model.alpha == alpha
         assert model.truncation_point == truncation_point
         d = model.get_ll_representation()
         assert d == {
             "name": "beta",
             "alpha": alpha,
             "truncation_point": truncation_point,
         }
Exemplo n.º 10
0
 def test_simulation_model_change(self):
     examples = [
         msprime.SimulationModelChange(),
         msprime.SimulationModelChange(model="hudson"),
         msprime.SimulationModelChange(
             model=msprime.DiscreteTimeWrightFisher()),
         msprime.SimulationModelChange(
             model=msprime.BetaCoalescent(alpha=1, truncation_point=2)),
     ]
     self.assert_repr_round_trip(examples)
Exemplo n.º 11
0
    def test_encode_simulation_models(self):
        simple_model = ["hudson", [10, "dtwf"], [20, "smc"], [None, None]]
        ts = msprime.simulate(10, model=simple_model)
        decoded = self.decode(ts.provenance(0).record)
        parameters = decoded.parameters
        self.assertEqual(parameters.sample_size, 10)
        self.assertEqual(list(parameters.model), simple_model)

        model_instances = [
            msprime.StandardCoalescent(),
            msprime.SimulationModelChange(10,
                                          msprime.DiscreteTimeWrightFisher()),
            msprime.SimulationModelChange(20, msprime.SmcApproxCoalescent()),
            msprime.SimulationModelChange(30,
                                          msprime.BetaCoalescent(alpha=1.1)),
        ]
        ts = msprime.simulate(10, model=model_instances)
        decoded = self.decode(ts.provenance(0).record)
        parameters = decoded.parameters
        self.assertEqual(parameters.sample_size, 10)
        self.assertEqual(parameters.model[0],
                         {"__class__": "msprime.ancestry.StandardCoalescent"})
        self.assertDictEqual(
            parameters.model[1],
            {
                "__class__": "msprime.ancestry.SimulationModelChange",
                "model": {
                    "__class__": "msprime.ancestry.DiscreteTimeWrightFisher"
                },
                "time": 10,
            },
        )
        self.assertDictEqual(
            parameters.model[2],
            {
                "__class__": "msprime.ancestry.SimulationModelChange",
                "model": {
                    "__class__": "msprime.ancestry.SmcApproxCoalescent"
                },
                "time": 20,
            },
        )
        self.assertDictEqual(
            parameters.model[3],
            {
                "__class__": "msprime.ancestry.SimulationModelChange",
                "model": {
                    "__class__": "msprime.ancestry.BetaCoalescent",
                    "alpha": 1.1,
                    "truncation_point": 1.0,
                },
                "time": 30,
            },
        )
Exemplo n.º 12
0
 def test_simulation_models(self):
     examples = [
         msprime.StandardCoalescent(),
         msprime.SmcApproxCoalescent(),
         msprime.SmcPrimeApproxCoalescent(),
         msprime.DiscreteTimeWrightFisher(),
         msprime.WrightFisherPedigree(),
         msprime.BetaCoalescent(),
         msprime.BetaCoalescent(alpha=1, truncation_point=10),
         msprime.DiracCoalescent(),
         msprime.DiracCoalescent(psi=1234, c=56),
         msprime.SweepGenicSelection(
             position=1,
             start_frequency=0.5,
             end_frequency=0.9,
             alpha=1,
             dt=1e-4,
         ),
     ]
     self.assert_repr_round_trip(examples)
Exemplo n.º 13
0
 def test_beta_coalescent_parameters(self):
     dbl_max = sys.float_info.max
     for alpha in [-1, 0, 1.1]:
         model = msprime.BetaCoalescent(alpha)
         self.assertEqual(model.alpha, alpha)
         self.assertEqual(model.truncation_point, dbl_max)
         d = model.get_ll_representation()
         self.assertEqual(d, {
             "name": "beta",
             "alpha": alpha,
             "truncation_point": dbl_max
         })
     alpha = 2
     for truncation_point in [0, 3, 1e6]:
         model = msprime.BetaCoalescent(alpha, truncation_point)
         self.assertEqual(model.alpha, alpha)
         self.assertEqual(model.truncation_point, truncation_point)
         d = model.get_ll_representation()
         self.assertEqual(
             d, {
                 "name": "beta",
                 "alpha": alpha,
                 "truncation_point": truncation_point
             })
Exemplo n.º 14
0
    def test_simulation_models(self):
        simple_model = ["hudson", [10, "dtwf"], [20, "smc"]]
        ts = msprime.simulate(10, model=simple_model)
        self.verify(ts)

        model_instances = [
            msprime.StandardCoalescent(),
            msprime.SimulationModelChange(10,
                                          msprime.DiscreteTimeWrightFisher()),
            msprime.SimulationModelChange(20, msprime.SmcApproxCoalescent()),
            msprime.SimulationModelChange(30,
                                          msprime.BetaCoalescent(alpha=1.1)),
        ]
        ts = msprime.simulate(10, model=model_instances)
        self.verify(ts)
Exemplo n.º 15
0
 def test_many_models_sim_ancestry(self):
     ts = msprime.sim_ancestry(
         samples=10,
         population_size=10_000,
         model=[
             msprime.StandardCoalescent(duration=10),
             msprime.SmcApproxCoalescent(duration=10),
             msprime.SmcPrimeApproxCoalescent(duration=10),
             msprime.DiscreteTimeWrightFisher(duration=10),
             msprime.BetaCoalescent(alpha=1.1, duration=10),
             msprime.StandardCoalescent(),
         ],
         random_seed=10,
     )
     for tree in ts.trees():
         assert tree.num_roots == 1
Exemplo n.º 16
0
 def test_model_instances(self):
     models = [
         msprime.StandardCoalescent(100),
         msprime.SmcApproxCoalescent(30),
         msprime.SmcPrimeApproxCoalescent(2132),
         msprime.DiscreteTimeWrightFisher(500),
         msprime.SweepGenicSelection(
             reference_size=500, position=0.5, start_frequency=0.1,
             end_frequency=0.9, alpha=0.1, dt=0.01),
         msprime.DiracCoalescent(),
         msprime.BetaCoalescent(),
     ]
     for model in models:
         new_model = msprime.model_factory(model=model)
         self.assertFalse(new_model is model)
         self.assertEqual(new_model.__dict__, model.__dict__)
Exemplo n.º 17
0
 def test_model_instances(self):
     for bad_type in [1234, {}]:
         self.assertRaises(TypeError,
                           msprime.simulator_factory,
                           sample_size=2,
                           model=bad_type)
     models = [
         msprime.StandardCoalescent(),
         msprime.SmcApproxCoalescent(),
         msprime.SmcPrimeApproxCoalescent(),
         msprime.BetaCoalescent(),
         msprime.DiracCoalescent(),
     ]
     for model in models:
         sim = msprime.simulator_factory(sample_size=10, model=model)
         self.assertEqual(sim.get_model(), model)
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
    def verify_simulation_models(self, sim_func):
        simple_model = ["hudson", [10, "dtwf"], [20, "smc"], [None, None]]
        ts = sim_func(10, model=simple_model)
        decoded = self.decode(ts.provenance(0).record)
        parameters = decoded.parameters
        assert list(parameters.model) == simple_model

        model_instances = [
            msprime.StandardCoalescent(),
            msprime.SimulationModelChange(10,
                                          msprime.DiscreteTimeWrightFisher()),
            msprime.SimulationModelChange(20, msprime.SmcApproxCoalescent()),
            msprime.SimulationModelChange(
                30, msprime.BetaCoalescent(alpha=1.1, truncation_point=1)),
        ]
        ts = sim_func(10, model=model_instances)
        decoded = self.decode(ts.provenance(0).record)
        parameters = decoded.parameters
        assert parameters.model[0] == {
            "__class__": "msprime.ancestry.StandardCoalescent"
        }
        assert parameters.model[1] == {
            "__class__": "msprime.ancestry.SimulationModelChange",
            "model": {
                "__class__": "msprime.ancestry.DiscreteTimeWrightFisher"
            },
            "time": 10,
        }
        assert parameters.model[2] == {
            "__class__": "msprime.ancestry.SimulationModelChange",
            "model": {
                "__class__": "msprime.ancestry.SmcApproxCoalescent"
            },
            "time": 20,
        }
        assert parameters.model[3] == {
            "__class__": "msprime.ancestry.SimulationModelChange",
            "model": {
                "__class__": "msprime.ancestry.BetaCoalescent",
                "alpha": 1.1,
                "truncation_point": 1.0,
            },
            "time": 30,
        }
Exemplo n.º 20
0
 def test_many_models_sim_ancestry(self):
     ts = msprime.sim_ancestry(
         samples=10,
         population_size=10_000,
         model=[
             "hudson",
             msprime.AncestryModelChange(10, msprime.StandardCoalescent()),
             msprime.AncestryModelChange(20, msprime.SmcApproxCoalescent()),
             msprime.AncestryModelChange(
                 30, msprime.SmcPrimeApproxCoalescent()),
             msprime.AncestryModelChange(
                 40, msprime.DiscreteTimeWrightFisher()),
             msprime.AncestryModelChange(50,
                                         msprime.BetaCoalescent(alpha=1.1)),
             msprime.AncestryModelChange(60, msprime.StandardCoalescent()),
         ],
         random_seed=10,
     )
     for tree in ts.trees():
         assert tree.num_roots == 1
Exemplo n.º 21
0
 def test_model_instances(self):
     models = [
         msprime.StandardCoalescent(),
         msprime.SmcApproxCoalescent(),
         msprime.SmcPrimeApproxCoalescent(),
         msprime.DiscreteTimeWrightFisher(),
         msprime.WrightFisherPedigree(),
         msprime.SweepGenicSelection(
             position=0.5,
             start_frequency=0.1,
             end_frequency=0.9,
             alpha=0.1,
             dt=0.01,
         ),
         msprime.BetaCoalescent(alpha=2),
         msprime.DiracCoalescent(psi=1, c=1),
     ]
     for model in models:
         new_model = msprime.model_factory(model=model)
         self.assertTrue(new_model is model)
         self.assertEqual(new_model.__dict__, model.__dict__)
Exemplo n.º 22
0
 def test_reference_size_inherited(self):
     for Ne in [1, 10, 100]:
         models = [
             msprime.DiracCoalescent(psi=0.5, c=0),
             msprime.StandardCoalescent(),
             msprime.SmcApproxCoalescent(),
             msprime.SmcPrimeApproxCoalescent(),
             msprime.DiscreteTimeWrightFisher(),
             msprime.WrightFisherPedigree(),
             msprime.SweepGenicSelection(
                 position=0.5,
                 start_frequency=0.1,
                 end_frequency=0.9,
                 alpha=0.1,
                 dt=0.01,
             ),
             msprime.BetaCoalescent(alpha=2),
             msprime.DiracCoalescent(psi=1, c=1),
         ]
         for model in models:
             new_model = msprime.model_factory(model, reference_size=Ne)
             self.assertEqual(new_model.reference_size, Ne)
Exemplo n.º 23
0
 def test_beta_coalescent(self):
     model = msprime.BetaCoalescent(alpha=1, truncation_point=2)
     repr_s = "BetaCoalescent(alpha=1, truncation_point=2)"
     assert repr(model) == repr_s
     assert str(model) == repr_s
Exemplo n.º 24
0
 def test_beta_coalescent(self):
     model = msprime.BetaCoalescent(alpha=1, truncation_point=2)
     repr_s = "BetaCoalescent(alpha=1, truncation_point=2)"
     self.assertEqual(repr(model), repr_s)
     self.assertEqual(str(model), repr_s)
Exemplo n.º 25
0
 def test_beta_coalescent(self):
     model = msprime.BetaCoalescent(alpha=1.5, truncation_point=1)
     ts = msprime.simulate(Ne=5, sample_size=10, model=model)
     self.assertTrue(all(tree.num_roots == 1 for tree in ts.trees()))
Exemplo n.º 26
0
 def test_beta_coalescent_integration_fails(self):
     model = msprime.BetaCoalescent(population_size=5,
                                    alpha=1e-10,
                                    truncation_point=10)
     with self.assertRaises(_msprime.LibraryError):
         msprime.simulate(sample_size=10, model=model)
Exemplo n.º 27
0
 def test_beta_coalescent(self):
     model = msprime.BetaCoalescent(5, 10)
     ts = msprime.simulate(sample_size=10, model=model)
     # TODO real tests
     self.assertTrue(ts is not None)
Exemplo n.º 28
0
 def test_beta_coalescent(self):
     model = msprime.BetaCoalescent(alpha=1.5)
     ts = msprime.simulate(Ne=5, sample_size=10, model=model)
     assert all(tree.num_roots == 1 for tree in ts.trees())