forked from bioinform/somaticseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
291 lines (271 loc) · 7.26 KB
/
Snakefile
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# -*- python -*-
# vim: set ft=python
import glob
import os
shell.prefix("set -eo pipefail; ")
configfile: "config.yaml"
rule sniper:
input:
tumor=config["tumor"],
normal=config["normal"]
output:
"SomaticSniper.vcf"
threads: 1
resources:
mem_mb=6000
shell:
"""
bam-somaticsniper \
-f {config[reference]} \
-F vcf \
-q 25 `# minimum mapping quality` \
-Q 15 `# minimum somatic SNV quality` \
-s 0.0001 `# prior probability of a somatic mutation` \
{input.tumor} \
{input.normal} \
{output}
"""
rule lofreq:
input:
tumor=config["tumor"],
normal=config["normal"]
output:
snps="lofreq/somatic_final.snvs.vcf.gz",
indels="lofreq/somatic_final.indels.vcf.gz"
threads: config["caller_threads"]
resources:
mem_mb=12000
shell:
"""
lofreq somatic \
--call-indels \
--threads {threads} \
--tumor {input.tumor} \
--normal {input.normal} \
--ref {config[reference]} \
--dbsnp {config[dbsnp]} \
--outprefix lofreq/
"""
rule muse:
input:
tumor=config["tumor"],
normal=config["normal"]
output:
"MuSE.vcf"
threads: 1
resources:
mem_mb=4000
shell:
"""
MuSE call \
-O MuSE \
-f {config[reference]} \
{input.tumor} \
{input.normal}
MuSE sump \
-G \
-I MuSE.MuSE.txt \
-O {output} \
-D {config[dbsnp]}
"""
rule mutect2:
input:
tumor=config["tumor"],
normal=config["normal"]
output:
"MuTect2.vcf"
threads: 1
resources:
mem_mb=7000
shell:
"""
# for now, copied straight from the original SomaticSeq pipeline code
tumor_name=$(samtools view -H {input.tumor} | egrep -w '^@RG' | grep -Po 'SM:[^\t$]+' | sed 's/SM://' | uniq | sed -e 's/[[:space:]]*$//')
normal_name=$(samtools view -H {input.normal} | egrep -w '^@RG' | grep -Po 'SM:[^\t$]+' | sed 's/SM://' | uniq | sed -e 's/[[:space:]]*$//')
java -Xmx{resources.mem_mb}m -jar {config[gatk]} \
Mutect2 \
--reference {config[reference]} \
--input {input.normal} \
--input {input.tumor} \
--normal-sample "$normal_name" \
--tumor-sample "$tumor_name" \
--dbsnp {config[dbsnp]} \
--output unfiltered-{output}
java -Xmx{resources.mem_mb}m -jar {config[gatk]} \
FilterMutectCalls \
--variant unfiltered-{output} \
--output {output}
"""
rule scalpel:
input:
tumor=config["tumor"],
normal=config["normal"],
refdict=config["reference"].replace('.fasta','.dict')
output:
"Scalpel.vcf"
threads: 1
resources:
mem_mb=32000
shell:
"""
scalpel-discovery --somatic \
--ref {config[reference]} \
--normal {input.normal} \
--tumor {input.tumor} \
--window 600 \
--dir scalpel \
&& scalpel-export --somatic \
--db scalpel/main/somatic.db.dir \
--ref {config[reference]} \
| vcfsorter.pl {input.refdict} - \
> {output}
"""
rule strelka:
input:
tumor=config["tumor"],
normal=config["normal"]
output:
snps="strelka/results/variants/somatic.snvs.vcf.gz",
indels="strelka/results/variants/somatic.indels.vcf.gz"
threads: config["caller_threads"]
resources:
mem_mb=6000
shell:
"""
configureStrelkaSomaticWorkflow.py \
--tumorBam={input.tumor} \
--normalBam={input.normal} \
--referenceFasta={config[reference]} \
--callMemMb={resources.mem_mb} \
--runDir=strelka
strelka/runWorkflow.py -m local -j {threads}
"""
rule genome_interval:
input:
config["reference"]+".fai"
output:
"genome.bed"
threads: 1
resources:
mem_mb=1000
shell:
"""
awk -F "\t" '{{print $1 "\t0\t" $2}}' {input} > {output}
"""
rule vardict:
input:
tumor=config["tumor"],
normal=config["normal"],
interval=rules.genome_interval.output
output:
"VarDict.vcf"
threads: 1
resources:
mem_mb=8000
shell:
"""
VarDict \
-h \
-G {config[reference]} \
-f 0.05 \
-b '{input.tumor}|{input.normal}' \
-Q 1 \
-c 1 \
-S 2 \
-E 3 \
-g 4 \
| awk 'NR!=1' \
| testsomatic.R \
| var2vcf_paired.pl -N 'TUMOR|NORMAL' -f 0.05 \
{input.interval} \
> {output}
"""
rule varscan:
input:
tumor=config["tumor"].replace(".bam",".mpileup"),
normal=config["normal"].replace(".bam",".mpileup")
output:
snps="VarScan2.snp.vcf",
indels="VarScan2.indel.vcf"
threads: 1
resources:
mem_mb=9000
shell:
"""
java -Xmx{resources.mem_mb}m -jar {config[varscan]} somatic \
{input.normal} {input.tumor} VarScan2 \
--output-vcf 1 \
--min-var-freq 0.10
java -Xmx{resources.mem_mb}m -jar {config[varscan]} processSomatic \
{output.snps}
java -Xmx{resources.mem_mb}m -jar {config[varscan]} somaticFilter \
VarScan2.snp.Somatic.hc.vcf \
-indel-file {output.indels} \
-output-file VarScan2.snp.Somatic.hc.filter.vcf
"""
rule mpileup:
input:
"{name}.bam"
output:
temp("{name}.mpileup")
threads: 1
resources:
mem_mb=2000
shell:
"""
samtools mpileup -B -q 25 -Q 20 -f {config[reference]} {input} \
> {output}
"""
varcallers_single_output = [
"muse",
"mutect2",
"scalpel",
"sniper",
"vardict",
]
# variant callers that have separate output files for SNVs and Indels
varcallers_multi_output = [
"lofreq",
"strelka",
"varscan",
]
varcallers = varcallers_single_output + varcallers_multi_output
somaticseq_inputs = [eval('.'.join(['rules',varcaller,'output']))
for varcaller in varcallers if config[varcaller]]
somaticseq_inputflags = ""
for varcaller in varcallers_single_output:
if config[varcaller]:
somaticseq_inputflags += (
" --" + varcaller + " "
+ eval('.'.join(['rules',varcaller,'output']))[0]
)
for varcaller in varcallers_multi_output:
if config[varcaller]:
somaticseq_inputflags += (
" --" + varcaller + "-snv "
+ eval('.'.join(['rules',varcaller,'output','snps'])) +
" --" + varcaller + "-indel "
+ eval('.'.join(['rules',varcaller,'output','indels']))
)
rule somaticseq:
input:
tumor=config["tumor"],
normal=config["normal"],
inputs=somaticseq_inputs
output:
"SomaticSeq/"
threads: 1
resources:
mem_mb=6000
params:
inputflags=somaticseq_inputflags
shell:
"""
SomaticSeq.Wrapper.sh \
--output-dir SomaticSeq \
--genome-reference {config[reference]} \
--dbsnp {config[dbsnp]} \
--tumor-bam {input.tumor} \
--normal-bam {input.normal} \
{params.inputflags}
"""