def runsim(args):
    rng = fwdpy11.GSLrng(args.seed)

    pdict = {'gvalue': fwdpy11.Multiplicative(FITNESS_SCALING),
             'rates': (0., args.mu, None),
             'nregions': [],
             'sregions': [fwdpy11.GammaS(0., GENOME_LENGTH, 1.0-args.proportion,
                                         args.mean, args.shape, FITNESS_SCALING/2.0,
                                         scaling=2*args.popsize, label=1),
                          fwdpy11.ConstantS(0, GENOME_LENGTH, args.proportion, TWONS,
                                            FITNESS_SCALING/2.0, label=2,
                                            scaling=2*args.popsize)],
             'recregions': [fwdpy11.PoissonInterval(0, GENOME_LENGTH, args.recrate)],
             'demography': np.array([args.popsize]*SIMLEN*args.popsize, dtype=np.uint32),
             # This could easily be True for these sims:
             'prune_selected': False
             }
    params = fwdpy11.ModelParams(**pdict)

    pop = fwdpy11.DiploidPopulation(args.popsize, GENOME_LENGTH)

    sampler = fwdpy11.RandomAncientSamples(
        args.seed, args.popsize, [i for i in range(10*pop.N, SIMLEN*pop.N)])

    # With a lot of ancient samples:
    # 1. RAM use already skyrockets
    # 2. Simplification slows down
    # So, we should do it a little less often:
    fwdpy11.evolvets(rng, pop, params, 1000, sampler,
                     suppress_table_indexing=True)

    return pop
Exemplo n.º 2
0
def set_up_standard_pop_gen_model():
    """
    For this sort of model, when mutations fix, they are
    removed from the simulation, INCLUDING THE TREE
    SEQUENCES. The fact of their existence gets
    recorded in pop.fixations and pop.fixation_times
    """
    # TODO add neutral variants
    N = 1000
    demography = np.array([N] * 10 * N, dtype=np.uint32)
    rho = 1.
    # theta = 100.
    # nreps = 500
    # mu = theta/(4*N)
    r = rho / (4 * N)

    a = fwdpy11.Multiplicative(2.0)
    pselected = 1e-3
    p = {
        'nregions': [],
        'sregions': [
            fwdpy11.GammaS(0,
                           1,
                           1. - pselected,
                           mean=-5,
                           shape=1,
                           scaling=2 * N),
            fwdpy11.ConstantS(0, 1, pselected, 1000, scaling=2 * N)
        ],
        'recregions': [fwdpy11.Region(0, 1, 1)],
        'rates': (0.0, 0.001, r),
        'gvalue':
        a,
        'prune_selected':
        True,
        'demography':
        demography
    }
    params = fwdpy11.ModelParams(**p)
    rng = fwdpy11.GSLrng(666**2)
    pop = fwdpy11.DiploidPopulation(N, 1.0)
    return params, rng, pop
Exemplo n.º 3
0
set_gen = (10 * Nstart) + 200  # adjust generation labels without burnin and start
rec1 = neutral_div(set_gen, final=pop2.generation + len(demog) + 200, Nstart=Nstart)

print("evolving from here")
wf.evolve(rng2, pop2, params, rec1)
print('Generation', pop2.generation)

# write output
write_output(rec1, out_path, 'neutral', replicate)



################## simulate BGS ############################

recregion =[fp11.Region(0,55,1., coupled=True)]
sregion =   [fp11.GammaS(0, 50, 1., -0.029426, 0.184, h=1.0, coupled=True)] +\
            [fp11.GammaS(0, 50, 2., -0.000518, 0.0415, h=1.0, coupled=True)] # conserved non-coding DFE 2/3 of sel mutations in this region


nregion = [fp11.Region(50, 55, 1., coupled=True)]

# Mutation rate
rec = 8.2e-10 * 40000 * 55
mu_s = mu * 40000 * 50 * 0.2
mu_n = mu * 40000 * 5
rates = [mu_n, mu_s, rec]




# constant size for 10 N generations
Exemplo n.º 4
0
if __name__ == "__main__":
    parser = parse_args()
    args = parser.parse_args(sys.argv[1:])

    pop = fp11.SlocusPop(args.popsize)

    # Set up parameters with defaults
    recrate = args.rho / (4.0 * float(args.popsize))
    mutrate_n = args.theta / (4.0 * float(args.popsize))
    mutrate_s = args.pdel * mutrate_n

    pdict = {'rates': (mutrate_n, mutrate_s, recrate),
             'nregions': [fp11.Region(0, 1, 1)],
             # The below is equivelent to R's -1*rgamma(1,shape=1.0,scale=5.0)
             # The scaling of 2N means that the DFE is with respect to 2Ns
             'sregions': [fp11.GammaS(0, 1, 1, h=0.5, mean=-5.0, shape=1.0, scaling=2 * args.popsize)],
             'recregions': [fp11.Region(0, 1, 1)],
             'gvalue': fwdpy11.fitness.SlocusMult(1.0),
             'demography': np.array([args.popsize] * args.simlen * args.popsize, dtype=np.uint32)
             }

    params = fwdpy11.model_params.SlocusParams(**pdict)

    # Adjust params based on user input
    if args.neutral is True:
        params.mutrate_s = 0.0
        params.sregions = []

    if args.neutral_mutations is False:
        params.mutrate_n = 0.0
        params.nregions = []
Exemplo n.º 5
0
 def setUp(self):
     self.r = fwdpy11.GammaS(BEG, END, WEIGHT,
                             -0.2, 0.5, DOM, COUPLED, LABEL)
Exemplo n.º 6
0
 def testBadDominance(self):
     with self.assertRaises(ValueError):
         fwdpy11.GammaS(0, 1, 1, mean=1., shape=1., h=np.nan)
Exemplo n.º 7
0
 def testBadMean(self):
     with self.assertRaises(ValueError):
         fwdpy11.GammaS(0, 1, 1, mean=np.nan, shape=1.0)
Exemplo n.º 8
0
def runsim(args):
    args, repid, repseed = args
    rng = fwdpy11.GSLrng(repseed)
    locus_boundaries = [(float(i + i * 11), float(i + i * 11 + 11))
                        for i in range(args.nloci)]
    NANC = args.N
    # In revision, change from using gamma_hat
    # to (2Ngamma^2)/(2VS) >= 100.
    # Keep the variable name to minimize
    # the refactoring...
    # ghat = gamma_hat(1.0, args.mu)
    ghat = np.sqrt(100. / 5000.)
    sregions = None
    if args.gamma is None:
        F = generate_gaussian_function_to_minimize(ghat, args.plarge)
        sigma_gamma = get_gaussian_sigma(F)
        sregions = [[
            fwdpy11.GaussianS(j[0] + 5.,
                              j[0] + 6.,
                              args.mu,
                              sigma_gamma,
                              coupled=False)
        ] for i, j in zip(range(args.nloci), locus_boundaries)]
    else:
        # Get a shape param for the gamma
        res = scipy.optimize.minimize_scalar(minimize_gamma_cdf,
                                             bounds=(0, 100),
                                             method='bounded',
                                             args=(args.gamma, ghat,
                                                   args.plarge))
        sregions = [[
            fwdpy11.GammaS(j[0] + 5.,
                           j[0] + 6.,
                           args.mu,
                           -1.0 * res.x,
                           args.gamma,
                           coupled=False),
            fwdpy11.GammaS(j[0] + 5.,
                           j[0] + 6.,
                           args.mu,
                           res.x,
                           args.gamma,
                           coupled=False)
        ] for i, j in zip(range(args.nloci), locus_boundaries)]
    print(sregions)
    nregions = [[
        fwdpy11.Region(j[0],
                       j[1],
                       args.theta / (4. * float(NANC)),
                       coupled=True)
    ] for i, j in zip(range(args.nloci), locus_boundaries)]
    recregions = [[
        fwdpy11.Region(j[0], j[1], args.rho / (4. * float(NANC)), coupled=True)
    ] for i, j in zip(range(args.nloci), locus_boundaries)]
    interlocus_rec = fwdpy11.multilocus.binomial_rec([0.5] * (args.nloci - 1))
    nlist = np.array([NANC] * 15 * NANC, dtype=np.uint32)
    env = [(0, 0, 1), (10 * NANC, args.opt, 1)]
    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
    gssmo = fwdpy11.genetic_values.GSSmo(env)
    gv = fwdpy11.genetic_values.MlocusAdditive(2.0, gssmo)
    pdict = {
        'nregions': nregions,
        'sregions': sregions,
        'recregions': recregions,
        'demography': nlist,
        'interlocus_rec': interlocus_rec,
        'gvalue': gv,
        'rates': (mutrates_n, mutrates_s, recrates),
        'prune_selected': False
    }
    params = fwdpy11.model_params.ModelParams(**pdict)
    pop = fwdpy11.MlocusPop(args.nloci, locus_boundaries)
    sampler = Sampler(rng, args.nsam)
    fwdpy11.wright_fisher.evolve(rng, pop, params, sampler)
    sampler.rng = None  # Cannot be pickled and is not needed
    return repid, pop, sampler