-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_randomise_tfce.bash
191 lines (183 loc) · 6.26 KB
/
run_randomise_tfce.bash
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
#!/bin/bash
#SBATCH --job-name=randomise
#SBATCH --output=%x_%A.out
#SBATCH --time=1-00:00:00
#SBATCH --partition=ncf
#SBATCH --mail-type=END,FAIL
#SBATCH --cpus-per-task=1
#SBATCH --mem=10G
#
#
#COMMAND LINE ARGUMENTS ARE USED TO SET THESE VALUES.
#NO NEED TO EDIT THEM DIRECTLY.
#SEE THE HELP TEXT BELOW OR BY RUNNING
# bash thisscriptname.bash -h
#
#THE ONE EXCEPTION ARE THE MODULES LOADED BELOW >>>
set -e
echo "Executing in $(pwd)"
gfeatdir=""
copenumber=""
analysis=""
cope4d=""
dryrun=""
onesample=""
outpre="randomise"
NPERM=10000
mask="${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz"
firstlevel4d=""
if [ $# -eq 0 ]; then
echo "No arguments supplied. Run this script with -h for help."
exit 1
fi
while getopts ":g:c:f:m:p:o:hn1" flag
do
case "${flag}" in
h )
echo " Please read the FSL Randomize user guide before using this script:"
echo " - https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Randomise/UserGuide"
echo ""
echo " Run randomise with 10,000 permutations using design of group-level"
echo " feat model. Given the design.fsf file, this script attempts to"
echo " locate the cope*.nii.gz files specified in the fsf file, concatenate"
echo " them into the requisite 4d file, and submit them to randomise along"
echo " with the design. The files that are normally required, and that are"
echo " generated by the group-level feat model are:"
echo ""
echo " - design.con"
echo " - design.fsf"
echo " - design.grp"
echo " - design.mat"
echo ""
echo " If the fsf file contains full paths to the first level feat but not"
echo " specific cope*.nii.gz, the user must specify which cope number to"
echo " use. In that case, the script assumes the cope file is found in"
echo " [group-level feat directory/reg_standard/stats/. If the user"
echo " specifies '-c 1', it will use cope1.nii.gz in that directory for"
echo " each first level feat directory in the design.fsf file. If the user"
echo " has already created a 4d file that corresponds to the design.mat"
echo " the script can use that rather than using fslmerge to create a new"
echo " one. If a one-sample t-test is requested, the user can bypass the"
echo " design.mat file with the -1 option, in which case only enough info"
echo " for the script to find or create the 4d cope is required."
echo " "
echo " Usage:"
echo " sbatch script.bash [options]"
echo " "
echo " Options are:"
echo " -h Show this message."
echo " -g [group-level feat directory] Specify group-level feat dir."
echo " -c [cope number as integer] Specify cope number from first-level."
echo " -f [4d nii.gz] Path of 4d nii.gz with first-level data."
echo " -m [mask] Path of the mask to use. Defaults to FSL MNI 2mm"
echo " -p [Number of permutations] Default is 10,000, which is recommended."
echo " -o [outfile prefix] Default is 'randomise'"
echo " -1 One sample t-test."
echo " -n Dry run."
exit 0
;;
g )
gfeatdir=${OPTARG}
;;
c )
copenumber=${OPTARG}
if [[ ! $copenumber =~ ^[0-9]$ ]]; then
echo "ERROR: $copenumber is not a valid integer"
exit 1
fi
;;
f )
cope4d=${OPTARG}
;;
m )
mask=${OPTARG}
;;
p )
NPERM=${OPTARG}
if [[ ! $NPERM =~ ^[0-9]+$ ]]; then
echo "ERROR: $NPERM is not a valid integer"
exit 1
fi
;;
o)
outpre=${OPTARG}
;;
1 )
onesample="onesample"
;;
n )
dryrun="dryrun"
;;
\? )
echo "Invalid option: ${OPTARG}" 1>&2
exit 1
;;
: )
echo "Invalid option: ${OPTARG} requires an argument" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
if [ -z "$dryrun" ]; then
echo "Loading FSL"
###########################################################################
# EDIT HERE IF YOU NEED TO LOAD A DIFFERENT VERSION OF FSL #
module load centos6/0.0.1-fasrc01 ncf/1.0.0-fasrc01 fsl/6.0.2-ncf
###########################################################################
fi
if [ -z "$mask" ]; then
mask="${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz"
fi
if [ $cope4d ]; then
echo "Using user specified 4d file for input: ${cope4d}"
firstlevel4d=${cope4d};
elif [ $gfeatdir ]; then
echo "Copying fsf file from ${gfeatdir}"
cp -v "${gfeatdir}/design.fsf" ./
inputs=`cat design.fsf | grep feat_file | awk -F " " '{print $3}' | sed -e 's/\"//g'`
if grep -q "nii.gz$" <<< "${inputs}"; then
if [ $copenumber ]; then
echo "Cope number supplied, but fsf file contains specific references to nii.gz files. Ignoring user-supplied cope number."
fi
echo "Creating 4d file from nii.gz files specified in design.fsf..."
firstlevel4d="first_level4d_fsf.nii.gz"
elif [ $copenumber ]; then
echo "design.fsf does not specify nii.gz files. Using cope number: ${copenumber}"
inputs=`cat design.fsf | grep feat_file | awk -F " " '{print $3}' | sed -e 's/\"//g' | sed -e "s/$/\/reg_standard\/stats\/cope${copenumber}.nii.gz/g"`
firstlevel4d="first_level4d_cope${copenumber}.nii.gz"
echo "Creating 4d file from nii.gz specified by user: ${firstlevel4d} ..."
else
echo "ERROR: design.fsf does not contain nii.gz files, and no cope number supplied. Aborting."
exit 1;
fi
if [ $dryrun ]; then
echo fslmerge -t first_level4d.nii.gz ${inputs}
else
srun -c 1 fslmerge -t ${firstlevel4d} ${inputs}
fi
echo "Done."
else
echo "ERROR: Must provide group-feat level directory or 4d file."
exit 1
fi
if [ -z $onesample ]; then
echo "Copying design files from ${gfeatdir}"
cp -v "${gfeatdir}/design.con" ./
cp -v "${gfeatdir}/design.grp" ./
cp -v "${gfeatdir}/design.mat" ./
echo "Contrasts are:"
cat design.con
echo "Running Randomise (${NPERM} per contrast)..."
if [ $dryrun ]; then
echo randomise -i ${firstlevel4d} -o ${outpre} -d design.mat -t design.con -e design.grp -m "${mask}" -n $NPERM -T
else
srun -c 1 randomise -i ${firstlevel4d} -o ${outpre} -d design.mat -t design.con -e design.grp -m "${mask}" -n ${NPERM} -T
fi
else
if [ $dryrun ]; then
echo randomise -i ${firstlevel4d} -o ${outpre} -1 -m "${mask}" -n ${NPERM} -T
else
srun -c 1 randomise -i ${firstlevel4d} -o ${outpre} -1 -m "${mask}" -n ${NPERM} -T
fi
fi