Пример #1
0
def _twopop_IM(engine_id,
               out_dir,
               seed,
               NA=1000,
               N1=500,
               N2=5000,
               T=1000,
               M12=0,
               M21=0,
               pulse=None,
               **sim_kwargs):
    species = stdpopsim.get_species("AraTha")
    contig = species.get_contig("chr5", length_multiplier=0.01)  # ~270 kb
    model = stdpopsim.IsolationWithMigration(NA=NA,
                                             N1=N1,
                                             N2=N2,
                                             T=T,
                                             M12=M12,
                                             M21=M21)
    if pulse is not None:
        model.demographic_events.append(pulse)
        model.demographic_events.sort(key=lambda x: x.time)
    model.generation_time = species.generation_time
    samples = model.get_samples(50, 50, 0)
    engine = stdpopsim.get_engine(engine_id)
    t0 = time.perf_counter()
    ts = engine.simulate(model, contig, samples, seed=seed, **sim_kwargs)
    t1 = time.perf_counter()
    out_file = out_dir / f"{seed}.trees"
    ts.dump(out_file)
    return out_file, t1 - t0
Пример #2
0
    def test_bad_population_size_addSubpopSplit(self):
        engine, species, contig = self.triplet()
        model = stdpopsim.IsolationWithMigration(NA=1000,
                                                 N1=100,
                                                 N2=1000,
                                                 T=1000,
                                                 M12=0,
                                                 M21=0)
        samples = model.get_samples(2)

        with self.assertWarns(stdpopsim.UnspecifiedSLiMWarning):
            engine.simulate(
                demographic_model=model,
                contig=contig,
                samples=samples,
                slim_scaling_factor=10,
                dry_run=True,
            )

        with self.assertRaises(stdpopsim.SLiMException):
            engine.simulate(
                demographic_model=model,
                contig=contig,
                samples=samples,
                slim_scaling_factor=200,
                dry_run=True,
            )
Пример #3
0
    def test_bad_population_size_addSubpopSplit(self):
        engine, species, contig = self.triplet()
        model = stdpopsim.IsolationWithMigration(
                NA=1000, N1=100, N2=1000, T=1000, M12=0, M21=0)
        samples = model.get_samples(2)

        with mock.patch("warnings.warn", autospec=True) as mock_warning:
            engine.simulate(
                    demographic_model=model, contig=contig, samples=samples,
                    slim_scaling_factor=10, dry_run=True)
        mock_warning.assert_called_once()

        with self.assertRaises(stdpopsim.SLiMException):
            engine.simulate(
                    demographic_model=model, contig=contig, samples=samples,
                    slim_scaling_factor=200, dry_run=True)
Пример #4
0
def _twopop_IM(
    engine_id,
    out_dir,
    seed,
    NA=1000,
    N1=500,
    N2=5000,
    T=1000,
    M12=0,
    M21=0,
    pulse=None,
    samples=None,
    **sim_kwargs,
):
    species = stdpopsim.get_species("AraTha")
    contig = species.get_contig("chr5", length_multiplier=0.01)  # ~270 kb
    contig = irradiate(contig)
    model = stdpopsim.IsolationWithMigration(NA=NA,
                                             N1=N1,
                                             N2=N2,
                                             T=T,
                                             M12=M12,
                                             M21=M21)
    if pulse is not None:
        model.demographic_events.append(pulse)
        model.demographic_events.sort(key=lambda x: x.time)
    # XXX: AraTha has species.generation_time == 1, but there is the potential
    # for this to mask bugs related to generation_time scaling, so we use 3 here.
    model.generation_time = 3
    if samples is None:
        samples = model.get_samples(50, 50, 0)
    engine = stdpopsim.get_engine(engine_id)
    t0 = time.perf_counter()
    ts = engine.simulate(model, contig, samples, seed=seed, **sim_kwargs)
    t1 = time.perf_counter()
    out_file = out_dir / f"{seed}.trees"
    ts.dump(out_file)
    return out_file, t1 - t0
Пример #5
0
import stdpopsim,sys

## I would like to simulate Drosophila melanogaster please
species = stdpopsim.get_species("DroMel")
## I have specified the desired chromosome arm at the command line, let's 
contig = species.get_contig(sys.argv[1], genetic_map = "ComeronCrossover_dm6")
## For testing, it is good to model a lil chunk of chromosome
#contig = species.get_contig(sys.argv[1], length_multiplier = 0.10)

## You can grab the genetic map out of the simulations using:
#for p, r in zip( contig.recombination_map.get_positions() , contig.recombination_map.get_rates() ):
#	print( p , r )

Ne = species.population_size/10
#Ne = 10000
model = stdpopsim.IsolationWithMigration(2*Ne, Ne, Ne, Ne, 1.5/Ne, 1.5/Ne)

print("NA", "N1", "N2", "T", "M12", "M21")
print( 2*Ne, Ne, Ne, Ne, 1.5/Ne, 1.5/Ne)

## I want to simulate 20 samples from each population
samples = model.get_samples(20,20)

## I will simulate using msprime
engine = stdpopsim.get_default_engine()

print("running simulation")
ts = engine.simulate(model, contig, samples)

## Save the simulated data to a VCF
with open("drosophilaSimulated."+ sys.argv[1] + ".vcf", "w") as vcf_file: