-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysisAsymmetry.m
223 lines (178 loc) · 7.98 KB
/
analysisAsymmetry.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
% This script loads the connectivity data, computes connectivity
% asymmetry, correlates this to cerebral volume, and produces the plots
% for figure 4C.
%% Load data
clear; clc; rng('default');
% Set some parameters
nRegions = 50; % 25, 50, or 100 per hemisphere
w = 1; % connection weight, 1: number of streamlines, 3: fractional anisotropy
nrand = 1000; % number of permuted networks
% Load the volumetric and connectivity data
load('data/volumetricData.mat');
load(sprintf('data/connectivityData%i.mat', nRegions));
% Calculate some overall metrics
cort_surf = sum(aparc_area{:,2:end}, 2);
cort_surf = cort_surf(1:13); % remove gibbon (no dwi)
aseg = aseg(1:13,:); % remove gibbon (no dwi)
% Choose x (supratentorial volume or cortical surface area)
x = log(aseg.SupraTentorialVol);
% x = log(cort_surf); % alternative: cortical surface area
%% Prepare connectivity data
% Find outliers per species
% Macaque
tmp_macaque_idx = find(strcmp(dwi.species, 'macaque'));
tmp_macaque_dens = getDensity(dwi.connectivity(:,:,1,tmp_macaque_idx));
loCutoff = median(tmp_macaque_dens) - 1.5*iqr(tmp_macaque_dens);
hiCutoff = median(tmp_macaque_dens) + 1.5*iqr(tmp_macaque_dens);
outliers = tmp_macaque_dens < loCutoff | tmp_macaque_dens > hiCutoff;
tmp_macaque_outliers = tmp_macaque_idx(outliers);
% Chimp
tmp_chimp_idx = find(strcmp(dwi.species, 'chimpanzee'));
tmp_chimp_dens = getDensity(dwi.connectivity(:,:,1,tmp_chimp_idx));
loCutoff = median(tmp_chimp_dens) - 1.5*iqr(tmp_chimp_dens);
hiCutoff = median(tmp_chimp_dens) + 1.5*iqr(tmp_chimp_dens);
outliers = tmp_chimp_dens < loCutoff | tmp_chimp_dens > hiCutoff;
tmp_chimp_outliers = tmp_chimp_idx(outliers);
% Human
tmp_human_idx = find(strcmp(dwi.species, 'human'));
tmp_human_dens = getDensity(dwi.connectivity(:,:,1,tmp_human_idx));
loCutoff = median(tmp_human_dens) - 1.5*iqr(tmp_human_dens);
hiCutoff = median(tmp_human_dens) + 1.5*iqr(tmp_human_dens);
outliers = tmp_human_dens < loCutoff | tmp_human_dens > hiCutoff;
tmp_human_outliers = tmp_human_idx(outliers);
% Remove outliers
outliers = [tmp_macaque_outliers; tmp_chimp_outliers; tmp_human_outliers];
dwi.connectivity(:,:,:,outliers) = [];
dwi.species(outliers) = [];
dwi.regionProperties(:,:,outliers) = [];
% Set equal density
for i = 1:size(dwi.connectivity, 4)
T = thresholdDensity(dwi.connectivity(:,:,1,i), dwi.connectivity(:,:,1,i), 0.1);
dwi.connectivity(:,:,:,i) = dwi.connectivity(:,:,:,i) .* double(T > 0);
end
%% Main analysis
% Initialize variables
N = size(dwi.connectivity, 1);
n = size(dwi.connectivity, 4);
weights_normalized = zeros(N,N,n);
weights_normalized_null = zeros(N,N,n,nrand);
asymmetry = nan(n, 1);
asymmetry_null = nan(n, nrand);
% Resample weights to normal distribution
for i = 1:n
W = dwi.connectivity(:,:,w,i);
W(1:N/2, N/2+1:end) = 0; % remove interhemispheric connections
W(N/2+1:end, 1:N/2) = 0; % remove interhemispheric connections
S = (W(1:N/2, 1:N/2) > 0) & (W(N/2+1:end, N/2+1:end) > 0); % connections both in lh and rh
W(1:N/2, 1:N/2) = W(1:N/2, 1:N/2) .* S; % weights of shared connections in LH
W(N/2+1:end, N/2+1:end) = W(N/2+1:end, N/2+1:end) .* S; % weights of shared connections in RH
W(1:N/2, 1:N/2) = resampleWeights(W(1:N/2, 1:N/2)); % resample LH to normal distribution
W(N/2+1:end, N/2+1:end) = resampleWeights(W(N/2+1:end, N/2+1:end)); % resample RH to normal distribution
weights_normalized(:,:,i) = W;
% Now also create null model in which the weights are permuted within LH
% and RH separately
for j = 1:nrand
WR = zeros(N);
LH = W(1:N/2, 1:N/2);
idx = find(LH > 0);
nIdx = length(idx);
LH(idx) = LH(idx(randperm(nIdx)));
WR(1:N/2, 1:N/2) = LH;
RH = W(N/2+1:end, N/2+1:end);
idx = find(RH > 0);
nIdx = length(idx);
RH(idx) = RH(idx(randperm(nIdx)));
WR(N/2+1:end, N/2+1:end) = RH;
weights_normalized_null(:,:,i,j) = WR;
end
end
% Calculate connectivity asymmetry
for i = 1:n
asymmetry(i) = nanmean(calcAsymmetry(weights_normalized(:,:,i), ...
dwi.regionDescriptions, 'includeInter', 0)); % excluding interhemispheric connections
end
% Average values for species with more than one subject
avg_asymmetry(1:7) = asymmetry(1:7);
avg_asymmetry(8) = mean(asymmetry(strcmp(dwi.species, 'macaque')), 1);
avg_asymmetry(9) = mean(asymmetry(strcmp(dwi.species, 'chimpanzee')), 1);
avg_asymmetry(10) = mean(asymmetry(strcmp(dwi.species, 'human')), 1);
avg_asymmetry(11) = mean(asymmetry(strcmp(dwi.species, 'bonobo')), 1);
avg_asymmetry(12) = mean(asymmetry(strcmp(dwi.species, 'gorilla')), 1);
avg_asymmetry(13) = mean(asymmetry(strcmp(dwi.species, 'orangutan')), 1);
% Standard correlation (for PGLS see below)
[beta, pval] = corr(x, avg_asymmetry');
%% Null model
betas_null = nan(nrand, 1);
pvals_null = nan(nrand, 1);
y_null = nan(length(avg_asymmetry), nrand);
for k = 1:nrand
fprintf('Permutation %i/%i...\n', k, nrand);
for l = 1:n
asymmetry_null(l,k) = nanmean(calcAsymmetry(weights_normalized_null(:,:,l,k), ...
dwi.regionDescriptions, 'includeInter', 0)); % excluding interhemispheric connections
end
% Average values for species with more than one subject
k_avg_asymmetry_null(1:7) = asymmetry_null(1:7, k);
k_avg_asymmetry_null(8) = mean(asymmetry_null(strcmp(dwi.species, 'macaque'), k), 1);
k_avg_asymmetry_null(9) = mean(asymmetry_null(strcmp(dwi.species, 'chimpanzee'), k), 1);
k_avg_asymmetry_null(10) = mean(asymmetry_null(strcmp(dwi.species, 'human'), k), 1);
k_avg_asymmetry_null(11) = mean(asymmetry_null(strcmp(dwi.species, 'bonobo'), k), 1);
k_avg_asymmetry_null(12) = mean(asymmetry_null(strcmp(dwi.species, 'gorilla'), k), 1);
k_avg_asymmetry_null(13) = mean(asymmetry_null(strcmp(dwi.species, 'orangutan'), k), 1);
% Standard correlation
[betas_null(k), pvals_null(k)] = corr(x, k_avg_asymmetry_null');
y_null(:,k) = k_avg_asymmetry_null;
end
%% Save for PGLS
outTable = aseg(:, ismember(aseg.Properties.VariableNames, ...
{'subject', 'SupraTentorialVol'}));
outTable.cort_surf = cort_surf;
outTable.conn_asymmetry = avg_asymmetry';
writetable(outTable, 'pgls/connectivityAsymmetry.csv');
% Also save the null results
outTable = array2table(y_null);
outTable.subject = aseg.subject;
outTable = [outTable(:,end), outTable(:,1:end-1)]; % reorder
writetable(outTable, 'pgls/connectivityAsymmetryNull.csv');
% Also save normalized results (easier interpretation of PGLS coefficients)
outTable = aseg(:, ismember(aseg.Properties.VariableNames, ...
{'subject', 'SupraTentorialVol'}));
outTable.cort_surf = zscore(log(cort_surf));
outTable.conn_asymmetry = zscore(avg_asymmetry)';
outTable.SupraTentorialVol = zscore(log(aseg.SupraTentorialVol));
writetable(outTable, 'pgls/connectivityAsymmetryNormalized.csv');
%% Figures
% Load PGLS slope estimates
pgls = readtable('pgls/pglsConnectivityAsymmetry.csv');
pgls(:,1) = []; % remove first column
% Supratentorial volume
y = avg_asymmetry;
x = aseg.SupraTentorialVol;
mdl = fitlm(log(x), y);
fA = figureLinearLog(y, x, pgls.slope_estimate(1), pgls.intercept_estimate(1), ...
'Connectivity asymmetry', 'Cerebral volume (mm^3)', ...
'confidenceBands', mdl);
ylim([0.6*min(y), 1.05*max(y)]);
% Cortical surface area
y = avg_asymmetry;
x = cort_surf;
mdl = fitlm(log(x), y);
fB = figureLinearLog(y, x, pgls.slope_estimate(2), pgls.intercept_estimate(2), ...
'Connectivity asymmetry', 'Cortical surface area (mm^2)', ...
'confidenceBands', mdl);
xlim([fB.CurrentAxes.XLim(1), 2.5*10^5]);
ylim([0.6*min(y), 1.05*max(y)]);
% Add null model (for the x chosen in first section of this script)
figure('Color', 'white', 'position', [200,200,100,100]);
[counts,edges] = histcounts(betas_null);
edges = edges(2:end) - (edges(2)-edges(1))/2;
h = plot(edges, counts);
box('Off');
hold on;
h2 = fill([min(edges), edges, max(edges)], [0, counts, 0], [0.9, 0.9, 0.9]);
l2 = xline(beta);
l2.LineStyle = '--';
l2.Color = 'r';
ylabel('Count');
xlabel("Pearson's {\it r}");
xlim([-1,1]);