-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmy_fba_stats.sh
executable file
·141 lines (106 loc) · 3.69 KB
/
my_fba_stats.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
#!/bin/bash
source `which my_do_cmd`
echo " Running on `hostname`"
if [ "$#" -lt 4 ]
then
echo " [ERROR]. Insufficient arguments."
echo " Usage: `basename $0` analysis_prefix output_prefix nperms fixel_metric"
echo ""
echo " This script is part of the set of scripts required for fixel-based analyses."
echo " See my_fba.sh for help."
exit 2
fi
# 16. Perform statistical analysis of FD, FC, and FDC
# You will need to perform a separate analysis for FD, FC and FDC. Statistics is performed using connectivity-based fixel enhancement as follows:
#
# fixelcfestats <input_files> <input_analysis_fixel.msf> <input_design_matrix.txt> <output_contrast_matrix.txt> <input_tracks_2_million_sift.tck> <output_prefix>
#
#
#
# Where the input files.txt is a text file containing the file path and name of each input fixel file on a separate line. The line ordering should correspond to the lines in the design_matrix.txt. Note that for correlation analysis, a column of 1’s will not be automatically included (as per FSL randomise). Note that fixelcfestats currently only accepts a single contrast. However if the opposite (negative) contrast is also required (i.e. a two-tailed test), then use the -neg option. Several output files will generated all starting with the supplied prefix.
analysis_prefix=$1
output_prefix=$2
nperms=$3
fixel_metric=$4
design=${analysis_prefix}.design
contrasts=${analysis_prefix}.contrasts
analysis_fixel_mask=${FBA_DIR}/template/fixel_mask
template_sift_tracks=${FBA_DIR}/template/fullTracto_sifted.tck
connmatrix=${FBA_DIR}/template/matrix
isOK=1
for f in $design $contrasts $template_sift_tracks
do
if [ ! -f $f ]
then
echo " [ERROR] Cannot find file: $f"
isOK=0
fi
done
for d in $connmatrix $analysis_fixel_mask
do
if [ ! -d $d ]
then
echo " [ERROR] Cannot find directory: $d"
isOK=0
fi
done
if [ $isOK -eq 0 ]
then
exit 2
fi
fixel_dir_smooth=${FBA_DIR}/template/${fixel_metric}_smooth
if [ ! -d $fixel_dir_smooth ]
then
echo " [ERROR] Directory does not exist: $fixel_dir_smooth"
echo " Maybe it is not a valid metric? Remember to input the _smooth version!"
exit 2
fi
# Prepare files
subjects=${analysis_prefix}.subjects
designmat=${analysis_prefix}.design_matrix
sed -e '/^\s*#.*$/d' $design | awk '{print $1}' > ${analysis_prefix}.subjects
sed -e '/^\s*#.*$/d' $design | cut -f 1 --complement > $designmat
# populate the inputFiles
inputFiles=${FBA_DIR}/logs/inputFiles_`basename $analysis_prefix`_${fixel_metric}_$$.txt
if [ -f $inputFiles ]; then rm $inputFiles;fi
while read subj;
do
f=${FBA_DIR}/template/${fixel_metric}/${subj}.mif
ff=$(basename $f)
if [ -f ${FBA_DIR}/${subj}/exclude ]
then
echo " [ERROR] Exclude file existis: ${FBA_DIR}/${subj}/exclude"
echo " Either remove this subject from the design file,
or delete the exclude file"
exit 2
fi
if [ ! -f $f ]
then
echo " [ERROR] Cannot find file: $f"
isOK=0
else
echo $ff >> $inputFiles
fi
done < <(cat $subjects)
if [ $isOK -eq 0 ]
then
echo " [ERROR] Cannot compute statistics. Quitting."
exit 2
fi
echo " [INFO] Stat analysis to be performed:"
paste $designmat $inputFiles | awk -v OFS="\t" '{$1=$1} 1'
echo "---------------------------------------"
cat $contrasts | awk -v OFS="\t" '{$1=$1} 1'
echo " [INFO] End of design"
out_stats_dir=${FBA_DIR}/template/stats_${fixel_metric}/`basename $analysis_prefix`
mkdir -pv $out_stats_dir
echo;echo " [USER] Now copy/paste this command and run it:"
my_do_cmd -fake fixelcfestats \
-nshuffles $nperms \
-info \
$fixel_dir_smooth \
$inputFiles \
$designmat \
$contrasts \
$connmatrix \
$out_stats_dir