forked from pnlbwh/TBSS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·282 lines (220 loc) · 6.67 KB
/
install.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
#!/usr/bin/env bash
# ===============================================================================
# tbss (2019) pipeline is written by-
#
# TASHRIF BILLAH
# Brigham and Women's Hospital/Harvard Medical School
#
# ===============================================================================
# See details at https://github.com/pnlbwh/tbss
# Submit issues at https://github.com/pnlbwh/tbss/issues
# View LICENSE at https://github.com/pnlbwh/tbss/blob/master/LICENSE
# ===============================================================================
# ================================
SCRIPT=$(readlink -m $(type -p $0))
SCRIPTDIR=$(dirname $SCRIPT)
dataDir=$SCRIPTDIR/data
enigmaDir=$SCRIPTDIR/data/enigmaDTI
testDir=$SCRIPTDIR/lib/tests/
testDataDir=$SCRIPTDIR/lib/tests/data
libDir=$SCRIPTDIR/lib
install()
{
# ================================
echo Checking python version
read -r _ v <<< $(python --version 2>&1)
if [ ${v//.} -gt "300" ]
then
echo "python>=3 found"
else
echo "Installation requires python>=3"
exit 1
fi
# ================================
echo Checking FSL environment
if [ ! -z $FSLDIR ]
then
echo "FSLDIR is set"
else
echo "FSL environment is not set, may be you want to do the following: "
echo "export FSLDIR=~/fsl && source ~/fsl/etc/fslconf/fsl.sh && export PATH=\$PATH:~/fsl/bin"
exit 1
fi
# ================================
echo Checking ANTSPATH
if [ -z $ANTSPATH ]
then
echo "ANTSPATH is not set and/or ANTs commands are not available in PATH"
echo "May be you forgot to do: "
echo "export ANTSPATH=/path/to/ANTs/scripts && export PATH=\$PATH:/path/to/ANTs/executables"
exit 1
else
echo "ANTSPATH is set"
fi
# ================================
echo Downloading enigma data
if [ ! -f $dataDir/enigmaDTI.zip ]
then
wget http://enigma.ini.usc.edu/wp-content/uploads/2013/02/enigmaDTI.zip -P $dataDir
else
echo $dataDir/enigmaDTI.zip exists, unzipping enigmaDTI.zip
fi
unzip -o -d $enigmaDir $dataDir/enigmaDTI.zip
cp $dataDir/ENIGMA_look_up_table.txt.bak $enigmaDir/ENIGMA_look_up_table.txt
# ================================
echo Installing python libraries
pip install -r $SCRIPTDIR/requirements.txt --upgrade --no-cache-dir
}
test_pipeline()
{
# ================================
# pipeline tests
echo "Preparing to run TBSS pipeline tests ...
FA,MD,AD,RD modality TBSS are run on four dwi/mask pairs
Running multi-modality TBSS pipeline tests should take less than an hour"
if [ ! -d $testDataDir ]
then
mkdir $testDataDir
fi
pushd .
echo Fetching test data ...
cd $testDataDir
if [ ! -d dcm_qa_uih ]
then
git clone https://github.com/neurolabusc/dcm_qa_uih.git
fi
pushd .
cd dcm_qa_uih/Ref
IMAGELIST=$testDataDir/imagelist.txt
CASELIST=$testDataDir/caselist.txt
if [ -f $IMAGELIST ]
then
rm $IMAGELIST
fi
touch $IMAGELIST
if [ -f $CASELIST ]
then
rm $CASELIST
fi
touch $CASELIST
echo Generating brain mask for test data ...
for i in `ls *.nii`
do
IFS=., read -r prefix _ _ <<< $i
if [ -f $prefix.bval ] && [ -f $prefix.bvec ]
then
$libDir/dwiMask.py -i $i -o $prefix
echo `pwd`/$i,`pwd`/${prefix}_mask.nii.gz >> $IMAGELIST
echo $prefix >> $CASELIST
fi
done
popd
# --enigma branch ==========================================
echo Testing --enigma branch ...
$libDir/tbss_all -i $IMAGELIST --generate \
-c $CASELIST \
--modality FA,MD,AD,RD --enigma \
--avg -o $testDir/enigmaTemplateOutput/ \
--ncpu -1 --force && echo --enigma branch execution successful \
|| echo --enigma branch execution FAILED
# read
# pushd .
# cd $SCRIPTDIR
# python -m unittest -v $testDir/"test_enigma.py"
# popd
# --fmrib branch ===========================================
echo Testing --fmrib branch ...
pushd .
cd $testDir/enigmaTemplateOutput/
$libDir/tbss_all -i FA/origdata,MD/origdata,AD/origdata,RD/origdata \
--modality FA,MD,AD,RD --fmrib \
-l $FSLDIR/data/atlases/JHU/JHU-ICBM-labels-1mm.nii.gz \
--avg -o $testDir/fmribTemplateOutput/ \
--ncpu -1 --force && echo --fmrib branch execution successful \
|| echo --fmrib branch execution FAILED
popd
# read
# pushd .
# cd $SCRIPTDIR
# python -m unittest -v $testDir/"test_fmrib.py"
# popd
# env variable for reproducing template
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1
# --studyTemplate branch ==================================
echo Testing --studyTemplate branch ...
pushd .
cd $testDir/enigmaTemplateOutput/
$libDir/tbss_all -i FA/origdata,MD/origdata,AD/origdata,RD/origdata \
-c $CASELIST \
--modality FA,MD,AD,RD --studyTemplate \
-s $FSLDIR/data/standard/FMRIB58_FA_1mm.nii.gz \
-l $FSLDIR/data/atlases/JHU/JHU-ICBM-labels-1mm.nii.gz \
--avg -o $testDir/studyTemplateOutput/ \
--ncpu -1 --force && echo --studyTemplate branch execution successful \
|| echo --studyTemplate branch execution FAILED
popd
# read
# pushd .
# cd $SCRIPTDIR
# python -m unittest -v $testDir/"test_study.py"
# popd
# partial testing =========================================
echo Testing partial --enigma branch ...
pushd .
cd $testDir/enigmaTemplateOutput
$libDir/tbss_all -i MD/origdata,RD/origdata \
-c $CASELIST \
--xfrmDir $testDir/enigmaTemplateOutput/transform \
--modality MD,RD --enigma \
--avg -o $testDir/enigmaTemplateOutput/ \
--ncpu -1 && echo Partial --enigma branch execution successful \
|| echo Partial --enigma branch execution FAILED
popd
echo Testing partial --studyTemplate branch ...
pushd .
cd $testDir/enigmaTemplateOutput/
$libDir/tbss_all -i AD/origdata,RD/origdata \
-c $CASELIST \
--xfrmDir $testDir/studyTemplateOutput/template \
--modality AD,RD \
--template $testDir/studyTemplateOutput/template/template0.nii.gz \
--templateMask $testDir/studyTemplateOutput/stats/mean_FA_mask.nii.gz \
--skeleton $testDir/studyTemplateOutput/stats/mean_FA_skeleton.nii.gz \
--skeletonMask $testDir/studyTemplateOutput/stats/mean_FA_skeleton_mask.nii.gz \
--skeletonMaskDst $testDir/studyTemplateOutput/stats/mean_FA_skeleton_mask_dst.nii.gz \
-s $FSLDIR/data/standard/FMRIB58_FA_1mm.nii.gz \
-l $FSLDIR/data/atlases/JHU/JHU-ICBM-labels-1mm.nii.gz \
--avg -o $testDir/studyTemplateOutput2/ \
--ncpu -1 && echo Partial --studyTemplate branch execution successful \
|| echo Partial --studyTemplate branch execution FAILED
popd
# run all unittests together ==============================
pushd .
cd $SCRIPTDIR
pytest -v $testDir/test_*
popd
echo Testing complete.
}
# main function ===========================================
if [ -z $1 ]
then
echo """Example usage:
./install.sh setup test
./install.sh setup
./install.sh test"""
exit 1
fi
for subcmd in $@
do
if [ $subcmd == "setup" ]
then
install
elif [ $subcmd == "test" ]
then
test_pipeline
else
echo Undefined argument $subcmd
exit 1
fi
done