-
Notifications
You must be signed in to change notification settings - Fork 12
/
KUL_MRtrix3_connectome.sh
executable file
·202 lines (157 loc) · 3.36 KB
/
KUL_MRtrix3_connectome.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
#!/bin/bash -e
# Bash shell script to run mrtrix_connectome
#
# Requires docker
#
# @ Stefan Sunaert - UZ/KUL - [email protected]
# 07/09/2021
version="0.1"
kul_main_dir=`dirname "$0"`
source $kul_main_dir/KUL_main_functions.sh
cwd=$(pwd)
# FUNCTIONS --------------
# function Usage
function Usage {
cat <<USAGE
`basename $0` runs MRtrix3_connectome tuned for KUL/UZLeuven data
Usage:
`basename $0` <OPT_ARGS>
Example:
`basename $0` -l 1
this will perform preprocessing on all participants/sessions in the BIDS directory
Required arguments:
-l: level (1=preproc, 2=participant, 3=group)
Optional arguments:
-p: participant name
-s: session
-g: use gpu (does not work an MacOs)
-n: number of cpu to use (default 15)
-v: show output from commands
USAGE
exit 1
}
# CHECK COMMAND LINE OPTIONS -------------
#
# Set defaults
silent=1 # default if option -v is not given
ncpu=15
gpu=0
level=0
session=""
# Set required options
p_flag=0
l_flag=0
if [ "$#" -lt 1 ]; then
Usage >&2
exit 1
else
while getopts "p:s:n:l:gv" OPT; do
case $OPT in
p) #participant
participant="$OPTARG"
p_flag=1
;;
l) #level
level=$OPTARG
l_flag=1
;;
s) #session
session=$OPTARG
;;
n) #ncpu
ncpu=$OPTARG
;;
g) #gpu
gpu=1
;;
v) #verbose
silent=0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo
Usage >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
echo
Usage >&2
exit 1
;;
esac
done
fi
# check for required options
if [ $p_flag -eq 0 ] ; then
echo
echo "Option -p is required: give the BIDS name of the participant." >&2
echo
exit 2
fi
if [ $l_flag -eq 0 ] ; then
echo
echo "Option -l is required: give the processing level." >&2
echo
exit 2
fi
# ---- MAIN ------------------------
#echo $participant
if [ -z $session ];then
sessuf=""
mrtrix_session_label=""
else
sessuf="/ses-"
mrtrix_session_label=" --session_label "$session" "
fi
if [ $gpu -eq 1 ]; then
gpu_cmd1="--gpus all"
else
gpu_cmd1=""
fi
outputdir="$cwd/MRtrix3_connectome"
scratchdir="$cwd/MRtrix3_connectome_sub-${participant}"
if [ $level -eq 1 ]; then
test_file="$cwd/MRtrix3_connectome/MRtrix3_connectome-preproc/sub-${participant}/dwi/sub-${participant}_desc-preproc_dwi.nii.gz"
if [ ! -f $test_file ];then
my_cmd="docker run -i --rm \
-v $cwd/BIDS:/bids_dataset \
-v $outputdir:/output \
$gpu_cmd1 \
treanus/mrtrix3_connectome \
/bids_dataset /output preproc \
--participant_label "$participant" \
$mrtrix_session_label \
--topup_prefix synb0 \
--output_verbosity 4 \
--n_cpus $ncpu"
else
my_cmd="echo Already preprocessed"
fi
elif [ $level -eq 2 ]; then
my_cmd="docker run -i --rm \
-v $cwd/BIDS:/bids_dataset \
-v $outputdir:/output \
$gpu_cmd1 \
bids/mrtrix3_connectome \
/bids_dataset /output participant \
--participant_label "$participant" \
$mrtrix_session_label \
--output_verbosity 4 \
--template_reg ants \
--parcellation desikan
--n_cpus $ncpu"
elif [ $level -eq 3 ]; then
my_cmd="docker run -i --rm \
-v $cwd/BIDS:/bids_dataset \
-v $outputdir:/output \
$gpu_cmd1 \
bids/mrtrix3_connectome \
/bids_dataset /output group \
$mrtrix_session_label \
--output_verbosity 4 \
--n_cpus $ncpu"
fi
echo $my_cmd
mkdir -p $outputdir
eval $my_cmd