I created a 3-population model in Slim with an initial split at 2e3 generations and a more recent split at 1e3, with a selective sweep occurring in the third (most recent split) population. The only mutations introduced by Slim are those undergoing the sweep in the third population.
The three populations have respective sizes 2e4, 4e3, and 4e3
When I recapitate this tree with an ancestral population size of 2e4 and apply mutations at a per-site substitution rate of 1.22e-8, I obtain nucleotide diversity that is nearly 100-fold too low. The population of size 20K undergoing neutral evolution should have pi ~ 1e-3, what I get instead is 2e-5. When I run the same mutation/recombination/conversion rates for this demogrpahic in msprime, I get the correct value of pi.
I suspect that the problem is in the recapitation step, but I don't see the possible source of error.
I've appended both my slim and pyslim code below:
Slim code for 3 population demography and sweep in third population, conditioning on fixation, generates ThreePopFix.trees
initialize() {
initializeTreeSeq();
initializeMutationRate(0);
initializeMutationType("m2", 1.0, "f", 0.025);
initializeGenomicElementType("g1", m2, 1.0);
initializeGenomicElement(g1, 0, 99999);
initializeRecombinationRate(7.04e-8);
initializeGeneConversion(0.838, 518, 1.0);
}
1 early() {defineConstant("simID", getSeed());}
1 early() { sim.addSubpop("p1", 2e+4); }
1 early() { sim.addSubpopSplit("p2", 4e+3, p1); }
1000 early() { sim.addSubpopSplit("p3", 4e+3, p2); }
1000 late() {
sim.outputFull("restart_slim_" + simID + ".txt");
x = rdunif(1,0,99999);
target = sample(p3.genomes, 8, replace=F);
target.addNewDrawnMutation(m2, x);
}
2000 late() {
m2mut = sim.mutationsOfType(m2);
freqs = sim.mutationFrequencies(p3, m2mut);
//print(freqs);
if(any(freqs == 1.0)){
cat(simID + ": FIXED\n");
sim.deregisterScriptBlock(self);
sim.treeSeqOutput("ThreePopFix.trees");
sim.simulationFinished();
}
else
{
//cat(simID + " : NOT FIXED - RESTARTING\n");
sim.readFromPopulationFile("restart_slim_" + simID + ".txt");
setSeed(rdunif(1, 0, asInteger(2^62) - 1));
// re-introduce a sweep mutation
x = rdunif(1,0,99999);
target = sample(p3.genomes, 8, replace=F);
target.addNewDrawnMutation(m2, x);
}
}
Recapitation (with ancestral population of 2e4, no structure) and applying mutations:
ts = tskit.load("ThreePopFix.trees")
ts_new = pyslim.SlimTreeSequence(ts)
rts = pyslim.recapitate(ts_new, recombination_rate = 1.14e-8, gene_conversion_rate = 5.9e-8, gene_conversion_tract_length = 518, ancestral_Ne=20000, random_seed = 10)
mts = msprime.sim_mutations(rts, rate = 1.22e-8, keep=True, random_seed = mutation_seed, model=msprime.BinaryMutationModel())
diversity = mts.diversity(sample_sets=[mts.samples(population=1), mts.samples(population=2), mts.samples(population=3),]).tolist()