This is a static copy of a profile report

Home

img2slml (1 call, 57700.311 sec)
Generated 05-Nov-2014 07:52:28 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/img2slml.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
demo3D11function1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
428
model = img2model( dimensional...
157691.459 s100.0%
854
make_intermediate_results_from...
18.732 s0.0%
843
save( filename, 'model', '-v7....
10.090 s0.0%
402
dimensionality = varargin{1};
10.010 s0.0%
865
end%img2slml
10 s0%
All other lines  0.020 s0.0%
Totals  57700.311 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
img2modelfunction157691.369 s100.0%
...intermediate_results_from_temp_folderfunction18.722 s0.0%
filesepfunction10 s0%
pwdfunction10 s0%
filepartsfunction10 s0%
isdirfunction10 s0%
datefunction10 s0%
ml_initparamfunction10 s0%
Self time (built-ins, overhead, etc.)  0.220 s0.0%
Totals  57700.311 s100% 
Code Analyzer results
Line numberMessage
155The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
159Best practice is for CATCH to be followed by an identifier that gets the error information.
176Best practice is for CATCH to be followed by an identifier that gets the error information.
185The value assigned to variable 'dislpay' might be unused.
187Best practice is for CATCH to be followed by an identifier that gets the error information.
198Best practice is for CATCH to be followed by an identifier that gets the error information.
211The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
227The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
231Best practice is for CATCH to be followed by an identifier that gets the error information.
239The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
243Best practice is for CATCH to be followed by an identifier that gets the error information.
250Best practice is for CATCH to be followed by an identifier that gets the error information.
267Best practice is for CATCH to be followed by an identifier that gets the error information.
295Best practice is for CATCH to be followed by an identifier that gets the error information.
306Best practice is for CATCH to be followed by an identifier that gets the error information.
317Best practice is for CATCH to be followed by an identifier that gets the error information.
382The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
436The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
465Best practice is for CATCH to be followed by an identifier that gets the error information.
476Best practice is for CATCH to be followed by an identifier that gets the error information.
488Best practice is for CATCH to be followed by an identifier that gets the error information.
501Best practice is for CATCH to be followed by an identifier that gets the error information.
512Best practice is for CATCH to be followed by an identifier that gets the error information.
525Best practice is for CATCH to be followed by an identifier that gets the error information.
543Best practice is for CATCH to be followed by an identifier that gets the error information.
554Best practice is for CATCH to be followed by an identifier that gets the error information.
569Best practice is for CATCH to be followed by an identifier that gets the error information.
588Best practice is for CATCH to be followed by an identifier that gets the error information.
599Best practice is for CATCH to be followed by an identifier that gets the error information.
610Best practice is for CATCH to be followed by an identifier that gets the error information.
646Best practice is for CATCH to be followed by an identifier that gets the error information.
655Best practice is for CATCH to be followed by an identifier that gets the error information.
664Best practice is for CATCH to be followed by an identifier that gets the error information.
674Best practice is for CATCH to be followed by an identifier that gets the error information.
684Best practice is for CATCH to be followed by an identifier that gets the error information.
693Best practice is for CATCH to be followed by an identifier that gets the error information.
705Best practice is for CATCH to be followed by an identifier that gets the error information.
714Best practice is for CATCH to be followed by an identifier that gets the error information.
725Best practice is for CATCH to be followed by an identifier that gets the error information.
740Best practice is for CATCH to be followed by an identifier that gets the error information.
749Best practice is for CATCH to be followed by an identifier that gets the error information.
758Best practice is for CATCH to be followed by an identifier that gets the error information.
768Best practice is for CATCH to be followed by an identifier that gets the error information.
781For better readability, use newline, semicolon, or comma before this statement.
782The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
789Best practice is for CATCH to be followed by an identifier that gets the error information.
791The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
815Best practice is for CATCH to be followed by an identifier that gets the error information.
830Assignment to 'filename' might be unnecessary.
844Best practice is for CATCH to be followed by an identifier that gets the error information.
Coverage results
[ Show coverage for parent directory ]
Total lines in function865
Non-code lines (comments, blank lines)356
Code lines (lines that can run)509
Code lines that did run123
Code lines that did not run386
Coverage (did run/can run)24.17 %
Function listing
   time   calls  line
1 function answer = img2slml( varargin )
2 % IMG2SLML Trains a generative model of protein subcellular location from a
3 % collection of microscope images and saves the model as an SLML instance. An SLML model
4 % consists of four components, a (optional) documentation component, a nuclear pattern model,
5 % a cell pattern model and a protein pattern model. The input argument param holds the valid
6 % options for these components.
7 %
8 % Arguments Description
9 % --------- ------------
10 % dimensionality 2D/3D
11 % dnaImagesDirectoryPath DNA images collection directory
12 % cellImagesDirectoryPath Cell images collection directory
13 % proteinImagesDirectoryPath Protein images collection directory
14 % param Parameter structure
15 %
16 % The shape of param is described
17 %
18 % List Of Parameters Descriptions
19 % ------------------ ------------
20 % documentation (optional)
21 % ------------------------
22 % This is an optional structure with multiple elements that holds documentation about this model.
23 %
24 % documentation.<name> Holds the value of variable <name>. This is meant to be meta information. Default is empty.
25 %
26 % generic model options
27 % ---------------------
28 % model.name (optional) Holds the name of the model. Default is empty.
29 % model.id (optional) Holds the id of the model. Default is empty.
30 % model.filename Holds the output filename.
31 % model.resolution Model resolution (in microns per pixel). This
32 % the resolution of the dataset used to train the model
33 % model.downsampling Downsampling vector used during preprocessing. Default value is
34 % [5 5 1]. Final model resolution will be resolution * downsampling
35 % vector and will be saved in the model as well
36 %
37 % nuclear shape model options
38 % ---------------------------
39 % nucleus.type Holds the nuclear model type. Default is
40 % "medial axis" for 2D and "major axis" for 3D
41 % nucleus.name (optional) Holds the name of the nuclear model. Default is empty.
42 % nucleus.id (optional) Holds the id of the nuclear model. Default is empty.
43 %
44 % cell shape model options
45 % ------------------------
46 % cell.type Holds the cell model type. Default is "ratio".
47 % cell.name (optional) Holds the name of the cell model. Default is empty.
48 % cell.id (optional) Holds the id the cell model. Default is empty.
49 %
50 % protein shape model options
51 % ---------------------------
52 % protein.type (optional) Holds the protein model type. The default is "vesicle".
53 % protein.name (optional) Holds the name of the protein model. The default is empty.
54 % protein.id (optional) Holds the id of the protein model. The default is empty.
55 % protein.class Holds the protein class, e.g. lysosome, endosome.
56 % protein.cytonuclearflag (optional) Determines whether the protein pattern will be generated in
57 % the cytosolic space ('cyto'), nuclear space ('nuc') or everywhere ('all').
58 % Default is cyto.
59 %
60 % other options
61 % -------------
62 % verbose (optional) Displays messages to screen. Default is true.
63 % debug (optional) Reports errors and warnings. Default is false.
64 % train.flag (optional) Selects what model is going to be trained ('nuclear',
65 % 'framework', or 'all'). Default is 'all'.
66 % masks (optional) A string with
67
68 % Author: Ivan E. Cao-Berg (icaoberg@cmu.edu)
69 %
70 % Copyright (C) 2007-2014 Murphy Lab
71 % Lane Center for Computational Biology
72 % School of Computer Science
73 % Carnegie Mellon University
74 %
75 % March 9, 2012 I. Cao-Berg Added documentation and updated license file
76 % March 9, 2012 I. Cao-Berg Added new input argument list for CellOrganizer but also
77 % kept backward compatibility with SLML Toolbox
78 % March 9, 2012 I. Cao-Berg Removed output argument model.
79 % March 28, 2012 I. Cao-Berg Added a control structure under which if img2model returns
80 % an empty model structure, the method exits
81 % March 28, 2012 I. Cao-Berg Removed saving of temporary models for debugging purposes and
82 % added backward compatibility mode message to screen
83 % March 28, 2012 I. Cao-Berg Added verification of input arguments when running in compatibility
84 % mode (compatible with SLML Tools)
85 % March 28, 2012 I. Cao-Berg Added verification of input arguments when running in default
86 % mode (CellOrganizer)
87 % April 11, 2012 I. Cao-Berg Added debug flag to parameter structure and set the default value
88 % to false
89 % April 17, 2012 I. Cao-Berg Added cytonuclearflag to the protein model
90 % July 3, 2012 M. Mackie Added train.flag to the parameter structure
91 % with the default value of 'all'
92 % July 5, 2012 I. Cao-Berg Fixed a bug where the default value was not set properly
93 % July 9, 2012 I. Cao-Berg Updated code so that when debug flag is set true, it saves the model as a mat file
94 % Fixed bug that replaced the model.id and model.name to the default values
95 % Updated code to include all possible options of the input parameter structure
96 % Nov 9, 2012 D. Sullivan Fixed bug in the param try catch that set
97 % model.cellShapeModel.type to param.nucleus.type instead of param.cell.type
98 % Jan 20, 2013 I. Cao-Berg Removed examples 1 and 2 from documentation.
99 % Users should refer to demos for examples.
100 % Jan 28, 2013 I. Cao-Berg Updated method so that models are saved as mat
101 % files instead of XML models
102 % Jan 30, 2013 I. Cao-Berg Updated code so that parameter display is
103 % always false
104 % Feb. 1, 2013 I. Cao-Berg Method requires model resolution as part of
105 % the parameter structure
106 % Feb 22, 2013 D. Sullivan Changed call to img2model to accept the
107 % updated param structure
108 % Feb 24, 2013 D. Sullivan Added param.model.protein_resolution from
109 % param.model.original_resolution so it can be
110 % adjusted later.
111 % May 2, 2013 I. Cao-Berg Fixed method so that it uses default value
112 % when param.train.flag not recognized
113 % May 9, 2013 I. Cao-Berg Updated method so that if will save the
114 % metadata of the model iff a model exists. This prevents inclusion of
115 % empty model fields
116 % May 17, 2013 I. Cao-Berg Updated methods so that they will save empty fields to SLML instance
117 %
118 % March 17, 2014 I. Cao-Berg Updated method so that 3D nuclear models types
119 % are labelled 'major axis' instead of 'medial axis'
120 % March 19, 2014 I. Cao-Berg Updated demo so that if output filename is a
121 % folder it will create the file model.mat in
122 % that folder. Also if the extension is other
123 % then .mat it will save it as a mat file
124 % April 24, 2014 I. Cao-Berg Fixed bug that was saving the downsampled
125 % resolution to the protein model instead of the
126 % original resolution
127 %
128 % This program is free software; you can redistribute it and/or modify
129 % it under the terms of the GNU General Public License as published
130 % by the Free Software Foundation; either version 2 of the License,
131 % or (at your option) any later version.
132 %
133 % This program is distributed in the hope that it will be useful, but
134 % WITHOUT ANY WARRANTY; without even the implied warranty of
135 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
136 % General Public License for more details.
137 %
138 % You should have received a copy of the GNU General Public License
139 % along with this program; if not, write to the Free Software
140 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
141 % 02110-1301, USA.
142 %
143 % For additional information visit http://murphylab.web.cmu.edu or
144 % send email to murphy@cmu.edu
145
146 %icaoberg 7/3/2013
1 147 answer = false;
148
149 %icaoberg moved upward so it is accesible to all methods
150
151 %checks the contents of the structure holding the parameters
1 152 try
1 153 param = varargin{5};
1 154 if ~isa( param, 'struct' )
155 warning('CellOrganizer: Input parameter list must be a structure.');
156 end
1 157 param.slml.level = '1';
1 158 param.slml.version = '1.1';
159 catch
160 param = [];
161 param.slml.level = '1';
162 param.slml.version = '1.1';
163 param.display = false;
164 param.debug = false;
165 param.verbose = true;
166 end
167
1 168 param = ml_initparam(param, ...
169 struct('saveIntermediateResults', true));
170
1 171 try
1 172 verbose = param.verbose;
1 173 if ~isa( verbose, 'logical' )
174 verbose = true;
175 end
176 catch
177 verbose = true;
178 end
179
180 %D. Sullivan 6/4/13 fixed assignment mismatch bug-verbose was being set
181 %instead of display
1 182 try
1 183 display = param.display;
184 if ~isa( display, 'logical' )
185 dislpay = false;
186 end
1 187 catch
1 188 display = false;
1 189 param.display = display;
1 190 end
191
1 192 try
1 193 debug = param.debug;
1 194 if ~isa( debug, 'logical' )
195 param.debug = false;
196 debug = false;
197 end
198 catch
199 param.debug = false;
200 debug = false;
201 end
202
203 %CHECK INPUT ARGUMENTS
1 204 if length(varargin) == 5
205 %icaoberg march 28, 2012
1 206 dimensionality = varargin{1};
1 207 if ~(strcmpi( dimensionality, '2d' ) || ...
208 strcmpi( dimensionality, '3d' ))
209
210 %icaoberg 7/3/2013
211 warning('Unrecognized or unsupported dimensionality. Exiting method.');
212 return
1 213 else
214 %icaoberg 9/16/2013
1 215 param.dimensionality = dimensionality;
1 216 end
217
1 218 dnaImagesDirectoryPath = varargin{2};
1 219 cellImagesDirectoryPath = varargin{3};
1 220 proteinImagesDirectoryPath = varargin{4};
221
222 %check the contents of param.model
1 223 try
1 224 temp = param.model.name;
225 %icaoberg 7/9/2012
1 226 if ~isa( temp, 'char' )
227 warning(['CellOrganizer: Optional input argument param.model.name must be a string. ' ...
228 'Changing to default value']);
229 param.model.name = '';
230 end
231 catch
232 param.model.name = '';
233 end
234
1 235 try
1 236 temp = param.model.id;
237 %icaoberg 7/9/2012
1 238 if ~isa( temp, 'char' )
239 warning(['CellOrganizer: Optional input argument param.model.id must be a string. ' ...
240 'Changing to default value']);
241 param.model.id = '';
242 end
243 catch
244 param.model.id = '';
245 end
246
247 %icaoberg 06/02/2013
1 248 try
1 249 downsampling = param.model.downsampling;
250 catch
251 if strcmpi( dimensionality, '3D' )
252 downsampling = [5 5 1];
253 else
254 downsampling = [1 1];
255 end
256 end
257
258 % model.resolution
1 259 try
1 260 param.model.original_resolution = param.model.resolution;
261 %D. Sullivan 2/24/13 added param.model.protein_resolution
1 262 param.model.protein_resolution = param.model.original_resolution;
263
1 264 param.model.downsampling = downsampling;
1 265 param.model.resolution = param.model.resolution .* downsampling;
1 266 clear downsampling
267 catch
268 disp('Model resolution not set. Exiting method.');
269
270 answer = false;
271 return
272 end
273
1 274 try
1 275 temp = param.model.filename;
1 276 if ~isa( temp, 'char' )
277 error('CellOrganizer: Input parameter filename must be a string.');
278 end
279 catch err
280 error( 'CellOrganizer: Unable to set output filename' );
281 end
282
283 %check the contents of param.nucleus, param.cell and param.protein
1 284 compartments = { 'nucleus', 'cell', 'protein' };
1 285 fields = { 'type', 'name', 'id' };
1 286 for c=1:1:length(compartments)
3 287 compartment = [ 'param.' compartments{c} ];
3 288 for f=1:1:length(fields)
9 289 field = [ compartment '.' fields{f} ];
9 290 try
9 291 eval(['temp=' field ';']);
5 292 if ~isa( temp, 'char' )
293 eval([field '=''''' ';']);
294 end
4 295 catch
4 296 eval([field '=''''' ';']);
4 297 end
9 298 end
3 299 end
300
1 301 try
1 302 documentation = param.documentation;
1 303 if ~isa( documentation, 'struct' )
304 error('CellOrganizer: Documentation must be a structure.');
305 end
306 catch
307 param.documentation = [];
308 end
309
310 %mmackie july 3, 2012
311 %checking the training flag
1 312 try
1 313 trainFlag = param.train.flag;
1 314 if ~isa( trainFlag, 'char' );
315 error('CellOrganizer: training flag must be a string');
316 end
317 catch
318 param.train.flag = 'all';
319 %icaoberg july 5, 2012
320 trainFlag = param.train.flag;
321 end
322
323 %icaoberg july 5, 2012
1 324 if ~strcmpi( trainFlag, 'nuclear') && ...
325 ~strcmpi( trainFlag, 'framework') && ...
326 ~strcmpi( trainFlag, 'all')
327 if debug
328 disp('CellOrganizer: unrecognized training flag. Using default value.');
329 end
330 trainFlag = 'all';
331 end
332
333 elseif length(varargin) == 10
334 %icaoberg march 28, 2012
335 if verbose
336 fprintf( 1, '%s', 'Entering backward compatibility mode' );
337 end
338
339 dimensionality = varargin{1};
340 if ~strcmpi( dimensionality, '2D' ) || ...
341 ~strcmpi( dimensionality, '3D' )
342 error('CellOrganizer: Unknown or unsupported dimensionality');
343 end
344
345 dnaImagesDirectoryPath = varargin{2};
346 if ~exist( dnaImagesDirectory, 'dir' )
347 error('CellOrganizer: DNA images directory does not exist.')
348 end
349
350 cellImagesDirectoryPath = varargin{3};
351 if ~exist( cellImagesDirectory, 'dir' )
352 error('CellOrganizer: Cell images directory does not exist.')
353 end
354
355 proteinImagesDirectoryPath = varargin{4};
356 if ~exist( proteinImagesDirectory, 'dir' )
357 error('CellOrganizer: Protein images directory does not exist.')
358 end
359
360 modelName = varargin{5};
361 if ~isa( modelName, 'char' )
362 error('CellOrganizer: Model name must be a string.');
363 end
364
365 cellName = varargin{6};
366 if ~isa( cellName, 'char' )
367 error('CellOrganizer: Cell name must be a string.');
368 end
369
370 compartmentName = varargin{7};
371 if ~isa( compartmentName, 'char' )
372 error('CellOrganizer: Compartment name must be a string.');
373 end
374
375 proteinName = varargin{8};
376 if ~isa( proteinName, 'char' )
377 error('CellOrganizer: Protein name must be a string.');
378 end
379
380 documentation = varargin{9};
381 if isempty( documentation )
382 warning('CellOrganizer: Documentation is empty.');
383 elseif ~isa( documentation, 'struct' )
384 error('CellOrganizer: Documentation must be a structure');
385 end
386
387 filename = varargin{10};
388 if isempty( filename )
389 error( 'CellOrganizer: Filename for output SLML instance cannot be empty.');
390 elseif ~isa( filename, 'char' );
391 error( 'CellOrganizer: Filename for output SLML instance must be a string.');
392 end
393 else
394 %there can only be 5 or 10 input arguments
395 error('CellOrganizer: Wrong number of input arguments.');
396 end
397
1 398 if verbose
1 399 fprintf( 1, '%s\n', 'Checking the existence of temporary folder' );
1 400 end
401
0.01 1 402 dimensionality = varargin{1};
403
404 %TRAIN THE GENERATIVE MODEL
1 405 if strcmpi( dimensionality, '2D' )
406 % Train a generative model from a set of images
407 model = img2model( dimensionality, ...
408 dnaImagesDirectoryPath, ...
409 cellImagesDirectoryPath, ...
410 proteinImagesDirectoryPath, param );
411
412 %icaoberg march 28, 2012
413 if isempty( model )
414 disp('CellOrganizer: img2model returned an empty model. Exiting program.')
415 return
416 end
1 417 elseif strcmpi( dimensionality, '3D' )
418
419 %D. Sullivan, 2/22/13 changed varargin{5} to updated param structure
420 %D. Sullivan 5/3/13 changed varargin{2}-nuc to varargin{3}-cell so that
421 %nuclear holefinding will still work
422 % model = img2model( dimensionality, varargin{2},...
423 % param );
1 424 dnaImagesDirectoryPath = varargin{2};
1 425 cellImagesDirectoryPath = varargin{3};
1 426 proteinImagesDirectoryPath = varargin{4};
427
57691.46 1 428 model = img2model( dimensionality, ...
429 dnaImagesDirectoryPath, ...
430 cellImagesDirectoryPath, ...
431 proteinImagesDirectoryPath, ...
432 param );
433
434 %icaoberg march 28, 2012
1 435 if isempty( model )
436 warning( ['CellOrganizer: img2model returned an empty model. ' ...
437 'Exiting program.']);
438 return
439 end
440 else
441 error(['CellOrganizer: Unknown dimensionality ' dimensionality ]);
442 end
443
444 %PARSE GENERATIVE MODEL INTO SLML INSTANCE
1 445 filename = param.model.filename;
1 446 if strcmpi( dimensionality, '2D' );
447 % Convert the trained model into SLML format
448
449 %model2slml( model, modelName, cellName, ...
450 % compartmentName, proteinName, ...
451 % documentation, filename );
452 %July 27, 2012 Y.Yu Added the dimensionality field to the model
453 if ~isfield(model,'dimensionality')
454 model.dimensionality = '2D';
455 end
456
457 %July 27, 2012 Y.Yu Used the new model2slml method to save slml file
458 %model2slml( model, filename );
459
460 % model.name (optional) Holds the name of the model. Default is empty.
461 try
462 if ~isempty( param.model.name )
463 model.name = param.model.name;
464 end
465 catch
466 if debug
467 disp('Model name not set. Ignoring meta data field.')
468 end
469 end
470
471 % model.id (optional) Holds the id of the model. Default is empty.
472 try
473 if ~isempty( param.model.id )
474 model.id = param.model.id;
475 end
476 catch
477
478 if debug
479 disp('Model ID not set. Ignoring meta data field.')
480 end
481 end
482
483 % model.filename Holds the output filename.
484 try
485 if ~isempty( param.model.filename )
486 model.filename = param.model.filename;
487 end
488 catch
489
490 if debug
491 disp('Model filename not set. Ignoring meta data field.')
492 end
493 end
494
495 % nucleus
496 % nucleus.name (optional) Holds the name of the nuclear model. Default is empty.
497 try
498 if ~isempty( param.nucleus.name )
499 model.nuclearShapeModel.name = param.nucleus.name;
500 end
501 catch
502 if debug
503 disp('Nuclear shape model name not set. Ignoring meta data field.')
504 end
505 end
506
507 % nucleus.id (optional) Holds the id of the nuclear model. Default is empty.
508 try
509 if ~isempty( param.nucleus.id )
510 model.nuclearShapeModel.id = param.nucleus.id;
511 end
512 catch
513 if debug
514 disp('Nuclear shape model ID not set. Ignoring meta data field.')
515 end
516 end
517
518 % nucleus.type Holds the nuclear model type. Default is "medial axis"
519 try
520 if ~isempty( param.nucleus.type )
521 model.nuclearShapeModel.type = param.nucleus.type;
522 else
523 model.nuclearShapeModel.type = 'medial axis';
524 end
525 catch
526 if debug
527 disp('Nuclear shape model type not set. Using default: medial axis.')
528 model.nuclearShapeModel.type = 'medial axis';
529 end
530 end
531
532 %at this point the param.model.resolution has been checked and is not
533 %empty and it exists
534 model.nuclearShapeModel.resolution = param.model.resolution;
535
536 % cell
537 % cell.name (optional) Holds the name of the cell model. Default is empty.
538 if strcmpi( param.train.flag, 'framework' ) || strcmpi( param.train.flag, 'all' )
539 try
540 if ~isempty( param.cell.name )
541 model.cellShapeModel.name = param.cell.name;
542 end
543 catch
544 if debug
545 disp('Cell shape model name not set. Ignoring meta data field.')
546 end
547 end
548
549 % cell.id (optional) Holds the id the cell model. Default is empty.
550 try
551 if ~isempty( param.cell.id )
552 model.cellShapeModel.id = param.cell.id;
553 end
554 catch
555 if debug
556 disp('Cell shape model ID not set. Ignoring meta data field.')
557 end
558 end
559
560 % cell.type Holds the cell model type. Default is "ratio".
561 try
562 %DPS 11/9/12 fixed bug setting model.cellShapeModel.type to nucleuse
563 %instead of cell.
564 if ~isempty( para.cell.type )
565 model.cellShapeModel.type = param.cell.type;
566 else
567 model.cellShapeModel.type = 'ratio';
568 end
569 catch
570 if debug
571 disp('Cell shape model type not set. Using default: ratio.')
572 model.cellShapeModel.type = 'ratio';
573 end
574 end
575
576 %at this point the param.model.resolution has been checked and is not
577 %empty and it exists
578 model.cellShapeModel.resolution = param.model.resolution;
579 end
580
581 % protein
582 % protein.name (optional) Holds the name of the protein model. The default is empty.
583 if strcmpi( param.train.flag, 'all' )
584 try
585 if ~isempty( param.protein.name )
586 model.proteinModel.name = param.protein.name;
587 end
588 catch
589 if debug
590 disp('Protein shape model name not set. Ignoring meta data field.')
591 end
592 end
593
594 % protein.id (optional) Holds the id of the protein model. The default is empty.
595 try
596 if ~isempty( param.protein.id )
597 model.proteinModel.id = param.protein.id;
598 end
599 catch
600 if debug
601 disp('Protein shape model ID not set. Ignoring meta data field.')
602 end
603 end
604
605 % protein.type (optional) Holds the protein model type. The default is "vesicle".
606 try
607 if ~isempty( param.protein.type )
608 model.proteinModel.type = param.protein.type;
609 end
610 catch
611 if debug
612 disp('Protein shape model type not set. Using default: vesicle.')
613 model.proteinModel.type = 'vesicle';
614 end
615 end
616
617 %at this point the param.model.resolution has been checked and is not
618 %empty and it exists
619 model.proteinModel.resolution = param.model.resolution;
620 end
621
622 %icaoberg 9/10/2013
623 %this helper method transforms the files in the temporary folder into
624 %intermediate results
625 disp( 'Building intermediate results' );
626 make_intermediate_results_from_temp_folder( param );
627
628 %icaoberg 9/10/2013
629 %removes temp folder if debug set to true
630 if ~debug
631 disp( 'Removing temporary folder' );
632 rmdir( [ pwd filesep 'temp' ], 's' );
633 end
634
635 %July 26, 2012 Y.Yu Save the result as mat file instead of xml file
636 save( [filename(1:end-3) 'mat'], 'model' );
637 answer = true;
1 638 else
639 % Conversion of the trained model into SLML format
640 % unsupported for 3D models in the current version.
1 641 model.dimensionality = dimensionality;
642
643 % model.name (optional) Holds the name of the model. Default is empty.
1 644 try
1 645 model.name = param.model.name;
646 catch
647 if debug
648 disp('Model name not set. Ignoring meta data field.')
649 end
650 end
651
652 % model.id (optional) Holds the id of the model. Default is empty.
1 653 try
1 654 model.id = param.model.id;
655 catch
656 if debug
657 disp('Model ID not set. Ignoring meta data field.')
658 end
659 end
660
661 % model.filename Holds the output filename.
1 662 try
1 663 model.filename = param.model.filename;
664 catch
665 if debug
666 disp('Model filename not set. Ignoring meta data field.')
667 end
668 end
669
670 % nucleus
671 % nucleus.name (optional) Holds the name of the nuclear model. Default is empty.
1 672 try
1 673 model.nuclearShapeModel.name = param.nucleus.name;
674 catch
675 if debug
676 disp('Nuclear shape model name not set. Ignoring meta data field.')
677 end
678 end
679
680
681 % nucleus.id (optional) Holds the id of the nuclear model. Default is empty.
1 682 try
1 683 model.nuclearShapeModel.id = param.nucleus.id;
684 catch
685 if debug
686 disp('Nuclear shape model ID not set. Ignoring meta data field.')
687 end
688 end
689
690 % nucleus.type Holds the nuclear model type. Default is "medial axis"
1 691 try
1 692 model.nuclearShapeModel.type = param.nucleus.type;
693 catch
694 if debug
695 disp('Nuclear shape model type not set. Using default: major axis.')
696 model.nuclearShapeModel.type = 'major axis';
697 end
698 end
699
1 700 if strcmpi( trainFlag, 'framework' ) || strcmpi( trainFlag, 'all' )
701 % cell
702 % cell.name (optional) Holds the name of the cell model. Default is empty.
1 703 try
1 704 model.cellShapeModel.name = param.cell.name;
705 catch
706 if debug
707 disp('Cell shape model name not set. Ignoring meta data field.')
708 end
709 end
710
711 % cell.id (optional) Holds the id the cell model. Default is empty.
1 712 try
1 713 model.cellShapeModel.id = param.cell.id;
714 catch
715 if debug
716 disp('Cell shape model ID not set. Ignoring meta data field.')
717 end
718 end
719
720 % cell.type Holds the cell model type. Default is "ratio".
1 721 try
722 %DPS 11/9/12 fixed bug setting model.cellShapeModel.type to nucleuse
723 %instead of cell.
1 724 model.cellShapeModel.type = param.cell.type;
725 catch
726 if debug
727 disp('Cell shape model type not set. Using default: ratio.')
728 model.cellShapeModel.type = 'ratio';
729 end
730 end
1 731 end
732
1 733 if strcmpi( trainFlag, 'all' )
734 % protein
735 % protein.name (optional) Holds the name of the protein model. The default is empty.
736 try
737 if isfield( param.protein, 'name' ) && ~isempty( param.protein.name )
738 model.proteinShape.name = param.protein.name;
739 end
740 catch
741 if debug
742 disp('Protein shape model name not set. Ignoring meta data field.')
743 end
744 end
745
746 % protein.id (optional) Holds the id of the protein model. The default is empty.
747 try
748 model.proteinShape.id = param.protein.id;
749 catch
750 if debug
751 disp('Protein shape model ID not set. Ignoring meta data field.')
752 end
753 end
754
755 % protein.type (optional) Holds the protein model type. The default is "vesicle".
756 try
757 model.proteinShape.type = param.protein.type;
758 catch
759 if debug
760 disp('Protein shape model type not set. Using default: vesicle.')
761 model.proteinShapeModel.type = 'vesicle';
762 end
763 end
764
765 % protein.class Holds the protein class, e.g. lysosome, endosome.
766 try
767 model.proteinShape.class = param.protein.class;
768 catch
769 if debug
770 disp('Protein shape model class not set. Ignoring meta data field.')
771 end
772 end
773
774 % protein.cytonuclearflag (optional) Determines whether the protein pattern will be generated in
775 % the cytosolic space ('cyto'), nuclear space ('nuc') or everywhere ('all').
776 % Default is cyto.
777 try
778 flag = param.protein.cytonuclearflag;
779 if ~strcmpi( flag, 'cyto' ) && ~strcmpi( flag, 'nuc' ) ...
780 ... & ~strcmpi( flag, 'all' )
781 if debug
782 warning('Protein shape model cytonuclear flag is unrecognized. Using default: cyto.');
783 end
784 flag = 'cyto';
785 end
786
787 model.proteinShape.cytonuclearflag = flag;
788 clear flag;
789 catch
790 if debug
791 warning( 'Protein shape model cytonuclear flag not set. Using default: cyto.');
792 end
793 model.proteinShape.cytonuclearflag = 'cyto';
794 end
795
796 %set model dimensionality
797 model.proteinShape.dimensionality = dimensionality;
798
799 %dpsulliv 2/24/13
800 %There are no assumptions of similar resolution, therefore there
801 %must be separate resolutions tracked for framework and protein
802 model.nuclearShapeModel.resolution = param.model.resolution;
803 model.cellShapeModel.resolution = param.model.resolution;
804
805 %icaoberg 4/23/2014
806 %included missing protein shape resolution;
807 %fixed bug where it was saving the wrong resolution. it was saving
808 %the downsampled resolution instead of the protein resolution
809 model.proteinShape.resolution = param.model.protein_resolution;
810 end
811
1 812 try
1 813 model.documentation = param.documentation;
1 814 model.documentation.date = date;
815 catch
816 model.documentation.date = date;
817 end
818
819 %icaoberg 3/19/2014
1 820 if isdir( filename )
821 if strcmpi( filename(end), filesep )
822 filename = [ filename 'model.mat' ];
823 else
824 filename = [ filename filesep 'model.mat' ];
825 end
1 826 else
1 827 [ path, name, extension ] = fileparts( filename );
828
1 829 if strcmpi( extension, '.mat' )
830 filename = filename;
1 831 else
1 832 if isempty( path )
1 833 filename = [ pwd filesep name '.mat' ];
834 else
835 filename = [ path filesep name '.mat' ];
836 end
1 837 end
1 838 end
839
840 %icaoberg 3/19/2014
841 %to make it work with older versions of matlab
1 842 try
0.09 1 843 save( filename, 'model', '-v7.3' );
844 catch
845 save( filename, 'model' );
846 end
847
1 848 answer = true;
849
850 %icaoberg 9/10/2013
851 %this helper method transforms the files in the temporary folder into
852 %intermediate results
1 853 if param.saveIntermediateResults
8.73 1 854 make_intermediate_results_from_temp_folder( param );
1 855 end
856 %icaoberg 9/10/2013
857 %removes temp folder if debug set to true
1 858 if ~debug
859 disp( 'Removing temporary folder' );
860 rmdir( [ pwd filesep 'temp' ], 's' );
861 end
862
863
1 864 end%3D
1 865 end%img2slml