This is a static copy of a profile reportHome
img2model (1 call, 57691.369 sec)
Generated 05-Nov-2014 07:52:29 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/utilities/img2model.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
img2slml | function | 1 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
307 | percellparam(dna_image_files{i... | 202 | 57685.260 s | 100.0% |  |
414 | model.cellShapeModel = train_c... | 1 | 3.054 s | 0.0% |  |
304 | [startimage, ~, ~, tmpfile] = ... | 202 | 1.662 s | 0.0% |  |
396 | model.nuclearShapeModel = trai... | 1 | 0.601 s | 0.0% |  |
314 | system(['touch ' isdonefile]); | 202 | 0.180 s | 0.0% |  |
All other lines | | | 0.611 s | 0.0% |  |
Totals | | | 57691.369 s | 100% | |
Children (called functions)
Code Analyzer results
Line number | Message |
70 | The value assigned to variable 'nuclearModelImages' might be unused. |
71 | The value assigned to variable 'cellModelImages' might be unused. |
72 | The value assigned to variable 'proteinModelImages' might be unused. |
81 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
104 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
109 | The value assigned to variable 'debug' might be unused. |
110 | The value assigned to variable 'verbose' might be unused. |
116 | Best practice is for CATCH to be followed by an identifier that gets the error information. |
122 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
127 | EXIST with two input arguments is generally faster and clearer than with one input argument. |
151 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
165 | Best practice is for CATCH to be followed by an identifier that gets the error information. |
191 | Use || instead of | as the OR operator in (scalar) conditional statements. |
191 | Use && instead of & as the AND operator in (scalar) conditional statements. |
191 | Use && instead of & as the AND operator in (scalar) conditional statements. |
199 | Use || instead of | as the OR operator in (scalar) conditional statements. |
199 | Use && instead of & as the AND operator in (scalar) conditional statements. |
199 | Use && instead of & as the AND operator in (scalar) conditional statements. |
207 | Use || instead of | as the OR operator in (scalar) conditional statements. |
207 | Use && instead of & as the AND operator in (scalar) conditional statements. |
207 | Use && instead of & as the AND operator in (scalar) conditional statements. |
220 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
227 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
238 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
248 | Use || instead of | as the OR operator in (scalar) conditional statements. |
248 | Use && instead of & as the AND operator in (scalar) conditional statements. |
254 | The value assigned to variable 'numimgs' might be unused. |
285 | Best practice is for CATCH to be followed by an identifier that gets the error information. |
320 | The variable 'cellCounter' appears to change size on every loop iteration. Consider preallocating for speed. |
321 | The variable 'tmpCounter' appears to change size on every loop iteration. Consider preallocating for speed. |
378 | Use || instead of | as the OR operator in (scalar) conditional statements. |
485 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
499 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 505 |
Non-code lines (comments, blank lines) | 250 |
Code lines (lines that can run) | 255 |
Code lines that did run | 100 |
Code lines that did not run | 155 |
Coverage (did run/can run) | 39.22 % |
Function listing
time calls line
1 function model = img2model( dimensionality, varargin )
2 %IMG2MODEL Trains a generative model of protein subcellular location from a
3 %collection of microscope images.
4 %
5 %Inputs
6 %dimensionality either '2D' or '3D'
7 %param a structure holding possible parameter options
8 %
9 %See also IMG2SLML
10
11 % Ivan E. Cao-Berg
12 %
13 % Copyright (C) 2007-2013 Murphy Lab
14 % Carnegie Mellon University
15 %
16 % ?? ??, 2011 I. Cao-Berg Added 3D model training functionality
17 % March 23, 2012 I. Cao-Berg Added the creation/deletion of temporary folder
18 % March 28, 2012 I. Cao-Berg Added a control structure under which if one or more of the
19 % image folders are nonexistent or they do not contain images,
20 % the method exits
21 % March 28, 2012 I. Cao-Berg Added verification of input arguments when training a 2D
22 % generative model
23 % March 28, 2012 I. Cao-Berg Added verification of input arguments when training a 3D
24 % generative model
25 % April 10, 2012 I. Cao-Berg Added debug flag to the method. If flag is true, temporary
26 % files will not be deleted
27 % April 11, 2012 I. Cao-Berg Added verbose flag to the method
28 % April 17, 2012 I. Cao-Berg Returns an empty model when model cannot be trained
29 % July 5, 2012 I. Cao-Berg Added training flags to method so that users can train whatever component they wish
30 % July 26, 2012 Y.Yu Fixed a bug of the order of input argument for ml_traingenmodel2D method
31 % August 29, 2012 G. Johnson Modified method call to include parameter structure
32 % May 7, 2013 I. Cao-Berg Included support of masks when training a model
33 % only for the 2D case
34 % May 8, 2013 I. Cao-Berg Removed check for the existence of image folder since the check will happen later in the code
35 % May 15, 2013 I. Cao-Berg Updated method to support wildcards
36 % June 7-13 2013 D. Sullivan Major refactoring to support parallel/per-cell
37 % parameter calcultaions for 3D
38 %
39 % Jul 22, 2013 G. Johnson Added parameter to skip preprocessing entirely
40 % and use only currently existing preprocessing
41 % results
42 % Aug 2, 2013 G. Johnson Fixed logic so that prot_image_files are not
43 % overwritten by an empty cell array if they exist
44 % Aug 2, 2013 G. Johnson Implemented chunk_start parallelization on
45 % per-cell parameterization
46 % Aug 30, 2013 G. Johnson Changed they way files are input into the
47 % diffeomorphic model function
48 % March 14, 2014 I. Cao-Berg Changed method so that if param.masks is empty
49 % or nonvalid it displays a warning
50 %
51 % This program is free software; you can redistribute it and/or modify
52 % it under the terms of the GNU General Public License as published
53 % by the Free Software Foundation; either version 2 of the License,
54 % or (at your option) any later version.
55 %
56 % This program is distributed in the hope that it will be useful, but
57 % WITHOUT ANY WARRANTY; without even the implied warranty of
58 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
59 % General Public License for more details.
60 %
61 % You should have received a copy of the GNU General Public License
62 % along with this program; if not, write to the Free Software
63 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
64 % 02110-1301, USA.
65 %
66 % For additional information visit http://murphylab.web.cmu.edu/ or
67 % send email to murphy@cmu.edu
68
69 % Get collection of images
1 70 nuclearModelImages = [];
1 71 cellModelImages = [];
1 72 proteinModelImages = [];
73
1 74 model = [];
1 75 switch lower(dimensionality)
1 76 case '2d'
77 %icaoberg march 28, 2012
78 %check number of input arguments. if there are not 5 input
79 %arguments, then the method returns an empty model
80 if nargin ~= 5
81 warning('CellOrganizer: Wrong number of input arguments.');
82 return;
83 end
84
85 %check the image directories. if they don't exist or they are
86 %empty, the method returns an empty model
87 nuclearModelImagesDirectory = varargin{1};
88
89 cellModelImagesDirectory = varargin{2};
90
91 proteinModelImagesDirectory = varargin{3};
92
93 nuclearModelImages = ml_ls( ...
94 nuclearModelImagesDirectory );
95 cellModelImages = ml_ls( ...
96 cellModelImagesDirectory );
97 proteinModelImages = ml_ls( ...
98 proteinModelImagesDirectory );
99
100
101 %check that the input parameter is a structure
102 param = varargin{4};
103 if ~isa( param, 'struct' )
104 warning('CellOrganizer: Input argument parameter must be a struct.');
105 return;
106 end
107
108 %grj 14/5/2013
109 debug = setDebugParam(param);
110 verbose = setVerboseParam(param);
111
112 %icaoberg 7/5/2013
113 try
114 masks = ml_ls( ...
115 param.masks );
116 catch
117 masks = [];
118 end
119
120 %icaoberg 24/3/2014
121 if isempty( masks ) && ~isempty( param.masks )
122 warning( [ 'Directory of masks was defined but method returned ' ...
123 'an empty list. Check the folder ' param.masks ' and try again.'] );
124 end
125
126 %check existence of temporary folder and make on if it doesn't exist
127 if ~exist([pwd filesep 'temp' filesep 'preprocessed'])
128 mkdir([pwd filesep 'temp' filesep 'preprocessed']);
129 end
130
131 % train generative model of protein subcellular location
132 param.disp = 'false';
133 model = ml_traingenmodel2D( ...
134 proteinModelImages,...
135 nuclearModelImages, ...
136 cellModelImages, ...
137 masks, param );
1 138 case '3d'
139 %icaoberg march 28, 2012
140 %check the existence of the image directory
1 141 dnaImagesDirectoryPath = varargin{1};
1 142 cellImagesDirectoryPath = varargin{2};
1 143 proteinImagesDirectoryPath = varargin{3};
1 144 param = varargin{4};
145
1 146 param = ml_initparam(param, ...
147 struct('skip_ls', false));
148
149
1 150 if ~isa( param , 'struct' )
151 warning('CellOrganizer: Input parameter list must be a structure.');
152 return
153 end
154
155 %grj 14/5/2013
1 156 debug = setDebugParam(param);
1 157 verbose = setVerboseParam(param);
158
159 %mmackie july 3 2012
1 160 try
1 161 trainFlag = param.train.flag;
1 162 if ~isa( trainFlag, 'char' );
163 error('CellOrganizer: training flag must be a string');
164 end
165 catch
166 param.train.flag = 'all';
167 trainFlag = param.train.flag;
168 end
169
170 %icaoberg july, 5 2012
1 171 if ~strcmpi( trainFlag, 'nuclear' ) && ...
172 ~strcmpi( trainFlag, 'framework' ) && ...
173 ~strcmpi( trainFlag, 'all' )
174 error('CellOrganizer: Unrecognized training flag');
175 end
176
177 %grj 7/26/13 - Check to see eith cell or nucleus are diffeomorphic
178 % and if so, use the diffeomorphic model
1 179 if (isfield( param, 'nucleus') && isfield( param.nucleus, 'type') && strcmpi(param.nucleus.type, 'diffeomorphic')) ...
180 || (isfield( param, 'cell') && isfield( param.cell, 'type') && strcmpi(param.cell.type, 'diffeomorphic'))
181
182 isdiffeomorphic = true;
1 183 else
1 184 isdiffeomorphic = false;
1 185 end
186
187 %grj 10/24/13 - If these contain characters, retreive filepaths
188 %associated with them, otherwise assume they're function handles
1 189 if isempty(dnaImagesDirectoryPath)
190 dna_image_files = [];
1 191 elseif ischar(dnaImagesDirectoryPath(1)) | (iscell(dnaImagesDirectoryPath) & ischar(dnaImagesDirectoryPath{1})) & ~param.skip_ls
0.06 1 192 dna_image_files = ml_ls( dnaImagesDirectoryPath );
193 else
194 dna_image_files = dnaImagesDirectoryPath;
195 end
196
1 197 if isempty(cellImagesDirectoryPath)
198 cell_image_files = [];
1 199 elseif ischar(cellImagesDirectoryPath(1)) | (iscell(cellImagesDirectoryPath) & ischar(cellImagesDirectoryPath{1})) & ~param.skip_ls
0.05 1 200 cell_image_files = ml_ls( cellImagesDirectoryPath );
201 else
202 cell_image_files = cellImagesDirectoryPath;
203 end
204
1 205 if isempty(proteinImagesDirectoryPath)
206 prot_image_files = [];
1 207 elseif ischar(proteinImagesDirectoryPath(1)) | (iscell(proteinImagesDirectoryPath) & ischar(proteinImagesDirectoryPath{1})) & ~param.skip_ls
0.07 1 208 prot_image_files = ml_ls( proteinImagesDirectoryPath );
209 else
210 prot_image_files = proteinImagesDirectoryPath;
211 end
212
213 %%%%%%%%
214 %D. Sullivan 6/5/13 refactor the code to produce cell
215 %parameterizations first and then create models. Can put this into
216 %separate functions once complete.
217
218 %icaoberg 7/3/2013
1 219 if isempty( dna_image_files )
220 warning('Could not find any images in the DNA images directory. Using DNA hole finding.' );
221 dna_image_files = cell(size(cell_image_files));
222 % model = [];
223 % return
224 end
225
1 226 if isempty( cell_image_files )
227 warning('Could not find any images in the cell images directory. Exiting method.' );
228 model = [];
229 return
230 end
231
232 %grj 8/2/13 fixed logic so that prot_image_files are not
233 %overwritten by an empty cell array if they exist
1 234 if isempty(prot_image_files)
235 if strcmpi(param.train.flag,'framework')
236 prot_image_files = cell(size(cell_image_files));
237 else
238 warning('Could not find any images in the protein images directory. Exiting method.' );
239 model = [];
240 return
241 end
242 end
243
244 %D. Sullivan 6/5/13 get all the masks if they exist
245
1 246 if ~isfield(param, 'masks')
247 mask_image_files = cell(1,length(dna_image_files));
1 248 elseif ischar(param.masks(1)) | (iscell(param.masks) & ischar(param.masks{1}))
0.05 1 249 mask_image_files = ml_ls(param.masks);
250 else
251 mask_image_files = param.masks;
252 end
253
1 254 numimgs = length(cell_image_files);
1 255 param.documentation.numimgs = length(cell_image_files);
1 256 param.documentation.im_cell = cell_image_files;
1 257 param.documentation.im_dna = dna_image_files;
1 258 param.documentation.im_prot = prot_image_files;
1 259 param.documentation.im_mask = mask_image_files;
260
261 %%%%%%
262 %D. Sullivan June/2013 - Refactoring to per-cell oriented feature
263 %extraction
264 %setup param folders
0.01 1 265 param = set_temp_result_folders(param);
1 266 param = ml_initparam(param,struct('downsample',[1,1,1], 'preprocess', true, 'display', false));
267
268 %D. Sullivan 6/7/13-6/13/13
269 %Do all the cells in parallel
270 %GRJ 6/17/13
271 % changed the percellparam_(for/parfor) to work on single
272 % images to improve maintainability
1 273 startmodel = true;
1 274 if param.preprocess
1 275 if ~isfield(param,'parallel') || param.parallel>=1
1 276 try
1 277 matlabpool('open', param.parallel)
278
279 parfor i = 1:param.documentation.numimgs
280 percellparam(dna_image_files{i},cell_image_files{i},...
281 prot_image_files{i},mask_image_files{i}, i, param)
282 end
283 parallelflag = true;
284
1 285 catch
1 286 disp('Parallel code failed, trying linear method');
1 287 parallelflag = false;
1 288 end
289 else
290 parallelflag = false;
291 end
292
293 %grj Implementing chunk_start to perform parallel computing
1 294 if ~parallelflag
1 295 cellCounter = [];
1 296 c = 1;
1 297 for i = 1:param.documentation.numimgs
0.11 202 298 tmpfile = [param.tempparent filesep 'image_lock_' num2str(i)];
299
0.01 202 300 isdonefile = [tmpfile '_done.tmp'];
301
0.11 202 302 if ~exist(isdonefile, 'file')
303
1.66 202 304 [startimage, ~, ~, tmpfile] = chunk_start(tmpfile);
202 305 if startimage
202 306 try
57685.26 202 307 percellparam(dna_image_files{i},cell_image_files{i},...
308 prot_image_files{i},mask_image_files{i}, i, param)
1 309 catch err
1 310 disp(['Skipping image ' num2str(i) ' due to error'])
1 311 getReport( err, 'extended' )
1 312 end
0.11 202 313 chunk_finish(tmpfile)
0.18 202 314 system(['touch ' isdonefile]);
315
316 else
317 disp(['Image ' num2str(i) ' currently being operated on. Skipping.']);
318 startmodel = false;
319
320 cellCounter(c) = i;
321 tmpCounter{c} = tmpfile;
322 c = c+1;
323 end
324
202 325 end
326
0.01 202 327 end
1 328 end
329 else
330 disp('Preprocessing flag set to false. Using only currently existing preprocessing results in the temp directory')
331 end
332
1 333 if ~startmodel
334 %check to see if the tmp files finished just incase
335 if any(cellfun(@(x) exist(x, 'file'), tmpCounter))
336 disp('The following images are still processing:')
337 for i = 1:length(cellCounter)
338 disp([num2str(cellCounter(i)) ': ' tmpCounter{i}])
339 end
340
341 %if the model is diffeomorphic, we can still build
342 %intermediate parts with the data that currently exists
343 if ~isdiffeomorphic
344 model = [];
345 return;
346 end
347
348
349 end
350 end
351
352 %D. Sullivan 6/17/13
353 %With the percell features computed, visualize the distributions of
354 %some interesting parameters
1 355 if isfield(param,'percellreport') && ...
356 (param.percellreport == true || param.percellreport == 1)
357
358 model2report_percell(param);
359 end
360
361 %Now load the relevant files and create single cell arrays for each
362 %compartment
363
364 %D. Sullivan 6/12/13 all this is now taken care of by set_temp_result_folders.m
365 %check existence of temporary folder and make on if it doesn't exist
366 % if ~exist( [ pwd filesep 'temp'], 'dir' )
367 % mkdir( [ pwd filesep 'temp'] );
368 % end
369
1 370 try
371 %icaoberg april 17, 2012
1 372 model.dimensionality = '3D';
373
374 %gj jul 23, 2013 add diffeomorphic model
1 375 if isdiffeomorphic
376
377 diff_model = train_diffeomorphic_model(param);
378 if strcmpi( trainFlag, 'all' ) | strcmpi(trainFlag, 'framework');
379 model.nuclearShapeModel = diff_model;
380 model.cellShapeModel = diff_model;
381 elseif strcmpi(trainFlag, 'nuc')
382 model.nuclearShapeModel = diff_model;
383 elseif strcmpi(trainFlag, 'cell')
384 model.cellShapeModel = diff_model;
385 end
386
1 387 else
1 388 if verbose
389 %clc;
1 390 fprintf( 1, '%s\n', 'Training nuclear shape model' );
1 391 end
392
393 %D. Sullivan 6/12/13 refactored to use per-cell parameters
394 %Nuclear model
1 395 if ~exist([param.tempparent filesep 'nuc_model.mat'],'file')
0.60 1 396 model.nuclearShapeModel = train_nuc_shape_model( param.nuctemppath,...
397 param.tempparent,param );
398 else
399 load([param.tempparent filesep 'nuc_model.mat']);
400 model.nuclearShapeModel = nuclearShapeModel;
401 end
402 %gj aug 29, 2012
403 %passes in 'param' now
404 % model.nuclearShapeModel = train_nuc_shape_model( ...
405 % dnaImagesDirectoryPath, ...
406 % cellImagesDirectoryPath, ...
407 % proteinImagesDirectoryPath, ...
408 % param );
409 %D. Sullivan 6/12/13 refactored to use per-cell features
410 %Cell model
1 411 if strcmpi(param.train.flag,'all')||strcmpi(param.train.flag,'framework')
1 412 fprintf( 1, '%s\n', 'Training cell shape model' );
0.01 1 413 if ~exist([param.tempparent filesep 'cell_shape_model.mat'],'file')
3.05 1 414 model.cellShapeModel = train_cell_shape_model3(param.celltemppath,...
415 param.tempparent);
416 else
417 load([param.tempparent filesep 'cell_shape_model.mat']);
418 model.cellShapeModel = cellShapeModel;
419 end
1 420 end
421 %mmackie july 3, 2012
422 % if strcmpi( trainFlag, 'framework' ) || strcmpi( trainFlag, 'all' )
423 % fprintf( 1, '%s\n', 'Training cell shape model' );
424 % model.cellShapeModel = train_cell_shape_model2( ...
425 % dnaImagesDirectoryPath, ...
426 % cellImagesDirectoryPath, ...
427 % proteinImagesDirectoryPath, ...
428 % param );
429 % end
430
1 431 if strcmpi( trainFlag, 'all' )
432 if verbose
433 %clc;
434 fprintf( 1, '%s\n', 'Training protein model' );
435 end
436 %D. Sullivan 6/12/13 refactored to use percell features
437 %Note: param contains all temp path info already from
438 %set_temp_result_folders.m
439 %Prot model
440 if ~exist([param.tempparent filesep 'protmodel.mat'],'file')
441 model.proteinShape = train_protein_model2( param );
442 else
443 load([param.tempparent filesep 'protmodel.mat']);
444 model.proteinShape = proteinShape;
445 end
446 % %D. Sullivan 2/22/13 added param structure to pass resolution
447 % model.proteinShape = train_protein_model( ...
448 % dnaImagesDirectoryPath, ...
449 % cellImagesDirectoryPath, ...
450 % proteinImagesDirectoryPath, ...
451 % param );
452 end
453
1 454 end
455 %grj 7/9/13 check for fields so the model wont crash
456
457 %icaoberg 22/02/2013
1 458 if isfield(param.model, 'original_resolution')
1 459 model.info.original_resolution = param.model.original_resolution;
460 else
461 model.info.original_resolution = 'n/a';
462 end
463
1 464 if isfield(param.model, 'downsampling')
1 465 model.info.downsampling_vector = param.model.downsampling;
466 else
467 model.info.downsampling_vector = 1;
468 end
469 %D. Sullivan 6/12/13 removed. already set and misspelled
470 % model.nuclearShapeModel = struct('resoluton', param.model.resolution);
1 471 if isfield(param.model, 'resolution')
1 472 model.cellShapeModel.resolution = param.model.resolution;
473 else
474 model.cellShapeModel.resolution = 'n/a';
475 end
476 %D. Sullivan 2/24/2013 This should be set already in
477 %train_protein_model
478 %model.proteinShape.resolution = param.model.protein_resolution;
479
480 catch err
481 %icaoberg april 17, 2012
482 %returns empty model if model cannot be trained
483
484 model = [];
485 warning('CellOrganizer: Unable to train 3D generative model.');
486
487 %icaoberg 06/02/2013
488 if debug
489 getReport( err, 'extended' )
490 end
491
492 if ~debug
493 rmdir( 'temp', 's' );
494 end
495
496 return
497 end
498 otherwise
499 warning(['Unknown dimensionality ' ...
500 dimensionality '. Exiting method.' ]);
501 model = [];
502 return
503 end
504
1 505 end%img2model
Other subfunctions in this file are not included in this listing.