-
Notifications
You must be signed in to change notification settings - Fork 1
/
warpSeg
executable file
·183 lines (126 loc) · 4.47 KB
/
warpSeg
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
#!/bin/bash
# # # # # # # # # # # # # # # # # #
#
# A command to make it easier on the user to warp the
# fmri time-series to the standard template using
# the warping calculation from newSeg
#
# This command will build a script to run and will also
# run the script in background.
#
# e.g. warpfMRI
#
#
# Robert C. Welsh
# Copyright 2005-2017
#
# warpSeg
#
# # # # # # # # # # # # # # # # # #
#
# Main warpSeg function.
#
VERSION="1.0"
VERSIONDATE="2017-02-16"
# Find out where the current command lives and execute some common code.
theFullCommand="$0 $*"
execDIR=`pwd`
# Find out where the current command lives and execute some common code.
theCommand=`which $0`
thisDir=`dirname $theCommand`
thisCommand=`echo $theCommand | awk -F/ '{print $NF}'`
allowedOptions=" B D d f h l M on t U v w z "
# This piece of code all of the spm12Batch scripts will use
. ${thisDir}/auxiliary/commonCode_AllScriptsStart
# This is the common in-line code for the warping steps.
. ${thisDir}/auxiliary/commonCode_WarpSeg_01
# This is common in-line code for all spm12Batch script to make sure arguments were passed
. ${thisDir}/auxiliary/commonCode_checkIfArgsPassed
#
# The actual function.
#
. ${thisDir}/auxiliary/parse_arguments
#
. ${thisDir}/auxiliary/superDebugStatus
# Make the sandbox if possible.
. ${thisDir}/auxiliary/make_sandbox
#
# Ok - let's start displaying things back to the terminal
#
. ${thisDir}/auxiliary/shellScriptInfo
#
# Prepare to write the script.
#
# Makes sure they speficied some subjects.
. ${thisDir}/auxiliary/checkInputForSubjects
# Write out debug status
. ${thisDir}/auxiliary/debugStatus
# Ok, lets do the business.
# Print out the list of subjects that we operate upon.
. ${thisDir}/auxiliary/printSubjectsList
# Now start building the automatic scripts.
#
# the following environmental variables are from spm12Batch_Global
#
# HOSTCOMPUTER - name of the computer.
# SCRIPTNAME - name of the scripts to write.
# MATLABDIR - location of the scripts.
# UMBatchMatcher - present working directory.
# FULLSCRIPTNAME - full path and name of scripts to write.
#
. ${thisDir}/auxiliary/warpSegPart_01
# Name of the functional volumes to find.
echo "UMVolumeWild = '${volumeWILD}';" >> ${FULLSCRIPTNAME}.m
# Now build the list of directories for each subject.
. ${thisDir}/auxiliary/createDirectoryList
echo " UMHighRes = {..." >> ${FULLSCRIPTNAME}.m
for (( is=1 ; is<=$nSubjects ; is++ ))
do
#
# Make sure that now the HIRES exists.
#
TARGETNAME=${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${fmriPATH}/${coregPATH}/${HIRESNAME}
TARGETEXT=${overlayExt}
. ${thisDir}/auxiliary/verifyTargetImage
debugout "HiRes name is : ${TARGETIMG}" $SuperDebugFLAG
debugout "HiRes name is : ${HIRESNAME}" $SuperDebugFLAG
debugout "- - - - - - - - - - - - - - - -" $SuperDebugFLAG
# Check for the warping matrix (_sn.mat) or the deformation field (y_r).
WARP_FILE=${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${fmriPATH}/${coregPATH}/y_r${HIRESNAME}.nii
WARP_FILEALT=${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${fmriPATH}/${coregPATH}/y_${HIRESNAME}.nii
if [ ! -e "${WARP_FILE}" ]
then
if [ ! -e "${WARP_FILEALT}" ]
then
echo
echo "MISSING warping instuctions ${WARP_FILE} for ${subjects[$is]}"
echo
#
# remove the sandbox if we made one.
#
${thisDir}/auxiliary/remove_sandbox ${SANDBOXYES} ${SANDBOXPID}
. ${thisDir}/auxiliary/exit_w_removal
else
WARP_FILE=${WARP_FILEALT}
fi
fi
echo "'${TARGETIMG}';..." >> ${FULLSCRIPTNAME}.m
done
echo " };" >> ${FULLSCRIPTNAME}.m
echo " 4) finalizing matlab scripts"
cat ${thisDir}/parts/warp_seg_part_2.m >> ${FULLSCRIPTNAME}.m
echo " 5) building shell script"
# Now build the shell script command that will get launched into the background.
# Common start to all shell scripts
. ${thisDir}/auxiliary/shellScriptStart
# Now create verify that the sandbox is there.
. ${thisDir}/auxiliary/shellScriptCreateSandBox
# Add the matlab code to the shell script
. ${thisDir}/auxiliary/shellScriptMATLABCall
# Finalize the shell script.
. ${thisDir}/auxiliary/shellScriptFinalize
# Now launch into the background if desired.
. ${thisDir}/auxiliary/shellScriptLaunch
#
# all done.
#