示例#1
0
def runsim(args):
    popsizes = np.array([args.popsize] * 20 * args.popsize, dtype=np.int32)
    locus_boundaries = [(i, i + 11) for i in range(0, 10 * 11, 11)]
    sregions = [fwdpy11.GaussianS(i[0] + 5, i[0] + 6, 1, args.sigma)
                for i in locus_boundaries]
    recregions = [fwdpy11.PoissonInterval(
        *i, args.rho / (4 * args.popsize)) for i in locus_boundaries]
    recregions.extend([fwdpy11.BinomialPoint(i[1], 0.5)
                       for i in locus_boundaries[:-1]])
    pop = fwdpy11.DiploidPopulation(args.popsize, locus_boundaries[-1][1])

    optima = fwdpy11.GSSmo(
        [(0, 0, args.VS), (10 * args.popsize, args.opt, args.VS)])
    p = {'nregions': [],  # No neutral mutations -- add them later!
         'gvalue': fwdpy11.Additive(2.0, optima),
         'sregions': sregions,
         'recregions': recregions,
         'rates': (0.0, args.mu, None),
         # Keep mutations at frequency 1 in the pop if they affect fitness.
         'prune_selected': False,
         'demography':  np.array(popsizes, dtype=np.uint32)
         }
    params = fwdpy11.ModelParams(**p)
    rng = fwdpy11.GSLrng(args.seed)
    s = Recorder(args.popsize)
    fwdpy11.evolvets(rng, pop, params, 100, s,
                     suppress_table_indexing=True,
                     track_mutation_counts=True)
    return pop
示例#2
0
def runsim(args):
    popsizes = np.array([args.popsize] * 20 * args.popsize, dtype=np.int32)
    pop = fwdpy11.DiploidPopulation(args.popsize, 1.0)
    sregions = [fwdpy11.GaussianS(0, 1, 1, args.sigma)]
    recregions = [fwdpy11.PoissonInterval(0, 1, args.recrate)]

    optima = fwdpy11.GSSmo([(0, 0, args.VS),
                            (10 * args.popsize, args.opt, args.VS)])
    p = {
        'nregions': [],  # No neutral mutations -- add them later!
        'gvalue': fwdpy11.Additive(2.0, optima),
        'sregions': sregions,
        'recregions': recregions,
        'rates': (0.0, args.mu, None),
        # Keep mutations at frequency 1 in the pop if they affect fitness.
        'prune_selected': False,
        'demography': np.array(popsizes, dtype=np.uint32)
    }
    params = fwdpy11.ModelParams(**p)
    rng = fwdpy11.GSLrng(args.seed)
    s = Recorder(args.popsize)
    fwdpy11.evolvets(rng,
                     pop,
                     params,
                     100,
                     s,
                     suppress_table_indexing=True,
                     track_mutation_counts=True)
    return pop
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
示例#4
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
示例#5
0
def runsim(args, simseed, npseed):
    dg = demes.load(args.yaml)

    final_demes = get_final_demes(dg)

    demog = fwdpy11.discrete_demography.from_demes(dg, burnin=args.burnin)

    final_deme_ids = sorted([
        i for i in demog.metadata["deme_labels"]
        if demog.metadata["deme_labels"][i] in final_demes
    ])

    initial_sizes = [
        demog.metadata["initial_sizes"][i]
        for i in sorted(demog.metadata["initial_sizes"].keys())
    ]
    recrate = RHO / (4.0 * initial_sizes[0])

    pdict = {
        "nregions": [],
        "sregions": [],
        "recregions": [fwdpy11.PoissonInterval(0, 1, recrate)],
        "gvalue": fwdpy11.Multiplicative(2.0),
        "rates": (0.0, 0.0, None),
        "simlen": demog.metadata["total_simulation_length"],
        "demography": demog,
    }
    params = fwdpy11.ModelParams(**pdict)
    pop = fwdpy11.DiploidPopulation(initial_sizes, 1.0)

    # FIXME: need seed as input argument to this fxn
    rng = fwdpy11.GSLrng(simseed)
    np.random.seed(npseed)

    fwdpy11.evolvets(rng, pop, params, 100)

    nmuts = fwdpy11.infinite_sites(rng, pop, THETA / (4.0 * initial_sizes[0]))

    md = np.array(pop.diploid_metadata, copy=False)
    sample_nodes = []
    for i in final_deme_ids:
        w = np.where(md["deme"] == i)
        s = np.random.choice(w[0], args.nsam, replace=False)
        sample_nodes.append(md["nodes"][s].flatten())

    fs = pop.tables.fs(sample_nodes)

    return fs
示例#6
0
    def testQtraitSim(self):
        N = 1000
        demography = np.array([N] * 10 * N, dtype=np.uint32)
        rho = 1.
        r = rho / (4 * N)

        GSS = fwdpy11.GSS(VS=1, opt=1)
        a = fwdpy11.Additive(2.0, GSS)
        p = {
            'nregions': [],
            'sregions': [fwdpy11.GaussianS(0, 1, 1, 0.25)],
            'recregions': [fwdpy11.PoissonInterval(0, 1, r)],
            'rates': (0.0, 0.005, None),
            'gvalue': a,
            'prune_selected': False,
            'demography': demography
        }
        params = fwdpy11.ModelParams(**p)
        rng = fwdpy11.GSLrng(101 * 45 * 110 * 210)
        pop = fwdpy11.DiploidPopulation(N, 1.0)

        class Recorder(object):
            """ Records entire pop every 100 generations """
            def __call__(self, pop, recorder):
                if pop.generation % 100 == 0.0:
                    recorder.assign(np.arange(pop.N, dtype=np.int32))

        r = Recorder()
        fwdpy11.evolvets(rng, pop, params, 100, r)

        ancient_sample_metadata = np.array(pop.ancient_sample_metadata,
                                           copy=False)
        alive_sample_metadata = np.array(pop.diploid_metadata, copy=False)
        metadata = np.hstack((ancient_sample_metadata, alive_sample_metadata))

        nodes = np.array(pop.tables.nodes, copy=False)
        metadata_nodes = metadata['nodes'].flatten()
        metadata_node_times = nodes['time'][metadata_nodes]
        metadata_record_times = nodes['time'][metadata['nodes'][:, 0]]

        genetic_trait_values_from_sim = []
        genetic_values_from_ts = []
        for u in np.unique(metadata_node_times):
            samples_at_time_u = metadata_nodes[np.where(
                metadata_node_times == u)]
            vi = fwdpy11.VariantIterator(pop.tables, samples_at_time_u)
            sum_esizes = np.zeros(len(samples_at_time_u))
            for variant in vi:
                g = variant.genotypes
                r = variant.records[0]
                mutant = np.where(g == 1)[0]
                sum_esizes[mutant] += pop.mutations[r.key].s
            ind = int(len(samples_at_time_u) / 2)
            temp_gvalues = np.zeros(ind)
            temp_gvalues += sum_esizes[0::2]
            temp_gvalues += sum_esizes[1::2]
            genetic_values_from_ts.extend(temp_gvalues.tolist())
            genetic_trait_values_from_sim.extend(metadata['g'][np.where(
                metadata_record_times == u)[0]].tolist())

        for i, j in zip(genetic_trait_values_from_sim, genetic_values_from_ts):
            self.assertAlmostEqual(i, j)
示例#7
0
 def setUp(self):
     self.pi = fwdpy11.PoissonInterval(0, 1, 1e-3)