Skip to content

Commit 48df842

Browse files
committed
add recipe 22.7 back in
1 parent bc93dd5 commit 48df842

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

QtSLiM/recipes.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,6 @@
202202
<file>recipes/Recipe 19.6 - A coevolutionary host-parasitoid trait-matching model.txt</file>
203203
<file>recipes/Recipe 19.7 - A coevolutionary host-parasite matching-allele model.txt</file>
204204
<file>recipes/Recipe 19.8 - Within-host reproduction in a host-pathogen model.txt</file>
205+
<file>recipes/Recipe 22.7 - Parallelizing nonWF reproduction and spatial interactions.txt</file>
205206
</qresource>
206207
</RCC>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
initialize() {
2+
initializeSLiMModelType("nonWF");
3+
initializeSLiMOptions(dimensionality="xy");
4+
defineConstant("K", 100000); // carrying-capacity density
5+
defineConstant("S", 0.005); // sigma_S, the spatial interaction width
6+
defineConstant("M", 0.025); // sigma_M, the spatial mating width
7+
8+
initializeMutationType("m1", 0.5, "f", 0.0);
9+
m1.convertToSubstitution = T;
10+
11+
initializeGenomicElementType("g1", m1, 1.0);
12+
initializeGenomicElement(g1, 0, 1e8 - 1);
13+
initializeMutationRate(1e-7);
14+
initializeRecombinationRate(1e-8);
15+
16+
// competition kernel
17+
initializeInteractionType(1, "xy", reciprocal=T, maxDistance=S * 2);
18+
i1.setInteractionFunction("n", 1.0, S);
19+
20+
// mating kernel
21+
initializeInteractionType(2, "xy", reciprocal=T, maxDistance=M * 2);
22+
i1.setInteractionFunction("n", 1.0, M);
23+
}
24+
2: first() {
25+
i2.evaluate(p1);
26+
}
27+
reproduction() {
28+
inds = p1.individuals;
29+
mates = i2.drawByStrength(inds, 1, returnDict=T);
30+
order = mates.compactIndices();
31+
inds = inds[order];
32+
num = rpois(size(inds), 5);
33+
nonzero_indices = which(num > 0);
34+
35+
for (i in nonzero_indices)
36+
{
37+
ind = inds[i];
38+
offspring = p1.addCrossed(ind, mates.getValue(i), count=num[i], defer=T);
39+
offspring.setSpatialPosition(ind.spatialPosition);
40+
}
41+
42+
self.active = 0;
43+
}
44+
1 early() {
45+
sim.addSubpop("p1", K);
46+
p1.individuals.setSpatialPosition(p1.pointUniform(K));
47+
}
48+
early() {
49+
// deviate offspring from their maternal positions
50+
newborns = p1.subsetIndividuals(maxAge=0);
51+
old_pos = newborns.spatialPosition;
52+
new_pos = p1.pointReflected(old_pos + rnorm(size(old_pos), 0, 0.02));
53+
newborns.setSpatialPosition(new_pos);
54+
}
55+
early() {
56+
// spatial competition
57+
i1.evaluate(p1);
58+
inds = p1.individuals;
59+
competition = i1.localPopulationDensity(inds);
60+
inds.fitnessScaling = K / competition;
61+
}
62+
100 late() { }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
initialize() {
2+
initializeSLiMModelType("nonWF");
3+
initializeSLiMOptions(dimensionality="xy");
4+
defineConstant("K", 100000); // carrying-capacity density
5+
defineConstant("S", 0.005); // sigma_S, the spatial interaction width
6+
defineConstant("M", 0.025); // sigma_M, the spatial mating width
7+
8+
initializeMutationType("m1", 0.5, "f", 0.0);
9+
m1.convertToSubstitution = T;
10+
11+
initializeGenomicElementType("g1", m1, 1.0);
12+
initializeGenomicElement(g1, 0, 1e8 - 1);
13+
initializeMutationRate(1e-7);
14+
initializeRecombinationRate(1e-8);
15+
16+
// competition kernel
17+
initializeInteractionType(1, "xy", reciprocal=T, maxDistance=S * 2);
18+
i1.setInteractionFunction("n", 1.0, S);
19+
20+
// mating kernel
21+
initializeInteractionType(2, "xy", reciprocal=T, maxDistance=M * 2);
22+
i1.setInteractionFunction("n", 1.0, M);
23+
}
24+
2: first() {
25+
i2.evaluate(p1);
26+
}
27+
reproduction() {
28+
inds = p1.individuals;
29+
mates = i2.drawByStrength(inds, 1, returnDict=T);
30+
order = mates.compactIndices();
31+
inds = inds[order];
32+
num = rpois(size(inds), 5);
33+
nonzero_indices = which(num > 0);
34+
35+
for (i in nonzero_indices)
36+
{
37+
ind = inds[i];
38+
offspring = p1.addCrossed(ind, mates.getValue(i), count=num[i], defer=T);
39+
offspring.setSpatialPosition(ind.spatialPosition);
40+
}
41+
42+
self.active = 0;
43+
}
44+
1 early() {
45+
sim.addSubpop("p1", K);
46+
p1.individuals.setSpatialPosition(p1.pointUniform(K));
47+
}
48+
early() {
49+
// deviate offspring from their maternal positions
50+
newborns = p1.subsetIndividuals(maxAge=0);
51+
old_pos = newborns.spatialPosition;
52+
new_pos = p1.pointReflected(old_pos + rnorm(size(old_pos), 0, 0.02));
53+
newborns.setSpatialPosition(new_pos);
54+
}
55+
early() {
56+
// spatial competition
57+
i1.evaluate(p1);
58+
inds = p1.individuals;
59+
competition = i1.localPopulationDensity(inds);
60+
inds.fitnessScaling = K / competition;
61+
}
62+
100 late() { }

0 commit comments

Comments
 (0)