-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFigure2_FC_subsetprofile.m
More file actions
executable file
·188 lines (167 loc) · 7.02 KB
/
Figure2_FC_subsetprofile.m
File metadata and controls
executable file
·188 lines (167 loc) · 7.02 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
clear;close all;clc;
addpath(genpath('./'));
%% ================ Figure 2 =======================
clim = [-0.5,0.5]; % color scale for FC
load(['/data/wheelock/data1/people/Cindy/BCP/ParcelPlots/Parcels_','Gordon','.mat']);
T = readtable('BCP_Jan2023_QCpass_asleep_atleast7pt2min_UNC_UMN_20240124_stats_withMullen.csv');
load('BCP_Gordon_BCP_Jan2023_QCpass_asleep_atleast7pt2min_UNC_UMN_20240124_7pt2min_randsample.mat')
zmatBCP = zmat;
for ii = 1:size(zmatBCP,1),zmatBCP(ii,ii,:) = 0;end
avg_zmatBCP = mean(zmatBCP,3);
load('/data/wheelock/data1/datasets/WashU120/pconns/washu120_parcellation_Gordon_20231101.mat')
for ii = 1:size(zmat,1), zmat(ii,ii,:) = 0; end
zmatWashU120 = mean(zmat,3);
load('IM_Gordon_13nets_333Parcels_renamed.mat','IM')
zmat_Gordon_all120 = zmat(IM.order,IM.order,:);
zmat_gordon_BCP = zmatBCP(IM.order,IM.order,:);
zmat_gordon_WashU120 = zmatWashU120(IM.order,IM.order);
avg_zmat_gordon_BCP = avg_zmatBCP(IM.order,IM.order);
KardanIM = load('IM_11_BCP94_renamed.mat','IM');
KardanIM = KardanIM.IM;
zmat_Kardan_BCP = zmatBCP(KardanIM.order,KardanIM.order,:);
zmat_Kardan_WashU120 = zmatWashU120(KardanIM.order,KardanIM.order);
zmat_Kardan_all120 = zmat(KardanIM.order,KardanIM.order,:);
avg_zmat_Kardan_BCP = avg_zmatBCP(KardanIM.order,KardanIM.order);%mean(zmat_Kardan_BCP,3);
[~,Nroi,~]=size(zmat_gordon_BCP);
%% Calculate SI for Adult and Infant FC
noneidx = find((string(IM.Nets)=="None")|(string(IM.Nets)=="USp"));
keepnets = IM.key(:,2)~=noneidx;
M = ones(max(IM.key(:,2)));M(noneidx,:) = 0; M(:,noneidx) = 0;M = M-diag(diag(M));
D = calc_correlationdist(zmat_gordon_WashU120);
s = silhouette_coef_mod(IM.key(keepnets,2),D(keepnets,keepnets),M);
SI_Adult_Gordon = NaN(Nroi,1);
SI_Adult_Gordon(keepnets) = s;
D = calc_correlationdist(avg_zmat_gordon_BCP);
s = silhouette_coef_mod(IM.key(keepnets,2),D(keepnets,keepnets),M);
SI_Infant_Gordon = NaN(Nroi,1);
SI_Infant_Gordon(keepnets) = s;
%% Plot the subset of parcels on brain
noneidx = find((string(IM.Nets)=="None")|(string(IM.Nets)=="USp"));
keepnets = IM.key(:,2)~=noneidx;
M = ones(max(IM.key(:,2)));M(noneidx,:) = 0; M(:,noneidx) = 0;M = M-diag(diag(M));
[~,sortid] = sort(IM.order);
vals = SI_Infant_Gordon(sortid);
rmidx = find(~(vals>=0));
load('MNI_coord_meshes_32k.mat');
Anat.CtxL = MNIl;Anat.CtxR = MNIr;
Anat.CtxL.data=Parcel_Nets.CtxL; % plot Original Gordon Networks
Anat.CtxL.data(any(Parcels.CtxL==rmidx',2)) = 0;
Anat.CtxR.data=Parcel_Nets.CtxR;
Anat.CtxR.data(any(Parcels.CtxR==rmidx',2)) = 0;
params.Cmap.P=IM.cMap;
params.TC=1;
params.ctx='inf'; % also, 'std','inf','vinf'
params.lighting = 'gouraud';
figure;
tiledlayout(2,1,'TileSpacing','tight')
ax = nexttile;
params.view='lat'; % also, 'post','lat','med'
params.fig_handle = ax;
PlotLRMeshes(Anat.CtxL,Anat.CtxR, params);
ax = nexttile;
params.fig_handle = ax;
params.view='med'; % also, 'post','lat','med'
PlotLRMeshes(Anat.CtxL,Anat.CtxR, params);
% print(['./Figures/GordonNetwork'],'-dtiff','-r300');
%% Get number of nodes and average FC for before and after removal
Nnet = 13;
Nsubj = size(zmatBCP,3)
[within_net_FC,within_net_FC_partial,within_net_FC_excluded] = deal(NaN(Nnet,Nsubj));
[count_node,count_node_partial] = deal(NaN(Nnet,1));
for inet = setdiff(1:Nnet,noneidx)
inet
netidx = IM.key(:,2)==inet;
netidx_partial = IM.key(:,2)==inet & SI_Infant_Gordon>0;
netidx_excluded = IM.key(:,2)==inet & SI_Infant_Gordon<0;
count_node(inet) = sum(netidx);
count_node_partial(inet) = sum(netidx_partial);
for isubj = 1:Nsubj
UDidx = get_triu_idx(sum(netidx));
tmp = zmat_gordon_BCP(netidx,netidx,isubj);
within_net_FC(inet,isubj) = mean(tmp(UDidx));
UDidx = get_triu_idx(sum(netidx_partial));
tmp = zmat_gordon_BCP(netidx_partial,netidx_partial,isubj);
within_net_FC_partial(inet,isubj) = mean(tmp(UDidx));
UDidx = get_triu_idx(sum(netidx_excluded));
tmp = zmat_gordon_BCP(netidx_excluded,netidx_excluded,isubj);
within_net_FC_excluded(inet,isubj) = mean(tmp(UDidx));
end
end
%% number of nodes remained in each network
figure('units','inches','position',[1,1,6,3]);hold on;
icounter = 0;
clear hb
for inet = setdiff(1:Nnet,noneidx)
icounter = icounter+1;
hb(1) = bar(icounter-0.2,count_node(inet),0.2,'FaceColor',IM.cMap(inet,:),'EdgeColor',IM.cMap(inet,:));
hb(2) = bar(icounter+0.2,count_node_partial(inet),0.2,'FaceColor','w','EdgeColor',IM.cMap(inet,:));
end
xticks(1:Nnet-1);xticklabels(IM.Nets(setdiff(1:Nnet,noneidx)));xtickangle(30);
set(gca,'FontWeight','Bold','FontSize',10);
grid minor
legend(hb,{'All','Subset'},'location','eastoutside');
ylabel('Number of parcels');
% print('./Figures/Gordon_BCP_numnodes_original_partial_barchart','-dpdf');
figure;
subplot(1,2,1);
cMap = IM.cMap(count_node>0,:);
h = pie(count_node(count_node>0));
for i = 1:size(cMap,1)
h(2*(i-1)+1).FaceColor = cMap(i,:);
end
title('All');
set(gca,'FontSize',12);
subplot(1,2,2);
cMap = IM.cMap(count_node_partial>0,:);
h = pie(count_node_partial(count_node_partial>0));
for i = 1:size(cMap,1)
h(2*(i-1)+1).FaceColor = cMap(i,:);
end
title('Subset');
set(gca,'FontSize',12);
% print('./Figures/Gordon_BCP_numnodes_original_partial_piechart','-dpdf');
%% Boxplot of within network FC in All VS Subset (Infant)
retained_nets = [1,2,4,5,6,9,12,13]
clear h
[~,p]=arrayfun(@(i)ttest(within_net_FC(i,:)',within_net_FC_partial(i,:)'),retained_nets);
p = mafdr(p,'BHFDR',true);
figure('units','inches','position',[1,1,7,3]);hold on;
X = [within_net_FC(retained_nets,:)',within_net_FC_partial(retained_nets,:)'];
for k = 1:length(retained_nets)
plot([k-0.2,k+0.2],X(:,[k,k+8])','Color',[0.5,0.5,0.5,0.1])
end
boxplot(X,1:16,'position',[[1:8]-0.2,[1:8]+0.2],'colors',repelem([IM.cMap(retained_nets,:)],2,1),'symbol','.');
h = findobj(gca, 'Tag', 'Box');
h2 = findobj(gca,'Tag','Upper Whisker');
h3 = findobj(gca,'Tag','Lower Whisker');
for k = 2:2:length(h)
h(k).LineWidth = 2;
h2(k).LineWidth = 2;
h3(k).LineWidth = 2;
end
sigstar(arrayfun(@(i)[i-0.2,i+0.2],1:length(retained_nets),'UniformOutput',false),p)
xticks(1:length(retained_nets))
xticklabels(IM.Nets(retained_nets))
xtickangle(30);
set(gca,'FontSize',12);
title('Within network FC');
% grid minor
ylabel('z(r)')
% print('./Figures/Gordon_BCP_withinnetFC_original_partial','-dtiff','-r300');
%% Is this difference between within network using All V.S. Subset related to age?
[r,p] = deal(NaN(size(retained_nets)));
counter = 0;
for inet = retained_nets
counter = counter+1;
figure('units','inches','position',[1,1,3,3]);hold on;
scatter(T.age_yrs,within_net_FC(inet,:)-within_net_FC_partial(inet,:),15,IM.cMap(inet,:),'.');
[r(counter),p(counter)] = corr(T.age_yrs,[within_net_FC(inet,:)-within_net_FC_partial(inet,:)]');
h = refline; h.Color = 'r';
xlabel('Age (yrs)');
set(gca,'FontSize',12);
text(0.1,0.1,sprintf('r = %1.2f, p = %1.3f',r(counter),p(counter)),'Units','Normalized')
title(IM.Nets{inet});
print(['./Figures/Individual_withinFC_Kardan_Infant_',IM.Nets{inet},'.tif'],'-dtiff','-r300');
end
close all
FDR = mafdr(p,'BHFDR',true)