-
Notifications
You must be signed in to change notification settings - Fork 2
/
prepare_UCLA_registration.sh
executable file
·196 lines (128 loc) · 3.84 KB
/
prepare_UCLA_registration.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
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
190
191
192
193
194
#!/bin/bash
clear
resolution=2mm
MaximumThreads=8 # Maximum number of parallel threads to use
threads=0
Study=UCLA
startDir=/home/andek/Research_projects/fMRI_GAN
dataDir=/home/andek/Research_projects/fMRI_GAN/data/${Study}
# Get one fMRI volume from each fMRI dataset
Subject=1
threads=0
echo "Extracting single fMRI volumes "
#for i in ${dataDir}/* ; do
# echo "Processing Subject $Subject"
# if ls $i/func/*task-rest*.nii.gz 1> /dev/null 2>&1; then
# fslroi $i/func/*task-rest*.nii.gz $i/func/fMRI.nii.gz 0 1 &
# else
# echo "No fMRI found for Subject $Subject"
# fi
#
# ((threads++))
# if [ $threads -eq "$MaximumThreads" ]; then
# wait
# threads=0
# fi
#
# ((Subject++))
#done
#wait
echo "Registering fMRI to T1 "
# Do T1 segmentations
Subject=1
threads=0
for i in ${dataDir}/* ; do
echo "Processing Subject $Subject"
#if ls $i/anat/*T1w.nii.gz 1> /dev/null 2>&1; then
# bet $i/anat/*T1w.nii.gz $i/anat/T1w_brain.nii.gz -R -f 0.3 &
#fi
((threads++))
if [ $threads -eq "$MaximumThreads" ]; then
wait
threads=0
fi
((Subject++))
done
wait
Subject=1
for i in ${dataDir}/* ; do
# Go to current directory
cd $i
# Get subject name
SubjectID=${PWD##*/}
echo "Processing" $SubjectID
# Go back to original directory
cd ${startDir}
#if [ -f "$i/anat/T1w_brain.nii.gz" ]; then
# cp $i/anat/*T1w.nii.gz ${dataDir}/brains/T1w_${SubjectID}.nii.gz
#
# cp $i/anat/T1w_brain.nii.gz ${dataDir}/brains/T1w_brain_${SubjectID}.nii.gz
#fi
((Subject++))
done
# Now do EPI T1 registrations
Subject=1
threads=0
for i in ${dataDir}/* ; do
echo "Processing Subject $Subject"
if ls $i/func/*task-rest*.nii.gz 1> /dev/null 2>&1; then
epi_reg --epi=$i/func/fMRI.nii.gz --t1=$i/anat/*T1w.nii.gz --t1brain=$i/anat/T1w_brain.nii.gz --out=$i/func/epi_to_T1 &
else
echo "No fMRI found for Subject $Subject"
fi
((threads++))
if [ $threads -eq "$MaximumThreads" ]; then
wait
threads=0
fi
((Subject++))
done
wait
# Now do T1 MNI registrations
Subject=1
threads=0
for i in ${dataDir}/* ; do
echo "Processing Subject $Subject"
if ls $i/anat/T1w_brain.nii.gz 1> /dev/null 2>&1; then
flirt -interp sinc -in $i/anat/T1w_brain.nii.gz -ref MNI_${resolution}_crop.nii.gz -out $i/anat/T1_MNI_${resolution}.nii.gz -omat $i/anat/T1_to_MNI_${resolution}.mat &
else
echo "No T1 found for Subject $Subject"
fi
((threads++))
if [ $threads -eq "$MaximumThreads" ]; then
wait
threads=0
fi
((Subject++))
done
wait
# Now combine transformations to MNI
Subject=1
threads=0
for i in ${dataDir}/* ; do
echo "Processing Subject $Subject"
if ls $i/func/*task-rest*.nii.gz 1> /dev/null 2>&1; then
# A = fMRI, B = T1, C = MNI
convert_xfm -omat $i/func/epi_to_MNI_${resolution}.mat -concat $i/anat/T1_to_MNI_${resolution}.mat $i/func/epi_to_T1.mat
flirt -interp sinc -in $i/func/fMRI.nii.gz -ref MNI_${resolution}_crop.nii.gz -applyxfm -init $i/func/epi_to_MNI_${resolution}.mat -out $i/func/fMRI_MNI_${resolution}.nii.gz &
else
echo "No fMRI found for Subject $Subject"
fi
((threads++))
if [ $threads -eq "$MaximumThreads" ]; then
wait
threads=0
fi
((Subject++))
done
wait
echo "Copying data "
Subject=1
for i in ${dataDir}/* ; do
cp $i/func/fMRI_MNI_${resolution}.nii.gz ${dataDir}/MNI_${resolution}/${Study}_fMRI_${Subject}.nii.gz
cp $i/anat/T1_MNI_${resolution}.nii.gz ${dataDir}/MNI_${resolution}/${Study}_T1_${Subject}.nii.gz
((Subject++))
done
# How to create cropped MNI volumes
# fslroi MNI152_T1_2mm_brain.nii.gz MNI_2mm_crop.nii.gz 8 76 12 88 18 60
# fslroi MNI152_T1_1mm_brain.nii.gz MNI_1mm_crop.nii.gz 15 152 21 180 36 120