def main(): try: opts, args = getopt.getopt(sys.argv[1:], "m:e:H:S:O:N:t:s:r:F:n:") except getopt.GetoptError as err: # print help information and exit: print(err) # will print something like "option -a not recognized" usage() sys.exit(2) N = 1000 # pop size e = 0.25 # s.d. of effect sizes S = 1 # V(S) H = None # desired b-sense H^2 mu_del_ttl = None # Mutation rate (per gamete, per generation) to alleles affecting trait value r = 0.5 # rec. rate b/w loci (per diploid, per gen) Opt = 0.0 # Value of optimum after 10N gens ofile = None seed = 0 t = None nsam = 100 for o, a in opts: if o == '-m': mu_del_ttl = float(a) elif o == '-e': e = float(a) elif o == '-H': H = float(a) elif o == '-S': S = float(a) elif o == '-O': Opt = float(a) elif o == '-N': N = int(a) elif o == '-s': seed = int(a) elif o == '-r': r = float(a) elif o == '-F': ofile = a elif o == '-t': t = int(a) elif o == '-n': nsam = int(a) if H is None: usage() sys.exit(2) if mu_del_ttl is None: usage() sys.exit(2) if ofile is None: usage() sys.exit(2) if t is None: t = 0.1 * float(N) #Constants: NLOCI = 10 NREPS = 64 ##The next 2 are the 'sizes' of each locus in scaled params. Roughly 100kb in 'humans' in terms of pi. theta = 100.0 rho = 100.0 #Can start working now: REP = 0 out = pd.HDFStore(ofile, "w", complevel=6, complib='zlib') little_r_per_locus = rho / (4.0 * float(N)) mu_n_region = theta / (4.0 * float(N)) rnge = fp.GSLrng(seed) rngs = fp.GSLrng(seed) nlist = np.array([N] * (10 * N), dtype=np.uint32) fitness = qtm.MlocusAdditiveTrait() sregions = [fp.GaussianS(0, 1, 1, e, 1.0)] * NLOCI for BATCH in range(16): #16*64=1024 x = fp.MlocusPopVec(NREPS, N, NLOCI) sampler = fp.PopSampler(len(x), nsam, rngs) qtm.evolve_qtraits_mloc_sample_fitness( rnge, x, sampler, fitness, nlist, [mu_n_region] * NLOCI, [mu_del_ttl / float(NLOCI)] * NLOCI, sregions, [little_r_per_locus] * NLOCI, [0.5] * (NLOCI - 1), #loci unlinked sample=t, VS=S) samples = sampler.get() get_summstats_parallel(samples, REP, out) sampler = fp.PopSampler(nsam, rngs) qtm.evolve_qtraits_mloc_sample_fitnes( rnge, x, sampler, fitness, nlist, [mu_n_region] * NLOCI, [mu_del_ttl / float(NLOCI)] * NLOCI, sregions, [little_r_per_locus] * NLOCI, [0.5] * (NLOCI - 1), #loci unlinked sample=t, VS=S, optimum=Opt) samples = sampler.get() get_summstats_parallel(samples, REP, out) REP += NREPS out.close()
import PopstatsLocus import fwdpy as fp import fwdpy.qtrait_mloc as qtm import numpy as np import pandas as pd import getopt import sys, math, gc, sqlite3, os def usage(): print("something went wrong") valid_trait_models = ['additive', 'mult'] trait_models = { 'additive': qtm.MlocusAdditiveTrait(), 'mult': qtm.MlocusMultTrait() } valid_sampler_names = ['lstats', 'stats', 'ages', 'ms'] def get_sampler(samplerString, length, optimum, nsam, rng, nstub, sstub): if samplerString == 'lstats': return PopstatsLocus.PopstatsLocus(length) elif samplerString == 'stats': return fp.QtraitStatsSampler(length, optimum) elif samplerString == 'ages': return mlocAges.MlocusAgeSampler(length) elif samplerString == 'ms': if nsam is None:
def main(): try: opts, args = getopt.getopt(sys.argv[1:],"m:e:H:S:O:N:s:r:",["traj="]) except getopt.GetoptError as err: # print help information and exit: print(err) # will print something like "option -a not recognized" usage() sys.exit(2) N=1000 # pop size e = 0.25 # s.d. of effect sizes S = 1 # V(S) H = None # desired b-sense H^2 mu_del_ttl = None # Mutation rate (per gamete, per generation) to alleles affecting trait value r = 0.5 # rec. rate b/w loci (per diploid, per gen) Opt = 0.0 # Value of optimum after 10N gens trajFile=None seed = 0 for o,a in opts: if o == '-m': mu_del_ttl = float(a) elif o == '-e': e = float(a) elif o == '-H': H = float(a) elif o == '-S': S = float(a) elif o == '-O': Opt = float(a) elif o == '-N': N=int(a) elif o == '-s': seed = int(a) elif o == '-r': r = float(a) elif o == '--traj': trajFile=a if H is None: usage() sys.exit(2) if mu_del_ttl is None: usage() sys.exit(2) if trajFile is None: usage() sys.exit(2) #Constants: NLOCI=10 NREPS=64 ##The next 2 are the 'sizes' of each locus in scaled params. Roughly 100kb in 'humans' in terms of pi. theta=100.0 rho=100.0 #Can start working now: REP=0 out=pd.HDFStore(trajFile,"w",complevel=6,complib='zlib') little_r_per_locus = rho/(4.0*float(N)) mu_n_region=theta/(4.0*float(N)) rnge=fp.GSLrng(seed) nlist=np.array([N]*(10*N),dtype=np.uint32) fitness = qtm.MlocusAdditiveTrait() sregions=[fp.GaussianS(0,1,1,e,1.0)]*NLOCI for BATCH in range(16): #16*64=1024 x = fp.MlocusPopVec(NREPS,N,NLOCI) sampler=fp.FreqSampler(len(x)) qtm.evolve_qtraits_mloc_sample_fitness(rnge,x,sampler,fitness,nlist, [mu_n_region]*NLOCI, [mu_del_ttl/float(NLOCI)]*NLOCI, sregions, [little_r_per_locus]*NLOCI, [0.5]*(NLOCI-1),#loci unlinked sample=1,VS=S) traj1=sampler.get() sampler=fp.FreqSampler(len(x)) qtm.evolve_qtraits_mloc_sample_fitness(rnge,x,sampler,fitness,nlist, [mu_n_region]*NLOCI, [mu_del_ttl/float(NLOCI)]*NLOCI, sregions, [little_r_per_locus]*NLOCI, [0.5]*(NLOCI-1),#loci unlinked sample=1,VS=S,optimum=Opt) traj2=sampler.get() m=fp.tidy_trajectories(fp.merge_trajectories(traj1,traj2)) for i in m: temp=pd.DataFrame(i) temp['rep']=[REP]*len(temp.index) out.append('traj',temp) REP+=1 out.close()
def run_batch(argtuple): args, repid, batch = argtuple print("seed for batch = ", args.seed) nstub = "neutral.mu" + str(args.mu) + ".opt" + str(args.opt) sstub = "selected.mu" + str(args.mu) + ".opt" + str(args.opt) rnge = fp.GSLrng(args.seed) NANC = 7310 locus_boundaries = [(float(i + i * 11), float(i + i * 11 + 11)) for i in range(args.nloci)] nregions = [ fp.Region(j[0], j[1], args.theta / (4. * float(NANC)), coupled=True) for i, j in zip(range(args.nloci), locus_boundaries) ] recregions = [ fp.Region(j[0], j[1], args.rho / (4. * float(NANC)), coupled=True) for i, j in zip(range(args.nloci), locus_boundaries) ] sregions = [ fp.GaussianS(j[0] + 5., j[0] + 6., args.mu, args.sigmu, coupled=False) for i, j in zip(range(args.nloci), locus_boundaries) ] f = qtm.MlocusAdditiveTrait() nlist = np.array(get_nlist1(), dtype=np.uint32) pops = fp.MlocusPopVec(args.ncores, nlist[0], args.nloci) sampler = fp.NothingSampler(len(pops)) d = datetime.datetime.now() print("starting batch, ", batch, "at ", d.now()) qtm.evolve_qtraits_mloc_regions_sample_fitness(rnge, pops, sampler, f, nlist[0:], nregions, sregions, recregions, [0.5] * (args.nloci - 1), 0, 0, 0.) d = datetime.datetime.now() print(d.now()) nlist = np.array(get_nlist2(), dtype=np.uint32) qtm.evolve_qtraits_mloc_regions_sample_fitness(rnge, pops, sampler, f, nlist[0:], nregions, sregions, recregions, [0.5] * (args.nloci - 1), 0, args.opt) d = datetime.datetime.now() print(d.now()) if args.statfile is not None: sched = lsp.scheduler_init(args.TBB) for pi in pops: #Apply the sampler 1 population at a time. #This saves a fair bit of RAM. neutralFile = nstub + '.rep' + str(repid) + '.gz' selectedFile = sstub + '.rep' + str(repid) + '.gz' BIGsampler = fp.PopSampler(1, 6000, rnge, False, neutralFile, selectedFile, recordSamples=True, boundaries=locus_boundaries) fp.apply_sampler_single(pi, BIGsampler) if args.statfile is not None: for di in BIGsampler: process_samples((di, args.statfile, locus_boundaries, repid)) repid += 1 pops.clear() pops = None