-
Notifications
You must be signed in to change notification settings - Fork 7
/
pipeline_test.sh
executable file
·290 lines (205 loc) · 7.32 KB
/
pipeline_test.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
#!/usr/bin/bash
usage () {
echo -e "
Convenient script for testing luigi-pnlpipe, pnlNipype,
CNN-Diffusion-MRIBrain-Segmentation, and pnlpipe_software
Usage:
./pipeline_test.sh [--no-remove] [--hack-fs] [--pytest-only] [--console-print]
[--to RECIPIENTS]
The default branches are the ones at https://github.com/pnlbwh/luigi-pnlpipe
and https://github.com/pnlbwh/pnlNipype. All test logs are exported to
https://github.com/pnlbwh/pnlpipe-nightly-tests.
TBD: Specify email recipients of the domain @bwh.harvard.edu within double quotes e.g.
--to \"sbouix tbillah kcho\"
"
exit 0
}
OPTS=`getopt -l help,no-remove,hack-fs,pytest-only,console-print,to: -o h,n,f,p,c,t: -- "$@"`
eval set -- "$OPTS"
while true
do
case $1 in
-h|--help)
usage;;
--no-remove)
noremove=1;
shift 1;;
--hack-fs)
hackfs=1;
shift 1;;
--pytest-only)
pytest_only=1;
shift 1;;
--console-print)
console_print=1;
shift 1;;
--to)
to=$2;
shift 2;;
--)
shift;
break;;
# FIXME does not fail on illegal options
*)
echo One or more of the args could not be recognized
echo See ./pipeline_test.sh --help
exit 1
esac
done
cd /home/pnlbwh
# do not remove any previous output
remove=1
if [[ ! -z $noremove ]]
then
echo Not removing any previous output
remove=0
fi
# download test data
test_data=luigi-pnlpipe-test-data.tar.gz
if [ ! -f $test_data ]
then
wget https://www.dropbox.com/s/pzloevkr8h3kyac/$test_data
fi
if [ ! -d CTE/rawdata ] || [ ! -d HCP/rawdata ]
then
tar -xzvf $test_data
# download and shorten T2w test data
if [ ! -d trainingDataT2Masks ]
then
git clone https://github.com/pnlbwh/trainingDataT2Masks.git
pushd .
cd trainingDataT2Masks
./mktrainingcsv.sh .
head -n 5 trainingDataT2Masks-hdr.csv > trainingDataT2Masks-curt.csv
popd
fi
fi
# download ground truth data
pushd .
cd luigi-pnlpipe/tests/
test_data=luigi-pnlpipe-g-truth.tar.gz
if [ ! -f $test_data ]
then
wget https://www.dropbox.com/s/gi7kukud44bl6p2/$test_data
fi
if [ ! -d Reference ]
then
tar -xzvf $test_data
fi
popd
# hack recon-all
if [[ ! -z $hackfs ]]
then
struct_pipe=luigi-pnlpipe/workflows/struct_pipe.py
lineno=`awk '/fs-exec/{ print NR; exit }' $struct_pipe`s
sed -i "$lineno+cmd+'cp -a $HOME/CTE/rawdata/freesurfer $HOME/CTE/derivatives/pnlpipe/sub-1004/ses-01/anat/'+g" \
$struct_pipe
fi
export ANTS_RANDOM_SEED=123456
cd luigi-pnlpipe
# create test log directory
datestamp=$(date +"%Y-%m-%d")
log=pnlpipe-nightly-tests/logs-$datestamp
mkdir -p $log
if [[ -z $pytest_only ]]
then
### HCP ###
## dwi pipeline ##
export LUIGI_CONFIG_PATH=`pwd`/test_params/dwi_pipe_params.cfg
# test of EddyEpi (TopupEddy) and Ukf
# replace eddy_epi_task, acqp, index in dwi_pipe_params
sed -i "s/eddy_epi_task:\ EddyEpi/eddy_epi_task:\ topupeddy/g" test_params/dwi_pipe_params.cfg
sed -i "s/acqp.txt/acqp_ap_pa.txt/g" test_params/dwi_pipe_params.cfg
sed -i "s+/home/pnlbwh/luigi-pnlpipe/test_params/index.txt++g" test_params/dwi_pipe_params.cfg
workflows/ExecuteTask.py --task Ukf --bids-data-dir $HOME/HCP/rawdata -c 1042 -s 1 \
--dwi-template sub-*/ses-*/dwi/*acq-PA*_dwi.nii.gz,sub-*/ses-*/dwi/*acq-AP*_dwi.nii.gz \
--num-workers 2 \
> $log/TopupEddyUkf.txt 2>&1 &
### CTE ###
## structural pipeline ##
export LUIGI_CONFIG_PATH=`pwd`/test_params/struct_pipe_params.cfg
# test of StructMask
workflows/ExecuteTask.py --task StructMask --bids-data-dir $HOME/CTE/rawdata -c 1004 -s 01 \
--t2-template sub-*/ses-01/anat/*_T2w.nii.gz \
> $log/StructMask.txt 2>&1
# test of Freesurfer
workflows/ExecuteTask.py --task Freesurfer --bids-data-dir $HOME/CTE/rawdata -c 1004 -s 01 \
--t1-template sub-*/ses-01/anat/*_T1w.nii.gz --t2-template sub-*/ses-01/anat/*_T2w.nii.gz \
--num-workers 2 \
> $log/Freesurfer.txt 2>&1
## dwi pipeline ##
git checkout -- test_params/dwi_pipe_params.cfg
export LUIGI_CONFIG_PATH=`pwd`/test_params/dwi_pipe_params.cfg
# test of EddyEpi (FslEddy+PnlEpi)
workflows/ExecuteTask.py --task EddyEpi --bids-data-dir $HOME/CTE/rawdata -c 1004 -s 01 \
--dwi-template sub-*/ses-01/dwi/*_dwi.nii.gz --t2-template sub-*/ses-01/anat/*_AXT2.nii.gz \
> $log/FslEddyPnlEpi.txt 2>&1
# test of EddyEpi (PnlEddy+PnlEpi) and Ukf
# replace eddy_task in dwi_pipe_params
sed -i "s/eddy_task:\ FslEddy/eddy_task:\ PnlEddy/g" test_params/dwi_pipe_params.cfg
# delete *Ed_dwi.nii.gz, *EdEp_dwi.nii.gz, and *EdEp_bse.nii.gz
(( remove==1 )) && rm $HOME/CTE/derivatives/pnlpipe/sub-*/ses-*/dwi/*Ed*_dwi.nii.gz \
$HOME/CTE/derivatives/pnlpipe/sub-*/ses-*/dwi/*Ed*_bse.nii.gz
workflows/ExecuteTask.py --task Ukf --bids-data-dir $HOME/CTE/rawdata -c 1004 -s 01 \
--dwi-template sub-*/ses-01/dwi/*_dwi.nii.gz --t2-template sub-*/ses-01/anat/*_AXT2.nii.gz \
> $log/PnlEddyPnlEpiUkf.txt 2>&1
## fs2dwi pipeline ##
export LUIGI_CONFIG_PATH=`pwd`/test_params/fs2dwi_pipe_params.cfg
# test of Wmql
# delete *Xc_T2w.nii.gz
(( remove==1 )) && rm $HOME/CTE/derivatives/pnlpipe/sub-*/ses-*/anat/*Xc_T2w.nii.gz
workflows/ExecuteTask.py --task Wmql --bids-data-dir $HOME/CTE/rawdata -c 1004 -s 01 \
--dwi-template sub-*/ses-*/dwi/*EdEp_dwi.nii.gz --t2-template sub-*/ses-*/anat/*_T2w.nii.gz \
> $log/Wmql.txt 2>&1
# test of TractMeasures
workflows/ExecuteTask.py --task TractMeasures --bids-data-dir $HOME/CTE/rawdata -c 1004 -s 01 \
--dwi-template sub-*/ses-*/dwi/*EdEp_dwi.nii.gz --t2-template sub-*/ses-*/anat/*_T2w.nii.gz \
> $log/TractMeasures.txt 2>&1
fi
### equivalence tests ###
function equality_tests() {
# nifti
for i in `find . -name fs2dwi -prune -false -o -name *.nii.gz`
do
pytest -v -s test_luigi.py -k "test_header or test_data" --filename $i --outroot ~
done
# wmparc
for i in `find . -name wmparc*`; do pytest -v -s test_luigi.py -k test_wmparc --filename $i --outroot ~; done
# bvals and bvecs
for i in `find . -name *.bval`; do pytest -v -s test_luigi.py -k test_bvals --filename $i --outroot ~; done
for i in `find . -name *.bvec`; do pytest -v -s test_luigi.py -k test_bvecs --filename $i --outroot ~; done
# tracts
for i in `find . -name sub-1004*EdEp_bse.nii.gz`,`find . -name sub-1004*EdEp.vtk`
do
pytest -v -s test_luigi.py -k test_tracts --filename $i --outroot ~
done
# wmql tract measures
for i in `find . -name *.csv`; do pytest -v -s test_luigi.py -k test_wmql --filename $i --outroot ~; done
# json
for i in `find . -name *.json`; do pytest -v -s test_luigi.py -k test_json --filename $i --outroot ~; done
# html
for i in `find . -name *.html`; do pytest -v -s test_luigi.py -k test_html --filename $i --outroot ~; done
}
cd tests
if [[ ! -z $console_print ]]
then
equality_tests
else
pytest_log=../$log/pytest-${datestamp}.txt
{
equality_tests
} > $pytest_log 2>&1
# docker email is hard to set up
# # email only pytest log
# for u in $to
# do
# cat $pytest_log | mailx -s "luigi-pnlpipe test results" \
# -a $pytest_log -- [email protected]
# done
# instead export test logs to GitHub
# bind ~/.gitconfig, ~/.ssh, and ~/pnlpipe-nightly-tests to the container
cd ../$log
git add .
git commit -m "test logs of ${datestamp}"
git push origin master
fi