-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_MVM_cluster_betas_4.sh
executable file
·147 lines (97 loc) · 2.93 KB
/
do_MVM_cluster_betas_4.sh
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
#!/bin/bash
# written by Nathan Muncy on 8/11/17
# this script will pull subject mean betas for each MVM cluster
workDir=/Volumes/Yorick/YAWNS3
grpDir=${workDir}/grpAnalysis
subjList=(004 006 007 008 009 010 012 013 014 015 017 019 020 021 022 023 024 025 027 028 029 030 032 033 034 035 036 037 038 041 042 043 044 045 046 047 048 049 050 051 052 053 055 056 058 059 060 061 063 064 066 067 068)
# build list of clusters
cd $grpDir
c=0; for a in Clust*HEAD; do
clust[$c]="${a/+tlrc.HEAD}"
let c=$[$c+1]
done
# pull number of labels per mask, split masks by label
if [ ! -f ${clust[0]}_1+tlrc.HEAD ]; then
for b in ${clust[@]}; do
if [ ! -f ${b}.nii.gz ]; then
3dcopy ${b}+tlrc ${b}.nii.gz
fi
num=`3dinfo ${b}+tlrc | grep "At sub-brick #0 '#0' datum type is short" | sed 's/[^0-9]*//g' | sed 's/^...//'`
for (( c=1; c<=$num; c++ )); do
c3d ${b}.nii.gz -thresh $c $c 1 0 -o ${b}_${c}.nii.gz
3dcopy ${b}_${c}.nii.gz ${b}_${c}+tlrc
done
rm *.nii.gz
done
fi
# build list of masks
c=0; for d in Clust*HEAD; do
if [[ $d != *mask+tlrc* ]]; then
mask[$c]="${d/+tlrc.HEAD}"
let c=$[$c+1]
fi
done
maskLen="${#mask[@]}"
# make output txt files
for e in ${mask[@]}; do
> ${e/Clust_}_betas.txt
done
# get, print betas
cd $workDir
for i in ${subjList[@]}; do
subjDir=${workDir}/Jensenpedisleep${i}
cd $subjDir
for a in 5_Hour 9_Hour; do
durDir=${subjDir}/$a
cd $a
for j in ${mask[@]}; do
print=${grpDir}/"${j/Clust_}"_betas.txt
if [[ $j == *DurNoGoFixBMI* ]]; then
betas=1,5
deconFile=deconv_gonogo2_blur5_ANTS_resampled+tlrc
elif [[ $j == *DurGoNoGoBMI* ]]; then
betas=1,3
deconFile=deconv_GNGvF_blur5_ANTS_resampled+tlrc
fi
stats=`3dROIstats -mask ${grpDir}/${j}+tlrc "${deconFile}[${betas}]"`
echo "$i $a $stats" >> $print
echo >> $print
done
cd $subjDir
done
cd $workDir
done
## organize print
#this part needs to be updated to be more robust in various environments
cd $grpDir
if [ ! -d clust_dir ]; then
mkdir clust_dir
fi
for i in Clust*; do
if [[ $i != *mask+tlrc* ]]; then
mv $i clust_dir
fi
done
for a in ${clust[@]}; do
> Master_"${a/Clust_}"_betas.txt
done
c=0; for b in Master*; do
printM[$c]=$b
let c=$[$c+1]
done
for a in ${printM[@]}; do
for i in MVM*txt; do
holdA=${a#*_}
stringA=${holdA%_mask*}
stringI=${i%_mask*}
if [[ $stringA == $stringI ]]; then
maskN=`ls $i | sed -e s/[^0-9]//g`
echo "Mask $maskN" >> $a
cat $i >> $a
fi
done
done
if [ ! -d txt_dir ]; then
mkdir txt_dir
fi
mv MVM*txt txt_dir