Hi,
Thanks for the great piece of software.
At the moment I am trying out the pyslim interface to start a simulation from a coalescent history or to recapitate a simulation.
Because recapitating in my specific scenario seems to take ages (probably due to sequence length of 8.5Mb and the chosen recombination rate, as well as migration of 0.01 between the demes) I decided to start from a neutral coalescent history (which is faster). This is the code I ran in msprime.
#msprime code
---------------------
length = 8.5e6
recombination_rate = 1.15e-8
mutation_rate = 0.0
Ne = 1e6
m = 0.01
M = np.array([
[0,m],
[m,0]])
pop_configs = [
msprime.PopulationConfiguration(sample_size=1000),
msprime.PopulationConfiguration(sample_size=1000)]
ts = msprime.simulate(population_configurations=pop_configs, migration_matrix=M, length=length)
new_ts = pyslim.annotate_defaults(ts, model_type="WF", slim_generation=1)
new_ts.dump(directory+'/neutr.trees')
---------------------
I then use the resulting treeSequence to start the following slim simulation (using QTLs as described in the SLiM recipe).
However after 20 time steps I always get the following error:
table_collection_sort: time[parent] must be greater than time[child]
#(SLiM code)
---------------------
initialize() {
defineConstant("optimum1", 2);
defineConstant("optimum2", -2);
//standard deviation normal distribution
defineConstant("sigma", 2.5);
defineConstant("sigma_m", 0.05);
defineConstant("simID", getSeed());
defineConstant("generations", 1000);
defineConstant("n_loci", 1000);
defineConstant("migration", 0.01);
defineConstant("mutation_rate", 3.46e-6);
//sample n_loci random positions
positions = sort(sample(4245000:4255000, n_loci));
defineConstant("POS", positions);
//adapt so enough neutral sequence at ends
ends = c(positions[n_loci-1], 8500000-1);
rates = c(mutation_rate, 0);
//use spatial dimension to store sum of effect sizes
//initializeSLiMOptions(dimensionality="x");
//mutation rate defined for all n_loci sites, add neutral section after last mutation site
initializeMutationRate(rates, ends);
// m1 mutation
initializeMutationType("m1", 0.5, "n", 0.0, sigma_m); //QTL
//make sure slim includes fixed mutations to calculate fitness
m1.convertToSubstitution = F;
//multiple mutations on one locus, stack effect sizes s, only remember last
m1.mutationStackPolicy = "l";
// g1 genomic element type: uses m1 for all mutations
initializeGenomicElementType("g1", m1, 1.0);
for (element in positions)
initializeGenomicElement(g1, element, element);
initializeRecombinationRate(1.15e-5);
initializeTreeSeq();
}
1 {
sim.readFromPopulationFile('neutr.trees');
//size in each deme 1000
//sim.addSubpop("p1", 1000);
//sim.addSubpop("p2", 1000);
p0.setMigrationRates(p1, migration);
p1.setMigrationRates(p0, migration);
}
1: late(){
inds = sim.subpopulations.individuals;
inds.tagF = inds.sumOfMutationsOfType(m1);
}
//make QTLs intrinsically neutral
fitness(m1){
return 1.0;
}
//calculate fitness based on sum of effect size of all loci
//selection to different optima (2.0 and -2.0)
1: fitness(NULL, p0){
return 1 + exp(-((individual.tagF - optimum1)^2)/(2*sigma^2));
}
1: fitness(NULL, p1){
return 1 + exp(-((individual.tagF - optimum2)^2)/(2*sigma^2));
}
1000 late() {
sim.treeSeqOutput('loc_adap.trees');
sim.simulationFinished();}
---------------------
I think I annotated the msprime treeSequence properly, so I can't figure out what I did wrong.
Any help would be greatly appreciated.
Kind regards,
gertjan