def test_ped_wf_recombination(self): inds = np.array([1, 2, 3, 4, 5, 6]) parent_indices = np.array([4, 5, 4, 5, 4, 5, 4, 5, -1, -1, -1, -1]).reshape(-1, 2) times = np.array([0, 0, 0, 0, 1, 1]) is_sample = np.array([1, 1, 1, 1, 0, 0]) t = max(times) model = msprime.WrightFisherPedigree() ped = msprime.Pedigree(inds, parent_indices, times, is_sample, sex=None, ploidy=2) ts = msprime.simulate( sample_size=4, pedigree=ped, recombination_rate=0.1, model=[model, (1, "dtwf")], ) tree = ts.first() self.assertEqual(tree.num_roots, 1) all_times = ts.tables.nodes.time ped_times = all_times[np.logical_and(all_times > 0, all_times <= t)] self.assertGreater(ped_times.shape[0], 0) self.assertTrue(np.all(ped_times == np.floor(ped_times))) wf_times = all_times[all_times > t] self.assertGreater(wf_times.shape[0], 0)
def test_ped_wf_single_locus(self): inds = np.array([1, 2, 3, 4, 5, 6]) parent_indices = np.array([4, 5, 4, 5, 4, 5, 4, 5, -1, -1, -1, -1]).reshape(-1, 2) times = np.array([0, 0, 0, 0, 1, 1]) is_sample = np.array([1, 1, 1, 1, 0, 0]) t = max(times) model = msprime.WrightFisherPedigree() ped = msprime.Pedigree(inds, parent_indices, times, is_sample, sex=None, ploidy=2) ts = msprime.simulate( sample_size=4, pedigree=ped, demographic_events=[ msprime.SimulationModelChange( t, msprime.DiscreteTimeWrightFisher(2)) ], model=model, ) tree = ts.first() self.assertEqual(tree.num_roots, 1) all_times = ts.tables.nodes.time ped_times = all_times[np.logical_and(all_times > 0, all_times <= t)] self.assertGreater(ped_times.shape[0], 0) self.assertTrue(np.all(ped_times == np.floor(ped_times))) wf_times = all_times[all_times > t] self.assertGreater(wf_times.shape[0], 0)
def test_ped_wf_single_locus(self): inds = np.array([1, 2, 3, 4, 5, 6]) parent_indices = np.array([4, 5, 4, 5, 4, 5, 4, 5, -1, -1, -1, -1]).reshape(-1, 2) times = np.array([0, 0, 0, 0, 1, 1]) is_sample = np.array([1, 1, 1, 1, 0, 0]) t = max(times) model = msprime.WrightFisherPedigree() ped = msprime.Pedigree(inds, parent_indices, times, is_sample, sex=None, ploidy=2) ts = msprime.simulate(sample_size=4, Ne=2, pedigree=ped, model=(model, (t, "dtwf"))) tree = ts.first() assert tree.num_roots == 1 all_times = ts.tables.nodes.time ped_times = all_times[np.logical_and(all_times > 0, all_times <= t)] assert ped_times.shape[0] > 0 assert np.all(ped_times == np.floor(ped_times)) wf_times = all_times[all_times > t] assert wf_times.shape[0] > 0
def test_ped_wf_recombination(self): inds = np.array([1, 2, 3, 4, 5, 6]) parent_indices = np.array([4, 5, 4, 5, 4, 5, 4, 5, -1, -1, -1, -1]).reshape(-1, 2) times = np.array([0, 0, 0, 0, 1, 1]) is_sample = np.array([1, 1, 1, 1, 0, 0]) t = max(times) model = msprime.WrightFisherPedigree() ped = pedigrees.Pedigree(inds, parent_indices, times, is_sample, sex=None, ploidy=2) ts = msprime.simulate( sample_size=4, pedigree=ped, recombination_rate=0.1, model=model, demographic_events=[ msprime.SimulationModelChange(time=1, model="dtwf") ], ) tree = ts.first() assert tree.num_roots == 1 all_times = ts.tables.nodes.time ped_times = all_times[np.logical_and(all_times > 0, all_times <= t)] assert ped_times.shape[0] > 0 assert np.all(ped_times == np.floor(ped_times)) wf_times = all_times[all_times > t] assert wf_times.shape[0] > 0
def test_wf_ped(self): inds = np.array([1, 2, 3, 4]) parent_indices = np.array([2, 3, 2, 3, -1, -1, -1, -1]).reshape(-1, 2) times = np.array([0, 0, 1, 1]) is_sample = np.array([1, 1, 0, 0]) model = msprime.WrightFisherPedigree() ped = msprime.Pedigree( inds, parent_indices, times, is_sample, sex=None, ploidy=2 ) ts = msprime.simulate(2, pedigree=ped, model=model) assert ts is not None
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)
def test_pedigree_replicates(self): individual = np.array([1, 2, 3, 4]) parents = np.array([2, 3, 2, 3, -1, -1, -1, -1]).reshape(-1, 2) time = np.array([0, 0, 1, 1]) is_sample = np.array([1, 1, 0, 0]) model = msprime.WrightFisherPedigree() ped = msprime.Pedigree(individual, parents, time, is_sample, sex=None, ploidy=2) replicates = msprime.simulate(2, pedigree=ped, model=model, recombination_rate=1, num_replicates=100) for ts in replicates: self.assertTrue(ts is not None)
def test_model_instances(self): models = [ msprime.StandardCoalescent(100), msprime.SmcApproxCoalescent(30), msprime.SmcPrimeApproxCoalescent(2132), msprime.DiscreteTimeWrightFisher(500), msprime.WrightFisherPedigree(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__)
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__)
def test_simple_case(self): # Simple test to check that the current code is still roughly working. # Should be replace by better tests. individual = np.array([1, 2, 3, 4]) parents = np.array([-1, -1, -1, -1, 0, 1, 1, 0]).reshape(-1, 2) time = np.array([1, 1, 0, 0]) is_sample = np.array([0, 0, 1, 1]) model = msprime.WrightFisherPedigree() ped = pedigrees.Pedigree(individual, parents, time, is_sample, sex=None, ploidy=2) ts = msprime.simulate(2, pedigree=ped, model=model, recombination_rate=1) table = ts.tables.individuals assert np.all(table[0].parents == [-1, -1]) assert np.all(table[1].parents == [-1, -1])
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)
def test_pedigree(self): inds = np.array([1, 2, 3, 4, 5, 6]) parent_indices = np.array([4, 5, 4, 5, 4, 5, 4, 5, -1, -1, -1, -1]).reshape(-1, 2) times = np.array([0, 0, 0, 0, 1, 1]) is_sample = np.array([1, 1, 1, 1, 0, 0]) t = max(times) model = msprime.WrightFisherPedigree() ped = msprime.Pedigree(inds, parent_indices, times, is_sample, sex=None, ploidy=2) ts = msprime.simulate( sample_size=4, pedigree=ped, demographic_events=[ msprime.SimulationModelChange( t, msprime.DiscreteTimeWrightFisher()) ], model=model, ) self.verify(ts)
def test_wf_pedigree(self): model = msprime.WrightFisherPedigree() repr_s = "WrightFisherPedigree()" self.assertEqual(repr(model), repr_s) self.assertEqual(str(model), repr_s)
def test_wf_pedigree(self): model = msprime.WrightFisherPedigree() repr_s = "WrightFisherPedigree()" assert repr(model) == repr_s assert str(model) == repr_s