-
Notifications
You must be signed in to change notification settings - Fork 0
/
mni152reg.dartel
executable file
·299 lines (253 loc) · 6.86 KB
/
mni152reg.dartel
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
289
290
291
292
293
294
295
296
297
298
299
#!/bin/tcsh -f
# mni152reg.dartel - sources
if(-e $FREESURFER_HOME/sources.csh) then
source $FREESURFER_HOME/sources.csh
endif
set VERSION = '$Id$';
set scriptname = `basename $0`
set mniprepdir = /autofs/space/curv_001/users/mni152reg-prep2
set mni152_15mm = $mniprepdir/mni152.1.5mm.brain.nii.gz
set mni152_15mm_to_1mmcrop_reg = $mniprepdir/mni152.1.5mm-to-1mmcrop.lta
# note: targvol not needed because VBM gets it internally
set outdir = ();
set subject = ();
set invol = ()
set ForceUpdate = 0
set tmpdir = ();
set cleanup = 1;
set LF = ();
set inputargs = ($argv);
set PrintHelp = 0;
if($#argv == 0) goto usage_exit;
set n = `echo $argv | grep -e -help | wc -l`
if($n != 0) then
set PrintHelp = 1;
goto usage_exit;
endif
set n = `echo $argv | grep -e -version | wc -l`
if($n != 0) then
echo $VERSION
exit 0;
endif
goto parse_args;
parse_args_return:
goto check_params;
check_params_return:
set StartTime = `date`;
set tSecStart = `date '+%s'`;
set year = `date +%Y`
set month = `date +%m`
set day = `date +%d`
set hour = `date +%H`
set min = `date +%M`
if($#outdir) then
mkdir -p $outdir/log
set tmpdir = $outdir
set cleanup = 0
else
set outdir = `dirname $m3z`
mkdir -p $outdir
endif
pushd $outdir > /dev/null
set outdir = `pwd`;
popd > /dev/null
#if($#tmpdir == 0) then
# if(-dw /scratch) set tmpdir = /scratch/tmpdir.mni152reg.dartel.$$
# if(! -dw /scratch) set tmpdir = $outdir/tmpdir.mni152reg.dartel.$$
#endif
#mkdir -p $tmpdir
# Set up log file
if($#LF == 0) set LF = $outdir/log/mni152reg.dartel.Y$year.M$month.D$day.H$hour.M$min.log
if($LF != /dev/null) rm -f $LF
echo "Log file for mni152reg.dartel" >> $LF
date | tee -a $LF
echo "" | tee -a $LF
echo "setenv SUBJECTS_DIR $SUBJECTS_DIR" | tee -a $LF
echo "cd `pwd`" | tee -a $LF
echo $0 $inputargs | tee -a $LF
ls -l $0 | tee -a $LF
echo "" | tee -a $LF
cat $FREESURFER_HOME/build-stamp.txt | tee -a $LF
echo $VERSION | tee -a $LF
uname -a | tee -a $LF
echo "pid $$" | tee -a $LF
if($?PBS_JOBID) then
echo "pbsjob $PBS_JOBID" >> $LF
endif
if($?SLURM_JOB_ID) then
echo SLURM_JOB_ID $SLURM_JOB_ID >> $LF
endif
#========================================================
setenv OMP_NUM_THREADS 1 # Not sure this matters for spm
# Crop the input?
set warp = $outdir/y_rinput.nii
set ud = `UpdateNeeded $warp $invol`
if($ud || $ForceUpdate) then
date | tee -a $LF
set cmd = (run-vbm --i $invol --o $outdir)
echo "\n\n"| tee -a $LF
echo $cmd | tee -a $LF
fs_time $cmd |& tee -a $LF
if($status) goto error_exit
echo "\n\n"| tee -a $LF
endif
# Compute the warp the the 1.5mm mni152 space (native spm)
set warpm3z = $outdir/warp.1.5mm.m3z
set ud = `UpdateNeeded $warpm3z $warp`
if($ud || $ForceUpdate) then
date | tee -a $LF
set cmd = (mri_warp_convert --inspm $warp --insrcgeom $invol --outm3z $warpm3z)
echo "\n\n"| tee -a $LF
echo $cmd | tee -a $LF
fs_time $cmd |& tee -a $LF
if($status) goto error_exit
echo "\n\n"| tee -a $LF
endif
# Compute the warp the the cropped 1.0mm mni152 space
set warpm3z = $outdir/warp.1mm.m3z
set ud = `UpdateNeeded $warpm3z $warp`
if($ud || $ForceUpdate) then
date | tee -a $LF
set cmd = (mri_warp_convert --inspm $warp --insrcgeom $invol \
--lta2 $mni152_15mm_to_1mmcrop_reg --outm3z $warpm3z)
echo "\n\n"| tee -a $LF
echo $cmd | tee -a $LF
fs_time $cmd |& tee -a $LF
if($status) goto error_exit
echo "\n\n"| tee -a $LF
endif
#========================================================
# Cleanup
#if($cleanup) rm -rf $tmpdir
# Done
echo " " |& tee -a $LF
set tSecEnd = `date '+%s'`;
@ tSecRun = $tSecEnd - $tSecStart;
set tRunMin = `echo $tSecRun/60|bc -l`
set tRunMin = `printf %5.2f $tRunMin`
set tRunHours = `echo $tSecRun/3600|bc -l`
set tRunHours = `printf %5.2f $tRunHours`
echo "Started at $StartTime " |& tee -a $LF
echo "Ended at `date`" |& tee -a $LF
echo "Mni152reg.Dartel-Run-Time-Sec $tSecRun" |& tee -a $LF
echo "Mni152reg.Dartel-Run-Time-Min $tRunMin" |& tee -a $LF
echo "Mni152reg.Dartel-Run-Time-Hours $tRunHours" |& tee -a $LF
echo " " |& tee -a $LF
echo "mni152reg.dartel Done" |& tee -a $LF
exit 0
###############################################
############--------------##################
error_exit:
echo "ERROR:"
exit 1;
###############################################
############--------------##################
parse_args:
set cmdline = ($argv);
while( $#argv != 0 )
set flag = $argv[1]; shift;
switch($flag)
case "--i":
if($#argv < 1) goto arg1err;
set invol = $argv[1]; shift;
breaksw
case "--m3z":
if($#argv < 1) goto arg1err;
set m3z = $argv[1]; shift;
breaksw
case "--o":
if($#argv < 1) goto arg1err;
set outdir = $argv[1]; shift;
breaksw
case "--s":
if($#argv < 1) goto arg1err;
set subject = $argv[1]; shift;
breaksw
case "--sd":
if($#argv < 1) goto arg1err;
setenv SUBJECTS_DIR $argv[1]; shift;
breaksw
case "--force":
set ForceUpdate = 1
breaksw
case "--log":
if($#argv < 1) goto arg1err;
set LF = $argv[1]; shift;
breaksw
case "--nolog":
case "--no-log":
set LF = /dev/null
breaksw
case "--tmp":
case "--tmpdir":
if($#argv < 1) goto arg1err;
set tmpdir = $argv[1]; shift;
set cleanup = 0;
breaksw
case "--nocleanup":
set cleanup = 0;
breaksw
case "--cleanup":
set cleanup = 1;
breaksw
case "--debug":
set verbose = 1;
set echo = 1;
breaksw
default:
echo ERROR: Flag $flag unrecognized.
echo $cmdline
exit 1
breaksw
endsw
end
goto parse_args_return;
############--------------##################
############--------------##################
check_params:
if($#subject) then
set sd = $SUBJECTS_DIR/$subject
if(! -e $sd) then
echo "ERROR: cannot find $subject"
exit 1;
endif
if($#invol == 0) set invol = $sd/mri/norm.mgz
if($#outdir == 0) set outdir = $sd/mri/mni152reg.dartel
endif
endif
if($#invol == 0) then
echo "ERROR: must spec input volume"
exit 1
endif
foreach f ($invol)
if(! -e $f) then
echo "ERROR: cannot find $f"
exit 1
endif
end
goto check_params_return;
############--------------##################
############--------------##################
arg1err:
echo "ERROR: flag $flag requires one argument"
exit 1
############--------------##################
arg2err:
echo "ERROR: flag $flag requires two arguments"
exit 1
############--------------##################
############--------------##################
usage_exit:
echo ""
echo "mni152reg.dartel"
echo " --i invol"
echo " --o outdir"
echo " --tmp tmpdir"
echo " --s subject (invol=norm.mgz, outdir=mni152reg.dartel) "
echo ""
if(! $PrintHelp) exit 1;
echo $VERSION
cat $0 | awk 'BEGIN{prt=0}{if(prt) print $0; if($1 == "BEGINHELP") prt = 1 }'
exit 1;
#---- Everything below here is printed out as part of help -----#
BEGINHELP