[0a8e41]: / ensemble_docker_pipelines / prepare_callers_scripts.sh

Download this file

456 lines (361 with data), 12.5 kB

  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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/bin/bash
# Use getopt instead of getopts for long options
set -e
OPTS=`getopt -o o: --long output-dir:,tumor-bam:,normal-bam:,tumor-name:,normal-name:,human-reference:,selector:,exclude:,dbsnp:,cosmic:,min-vaf:,splits:,mutect2,varscan2,somaticsniper,vardict,muse,strelka,wrapper,exome,singularity,mutect2-arguments:,mutect2-filter-arguments:,varscan-arguments:,varscan-pileup-arguments:,somaticsniper-arguments:,vardict-arguments:,muse-arguments:,strelka-config-arguments:,strelka-run-arguments:,wrapper-arguments:, -n 'prepare_callers_scripts.sh' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"
eval set -- "$OPTS"
MYDIR="$( cd "$( dirname "$0" )" && pwd )"
tumor_name='TUMOR'
normal_name='NORMAL'
wrapper_dir='Wrapper'
min_vaf=0.05
splits=12
muse_extra_arguments=''
action='echo'
singularity=''
while true; do
case "$1" in
-o | --output-dir )
case "$2" in
"") shift 2 ;;
*) outdir=$2 ; shift 2 ;;
esac ;;
--tumor-bam )
case "$2" in
"") shift 2 ;;
*) tumor_bam=$2 ; shift 2 ;;
esac ;;
--normal-bam )
case "$2" in
"") shift 2 ;;
*) normal_bam=$2 ; shift 2 ;;
esac ;;
--tumor-name )
case "$2" in
"") shift 2 ;;
*) tumor_name=$2 ; shift 2 ;;
esac ;;
--normal-name )
case "$2" in
"") shift 2 ;;
*) normal_name=$2 ; shift 2 ;;
esac ;;
--human-reference )
case "$2" in
"") shift 2 ;;
*) HUMAN_REFERENCE=$2 ; shift 2 ;;
esac ;;
--selector )
case "$2" in
"") shift 2 ;;
*) SELECTOR=$2 ; shift 2 ;;
esac ;;
--exclude )
case "$2" in
"") shift 2 ;;
*) EXCLUSION=$2 ; shift 2 ;;
esac ;;
--dbsnp )
case "$2" in
"") shift 2 ;;
*) dbsnp=$2 ; shift 2 ;;
esac ;;
--cosmic )
case "$2" in
"") shift 2 ;;
*) cosmic=$2 ; shift 2 ;;
esac ;;
--min-vaf )
case "$2" in
"") shift 2 ;;
*) min_vaf=$2 ; shift 2 ;;
esac ;;
--splits )
case "$2" in
"") shift 2 ;;
*) splits=$2 ; shift 2 ;;
esac ;;
--mutect2 )
mutect2=1 ; shift ;;
--varscan2 )
varscan2=1 ; shift ;;
--somaticsniper )
somaticsniper=1 ; shift ;;
--vardict )
vardict=1 ; shift ;;
--muse )
muse=1 ; shift ;;
--strelka )
strelka=1 ; shift ;;
--wrapper )
wrapper=1 ; shift ;;
--mutect2-arguments )
case "$2" in
"") shift 2 ;;
*) mutect2_arguments=$2 ; shift 2 ;;
esac ;;
--mutect2-filter-arguments )
case "$2" in
"") shift 2 ;;
*) mutect2_filter_arguments=$2 ; shift 2 ;;
esac ;;
--varscan-arguments )
case "$2" in
"") shift 2 ;;
*) varscan_arguments=$2 ; shift 2 ;;
esac ;;
--varscan-pileup-arguments )
case "$2" in
"") shift 2 ;;
*) varscan_pileup_arguments=$2 ; shift 2 ;;
esac ;;
--somaticsniper-arguments )
case "$2" in
"") shift 2 ;;
*) somaticsniper_arguments=$2 ; shift 2 ;;
esac ;;
--vardict-arguments )
case "$2" in
"") shift 2 ;;
*) vardict_arguments=$2 ; shift 2 ;;
esac ;;
--muse-arguments )
case "$2" in
"") shift 2 ;;
*) muse_extra_arguments=$2 ; shift 2 ;;
esac ;;
--strelka-config-arguments )
case "$2" in
"") shift 2 ;;
*) strelka_config_arguments=$2 ; shift 2 ;;
esac ;;
--strelka-run-arguments )
case "$2" in
"") shift 2 ;;
*) strelka_run_arguments=$2 ; shift 2 ;;
esac ;;
--wrapper-arguments )
case "$2" in
"") shift 2 ;;
*) wrapper_arguments=$2 ; shift 2 ;;
esac ;;
--exome )
exome_stat=1 ; shift ;;
--singularity )
singularity='--singularity' ; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
logdir=${outdir}/logs
mkdir -p ${logdir}
if [[ ${dbsnp} ]];then
dbsnp_input="--dbsnp ${dbsnp}";
fi
if [[ $SELECTOR ]]
then
if [[ $singularity ]]; then
singularity exec --bind /:/mnt docker://lethalfang/somaticseq:3.3.0 bash -c \
"bedtools sort -i /mnt/$SELECTOR -faidx /mnt/${HUMAN_REFERENCE}.fai > /mnt/${outdir}/genome.bed"
else
docker run --rm -v /:/mnt -u $UID --memory 10G lethalfang/somaticseq:3.3.0 bash -c \
"bedtools sort -i /mnt/$SELECTOR -faidx /mnt/${HUMAN_REFERENCE}.fai > /mnt/${outdir}/genome.bed"
fi
else
cat ${HUMAN_REFERENCE}.fai | awk -F "\t" '{print $1 "\t0\t" $2}' | awk -F "\t" '$1 ~ /^(chr)?[0-9XYMT]+$/' > ${outdir}/genome.bed
fi
if [[ $singularity ]]; then
singularity exec --bind /:/mnt docker://lethalfang/somaticseq:3.3.0 \
/opt/somaticseq/utilities/split_Bed_into_equal_regions.py \
-infile /mnt/${outdir}/genome.bed -num $splits -outfiles /mnt/${outdir}/bed
else
docker run --rm -v /:/mnt -u $UID lethalfang/somaticseq:3.3.0 \
/opt/somaticseq/utilities/split_Bed_into_equal_regions.py \
-infile /mnt/${outdir}/genome.bed -num $splits -outfiles /mnt/${outdir}/bed
fi
ith_split=1
while [[ $ith_split -le $splits ]]
do
mkdir -p ${outdir}/${ith_split}
mv ${outdir}/${ith_split}.bed ${outdir}/${ith_split}
if [[ $somaticsniper -eq 1 ]]
then
sniper_input="--sniper ${outdir}/${ith_split}/SomaticSniper.vcf"
fi
if [[ $mutect2 -eq 1 ]]
then
input_mutect2_arguments=''
input_mutect2_filter_arguments=''
if [[ ${mutect2_arguments} ]]
then
input_mutect2_arguments="${mutect2_arguments}"
fi
if [[ ${mutect2_filter_arguments} ]]
then
input_mutect2_filter_arguments="${mutect2_filter_arguments}"
fi
$MYDIR/mutation_callers/submit_MuTect2.sh \
--normal-bam ${normal_bam} \
--tumor-bam ${tumor_bam} \
--out-dir ${outdir}/${ith_split} \
--out-vcf MuTect2.vcf \
--selector ${outdir}/${ith_split}/${ith_split}.bed \
--human-reference ${HUMAN_REFERENCE} \
--extra-arguments "${input_mutect2_arguments}" \
--extra-filter-arguments "${input_mutect2_filter_arguments}" \
$singularity \
--action $action
mutect2_input="--mutect2 ${outdir}/${ith_split}/MuTect2.vcf"
fi
if [[ $varscan2 -eq 1 ]]
then
input_varscan_pileup_arguments=''
input_varscan_arguments=''
if [[ ${varscan_pileup_arguments} ]]
then
input_varscan_pileup_arguments="${varscan_pileup_arguments}"
fi
if [[ ${varscan_arguments} ]]
then
input_varscan_arguments="${varscan_arguments}"
fi
$MYDIR/mutation_callers/submit_VarScan2.sh \
--normal-bam ${normal_bam} \
--tumor-bam ${tumor_bam} \
--out-dir ${outdir}/${ith_split} \
--out-vcf VarScan2.vcf \
--selector ${outdir}/${ith_split}/${ith_split}.bed \
--human-reference ${HUMAN_REFERENCE} \
--extra-pileup-arguments "${input_varscan_pileup_arguments}" \
--extra-arguments "${input_varscan_arguments}" \
$singularity \
--action $action
varscan_snv_input="--varscan-snv ${outdir}/${ith_split}/VarScan2.snp.vcf"
varscan_indel_input="--varscan-indel ${outdir}/${ith_split}/VarScan2.indel.vcf"
fi
if [[ $vardict -eq 1 ]]
then
input_vardict_arguments=''
if [[ ${vardict_arguments} ]]
then
input_vardict_arguments="${vardict_arguments}"
fi
$MYDIR/mutation_callers/submit_VarDictJava.sh \
--normal-bam ${normal_bam} \
--tumor-bam ${tumor_bam} \
--out-dir ${outdir}/${ith_split} \
--selector ${outdir}/${ith_split}/${ith_split}.bed \
--out-vcf VarDict.vcf \
--human-reference ${HUMAN_REFERENCE} \
--VAF ${min_vaf} \
--extra-arguments "${input_vardict_arguments}" \
$singularity \
--action $action
vardict_input="--vardict ${outdir}/${ith_split}/VarDict.vcf"
fi
if [[ $muse -eq 1 ]]
then
if [[ ! ${muse_extra_arguments} ]]
then
if [[ $exome_stat ]]
then
muse_extra_arguments='-E'
else
muse_extra_arguments='-G'
fi
fi
$MYDIR/mutation_callers/submit_MuSE.sh \
--normal-bam ${normal_bam} \
--tumor-bam ${tumor_bam} \
--out-dir ${outdir}/${ith_split} \
--selector ${outdir}/${ith_split}/${ith_split}.bed \
--out-vcf MuSE.vcf \
--human-reference ${HUMAN_REFERENCE} \
${dbsnp_input} \
--extra-arguments "${muse_extra_arguments}" \
$singularity \
--action $action
muse_input="--muse ${outdir}/${ith_split}/MuSE.vcf"
fi
if [[ $strelka -eq 1 ]]
then
if [[ $exome_stat ]]
then
strelka_exome_stat='--exome'
fi
if [[ ${strelka_config_arguments} ]]
then
input_strelka_config_arguments=" --extra-config-arguments ${strelka_config_arguments}"
fi
if [[ ${strelka_run_arguments} ]]
then
input_strelka_run_arguments="--extra-run-arguments ${strelka_run_arguments}"
fi
$MYDIR/mutation_callers/submit_Strelka.sh \
--normal-bam ${normal_bam} \
--tumor-bam ${tumor_bam} \
--out-dir ${outdir}/${ith_split} \
--selector ${outdir}/${ith_split}/${ith_split}.bed \
--out-vcf Strelka.vcf \
--human-reference ${HUMAN_REFERENCE} \
${strelka_exome_stat} \
${input_strelka_config_arguments} \
${input_strelka_run_arguments} \
$singularity \
--action $action
strelka_snv_input="--strelka-snv ${outdir}/${ith_split}/Strelka/results/variants/somatic.snvs.vcf.gz"
strelka_indel_input="--strelka-indel ${outdir}/${ith_split}/Strelka/results/variants/somatic.indels.vcf.gz"
fi
# Wrapper
if [[ $wrapper -eq 1 ]]
then
input_wrapper_arguments=''
if [[ $EXCLUSION ]]; then exclusion_text="--exclude ${EXCLUSION}" ; fi
if [[ ${cosmic} ]]; then cosmic_input="--cosmic ${cosmic}" ; fi
if [[ ${wrapper_arguments} ]]
then
input_wrapper_arguments="${wrapper_arguments}"
fi
$MYDIR/mutation_callers/submit_Wrapper.sh \
--normal-bam ${normal_bam} \
--tumor-bam ${tumor_bam} \
--out-dir ${outdir}/${ith_split}/${wrapper_dir} \
--human-reference ${HUMAN_REFERENCE} \
$dbsnp_input \
$cosmic_input \
--selector ${outdir}/${ith_split}/${ith_split}.bed \
$exclusion_text \
$mutect2_input \
$varscan_snv_input \
$varscan_indel_input \
$sniper_input \
$vardict_input \
$muse_input \
$strelka_snv_input \
$strelka_indel_input \
--extra-arguments "${input_wrapper_arguments}" \
$singularity \
--action ${action}
fi
ith_split=$(( $ith_split + 1))
done
# SomaticSniper is very fast, so no need to parallelize
if [[ $somaticsniper -eq 1 ]]
then
input_somaticsniper_arguments=''
if [[ ${somaticsniper_arguments} ]]
then
input_somaticsniper_arguments="${somaticsniper_arguments}"
fi
$MYDIR/mutation_callers/submit_SomaticSniper.sh \
--normal-bam ${normal_bam} \
--tumor-bam ${tumor_bam} \
--out-dir ${outdir} \
--out-vcf SomaticSniper.vcf \
--human-reference ${HUMAN_REFERENCE} \
--split $splits \
--extra-arguments "${input_somaticsniper_arguments}" \
$singularity \
--action $action
fi