slim code to simulate a selective sweep at a locus on a 1Mbp chromosome, with mutation rate \(\mu=10^{-8}\), recombination rate \(\rho=10^{-8}\), and \(N_e=5,000\).
initialize() {defineConstant("Nref", 5e3);if (!exists("seed"))defineConstant("seed", getSeed());defineConstant("SimID", seed);if (!exists("N"))defineConstant("N", Nref);if (!exists("outdir"))defineConstant("outdir", tempdir());if (!exists("mu"))defineConstant("mu", 1e-8);if (!exists("rho"))defineConstant("rho", 1e-8);if (!exists("seqlength"))defineConstant("seqlength", 1e6);if (!exists("position"))defineConstant("position", asInteger(seqlength /2));if (!exists("outfile"))defineConstant("outfile", outdir +"slim_"+ SimID +".rho_"+ rho +".mu_"+ mu +".N_"+ N +".trees");setSeed(seed);initializeTreeSeq(simplificationRatio=INF);initializeMutationRate(0);initializeMutationType("m1", 0.5, "f", 0.0);initializeMutationType("m2", 1.0, "f", 0.5); // introduced mutationinitializeGenomicElementType("g1", m1, 1.0);initializeGenomicElement(g1, 0, seqlength -1);initializeRecombinationRate(rho);}1early() {// Chapter 14.9: SLiM models diploid individuals that contain two// haploid genomes; this is, at present, a design constraint in SLiM// that cannot be modified. IOW: N individuals, 2*N genomessim.addSubpop("p1", N);}1000late() {// introduce the sweep mutation target =sample(p1.genomes, 1);target.addNewDrawnMutation(m2, position);// save the state of the simulationsim.treeSeqOutput(tempdir() +"slim_"+ SimID +".trees");}1000:100000late() {if (sim.countOfMutationsOfType(m2) ==0) { fixed = (sum(sim.substitutions.mutationType == m2) ==1);if (fixed) {cat(SimID +": FIXED\n");cat("Writing output file : "+ outfile +"\n");sim.treeSeqOutput(outfile);sim.simulationFinished(); }else {cat(SimID +": LOST - RESTARTING\n");// go back to tick 1000sim.readFromPopulationFile(tempdir() +"slim_"+ SimID +".trees");setSeed(rdunif(1, 0, asInteger(2^62) -1)); } }}
Recipe to simulate a selective sweep.
1.2 Neutral simulation
slim code to simulate a neutrally evolving locus on a 100kbp chromosome, with mutation rate \(\mu=10^{-8}\), recombination rate \(\rho=10^{-8}\), and \(N_e=5,000\).