-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdistortionCorrect
executable file
·201 lines (145 loc) · 4.66 KB
/
distortionCorrect
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
#!/bin/bash
# # # # # # # # # # # # # # # # # #
#
# This code will use anima to do distortion
# correction of data.
#
# This code prefers to have a target directory that will
# be where derivatsive data live to keep separated
# from the orignal Subjects/ directory
#
#
# Robert C. Welsh
# Copyright 2005-2021
#
# distortionCorrection
#
# This will correct all data associated with a give task
# assuming there is a fieldMap directory in that task.
#
# Expected is:
#
# [task]/
# fieldMap/
# forward.nii
# backward.nii
# run_01/
# run_01.nii
# run_02/
# run_02.nii
#
# This script utilized anima for the correction
#
# # # # # # # # # # # # # # # # # #
#
# Main distortionCorrect function.
#
VERSION="1.0"
VERSIONDATE="2021-03-14"
# 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 bi f fg fi fm M MO on t U v "
# This piece of code all of the spm12Batch scripts will use
. ${thisDir}/auxiliary/commonCode_AllScriptsStart
# This is the common in-line code for the distort
. ${thisDir}/auxiliary/commonCode_Distort_01
# This is common in-line code for all spm12Batch script to make sure arguments were passed
. ${thisDir}/auxiliary/commonCode_checkIfArgsPassed
# This is common code for distortion_correctionn
#. ${thisDir}/auxiliary/commonCode_Distort_02
#
# The actual function.
#
. ${thisDir}/auxiliary/parse_arguments
# Small trick to remove trailing / as needed. and remove any double-/
SUBJDIR=`dirname ${SUBJDIR}/nonsense.txt| sed -e 's/\/\//\//g'`
SUBJDIROUT=`dirname ${SUBJDIROUT}/nonsense.txt| sed -e 's/\/\//\//g'`
#
. ${thisDir}/auxiliary/superDebugStatus
#
# Ok - let's start displaying things back to the terminal
#
. ${thisDir}/auxiliary/shellScriptInfo
#
# Prepare to write the script.
#
# Makes sure they specified 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.
# UMBatchMatcher - present working directory.
# FULLSCRIPTNAME - full path and name of scripts to write.
#
# Check that all data is there to proceed.
# Now build the list of directories for each subject.
declare -i is
declare -i ii
curDIR=`pwd`
# Prepare the directory where the work is to take place.
echo " 4) checking images before building command"
echo
BAD_DATA=0
BAD_SESSIONS=
for (( is=1 ; is<=$nSubjects ; is++ ))
do
if [ -d ${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/ ]
then
cd ${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/
# Look for the field map images.
OK_FORWARD=`ls ${fmriPATH}/${fieldMapPath}/${forwardImage} 2> /dev/null | wc -l | awk '{print $1}'`
OK_BACKWARD=`ls ${fmriPATH}/${fieldMapPath}/${backwardImage} 2> /dev/null | wc -l | awk '{print $1}'`
# Look for how many run images
NRUNS=`ls ${fmriPATH}/run*/${volumeWILD}*.nii 2> /dev/null | wc -l | awk '{print $1}'`
if [ ${NRUNS} -eq 0 ] || [ ${OK_FORWARD} -ne 1 ] || [ ${OK_BACKWARD} -ne 1 ]
then
BAD_DATA=1
BAD_SESSION="${subjects[$is]} ${BAD_SESSIONS}"
echo " Bad condition for ${subjects[$is]} runs(${NRUNS}) forward(${OK_FORWARD}) backward(${OK_BACKWARD}) "
else
echo " Good condition for ${subjects[$is]}"
fi
fi
done
cd ${curDIR}
if [ ${BAD_DATA} -ne 0 ]
then
echo
echo Found issues with the data .. prefering not to run.
echo
exit 1
fi
echo
. ${thisDir}/auxiliary/distortCorrect_part_01
# Common start to all shell scripts
. ${thisDir}/auxiliary/buildMatlabScripts_01
. ${thisDir}/auxiliary/shellScriptStart
#. ${thisDir}/auxiliary/distortCorrectScript
echo " 5) building shell script"
echo
# Now put in some varibles needed
. ${thisDir}/auxiliary/distortCorrect_part_02
. ${thisDir}/auxiliary/startBashSubjectLoop
# Add the distortion code to the shell script
cat ${thisDir}/auxiliary/distortCorrect_part_03 >> ${FULLSCRIPTNAME}.sh
. ${thisDir}/auxiliary/endBashSubjectLoop
# Finalize the shell script.
. ${thisDir}/auxiliary/shellScriptFinalize
# Now launch into the background if desired.
. ${thisDir}/auxiliary/shellScriptLaunch
#
# all done.
#