-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpart1_demo4_analysis.m
293 lines (249 loc) · 8.82 KB
/
part1_demo4_analysis.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
% Part 1: Diffusivity time-dependence along realistic white matter axons
% Demo 4: Analysis (Lee, et al., Commun Biol 2020)
%
% The purpose of this demontration includes:
% 1. Calculate diffusivity and kurtosis time-dependence based on
% displacement cumulants (Fig. 2b-h).
%
% Reference:
% Lee, et al., Communications Biology 2020 (doi:10.1038/s42003-020-1050-x)
% Lee, et al., Brain Structure and Function 2019
% (doi:10.1007/s00429-019-01844-6)
%
% Author: Hong-Hsi Lee (0000-0002-3663-6559)
% Setup directory to this code
root = pwd;
% Load RMS analysis tool
addpath(fullfile(root,'analysis'));
% Load SphereDistributionRand tool
addpath(genpath(fullfile(root,'tool')));
%% Read simulation results
target = cell(4,1);
target{1} = fullfile(root,'hpc_code','input','I_realistic_axon_mitochondria');
target{2} = fullfile(root,'hpc_code','input','II_realistic_axon');
target{3} = fullfile(root,'hpc_code','input','III_caliber_variation');
target{4} = fullfile(root,'hpc_code','input','IV_undulation');
sim = struct([]);
for i = 1:numel(target)
files = dir(fullfile(target{i},'setup*'));
for j = 1:numel(files)
sim(i,j).data = readRMS(fullfile(target{i},files(j).name));
end
end
mkdir(fullfile(root,'hpc_code','result'));
save(fullfile(root,'hpc_code','result','example.mat'),'sim');
%% Analyze packing
fiber = struct([]);
for i = 1:numel(target)
file = load(fullfile(target{i},'fiber.mat'));
fiberi = file.fiber;
for j = 1:numel(fiberi)
ri = sqrt(sum(sum(fiberi(j).shape,1),2)/pi)*fiberi(j).voxel_size;
fiber(i,j).CV_radius = std(ri)/mean(ri);
fiber(i,j).volume = nnz(fiberi(j).shape)*fiberi(j).voxel_size^3;
if i == 1
fiber(i,j).mitochondrial_volume = ...
nnz(fiberi(j).shape==2)*fiberi(j).voxel_size^3;
end
end
end
for i = 1:numel(target)
volume = sum([fiber(i,:).volume]);
for j = 1:numel(fiberi)
fiber(i,j).volume_fraction = fiber(i,j).volume/volume;
end
end
%% Calculate diffusivity and kurtosis based on displacement cumulants
load(fullfile(root,'hpc_code','result','example.mat'));
% Plot Fig. 2b-c: AD and AK in four geometries in Fig. 2a (no dispersion)
figure('unit','inch','position',[0 0 12 8]);
cmap = colormap('lines');
clear h
Dinf = zeros(size(sim,2),1);
for i = 1:size(sim,1)
Di = []; Ki = [];
for j = 1:size(sim,2)
simj = sim(i,j).data;
n = [0 0 1];
[Kj, Dj] = simj.akc_mom(n);
Di = cat(2,Di,Dj);
Ki = cat(2,Ki,Kj);
if i == 1
tlist = 200:800;
t = simj.TD;
X = [ones(numel(tlist),1) 1./sqrt(t(tlist))]\Dj(tlist);
Dinf(i) = X(1);
end
end
fi = [fiber(i,:).volume_fraction];
D = sum(fi.*Di,2);
K = 3*( sum(fi.*Di.^2,2) - D.^2 ) ./ D.^2 + sum(fi.*Di.^2.*Ki,2)./D.^2;
t = simj.TD;
D0 = simj.D0(2);
subplot(121);
hold on;
plot(1./sqrt(t),D/D0,'.','MarkerSize',8,'Color',cmap(i,:));
subplot(122);
hold on;
h(i) = plot(1./sqrt(t),K,'.','MarkerSize',8,'Color',cmap(i,:));
end
subplot(121);
xlim([0 0.5]); ylim([0.6 0.95]);
set(gca,'fontsize',14);
xlabel('$1/\sqrt{t}$ (ms$^{-1/2}$)','Interpreter','latex','FontSize',24);
ylabel('$D(t)/D_0$','Interpreter','latex','FontSize',24);
pbaspect([1 1.5 1]); box on;
subplot(122);
xlim([0 0.5]); ylim([0 0.5]);
set(gca,'fontsize',14);
xlabel('$1/\sqrt{t}$ (ms$^{-1/2}$)','Interpreter','latex','FontSize',24);
ylabel('$K(t)$','Interpreter','latex','FontSize',24);
pbaspect([1 1.5 1]); box on;
legend(h,{'I: original','II: mitochondria removed',...
'III. caliber variation only','IV: undulation only'},...
'Interpreter','latex','FontSize',16,'Location','east');
% Plot Fig. 2d: Relation of relative diffusivity and coefficient of
% variation of radius
Da = sim(1,1).data.D0(2); % Intrinsic diffusivity in cytoplasm
Dm = sim(1,1).data.D0(3); % Intrinsic diffusivity in mitochondria
% Mitochondrial volume fraction
fm = [fiber(1,:).mitochondrial_volume]./[fiber(1,:).volume];
D0 = (1-fm)*Da + fm*Dm; % Mean instrinsic diffusivity
zeta = D0./Dinf(1,:)-1; % Relative diffusivity change
CV = [fiber(1,:).CV_radius]; % Coefficient of variation of radius
figure;
plot(CV.^2,zeta,'.','MarkerSize',10);
xlim([0 0.4]); ylim([0 3]);
set(gca,'fontsize',16);
xlabel('${\rm CV}^2(r)$','Interpreter','latex','FontSize',24);
ylabel('$\zeta$','Interpreter','latex','FontSize',24);
pbaspect([1 1 1]); box on; grid on;
% Plot Fig. e-f: AD and AK in geometry I with four dispersion angles
mu = [0 0 1]; % Mean direction: z-axis
kappa = [Inf 15.4 4.7 1.65]; % polar angle: 0 ,15, 30, 45 degree
Ntheta = numel(kappa); % # polar angle
Nphi = 10; % # azimuthal angle
simi = sim(1,:);
figure('unit','inch','position',[0 0 12 8]);
cmap = colormap('lines');
cmap = cmap([1 5:7],:);
clear h
for i = 1:Ntheta
% Sampling directions based on the Watson distribution
rng(0);
if i == 1
n = repmat([0 0 1],numel(simi)*Nphi,1);
else
n = randWatson(numel(simi)*Nphi, mu, kappa(i));
end
% Calculate displacement cumulants
dx2i = []; dx4i = [];
for j = 1:numel(simi)
list = (j-1)*Nphi+1 : j*Nphi;
ni = n(list,:);
[Kj,Dj] = simi(j).data.akc_mom(ni);
t = simi(j).data.TD;
dx2j = Dj*2.*t;
dx4j = (Kj+3).*dx2j.^2;
dx2j = mean(dx2j,2);
dx4j = mean(dx4j,2);
dx2i = cat(2,dx2i,dx2j);
dx4i = cat(2,dx4i,dx4j);
end
dx2 = sum(fi.*dx2i,2);
dx4 = sum(fi.*dx4i,2);
% Calculate diffusivity and kurtosis
D = dx2/2./t;
K = dx4./dx2.^2-3;
t = simi(1).data.TD;
D0 = simi(1).data.D0(2);
subplot(121);
hold on;
plot(1./sqrt(t),D/D0,'.','MarkerSize',8,'Color',cmap(i,:));
subplot(122);
hold on;
h(i) = plot(1./sqrt(t),K,'.','MarkerSize',8,'Color',cmap(i,:));
end
subplot(121);
xlim([0 0.5]); ylim([0.3 0.8]);
set(gca,'fontsize',14);
xlabel('$1/\sqrt{t}$ (ms$^{-1/2}$)','Interpreter','latex','FontSize',24);
ylabel('$D(t)/D_0$','Interpreter','latex','FontSize',24);
pbaspect([1 1.5 1]); box on;
subplot(122);
xlim([0 0.5]); ylim([0 2]);
set(gca,'fontsize',14);
xlabel('$1/\sqrt{t}$ (ms$^{-1/2}$)','Interpreter','latex','FontSize',24);
ylabel('$K(t)$','Interpreter','latex','FontSize',24);
pbaspect([1 1.5 1]); box on;
legend(h,{'$\theta=0^\circ$','$\theta=15^\circ$',...
'$\theta=30^\circ$','$\theta=45^\circ$'},...
'Interpreter','latex','FontSize',16,'Location','east');
% Plot Fig. 2g-h
mu = [0 0 1]; % Mean direction: z-axis
% Concentration parameter: no dispersion to high dispersion
kappa = [0.05:0.05:1 1.1:0.1:10 11:30 32:2:100 Inf]; kappa = kappa(end:-1:1);
Ntheta = numel(kappa); % # polar angle
Nphi = 1; % # azimuthal angle
cos2 = zeros(Ntheta,1); % Mean cosine square of axon directions
Dinf = zeros(Ntheta,2); % Bulk diffusivity at long time
c = zeros(Ntheta,2); % Strength of restrictions
simi = sim(1,:);
for i = 1:Ntheta
% Sampling directions based on the Watson distribution
rng(0);
if i == 1
n = repmat([0 0 1],numel(simi)*Nphi,1);
else
n = randWatson(numel(simi)*Nphi, mu, kappa(i));
end
cos2(i) = mean(n(:,3).^2);
% Calculate displacement cumulants
dx2i = []; dx4i = [];
for j = 1:numel(simi)
list = (j-1)*Nphi+1 : j*Nphi;
ni = n(list,:);
[Kj,Dj] = simi(j).data.akc_mom(ni);
t = simi(j).data.TD;
dx2j = Dj*2.*t;
dx2j = mean(dx2j,2);
dx2i = cat(2,dx2i,dx2j);
end
dx2 = sum(fi.*dx2i,2);
t = simi(1).data.TD;
% Calculate diffusivity
D = dx2/2./t;
% Fit the structural disorder model to AD = Dinf + c/sqrt(t)
tlist = 200:800;
X = [ones(numel(tlist),1) 1./sqrt(t(tlist))]\D(tlist);
Dinf(i,1) = X(1);
c(i,1) = X(2);
% Fit the modified model to AD = Dinf + c/sqrt(t) + c'/t
X = [ones(numel(tlist),1) 1./sqrt(t(tlist)) 1./t(tlist)]\D(tlist);
Dinf(i,2) = X(1);
c(i,2) = X(2);
end
figure('unit','inch','position',[0 0 12 6]);
subplot(121);
hold on;
plot(cos2,Dinf(:,1)/Dinf(1,1),'.','MarkerSize',10);
plot(cos2,Dinf(:,2)/Dinf(1,2),'.','MarkerSize',10);
xlim([0 1]); ylim([0 1]);
box on;
refline(1,0);
xline(1/3);
set(gca,'fontsize',14);
xlabel('$\langle\cos^2\theta\rangle$','Interpreter','latex','FontSize',24);
ylabel('$D_{\infty}/D_{\infty,\,\theta=0}$','Interpreter','latex','FontSize',24);
subplot(122);
hold on;
h1 = plot(cos2,c(:,1)/c(1,1),'.','MarkerSize',10);
h2 = plot(cos2,c(:,2)/c(1,2),'.','MarkerSize',10);
xlim([0 1]); ylim([0 1]);
box on;
refline(1,0);
xline(1/3);
set(gca,'Fontsize',14);
xlabel('$\langle\cos^2\theta\rangle$','Interpreter','latex','FontSize',24);
ylabel('$c/c_{\,\theta=0}$','Interpreter','latex','FontSize',24);
legend([h1 h2],{'uncorrected','corrected'},'Interpreter','latex','FontSize',20);