forked from AG-Boerries/MIRACUM-Pipe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
miracum_pipe.sh
executable file
·502 lines (411 loc) · 17 KB
/
miracum_pipe.sh
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#!/usr/bin/env bash
readonly DIR_SCRIPT=$(
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
pwd -P
)
## load settings
# shellcheck source=common.cfg.sh
. "${DIR_SCRIPT}"/common.cfg.sh
readonly VALID_TASKS=("gd td vc cnv report td_gd_parallel vc_cnv_parallel rna_fusions")
readonly VALID_PROTOCOLS=("wes panel tumorOnly")
function usage() {
echo "usage: miracum_pipe.sh [-d dir] [-t task] [-p protocol] [-f] [-h]"
echo " -t task specify task ${VALID_TASKS}"
echo " -p protocol specify protocol ${VALID_PROTOCOLS}"
echo " -f specify forced run, i.e. neglecting if a patient already was computed"
echo " -d dir specify directory in which the patient is located"
echo " -s computing sequentially; might be required if ressources are limited"
echo " -h show this help screen"
exit 1
}
# setup relative_patient_dir dir_target
function setup() {
local dir_patient="${1}"
local dir_target="${2}"
local dir_tmp="$(get_config_value common.dirTmp "${dir_patient}")/${dir_patient}"
mkdir -p ${dir_tmp}
local dir_log="${dir_target}/log"
mkdir -p "${dir_log}"
}
# cleanup relative_patient_dir
function cleanup() {
local dir_patient="${1}"
local dir_tmp="$(get_config_value common.dirTmp "${dir_patient}")/${dir_patient}"
rm -rf "${dir_tmp:?}"
}
# WES protocol
# run_pipe relative_patient_dir dir_target
function run_pipe() {
local dir_patient="${1}"
local dir_target="${2}"
local dir_log="${dir_target}/log"
setup "${dir_patient}" "${dir_target}"
# use parallel shell scripting
("${DIR_SCRIPT}"/make_alignment.sh -p -t td -d "${dir_patient}" &> "${dir_log}/td.log") &
("${DIR_SCRIPT}"/make_alignment.sh -p -t gd -d "${dir_patient}" &> "${dir_log}/gd.log") &
wait
# use parallel shell scripting
("${DIR_SCRIPT}"/make_vc.sh -p -d "${dir_patient}" &> "${dir_log}/vc.log") &
("${DIR_SCRIPT}"/make_cnv.sh -p -d "${dir_patient}" &> "${dir_log}/cnv.log") &
wait
# create report based on the results of the processes above
("${DIR_SCRIPT}"/make_report.sh -d "${dir_patient}" &> "${dir_log}/report.log")
cleanup "${dir_patient}"
}
# run_pipe_seq relative_patient_dir dir_target
function run_pipe_seq() {
local dir_patient="${1}"
local dir_target="${2}"
local dir_log="${dir_target}/log"
setup "${dir_patient}" "${dir_target}"
("${DIR_SCRIPT}"/make_alignment.sh -t td -d "${dir_patient}" &> "${dir_log}/td.log")
("${DIR_SCRIPT}"/make_alignment.sh -t gd -d "${dir_patient}" &> "${dir_log}/gd.log")
("${DIR_SCRIPT}"/make_vc.sh -d "${dir_patient}" &> "${dir_log}/vc.log")
("${DIR_SCRIPT}"/make_cnv.sh -d "${dir_patient}" &> "${dir_log}/cnv.log")
("${DIR_SCRIPT}"/make_report.sh -d "${dir_patient}" &> "${dir_log}/report.log")
cleanup "${dir_patient}"
}
# Panel protocol
# run_pipe_panel relative_patient_dir dir_target
function run_panel_pipe() {
local dir_patient="${1}"
local dir_target="${2}"
local dir_log="${dir_target}/log"
setup "${dir_patient}" "${dir_target}"
# use parallel shell scripting
("${DIR_SCRIPT}"/make_panel_alignment.sh -t td -d "${dir_patient}" &> "${dir_log}/td.log") &
("${DIR_SCRIPT}"/make_rna_fusions.sh -d "${dir_patient}" &> "${dir_log}/fusions.log") &
wait
# use parallel shell scripting
("${DIR_SCRIPT}"/make_panel_vc.sh -d "${dir_patient}" &> "${dir_log}/vc.log") &
("${DIR_SCRIPT}"/make_panel_cnv.sh -p -d "${dir_patient}" &> "${dir_log}/cnv.log") &
wait
# create report based on the results of the processes above
("${DIR_SCRIPT}"/make_panel_report.sh -d "${dir_patient}" &> "${dir_log}/report.log")
cleanup "${dir_patient}"
}
# run_pipe_seq relative_patient_dir dir_target
function run_panel_pipe_seq() {
local dir_patient="${1}"
local dir_target="${2}"
local dir_log="${dir_target}/log"
setup "${dir_patient}" "${dir_target}"
("${DIR_SCRIPT}"/make_panel_alignment.sh -t td -d "${dir_patient}" &> "${dir_log}/td.log")
("${DIR_SCRIPT}"/make_panel_vc.sh -d "${dir_patient}" &> "${dir_log}/vc.log")
("${DIR_SCRIPT}"/make_panel_cnv.sh -d "${dir_patient}" &> "${dir_log}/cnv.log")
("${DIR_SCRIPT}"/make_rna_fusions.sh -d "${dir_patient}" &> "${dir_log}/fusions.log")
("${DIR_SCRIPT}"/make_panel_report.sh -d "${dir_patient}" &> "${dir_log}/report.log")
cleanup "${dir_patient}"
}
# tumorOnly protocol
# run_pipe_panel relative_patient_dir dir_target
function run_tumorOnly_pipe() {
local dir_patient="${1}"
local dir_target="${2}"
local dir_log="${dir_target}/log"
setup "${dir_patient}" "${dir_target}"
# use parallel shell scripting
("${DIR_SCRIPT}"/make_tumorOnly_alignment.sh -t td -d "${dir_patient}" &> "${dir_log}/td.log")
# use parallel shell scripting
("${DIR_SCRIPT}"/make_tumorOnly_vc.sh -d "${dir_patient}" &> "${dir_log}/vc.log") &
("${DIR_SCRIPT}"/make_tumorOnly_cnv.sh -p -d "${dir_patient}" &> "${dir_log}/cnv.log") &
wait
# create report based on the results of the processes above
("${DIR_SCRIPT}"/make_tumorOnly_report.sh -d "${dir_patient}" &> "${dir_log}/report.log")
cleanup "${dir_patient}"
}
# run_pipe_seq relative_patient_dir dir_target
function run_tumorOnly_pipe_seq() {
local dir_patient="${1}"
local dir_target="${2}"
local dir_log="${dir_target}/log"
setup "${dir_patient}" "${dir_target}"
("${DIR_SCRIPT}"/make_tumorOnly_alignment.sh -t td -d "${dir_patient}" &> "${dir_log}/td.log")
("${DIR_SCRIPT}"/make_tumorOnly_vc.sh -d "${dir_patient}" &> "${dir_log}/vc.log")
("${DIR_SCRIPT}"/make_tumorOnly_cnv.sh -d "${dir_patient}" &> "${dir_log}/cnv.log")
("${DIR_SCRIPT}"/make_tumorOnly_report.sh -d "${dir_patient}" &> "${dir_log}/report.log")
cleanup "${dir_patient}"
}
# get_case relative_patient_dir
function get_case() {
local dir_patient="${1}"
if [[ "$(get_config_value common.protocol "${dir_patient}")" = "wes" ]]; then
if [[ "$(get_config_value common.germline "${dir_patient}")" = "True" ]]; then
echo "somaticGermline"
else
echo "somatic"
fi
fi
if [[ "$(get_config_value common.protocol "${dir_patient}")" = "panel" ]]; then
echo "panelTumor"
fi
if [[ "$(get_config_value common.protocol "${dir_patient}")" = "tumorOnly" ]]; then
echo "tumorOnly"
fi
}
while getopts d:t:p:fhs option; do
case "${option}" in
t) readonly PARAM_TASK=$OPTARG;;
p) readonly PARAM_PROTOCOL=$OPTARG;;
d) readonly PARAM_DIR_PATIENT=$OPTARG;;
f) readonly PARAM_FORCE=true;;
s) readonly PARAM_SEQ=true;;
h) usage ;;
\?)
echo "Unknown option: -$OPTARG" >&2
exit 1
;;
:)
echo "Missing option argument for -$OPTARG" >&2
exit 1
;;
*)
echo "Unimplemented option: -$OPTARG" >&2
exit 1
;;
esac
done
# run script
if [[ ! -z "${PARAM_PROTOCOL}" ]]; then
if [[ ! " ${VALID_PROTOCOLS[@]} " =~ " ${PARAM_PROTOCOL} " ]]; then
echo "unknown protocol: ${PARAM_PROTOCOL}"
echo "use one of the following values: $(join_by ' ' ${VALID_PROTOCOLS})"
exit 1
fi
if [[ !("${PARAM_FORCE}") && -e "${DIR_TARGET}/.processed" ]]; then
echo "Analyses already exist. If you want to re-analyze it, it has to be forced (-f)."
fi
if [[ -z "${PARAM_DIR_PATIENT}" && -z "${PARAM_TASK}" && -n "${PARAM_PROTOCOL}" ]]; then
for dir in "${DIR_SCRIPT}"/assets/input/*; do
# get relative dir patient
DIR_PATIENT=${dir##*/}
# estimate output dir
CFG_CASE=$(get_case ${DIR_PATIENT})
DIR_TARGET="${DIR_OUTPUT}/${CFG_CASE}_${DIR_PATIENT}"
DIR_ANALYSES="${DIR_TARGET}/Analyses"
if [[ "${PARAM_FORCE}" || ! -f "${DIR_TARGET}/.processed" ]]; then
echo "computing ${DIR_PATIENT}"
echo "${PARAM_PROTOCOL}"
if [[ "${PARAM_PROTOCOL}" == "wes" ]]; then
echo "WES Protocol"
if [[ -z "${PARAM_SEQ}" ]]; then
run_pipe "${DIR_PATIENT}" "${DIR_TARGET}"
else
run_pipe_seq "${DIR_PATIENT}" "${DIR_TARGET}"
fi
# check if report was generated successfully
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${DIR_PATIENT}_Report.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${DIR_PATIENT} finished"
else
echo "${DIR_PATIENT} failed"
fi
fi
if [[ "${PARAM_PROTOCOL}" == "panel" ]]; then
echo "Panel Protocol"
if [[ -z "${PARAM_SEQ}" ]]; then
run_panel_pipe "${DIR_PATIENT}" "${DIR_TARGET}"
else
run_panel_pipe_seq "${DIR_PATIENT}" "${DIR_TARGET}"
fi
# check if report was generated successfully
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${DIR_PATIENT}_Report_Panel.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${DIR_PATIENT} finished"
else
echo "${DIR_PATIENT} failed"
fi
fi
if [[ "${PARAM_PROTOCOL}" == "tumorOnly" ]]; then
echo "tumorOnly Protocol"
if [[ -z "${PARAM_SEQ}" ]]; then
run_tumorOnly_pipe "${DIR_PATIENT}" "${DIR_TARGET}"
else
run_tumorOnly_pipe_seq "${DIR_PATIENT}" "${DIR_TARGET}"
fi
# check if report was generated successfully
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${DIR_PATIENT}_Report_tumorOnly.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${DIR_PATIENT} finished"
else
echo "${DIR_PATIENT} failed"
fi
fi
fi
done
else
CFG_CASE=$(get_case ${PARAM_DIR_PATIENT})
DIR_TARGET="${DIR_OUTPUT}/${CFG_CASE}_${PARAM_DIR_PATIENT}"
DIR_LOG="${DIR_TARGET}/log"
readonly DIR_TMP="$(get_config_value common.dirTmp "${PARAM_DIR_PATIENT}")/${PARAM_DIR_PATIENT}"
# create temporary folder if not existent
[[ -d "${DIR_TMP}" ]] || mkdir -p "${DIR_TMP}"
[[ -d "${DIR_LOG}" ]] || mkdir -p "${DIR_LOG}"
# estimate output dir
CFG_CASE=$(get_case ${PARAM_DIR_PATIENT})
DIR_TARGET="${DIR_OUTPUT}/${CFG_CASE}_${PARAM_DIR_PATIENT}"
DIR_ANALYSES="${DIR_TARGET}/Analyses"
# if already computed, i.e. file .processed exists, only compute again if forced
if [[ "${PARAM_FORCE}" || ! -f "${DIR_TARGET}/.processed" ]]; then
if [[ ! -z ${PARAM_TASK} ]]; then
if [[ ! " ${VALID_TASKS[@]} " =~ " ${PARAM_TASK} " ]]; then
echo "unknown task: ${PARAM_TASK}"
echo "use one of the following values: $(join_by ' ' ${VALID_TASKS})"
exit 1
fi
# setup processing
setup "${PARAM_DIR_PATIENT}" "${DIR_TARGET}"
# possibility to comfortably run tasks separately
case "${PARAM_PROTOCOL}" in
wes)
case "${PARAM_TASK}" in
td)
"${DIR_SCRIPT}"/make_alignment.sh -t td -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/td.log"
;;
gd)
"${DIR_SCRIPT}"/make_alignment.sh -t gd -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/gd.log"
;;
cnv)
"${DIR_SCRIPT}"/make_cnv.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/cnv.log"
;;
vc)
"${DIR_SCRIPT}"/make_vc.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/vc.log"
;;
report)
"${DIR_SCRIPT}"/make_report.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/report.log"
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${PARAM_DIR_PATIENT} Report finished"
else
echo "${PARAM_DIR_PATIENT} failed"
fi
;;
td_gd_parallel)
("${DIR_SCRIPT}"/make_alignment.sh -p -t td -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/td.log") &
("${DIR_SCRIPT}"/make_alignment.sh -p -t gd -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/gd.log") &
wait
;;
vc_cnv_parallel)
("${DIR_SCRIPT}"/make_vc.sh -p -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/vc.log") &
("${DIR_SCRIPT}"/make_cnv.sh -p -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/cnv.log") &
wait
;;
esac
;;
panel)
case "${PARAM_TASK}" in
td)
"${DIR_SCRIPT}"/make_panel_alignment.sh -t td -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/td.log"
;;
cnv)
"${DIR_SCRIPT}"/make_panel_cnv.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/cnv.log"
;;
vc)
"${DIR_SCRIPT}"/make_panel_vc.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/vc.log"
;;
rna_fusions)
"${DIR_SCRIPT}"/make_rna_fusions.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/fusions.log"
;;
report)
"${DIR_SCRIPT}"/make_panel_report.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/report.log"
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_Panel.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${PARAM_DIR_PATIENT} Report finished"
else
echo "${PARAM_DIR_PATIENT} failed"
fi
;;
td_rna_fusions_parallel)
("${DIR_SCRIPT}"/make_panel_alignment.sh -t td -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/td.log") &
("${DIR_SCRIPT}"/make_rna_fusions.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/fusions.log") &
wait
;;
vc_cnv_parallel)
("${DIR_SCRIPT}"/make_panel_vc.sh -p -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/vc.log") &
("${DIR_SCRIPT}"/make_panel_cnv.sh -p -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/cnv.log") &
wait
;;
esac
;;
tumorOnly)
case "${PARAM_TASK}" in
td)
"${DIR_SCRIPT}"/make_tumorOnly_alignment.sh -t td -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/td.log"
;;
cnv)
"${DIR_SCRIPT}"/make_tumorOnly_cnv.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/cnv.log"
;;
vc)
"${DIR_SCRIPT}"/make_tumorOnly_vc.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/vc.log"
;;
report)
"${DIR_SCRIPT}"/make_tumorOnly_report.sh -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/report.log"
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${PARAM_DIR_PATIENT} Report finished"
else
echo "${PARAM_DIR_PATIENT} failed"
fi
;;
vc_cnv_parallel)
("${DIR_SCRIPT}"/make_tumorOnly_vc.sh -p -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/vc.log") &
("${DIR_SCRIPT}"/make_tumorOnly_cnv.sh -p -d "${PARAM_DIR_PATIENT}" &> "${DIR_LOG}/cnv.log") &
wait
;;
esac
;;
esac
cleanup "${PARAM_DIR_PATIENT}"
else
echo "computing ${PARAM_DIR_PATIENT}"
if [[ ${PARAM_PROTOCOL} == "wes" ]]; then
echo "WES Protocol"
if [[ -z "${PARAM_SEQ}" ]]; then
run_pipe "${PARAM_DIR_PATIENT}" "${DIR_TARGET}"
else
run_pipe_seq "${PARAM_DIR_PATIENT}" "${DIR_TARGET}"
fi
# check if report was generated successfully
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${PARAM_DIR_PATIENT} finished"
else
echo "${PARAM_DIR_PATIENT} failed"
fi
fi
if [[ ${PARAM_PROTOCOL} == "panel" ]]; then
echo "Panel Protocol"
if [[ -z "${PARAM_SEQ}" ]]; then
run_panel_pipe "${PARAM_DIR_PATIENT}" "${DIR_TARGET}"
else
run_panel_pipe_seq "${PARAM_DIR_PATIENT}" "${DIR_TARGET}"
fi
# check if report was generated successfully
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_Panel.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${PARAM_DIR_PATIENT} finished"
else
echo "${PARAM_DIR_PATIENT} failed"
fi
fi
if [[ ${PARAM_PROTOCOL} == "tumorOnly" ]]; then
echo "tumorOnly Protocol"
if [[ -z "${PARAM_SEQ}" ]]; then
run_tumorOnly_pipe "${PARAM_DIR_PATIENT}" "${DIR_TARGET}"
else
run_tumorOnly_pipe_seq "${PARAM_DIR_PATIENT}" "${DIR_TARGET}"
fi
# check if report was generated successfully
if [[ -f "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.pdf" ]]; then
touch "${DIR_TARGET}/.processed"
echo "${PARAM_DIR_PATIENT} finished"
else
echo "${PARAM_DIR_PATIENT} failed"
fi
fi
fi
else
echo "Analyses already exist. If you want to re-analyze it, it has to be forced (-f)."
fi
fi
fi