-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathKUL_anat_lesionheatmap.sh
executable file
·243 lines (195 loc) · 6.26 KB
/
KUL_anat_lesionheatmap.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
#!/bin/bash
# Bash shell script to create a lesion heat map after KUL_anat_segment_tumor
#
# Requires ants
#
# @ Stefan Sunaert - UZ/KUL - [email protected]
# 01/05/2022
version="0.1"
kul_main_dir=$(dirname "$0")
script=$(basename "$0")
source $kul_main_dir/KUL_main_functions.sh
# $cwd & $log_dir is made in main_functions
fix_im="$kul_main_dir/atlasses/Ganzetti2014/mni_icbm152_t1_tal_nlin_sym_09a.nii"
# FUNCTIONS --------------
# function Usage
function Usage {
cat <<USAGE
`basename $0` create a lesion heat map after KUL_anat_segment_tumor
and running the anatomical workflow of fmriprep (for MNI normalisation)
Usage:
`basename $0` <OPT_ARGS>
Example:
`basename $0` -p JohnDoe
Required arguments:
-p: names of participants to include in heatmap (put them between "")
OR
-a: run on all in BIDS folder
Optional arguments:
-c: use the VBG output instead of native lesioned brains for MNI registration
-n: number of cpu to use (default 15)
-v: show output from commands (0=silent, 1=normal, 2=verbose; default=1)
USAGE
exit 1
}
# CHECK COMMAND LINE OPTIONS -------------
#
# Set defaults
silent=1 # default if option -v is not given
ants_verbose=1
ncpu=15
verbose_level=1
run_all=0
use_vbg=0
# Set required options
p_flag=0
d_flag=0
if [ "$#" -lt 1 ]; then
Usage >&2
exit 1
else
while getopts "p:a:n:v:c" OPT; do
case $OPT in
p) #participant
participants=($OPTARG)
p_flag=1
;;
a) #all
run_all=$OPTARG
;;
c) #use_vbg
use_vbg=1
;;
n) #ncpu
ncpu=$OPTARG
;;
v) #verbose
verbose_level=$OPTARG
;;
\?)
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
KUL_LOG_DIR="KUL_LOG/${script}/sub-${participant}"
mkdir -p $KUL_LOG_DIR
# MRTRIX and others verbose or not?
if [ $verbose_level -lt 2 ] ; then
export MRTRIX_QUIET=1
silent=1
str_silent=" > /dev/null 2>&1"
ants_verbose=0
elif [ $verbose_level -eq 2 ] ; then
silent=0
str_silent=""
ants_verbose=1
fi
# --- MAIN ---
# STEP 1 - SETUP
heat1=""
heat2=""
heat3=""
heat4=""
for participant in ${participants[@]}; do
echo "Registering $participant to MNI"
# register to MNI
wd=$cwd/BIDS/derivatives/KUL_compute/sub-${participant}/KUL_anat_register_mni
lesion1_test="RESULTS/sub-${participant}/Lesionmap/sub-${participant}_lesion_and_cavity_corr1.nii.gz"
if [ -f $lesion1_test ]; then
lesion1=$lesion1_test
lesion1_label=lesion_and_cavity_corr1
else
lesion1="RESULTS/sub-${participant}/Lesion/sub-${participant}_lesion_and_cavity.nii.gz"
lesion1_label=lesion_and_cavity
fi
lesion1a_test="RESULTS/sub-${participant}/Lesionmap/sub-${participant}_lesion_and_cavity_corr2.nii.gz"
if [ -f $lesion1a_test ]; then
lesion1a=$lesion1a_test
lesion1a_label=lesion_and_cavity_corr2
else
lesion1a=$lesion1
lesion1a_label=$lesion1_label
fi
lesion2_test="RESULTS/sub-${participant}/Lesion/sub-${participant}_hdglio_lesion_perilesional_tissue_corr1.nii.gz"
if [ -f $lesion2_test ]; then
lesion2=$lesion2_test
lesion2_label=hdglio_lesion_perilesional_tissue_corr1
else
lesion2="RESULTS/sub-${participant}/Lesion/sub-${participant}_hdglio_lesion_perilesional_tissue.nii.gz"
lesion2_label=hdglio_lesion_perilesional_tissue
fi
lesion3_test="RESULTS/sub-${participant}/Lesion/sub-${participant}_hdglio_lesion_total_corr1.nii.gz"
if [ -f $lesion3_test ]; then
lesion3=$lesion3_test
lesion3_label=hdglio_lesion_total_corr1
else
lesion3="RESULTS/sub-${participant}/Lesion/sub-${participant}_hdglio_lesion_total.nii.gz"
lesion3_label=hdglio_lesion_total
fi
lesion4_test="RESULTS/sub-${participant}/Lesion/sub-${participant}_resseg_cavity_only_corr1.nii.gz"
if [ -f $lesion4_test ]; then
lesion4=$lesion4_test
lesion4_label=resseg_cavity_only_corr1
else
lesion4="RESULTS/sub-${participant}/Lesion/sub-${participant}_resseg_cavity_only.nii.gz"
lesion4_label=resseg_cavity_only
fi
if [ $use_vbg -eq 1 ]; then
T1w=VBG_out/output_VBG/sub-${participant}/sub-${participant}_T1_nat_filled.nii.gz
else
T1w=BIDS/sub-${participant}/ses-study/anat/sub-${participant}_ses-study_T1w.nii.gz
fi
KUL_anat_register.sh \
-t /usr/local/KUL_apps/KUL_NIS/atlasses/Ganzetti2014/mni_icbm152_t1_tal_nlin_sym_09a.nii \
-s $T1w \
-d $wd \
-w -m 1 -i 2 \
-o "$lesion1 $lesion1a $lesion2 $lesion3 $lesion4"
map_d="BIDS/derivatives/KUL_compute/sub-${participant}/KUL_anat_register_mni/"
map1="$map_d/sub-${participant}_${lesion1_label}_reg2_mni_icbm152_t1_tal_nlin_sym_09a.nii.gz"
map1a="$map_d/sub-${participant}_${lesion1a_label}_reg2_mni_icbm152_t1_tal_nlin_sym_09a.nii.gz"
map2="$map_d/sub-${participant}_${lesion2_label}_reg2_mni_icbm152_t1_tal_nlin_sym_09a.nii.gz"
map3="$map_d/sub-${participant}_${lesion3_label}_reg2_mni_icbm152_t1_tal_nlin_sym_09a.nii.gz"
map4="$map_d/sub-${participant}_${lesion4_label}_reg2_mni_icbm152_t1_tal_nlin_sym_09a.nii.gz"
if [ -f $map1 ]; then
heat1="$heat1 $map1 "
fi
if [ -f $map1a ]; then
heat1a="$heat1a $map1a "
fi
if [ -f $map2 ]; then
heat2="$heat2 $map2 "
fi
if [ -f $map3 ]; then
heat3="$heat3 $map3 "
fi
if [ -f $map4 ]; then
heat4="$heat4 $map4 "
fi
done
kulderivativesdir=BIDS/derivatives/KUL_compute/KUL_anat_lesionheatmap
mkdir -p $kulderivativesdir
mrmath $heat1 sum $kulderivativesdir/lesionheatmap_lesion_and_cavity1.nii.gz -force
echo $heat1a
mrmath $heat1a sum $kulderivativesdir/lesionheatmap_lesion_and_cavity2.nii.gz -force
mrmath $heat2 sum $kulderivativesdir/lesionheatmap_hdglio_lesion_perilesional_tissue.nii.gz -force
mrmath $heat3 sum $kulderivativesdir/lesionheatmap_hdglio_lesion_total.nii.gz -force
mrmath $heat4 sum $kulderivativesdir/lesionheatmap_resseg_cavity_only.nii.gz -force
echo "Finished"