Example #1
0
def runsim(argtuple):
    seed = argtuple

    rng = fwdpy11.GSLrng(seed)

    pdict = {
        'gvalue':
        fwdpy11.Multiplicative(2.),
        'rates': (0., U / 2., R),  # The U/2. is from their eqn. 2.
        'nregions': [],
        'sregions': [
            fwdpy11.ConstantS(0, 1. / 3., 1, -0.02, 1.),
            fwdpy11.ConstantS(2. / 3., 1., 1, -0.02, 1.)
        ],
        'recregions':
        [fwdpy11.Region(0, 1. / 3., 1),
         fwdpy11.Region(2. / 3., 1., 1)],
        'demography':
        np.array([N] * 20 * N, dtype=np.uint32)
    }
    params = fwdpy11.ModelParams(**pdict)

    pop = fwdpy11.DiploidPopulation(N, GENOME_LENGTH)

    fwdpy11.evolvets(rng, pop, params, 100, suppress_table_indexing=True)

    rdips = np.random.choice(N, NSAM, replace=False)
    md = np.array(pop.diploid_metadata, copy=False)
    rdip_nodes = md['nodes'][rdips].flatten()
    nodes = np.array(pop.tables.nodes, copy=False)
    # Only visit trees spanning the
    # mutation-free segment of the genome
    tv = fwdpy11.TreeIterator(pop.tables,
                              rdip_nodes,
                              begin=1. / 3.,
                              end=2. / 3.)
    plist = np.zeros(len(nodes), dtype=np.int8)
    sum_pairwise_tmrca = 0
    for t in tv:
        for i in range(len(rdip_nodes) - 1):
            u = rdip_nodes[i]
            while u != fwdpy11.NULL_NODE:
                plist[u] = 1
                u = t.parent(u)
            for j in range(i + 1, len(rdip_nodes)):
                u = rdip_nodes[j]
                while u != fwdpy11.NULL_NODE:
                    if plist[u] == 1:
                        sum_pairwise_tmrca += 2 * \
                            (pop.generation-nodes['time'][u])
                        u = fwdpy11.NULL_NODE
                    else:
                        u = t.parent(u)
            plist.fill(0)
    return 2 * sum_pairwise_tmrca / (len(rdip_nodes) * (len(rdip_nodes) - 1))
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
Example #3
0
def build_parameters_dict(args):
    """
    Returns sim params and the final sizes
    in each deme
    """
    demog, simlen, finalNs = build_demography(args)

    nregions = []
    sregions = []
    recregions = [fwdpy11.PoissonInterval(0, 1, args.rho / (4.0 * args.Nref))]

    rates = (0, 0, None)
    if args.gamma is not None:
        sregions = [
            fwdpy11.ConstantS(0,
                              1,
                              1,
                              args.gamma,
                              args.H,
                              scaling=2 * args.Nref)
        ]
        rates = (0, args.theta / (4.0 * args.Nref), None)

    pdict = {
        "nregions": nregions,
        "sregions": sregions,
        "recregions": recregions,
        "rates": rates,
        "gvalue": fwdpy11.Multiplicative(2.0),
        "demography": demog,
        "simlen": simlen,
        "prune_selected": True,
    }

    return pdict, simlen, finalNs
Example #4
0
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 setUp(self):
     self.pop = fwdpy11.DiploidPopulation(1000)
     self.pdict = fwdpy11.ezparams.mslike(self.pop,
                                          dfe=fwdpy11.ConstantS(
                                              0, 1, 1, -0.05, 0.05),
                                          pneutral=0.95,
                                          simlen=10)
     self.pdict['gvalue'] = general.GeneralW()
     self.rng = fwdpy11.GSLrng(42)
     self.params = fwdpy11.ModelParams(**self.pdict)
Example #6
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
Example #7
0
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)):
    """
    Wrapper around evolve_track to facilitate testing.

    :param popsize: Diploid population size.
    :param rho: 4Nr
    :param mu: Mutation rate to selected alleles
    :param seed: RNG seed
    :param gc_interval: Garbage collection interval.
    :param dfe: An instance of a fwdpy11.Sregion

    :rtype: tuple

    :return: See evolve_track for details.
    """
    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] * 20 * popsize, dtype=np.uint32)
             }

    params = fwdpy11.model_params.SlocusParams(**pdict)
    rng = fwdpy11.GSLrng(seed)
    return evolve_track(rng, pop, params, gc_interval)
Example #8
0
 def setUp(self):
     self.nregions = [fwdpy11.Region(0, 1, 1)]
     self.sregions = [fwdpy11.ConstantS(
         0, 1, 1, -0.1, 0.25), fwdpy11.ExpS(0, 1, 0.001, 0.01, 1.0)]
Example #9
0
 def setUp(self):
     self.r = fwdpy11.ConstantS(BEG, END, WEIGHT,
                                0.5, DOM, COUPLED, LABEL)
Example #10
0
 def testBadDominance(self):
     with self.assertRaises(ValueError):
         fwdpy11.ConstantS(0, 1, 1, 1, np.nan)
Example #11
0
print(models)



Nstart = 20000#int(demog.item(0))
mu = 1.66e-8

s_value= float(float(gamma_value)/(2*float(Nstart)))

print(s_value)

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

recregion =[fp11.Region(0,55,1., coupled=True)]
sregion =   [fp11.ConstantS(0, 50, 1., s_value, h=1.0, coupled=True)]
#sregion = [fp11.GammaS(-1, 0, 1, -0.83, 0.01514, h=1.0, coupled=True)]


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