-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulations.smk
201 lines (186 loc) · 6.09 KB
/
simulations.smk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
rule sim_msprime_simple_scenarios:
input:
demes_file = 'results/simulations/scenario_{sc}.yaml',
output:
trees_file = 'results/simulations/sim_msprime_rep/sim_msprime_scenario_{sc}_{rep}.trees',
params:
recombination_rate = 2e-8,
census_time = 200,
n_sample = 100,
sampling_times = [200, 160, 140, 120, 100, 80, 60, 40, 20, 0],
resources:
mem_mb = 3_000,
conda:
"../envs/popgensim.yaml"
script:
'../scripts/sim_msprime_simple_scenarios.py'
rule sim_slim_sel_simple_scenarios:
input:
demes_file = 'results/simulations/scenario_{sc}.json',
output:
trees_file = temp('results/simulations/sim_slim_sel_rep/raw_sim_slim_sel_scenario_{sc}_{type}_t{time}_s{ssize}_{rep}.trees'),
pheno_file = 'results/simulations/sim_slim_sel_rep/sim_slim_sel_scenario_{sc}_{type}_t{time}_s{ssize}_{rep}_pheno.tsv',
params:
census_time = 200,
n_sample = 100,
sampling_times = 'c(200, 160, 140, 120, 100, 80, 60, 40, 20, 0)',
shift_delay = lambda w: 200 - int(w.time), # delay of shift from admix_start
resources:
mem_mb = 9_000,
log:
"logs/sim_slim_sel_simple_scenarios_{sc}_{type}_t{time}_s{ssize}_{rep}.log"
conda:
"../envs/popgensim.yaml"
shell:
'''
slim \
-d 'JSON_FILE="{input.demes_file}"' \
-d 'TREES_FILE="{output.trees_file}"' \
-d 'PHENO_FILE="{output.pheno_file}"' \
-d 'backward_sampling={params.sampling_times}' \
-d 'N_sample={params.n_sample}' \
-d 'census_time={params.census_time}' \
-d 'shift_type="{wildcards.type}"' \
-d 'shift_size={wildcards.ssize}' \
-d 'shift_delay={params.shift_delay}' \
workflow/scripts/sim_slim_sel_simple_scenarios.slim \
> {log}
'''
rule sim_slim_sel_postprocessing:
input:
trees_file = 'results/simulations/sim_slim_sel_rep/raw_sim_slim_sel_scenario_{sc}_{type}_t{time}_s{ssize}_{rep}.trees',
demes_file = 'results/simulations/scenario_{sc}.json',
output:
trees_file = 'results/simulations/sim_slim_sel_rep/sim_slim_sel_scenario_{sc}_{type}_t{time}_s{ssize}_{rep}.trees',
params:
neutral_mut_rate = 1e-08,
resources:
mem_mb = 3_000,
conda:
"../envs/popgensim.yaml"
script:
'../scripts/sim_slim_postprocessing.py'
rule sim_msprime_europe_uk:
input:
demes_file = 'resources/AncientEurope_4A21_mod.yaml',
output:
trees_file = 'results/simulations/sim_msprime_europe_uk/sim_msprime_europe_uk_{rep}.trees',
params:
n_sample = 300,
resources:
mem_mb = 9_000,
conda:
"../envs/popgensim.yaml"
script:
'../scripts/sim_msprime_europe_uk.py'
#========================
# High sampling frequency
rule sim_msprime_high_sampling_freq:
input:
demes_file = 'results/simulations/scenario_{sc}.yaml',
output:
trees_file = 'results/simulations/sim_msprime_rep/sim_msprime_high_freq_{sc}_r{rec}_{rep}.trees',
params:
recombination_rate = lambda w: float(w.rec),
census_time = 200,
n_sample = 100,
sampling_times = lambda w: [x for x in list(range(0, 201, 1))[::-1]],
resources:
mem_mb = 9_000,
conda:
"../envs/popgensim.yaml"
script:
'../scripts/sim_msprime_simple_scenarios.py'
rule sim_slim_sel_high_sampling_freq:
input:
demes_file = 'results/simulations/scenario_{sc}.json',
output:
trees_file = temp('results/simulations/sim_slim_sel_rep/raw_sim_slim_sel_high_freq_{sc}_{type}_t{time}_s{ssize}_r{rec}_{rep}.trees'),
pheno_file = 'results/simulations/sim_slim_sel_rep/sim_slim_sel_high_freq_{sc}_{type}_t{time}_s{ssize}_r{rec}_{rep}_pheno.tsv',
params:
census_time = 200,
n_sample = 50,
sampling_times = lambda w: f"c({','.join([str(x) for x in list(range(0, 201, 1))[::-1]])})",
shift_delay = lambda w: 200 - int(w.time), # delay of shift from admix_start
resources:
mem_mb = 9_000,
log:
"logs/sim_slim_sel_high_freq_{sc}_{type}_t{time}_s{ssize}_r{rec}_{rep}.log"
conda:
"../envs/popgensim.yaml"
shell:
'''
slim \
-d 'JSON_FILE="{input.demes_file}"' \
-d 'TREES_FILE="{output.trees_file}"' \
-d 'PHENO_FILE="{output.pheno_file}"' \
-d 'rec={wildcards.rec}' \
-d 'backward_sampling={params.sampling_times}' \
-d 'N_sample={params.n_sample}' \
-d 'census_time={params.census_time}' \
-d 'shift_type="{wildcards.type}"' \
-d 'shift_size={wildcards.ssize}' \
-d 'shift_delay={params.shift_delay}' \
workflow/scripts/sim_slim_sel_simple_scenarios.slim \
> {log}
'''
rule sim_slim_sel_high_sampling_freq_postprocessing:
input:
trees_file = 'results/simulations/sim_slim_sel_rep/raw_sim_slim_sel_high_freq_{sc}_{type}_t{time}_s{ssize}_r{rec}_{rep}.trees',
demes_file = 'results/simulations/scenario_{sc}.json',
output:
trees_file = 'results/simulations/sim_slim_sel_rep/sim_slim_sel_high_freq_{sc}_{type}_t{time}_s{ssize}_r{rec}_{rep}.trees',
params:
neutral_mut_rate = 1e-08,
resources:
mem_mb = 6_000,
conda:
"../envs/popgensim.yaml"
script:
'../scripts/sim_slim_postprocessing.py'
#========================
# Background selection
rule sim_slim_bgs_high_sampling_freq:
input:
demes_file = 'results/simulations/scenario_{sc}.json',
output:
trees_file = temp('results/simulations/sim_slim_bgs_rep/raw_sim_slim_bgs_scenario_{sc}_r{rec}_{rep}.trees'),
params:
census_time = 200,
n_sample = 50,
sampling_times = lambda w: f"c({','.join([str(x) for x in list(range(0, 201, 1))[::-1]])})",
U = 1,
s = 0.1, # made negative in slim script
resources:
mem_mb = 9_000,
log:
"logs/sim_slim_bgs_simple_scenarios_{sc}_r{rec}_{rep}.log"
conda:
"../envs/popgensim.yaml"
shell:
'''
slim \
-d 'JSON_FILE="{input.demes_file}"' \
-d 'TREES_FILE="{output.trees_file}"' \
-d 'backward_sampling={params.sampling_times}' \
-d 'N_sample={params.n_sample}' \
-d 'census_time={params.census_time}' \
-d 'U={params.U}' \
-d 's={params.s}' \
workflow/scripts/sim_slim_bgs_simple_scenarios.slim \
> {log}
'''
rule sim_slim_bgs_postprocessing:
input:
trees_file = 'results/simulations/sim_slim_bgs_rep/raw_sim_slim_bgs_scenario_{sc}_r{rec}_{rep}.trees',
demes_file = 'results/simulations/scenario_{sc}.json',
output:
trees_file = 'results/simulations/sim_slim_bgs_rep/sim_slim_bgs_scenario_{sc}_r{rec}_{rep}.trees',
params:
neutral_mut_rate = 1e-08,
resources:
mem_mb = 6_000,
conda:
"../envs/popgensim.yaml"
script:
'../scripts/sim_slim_postprocessing.py'