-
Notifications
You must be signed in to change notification settings - Fork 0
/
runScript.sh
executable file
·380 lines (367 loc) · 9.27 KB
/
runScript.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
#!/bin/sh
show_help(){
echo "Usage: $0 [options] SubjectFolder
Required arguments:
-f|--subject-dir [SubjectFolder] (directory name only)
-F|--study-dir [StudyFolder] (path the study directory)
Optional arguments:
-d|--distortion-correction
-r|--coregistration
-N|--fit-noddi
-K|--fit-dki
-D|--fit-dti
-w|--prep-wmh
-m|--prep-wmh-shells
-c|--prep-clusters
-s|--prep-shells
-W|--measure-wmh
-M|--measure-wmh-shells
-C|--measure-clusters
-S|--measure-shells
-a|--all (default)
-q|--sge-submit
-X|--script-dir [ScriptDir]">&2
exit 1
}
TRUE=0
FALSE=""
#################################################
# Argument Flags
#################################################
ALL=$TRUE
SUBJECT_DIR=$FALSE
STUDY_DIR=$(pwd)
SGE_SUBMIT=$FALSE
DISTORTION_CORRECTION=$FALSE
COREGISTRATION=$FALSE
FIT_NODDI=$FALSE
FIT_DKE=$FALSE
FIT_DTI=$FALSE
PREP_WMH=$FALSE
PREP_WMH_SHELLS=$FALSE
PREP_CLUSTERS=$FALSE
PREP_CLUSTER_SHELLS=$FALSE
MEASURE_WMH=$FALSE
MEASURE_WMH_SHELLS=$FALSE
MEASURE_CLUSTERS=$FALSE
MEASURE_CLUSTER_SHELLS=$FALSE
SCRIPTS_DIR="$DTIPIPE"
#################################################
# Argument Parsing
#################################################
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-f|--subject-dir)
SUBJECT_DIR="$2"
shift
shift
;;
-F|--study-dir)
STUDY_DIR="$2"
shift
shift
;;
-X|--script-dir)
SCRIPTS_DIR="$2"
export DTIPIPE="$2"
shift
shift
;;
-d|--distortion-correction)
ALL=$FALSE
DISTORTION_CORRECTION=$TRUE
shift # past argument
;;
-r|--coregistration)
ALL=$FALSE
COREGISTRATION=$TRUE
shift # past argument
;;
-N|--fit-noddi)
ALL=$FALSE
FIT_NODDI=$TRUE
shift # past argument
;;
-K|--fit-dki)
ALL=$FALSE
FIT_DKE=$TRUE
shift # past argument
;;
-D|--fit-dti)
ALL=$FALSE
FIT_DTI=$TRUE
shift # past argument
;;
-w|--prep-wmh)
ALL=$FALSE
PREP_WMH=$TRUE
shift # past argument
;;
-m|--prep-wmh-shells)
ALL=$FALSE
PREP_WMH_SHELLS=$TRUE
shift # past argument
;;
-c|--prep-clusters)
ALL=$FALSE
PREP_CLUSTERS=$TRUE
shift # past argument
;;
-s|--prep-shells)
ALL=$FALSE
PREP_CLUSTER_SHELLS=$TRUE
shift # past argument
;;
-W|--measure-wmh)
ALL=$FALSE
MEASURE_WMH=$TRUE
shift # past argument
;;
-M|--measure-wmh-shells)
ALL=$FALSE
MEASURE_WMH_SHELLS=$TRUE
shift # past argument
;;
-C|--measure-clusters)
ALL=$FALSE
MEASURE_CLUSTERS=$TRUE
shift # past argument
;;
-S|--measure-shells)
ALL=$FALSE
MEASURE_CLUSTER_SHELLS=$TRUE
shift # past argument
;;
-q|--sge-submit)
SGE_SUBMIT=$TRUE
shift # past argument
;;
-a|--all)
ALL=$TRUE
shift # past value
;;
*|-h|--help) # unknown option
show_help
;;
esac
done
if [ $ALL ]; then
DISTORTION_CORRECTION=$TRUE
COREGISTRATION=$TRUE
FIT_NODDI=$TRUE
FIT_DKE=$TRUE
FIT_DTI=$TRUE
PREP_WMH=$TRUE
PREP_WMH_SHELLS=$TRUE
PREP_CLUSTERS=$TRUE
PREP_CLUSTER_SHELLS=$TRUE
MEASURE_WMH=$TRUE
MEASURE_WMH_SHELLS=$TRUE
MEASURE_CLUSTERS=$TRUE
MEASURE_CLUSTER_SHELLS=$TRUE
fi
#################################################
# Argument Validation
#################################################
if [ ! -d "$SCRIPTS_DIR" ]; then
echo "ERROR: Could not find scripts directory: ${SCRIPTS_DIR}.">&2
exit 1
fi
if [ ! -d "$STUDY_DIR" ]; then
echo "ERROR: Could not find study directory: ${STUDY_DIR}.">&2
exit 1
fi
if [ ! $SUBJECT_DIR ]; then
echo "ERROR: no subject directory specified.">&2
fi
if [ ! -d "$STUDY_DIR/$SUBJECT_DIR" ]; then
echo "ERROR: Could not find subject: ${SUBJECT_DIR}.">&2
exit 1
fi
#################################################
# Execute Scripts
#################################################
cd "$STUDY_DIR/$SUBJECT_DIR"
process="$SCRIPTS_DIR/scripts/processing"
mkdir -p logs/out
mkdir -p logs/err
# prepare some special stuff for queue submittion
if [ $SGE_SUBMIT ]; then
module load fsl/5.0.11
module load mrtrix
module load python/3.6.6
module load matlab/R2018a
out='logs/out/${script_name}.out'
err='logs/err/${script_name}.err'
script='$process/${script_name}.sh'
name='${script_name}_${SUBJECT_DIR}'
qsub_command="qsub -pe mpi \$slots -q long.q -V -cwd -o $out -e $err -N $name -hold_jid \$holds $script"
fi
if [ $DISTORTION_CORRECTION ]; then
script_name=distortion_correction
if [ $SGE_SUBMIT ]; then
slots=6
holds=tmp
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $COREGISTRATION ]; then
script_name=coregister
if [ $SGE_SUBMIT ]; then
slots=1
holds="distortion_correction_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $FIT_NODDI ]; then
script_name=calculate_noddi
if [ $SGE_SUBMIT ]; then
slots=12
holds="coregister_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $FIT_DKE ]; then
script_name=calculate_kurtosis
if [ $SGE_SUBMIT ]; then
slots=12
holds="coregister_${SUBJECT_DIR}"
module unload matlab
module load matlab/MCR-R2012a
module load dke
eval $qsub_command
module unload dke
module unload matlab
module load matlab/R2018a
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $FIT_DTI ]; then
script_name=fit_tensors
if [ $SGE_SUBMIT ]; then
slots=1
holds="coregister_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $PREP_WMH ]; then
script_name=prepare_wmh_vs_nawm
if [ $SGE_SUBMIT ]; then
slots=1
holds="distortion_correction_${SUBJECT_DIR}"
holds="$holds,calculate_noddi_${SUBJECT_DIR}"
holds="$holds,calculate_kurtosis_${SUBJECT_DIR}"
holds="$holds,fit_tensors_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $PREP_WMH_SHELLS ]; then
script_name=prep_wmh_shells
if [ $SGE_SUBMIT ]; then
slots=1
holds="prepare_wmh_vs_nawm_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $PREP_CLUSTERS ]; then
script_name=prep_clusters
if [ $SGE_SUBMIT ]; then
slots=1
holds="prepare_wmh_vs_nawm_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $PREP_CLUSTER_SHELLS ]; then
script_name=prep_cluster_shells
if [ $SGE_SUBMIT ]; then
slots=1
holds="prep_clusters_${SUBJECT_DIR}"
holds=",$holds,prep_wmh_shells_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $MEASURE_WMH ]; then
script_name=compare_wmh_vs_nawm
if [ $SGE_SUBMIT ]; then
slots=1
holds="prepare_wmh_vs_nawm_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $MEASURE_WMH_SHELLS ]; then
script_name=compare_wmh_shells
if [ $SGE_SUBMIT ]; then
slots=1
holds="prep_wmh_shells_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $MEASURE_CLUSTERS ]; then
script_name=measure_clusters
if [ $SGE_SUBMIT ]; then
slots=1
holds="prep_clusters_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi
if [ $MEASURE_CLUSTER_SHELLS ]; then
script_name=measure_cluster_shells
if [ $SGE_SUBMIT ]; then
slots=1
holds="prep_cluster_shells_${SUBJECT_DIR}"
eval $qsub_command
else
$process/${script_name}.sh>\
logs/out/${script_name}.out 2>\
logs/err/${script_name}.err
fi
fi