def run_replicate(argtuple): args, repid, repseed = argtuple rng = fp11.GSLrng(repseed) NANC = args.N locus_boundaries = [(float(i + i * 11), float(i + i * 11 + 11)) for i in range(args.nloci)] nregions = [[ fp11.Region(j[0], j[1], args.theta / (4. * float(NANC)), coupled=True) ] for i, j in zip(range(args.nloci), locus_boundaries)] recregions = [[ fp11.Region(j[0], j[1], args.rho / (4. * float(NANC)), coupled=True) ] for i, j in zip(range(args.nloci), locus_boundaries)] sregions = [[ fp11.GaussianS(j[0] + 5., j[0] + 6., args.mu, args.sigmu, coupled=False) ] for i, j in zip(range(args.nloci), locus_boundaries)] interlocus_rec = fp11ml.binomial_rec(rng, [0.5] * (args.nloci - 1)) nlist = np.array([NANC] * 20 * NANC, dtype=np.uint32) env = [(0, 0, 1), (10 * NANC, args.opt, 1)] pdict = { 'nregions': nregions, 'sregions': sregions, 'recregions': recregions, 'demography': nlist, 'interlocus': interlocus_rec, 'agg': fp11ml.AggAddTrait(), 'gvalue': fp11ml.MultiLocusGeneticValue([fp11tv.SlocusAdditiveTrait(2.0)] * args.nloci), 'trait2w': fp11qt.GSSmo(env), 'mutrates_s': [args.mu / float(args.nloci)] * args.nloci, 'mutrates_n': [10 * args.theta / float(4 * NANC)] * args.nloci, 'recrates': [10 * args.rho / float(4 * NANC)] * args.nloci, 'prune_selected': False } params = fp11.model_params.MlocusParamsQ(**pdict) ofilename = args.stub + '.rep' + str(repid) + '.pickle.lzma' recorder = Pickler(repid, NANC, ofilename) pop = fp11.MlocusPop(NANC, args.nloci, locus_boundaries) fp11qt.evolve(rng, pop, params, recorder) #Make sure last gen got pickled! if recorder.last_gen_recorded != pop.generation: with open(ofilename, "ab") as f: pickle.dump((repid, pop), f, -1) return ofilename
def evolve_track_wrapper(popsize=1000, rho=10000.0, mu=1e-2, seed=42, gc_interval=10, dfe=fwdpy11.ConstantS(0, 1, 1, -0.025, 1.0)): if isinstance(dfe, fwdpy11.Sregion) is False: raise TypeError("dfe must be a fwdpy11.Sregion") if dfe.b != 0.0 or dfe.e != 1.0: raise ValueError("DFE beg/end must be 0.0/1.0, repsectively") pop = fwdpy11.SlocusPop(popsize) recrate = float(rho) / (4.0 * float(popsize)) pdict = { 'rates': (0.0, mu, recrate), 'nregions': [], 'sregions': [dfe], 'recregions': [fwdpy11.Region(0, 1, 1)], 'gvalue': fwdpy11.fitness.SlocusMult(2.0), 'demography': np.array([popsize] * 10 * popsize, dtype=np.uint32) } params = fwdpy11.model_params.SlocusParams(**pdict) rng = fwdpy11.GSLrng(seed) ancestry = evolve_track(rng, pop, params, gc_interval) return (pop, ancestry)
def set_up_quant_trait_model(): N = 1000 demography = np.array([N] * 10 * N, dtype=np.uint32) rho = 1000. r = rho / (4 * N) timepoints = np.array([0], dtype=np.uint32) ntraits = 4 optima = np.array(np.zeros(len(timepoints) * ntraits)) optima = optima.reshape((len(timepoints), ntraits)) GSSmo = fwdpy11.MultivariateGSSmo(timepoints, optima, 1) cmat = np.identity(ntraits) np.fill_diagonal(cmat, 0.1) a = fwdpy11.StrictAdditiveMultivariateEffects(ntraits, 0, GSSmo) p = { 'nregions': [], 'sregions': [fwdpy11.MultivariateGaussianEffects(0, 1, 1, cmat)], 'recregions': [fwdpy11.Region(0, 1, 1)], 'rates': (0.0, 0.001, r), 'gvalue': a, 'prune_selected': False, 'demography': demography } params = fwdpy11.ModelParams(**p) rng = fwdpy11.GSLrng(101 * 45 * 110 * 210) pop = fwdpy11.DiploidPopulation(N, 1.0) return params, rng, pop, ntraits
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 evolve(N, rho, simlen=20, seed=42): """ Evolve without selection and without simplifying. :param (int) N: Number of diploids :param (float) rho: 4Nr :param (int) simlen: (Default: 10) Evolve for simlen*N generations. :param (int) seed: (Default: 42) RNG seed. :rtype: fwdpy11_arg_example.argsimplifier.ArgSimplifier :return: Unsimplified data """ pop = fp11.SlocusPop(N) # Set up parameters with defaults recrate = rho / (4.0 * float(N)) mutrate_n = 0.0 mutrate_s = 0.0 pdict = {'rates': (mutrate_n, mutrate_s, recrate), 'nregions': [], 'sregions': [], 'recregions': [fp11.Region(0, 1, 1)], 'gvalue': fp11w.SlocusMult(1.0), 'demography': np.array([N] * simlen * N, dtype=np.uint32) } params = fp11mp.SlocusParams(**pdict) # Set the gc_interval to be so long that it never happens gc_interval = 2 * simlen * N simplifier = ArgSimplifier(gc_interval, None) atracker = AncestryTracker(pop.N, False, 2*pop.N) mm = makeMutationRegions(params.nregions, params.sregions) rm = makeRecombinationRegions(params.recregions) rng = fp11.GSLrng(seed) tsim = evolve_singlepop_regions_track_ancestry(rng, pop, atracker, simplifier, params.demography, params.mutrate_s, params.recrate, mm, rm, params.gvalue, params.pself) # Reverse time: atracker.prep_for_gc() return atracker
def runsim(args): """ Run the simulation and deliver output to files. """ pop = fwdpy11.DiploidPopulation(args.popsize, GENOME_LENGTH) rng = fwdpy11.GSLrng(args.seed) GSSmo = fwdpy11.GSSmo([(0, 0, args.VS), (10 * args.popsize, args.opt, args.VS)]) popsizes = [args.popsize ] * (10 * args.popsize + int(args.time * float(args.popsize))) p = { 'nregions': [], # No neutral mutations -- add them later! 'gvalue': fwdpy11.Additive(2.0, GSSmo), 'sregions': [fwdpy11.GaussianS(0, GENOME_LENGTH, 1, args.sigma)], 'recregions': [fwdpy11.Region(0, GENOME_LENGTH, 1)], 'rates': (0.0, args.mu, args.rho / float(4 * args.popsize)), # Keep mutations at frequency 1 in the pop if they affect fitness. 'prune_selected': False, 'demography': np.array(popsizes, dtype=np.uint32) } params = fwdpy11.ModelParams(**p) r = Recorder(args.record, args.preserve, args.num_ind) fwdpy11.evolvets(rng, pop, params, 100, r, suppress_table_indexing=True) with lzma.open(args.filename, 'wb') as f: pickle.dump(pop, f) if args.statfile is not None: stats = pd.DataFrame(r.data, columns=DATA._fields) # Write the statistics to an sqlite3 database, # which can be processed in R via dplyr. conn = sqlite3.connect(args.statfile) stats.to_sql('data', conn)