-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUNNIFTI
279 lines (243 loc) · 5.57 KB
/
UNNIFTI
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
#!/bin/bash
# # # # # # # # # # # # # # # # # #
#
# A command to rummage about
# a subject and convert NIFTI files
# into ANALYZE
#
# Note, images that exist in "NIFTI" directory
# will be ignored.
#
#
# run_XX/
# ANALZE/
# apimg/
# aprvol_XXXX.img, hdr
# NIFIT/
# aprun_XX.nii
#
# will turn into
#
# run_XX/
# aprun_XX.nii
#
# And anatomy directory this is
#
# anatomy/
# NIFTI/
# ...
# ANALZE/
# ...
#
# will become
#
# anatomy/
#
# Robert C. Welsh
# Copyright 2007
#
#
#
# Modified to do flipping by default.
#
# # # # # # # # # # # # # # # # # #
#
# Main UNNIFTI function.
#
VERSION="2.0"
VERSIONDATE="2011-09-14"
# Find out where the current command lives and execute some common code.
theFullCommand="$0 $*"
execDIR=`pwd`
theCommand=`which $0`
thisDir=`dirname $theCommand`
# 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=" f M V "
# This piece of code all of the spm12Batch scripts will use
. ${thisDir}/auxiliary/commonCode_AllScriptsStart
# Validate that we have FSL installed.
. ${thisDir}/auxiliary/commonCode_FSL_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
#
# 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
# Get the name of this experiment.
expDIR=`pwd`
# Now start building the automatic scripts.
theDate=`date`
HOSTCOMPUTER=`echo $HOSTNAME | awk -F. '{print $1}'`
echo
echo " UNNIFTI. Version ${VERSION} ${VERSIONDATE}"
echo " Running on ${HOSTCOMPUTER} at ${theDate}"
echo " Will perform move NIFTI back to where they need to be for spm12 processing."
echo
echo " Verify Flag : ${verifyFLAG}"
echo " fMRI Path : ${fmriPATH}"
echo " Subjects in : ${SUBJDIR}"
# Print out the list of subjects that we operate upon.
. ${thisDir}/auxiliary/printSubjectsList
# Now do the work.
echo
echo " Starting...."
echo
for (( ii=1 ; ii<=$nSubjects ; ii++ ))
do
echo
echo " Processing subject : ${subjects[$ii]}"
echo
cd ${expDIR}/${SUBJDIR}/${subjects[$ii]}
echo " ANATOMY"
echo
if [ -e "anatomy" ]
then
cd anatomy
# just go ahead and move the ginx format files.
mkdir -p ginx/
mv e????s*i* ginx/ 2> /dev/null
NNII=`ls *.nii 2> /dev/null| wc | awk '{print $1}'`
if [ ${NNII} -gt 0 ]
then
echo
echo " Found nifti files in anatomy directory"
fi
if [ ! -d NIFTI ]
then
echo " No anatomy/NIFTI directory"
else
echo " Found anatomy/NIFTI"
cd NIFTI
NNII=`ls *.nii 2> /dev/null| wc | awk '{print $1}'`
if [ ${NNII} -gt 0 ]
then
echo
echo " Found nifti files in anatomy/NIFTI directory"
for FILE in `ls *.nii 2> /dev/null`
do
if [ -e ../$FILE ]
then
echo
echo "Potential conflict, found $FILE in anatomy/NIFTI and it also exists in anatomy"
echo
echo "ABORTING"
echo
exit 0
fi
done
if [ "${verifyFLAG}" -eq 0 ]
then
mv *.nii ../
else
echo
echo List of anatomy files to be moved :
for FILE in `ls *.nii 2> /dev/null`
do
echo " $FILE"
done
fi
else
echo
echo " NO NIFTI FILES IN ANATOMY DIRECTORY"
echo
fi
cd ../
fi
cd ..
else
echo
echo " * * * ANATOMY DIRECTORY IS MISSING * * * "
echo
fi
# Now the runs
#
# now do the functional directories
#
echo
echo " FUNCTIONALS"
echo
if [ -d "${fmriPATH}" ]
then
echo
echo " Working on time-series NIFTI files."
echo
cd ${fmriPATH}
nRUNS=`ls 2> /dev/null | wc | awk '{print $1}'`
if [ $nRUNS -gt 0 ]
then
for RUN in `ls -l | grep drw | grep run | awk '{print $9}'`
do
if [ -d ${RUN} ]
then
echo " Found run : ${RUN}"
cd ${RUN}
nRUNFILES=`ls *run*.nii 2> /dev/null | wc | awk '{print $1}'`
echo " has : $nRUNFILES NIFTI files"
if [ ! -d NIFTI ]
then
echo " but no NIFTI subdirectory"
else
cd NIFTI
nRUNFILES=`ls *run*.nii 2> /dev/null | wc | awk '{print $1}'`
echo " NIFTI/ : $nRUNFILES NIFTI files"
if [ "${nRUNFILES}" != "0" ]
then
for FILE in `ls *run*.nii 2> /dev/null`
do
if [ -e ../$FILE ]
then
echo
echo "Potential conflict, found $FILE in ${RUN}/NIFTI and it also exists in ${RUN}"
echo
echo "ABORTING"
echo
exit 0
fi
done
if [ "${verifyFLAG}" -eq 0 ]
then
mv *run*.nii ../
else
echo
echo " List of run files to be moved : "
for FILE in `ls *run*.nii 2> /dev/null`
do
echo " $FILE"
done
fi
fi
cd ../
fi
cd ../
fi
done
else
echo
echo " NO RUN FILES PRESENT."
echo
fi
cd ../
else
echo
echo " * * * FUNCTIONAL DIRECTORY IS MISSING * * * "
echo
fi
done
echo
echo " All done."
echo