Stdpopsim: Output SLiM code for population models

Created on 4 Feb 2019  路  4Comments  路  Source: popsim-consortium/stdpopsim

The population models are current defined in terms of the msprime APIs for defining populations, migration matrices and demographic events. Ideally, we would like to make these apply to SLiM also, so that we don't have to write the population models twice. Is it possible, even in principle, to output fragments of Eidos code which would implement the intended demography?

Concretely, we'd have something like

import string
import stdpopsim
from stdpopsim import homo_sapiens

chrom = homo_sapiens.genome.chromosomes["chr22"]
model = homo_sapiens.GutenkunstThreePopOutOfAfrica()

slim_template = string.Template("""
initialize() {
    initializeTreeSeq();
    initializeMutationRate(0);
    initializeMutationType("m1", 0.5, "f", 0.0);
    initializeGenomicElementType("g1", m1, 1.0);
    initializeGenomicElement(g1, 0, 1e8-1);
    initializeRecombinationRate($recombination_rate);
}

$demographic_model

5000late() {
     sim.treeSeqOutput("ex1_TS.trees");
}""")
slim_program = slim_template.substitute(
    recombination_rate=chrom.mean_recombination_rate,
    demographic_model=model.as_slim())
ts = pyslim.run(slim_program)

Any thoughts @petrelharp, @benhaller?

Most helpful comment

@petrelharp, @andrewkern would this be a good project for me?

All 4 comments

Oops, make that @bhaller.

@jeromekelleher I don't see why not, in principle. You can probably just generate "WF" type models (like the example you post above), which keeps things simpler than the non-Wright-Fisher model type. And for simple models like this the auto-generated demographic code probably won't interact in unexpected ways with other aspects of the model since the rest of the model is very simple. For a bit of guidance on how to proceed, I'd recommend looking at section 5.4 of the SLiM manual (available from messerlab.org/slim/), which shows how to write the Gravel model of human evolution in SLiM. It has subpopulation splits, migration, and exponential growth. Generalizing that to auto-generated code for any msprime demographic model will doubtless be annoying, but I don't see any fundamental obstacle, and it might prove to be a useful tool for others, too. Conceivably you could write general Eidos code that would run the demographics driven by some sort of table-based input of the desired behavior, but the Eidos language might be a bit too limited for that sort of general-purpose code to be easy; generating the appropriate Eidos code in Python from the same data might prove easier. But I'm not sure which approach is better; you might explore both at least a bit. Anyway, let me know if you run into issues.

@petrelharp, @andrewkern would this be a good project for me?

Closing this as it's covered by the ongoing SLiM engine project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grahamgower picture grahamgower  路  6Comments

agladstein picture agladstein  路  7Comments

David-Peede picture David-Peede  路  6Comments

agladstein picture agladstein  路  5Comments

agladstein picture agladstein  路  4Comments