-
Notifications
You must be signed in to change notification settings - Fork 0
/
II_IV_Ia_REL_Stats_FCandREL.m
280 lines (203 loc) · 12.4 KB
/
II_IV_Ia_REL_Stats_FCandREL.m
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
%2.4. Statistical analysis
%2.4.1. Functional connectivity and ICC calculation
% In this code, functional connectivity and its reliability were calculated for the following
% manuscript: "" using the following dataset: https://openneuro.org/datasets/ds004386
% NOTE:
% run this script x4 times with different input data and save the results under different directories
% (see fileNames saveFolderName order variables as defined below)
%
% Merve Kaptan, [email protected]
% 22.12.2022
%%
clc
clear all
close all
%%
dataDir = '/data/pt_02098/RELIABILITY_FC/Reliability_Spinal_RestingStatefMRI/derivatives'
saveFolderName = '_Denoised_NoThermal' % save results to this folder physiological
% noise correction
%'_Denoised_ThermalvsSmooth' % save results to this folder for thermal noise
%'Denoised_Prewhiten' % save results to this folder for comparison of prewhiten vs not
%'Denoised_Partial' % save results to this folder
%for comparison of partial vs pearson correlation
saveDir = ['/data/pt_02098/RELIABILITY_FC/Reliability_Spinal_RestingStatefMRI/derivatives/ICCandCon' saveFolderName '/'];
codeDir = '/data/pt_02098/RELIABILITY_FC/Reliability_Spinal_RestingStatefMRI/derivatives/Code'
addpath(genpath(codeDir))
cd(dataDir)
subjects = dir('sub-ZS*');
subjects([9,18,30]) = []; %exclude problematic subjects 9, 18, 30!!! Because of bad ECG
subjects = {subjects.name};
if ~exist(saveDir)
mkdir(saveDir)
end
save(fullfile(saveDir,filesep,'subjects.mat'))
%%
% type of connectivity calculation --> do slice-wise correlation
% calculations, take the mean. (simple corr --> Pearson correlation coefficient)
order = {'slice-wise [mean] + avg & simple corr'}
%{'slice-wise [mean] + avg & simple corr', 'slice-wise [mean] + avg & partial corr'} % use this for comparison of partial vs pearson correlation
saveICC = 1; % save ICC results or not
saveCorrs = 1; % save FC results or not
CalculateICC =1; % calculate ICC
fileNames = {'min','moco','csf', 'breath', 'cardiac', 'pnm','max'}; % physio noise correction to use for analysis
%{'max', 'denoised_max', 'max_smooth', 'max_smooth4'}; % use this for thermal noise section
%{'max', 'prewhiten_max'} %use this for supplementary results (prewhitening vs not)
if isequal(analysisSpace, 'ts')
aspace = 'templspace' %'templspace' %or subjspace
elseif isequal(analysisSpace, 'ns')
aspace = 'nativespace';
end
%%
for f = 1:numel(fileNames)
for o = 1:numel(order)
if isequal(order{o}, 'slice-wise [mean] & simple corr')
[DD_session1, DD_session2, VV_session1, VV_session2, ...
LDV_session1,LDV_session2,RDV_session1,RDV_session2, ...
within_session1, within_session2, between_session1, between_session2, ...
ICCvalue, ICCvalue_CI ] = ...
REL_helper_CalculateConnandRel('slicewise',dataDir,subjects,analysisSpace, sessions, 'pearson',...
'mean',fileNames{f}, signalFolder, CalculateICC);
if saveICC
save([saveDir filesep order{o} '_' aspace '_' [sessions{:} ] '_' fileNames{f} 'ICC.mat'] ...
,'ICCvalue', 'ICCvalue_CI')
end
if saveCorrs
save([saveDir filesep order{o} '_' aspace '_' fileNames{f} 'corrs.mat'] ...
,'DD_session1', 'DD_session2', 'VV_session1', 'VV_session2', ...
'LDV_session1','LDV_session2','RDV_session1','RDV_session2', ...
'within_session1', 'within_session2', 'between_session1', 'between_session2')
end
elseif isequal(order{o}, 'slice-wise [mean] & partial corr')
[DD_auto, DD_manual, VV_auto, VV_manual, ...
LDV_auto,LDV_manual,RDV_auto,RDV_manual, ...
within_auto, within_manual,...
between_auto, between_manual, ICCvalue, ICCvalue_CI ] = ...
REL_helper_CalculateConnandRel('slicewise',dataDir,subjects,analysisSpace, sessions, 'partial', ...
'mean',fileNames{f}, signalFolder, CalculateICC);
if saveICC
save([saveDir filesep order{o} '_' aspace '_' [sessions{:} ] '_' fileNames{f} 'ICC.mat'] ...
,'ICCvalue', 'ICCvalue_CI')
end
if saveCorrs
save([saveDir filesep order{o} '_' aspace '_' fileNames{f} 'corrs.mat'] ...
,'DD_session1', 'DD_session2', 'VV_session1', 'VV_session2', ...
'LDV_session1','LDV_session2','RDV_session1','RDV_session2', ...
'within_session1', 'within_session2', 'between_session1', 'between_session2')
end
elseif isequal(order{o}, 'avg & simple corr')
[DD_session1, DD_session2, VV_session1, VV_session2, ...
LDV_session1,LDV_session2,RDV_session1,RDV_session2, ...
within_session1, within_session2, between_session1, between_session2, ...
ICCvalue, ICCvalue_CI ] = ...
REL_helper_CalculateConnandRel('avgTS',dataDir,subjects,analysisSpace, sessions, 'pearson', ...
'mean',fileNames{f}, signalFolder, CalculateICC);
if saveICC
save([saveDir filesep order{o} '_' aspace '_' [sessions{:} ] '_' fileNames{f} 'ICC.mat'] ...
,'ICCvalue', 'ICCvalue_CI')
end
if saveCorrs
save([saveDir filesep order{o} '_' aspace '_' fileNames{f} 'corrs.mat'] ...
,'DD_session1', 'DD_session2', 'VV_session1', 'VV_session2', ...
'LDV_session1','LDV_session2','RDV_session1','RDV_session2', ...
'within_session1', 'within_session2', 'between_session1', 'between_session2')
end
elseif isequal(order{o}, 'avg & partial corr')
[DD_session1, DD_session2, VV_session1, VV_session2, ...
LDV_session1,LDV_session2,RDV_session1,RDV_session2, ...
within_session1, within_session2, between_session1, between_session2, ...
ICCvalue, ICCvalue_CI ] = ...
REL_helper_CalculateConnandRel('avgTS',dataDir,subjects,analysisSpace, sessions, 'partial',...
'mean', fileNames{f}, signalFolder ,CalculateICC);
if saveICC
save([saveDir filesep order{o} '_' aspace '_' [sessions{:} ] '_' fileNames{f} 'ICC.mat'] ...
,'ICCvalue', 'ICCvalue_CI')
end
if saveCorrs
save([saveDir filesep order{o} '_' aspace '_' fileNames{f} 'corrs.mat'] ...
,'DD_session1', 'DD_session2', 'VV_session1', 'VV_session2', ...
'LDV_session1','LDV_session2','RDV_session1','RDV_session2', ...
'within_session1', 'within_session2', 'between_session1', 'between_session2')
end
elseif isequal(order{o}, 'slice-wise [95%] & partial corr')
[DD_session1, DD_session2, VV_session1, VV_session2, ...
LDV_session1,LDV_session2,RDV_session1,RDV_session2, ...
within_session1, within_session2, between_session1, between_session2, ...
ICCvalue, ICCvalue_CI ] = ...
REL_helper_CalculateConnandRel('slicewise',dataDir,subjects,analysisSpace, sessions, 'partial', ...
'voxel', signalFolder ,CalculateICC);
if saveICC
save([saveDir filesep order{o} '_' aspace '_' [sessions{:} ] '_' fileNames{f} 'ICC.mat'] ...
,'ICCvalue', 'ICCvalue_CI')
end
if saveCorrs
save([saveDir filesep order{o} '_' aspace '_' fileNames{f} 'corrs.mat'] ...
,'DD_session1', 'DD_session2', 'VV_session1', 'VV_session2', ...
'LDV_session1','LDV_session2','RDV_session1','RDV_session2', ...
'within_session1', 'within_session2', 'between_session1', 'between_session2')
end
end
if contains(order{o}, ' + avg')
if isequal(order{o}, 'slice-wise [mean] + avg & simple corr')
[DD_session1, DD_session2, VV_session1, VV_session2, ...
LDV_session1,LDV_session2,RDV_session1,RDV_session2, ...
within_session1, within_session2, between_session1, between_session2, ...
ICCvalue, ICCvalue_CI ] = ...
REL_helper_CalculateConnandRel('slicewise', dataDir,subjects,analysisSpace, sessions, 'pearson', ...
'mean',fileNames{f},signalFolder, CalculateICC);
elseif isequal(order{o}, 'slice-wise [mean] + avg & partial corr')
[DD_session1, DD_session2, VV_session1, VV_session2, ...
LDV_session1,LDV_session2,RDV_session1,RDV_session2, ...
within_session1, within_session2, between_session1, between_session2, ...
~, ~] = ...
REL_helper_CalculateConnandRel('slicewise',dataDir,subjects,analysisSpace, sessions, 'partial', ...
'mean',fileNames{f},signalFolder, CalculateICC);
elseif isequal(order{o}, 'slice-wise [95%] + avg & partial corr')
[DD_auto, DD_manual, VV_auto, VV_manual, ...
LDV_auto,LDV_manual,RDV_auto,RDV_manual, ...
within_auto, within_manual,...
between_auto, between_manual, ICCvalue, ICCvalue_CI ] = ...
REL_helper_CalculateConnandRel('slicewise',dataDir,subjects,analysisSpace, sessions,...
'partial', 'voxel',fileNames{f}, signalFolder,CalculateICC);
end
DD_session1 = nanmean(DD_session1,2);
DD_session2 = nanmean(DD_session2,2);
VV_session1 = nanmean(VV_session1,2);
VV_session2 = nanmean(VV_session2,2)
LDV_session1 = nanmean(LDV_session1,2);
LDV_session2 = nanmean(LDV_session2,2);
RDV_session1 = nanmean(RDV_session1,2);
RDV_session2 = nanmean(RDV_session2,2);
within_session1 = nanmean(within_session1,2);
within_session2 = nanmean(within_session2,2);
between_session1 = nanmean(between_session1,2);
between_session2 = nanmean(between_session2,2);
if CalculateICC
X = [DD_session1, DD_session2];
ICCvalue(1,1) = ICC(X, '2', '1');
ICCvalue_CI(1,:) = bootci(100000,@myICC,X);
clear X
X = [VV_session1, VV_session2];
ICCvalue(2,1) = ICC(X, '2', '1');
ICCvalue_CI(2,:) = bootci(100000,@myICC,X);
clear X
X = [within_session1, within_session2];
ICCvalue(3,1) = ICC(X, '2', '1');
ICCvalue_CI(3,:) = bootci(100000,@myICC,X);
clear X
X = [between_session1, between_session2];
ICCvalue(4,1) = ICC(X, '2', '1');
ICCvalue_CI(4,:) = bootci(100000,@myICC,X);
end
if saveICC
save([saveDir filesep order{o} '_' aspace '_' [sessions{:} ] '_' fileNames{f} 'ICC.mat'] ...
,'ICCvalue', 'ICCvalue_CI')
end
end
if saveCorrs
save([saveDir filesep order{o} '_' aspace '_' fileNames{f} 'corrs.mat'] ...
,'DD_session1', 'DD_session2', 'VV_session1', 'VV_session2', ...
'LDV_session1','LDV_session2','RDV_session1','RDV_session2', ...
'within_session1', 'within_session2', 'between_session1', 'between_session2')
end
end
end