Ejemplo n.º 1
0
 def test_generate_nucleotides_keep(self):
     ts = msprime.sim_ancestry(4, sequence_length=10, population_size=10)
     ts = pyslim.annotate_defaults(ts, model_type='nonWF', slim_generation=1)
     mts1 = msprime.sim_mutations(ts,
             model=msprime.SLiMMutationModel(type=1),
             rate=0.1,
             random_seed=23)
     mts1.dump("out.trees")
     nts1 = pyslim.generate_nucleotides(mts1, seed=10, keep=False)
     assert nts1.num_mutations > 0
     self.verify_generate_nucleotides(nts1, check_transitions=False)
     mts2 = msprime.sim_mutations(nts1,
             model=msprime.SLiMMutationModel(
                 type=2,
                 next_id=nts1.num_mutations,
             ),
             rate=0.1,
             random_seed=24,
     )
     # keep defaults to True
     nts2 = pyslim.generate_nucleotides(mts2, seed=12)
     assert nts2.num_mutations > nts1.num_mutations
     muts1 = {}
     for mut in nts1.mutations():
         for i, md in zip(mut.derived_state.split(","), mut.metadata['mutation_list']):
             muts1[i] = md['nucleotide']
     for mut in nts2.mutations():
         for i, md in zip(mut.derived_state.split(","), mut.metadata['mutation_list']):
             if md['mutation_type'] == 1:
                 assert i in muts1
                 assert muts1[i] == md['nucleotide']
             else:
                 assert md['nucleotide'] in [0, 1, 2, 3]
     nts3 = pyslim.generate_nucleotides(mts2, keep=False, seed=15)
     self.verify_generate_nucleotides(nts3, check_transitions=False)
Ejemplo n.º 2
0
 def test_generate_nucleotides(self, recipe):
     ts = recipe["ts"]
     nts = pyslim.generate_nucleotides(ts, keep=False, seed=5)
     self.verify_generate_nucleotides(
             nts,
             check_transitions=("adds_mutations" not in recipe),
     )
Ejemplo n.º 3
0
 def test_generate_nucleotides_errors(self):
     ts = msprime.sim_ancestry(4, sequence_length=10, population_size=10)
     with pytest.raises(ValueError, match="must have length equal"):
         _ = pyslim.generate_nucleotides(ts, reference_sequence="AAA")
     with pytest.raises(ValueError, match="must have length equal"):
         _ = pyslim.generate_nucleotides(ts, reference_sequence=[1, 2, 3])
     with pytest.raises(ValueError, match="must be a string of"):
         _ = pyslim.generate_nucleotides(
                 ts,
                 reference_sequence="X" * int(ts.sequence_length)
         )
     with pytest.raises(ValueError, match="must be a string of"):
         _ = pyslim.generate_nucleotides(
                 ts,
                 reference_sequence=np.arange(int(ts.sequence_length)),
         )
Ejemplo n.º 4
0
 def test_generate_and_convert(self, recipe, helper_functions, tmp_path):
     ts = recipe["ts"]
     nts = pyslim.generate_nucleotides(ts, seed=123)
     cts = pyslim.convert_alleles(nts)
     self.verify_converted_nucleotides(nts, cts)
     helper_functions.run_slim_restart(
             nts,
             "restart_nucleotides_nonWF.slim",
             tmp_path,
             WF=False,
     )
Ejemplo n.º 5
0
 def test_generate_nucleotides_refseq(self):
     ts = msprime.sim_ancestry(
             4,
             sequence_length=10,
             population_size=10,
             random_seed=10,
     )
     ts = pyslim.annotate_defaults(ts, model_type='nonWF', slim_generation=1)
     mts = msprime.sim_mutations(ts,
             model=msprime.SLiMMutationModel(type=1),
             rate=0.5,
             random_seed=23)
     refseq = "A" * int(mts.sequence_length)
     nts = pyslim.generate_nucleotides(mts, reference_sequence=refseq, seed=6)
     self.verify_generate_nucleotides(nts, check_transitions=True)
     assert nts.reference_sequence.data == refseq