88# c. 2=No Scrubbing, Motion Scrubbing in parallel
99# #################################################################################################################
1010
11- scriptPath=` perl -e ' use Cwd "abs_path";print abs_path(shift)' $0 `
12- scriptDir=` dirname $scriptPath `
11+ scriptPath=$( perl -e ' use Cwd "abs_path";print abs_path(shift)' " $0 " )
12+ scriptDir=$( dirname " $scriptPath " )
1313filename=run_motionscrub.m
1414
1515
@@ -24,44 +24,44 @@ function Usage {
2424
2525# ######### FSL's arg parsing functions ###################
2626get_opt1 () {
27- arg=$( echo $1 | sed ' s/=.*// ' )
28- echo $arg
27+ arg=${1 // = */ }
28+ echo " $arg "
2929}
3030
3131
3232get_imarg1 () {
33- arg=$( get_arg1 $1 ) ;
34- arg=$( $FSLDIR /bin/remove_ext $arg ) ;
35- echo $arg
33+ arg=$( get_arg1 " $1 " ) ;
34+ arg=$( " $FSLDIR " /bin/remove_ext " $arg " ) ;
35+ echo " $arg "
3636}
3737
3838get_arg1 () {
39- if [ X" ` echo $1 | grep ' =' ` " = X ] ; then
39+ if [ X" $( echo " $1 " | grep ' =' ) " = X ] ; then
4040 echo " Option $1 requires an argument" 1>&2
4141 exit 1
4242 else
43- arg=` echo $1 | sed ' s/. *=// ' `
44- if [ X$arg = X ] ; then
43+ arg=${1 // * =/ }
44+ if [ X" $arg " = X ] ; then
4545 echo " Option $1 requires an argument" 1>&2
4646 exit 1
4747 fi
48- echo $arg
48+ echo " $arg "
4949 fi
5050}
5151
5252
5353# Parse Command line arguments
5454if [ $# -lt 1 ] ; then Usage; exit 0; fi
5555while [ $# -ge 1 ] ; do
56- iarg=$( get_opt1 $1 ) ;
56+ iarg=$( get_opt1 " $1 " ) ;
5757 case " $iarg "
5858 in
5959 --epi)
60- epiData=` get_arg1 $1 ` ;
60+ epiData=$( get_arg1 " $1 " ) ;
6161 export epiData;
62- indir=$( dirname $epiData ) ;
62+ indir=$( dirname " $epiData " ) ;
6363 export indir;
64- rawEpiDir=$( dirname $( x=$indir ; while [ " $x " != " /" ] ; do x=` dirname " $x " ` ; find " $x " -maxdepth 1 -type f -name " mcImg.nii.gz" ; done 2> /dev/null) ) ;
64+ rawEpiDir=$( dirname " $( x=$indir ; while [ " $x " != " /" ] ; do x=$( dirname " $x " ) ; find " $x " -maxdepth 1 -type f -name " mcImg.nii.gz" ; done 2> /dev/null) " ) ;
6565 export rawEpiDir
6666 if [ " $epiData " == " " ]; then
6767 echo " Error: The restingStateImage (-E) is a required option"
8080
8181# #Echo out all input parameters into a log
8282logDir=$rawEpiDir
83- echo " $scriptPath " >> $logDir /rsParams_log
84- echo " ------------------------------------" >> $logDir /rsParams_log
85- echo " -E $epiData " >> $logDir /rsParams_log
86- echo " ` date` " >> $logDir /rsParams_log
87- echo " " >> $logDir /rsParams_log
88- echo " " >> $logDir /rsParams_log
83+ {
84+ echo " $scriptPath "
85+ echo " ------------------------------------"
86+ echo " -E $epiData "
87+ date
88+ echo " "
89+ echo " "
90+ } >> " $logDir " /rsParams_log
8991
90- cd $indir || exit
91- gunzip ${epiData}
92+ cd " $indir " || exit
93+ gunzip " ${epiData} "
9294
9395
9496echo " Running $0 ..."
9597
9698
9799
98- cd $rawEpiDir || exit
100+ cd " $rawEpiDir " || exit
99101
100102
101103# Extract image dimensions from the NIFTI File
102- numXdim=` fslinfo $epiData | grep ^dim1 | awk ' {print $2}' `
103- numYdim=` fslinfo $epiData | grep ^dim2 | awk ' {print $2}' `
104- numZdim=` fslinfo $epiData | grep ^dim3 | awk ' {print $2}' `
105- numtimepoint=` fslinfo $epiData | grep ^dim4 | awk ' {print $2}' `
104+ numXdim=$( fslinfo " $epiData " | grep ^dim1 | awk ' {print $2}' )
105+ numYdim=$( fslinfo " $epiData " | grep ^dim2 | awk ' {print $2}' )
106+ numZdim=$( fslinfo " $epiData " | grep ^dim3 | awk ' {print $2}' )
107+ numtimepoint=$( fslinfo " $epiData " | grep ^dim4 | awk ' {print $2}' )
106108
107109
108110
@@ -123,17 +125,17 @@ EOF
123125
124126
125127# Run script using Matlab or Octave
126- haveMatlab=` which matlab`
128+ haveMatlab=$( which matlab)
127129if [ " $haveMatlab " == " " ]; then
128- octave --no-window-system $rawEpiDir /$filename
130+ octave --no-window-system " $rawEpiDir /$filename "
129131else
130132 matlab -nodisplay -r " run $rawEpiDir /$filename "
131133fi
132134
133135# ################################
134136
135137
136- cd ${rawEpiDir} /motionScrub || exit
138+ cd " ${rawEpiDir} " /motionScrub || exit
137139# ### Process Summary ############
138140echo " ...Summarizing Results"
139141
@@ -144,34 +146,35 @@ fsl_tsplot -i fd.txt -t "FD (mm)" -w 800 -h 300 -u 1 --start=1 -o fd.png
144146fsl_tsplot -i dvars.txt -t " DVARS" -w 800 -h 300 -u 1 --start=1 -o dvars.png
145147# #Echo out the pertinent info for the motion-scrubbed/processed subjects
146148
147- numvols=` fslinfo ${epiData} | grep ^dim4 | awk ' {print $2}' `
149+ numvols=$( fslinfo " ${epiData} " | grep ^dim4 | awk ' {print $2}' )
148150
149- delvols=` cat deleted_vols.txt | wc | awk ' {print $2}' `
151+ delvols=$( wc < deleted_vols.txt | awk ' {print $2}' )
150152
151- propdel=` echo ${numvols} ${delvols} | awk ' {print ($2/$1)}' `
152- residvols=` echo ${numvols} ${delvols} | awk ' {print ($1-$2)}' `
153+ propdel=$( echo " ${numvols} ${delvols} " | awk ' {print ($2/$1)}' )
154+ residvols=$( echo " ${numvols} ${delvols} " | awk ' {print ($1-$2)}' )
153155echo " ${indir} ,${numvols} ,${delvols} ,${propdel} ,${residvols} " >> motion_scrubbing_info.txt
154156
155157# Echo out motionscrub info to rsParams file
156- echo " epiNormMS=${epiData// .nii/ _ms.nii} " >> $rawEpiDir /rsParams
158+ echo " epiNormMS=${epiData// .nii/ _ms.nii} " >> " $rawEpiDir " /rsParams
157159
158160
161+ {
162+ echo " <hr>"
163+ echo " <h2>Motion Scrubbing</h2>"
164+ echo " <b>Total Volumes</b>: $numvols <br>"
165+ echo " <b>Deleted Volumes</b>: $delvols <br>"
166+ echo " <b>Remaining Volumes</b>: $residvols <br>"
167+ } >> " ${rawEpiDir} " /analysisResults.html
159168
160- echo " <hr>" >> ${rawEpiDir} /analysisResults.html
161- echo " <h2>Motion Scrubbing</h2>" >> ${rawEpiDir} /analysisResults.html
162- echo " <b>Total Volumes</b>: $numvols <br>" >> ${rawEpiDir} /analysisResults.html
163- echo " <b>Deleted Volumes</b>: $delvols <br>" >> ${rawEpiDir} /analysisResults.html
164- echo " <b>Remaining Volumes</b>: $residvols <br>" >> ${rawEpiDir} /analysisResults.html
165169
166-
167- scrubDataCheck=` cat deleted_vols.txt | head -1`
170+ scrubDataCheck=$( head -1 deleted_vols.txt)
168171if [[ $scrubDataCheck != " " ]]; then
169- echo " <b>Scrubbed TR</b>: ` cat deleted_vols.txt | awk ' {$1=$1}1' ` <br>" >> ${rawEpiDir} /analysisResults.html
172+ echo " <b>Scrubbed TR</b>: $( awk ' {$1=$1}1' deleted_vols.txt ) <br>" >> " ${rawEpiDir} " /analysisResults.html
170173fi
171174
172175# ################################
173176# clean up gunzipped nifti
174- gzip ${epiData// .nii.gz/ .nii}
177+ gzip " ${epiData// .nii.gz/ .nii} "
175178
176179echo " $0 Complete"
177180echo " "
0 commit comments