示例#1
0
def evolve_and_return(args):
    """
    This function runs our simulation.
    The input arguments come in a tuple,
    which is required by many of Python's
    functions for execution in separate processes.

    For this function, the arguments are the population
    size and a random number seed.
    """
    from fwdpy11 import Multiplicative
    N, seed = args
    # Construct as single-deme object
    # with N diploids
    pop = fp11.DiploidPopulation(N)
    theta = 100.0
    # Initialize a random number generator
    rng = fp11.GSLrng(seed)
    p = fp11ez.mslike(pop,
                      simlen=100,
                      rates=(theta / float(4 * pop.N), 1e-3,
                             theta / float(4 * pop.N)))
    p['gvalue'] = Multiplicative(2.)
    params = fp11.ModelParams(**p)
    fp11.evolve_genomes(rng, pop, params)
    # The population is picklable, and so
    # we can return it from another process
    return pop
示例#2
0
def evolve_snowdrift(args):
    """
    We write the function taking a tuple
    out of habit, simplifying later
    integration with multiprocessing or
    concurrent.futures.
    """
    N, seed = args
    # Construct as single-deme object
    # with N diploids
    pop = fp11.DiploidPopulation(N)
    # Initialize a random number generator
    rng = fp11.GSLrng(seed)
    p = {
        'sregions': [fp11.ExpS(0, 1, 1, -0.1, 1.0)],
        'recregions': [fp11.Region(0, 1, 1)],
        'nregions': [],
        'gvalue': snowdrift.DiploidSnowdrift(0.2, -0.2, 1, -2),
        # evolve for 100 generations so that unit tests are
        # fast
        'demography': np.array([N] * 100, dtype=np.uint32),
        'rates': (0.0, 0.0025, 0.001),
        'prune_selected': False
    }
    params = fwdpy11.ModelParams(**p)
    sampler = SamplePhenotypes(params.gvalue)
    fp11.evolve_genomes(rng, pop, params, sampler)
    # return our pop
    return pop
示例#3
0
 def testMutationLookupTable(self):
     params = fwdpy11.ModelParams(**self.pdict)
     fwdpy11.evolve_genomes(self.rng, self.pop, params)
     lookup = self.pop.mut_lookup
     for i in range(len(self.pop.mcounts)):
         if self.pop.mcounts[i] > 0:
             self.assertTrue(self.pop.mutations[i].pos in lookup)
             self.assertTrue(i in lookup[self.pop.mutations[i].pos])
示例#4
0
 def testParentalData(self):
     params = fwdpy11.ModelParams(**self.pdict)
     fwdpy11.evolve_genomes(self.rng, self.pop, params)
     parents = [i.parents for i in self.pop.diploid_metadata]
     for i in parents:
         self.assertTrue(i is not None)
         self.assertTrue(len(i) == 2)
         self.assertTrue(i[0] < self.pop.N)
         self.assertTrue(i[1] < self.pop.N)
示例#5
0
 def testMutationIndices(self):
     params = fwdpy11.ModelParams(**self.pdict)
     fwdpy11.evolve_genomes(self.rng, self.pop, params)
     lookup = self.pop.mut_lookup
     for key, val in lookup.items():
         indexes = self.pop.mutation_indexes(key)
         self.assertTrue(indexes is not None)
         for i in indexes:
             self.assertTrue(i in val)
示例#6
0
 def testPopGenSimWithPruning(self):
     import fwdpy11
     import numpy as np
     self.p['prune_selected'] = True
     params = fwdpy11.ModelParams(**self.p)
     fwdpy11.evolve_genomes(self.rng, self.pop, params)
     assert len(
         self.pop.fixations) > 0, "Test is meaningless without fixations"
     mc = np.array(self.pop.mcounts)
     self.assertEqual(len(np.where(mc == 2 * self.pop.N)[0]), 0)
示例#7
0
def quick_neutral_slocus(N=1000, simlen=100):
    from fwdpy11.ezparams import mslike
    from fwdpy11 import ModelParams
    from fwdpy11 import DiploidPopulation, GSLrng
    from fwdpy11 import Multiplicative
    from fwdpy11 import evolve_genomes
    pop = DiploidPopulation(N)
    params_dict = mslike(pop, simlen=simlen)
    params_dict['gvalue'] = Multiplicative(2.)
    params = ModelParams(**params_dict)
    rng = GSLrng(42)
    evolve_genomes(rng, pop, params)
    return pop
示例#8
0
def quick_nonneutral_slocus(N=1000, simlen=100, dfe=None):
    from fwdpy11.ezparams import mslike
    from fwdpy11 import ModelParams
    from fwdpy11 import DiploidPopulation, GSLrng
    from fwdpy11 import evolve_genomes
    from fwdpy11 import ExpS
    from fwdpy11 import Multiplicative
    pop = DiploidPopulation(N)
    if dfe is None:
        dfe = ExpS(0, 1, 1, -0.1)
    params_dict = mslike(pop, simlen=simlen, dfe=dfe, pneutral=0.95)
    params_dict['gvalue'] = Multiplicative(2.0)
    params = ModelParams(**params_dict)
    rng = GSLrng(42)
    evolve_genomes(rng, pop, params)
    return pop
示例#9
0
 def test_nodes_after_evolution(self):
     params = fwdpy11.ModelParams(**self.pdict)
     fwdpy11.evolve_genomes(self.rng, self.pop, params)
     for i in self.pop.diploid_metadata:
         self.assertEqual(i.nodes[0], fwdpy11.NULL_NODE)
         self.assertEqual(i.nodes[1], fwdpy11.NULL_NODE)
 def testEvolve(self):
     fwdpy11.evolve_genomes(self.rng, self.pop, self.params)