-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigClass.m
executable file
·416 lines (393 loc) · 16.3 KB
/
ConfigClass.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
classdef ConfigClass < handle
properties
Version = 2.03;
TrackingServer = '';
PixSize = 266.7;
Time = 1000;
FileName = '';
StackName = '';
Directory = '';
StackType = 'TIFF';
FirstCFrame = 1;
FirstTFrame = 1;
LastFrame = 1;
FilFocus = 0;
OnlyTrack = struct('MolFull', 0, 'FilFull', 1, 'MolLeft', 0,...
'FilLeft', 0, 'MolRight', 0, 'FilRight', 0);
Threshold = struct('Area', 30, 'Mode', 'relative','Height', 2,...
'Fit', 0, 'FWHM', 534, 'Filter', 'average',...
'Value', 0.0000e+00 + 1.6000e+02i, 'MinFilamentLength', 3)
BorderMargin = 2
Connect = struct('MaxVelocity', 1500, 'Position', 0.4,...
'Direction', 0.4, 'Speed', 0.2, 'IntensityOrLength', 0,...
'UseIntensity', 0, 'MinLength', 4, 'MaxBreak', 5, 'MaxAngle', 45,...
'NumberVerification', 2, 'ReEval', 0);
ConnectMol = struct('MaxVelocity', 1500, 'Position', 0.4,...
'Direction', 0.4, 'Speed', 0.2, 'IntensityOrLength', 0,...
'UseIntensity', 0, 'MinLength', 4, 'MaxBreak', 5, 'MaxAngle', 45,...
'NumberVerification', 2, 'ReEval', 0);
MaxFunc = 4
Model = 'GaussSymmetric'
ConnectFil = struct('MaxVelocity', 1000, 'Position', 0.3,...
'Direction', 0.3, 'Speed', 0.2, 'IntensityOrLength', 0.2,...
'DisregardEdge', 1,'MinLength', 4, 'MaxBreak', 5, 'MaxAngle', 45,...
'NumberVerification', 2, 'ReEval', 0);
RefPoint = 'start';
ReduceFitBox = 1;
maxObjects = 1000;
Times = [];
Avi = struct('BarSize', 25, 'mPosBar', 4, 'mPosTime', 1,...
'mFontSize', 0.06, 'Make', 0);
Path = struct('Generate', 1, 'Method', 'Fit', 'Status', 'TBD');
Width = 512;
Height = 512;
UseParpool=true;
UseChannel = 1;
UseGui=true;
SubtractBackground=struct('BallRadius',30,'Smoothe',1);
PreferStackPixSize=true;
EvaluationClassName='SpeedEvaluation2Class'
AcquisitionDate='';
Evaluation=struct('EvalClassNo',2,...
'EvalClassNames',{{...
'SpeedEvaluationClass',...
'SpeedEvaluation2Class',...
'BundlingEvaluationClass',...
'Speed2TempEvaluationClass',...
'SpeedJannesEvaluationClass',...
'MakeMovieEvaluationClass',...
'BioCompEvaluationClass',...
'DilutionSeriesEvaluationClass',...
'AngleEvaluationClass'}},...
'TasksNeeded',{{...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false),...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false),...
struct('Track',true,'Connect',false,'Fit',false,'Evaluate',true,'Overview',true,'Avi',false),...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false),...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false),...
struct('Track',false,'Connect',false,'Fit',false,'Evaluate',true,'Overview',false,'Avi',true),...
struct('Track',true,'Connect',true,'Fit',false,'Evaluate',true,'Overview',true,'Avi',false),...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false),...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false)}},...
'ImagesNeeded',{{1,1,inf,1,1,inf,inf,1,1}});
Tasks=struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false);
ImageScaling = struct('Modes',{{'auto','manual'}},'ModeNo',1,'Black',0,'White',0);
LegacyData = false;
end
methods
function C=ConfigClass(varargin)
if ~isempty(varargin)
p=inputParser;
p.addParameter('Path','',@ischar);
p.addParameter('ConfigStructure',struct([]),@isstruct);
p.parse(varargin{:})
if ~isempty(p.Results.Path)
C.loadConfig(p.Results.Path);
end
if ~isempty(p.Results.ConfigStructure)
C.importConfigStruct(p.Results.ConfigStructure);
end
end
end
function C=loadConfig(C,path)
load(path,'Config');
C.importConfigStruct(Config);
end
function C=reloadConfig(C,path)
load(path,'Config');
%always use the path from the current config file not from the
%config that came with the data (in case the data was moved)
if ~isempty(C.Directory)
Config.Directory=C.Directory;
end
%update the path configuration if it has changed
if isfield(Config, 'Path') && (~strcmp(Config.Path.Method,C.Path.Method))
Config.Path.Method=C.Path.Method;
Config.Path.Status='TBD';
end
%Always use the evaluation configuration from the current config to
%allow changing the evaluation method after tracking the data
if isfield(Config, 'Evaluation')
Config.EvaluationClassName=C.EvaluationClassName;
Config.Evaluation=C.Evaluation;
Config = ConfigClass.upgradeNeedsWholeStack(Config);
end
C.importConfigStruct(Config);
end
function C=importConfigStruct(C,Config)
Config=ConfigClass.validate(C,Config);
%now that we are sure that the config structure contains the same
%elements as the ConfigClass properties, we can just copy them over
fields=fieldnames(Config);
for i=1:numel(fields)
C.(fields{i})=Config.(fields{i});
end
end
function Config=exportConfigStruct(C)
fields=fieldnames(C);
Config=struct();
for i=1:numel(fields)
Config.(fields{i})=C.(fields{i});
end
end
function save(C,config_file)
Config=C.exportConfigStruct(); %#ok<NASGU>
save(config_file,'-v6','Config');
end
end
methods(Static)
function Config=upgrade(Config)
if Config.Version < 1.0
warning('MATLAB:AutoTipTrack:ConfigClass:upgrade','incompatible version: %f',Config.Version)
end
if Config.Version < 1.1
%these fields were added because they are assigned later in the
%code and generated errors because they cannot be dynamically
%created for the class
if ~isfield (Config,'Width')
Config.Width = 512;
end
if ~isfield (Config,'Height')
Config.Height = 512;
end
if ~isfield (Config,'Connect')
Config.Connect = struct('MaxVelocity', 1500, 'Position', 0.4,...
'Direction', 0.4, 'Speed', 0.2, 'IntensityOrLength', 0,...
'UseIntensity', 0, 'MinLength', 4, 'MaxBreak', 2, 'MaxAngle', 45,...
'NumberVerification', 2, 'ReEval', 0);
end
Config.Version=1.1;
end
if Config.Version<1.2
%Add a parameter to control whether we are going to use a parallel
%pool
if ~isfield (Config,'UseParpool')
Config.UseParpool=true;
end
Config.Version=1.2;
end
if Config.Version<1.3
%Add a parameter to control which channel of a multi color
%stack we want to use.
if ~isfield (Config,'UseChannel')
Config.UseChannel=1;
end
%Add a parameter to control whether we want a GUI
if ~isfield (Config,'UseGui')
Config.UseGui=true;
end
Config.Version=1.3;
end
if Config.Version<1.4
%Add a parameter to control background subtraction
if ~isfield (Config,'SubtractBackground')
Config.SubtractBackground=struct('BallRadius',30,'Smoothe',1);
end
Config.Version=1.4;
end
if Config.Version<1.6
%change the default value for MaxBreak
if Config.Connect.MaxBreak==2
Config.Connect.MaxBreak=5;
end
if Config.ConnectMol.MaxBreak==2
Config.ConnectMol.MaxBreak=5;
end
if Config.ConnectFil.MaxBreak==2
Config.ConnectFil.MaxBreak=5;
end
%Add a parameter to choose whether to use the pixsize stored in the
%stack
if ~isfield(Config, 'PreferStackPixSize')
Config.PreferStackPixSize=true;
end
Config.Version=1.6;
end
if Config.Version<1.8
if Config.Avi.Make
Config.Avi.Make=false;
end
% Add a parameter to configure which class to use for evaluation
if ~isfield(Config, 'EvaluationClassName')
Config.EvaluationClassName='SpeedEvaluation2Class';
end
% change the default values for SubtractBackground
if Config.SubtractBackground.BallRadius==20
Config.SubtractBackground=struct('BallRadius',30,'Smoothe',1);
end
Config.Version=1.8;
end
if Config.Version<1.9
%Add a parameter that stores when the stack was imaged
if ~isfield(Config, 'AcquisitionDate')
Config.AcquisitionDate='';
end
Config.Version=1.9;
end
if Config.Version<1.914
%Add a parameter that stores info about evaluation
if ~isfield(Config, 'Evaluation')
Config.Evaluation=struct('EvalClassNo',2,...
'EvalClassNames',{{...
'SpeedEvaluationClass',...
'SpeedEvaluation2Class',...
'BundlingEvaluationClass'}});
end
Config.Version=1.914;
end
if Config.Version<1.915
%Add a parameter that stores info about evaluation
if ~isfield(Config.Evaluation, 'TasksNeeded')
Config.Evaluation.TasksNeeded={...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true),...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true),...
struct('Track',true,'Connect',false,'Fit',false,'Evaluate',true,'Overview',true)};
end
if ~isfield(Config.Evaluation, 'NeedsWholeStack')
Config.Evaluation.NeedsWholeStack={false,false,true};
end
if ~isfield(Config, 'Tasks')
Config.Tasks=Config.Evaluation.TasksNeeded{Config.Evaluation.EvalClassNo};
end
Config.Version=1.915;
end
if Config.Version<1.916
if ~isfield(Config.Evaluation, 'NeedsWholeStack')
Config.Evaluation.NeedsWholeStack={false,false,true};
end
Config.Evaluation.EvalClassNames=[Config.Evaluation.EvalClassNames,...
'Speed2TempEvaluationClass'];
Config.Evaluation.TasksNeeded=[Config.Evaluation.TasksNeeded,...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true)];
Config.Evaluation.NeedsWholeStack=[Config.Evaluation.NeedsWholeStack,false];
Config.Version=1.916;
end
if Config.Version<1.917
%Add a evaluation class for Screening evaluation
Config.Evaluation.EvalClassNames=[Config.Evaluation.EvalClassNames,...
'SpeedJannesEvaluationClass'];
Config.Evaluation.TasksNeeded=[Config.Evaluation.TasksNeeded,...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true)];
Config.Evaluation.NeedsWholeStack=[Config.Evaluation.NeedsWholeStack,false];
Config.Version=1.917;
end
if Config.Version<1.918
%Add a evaluation class for movie evaluation
Config.Evaluation.EvalClassNames=[Config.Evaluation.EvalClassNames,...
'MakeMovieEvaluationClass'];
for n=1:length(Config.Evaluation.TasksNeeded)
Config.Evaluation.TasksNeeded{n}.Avi=false;
end
Config.Evaluation.TasksNeeded{end+1}=...
struct('Track',false,'Connect',false,'Fit',false,'Evaluate',true,'Overview',false,'Avi',true);
Config.Evaluation.NeedsWholeStack=[Config.Evaluation.NeedsWholeStack,true];
Config.Tasks=Config.Evaluation.TasksNeeded{Config.Evaluation.EvalClassNo};
Config.ImageScaling = struct('Modes',{{'auto','manual'}},'ModeNo',1,'Black',0,'White',0);
Config.Version=1.918;
end
if Config.Version<2.0
Config.LegacyData = true;
%Add a evaluation class for biocomputation junction evaluation
Config.Evaluation.EvalClassNames=[Config.Evaluation.EvalClassNames,...
'BioCompEvaluationClass'];
Config.Evaluation.TasksNeeded=[Config.Evaluation.TasksNeeded,...
struct('Track',true,'Connect',true,'Fit',false,'Evaluate',true,'Overview',true,'Avi',false)];
Config.Evaluation.NeedsWholeStack=[Config.Evaluation.NeedsWholeStack,true];
Config.Version=2.0;
end
if Config.Version < 2.01
Config = ConfigClass.upgradeNeedsWholeStack(Config);
Config.Version = 2.01;
end
if Config.Version < 2.02
Config.LegacyData = true;
%Add a evaluation class for dilution series evaluation
Config.Evaluation.EvalClassNames=[Config.Evaluation.EvalClassNames,...
'DilutionSeriesEvaluationClass'];
Config.Evaluation.TasksNeeded=[Config.Evaluation.TasksNeeded,...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false)];
Config.Evaluation.ImagesNeeded=[Config.Evaluation.ImagesNeeded,true];
Config.Version=2.02;
end
if Config.Version < 2.03
Config.LegacyData = true;
%Add a evaluation class for dilution series evaluation
Config.Evaluation.EvalClassNames=[Config.Evaluation.EvalClassNames,...
'AngleEvaluationClass'];
Config.Evaluation.TasksNeeded=[Config.Evaluation.TasksNeeded,...
struct('Track',true,'Connect',true,'Fit',true,'Evaluate',true,'Overview',true,'Avi',false)];
Config.Evaluation.ImagesNeeded=[Config.Evaluation.ImagesNeeded,true];
Config.Version=2.03;
end
end
function Config = upgradeNeedsWholeStack(Config)
if isfield(Config.Evaluation, 'NeedsWholeStack')
for n = 1:length(Config.Evaluation.NeedsWholeStack)
if Config.Evaluation.NeedsWholeStack{n}
Config.Evaluation.ImagesNeeded{n} = Inf;
else
Config.Evaluation.ImagesNeeded{n} = 1;
end
end
Config.Evaluation.ImagesNeeded{7} = inf;
Config.Evaluation = rmfield(Config.Evaluation, 'NeedsWholeStack');
end
end
function Config=validate(C,Config)
if isstruct(Config)
if isfield(Config,'Version')
%use the proper upgrade routine if we know the version of the
%configuration
Config=ConfigClass.upgrade(Config);
elseif isfield(Config,'StackType') && strcmpi(Config.StackType,'TIFF') ...
&& isempty(Config.FileName) && ~isempty(Config.Directory)
%for old configs, we need to fix the stack name for many tiff
%files
Config.FileName=Config.StackName;
separators=strfind(Config.Directory,'/');
if isempty(separators) %if the directory was saved under windows
separators=strfind(Config.Directory,'\');
end
Config.StackName=Config.Directory(separators(end-2)+1:separators(end-1)-1);
end
%check the two Config structures for consistency
try
equal=strcmp(fieldnames(Config),fieldnames(C));
catch
equal=false;
end
if ~all(equal)
notInConfig=setdiff(fieldnames(C),fieldnames(Config));
notInC=setdiff(fieldnames(Config),fieldnames(C));
if ~isempty(notInConfig)
if ~iscell(notInConfig)
notInConfig={notInConfig};
end
fprintf('The field(s) "%s" appear(s) in the config object but not in the imported configuration. Using default value(s).\n',strjoin(notInConfig, ', '));
for j=1:length(notInConfig)
Config.(notInConfig{j})=C.(notInConfig{j});
end
end
if ~isempty(notInC)
if ~iscell(notInC)
notInC={notInC};
end
fprintf('The field(s) "%s" appears in the imported configuration but not in the config object. The extra fields will be ignored. This can happen when you are importing a config from a newer version or from FIESTA.\n',strjoin(notInC,', '));
for j=1:length(notInC)
Config.(notInC{j})=[];
end
end
end
%recursively check substructures
fields=fieldnames(Config);
for i=1:numel(fields)
if isstruct(Config.(fields{i}))
Config.(fields{i})=ConfigClass.validate(C.(fields{i}),Config.(fields{i}));
end
end
else
error('AutoTipTrack:ConfigClass:validate:TypeError','Config parameter must be a structure.');
end
end
end
end