コード例 #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
コード例 #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
コード例 #3
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([0.5] * (args.nloci - 1))
    nlist = np.array([NANC] * args.simlen * NANC, dtype=np.uint32)

    # the tuples are (time, z_o, VS)
    env = [(0, 0, 1), (10 * NANC, args.opt, 1)]
    gv = fwdpy11.genetic_values.MlocusAdditive(
        2.0, fwdpy11.genetic_values.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
    pdict = {
        'nregions': nregions,
        'sregions': sregions,
        'recregions': recregions,
        'demography': nlist,
        'interlocus_rec': interlocus_rec,
        'rates': (mutrates_n, mutrates_s, recrates),
        'gvalue': gv,
        'prune_selected': False
    }
    params = fp11.model_params.ModelParams(**pdict)
    recorder = HapStatSampler(repid, NANC, args.nsam)
    # sched prevents the TBB library
    # from over-subscribing a node
    # when running many sims in parallel
    sched = None
    if HAVESCHED is True:
        sched = Scheduler(1)
    pop = fp11.MlocusPop(NANC, locus_boundaries)
    assert pop.nloci == len(locus_boundaries), "nloci != len(locus_boundaries)"
    fwdpy11.wright_fisher.evolve(rng, pop, params, recorder)
    return repid, recorder.data, pop
コード例 #4
0
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
コード例 #5
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)]
    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