Exemple #1
0
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
Exemple #2
0
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)]

    # Get the variance in effect sizes
    sigmu = args.sigmu  # default
    if args.plarge is not None:
        ghat = gamma_hat(1.0, args.mu)
        F = generate_gaussian_function_to_minimize(ghat, args.plarge)
        sigmu = get_gaussian_sigma(F)

    sregions = [[
        fp11.GaussianS(j[0] + 5., j[0] + 6., args.mu, 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, args.vsopt)]
    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)
    recorder = Recorder(repid, NANC, args.nsam)
    pop = fp11.MlocusPop(NANC, args.nloci, locus_boundaries)
    fp11qt.evolve(rng, pop, params, recorder)
    return recorder
Exemple #3
0
def runsim(args):
    mutrate, seed, repid = args
    rng = fp11.GSLrng(seed)
    t2f = fp11qt.GSSmo([(0, 0, 1), (10 * N, 1, 1)])
    pop = fp11.SlocusPop(N)
    p = {
        'nregions': [fp11.Region(0, 11, 1.0)],  # nregions must be a region
        'sregions': [fp11.GaussianS(5, 6, 1, 0.25)],
        'recregions': [fp11.Region(0, 11, 1)],
        'mutrate_n': THETA / float(4 * N),
        'mutrate_s': mutrate,
        'recrate': RHO / float(4 * N),
        'demography': np.array([N] * (10 * N + 100), dtype=np.uint32),
        'gvalue': fp11tv.SlocusAdditiveTrait(2.0),
        'trait_to_fitness': t2f,
        'prune_selected': False
    }

    params = fp11.model_params.SlocusParamsQ(**p)

    fp11qt.evolve(rng, pop, params)
    samples = take_sample(rng, pop)
    return repid, pop, samples
def run_replicate(argtuple):
    args, repid, repseed = argtuple
    rng = fp11.GSLrng(repseed)
    NANC = 7310
    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 = get_nlist()
    env = [(0, 0, 1), (np.argmax(nlist == 1861), 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] * args.nloci,
        'mutrates_n':
        [float(args.nloci) * args.theta / float(4 * NANC)] * args.nloci,
        'recrates':
        [float(args.nloci) * args.rho / float(4 * NANC)] * args.nloci,
    }
    #print(pdict['mutrates_n'])
    #for i in sregions:
    #    for j in i:
    #        print(str(j))
    #return
    params = fp11.model_params.MlocusParamsQ(**pdict)
    ofilename = args.stub + '.rep' + str(repid) + '.gz'
    recorder = Pickler(repid, args.nsam, 8 * NANC, np.argmax(nlist == 1861),
                       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:
            with gzip.open(ofilename, "ab") as f:
                m = get_matrix(pop, args.nsam)
                pickle.dump(m, f, -1)
    pop.clear()
    del pop
    pop = None
    return ofilename
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)]
    nregions = [[]] * args.nloci
    #Put the neutral variants in the selected regions
    nregions[0] = [
        fp11.Region(locus_boundaries[0][0] + 5.0, locus_boundaries[0][0] + 6.0,
                    1)
    ]
    #Put the neutral variants in middle
    nregions[int(args.nloci / 2)] = [
        fp11.Region(locus_boundaries[int(args.nloci / 2)][0] + 5.,
                    locus_boundaries[int(args.nloci / 2)][0] + 6., 1.0)
    ]
    #Put the neutral variants at far rigth end.
    nregions[args.nloci - 1] = [
        fp11.Region(locus_boundaries[args.nloci - 1][1] - 1.0,
                    locus_boundaries[args.nloci - 1][1], 1.0)
    ]
    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)]
    #The middle region has no sregions:
    sregions[int(args.nloci / 2)] = []
    mutrates_s = [args.mu / float(args.nloci - 1)] * args.nloci
    #No selected mutations in the middle locus
    mutrates_s[int(args.nloci / 2)] = 0.0
    mutrates_n = [0.0] * args.nloci
    for i in [0, int(args.nloci / 2), args.nloci - 1]:
        #The next line keeps scaling, etc., same as in other sims.
        mutrates_n[i] = (10.0 / 11.0) * (args.theta / float(4 * NANC))
    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)]
    #print(mutrates_s)
    #print(mutrates_n)
    #print([10*args.rho/float(4*NANC)]*args.nloci)
    #for i in enumerate(nregions):
    #    if len(nregions[i[0]])>0:
    #        print("the type is",type(i[1]))
    #        print(i,i[1][0].b,i[1][0].e,i[1][0].w)
    #for i in enumerate(sregions):
    #    if len(sregions[i[0]])>0:
    #        print(i,i[1][0].b,i[1][0].e,i[1][0].w)
    #for i in enumerate(recregions):
    #    print(i,i[1][0].b,i[1][0].e)
    #sys.exit(0)
    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':
        mutrates_s,
        'mutrates_n':
        mutrates_n,
        'recrates': [10 * args.rho / float(4 * NANC)] * args.nloci,
    }
    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
    raise Warning("output file", args.output, "exits--exiting!")
    sys.exit(0)

N = 1000

#KRT: I changed theta and rho
#to 1100.  Thus, the value
#for each window is 100,
#which is what you will use for discoal.
theta = 1100.0  # float, not int
rho = 1100.0

rng = fp11.GSLrng(args.seed)

for rep in range(args.nreps):
    t2f = fp11qt.GSSmo([(0, 0, 1), (10 * N, 1, 1)])
    pop = fp11.SlocusPop(N)
    p = {
        'nregions': [fp11.Region(0, 11, 1.0)],  #nregions must be a region
        'sregions': [fp11.GaussianS(5, 6, 1, 0.25)],
        'recregions': [fp11.Region(0, 11, 1)],
        'mutrate_n': theta / float(4 * N),
        'mutrate_s':
        args.mutrate,  # Add this as you are using mutrate_n and recrate
        'recrate': rho / float(4 * N),
        # 'rates':(2.5e-4,1e-3,5e-3),  # Do not need this if using mutrate_n and recrate
        # Change to N instead of 10
        'demography': np.array([N] * (10 * N + 100), dtype=np.uint32),
        'gvalue': fp11tv.SlocusAdditiveTrait(2.0),
        'trait_to_fitness': t2f,
        # Do not remove selected fixations