Skip to content

Commit 9818788

Browse files
authored
Merge pull request #1 from gulki/patch-1
Patch 1
2 parents e4171a2 + e5cc445 commit 9818788

File tree

6 files changed

+296
-0
lines changed

6 files changed

+296
-0
lines changed

slim_simulation/run_slim.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash -l
2+
#SBATCH -p chimp
3+
#SBATCH -n 3
4+
#SBATCH -t 5-00:00:00
5+
#SBATCH -J slim
6+
#SBATCH -o slurm-%j-%N-%u.out
7+
#SBATCH -e slurm-%J-%N-%u.err
8+
9+
simfile=$1
10+
outfile=$2
11+
12+
#seed=$RANDOM
13+
/usr/local/sw/SLiM-3.7/build/slim -d seed=$RANDOM ${simfile} > ${outfile}

slim_simulation/ws_model1.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Simulations by SLiM - aDNAworkshop2022 - Happy simulations!
2+
3+
// Don't worry, be happy!
4+
5+
// Let's start:
6+
7+
//manual page 86 for more information about initialize
8+
9+
initialize()
10+
11+
{
12+
// set the overall mutation rate
13+
initializeMutationRate(1e-7);
14+
15+
// m1 mutation type: neutral
16+
initializeMutationType("m1", 0.5, "f", 0.0);
17+
18+
// g1 genomic element type: uses m1 for all mutations
19+
initializeGenomicElementType("g1", m1, 1.0);
20+
21+
// uniform chromosome of length 100 kb
22+
initializeGenomicElement(g1, 0, 99999);
23+
24+
// uniform recombination along the chromosome
25+
initializeRecombinationRate(1e-8);
26+
27+
}
28+
29+
// create a population of 500 individuals
30+
1
31+
{
32+
sim.addSubpop("p1", 500);
33+
}
34+
35+
// run to generation 10000
36+
10000
37+
{
38+
sim.simulationFinished();
39+
}

slim_simulation/ws_model2.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Simulations by SLiM - aDNAworkshop2022 - Happy simulations!
2+
3+
// Let's add output:
4+
5+
//manual page 93 for more information about output and also section 26.1.1 page 657
6+
7+
initialize()
8+
9+
{
10+
// set the overall mutation rate
11+
initializeMutationRate(1e-7);
12+
13+
// m1 mutation type: neutral
14+
initializeMutationType("m1", 0.5, "f", 0.0);
15+
16+
// g1 genomic element type: uses m1 for all mutations
17+
initializeGenomicElementType("g1", m1, 1.0);
18+
19+
// uniform chromosome of length 100 kb
20+
initializeGenomicElement(g1, 0, 99999);
21+
22+
// uniform recombination along the chromosome
23+
initializeRecombinationRate(1e-8);
24+
25+
}
26+
27+
// create a population of 500 individuals
28+
1 {sim.addSubpop("p1", 500);}
29+
30+
// output:
31+
late() { sim.outputFull(); }

slim_simulation/ws_model3.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Simulations by SLiM - aDNAworkshop2022 - Happy simulations!
2+
3+
// Let's run a nucleotide-based simulation and a population split scenario
4+
5+
6+
7+
initialize() {
8+
setSeed(seed);
9+
10+
//simulate 100 Kb segment
11+
defineConstant("L", 100000);
12+
13+
//set the mutation rate
14+
defineConstant("mu", 1e-8);
15+
16+
// nucleotide-based simulation
17+
initializeSLiMOptions(nucleotideBased=T);
18+
19+
//generate random order of ACGTs of length "L" defined above
20+
initializeAncestralNucleotides(randomNucleotides(L));
21+
22+
//Introduce nucleotide-based neutral mutations -> dominance coeff is 0.5, DFE was set to fixed fittness effect, selection coeff is zero -> neutral
23+
initializeMutationTypeNuc("m1", 0.5, "f", 0.0);
24+
m1.convertToSubstitution = F;
25+
26+
initializeGenomicElementType("g1", m1, 1.0, mmJukesCantor(mu));
27+
initializeGenomicElement(g1, 0, L-1);
28+
29+
//set the recombination rate
30+
initializeRecombinationRate(1e-8);
31+
}
32+
33+
34+
// create a population of 10000 individuals
35+
1 {sim.addSubpop("p1", 10000);}
36+
37+
38+
// Population split
39+
40+
1000 { sim.addSubpopSplit("p2", 2000, p1); }
41+
42+
43+
// output:
44+
45+
1000 late() {
46+
p2.outputVCFSample(5, replace=T, simplifyNucleotides=T);
47+
}

slim_simulation/ws_model4.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Simulations by SLiM - aDNAworkshop2022 - Happy simulations!
2+
3+
// Mutationtype - page 144
4+
5+
6+
7+
initialize() {
8+
setSeed(seed);
9+
10+
//simulate 100 Kb segment
11+
defineConstant("L", 100000);
12+
13+
//set the mutation rate
14+
defineConstant("mu", 1e-8);
15+
16+
// nucleotide-based simulation
17+
initializeSLiMOptions(nucleotideBased=T);
18+
19+
//generate random order of ACGTs of length "L" defined above
20+
initializeAncestralNucleotides(randomNucleotides(L));
21+
22+
//Introduce nucleotide-based neutral mutations -> dominance coeff is 0.5, DFE was set to fixed fittness effect, selection coeff is zero -> neutral
23+
initializeMutationTypeNuc("m1", 0.1, "g", -0.03, 0.2);
24+
m1.convertToSubstitution = F;
25+
26+
initializeGenomicElementType("g1", m1, 1.0, mmJukesCantor(mu));
27+
initializeGenomicElement(g1, 0, L-1);
28+
29+
//set the recombination rate
30+
initializeRecombinationRate(1e-8);
31+
}
32+
33+
34+
// create a population of 10000 individuals
35+
1 {sim.addSubpop("p1", 10000);}
36+
37+
38+
// Population split
39+
40+
1000 { sim.addSubpopSplit("p2", 2000, p1); }
41+
42+
43+
// output:
44+
45+
1000 late() {
46+
p2.outputVCFSample(5, replace=T, simplifyNucleotides=T);
47+
}

slim_simulation/ws_model5.txt

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// A more complex scenario
2+
3+
// Example paper 1: https://www.nature.com/articles/s41467-018-04191-y 10mb segment
4+
// Example paper 2: https://genome.cshlp.org/content/24/6/885.long 4 mb segment
5+
// Multi-population model of ancient Eurasia -> https://stdpopsim.readthedocs.io/en/latest/catalog.html#sec_catalog_HomSap
6+
// https://www.tandfonline.com/doi/full/10.1080/01621459.2019.1635482
7+
8+
9+
10+
// I use mutation rate as 1e-8
11+
12+
// Model-2: Neutral simulation - add mutation to the middle of the sequence
13+
14+
initialize() {
15+
setSeed(seed);
16+
17+
//simulate 100 kb segment
18+
defineConstant("L", 100000);
19+
20+
//set the mutation rate
21+
defineConstant("mu", 1e-8);
22+
23+
// nucleotide-based simulation
24+
initializeSLiMOptions(nucleotideBased=T);
25+
26+
//generate random order of ACGTs of length "L" defined above
27+
initializeAncestralNucleotides(randomNucleotides(L));
28+
29+
//Introduce nucleotide-based neutral mutations -> dominance coeff is 0.5, DFE was set to fixed fittness effect, selection coeff is zero -> neutral
30+
initializeMutationTypeNuc("m1", 0.5, "f", 0.0);
31+
m1.convertToSubstitution = F;
32+
33+
//Non-nucloide based (target) neutral mutation to be introduced at certain time point.
34+
initializeMutationType("m2", 0.5, "f", 0.0);
35+
m2.convertToSubstitution = F;
36+
37+
//simulate genomic segment of length of L
38+
39+
initializeGenomicElementType("g1", m1, 1.0, mmJukesCantor(mu));
40+
initializeGenomicElement(g1, 0, L-1);
41+
42+
43+
//set the recombination rate
44+
45+
initializeRecombinationRate(1e-8);
46+
}
47+
48+
// initial population size 29,100 individuals ancestral population (assume Mbuty and WHG) -> simulate for 58,000 generation -> 1,450,000 years
49+
50+
1 {
51+
defineConstant("simID", getSeed());
52+
sim.addSubpop("p1", 29100);}
53+
54+
// Time of WHG and Mbuti split at 95,800 years ago (3,832 generations) "p2 is Mbuty". Mbuty pop. size is 17,300
55+
56+
54164 { sim.addSubpopSplit("p2", 17300, p1); }
57+
58+
// Time of WHG and Basal Eurasian split at 79,800 years ago (3,192 generations), "p3 is Basal Eurasian". Basal Eurasian pop. size is 1,920
59+
60+
54808 { sim.addSubpopSplit("p3", 1920, p1); }
61+
62+
// Time of WHG and Ust’Ishim split at 51,500 years ago (2,060 generations), "p4 is Ust Ishim". Ust Ishim pop size is 1,920
63+
64+
55940 { sim.addSubpopSplit("p4", 1920, p1); }
65+
66+
// Time of WHG and Han Chinese split at 50,400 years ago (2,016 generations), "p5 is Han Chinese". Han. Chinese pop size is 6,300
67+
68+
55984 { sim.addSubpopSplit("p5", 6300, p1); }
69+
70+
// Time of WHG and Mal’ta split at 44,900 years ago (1,796 generation), "p6 is Mal'ta". Mal'ta pop size is 1,920
71+
72+
56204 { sim.addSubpopSplit("p6", 1920, p1); }
73+
74+
// Time of WHG and AnatoliaNeolithic split at 15,000 years ago (600 generations), "p7 is Anatolia Neolithic". Anatolia Neolithic pop size is 2000
75+
76+
57400 { sim.addSubpopSplit("p7", 2000, p1); }
77+
78+
79+
// Add the target neutral mutation (m2) at generation 57500 to 100 individuals
80+
// Change 57500 to any time you wish
81+
57500 late() {
82+
// Save the current state of simulation into a tmp file.
83+
sim.outputFull("/tmp/slim_" + simID + ".txt");
84+
85+
// Select 100 random haploid indvidual from p7
86+
targetinds = sample(p7.genomes, 100);
87+
88+
// Introduce m2 mutation into the center of the sequence of these 100 individuals
89+
targetinds.addNewDrawnMutation(m2, asInteger(L/2));
90+
}
91+
92+
93+
// Check if the target mutation (m2) is lost
94+
// Change 5750 to any time you wish
95+
57500:58000 late() {
96+
if (sim.countOfMutationsOfType(m2) == 0) {
97+
print(simID + ": LOST-RESTARTING ");
98+
99+
// if the mutation is lost, restart simulation from the tmp file
100+
sim.readFromPopulationFile("/tmp/slim_" + simID + ".txt");
101+
setSeed(getSeed() + 1);
102+
target = sample(p7.genomes, 100);
103+
target.addNewDrawnMutation(m2, asInteger(L/2));
104+
} }
105+
106+
107+
108+
57600 late() {
109+
p7.outputVCFSample(1000, replace=T, simplifyNucleotides=T);
110+
}
111+
112+
57800 late() {
113+
p7.outputVCFSample(1000, replace=T, simplifyNucleotides=T);
114+
}
115+
116+
58000 late() {
117+
p7.outputVCFSample(1000, replace=T, simplifyNucleotides=T);
118+
deleteFile("/tmp/slim_" + simID + ".txt");
119+
}

0 commit comments

Comments
 (0)