This repository has been archived by the owner on May 26, 2023. It is now read-only.
forked from caseypaquola/BigBrainWarp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigbrainwarp
executable file
·225 lines (204 loc) · 7.94 KB
/
bigbrainwarp
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
#!/bin/bash
#
# BigBrainWarp
#
version() {
echo -e "\nBigBrainWarp July 2021 (Beta)\n"
}
#---------------- FUNCTION: HELP ----------------#
help() {
echo -e "
\033[38;5;141mCOMMAND:\033[0m
$(basename $0)
\033[38;5;141mREQUIRED ARGUMENTS:\033[0m
\t\033[38;5;197m--in_space\033[0m : space of input data (bigbrain, bigbrainsym, icbm, fsaverage or fs_LR)
\t\033[38;5;197m--out_space\033[0m : space of output data (bigbrain, bigbrainsym, icbm, fsaverage or fs_LR)
\t\033[38;5;197m--wd\033[0m : Path to a working directory, where data will be output
\033[38;5;141mINPUT ARGUMENTS (use either -in_vol or both --in_lh and --in_rh):\033[0m
\t\033[38;5;197m--in_vol\033[0m : full path to input data. Must be whole brain. Can be mnc, nii or nii.gz
\t\033[38;5;197m--in_lh\033[0m : full path to input data for left hemisphere. Can be .label.gii, .annot, .shape.gii, .curv or .txt
\t\033[38;5;197m--in_rh\033[0m : full path to input data for right hemisphere. Can be .label.gii, .annot, .shape.gii, .curv or .txt
\t\033[38;5;197m--desc\033[0m : descriptor of input data, which will be used to name the output.
\033[38;5;141mEXTRA ARGUMENTS:\033[0m
\t\033[38;5;197m--interp\033[0m : interpolation method. For --in_vol, it can be trilinear (default), tricubic, nearest or sinc. For --in_lh/--in_rh, can be linear or nearest. Only works for .txt, however. Other types are forced to defaults (label.gii and .annot to nearest, shape.gii and .curv to linear)
\t\033[38;5;197m--out_type\033[0m : (optional) specify output in surface or volume space. Otherwise, defaults to the same type as the input.
\t\033[38;5;197m--out_den\033[0m : (optional) density of output mesh. Only applicable for -in_lh/-in_rh and if out_space is fs_LR. Can be 164 or 32. Default is 32.
\t\033[38;5;197m--out_res\033[0m : (optional) resolution of output volume. Only applicable for -in_vol. Provide in mm. Default is 1.
\t\033[38;5;197m--h|-help\033[0m : Print help
Casey Paquola, MNI, MICA Lab, 2021
https://bigbrainwarp.readthedocs.io/
"
}
# -----------------------------------------------------------------------------------------------#
# ARGUMENTS
# Create VARIABLES
for arg in "$@"
do
case "$arg" in
-h|-help)
help
exit 1
;;
--in_space)
in_space=$2
shift;shift
;;
--out_space)
out_space=$2
shift;shift
;;
--wd)
wd=$2
shift;shift
;;
--interp)
interp=$2
shift;shift
;;
--in_vol)
in_vol=$2
shift;shift
;;
--in_lh)
in_lh=$2
shift;shift
;;
--in_rh)
in_rh=$2
shift;shift
;;
--desc)
desc=$2
shift;shift
;;
--out_type)
out_type=$2
shift;shift
;;
--out_den)
out_den=$2
shift;shift
;;
--out_res)
out_res=$2
shift;shift
;;
-*)
echo "Unknown option ${2}"
help
exit 1
;;
esac
done
# argument check out & warning
arg=($in_space $out_space $wd $desc)
if [ ${#arg[@]} -lt 4 ]; then
echo "One or more mandatory arguments are missing:
-in_space : $in_space
-out_space : $out_space
-wd : $wd
-desc : $desc"
fi
# use arguments to identify form of transformation (ie: surface or volume-based)
if [[ -z $in_vol ]] ; then
if [[ -z $in_lh ]] || [[ -z $in_rh ]] ; then
print "did not find required input arguments"
else
in_type=surface
fi
else
in_type=volume
fi
if [[ -z $out_type ]] ; then
surface_spaces="fsaverage fs_LR"
if [[ "$surface_spaces" =~ .*"$out_space".* ]] ; then
out_type=surface
elif [[ "$surface_spaces" =~ .*icbm.* ]] ; then
out_type=volume
else
# default to same type as input
out_type=$in_type
fi
fi
# set default interpolation
if [[ -z "$interp" ]] ; then
if [[ "$in_type" == "volume" ]] ; then
interp=trilinear # default to trilinear interpolation for volume-based transformations
else
interp=nearest # default interpolation, but this option only has an effect if the input is .txt
fi
fi
# set specific space parameter for bigbrain
if [[ "$in_space" == *bigbrain* ]] || [[ "$out_space" == *bigbrain* ]] ; then
if [[ "bigbrainsym" == "$in_space" ]] || [[ "bigbrainsym" == "$out_space" ]] ; then
bb_space=sym
else
bb_space=histological
fi
fi
# set density parameter for fsaverage outputs
if [[ "$out_type" == "surface" ]] ; then
if [[ -z "$out_den" ]] ; then
if [[ "fsaverage" == "$out_space" ]] ; then
out_den=164
elif [[ "fs_LR" == "$out_space" ]] ; then
out_den=32
fi
fi
fi
# set default resolution parameter for volume outputs
if [[ "$out_type" == "volume" ]] ; then
if [[ -z "$out_res" ]] ; then
out_res=1
fi
fi
# print out parameters for the user (handy for debugging)
echo "Input parameters:
--in_space : $in_space
--out_space : $out_space
--bb_space : $bb_space
--wd : $wd
--desc : $desc
--in_vol : $in_vol
--in_lh : $in_lh
--in_rh : $in_rh
--interp : $interp
--out_type : $out_type
--out_den : $out_den
--out_res : $out_res"
# use combination of three parameters to determine the form of the transformation
if [[ "$in_type" == "volume" ]] && [[ "$in_space" == *bigbrain* ]] && [[ "$out_type" == "volume" ]] ; then
# bigbrain volume to icbm volume
bash $bbwDir/scripts/bigbrain_to_icbm.sh $in_vol $bb_space $interp $out_res $desc $wd
echo "employed nonlinear transformation from bigbrain to icbm"
elif [[ "$in_type" == "volume" ]] && [[ "$in_space" == *bigbrain* ]] && [[ "$out_type" == "surface" ]] ; then
# bigbrain volume to fsaverage
bash $bbwDir/scripts/bigbrainvol_to_fsaverage.sh $in_vol $bb_space $interp $out_space $out_den $desc $wd
echo "sampled data from midsurface and used multimodal surface matching to transform from bigbrain surface to ${out_space}"
elif [[ "$in_type" == "volume" ]] && [[ "icbm" == "$in_space" ]] && [[ "$out_type" == "volume" ]] ; then
# icbm volume to bigbrain volume
bash $bbwDir/scripts/icbm_to_bigbrain.sh $in_vol $bb_space $interp $out_res $desc $wd
echo "employed nonlinear transformation from icbm to bigbrain"
elif [[ "$in_type" == "volume" ]] && [[ "icbm" == "$in_space" ]] && [[ "$out_type" == "surface" ]] ; then
# icbm volume to bigbrain surface
bash $bbwDir/scripts/icbm_to_bigbrainsurf.sh $in_vol $interp $desc $wd
echo "employed nonlinear transformation from icbm to bigbrainsym then sampled the values along the midsurface"
elif [[ "$in_type" == "surface" ]] && [[ "$in_space" == *bigbrain* ]] && [[ "$out_type" == "volume" ]] ; then
# bigbrain surface to icbm volume
bash $bbwDir/scripts/bigbrainsurf_to_icbm.sh $in_lh $in_rh $interp $out_res $desc $wd
echo "projected data to bigbrainsym volume then employed nonlinear transformation to icbm"
elif [[ "$in_type" == "surface" ]] && [[ "$in_space" == *bigbrain* ]] && [[ "$out_type" == "surface" ]] ; then
# bigbrain surface to fsaverage
bash $bbwDir/scripts/bigbrain_to_fsaverage.sh $in_lh $in_rh $interp $out_space $out_den $desc $wd
echo "employed multimodal surface matching transformation from bigbrain surface to $out_space"
elif [[ "$in_type" == "surface" ]] && [[ "$in_space" == *fs* ]] && [[ "$out_type" == "volume" ]] ; then
# fsaverage to bigbrain volume
bash $bbwDir/scripts/fsaverage_to_bigbrainvol.sh $in_lh $in_rh $in_space $interp $bb_space $out_res $desc $wd
echo "employed multimodal surface matching transformation from fsaverage to bigbrain surface then filled the cortical ribbon"
elif [[ "$in_type" == "surface" ]] && [[ "$in_space" == *fs* ]] && [[ "$out_type" == "surface" ]] ; then
# fsaverage to bigbrain surface
bash $bbwDir/scripts/fsaverage_to_bigbrain.sh $in_lh $in_rh $in_space $interp $desc $wd
echo "employed multimodal surface matching transformation from fsaverage to bigbrain surface"
else
echo "error: cannot match combination of ${in_space} ${in_type} to ${out_type} to a transformation strategy"
fi