-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextract_rsns_features.sh
More file actions
executable file
·192 lines (134 loc) · 7.33 KB
/
Copy pathextract_rsns_features.sh
File metadata and controls
executable file
·192 lines (134 loc) · 7.33 KB
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
#!/bin/bash
# SCRIPT MIGHT HAVE BUGS
#This script extracts the average signal from a given ROI, obtained by
#thresholding the IC in melodic_IC most similar with the DMN in Smith et al. 2009
#
# The following scripts are called:
# settings_pipeline: assigns, for each pipeline, input functional data and output directory
# settings_dataset:
#
# Analysis inputs, specified in the begining of the script:
# pe_dir: phase enconding direction
# z_thresh: z threshold value to obtain rois
# subj_list: list of subjects to be analysed
# cleanup_list: cleanup pipeline list (from a predefined list)
#
# The cleanup pipelines suported in this version are the following:
# all: ica-fix + nuisance regression (WM, CSF, RP, MO)
# all_gs: ica-fix + nuisance regression (WM, CSF, RP, MO, GS)
# nuisance: nuisance regression (WM, CSF, RP, MO)
# nuisance_gs: nuisance regression (WM, CSF, RP, MO, GS)
# icafix: ica-fix
# icafix_physio: ica-fix + nuisance regression (WM, CSF)
# icafix_motion: ica-fix + nuisance regression (MO, RP)
# nocleanup: none
#
# Inputs in PREPROCESS/$subj/$pedir_dir/$mel_dir directory:
# example_func: middle volume of epi, in EF_U space
# mask: brain mask in EF_U space, output of BET (plus some processing operations)
# filtered_func_data_clean: functional data after ica-fix cleaning
# filtered_func_data_preprocessed: functional data after ica-fix + nuisance reg + smoothing
# filtered_func_data_peprocessed_gs: functional data after ica-fix + nuisance reg (+gs) + smoothing
# filtered_func_data_clean_preprocessed: functional data after ica-fix + smoothing
# filtered_func_data_clean_physio_preprocessed: functional data after ica-fix + nuisance reg (wm, csf) + smoothing
# filtered_func_data_clean_motion_preprocessed: functional data after ica-fix + nuisance reg (mo, rp) + smoothing
# filtered_func_data_nuisance_preprocessed: functional data after nuisance reg + hp temporal filtering + smoothing
# filtered_func_data_nuisance_gs_preprocessed: functional data after nuisance reg (+gs) + hp temp filt + smoothing
path=/home/mxavier/eeg-fmri/
cd $path
#--------------------------------------------- Declare analysis settings ---------------------------------------------#
#---------------------------------------------------------------------------------------------------------------------#
# Declare analysis settings
dataset=PARIS
pe_dir="y-" # phase encoding direction
task="task-rest" # "task-rest" "task-calib"
run="run-3" # "run-1" "run-2" "run-3"
# Cleanup list:
cleanup_list=("ica_mo_reg" "ica_mo_csf_reg" "ica_mo_csf_wm_reg")
# Declare reference RSN template ("smith" - Smith, 2009; "yeo" - Yeo, 2011)
rsn_template="smith"
if [[ $pe_dir == y- ]]; then pedir_dir="minusy"; else pedir_dir="plusy"; fi
#---------------------------------------- Read RSNs list from input .txt file ----------------------------------------#
#---------------------------------------------------------------------------------------------------------------------#
# Specify which .txt file containing the rsn names is going to be read
if [ $rsn_template == "smith" ]; then
input_list="list_smith_rsns.txt"
elif [ $rsn_template == "yeo" ]; then
input_list="list_yeo_rsns.txt"
fi
rsn_list=()
n=1
# Read specified file line by line and
# add rsn name to variable rsn_list
while read line; do
new_rsn=$(echo "$line")
rsn_list=( "${rsn_list[@]}" $new_rsn )
n=$((n+1))
done < $input_list
#--------------------------------------------------- Read dataset settings -------------------------------------------#
#---------------------------------------------------------------------------------------------------------------------#
if find ${path}tmp -mindepth 1 -maxdepth 1 | read; then rm ${path}tmp/*; fi
tmpdir=$path/tmp
# Read dataset settings
. settings_dataset.sh
read subj_list < $tmpdir/subj_list.txt
#------------------------------------------- Go through cleanup pipelines -------------------------------------------#
#---------------------------------------------------------------------------------------------------------------------#
# Iterate through cleanup pipelines
for cleanup in "${cleanup_list[@]}"; do
cd $path
# Assign flags and inputs for pipeline
. settings_pipeline.sh
# Read variables created in child process, in temporary directory
read func_data < $tmpdir/func_data_final.txt
read mel_dir < $tmpdir/mel_dir.txt;
func_data_dir=$func_data
#----------------------------------------------- Go through subjects ----------------------------------------------#
#-------------------------------------------------------------------------------------------------------------------#
s=0
for i in "${subj_list[@]}"; do
subj_dir=$dataset/PREPROCESS/$task/$i/$run/$pedir_dir
cd $path/$subj_dir
if [[ ! -d "rsns" ]]; then mkdir "rsns"; fi;
#-------------------------------------------- Read subject's rsns file ---------------------------------------------#
#-------------------------------------------------------------------------------------------------------------------#
while read line; do rsns+=("$line"); done < "rsns/rsns.txt"
cd $mel_dir
# Binarize subject IC image, thresholding at Z=3
fslmaths "${func_data_dir}.ica/melodic_IC" -thr $z_thresh -bin $i
# Split binarized subject IC maps into separate images
fslsplit $i subj
cd ..
r=0
for j in "${rsn_list[@]}"; do
#------------------------------------------- Extract IC time-series ---------------------------------------------#
#-----------------------------------------------------------------------------------------------------------------#
ic=$(echo "${rsns[$r]}")
cp "$mel_dir/${func_data_dir}.ica/report/t${ic}.txt" "rsns/ic_${j}.txt"
#----------------------------------------- Extract ROI from melodic_IC ------------------------------------------#
#-----------------------------------------------------------------------------------------------------------------#
# Extract roi from DMN IC (in ic_list)
ic_mel=$(echo "$ic - 1" | bc -l)
if [ $ic_mel -lt 10 ]
then
ic_mel=$(echo "000${ic_mel}")
else
ic_mel=$(echo "00${ic_mel}")
fi
cp "$mel_dir/subj${ic_mel}.nii.gz" "rsns/mask_${j}.nii.gz"
#------------------------------------- Extract average time-series from ROI -------------------------------------#
#-----------------------------------------------------------------------------------------------------------------#
# Extract average signal from ROI
fslmeants -i $func_data -m "$mel_dir/subj${ic_mel}" -o "rsns/avg_${j}.txt"
# Update rsn number
r=$(echo "$r + 1" | bc -l)
done # Looping through rsns
# Clear rsns variable for current subject
unset rsns
# Remove aux data for current subject
cd $mel_dir; rm subj*; imrm sub*; cd ..
# Update subject number
s=$(echo "$s + 1" | bc -l)
echo "RSNs extracted for ${i}"
done # Subjects
done # Cleanup pipelines