示例#1
0
 def _get_xi_dirac_mutation_stats(self, sample_size, num_repeat, mut_rate,
                                  rec_rate, num_loci):
     # TODO Fix this! We can write the output to a proper temporary file, or
     # pipe it directly into sample_stats.
     output = open("tmp", "w")
     output.write("msprimedirac " + str(sample_size) + " " +
                  str(num_repeat) + "\n1 1 1\n")
     model = msprime.DiracCoalescent(psi=0.99, c=0)
     rep_ts = msprime.simulate(
         sample_size,
         recombination_rate=rec_rate,
         mutation_rate=mut_rate / 4,  # See line 317, theta divide by 4
         length=num_loci,
         model=model,
         num_replicates=num_repeat)
     for i, ts in enumerate(rep_ts):
         print("\n//", file=output)
         print("segsites: " + str(ts.get_num_mutations()), file=output)
         print("positions: " + ' '.join(
             str(mutation.position / num_loci)
             for mutation in ts.mutations()),
               file=output)
         for hap in ts.haplotypes():
             print(hap, file=output)
     output.close()
示例#2
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)
示例#3
0
 def test_dirac_coalescent_lambda_regime_recombination(self):
     model = msprime.DiracCoalescent(psi=0.9, c=100)
     ts = msprime.simulate(sample_size=100,
                           recombination_rate=100,
                           model=model,
                           random_seed=3)
     self.verify_non_binary(ts)
示例#4
0
 def test_dirac_coalescent_parameters(self):
     for psi in [0.01, 0.5, 0.99]:
         for c in [1e-6, 1.0, 1e2]:
             model = msprime.DiracCoalescent(psi, c)
             assert model.psi == psi
             assert model.c == c
             d = model.get_ll_representation()
             assert d == {"name": "dirac", "psi": psi, "c": c}
示例#5
0
    def test_dirac_coalescent(self):
        model = msprime.DiracCoalescent(psi=123, c=2)
        assert model.duration is None
        assert model.psi == 123
        assert model.c == 2

        model = msprime.DiracCoalescent(psi=123, c=2, duration=3)
        assert model.duration == 3
        assert model.psi == 123
        assert model.c == 2

        model = msprime.DiracCoalescent()
        assert model.duration is None
        assert model.psi is None

        with pytest.raises(TypeError, match="takes 1 positional"):
            msprime.DiracCoalescent(1)
示例#6
0
 def test_dirac_coalescent_kingman_regime(self):
     # When c=0, we should a kingman coalescent and no multiple mergers.
     model = msprime.DiracCoalescent(psi=0.5, c=0)
     ts = msprime.simulate(sample_size=10, model=model, random_seed=2)
     for t in ts.trees():
         for u in t.nodes():
             if t.is_internal(u):
                 self.assertEqual(len(t.children(u)), 2)
示例#7
0
 def test_dirac_coalescent_parameters(self):
     for psi in [0.01, 0.5, 0.99]:
         for c in [1e-6, 1.0, 1e2]:
             model = msprime.DiracCoalescent(psi, c)
             self.assertEqual(model.psi, psi)
             self.assertEqual(model.c, c)
             d = model.get_ll_representation()
             self.assertEqual(d, {"name": "dirac", "psi": psi, "c": c})
示例#8
0
 def test_dirac_coalescent_lambda_regime(self):
     # With large c and psi ~ 1, we should be guaranteed some multiple mergers.
     model = msprime.DiracCoalescent(psi=0.999, c=1000)
     ts = msprime.simulate(sample_size=100, model=model, random_seed=4)
     non_binary = False
     for e in ts.edgesets():
         if len(e.children) > 2:
             non_binary = True
     self.assertTrue(non_binary)
示例#9
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)
示例#10
0
 def test_dirac_coalescent_lambda_regime_recombination(self):
     model = msprime.DiracCoalescent(psi=0.999, c=1)
     ts = msprime.simulate(sample_size=100,
                           recombination_rate=100,
                           model=model,
                           random_seed=3)
     non_binary = False
     for e in ts.edgesets():
         if len(e.children) > 2:
             non_binary = True
     self.assertTrue(non_binary)
示例#11
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)
示例#12
0
 def test_dirac_coalescent_parameters(self):
     for psi in [0.01, 0.5, 0.99]:
         for c in [1e-6, 1.0, 1e2]:
             model = msprime.DiracCoalescent(psi=psi, c=c)
             assert model.psi == psi
             assert model.c == c
             d = model._as_lowlevel()
             assert d == {
                 "name": "dirac",
                 "psi": psi,
                 "c": c,
                 "duration": None
             }
示例#13
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)
示例#14
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__)
示例#15
0
    def _run_xi_dirac_coalescent_stats(self, sample_size, num_repeat, r,
                                       num_loci):
        print("\t msprime dirac")
        replicates = num_repeat
        model = msprime.DiracCoalescent(psi=0.99, c=0)
        sim = msprime.simulator_factory(
            sample_size=sample_size,
            recombination_map=msprime.RecombinationMap.uniform_map(
                num_loci, r / (num_loci - 1), num_loci),
            model=model)
        num_populations = sim.num_populations

        num_trees = [0 for j in range(replicates)]
        time = [0 for j in range(replicates)]
        ca_events = [0 for j in range(replicates)]
        re_events = [0 for j in range(replicates)]
        mig_events = [None for j in range(replicates)]

        for j in range(replicates):
            sim.reset()
            sim.run()
            num_trees[j] = sim.num_breakpoints + 1
            time[j] = sim.time / 4  # Convert to coalescent units
            ### THIS IS NOT RIGHT, this following line will work, but it is not right
            #time[j] = sim.time  # Convert to coalescent units
            ca_events[j] = sim.num_common_ancestor_events
            re_events[j] = sim.num_recombination_events
            mig_events[j] = [
                r for row in sim.num_migration_events for r in row
            ]
        d = {
            "t": time,
            "num_trees": num_trees,
            "ca_events": ca_events,
            "re_events": re_events
        }
        for j in range(num_populations**2):
            events = [mig_events[k][j] for k in range(replicates)]
            d["mig_events_{}".format(j)] = events
        df = pd.DataFrame(d)
        return df
示例#16
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__)
示例#17
0
 def test_dirac_coalescent_lambda_regime(self):
     # With large c and psi ~ 1, we should be guaranteed some multiple mergers.
     model = msprime.DiracCoalescent(psi=0.999, c=1000)
     ts = msprime.simulate(sample_size=100, model=model, random_seed=4)
     self.verify_non_binary(ts)
示例#18
0
 def test_dirac_coalescent(self):
     model = msprime.DiracCoalescent(100, 0.3, 10)
     ts = msprime.simulate(sample_size=10, model=model)
     # TODO real tests
     self.assertTrue(ts is not None)
示例#19
0
 def test_dirac_coalescent(self):
     model = msprime.DiracCoalescent(0.3, 10)
     ts = msprime.simulate(Ne=100, sample_size=10, model=model)
     self.assertTrue(all(tree.num_roots == 1 for tree in ts.trees()))
示例#20
0
 def test_dirac_coalescent_kingman_regime(self):
     # When c=0, we should a kingman coalescent and no multiple mergers.
     model = msprime.DiracCoalescent(psi=0.5, c=0)
     ts = msprime.simulate(sample_size=10, model=model, random_seed=2)
     for e in ts.edgesets():
         self.assertEqual(len(e.children), 2)
示例#21
0
 def test_dirac_coalescent(self):
     model = msprime.DiracCoalescent(psi=123, c=2)
     repr_s = "DiracCoalescent(psi=123, c=2)"
     self.assertEqual(repr(model), repr_s)
     self.assertEqual(str(model), repr_s)
示例#22
0
 def test_dirac_coalescent(self):
     model = msprime.DiracCoalescent(psi=123, c=2)
     repr_s = "DiracCoalescent(psi=123, c=2)"
     assert repr(model) == repr_s
     assert str(model) == repr_s