-
Notifications
You must be signed in to change notification settings - Fork 0
/
UKBclonefMRI.sh
executable file
·163 lines (124 loc) · 3.69 KB
/
UKBclonefMRI.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
#
# Script: UKBclonefMRI.sh
# Purpose: Clone a feat analysis
# Author: T. Nichols, F. Alfaro Almagro
# Version: 1.0
#
###############################################################################
#
# Environment set up
#
###############################################################################
shopt -s nullglob # No-match globbing expands to null
Tmp=/tmp/`basename $0`-${$}-
trap CleanUp INT
# Check for essential env var
if [[ "$FSLDIR" == "" || "$UKB_SMS" == "" || "$UKB_SUBJECTS" == "" || "$UKB_SCRIPTS" == "" ]] ; then
echo "ERROR: Key env vars, FSLDIR, UKB_SMS, UKB_SUBJECTS and UKB_SCRIPTS not all set"
exit 1
fi
# Template Feat file; @@SubjDir@@ is to be replaced with subject dir,
# @@OutDir@@ with output directory
FeatTemplate="/vols/Scratch/ukbiobank/nichols/TEMPLATES/tfMRI_template.fsf"
# Which data, Task? (0= rest)
UseTask=1
###############################################################################
#
# Functions
#
###############################################################################
Usage() {
cat <<EOF
Usage: `basename $0` [options] <SubjIds> <DestDir> <JobFile>
Creates a job file, to be used with fsl_sub -t, to convert UK Biobank task fMRI
from subject-space to MNI space.
SubjIds Plain text file listing the subject Ids to consider (each will
be checked to confirm availablity of data).
DestDir Location of root under which to create results in the from
where MNI space files should be put; files created will be named:
XXXXXX/fMRI/tfMRI.{fsf,feat}
JobFile Text file with one applywarp command per line.
Options
-t Template Template feat file; by default it is:
$FeatTemplate
-r Use resting data not task data, for when doing 'resting
as task' analyses.
_________________________________________________________________________
Version 1.0
EOF
exit
}
CleanUp () {
/bin/rm -f /tmp/`basename $0`-${$}-*
exit 0
}
ReplTemplate() {
local SrcDir="$1"
local Subj="$2"
local DestDir="$3"
local Template="$4"
local Npts="$5"
local ImgData="$6"
local OutDir="$DestDir"/"$Subj"/fMRI/tfMRI.feat
local OutFsf="$DestDir"/"$Subj"/fMRI/tfMRI.fsf
sed "s@/tfMRI@/${ImgData}@;s%@@SubjDir@@%$SrcDir"/"$Subj"%';'s%@@OutDir@@%"$OutDir"%';'"s/@@Npts@@/$Npts/" "$Template" > "$OutFsf"
echo $UKB_SCRIPTS/UKButil/feat_then_clean.sh "$OutFsf"
}
###############################################################################
#
# Parse arguments
#
###############################################################################
while (( $# > 1 )) ; do
case "$1" in
"-help")
Usage
;;
"-t")
shift
FeatTemplate="$1"
shift
;;
"-r")
shift
UseTask=0
;;
-*)
echo "ERROR: Unknown option '$1'"
exit 1
break
;;
*)
break
;;
esac
done
if (( $# != 3 )) ; then
Usage
fi
if (( $UseTask == 1 )) ; then
ImgData=tfMRI
else
ImgData=rfMRI
fi
SubjIds="$1"
DestDir="$2"
JobFile="$3"
cp /dev/null "$JobFile"
SrcDir=$UKB_SUBJECTS/subjectsAll
for Subj in `cat $SubjIds` ; do
if [ "$(imtest $SrcDir/$Subj/fMRI/$ImgData)" = 1 ] ; then
echo -n "$Subj "
Npts=$(fslnvols $SrcDir/$Subj/fMRI/$ImgData)
mkdir -p $DestDir/$Subj/fMRI
ReplTemplate "$SrcDir" "$Subj" "$DestDir" "$FeatTemplate" "$Npts" "$ImgData" >> "$JobFile"
fi
done
echo " "
###############################################################################
#
# Exit & Clean up
#
###############################################################################
CleanUp