Skip to content

Commit ad71419

Browse files
committed
adjust ids versus indices in recipe 5.3.1
1 parent d908c65 commit ad71419

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Keywords: migration, dispersal
22

33
initialize() {
4+
defineConstant("COUNT", 10);
45
initializeMutationRate(1e-7);
56
initializeMutationType("m1", 0.5, "f", 0.0);
67
initializeGenomicElementType("g1", m1, 1.0);
78
initializeGenomicElement(g1, 0, 99999);
89
initializeRecombinationRate(1e-8);
910
}
1011
1 early() {
11-
subpopCount = 10;
12-
for (i in 1:subpopCount)
12+
for (i in 0:(COUNT-1))
1313
sim.addSubpop(i, 500);
14-
for (i in 2:subpopCount)
15-
sim.subpopulations[i-1].setMigrationRates(i-1, 0.2);
16-
for (i in 1:(subpopCount-1))
17-
sim.subpopulations[i-1].setMigrationRates(i+1, 0.05);
14+
15+
subpops = sim.subpopulations;
16+
for (i in 1:(COUNT-1)) subpops[i].setMigrationRates(i-1, 0.2);
17+
for (i in 0:(COUNT-2)) subpops[i].setMigrationRates(i+1, 0.05);
1818
}
1919
10000 late() { sim.outputFixedMutations(); }
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Keywords: migration, dispersal
22

33
initialize() {
4+
defineConstant("COUNT", 10);
45
initializeMutationRate(1e-7);
56
initializeMutationType("m1", 0.5, "f", 0.0);
67
initializeGenomicElementType("g1", m1, 1.0);
78
initializeGenomicElement(g1, 0, 99999);
89
initializeRecombinationRate(1e-8);
910
}
1011
1 early() {
11-
subpopCount = 10;
12-
for (i in 1:subpopCount)
12+
for (i in 0:(COUNT-1))
1313
sim.addSubpop(i, 500);
14-
for (i in 2:subpopCount)
15-
sim.subpopulations[i-1].setMigrationRates(i-1, 0.2);
16-
for (i in 1:(subpopCount-1))
17-
sim.subpopulations[i-1].setMigrationRates(i+1, 0.05);
14+
15+
subpops = sim.subpopulations;
16+
for (i in 1:(COUNT-1)) subpops[i].setMigrationRates(i-1, 0.2);
17+
for (i in 0:(COUNT-2)) subpops[i].setMigrationRates(i+1, 0.05);
1818
}
1919
10000 late() { sim.outputFixedMutations(); }

VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ development head (in the master branch):
4141
fix a bug that would cause failures to write buffered compressed data from writeFile(), only in SLiMgui; these failures were not reported to the user well (only through SLiMgui's stderr)
4242
recipe 14.7 is a ground-up rewrite, to show the utility of using marker mutations to track true local ancestry, including live plotting in SLiMgui
4343
add estimatedLastTick() method to Community; useful for custom plotting where you want to know the span of the model up front, to set an axis range, for example
44+
adjusted recipe 5.3.1 to use zero-based subpopulation ids, simplifying the logic; the workshop uses this recipe and it was a common source of confusion
4445

4546

4647
version 4.1 (Eidos version 3.1):

0 commit comments

Comments
 (0)