-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain_CHBM_act_level.m
317 lines (295 loc) · 13.8 KB
/
Main_CHBM_act_level.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
%% Get BC-VARETA Outputs
clc;
clear all;
close all;
addpath('external');
addpath('functions');
addpath('templates');
addpath('make_reports');
addpath('test');
properties = jsondecode(fileread(fullfile('app','properties.json')));
%% Printing data information
disp(strcat("-->> Name:",properties.generals.name));
disp(strcat("-->> Version:",properties.generals.version));
disp(strcat("-->> Version date:",properties.generals.version_date));
disp("=================================================================");
root_path_g1 = 'Z:\data3_260T\share_space\jcclab-users\Ariosky\BC-V_Output\CHBM_Template';
root_path_g2 = 'Z:\data3_260T\data\CCLAB_DATASETS\Covid\Corrected\BC-V_Output\Controls_manual_&_auto';
root_path_g3 = 'Z:\data3_260T\data\CCLAB_DATASETS\Covid\Corrected\BC-V_Output\Pathol_manual_&_auto';
output_path = 'Output';
load(properties.general_params.colormap);
%Getting subject surface
surf = load(fullfile('Z:\data3_260T\data\CCLAB_DATASETS\Covid\Corrected\BC-V_Structure\Controls_manual_&_auto\CU COVID 003\surf\surf.mat'));
Sc = surf.Sc(surf.iCortex);
disp("-->> Starting process");
disp("------------------>> Processing CHBM normative dataset <<-----------------");
disp("----------------------------------------------------------------");
disp("-->> Finding completed files");
%%
%% Group 1
%%
% Checking firt subject for create the tensors
subjects_g1 = dir(fullfile(root_path_g1,'**','BC_V_info.mat'));
disp("----------------------------------------------------------------");
good_cases = dir("Z:\data3_260T\data\CCLAB_DATASETS\CHBM\CHBM_Pedrito\CNEURO_datos\EEG_name_corrected");
good_cases(ismember({good_cases.name},{'..','.'})) = [];
info_g1 = load('CHBM_info');
subject = subjects_g1(1);
load(fullfile(subject.folder,subject.name));
activ_level = BC_V_info.activation_level;
activ_file = fullfile(subject.folder,activ_level(1).Ref_path,activ_level(1).Name);
load(activ_file,"J");
activ3D_g1 = zeros(size(J,1),length(activ_level),length(subjects_g1));
age_g1 = zeros(length(subjects_g1),1);
count_g1 = 1;
for i=1:length(subjects_g1)
subject = subjects_g1(i);
load(fullfile(subject.folder,subject.name));
subID = BC_V_info.subjectID;
if(find(ismember({good_cases.name},strcat(subID,'.mat')),1))
disp(strcat("-->> Processing subject: ",subID," Iter: ", num2str(i)));
activ_level = BC_V_info.activation_level;
age_g1(count_g1) = info_g1.data_info(contains({info_g1.data_info.SubID},subID)).Age;
for j=1:length(activ_level)
activ_file = fullfile(subject.folder,activ_level(j).Ref_path,activ_level(j).Name);
load(activ_file,"J");
activ3D_g1(:,j,count_g1) = J;
end
count_g1 = count_g1 + 1;
end
end
activ3D_g1(:,:,count_g1:end) = [];
age_g1(count_g1:end) = [];
%%
%% Group 2
%%
disp("------------------>> Processing Covid-control dataset <<-----------------");
disp("----------------------------------------------------------------");
disp("-->> Finding completed files");
subjects_g2 = dir(fullfile(root_path_g2,'**','BC_V_info.mat'));
disp("----------------------------------------------------------------");
info_g2 = load('Controls_info');
% Checking firt subject for create the tensors
subject = subjects_g2(1);
load(fullfile(subject.folder,subject.name));
activ_level = BC_V_info.activation_level;
activ_file = fullfile(subject.folder,activ_level(1).Ref_path,activ_level(1).Name);
load(activ_file,"J");
activ3D_g2 = zeros(size(J,1),length(activ_level),length(subjects_g2));
age_g2 = zeros(length(subjects_g2),1);
count_g2 = 1;
for i=1:length(subjects_g2)
subject = subjects_g2(i);
load(fullfile(subject.folder,subject.name));
subID = BC_V_info.subjectID;
disp(strcat("-->> Processing subject: ",subID," Iter: ", num2str(i)));
activ_level = BC_V_info.activation_level;
age_g2(i) = info_g2.data_info(contains({info_g2.data_info.SubID},subID)).Age;
for j = 1:length(activ_level)
activ_file = fullfile(subject.folder,activ_level(j).Ref_path,activ_level(j).Name);
load(activ_file,"J");
activ3D_g2(:,j,count_g2) = J;
end
count_g2 = count_g2 + 1;
end
%%
%% Group 3
%%
disp("------------------>> Processing Covid dataset <<-----------------");
disp("----------------------------------------------------------------");
disp("-->> Finding completed files");
subjects_g3 = dir(fullfile(root_path_g3,'**','BC_V_info.mat'));
disp("----------------------------------------------------------------");
info_g3 = load('Pathol_info');
% Checking firt subject for create the tensors
subject = subjects_g3(1);
load(fullfile(subject.folder,subject.name));
activ_level = BC_V_info.activation_level;
activ_file = fullfile(subject.folder,activ_level(1).Ref_path,activ_level(1).Name);
load(activ_file,"J");
activ3D_g3 = zeros(size(J,1),length(activ_level),length(subjects_g3));
age_g3 = zeros(length(subjects_g3),1);
count_g3 = 1;
for i=1:length(subjects_g3)
subject = subjects_g3(i);
load(fullfile(subject.folder,subject.name));
subID = BC_V_info.subjectID;
disp(strcat("-->> Processing subject: ",subID," Iter: ", num2str(i)));
activ_level = BC_V_info.activation_level;
age_g3(i) = info_g3.data_info(contains({info_g3.data_info.SubID},subID)).Age;
for j = 1:length(activ_level)
activ_file = fullfile(subject.folder,activ_level(j).Ref_path,activ_level(j).Name);
load(activ_file,"J");
activ3D_g3(:,j,count_g3) = J;
end
count_g3 = count_g3 + 1;
end
%%
%% Group comparison
%%
%% remove subject scale
activ3D_g1t = log(activ3D_g1);
activ3D_g1t = activ3D_g1t - mean(activ3D_g1t,[1 2]);
activ3D_g2t = log(activ3D_g2);
activ3D_g2t = activ3D_g2t - mean(activ3D_g2t,[1 2]);
activ3D_g3t = log(activ3D_g3);
activ3D_g3t = activ3D_g3t - mean(activ3D_g3t,[1 2]);
fig_scattergram = plot_age_roi(activ3D_g1t,age_g1,activ3D_g2t,age_g2,activ3D_g3t,age_g3,Sc);
%% linea regression
[activ3D_g1t,activ3D_g2t,activ3D_g3t] = linear_regression(activ3D_g1t,age_g1,activ3D_g2t,age_g2,activ3D_g3t,age_g3);
activ3D_g1t = reshape(activ3D_g1t,size(activ3D_g1t,1)*size(activ3D_g1t,2),size(activ3D_g1t,3));
activ3D_g2t = reshape(activ3D_g2t,size(activ3D_g2t,1)*size(activ3D_g2t,2),size(activ3D_g2t,3));
activ3D_g3t = reshape(activ3D_g3t,size(activ3D_g3t,1)*size(activ3D_g3t,2),size(activ3D_g3t,3));
activ3D_g1t = permute(activ3D_g1t,[2 1]);
activ3D_g2t = permute(activ3D_g2t,[2 1]);
activ3D_g3t = permute(activ3D_g3t,[2 1]);
nperm = 1000;
psignif = 0.05;
%% diff g1_g2
[stats_max_abs_t,orig_max_abs_t,orig_t] = max_abs_t_2group(activ3D_g1t,activ3D_g2t,nperm,psignif);
data_diff_g1g2 = reshape(orig_t,size(activ3D_g1,1),size(activ3D_g1,2));
data_diff_g1g2(data_diff_g1g2 < stats_max_abs_t.th) = 0;
%% diff g2_g3
[stats_max_abs_t,orig_max_abs_t,orig_t] = max_abs_t_2group(activ3D_g2t,activ3D_g3t,nperm,psignif);
data_diff_g2g3 = reshape(orig_t,size(activ3D_g1,1),size(activ3D_g1,2));
data_diff_g2g3(data_diff_g2g3 < stats_max_abs_t.th) = 0;
%% figures
% Creating a report
report_name = 'Covid dataset';
f_report('New');
% Add a title to the report
f_report('Title','Group difference normativeVScontrol, controlVScovid');
% Add a title to the report
f_report('Header','Cortical topography');
% Add a info to the report
f_report('Index','Linear trend of the data with age'); % a line information
bands = {'delta','theta','alpha','beta','gamma'};
for band = 1:length(bands)
fig_out = fig_scattergram{band};
fig_name = ['age-scattergram ',bands{band}];
f_report('Snapshot', fig_out, fig_name, [] , [200,200,875,350]);
close(fig_out);
end
% Add topic to the report
f_report('Index','Student T-test of the groups');
% Add a info to the report
f_report('Info','Transformations applied to the data'); % a line information
% Add multielements info to the report
line_1 = 'collect normative data_g1(gen,band,nsubj_g1)';
line_2 = 'collect control data_g2(gen,band,nsubj_g2)';
line_3 = 'collect covid data_g3(gen,band,nsubj_g3)';
line_4 = 'log transformation data <- log(data)';
line_5 = 'remove individual subject scale data <- mean(data,[1 2])';
line_6 = 'obtain age regression coefficients with normative data_g1';
line_7 = 'remove age effect in data_g1, data_g2, data_g3 with regression coeffcients';
line_8 = 'obtain Tstudent(data_g1,data_g2) between normative and control data';
line_9 = 'obtain Tstudent(data_g2,data_g3) between control and covid data';
f_report('Info',{line_1,line_2,line_3,line_4,line_5,line_6,line_7,line_8,line_9}); % multiline information cell array
%%
for band = 1:length(bands)
% diff g1_g2
figure_diff_g1_g2 = figure;
patch('Faces',Sc.Faces,'Vertices',Sc.Vertices,'FaceVertexCData',...
data_diff_g1g2(:,band),'FaceColor','interp','EdgeColor','none','FaceAlpha',.99);
set(gca,'xcolor','k','ycolor','k','zcolor','k');
% patch('Faces',Sc.Faces,'Vertices',Sc.Vertices,'FaceVertexCData',Sc.SulciMap*0.06 + 0.06 +...
% data_diff_g1g2(:,band),'FaceColor','interp','EdgeColor','none','FaceAlpha',.99);
% set(gca,'xcolor','k','ycolor','k','zcolor','k');
% colormap(gca,cmap);
colorbar
axis off
figures = {figure_diff_g1_g2,figure_diff_g1_g2,figure_diff_g1_g2,figure_diff_g1_g2};
fig_name = strcat(['cortex-tstat-normativeVScontrol ',bands{band}]);
fig_title = strcat(['cortex-tstat-normativeVScontrol ',bands{band}]);
fig_out = merge_figures(fig_name, fig_title, figures,'width',875,'height',350,...
'rows', 2, 'cols', 2,'axis_on',{'off','off','off','off'},...
'colorbars',{'on','on','on','on'},...
'view_orient',{[0,0],[180,0],[90,0],[270,0]});
f_report('Snapshot', fig_out, fig_name, [] , [200,200,875,350]);
close(figure_diff_g1_g2,fig_out);
% diff g2_g3
figure_diff_g2_g3 = figure;
patch('Faces',Sc.Faces,'Vertices',Sc.Vertices,'FaceVertexCData',...
data_diff_g2g3(:,band),'FaceColor','interp','EdgeColor','none','FaceAlpha',.99);
set(gca,'xcolor','k','ycolor','k','zcolor','k');
% patch('Faces',Sc.Faces,'Vertices',Sc.Vertices,'FaceVertexCData',Sc.SulciMap*0.06 + 0.06 +...
% data_diff_g1g2(:,band),'FaceColor','interp','EdgeColor','none','FaceAlpha',.99);
% set(gca,'xcolor','k','ycolor','k','zcolor','k');
% colormap(gca,cmap);
colorbar
axis off
figures = {figure_diff_g2_g3,figure_diff_g2_g3,figure_diff_g2_g3,figure_diff_g2_g3};
fig_name = strcat(['cortex-tstat-controlVScovid ',bands{band}]);
fig_title = strcat(['cortex-tstat-controlVScovid ',bands{band}]);
fig_out = merge_figures(fig_name, fig_title, figures,'width',875,'height',350,...
'rows', 2, 'cols', 2,'axis_on',{'off','off','off','off'},...
'colorbars',{'on','on','on','on'},...
'view_orient',{[0,0],[180,0],[90,0],[270,0]});
f_report('Snapshot', fig_out, fig_name, [] , [200,200,875,350]);
close(figure_diff_g2_g3,fig_out);
end
% Add the footer info to the report
footer_title = 'Organization';
text = 'All rights reserved';
copyright = '@copy CC-Lab';
contact = '[email protected]';
references = {'https://github.com/CCC-members', 'https://www.neuroinformatics-collaboratory.org/'};
f_report('Footer', footer_title, text, 'ref', references, 'copyright', copyright, 'contactus', contact);
disp('-->> Saving report.');
% Export the report
disp('-->> Exporting report.');
% report_name = 'CHBM_by_events';
FileFormat = 'html';
f_report('Export',output_path, report_name, FileFormat);
%%
% [activ3D_g1t,~] = get_roi_data(activ3D_g1,Sc);
% [activ3D_g2t,~] = get_roi_data(activ3D_g2,Sc);
% activ3D_g1t = log(activ3D_g1t);
% activ3D_g1t = activ3D_g1t - mean(activ3D_g1t,[1 2]);
% activ3D_g2t = log(activ3D_g2t);
% activ3D_g2t = activ3D_g2t - mean(activ3D_g2t,[1 2]);
% nperm = 1000;
% psignif = 0.05;
% activ3D_g1t = reshape(activ3D_g1t,size(activ3D_g1t,1)*size(activ3D_g1t,2),size(activ3D_g1t,3));
% activ3D_g2t = reshape(activ3D_g2t,size(activ3D_g2t,1)*size(activ3D_g2t,2),size(activ3D_g2t,3));
% activ3D_g1t = permute(activ3D_g1t,[2 1]);
% activ3D_g2t = permute(activ3D_g2t,[2 1]);
%
%
% %% mean data1
% figure
% patch('Faces',Sc.Faces,'Vertices',Sc.Vertices,'FaceVertexCData',...
% squeeze(mean(activ3D_g1(:,1,:),3)),'FaceColor','interp','EdgeColor','none','FaceAlpha',.99);
% set(gca,'xcolor','k','ycolor','k','zcolor','k');
% az = 90; el = 270;
% view(az,el);
% colormap(gca,cmap);
% % title(['cortex-tstat ',bands{band}]);
% %% mean data2
% figure
% patch('Faces',Sc.Faces,'Vertices',Sc.Vertices,'FaceVertexCData',...
% squeeze(mean(activ3D_g2(:,1,:),3)),'FaceColor','interp','EdgeColor','none','FaceAlpha',.99);
% set(gca,'xcolor','k','ycolor','k','zcolor','k');
% az = 90; el = 270;
% view(az,el);
% colormap(gca,cmap);
% % title(['cortex-tstat ',bands{band}]);
% %
%
%
% group_difference(activ3D_g1t,activ3D_g2t,Sc);
%
%
%
% activ3D_g1t = log(activ3D_g1t);
% activ3D_g1t = activ3D_g1t - mean(activ3D_g1t,[1 2]);
% activ3D_g2t = log(activ3D_g2t);
% activ3D_g2t = activ3D_g2t - mean(activ3D_g2t,[1 2]);
%
%
% group_difference(activ3D_g1t_regressed,activ3D_g2t_regressed,Sc)
%
%
% plot_differ_by_roi(activ3D_g1t,activ3D_g2t,Sc);
% avrg_cortex(activ3D_g1t,Sc,'g1');
% avrg_cortex(activ3D_g2t,Sc,'g2');