-
Notifications
You must be signed in to change notification settings - Fork 1
/
spm12Batch_Global
executable file
·370 lines (299 loc) · 9.64 KB
/
spm12Batch_Global
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#
# Copyright Robert C. Welsh, Ann Arbor MI 2005-2016
# Salt Lake City, UT, 2016-2021
#
# No warranty or guarantee made. USE AT OWN RISK.
#
# To make this work at your site you need to change the
# definition of "topDIR" below. Point to the parent directory
# of the spm12 and spm12Batch directories. In our local installation
# the directories "spm12" and "spm12Batch" and "spm12_patch"
# live side-by-side under the same parent. If you wish something different
# than that then you will need "bash" knowledge greater than novice.
#
#
# Things that you need to change to make it work locally (search for these below):
#
# topDIR
# LOCALOWNER
# MATLAB
# TemplateImageFile (we have our own)
# MAILRECPT
#
#
# ** INSTALLATION VARIABLE TO CHECK
#
# SPM12B1 -- points to your local SPM12 installation directory
# SPM12B2 -- automatically defined
# SPM12B3 -- automatically defined
#
# SANDBOXTOP -- top directory of the sandbox directory
#
# SANDBOXUSE -- string that is passed to a grep command to determine
# if a sandbox should be used. See the Documentation/
# about why a sandbox is used.
#
# MATLAB -- where MATLAB is found. If in your path it will be okay, but for
# Mac OS X it is looking in the Applications/ folder, so make sure
# it points to the correct. It will point to the actual binary
# image and not just the ".app" folder.
#
# LOGSPM12BATCHUSAGE --
# Set to something other than 1 for logging of usage. The usage
# goes into spm12Batch/Usage. All users must have write access
# to that sub-folder.
#
# ** End of Job Email
#
# If you system has postfix enabled for sending out email, you can configure the system
# to send emails to the user when the job has finished. In the past I have been
# successful with also sending text messages to phones.
#
# ** Other software needed
#
# YOU NEED TO MAKE SURE TO HAVE FSL, ANTs, ANIMA, AFNI installed and in your path
#
# ** Installation check
#
# Run the command spm12Batch_CheckInstall which will look for executables.
#
# ** Daisy Chain -- experts
#
# Using standard error exit codes as shown in
# https://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD%204.3-RELEASE&format=html
#
# 78 = misconfiguration
# 77 = no permission
# 74 = I/O error
# 69 = command not supported yet
# 66 = input file does not exist
# 65 = input data was incorrect
# 64 = command issued incorrectly
#
# -----------------------------------------------------------------------------
# Added some proper error returns when failing due to error.
COPYRIGHTENDYEAR=`date +%Y`
COPYRIGHT="Copyright Robert C. Welsh, 2005-${COPYRIGHTENDYEAR}, Version"
# There can be a recursive call accidentally, so don't allow.
if [ -z "${SPM12BATCHGLOBAL_CALLED}" ]
then
echo
echo Initializing spm12 Batch
echo
# Are we logging usage? Set to something other than 1 to not log.
# The logs do into the spm12Batch/Usage directory
LOGSPM12BATCHUSAGE=1
# Bring in out function to determine whether something
# is a number or not.
. ${thisDir}/isnumber.sh
#
# SOME GLOBAL THINGS TO CHANGE ACCORDING TO SITE
#
# Since the path is set to this command, then
# the code will use the following to define
# some internal variables needed.
curdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
topDIR="$( cd $curdir/.. && pwd )"
# ----------VERY CRUCIAL TO DEFINE THESE CORRECTLY
# You must point to SPM12 !!!
SPM12B1=/Users/rcwelsh/Software/SPM12/spm12_r7771
# Are we running on mnemosyne?
if [ -d /erato ]
then
SPM12B1=/erato/mnemosyne/Software/SPM/spm12_r7771
fi
# This is Robert Welsh's UNIX batch interface to spm12
SPM12B2=${topDIR}/spm12Batch
# This must point to the place where the SPM12 patch is locally.
SPM12B3=${SPM12B2}/matlabScripts
AUXPATH=${SPM12B2}/spm12_patch
#
# If the sandbox is populated then we copy files to local disk for processing
# and then copy back after completion. This will increase performance
# of processing of warpfMRI and smoothfMRI
#
SANDBOXHOST=`echo $HOSTNAME | awk -F. '{print $1}' | awk -F- '{print $1}'`
HOSTTYPE=`uname`
if [ "${HOSTTYPE}" == "Darwin" ]
then
SANDBOXTOP=${HOME}/sandbox
else
SANDBOXTOP=/home/sandbox
fi
SANDBOX=${SANDBOXTOP}/${SANDBOXHOST}/sandbox/
# list the devices that require the use of the sandbox
SANDBOXUSE="-e erato"
#
# You should put in the user id of the person
# that locally manages this software.
#
LOCALOWNER=rcwelsh
#
# Mail job will be sent to your user name at the institutionname
# Please set the instituion email server name here.
MAILRECPT=utah.edu
#
# Default email address to send messages to, on the linux machines
# use the currently logged in user as the name, on machines with a common
# analysis login you will need to set to a unique person.
#
DEFAULTUSER=${USER}
#
#****
# Where to find the template image to normalize to.
# This is site DEPENDENT!!!!
TemplateImageDir=${SPM12B1}/toolbox/OldNorm
TemplateImageFile=T1.nii
TemplateImage=${TemplateImageDir}/${TemplateImageFile}
# And finally, you need to point to matlab
OSTYPE=`uname`
if [ "${OSTYPE}" == "Darwin" ]
then
# Use the latest MATLAB we can find, but this should be static for stability.
MATLAB=/Applications/MATLAB_R2020b.app/bin/matlab # added 2020-03-12
else
MATLAB=`which matlab`
if [ -d /erato ]
then
MATLAB=/home/Software/MATLAB/R2020b/bin/matlab
fi
fi
#
# Only allow author to execute code during switch.
# If the current user is the localowner then they may
# execute the software.
if [ -e "${thisDir}/.${LOCALOWNER}.Only" ]
then
if [ ! "${USER}" == "${LOCALOWNER}" ]
then
echo
echo " Currently disabled during switch to new version."
echo
# return the error code of EX_NOPERM
SPM12BATCH_ERROR_CODE=77
. ${thisDir}/auxiliary/exit_w_removal
else
echo
echo " AUTHORIZED USER."
echo
fi
fi
# Done with author check
# Now check the critical components are here.
for CRITICALCOMPONENT in $topDIR $SPM12B1 $SPM12B2 $SPM12B3
do
if [ ! -z "${CRITICALCOMPONENT}" ]
then
if [ ! -d ${CRITICALCOMPONENT} ]
then
echo
echo " FATAL ERROR - CHECK THE INSTALL"
echo
echo " The directory :"
echo
echo " ${CRITICALCOMPONENT}"
echo
echo " does not exist."
# error EX_CONFIG
SPM12BATCH_ERROR_CODE=78
. ${thisDir}/auxiliary/exit_w_removal
fi
fi
done
# Make sure we have access to matlab
if [ ! -e "${MATLAB}" ]
then
echo
echo " FATAL ERROR - CHECK THE INSTALL"
echo
echo " I can not find matlab: "
echo
echo " $MATLAB"
echo
# EX_CONFIG error
SPM12BATCH_ERROR_CODE=78
. ${thisDir}/auxiliary/exit_w_removal
fi
# Now fix on whether we are on 64bit machine or 32bit machine
# Not sure if we need this, we really should be using
# the 64 bit version.
ARCH=`uname -m`
#if [ "${ARCH}" == "x86_64" ]
#then
# MATLAB="linux32 ${MATLAB}"
#fi
# Well, if we got this far then software seems to be installed
# ok.
# Now start building the automatic scripts. Some of these variables are from the parent shell script that
# has sourced this code block.
# We can build the names for the scripts right here.
# Put in a little more protection for the
# naming of the script files. On linux we can request
# the nanosecond timing and then take the first two (most significan digits)
# On MAC OS X we just have to suck it up and hope there are no
# clashes of file names. In general it shoudl not happen as
# the script builing has a forced delay of 1 second in it.
# For MAC OS X we just throw a 3-digit random number on it.
if [ "${OSTYPE}" == "Darwin" ]
then
theDate=`date +%y%m%d_%H_%M_%S`
# Need to seed with process ID, else we get the same number
RANDOM=$$
THERANDOM=$RANDOM
theRandom=`echo $THERANDOM | awk '{printf "%05d",$1}'`
theDate=${theDate}_${theRandom:0:3}
theYearMonth=`date +%Y_%m`
else
# On LINUX we can get the nano-second clock as well.
theDate=`date +%y%m%d_%H_%M_%S_%N`
theDate=${theDate:0:19}
theYearMonth=`date +%Y_%m`
fi
HOSTCOMPUTER=`echo $HOSTNAME | awk -F. '{print $1}' | sed 's/-/_/g'`
# grab part of host name.
if (( ${#HOSTCOMPUTER} > 8 ))
then
HOSTCOMPUTER=${HOSTCOMPUTER:0:8}
fi
SCRIPTNAME=${thisCommand}_${theDate}_${USER}_${HOSTCOMPUTER}
MATLABDIR=matlabScripts/spm12Batch/${thisCommand}/${theYearMonth}
UMBatchMaster=`pwd`
FULLSCRIPTNAME=${UMBatchMaster}/${MATLABDIR}/${SCRIPTNAME}
GENERICRUNDIR=run_
fi
SPM12BATCHGLOBAL_CALLED=YES
# # # # # # # # # # # # #
#
# Function Definitions
#
# # # # # # # # # # # # #
# define out debug output function
# to use debugout then do 'debugout "string" D'
function debugout()
{
if ! [ -z "$1" ]
then
if ! [ -z "$2" ]
then
if [ $2 == "D" ] || [ $2 == 'd' ]
then
echo $1
fi
fi
fi
}
# A function to return NIFTI file information to the screen.
function NIFTIINFO()
{
printf " ${2} ${1} \t\t:"
for DIM in dim1 dim2 dim3
do
INFO=`fslinfo ${1} | grep -v pix | grep ${DIM} | awk '{print $2}'`
echo -n "${INFO} x "
done
INFO=`fslinfo ${1} | grep -v pix | grep dim4 | awk '{print $2}'`
echo "${INFO}"
}
#
# Globals all done.
#