-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomputenP2P.m
241 lines (207 loc) · 6.67 KB
/
computenP2P.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
function [opFeature, noNeuronPaths, avL, pL] = computenP2P(ipData)
%% Initialization
opFeature = [];
noNeuronPaths = 0;
avL = 0;
pL = 0;
%% total sampled locations
noNodes = size(ipData,1);
%% translating the root to (0,0,0)
rootN = ipData(1,3:5);
if norm(rootN,2) == 0
ipData(:,3:5) = ipData(:,3:5)-rootN;
end
%% alignment of dimensions based on maximum range
rangeX = max(ipData(:,3))-min(ipData(:,3));
rangeY = max(ipData(:,4))-min(ipData(:,4));
rangeZ = max(ipData(:,5))-min(ipData(:,5));
indx = [3 4 5];
[~,IX] = sort([rangeX;rangeY;rangeZ]);
indx = indx(IX);
ipData(:,3:5) = ipData(:,indx);
clear rangeX rangeY rangeZ IX indx
%% find degree of nodes
degNeuron = zeros(noNodes,1);
for k = 2:noNodes
degNeuron(ipData(k,1)) = degNeuron(ipData(k,1))+1;
degNeuron(ipData(k,7)) = degNeuron(ipData(k,7))+1;
end
degNeuron(1) = sum(ipData(:,7)==1);
clear k
%% list of bifurcation nodes
nodeDendrite = (ipData(:,2)==3)+ (ipData(:,2)==4);
nodeDegUnity = (degNeuron==1);
dendriteEnd = find((nodeDegUnity.*nodeDendrite)==1);
if isempty(dendriteEnd) % It is axon file
return
end
if dendriteEnd(1)==1
dendriteEnd(1)=[];
end
noNeuronPaths = length(dendriteEnd);
clear nodeDendrite nodeDegUnity
%% find bifurcations and multifurcations
bifurList = find(degNeuron(2:end)>=3)+1;
%% path concurrence
concurList = zeros(noNodes,1);
concurList(dendriteEnd)=1;
for k = 1:size(dendriteEnd,1)
pvt = dendriteEnd(k);
concurList = pathConcurrence(ipData,concurList,pvt);
end
concurList(1)= noNeuronPaths;
clear pvt k
%% find bifurcation angle + partition asymmetry
bifurAngle = zeros(length(bifurList),1);
cauL = zeros(length(bifurList),1);
for k = 1:length(bifurList)
pvt = bifurList(k);
loc = find(ipData(:,7)==pvt);
maxAngle = 0;
maxAsym = 0;
for m =1:length(loc)-1
uu = ipData(loc(m),3:5)-ipData(pvt,3:5);
gg = concurList(loc(m));
for n=m+1:length(loc)
vv = ipData(loc(n),3:5)-ipData(pvt,3:5);
%thetaD = abs(atan2d(norm(cross(uu,vv)),dot(uu,vv)));
thetaD = abs(acos(dot(uu,vv)/(norm(uu,2)*norm(vv,2))));
hh = concurList(loc(n));
asym = abs(gg-hh)/(gg+hh);
if thetaD > maxAngle
maxAngle = thetaD;
end
if asym > maxAsym
maxAsym = asym;
end
end
end
bifurAngle(k) = maxAngle;
cauL(k)=maxAsym;
end
% find bifurcation at the root.
pvt = 1;
loc = find(ipData(:,7)==pvt);
maxAngle = 0;
maxAsym = 0;
for m =1:length(loc)-1
uu = ipData(loc(m),3:5)-ipData(pvt,3:5);
gg = concurList(loc(m));
for n=m+1:length(loc)
vv = ipData(loc(n),3:5)-ipData(pvt,3:5);
thetaD = abs(acos(dot(uu,vv)/(norm(uu,2)*norm(vv,2))));
hh = concurList(loc(n));
asym = abs(gg-hh)/(gg+hh);
if thetaD > maxAngle
maxAngle = thetaD;
end
if asym > maxAsym
maxAsym = asym;
end
end
end
bifurRoot = maxAngle;
bifurcauL = maxAsym;
clear m k uu vv thetaD maxAngle k pvt loc asym gg hh maxAsym
%% hierarchy can be computed from Concurrence
%% List of paths with location indices
tmp = [];
enumeratePath = cell(noNeuronPaths,1);
for k = 1:noNeuronPaths
pvt = dendriteEnd(k);
while pvt ~=1
tmp = [tmp; pvt];
pvt = ipData(pvt,7);
end
tmp = [tmp; 1];
enumeratePath{k} = flipud(tmp); % each path in enumerate starts with node 1 at top
tmp = [];
end
clear k pvt tmp
%% competitive proximity
delT = 0.5;
comProx = zeros(length(bifurList),1);
for k = 1:length(bifurList)
pvt = bifurList(k);
tmpData = ipData(:,3:5);
%%%%%%%%%%%%%%%% standardization parameters%%%%%%%%%
muC = mean(tmpData,1);
sdC = std(tmpData,1);
tmpData(:,1) = (tmpData(:,1)-muC(1))./sdC(1);
tmpData(:,2) = (tmpData(:,2)-muC(2))./sdC(2);
tmpData(:,3) = (tmpData(:,3)-muC(3))./sdC(3);
%%%%%%%%%%%%%%%%
pvtC = tmpData(pvt,:);
for m = 1:length(enumeratePath)
tmp = enumeratePath{m};
if isempty(intersect(tmp,pvt))
dsT = sqrt((tmpData(tmp,1)-pvtC(1)).^2+(tmpData(tmp,2)-pvtC(2)).^2+(tmpData(tmp,3)-pvtC(3)).^2);
if any(dsT<=delT)
comProx(k) = comProx(k)+1;
end
end
end
end
comProx = comProx./noNeuronPaths;
clear dsT m k node2del tmpData muC sdC pvt
%% feature [EACH PATH]
%% tortuosity+bifurcation-angle+partition-asymmetry+concurrence+hierarchy+length+curvature+proximity
tortuositY = cell(noNeuronPaths,1);
bifurAnglePath = cell(noNeuronPaths,1);
caulescencE = cell(noNeuronPaths,1);
concurrencE = cell(noNeuronPaths,1);
hierarchY = cell(noNeuronPaths,1);
seglengtH = cell(noNeuronPaths,1);
competitioN = cell(noNeuronPaths,1);
for k = 1:noNeuronPaths
tmp = enumeratePath{k};
[B,ia,ib] = intersect(bifurList,tmp);
bifurPerpath = [1;B;tmp(end)];
tort = zeros(length(bifurPerpath)-1,1);
sgL = zeros(length(bifurPerpath)-1,1);
%avLval = zeros(length(bifurPerpath)-1,1);
for m=1:length(bifurPerpath)-1
fI = find(tmp == bifurPerpath(m));
fS = find(tmp == bifurPerpath(m+1));
if fS == fI+1
tort(m)=1;
sgL(m) = norm(ipData(bifurPerpath(m),3:5)-ipData(bifurPerpath(m+1),3:5),2);
%avLval = sgL(m);
else
segmenT = tmp(fI:fS);
eucliD = norm(ipData(bifurPerpath(m),3:5)-ipData(bifurPerpath(m+1),3:5),2);
coord = ipData(segmenT,3:5);
coord = diff(coord,1);
dsT = sum(sqrt(coord(:,1).^2+coord(:,2).^2+coord(:,3).^2));
tort(m) = dsT/eucliD;
sgL(m) = dsT;
%avLval(m) = sgL(m)/concurList(tmp(ib));
end
end
tortuositY{k} = tort;
bifurAnglePath{k} = [bifurRoot;bifurAngle(ia)];
caulescencE{k} = [bifurcauL;cauL(ia)];
concurrencE{k} = [concurList(1);concurList(tmp(ib))];
[~,IIX] = sort([concurList(1);concurList(tmp(ib))],'descend');
hierarchY{k} = IIX;
seglengtH{k} = sgL;
competitioN{k} = [0;comProx(ia)];
end
clear k tort segmenT eucliD coord fS fI m dsT bifurPerpath ia ib sgL IIX
clear bifurAngle cauL concurList
%% Average path length computation
avL = 0;
for k = 1:noNeuronPaths
avL = avL+sum(seglengtH{k});
end
avL = avL/noNeuronPaths;
%% order span calculation
%% pL calculation
pL = [];
for k = 1:noNeuronPaths
pL = [pL;max(hierarchY{k})];
end
pL = max(pL);
%% feature assembly
opFeature = [tortuositY bifurAnglePath caulescencE concurrencE hierarchY seglengtH competitioN enumeratePath];
end