-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_6_system_verification.m
183 lines (173 loc) · 7.37 KB
/
Main_6_system_verification.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
% Copyright (c) 2024 Mohammad Al-Sa'd
%
% Permission is hereby granted, free of charge, to any person obtaining a
% copy of this software and associated documentation files (the "Software"),
% to deal in the Software without restriction, including without limitation
% the rights to use, copy, modify, merge, publish, distribute, sublicense,
% and/or sell copies of the Software, and to permit persons to whom the
% Software is furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included
% in all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
% OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
% DEALINGS IN THE SOFTWARE.
%
% Email: mohammad.al-sad@helsinki.fi, alsad.mohamed@gmail.com
%
% The following reference should be cited whenever this script is used:
% Al‐Sa'd, M., Vanhatalo, S. and Tokariev, A., 2024. Multiplex dynamic
% networks in the newborn brain disclose latent links with neurobehavioral
% phenotypes. Human Brain Mapping, 45(2), https://doi.org/10.1002/hbm.26610
%
% Last Modification: 12-February-2024
%
% Description:
% It verifies the mdFCN analysis pipeline. Note that the neonates raw EEG
% and neurocognitive scores are not supplied.
%% Initialization
clear; close all; clc;
addpath(genpath('Functions'));
%% Parameters
grp_idx = 'AED'; % HC or AED
alpha = 0.05; % statistical significance level
%% Main
for test_num = 1:5
for subset = 1:2
% Get subject scores
load(['Results\' grp_idx '\scores.mat'],'Scores','Age','idx_all');
Scores = Scores(idx_all(:,subset),:);
Age = Age(idx_all(:,subset),:);
if(subset == 1)
Scores = Scores(:,1:2);
else
Scores = Scores(:,3:end);
end
% Mask for the measures
load('Head Model\FidelityOperator.mat');
mask = logical(FidelityOperator);
I = unfold_upper_matrix(mask);
% Get values and perform correlations
r = cell(1,size(Scores,2));
p = cell(1,size(Scores,2));
switch test_num
case 1 % Static FC
data_folder = ['Results\' grp_idx '\FC'];
m = 1:length(dir([data_folder '*\*.mat']));
m = m(idx_all(:,subset));
T = [];
g = [];
for i = 1:length(m)
load([data_folder '\Subj_' num2str(m(i)) '.mat']);
if(~isempty(sdwPLI_TA))
T = cat(3,T,sdwPLI_TA(:,I));
g = cat(1,g,m(i));
end
if(~isempty(sdwPLI_AS))
T = cat(3,T,sdwPLI_AS(:,I));
g = cat(1,g,m(i));
end
end
x = [];
K = unique(g);
for k = 1:length(K)
x = cat(3,x,mean(T(:,:,g==K(k)),3));
end
x = permute(x,[1 3 2]);
clear T dwPLI_TA dwPLI_AS sdwPLI_TA sdwPLI_AS g
%%% Correlation
Kp = zeros(size(Scores,2),size(x,1));
Kn = zeros(size(Scores,2),size(x,1));
x = tensor_correct_median(x);
for i = 1:size(Scores,2)
[r{i}, p{i}] = partialcorr_score_tensor(x, Scores(:,i), Age);
[Kp(i,:), Kn(i,:)] = corr_density(r(:,i), p(:,i), alpha);
end
case 2 % Dynamic FC
data_folder = ['Results\' grp_idx '\FC'];
m = 1:length(dir([data_folder '*\*.mat']));
m = m(idx_all(:,subset));
T = [];
g = [];
for i = 1:length(m)
load([data_folder '\Subj_' num2str(m(i)) '.mat']);
if(~isempty(dwPLI_TA))
T = cat(2,T,dwPLI_TA(:,:,I));
g = cat(1,g,m(i));
end
if(~isempty(dwPLI_AS))
T = cat(2,T,dwPLI_AS(:,:,I));
g = cat(1,g,m(i));
end
end
x = [];
K = unique(g);
for k = 1:length(K)
x = cat(2,x,mean(T(:,g==K(k),:),2));
end
clear T dwPLI_TA dwPLI_AS sdwPLI_TA sdwPLI_AS g
%%% Correlation
Kp = zeros(size(Scores,2),size(x,1));
Kn = zeros(size(Scores,2),size(x,1));
x = tensor_correct_median(x);
for i = 1:size(Scores,2)
[r{i}, p{i}] = partialcorr_score_tensor(x, Scores(:,i), Age);
[Kp(i,:), Kn(i,:)] = corr_density(r(:,i), p(:,i), alpha);
end
case 3 % Latent dynamic FC
T = [];
load(['Results\' grp_idx '\NMF\subset_' num2str(subset) '_order']);
order = out_entropy.order;
for i = 1:5
fname = ['Results\' grp_idx '\NMF\subset_' num2str(subset) '_f'...
num2str(i) '_order_' num2str(order(i))];
load(fname,'W','H','g');
T = cat(3,T,W*H);
end
x = [];
K = unique(g);
for k = 1:length(K)
x = cat(1,x,mean(T(g==K(k),:,:),1));
end
x = permute(x,[3 1 2]);
clear T W H g
%%% Correlation
Kp = zeros(size(Scores,2),size(x,1));
Kn = zeros(size(Scores,2),size(x,1));
x = tensor_correct_median(x);
for i = 1:size(Scores,2)
[r{i}, p{i}] = partialcorr_score_tensor(x, Scores(:,i), Age);
[Kp(i,:), Kn(i,:)] = corr_density(r(:,i), p(:,i), alpha);
end
case 4 % Decomposed dynamic FC
load(['Results\' grp_idx '\CPD\subset_' num2str(subset) ...
'_block_averaged_network']);
x = sum(cat(4, block_avg_tensor{:}),4);
%%% Correlation
Kp = zeros(size(Scores,2),size(x,1));
Kn = zeros(size(Scores,2),size(x,1));
x = tensor_correct_median(x);
for i = 1:size(Scores,2)
[r{i}, p{i}] = partialcorr_score_tensor(x, Scores(:,i), Age);
[Kp(i,:), Kn(i,:)] = corr_density(r(:,i), p(:,i), alpha);
end
case 5 % Reconstructed dynamic FC
load(['Results\' grp_idx '\Selection\subset_' num2str(subset) ...
'_selected'],'K_pos','K_neg');
Kp = zeros(size(Scores,2),size(K_pos{1},2));
Kn = zeros(size(Scores,2),size(K_neg{1},2));
for i = 1:size(Scores,2)
Kp(i,:) = K_pos{i};
Kn(i,:) = -1.*K_neg{i};
end
end
%%% Saving
save(['Results\' grp_idx '\Verification\subset_' ...
num2str(subset) '_test_' num2str(test_num)],'Kp','Kn');
end
end