-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoTrackSep.asv
More file actions
199 lines (194 loc) · 9.48 KB
/
TwoTrackSep.asv
File metadata and controls
199 lines (194 loc) · 9.48 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
189
190
191
192
193
194
195
196
197
198
199
function [HCluster,HSort,Clusterspecies,SepID] = TwoTrackSep(data_ev,data_particle,SepID,...
appear_part,maximalval)
%TWOTRACKSEP Summary of this function goes here
% Detailed explanation goes here
%% Input data
% convID =data_ev(:,1);
% convDiffco = data_particle(1,3);
% conv_diam = data_particle(1,2);
% position = data_particle(:,5:6);
% [sz,~] = size(data_particle);
% numbCdSep = [];
% ol_spec_sep = [];
[sz,~] = size(data_particle);
Clusterspecies = [];
HCluster = [];
HSort = [];
if sz ~= 0 && data_particle(1,2) > maximalval/0.75 %0.75 is omega for Dimer
obspos = data_particle(sz,5:6);
obstime = data_particle(sz,4);
obspart = data_particle(sz,:);
% Determination of max particle movement
t =30; % in frames
r_length_max = sqrt(4*data_particle(1,3)*(t/30)*log(1/(1-0.95))); % MaxMovement of particle in nm to a certain percentage
r_max = ceil (r_length_max/166);
% Which appearing particles are in time window of observed particle?
TimeMatches = appear_part((appear_part(:,4) > obstime & appear_part(:,4) < obstime+t),:);
% Which particles are smaller than the fading signal
SizeMatches = TimeMatches(TimeMatches(:,2) < obspart(:,2),:);
% KDTreeSearch for every particle in r_max:
MdlKDT_Time = KDTreeSearcher(SizeMatches(:,5:6));
IdxKDT_r_max = rangesearch(MdlKDT_Time,obspos,r_max);
lines = sort(IdxKDT_r_max {1,1});
XYMatches = SizeMatches(sort(lines(1:end)),:);
% Cluster out of fading particles, these would be the fading species
Cluster = [obspart;XYMatches(:,:)];
[appsz,~] = size (XYMatches);
% [FCsz,~] = size (Cluster);
% FdSort = {};
if appsz >=2
SID = [];
AppSort(1:appsz,1) = {'Appearing'};
FdSort = {'Fading'};
Sort = [FdSort;AppSort];
[Clustersz,~] = size(Cluster);
SID(1:Clustersz,1) = SepID;
HCluster = [SID,Cluster];
HSort = [HSort,Sort];
SepID = SepID+1;
[Clusterspecies,SpeciesCode,Code] = SpeciesDetermine(data_ev,HCluster,maximalval);
% Now check if particles belong to different species, for sppraration the
% species has to be smaller than the later species. If Something is unknown
% this will be kicked out directly in this window.
ObsparticleSpecies = cell2mat(SpeciesCode(1,1));
if ObsparticleSpecies ~= 8
Check4Cell = iscell(Code);
if Check4Cell == 0
NewParticles = SpeciesCode(2:end,1);
NewMaxSpec = Code(2:end,1);
NewClusterspecies = Clusterspecies(2:end,1);
NewPartCheck = NewParticles(1:end,1) < 8;
NewParticleAmount = sum(NewPartCheck);
if NewParticleAmount >=1
% If there is an unknown particle kick it out
NewParticles = NewParticles(NewPartCheck);
NewMaxSpec = NewMaxSpec(NewPartCheck);
NewSort = AppSort(NewPartCheck,1);
NewCluster = XYMatches(NewPartCheck,:);
NewClusterspecies = NewClusterspecies(NewPartCheck,1);
% If the particles are smaller than the fvanishing one
% kick them out
SpeciesCheck = NewMaxSpec(:,1) < Code(1,1);
NewParticles = NewParticles(SpeciesCheck,1);
NewSort = NewSort(SpeciesCheck,1);
NewCluster = NewCluster(SpeciesCheck,:);
NewClusterspecies = NewClusterspecies(SpeciesCheck,1);
% If there are still more than two particles appearing
% then use the cluster, otherwise kick it.
if length(NewParticles) >=2
% Put together the whole results:
Clusterspecies = [Clusterspecies(1,1);NewClusterspecies];
HCluster = [HCluster(1,:);NewCluster(:,:)];
HSort = [HSort(1,1);NewSort];
else
Clusterspecies = [];
HCluster = [];
HSort = [];
SepID = SepID-1;
end
else
Clusterspecies = [];
HCluster = [];
HSort = [];
SepID = SepID-1;
end
else
MaxSpec = zeros(length(Code),1);
OverallSpec = zeros(length(SpeciesCode),1);
for xx = 1:length(Code)
CheckRow = isnumeric(cell2mat(Code(xx,1)));
CheckRow2 = isnumeric(cell2mat(SpeciesCode(xx,1)));
if CheckRow == 0
Convert = cell2mat(Code(xx,1));
Convert2 = cell2mat(SpeciesCode(xx,1));
LengthConvert = length(Convert);
LengthConvert2 = length(Convert2);
if LengthConvert == 6
MaxSpec(xx,1) = min([str2num(Convert(1,1)),str2num(Convert(1,6))]);
else
MaxSpec(xx,1) = min([str2num(Convert(1:3)),str2num(Convert(7:end))]);
end
OverallSpec (xx,1) = min([str2num(Convert(1,1)),str2num(Convert(1,6))]);
else
MaxSpec(xx,1) = cell2mat(Code(xx,1));
OverallSpec(xx,1) = cell2mat(SpeciesCode(xx,1));
end
end
% Check the appearing particles for known particles:
NewParticles = OverallSpec(2:end,1);
NewMaxSpec = MaxSpec(2:end,1);
NewClusterspecies = Clusterspecies(2:end,1);
NewCluster = HCluster(2:end,:);
NewPartCheck = NewParticles(1:end,1) < 8;
NewParticleAmount = sum(NewPartCheck);
if NewParticleAmount >=1
% If there is an unknown particle kick it out
NewParticles = NewParticles(NewPartCheck);
NewMaxSpec = NewMaxSpec(NewPartCheck);
NewSort = AppSort(NewPartCheck,1);
NewCluster = NewCluster(NewPartCheck,:);
NewClusterspecies = NewClusterspecies(NewPartCheck,1);
% If the particles are smaller than the fvanishing one
% kick them out
SpeciesCheck = NewMaxSpec(:,1) < MaxSpec(1,1);
NewParticles = NewParticles(SpeciesCheck,1);
NewSort = NewSort(SpeciesCheck,1);
NewCluster = NewCluster(SpeciesCheck,:);
NewClusterspecies = NewClusterspecies(SpeciesCheck,1);
% If there are still more than two particles appearing
% then use the cluster, otherwise kick it.
if length(NewParticles) >=2
if length(NewParticles)==2
SeparationSpecies = zeros(length(NewParticles)-1,1);
for xx = 2:length(NewParticles)
SeparationSpecies(xx-1,1) = NewParticles(xx-1,1)+NewParticles(xx,1);
end
SeparationParticles = zeros(length(NewParticles),1);
SeparationCount = 0;
for yy = 1:length(SeparationSpecies)
SeparationTest = OverallSpec(1,1) == SeparationSpecies(yy,1);
SeparationCount = SeparationTest+SeparationCount;
end
if SeparationCount~=0
% Put together the whole results:
Clusterspecies = [Clusterspecies(1,1);NewClusterspecies];
HCluster = [HCluster(1,:);NewCluster(:,:)];
HSort = [HSort(1,1);NewSort];
else
Clusterspecies = [];
HCluster = [];
HSort = [];
SepID = SepID-1;
end
else
% Put together the whole results:
Clusterspecies = [Clusterspecies(1,1);NewClusterspecies];
HCluster = [HCluster(1,:);NewCluster(:,:)];
HSort = [HSort(1,1);NewSort];
end
% % Put together the whole results:
% Clusterspecies = [Clusterspecies(1,1);NewClusterspecies];
% HCluster = [HCluster(1,:);NewCluster(:,:)];
% HSort = [HSort(1,1);NewSort];
else
Clusterspecies = [];
HCluster = [];
HSort = [];
SepID = SepID-1;
end
else
Clusterspecies = [];
HCluster = [];
HSort = [];
SepID = SepID-1;
end
end
else
Clusterspecies = [];
HCluster = [];
HSort = [];
SepID = SepID-1;
end
end
end
end