-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetTreeProperties2.m
More file actions
132 lines (98 loc) · 5.59 KB
/
getTreeProperties2.m
File metadata and controls
132 lines (98 loc) · 5.59 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
function [propsBranchLevels, propsDendTrees, zeroOrderSegments, segmentsFromUnbranchedSubTrees] = getTreeProperties2 (properties, parameters)
childs_cellarray = properties.('data').('local').('childs_cellarray');
isBranchPoint = properties.('data').('local').('isBranchPoint');
isTermination = properties.('data').('local').('isTermination');
parent = properties.('data').('local').('parent');
id = properties.('data').('local').('id');
zeroOrderSegments = find(parent==1);
treeHasBranchPoint = ones(length(zeroOrderSegments), 1);
min_array = [];
lowerQuartile_array = [];
median_array = [];
upperQuartile_array = [];
max_array = [];
mean_array = [];
std_array = [];
total_array = [];
segmentsFromUnbranchedSubTrees = zeros(length(id), 1);
% Eliminate unbranched trees from analysis
if parameters.isEliminateUnbranchedTrees
for i = 1:length(zeroOrderSegments)
[subTree, ~] = getSubTree(zeroOrderSegments(i), childs_cellarray, isBranchPoint, isTermination);
indexes = and(isBranchPoint, ismember(id,subTree));
if nnz(indexes) == 0
treeHasBranchPoint(i) = 0;
segmentsFromUnbranchedSubTrees = or(segmentsFromUnbranchedSubTrees, ismember(id,subTree));
str = sprintf('MNS: Dendritic tree %d has no branch point!\nThis tree will not be considered in analysis', i);
display(str);
end
end
zeroOrderSegments(not(treeHasBranchPoint)) = [];
treeHasBranchPoint(not(treeHasBranchPoint)) = [];
end
[propsBranchLevels, indexesBranches] = getBranchProperties (properties, parameters, segmentsFromUnbranchedSubTrees);
propsBranchLevels.('branchIndexes') = indexesBranches;
% This aditional code is necessary due to elimination
% of branches with NaN value at getBranchProperties()
for i = 1:length(zeroOrderSegments)
[subTree, ~] = getSubTree(zeroOrderSegments(i), childs_cellarray, isBranchPoint, isTermination);
indexes = ismember(indexesBranches, subTree);
if nnz(indexes) == 0
treeHasBranchPoint(i) = 0;
str = sprintf('MNS: Dendritic tree %d has no branch point!\nThis tree will not be considered in analysis', i);
display(str);
end
end
zeroOrderSegments(not(treeHasBranchPoint)) = [];
treeHasBranchPoint(not(treeHasBranchPoint)) = [];
% propNames = parameters.featureNames.branchLevel.mixed;
propNames = [parameters.('featureNames').('treeLevel').('morphological'); parameters.('featureNames').('treeLevel').('electronic')];
for j = 1:length(propNames)
name = char(propNames(j));
prop = propsBranchLevels.(name);
for i = 1:length(zeroOrderSegments)
if treeHasBranchPoint(i)
[subTree, ~] = getSubTree(zeroOrderSegments(i), childs_cellarray, isBranchPoint, isTermination);
indexes = ismember(indexesBranches, subTree);
prop_subTree = prop(indexes,:);
prop_subTree(isnan(prop_subTree))=[]; % eliminate NaN values
aux = size(prop_subTree);
if aux(1)==1 % only one line
min_array = [min_array; prop_subTree];
lowerQuartile_array = [lowerQuartile_array; prop_subTree];
median_array = [median_array; prop_subTree];
upperQuartile_array = [upperQuartile_array; prop_subTree];
max_array = [max_array; prop_subTree];
mean_array = [mean_array; prop_subTree];
std_array = [std_array; prop_subTree];
total_array = [total_array; prop_subTree];
else
min_array = [min_array; min(prop_subTree)];
lowerQuartile_array = [lowerQuartile_array; quantile(prop_subTree, 0.25)];
median_array = [median_array; quantile(prop_subTree, 0.5)];
upperQuartile_array = [upperQuartile_array; quantile(prop_subTree, 0.75)];
max_array = [max_array; max(prop_subTree)];
mean_array = [mean_array; mean(prop_subTree)];
std_array = [std_array; std(prop_subTree)];
total_array = [total_array; sum(prop_subTree)];
end
end
end
propsDendTrees.(name).('min') = min_array;
propsDendTrees.(name).('lowerQuartile') = lowerQuartile_array;
propsDendTrees.(name).('median') = median_array;
propsDendTrees.(name).('upperQuartile') = upperQuartile_array;
propsDendTrees.(name).('max') = max_array;
propsDendTrees.(name).('mean') = mean_array;
propsDendTrees.(name).('std') = std_array;
propsDendTrees.(name).('total') = total_array;
min_array = [];
lowerQuartile_array = [];
median_array = [];
upperQuartile_array = [];
max_array = [];
mean_array = [];
std_array = [];
total_array = [];
end
end