def testPopGenSim(self): N = 1000 demography = np.array([N] * 10 * N, dtype=np.uint32) rho = 1. r = rho / (4 * N) a = fwdpy11.Multiplicative(2.0) p = { 'nregions': [], 'sregions': [fwdpy11.ExpS(0, 1, 1, 0.01)], 'recregions': [fwdpy11.Region(0, 1, 1)], 'rates': (0.0, 0.00005, r), 'gvalue': a, 'prune_selected': True, 'demography': demography } params = fwdpy11.ModelParams(**p) rng = fwdpy11.GSLrng(101 * 45 * 110 * 210) pop = fwdpy11.DiploidPopulation(N, 1.0) fwdpy11.evolvets(rng, pop, params, 100, track_mutation_counts=True) mc = fwdpy11.count_mutations(pop.tables, pop.mutations, [i for i in range(2 * pop.N)]) assert len(pop.fixations) > 0, "Test is meaningless without fixations" fixations = np.where(mc == 2 * pop.N)[0] self.assertEqual(len(fixations), 0) # Brute-force calculation of fixations brute_force = np.zeros(len(pop.mutations), dtype=np.int32) for g in pop.haploid_genomes: if g.n > 0: for k in g.smutations: brute_force[k] += g.n self.assertTrue(np.array_equal(brute_force, mc)) self.assertTrue(np.array_equal(brute_force, pop.mcounts))
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
def setUp(self): self.pop = fwdpy11.DiploidPopulation(1000) self.pdict = fwdpy11.ezparams.mslike(self.pop, dfe=fwdpy11.ExpS(0, 1, 1, -0.05), pneutral=0.95, simlen=10) self.pdict['gvalue'] = ca.additive() self.rng = fwdpy11.GSLrng(42) self.params = fwdpy11.ModelParams(**self.pdict)
def setUp(self): self.pop = fwdpy11.DiploidPopulation(1000, 1.0) p = {'nregions': [], # No neutral mutations -- add them later! 'gvalue': fwdpy11.Additive(2.0), 'sregions': [fwdpy11.ExpS(0, 1, 1, -0.1)], 'recregions': [fwdpy11.Region(0, 1, 1)], 'rates': (0.0, 1e-3, 1e-3), # Keep mutations at frequency 1 in the pop if they affect fitness. 'prune_selected': False, 'demography': np.array([1000]*10000, dtype=np.uint32) } self.params = fwdpy11.ModelParams(**p)
def setUpClass(self): from fwdpy11 import ModelParams from fwdpy11 import Multiplicative self.pop = fp11.DiploidPopulation(1000) self.rng = fp11.GSLrng(42) self.recorder = GenerationRecorder() self.p = ModelParams() self.p.rates = (1e-3, 1e-3, 1e-3) self.p.demography = np.array([1000] * 100, dtype=np.uint32) self.p.nregions = [fp11.Region(0, 1, 1)] self.p.sregions = [fp11.ExpS(0, 1, 1, -1e-2)] self.p.recregions = self.p.nregions self.p.gvalue = Multiplicative(2.0)
def setUp(self): import numpy as np N = 1000 demography = np.array([N] * 10 * N, dtype=np.uint32) rho = 1. r = rho / (4 * N) a = fwdpy11.Multiplicative(2.0) self.p = { 'nregions': [], 'sregions': [fwdpy11.ExpS(0, 1, 1, 0.01)], 'recregions': [fwdpy11.Region(0, 1, 1)], 'rates': (0.0, 0.00005, r), 'gvalue': a, 'demography': demography } self.pop = fwdpy11.DiploidPopulation(N) self.rng = fwdpy11.GSLrng(101 * 45 * 110 * 210)
def setUp(self): self.r = fwdpy11.ExpS(BEG, END, WEIGHT, -0.2, DOM, COUPLED, LABEL)
def testBadDominance(self): with self.assertRaises(ValueError): fwdpy11.ExpS(0, 1, 1, -1.0, h=np.nan)
def testBadMean(self): with self.assertRaises(ValueError): fwdpy11.ExpS(0, 1, 1, np.nan)
def testBadScaling(self): with self.assertRaises(ValueError): fwdpy11.ExpS(0, 1, 1.0, -0.1, scaling=np.nan)
def test_bad_input(self): with self.assertRaises(TypeError): fwdpy11.RecombinationRegions(1e-3, [fwdpy11.ExpS(0, 1, 1, -0.2), fwdpy11.GaussianS(1, 2, 1, 0.25)])
def setUp(self): self.nregions = [fwdpy11.Region(0, 1, 1)] self.sregions = [fwdpy11.ConstantS( 0, 1, 1, -0.1, 0.25), fwdpy11.ExpS(0, 1, 0.001, 0.01, 1.0)]
p = fp11.Spop(1000) print(p.N) nlist = np.array([p.N] * 323, dtype=np.uint32) #Our "neutral" regions will be from positions [0,1000) and [2000,3000). #The regions will have equal weights, and thus will each get #1/2 of newly-arising, neutral mutations nregions = [fp11.Region(0, 1000, 1), fp11.Region(2000, 3000, 1)] #Our "selected" regions will have positions on the continuous #interval [1000,2000). There will be two classes of such mutations, #each with exponentially-distrubted selection coefficients. #The first class will have a mean of s = -0.1 (deleterious), and the second #will have a mean of 1e-3 (adaptive). The former will be 100x more common than #the latter, as the weights are 1 and 0.01, respectively. sregions = [fp11.ExpS(1000, 2000, 1, -0.1), fp11.ExpS(1000, 2000, .01, .01)] #Recombination will be uniform along the interval [0,3000). rregions = [fp11.Region(0, 3000, 1)] # Neutral mutation rate mu_neutral = 0.0001 # Selected mutation rate mu_selected = 0.0000005 # Recombination rec_rate = 0.005 wf.evolve_regions(rng, p, nlist, mu_neutral, mu_selected, rec_rate, nregions, sregions, rregions)