Skip to content

Commit 51acb67

Browse files
authored
Merge pull request #109 from jdkent/shellcheck
[MAINT] Shellcheck
2 parents b5e0da6 + 2dd23c7 commit 51acb67

18 files changed

+721
-721
lines changed

.circleci/ds005_compcor.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@
280280
/sub-01/rot_mm.png
281281
/sub-01/rot.png
282282
/sub-01/rot_trans.png
283-
/sub-01/rsParam
284283
/sub-01/rsParams
285284
/sub-01/rsParams_log
286285
/sub-01/run_motionscrub.m
@@ -304,7 +303,6 @@
304303
/sub-01/seedCorrelation/compcor/rois/seedQC/UIUC_VIS_rvis_underlay_coronal.nii
305304
/sub-01/seedCorrelation/compcor/rois/seedQC/UIUC_VIS_rvis_underlay_sagittal.nii
306305
/sub-01/seedCorrelation/compcor/rois/seeds_forQC.txt
307-
/sub-01/seedCorrelation/compcor/rois/seeds_ms.txt
308306
/sub-01/seedCorrelation/compcor/rois/seeds.txt
309307
/sub-01/seedCorrelation/compcor/rois/UIUC_VIS_lvis_mask.nii.gz
310308
/sub-01/seedCorrelation/compcor/rois/UIUC_VIS_lvis_residvol_ms_ts.txt

.circleci/ds005_compcor_global.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
/sub-01/rot_mm.png
133133
/sub-01/rot.png
134134
/sub-01/rot_trans.png
135-
/sub-01/rsParam
136135
/sub-01/rsParams
137136
/sub-01/rsParams_log
138137
/sub-01/run_motionscrub.m

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
language: bash
2-
before_install:
3-
- wget -c https://goo.gl/ZzKHFv -O - | tar -xvJ -C /tmp/
4-
- PATH="/tmp/shellcheck-latest:$PATH"
5-
script: ./tests/shellcheck.sh
1+
language: shell
2+
script:
3+
- bash -c 'shopt -s globstar; shellcheck **/*.sh'

PlotPow.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
shopt -s nullglob # No-match globbing expands to null
1717
TmpDir=/tmp
18-
Tmp=$TmpDir/`basename $0`-${$}-
18+
Tmp=$TmpDir/$(basename "$0")-${$}-
1919
trap CleanUp INT
2020

2121
###############################################################################
@@ -26,7 +26,7 @@ trap CleanUp INT
2626

2727
Usage() {
2828
cat <<EOF
29-
Usage: `basename $0` [options] 4Dimage mask PlotNm
29+
Usage: $(basename "$0") [options] 4Dimage mask PlotNm
3030
3131
Within mask voxels, computes power spectrum at each point in 4Dimage, creating a
3232
plot in file PlotNm.png. Image is always demeaned before computing the powerspectrum;
@@ -47,7 +47,7 @@ exit
4747
}
4848

4949
CleanUp () {
50-
/bin/rm -f ${Tmp}*
50+
/bin/rm -f "${Tmp}*"
5151
exit 0
5252
}
5353

@@ -60,6 +60,7 @@ CleanUp () {
6060

6161
TR=1
6262
Units=""
63+
VarNorm=0
6364
while (( $# > 1 )) ; do
6465
case "$1" in
6566
"-help")
@@ -132,13 +133,13 @@ fi
132133

133134
# High pass?
134135
if [ "$HighPass" = "1" ] ; then
135-
HPsigma=$(echo 100/2/$TR | bc -l)
136+
HPsigma=$(echo 100/2/"$TR" | bc -l)
136137
fslmaths "$Img" -bptf "$HPsigma" -1 $Tmp-HPf
137138
Img=$Tmp-HPf
138139
fi
139140

140141
# Center and possibly variance normalize
141-
if [ "$VolNorm" = "1" ] ; then
142+
if [ "$VarNorm" = "1" ] ; then
142143
fslmaths "$Img" -Tstd $Tmp-sd -odt float
143144
fslmaths "$Img" -sub $Tmp-mean -div $Tmp-sd -mas "$Mask" $Tmp-img -odt float
144145
else
@@ -150,9 +151,9 @@ fslpspec $Tmp-img $Tmp-pspec
150151

151152
# Make the plot
152153
fslmeants -i $Tmp-pspec -m $Tmp-mean -o "$Plot".txt
153-
Len=$(cat "$Plot".txt | wc -l )
154+
Len=$(wc -l < "$Plot".txt)
154155
Nyq=$(echo "0.5/$TR/$Len" | bc -l);
155-
fsl_tsplot -i "$Plot".txt -u $Nyq -t "$(basename $Plot)" -y "Power" -x "Frequency$Units" -o "$Plot".png
156+
fsl_tsplot -i "$Plot".txt -u "$Nyq" -t "$(basename "$Plot")" -y "Power" -x "Frequency$Units" -o "$Plot".png
156157

157158

158159
###############################################################################

ROIs/Schaefer2018_LocalGlobal_MNI/Schaefer2018_400Parcels_17Networks/split400.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#mwvoss script to split 400 parcellation to separate mask files
44
#
55

6-
rows=`wc Schaefer2018_400Parcels_17Networks_order.txt | awk '{print $1;}'`
6+
rows=$(wc Schaefer2018_400Parcels_17Networks_order.txt | awk '{print $1;}')
77

8-
for (( i=1; i<=$rows; i++ )) ; do
9-
parcel=`cat Schaefer2018_400Parcels_17Networks_order.txt | tr -s ' ' | awk -v i=$i 'FNR==i { print $2 }'`
10-
echo $i $parcel
11-
fslmaths Schaefer2018_400Parcels_17Networks_order_FSLMNI152_2mm.nii.gz -thr $i -uthr $i $parcel
8+
for (( i=1; i<=rows; i++ )) ; do
9+
parcel=$(tr -s ' ' < Schaefer2018_400Parcels_17Networks_order.txt | awk -v i=$i 'FNR==i { print $2 }')
10+
echo $i "$parcel"
11+
fslmaths Schaefer2018_400Parcels_17Networks_order_FSLMNI152_2mm.nii.gz -thr $i -uthr $i "$parcel"
1212
# JK: note ^^ probably want to add -bin after -uthr $i to the command, I'll
1313
# make a more formal request as soon as this file is under version control.
1414
done

makeROI_Noise.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ outputImage=$4
2424

2525
# ROI is arbitrarily set to %age of xy voxel dimensions ($2)
2626

27-
fslmaths $inputImage -mul 0 -add 1 -roi 0 -1 ${1} 1 0 -1 0 1 $outputImage -odt float
28-
fslmaths $outputImage -kernel sphere $2 -fmean $outputImage -odt float
29-
fslmaths $outputImage -bin $outputImage
27+
fslmaths "$inputImage" -mul 0 -add 1 -roi 0 -1 "${1}" 1 0 -1 0 1 "$outputImage" -odt float
28+
fslmaths "$outputImage" -kernel sphere "$2" -fmean "$outputImage" -odt float
29+
fslmaths "$outputImage" -bin "$outputImage"

makeROI_batch.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22
# feed csv of ROI coordinates to make seeds
33
# run while in RestingState scripts directory
4-
scriptPath=$(perl -e 'use Cwd "abs_path";print abs_path(shift)' $0)
5-
Path=$(dirname $scriptPath)
6-
echo $Path
7-
cd $Path
4+
scriptPath=$(perl -e 'use Cwd "abs_path";print abs_path(shift)' "$0")
5+
Path=$(dirname "$scriptPath")
6+
echo "$Path"
7+
cd "$Path" || exit
88

99
# example csv setup: net x y z diameter seed StudyOrigin
1010
# DMN 6 -60 32 14 rPCC UIUC
@@ -17,33 +17,33 @@ Usage() {
1717
[ "$1" = "" ] && Usage
1818

1919

20-
inDir=$(dirname ${1})
21-
if [ -e $inDir/runseeds.txt ]; then
22-
rm $inDir/runseeds.txt
20+
inDir=$(dirname "${1}")
21+
if [ -e "$inDir"/runseeds.txt ]; then
22+
rm "$inDir"/runseeds.txt
2323
fi
2424

25-
tr '\015' '\012' < ${1} > tmp_seedList.csv
25+
tr '\015' '\012' < "${1}" > tmp_seedList.csv
2626

2727
awk -F, '{$1=$1"_"$x;for(i=1;i<=NF;i++)if(i!=x)f=f?f FS $i:$i;print f;f=""}' x=6 tmp_seedList.csv > tmp_seedList2.csv
2828
mv tmp_seedList2.csv tmp_seedList.csv
29-
for seed in $(awk -F"," 'NR!=1{print $1}' tmp_seedList.csv); do
3029

31-
echo $seed
32-
coord=$(awk -v var="$seed" -F"," '{if($1==var) print $2,$3,$4;}' tmp_seedList.csv)
30+
awk -F"," 'NR!=1{print $1}' tmp_seedList.csv | while IFS= read -r seed; do
31+
echo "$seed"
32+
coord=$(awk -v var="$seed" -F"," '{if($1==var) print $2,$3,$4;}' tmp_seedList.csv)
3333

34-
if [[ $2 == "" ]]; then
35-
study=$(awk -v var="$seed" -F"," '{if($1==var) print $6;}' tmp_seedList.csv)
36-
else
37-
study=${2}
38-
fi
34+
if [[ $2 == "" ]]; then
35+
study=$(awk -v var="$seed" -F"," '{if($1==var) print $6;}' tmp_seedList.csv)
36+
else
37+
study=${2}
38+
fi
3939

40-
size=$(awk -v var="$seed" -F"," '{if($1==var) print $5;}' tmp_seedList.csv)
40+
size=$(awk -v var="$seed" -F"," '{if($1==var) print $5;}' tmp_seedList.csv)
4141

42-
sh makeROI.sh $coord mm $size sphere ${study}_${seed}
42+
sh makeROI.sh "$coord" mm "$size" sphere "${study}_${seed}"
4343

4444

45-
# txt file of newly made seeds that can be fed into seedVoxelCorrelation.sh
46-
echo ${study}_${seed} >> $inDir/runseeds.txt
45+
# txt file of newly made seeds that can be fed into seedVoxelCorrelation.sh
46+
echo "${study}_${seed}" >> "$inDir"/runseeds.txt
4747
done
4848

4949

motionScrub.sh

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
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")
1313
filename=run_motionscrub.m
1414

1515

@@ -24,44 +24,44 @@ function Usage {
2424

2525
########## FSL's arg parsing functions ###################
2626
get_opt1() {
27-
arg=$(echo $1 | sed 's/=.*//')
28-
echo $arg
27+
arg=${1//=*/}
28+
echo "$arg"
2929
}
3030

3131

3232
get_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

3838
get_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
5454
if [ $# -lt 1 ] ; then Usage; exit 0; fi
5555
while [ $# -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"
@@ -80,29 +80,31 @@ done
8080

8181
##Echo out all input parameters into a log
8282
logDir=$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

9496
echo "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)
127129
if [ "$haveMatlab" == "" ]; then
128-
octave --no-window-system $rawEpiDir/$filename
130+
octave --no-window-system "$rawEpiDir/$filename"
129131
else
130132
matlab -nodisplay -r "run $rawEpiDir/$filename"
131133
fi
132134

133135
#################################
134136

135137

136-
cd ${rawEpiDir}/motionScrub || exit
138+
cd "${rawEpiDir}"/motionScrub || exit
137139
#### Process Summary ############
138140
echo "...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
144146
fsl_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)}')
153155
echo "${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)
168171
if [[ $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
170173
fi
171174

172175
#################################
173176
# clean up gunzipped nifti
174-
gzip ${epiData//.nii.gz/.nii}
177+
gzip "${epiData//.nii.gz/.nii}"
175178

176179
echo "$0 Complete"
177180
echo ""

proc_fmap.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
inFile=$1
55

66
#Adjust the fieldMap_Hz to rad/s by multiplying by 6.28 (2*pi=6.28)
7-
fslmaths ${inFile} -mul 6.28 ${inFile}
7+
fslmaths "${inFile}" -mul 6.28 "${inFile}"
88

99
# https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FUGUE/Guide#Step_5_-_Regularising_the_fieldmap
1010
# smooth (1mm), despike, median filter
11-
fugue --loadfmap=${inFile} -s 1 --savefmap=${inFile%.nii.gz}_prepped.nii.gz
12-
fugue --loadfmap=${inFile} --despike --savefmap=${inFile%.nii.gz}_prepped.nii.gz
13-
fugue --loadfmap=${inFile} -m --savefmap=${inFile%.nii.gz}_prepped.nii.gz
11+
fugue --loadfmap="${inFile}" -s 1 --savefmap="${inFile%.nii.gz}"_prepped.nii.gz
12+
fugue --loadfmap="${inFile}" --despike --savefmap="${inFile%.nii.gz}"_prepped.nii.gz
13+
fugue --loadfmap="${inFile}" -m --savefmap="${inFile%.nii.gz}"_prepped.nii.gz

0 commit comments

Comments
 (0)