Skip to content

Commit

Permalink
cellorganizer v2.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tCeZ committed Apr 28, 2021
1 parent 968f80c commit fbb28dc
Show file tree
Hide file tree
Showing 20 changed files with 942 additions and 636 deletions.
3 changes: 3 additions & 0 deletions demos/3D/demo3D61/comparemodels.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
options = struct('verbose',true,'includenuclear',true, ...
'includecell',true,'includeprot',true,'hd_threshold',10);
slml2report('images1to5/model.mat','images11to15/model.mat',options);
2 changes: 2 additions & 0 deletions demos/3D/demo3D61/demo3D61.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
options.labels{length(options.labels)+1} = 'LAMP2';
options.masks{i} = [directory filesep 'LAM_cell' num2str(i) '_mask_t1.tif'];
end
disp(dna_paths)
pause

%set the dimensionality
dimensionality = '3D';
Expand Down
178 changes: 178 additions & 0 deletions img2shapespace.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
function answer = img2shapespace(varargin)
% img2shapespace.m
%
% Train 3D generative SPHARM-RPDM cell shape model and creates a report
% using the trained model.
%
% Input
% -----
% * a directory of raw or synthetic cell shape images (cell shapes file
% format 'LAM_cell[1-9]_ch1_t1.tif') or OME.TIFFs
% * an options structure to override default options
% see http://www.cellorganizer.org/docs/2.9.0/chapters/cellorganizer_options.html#img2slml
% important options include
% .model.name for name of the model itself
% .model.filename for name of the file in which to store the model
% .model.resolution for setting image/model pixel size
% .downsampling for setting downsampling before model building
% .shape_evolution for setting whether report includes example
% shape evolution
%
% Output
% ------
% * a valid SLML model file
% * a report with an embedded shape space

% Soham Chakraborti (sohamc@andrew.cmu.edu)
% R.F. Murphy (murphy@cmu.edu)
%
% Copyright (C) 2020 Murphy Lab
% Computational Biology Department
% School of Computer Science
% Carnegie Mellon University
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published
% by the Free Software Foundation; either version 2 of the License,
% or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
% 02110-1301, USA.
%
% For additional information visit http://murphylab.cbd.cmu.edu or
% send email to murphy@cmu.edu
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if isdeployed()
%when method is deployed
if length(varargin) == 1
text_file = varargin{1};
else
error('Deployed function takes only 1 argument. Exiting method.');
return
end

[filepath, name, ext] = fileparts(text_file);

if ~exist(text_file, 'file')
warning('Input file does not exist. Exiting method.');
return
end

disp(['Attempting to read input file ' text_file]);
fid = fopen(text_file, 'r' );

disp('Evaluating lines from input file');
while ~feof(fid)
line = fgets(fid);
disp(line);
try
eval(line);
catch err
disp('Unable to parse line');
getReport(err)
return
end
end
fclose(fid);

if ~exist('options', 'var')
options = {};
end
else
if nargin == 2
dnaImagesDirectoryPath = varargin{1};
cellImagesDirectoryPath = varargin{2};
options = struct([]);
else
dnaImagesDirectoryPath = varargin{1};
cellImagesDirectoryPath = varargin{2};
options = varargin{3};
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% img2slml %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defaultoptions = struct();
defaultoptions.verbose = false;
defaultoptions.debug = false;
defaultoptions.display = false;
defaultoptions.model.id = uuidgen();
%is this needed? what does it do?
defaultoptions.train = struct( 'flag', 'cell' );
defaultoptions.cell.class = 'cell_membrane';
defaultoptions.cell.type = 'spharm_rpdm';
defaultoptions.labels = 'unique';

options = ml_initparam( options, defaultoptions);

if ~isfield(options,'model.filename')
options.model.filename = [options.model.name '.mat'];
end

if ~isfield(options,'model.resolution')
disp ('No resolution specified for the input images;')
disp ('Using default of [0.1, 0.1, 0.1]');
% this is the resolution of the input image
options.model.resolution = [0.1, 0.1, 0.1];
end

if ~isfield(options,'downsampling')
disp ('No downsampling specified prior to model creation;')
disp ('Using default of no downsampling');
options.downsampling = [1, 1, 1];
end

% postprocess of parameterization: alignment
options.model.spharm_rpdm.postprocess = ~false;
% alignment method: 'major_axis' or 'foe'
options.model.spharm_rpdm.alignment_method = 'major_axis';
% plane of rotation: 'xy', 'xz', 'yz' or 'xyz'
options.model.spharm_rpdm.rotation_plane = 'xy';

% degree of the descriptor
options.model.spharm_rpdm.maxDeg = 31;

% latent dimension for the model
options.model.spharm_rpdm.latent_dim = 15;
options.model.spharm_rpdm.segmindnaImagesDirectoryPathfraction = 0.1;

if exist(dnaImagesDirectoryPath,'var') && ~isempty(dnaImagesDirectoryPath)
options.model.name = 'SPHARM-RPDM-NucCellShapeModel';
options.dnaImagesDirectoryPathleus.class = 'nuc_membrane';
options.dnaImagesDirectoryPathleus.type = 'spharm_rpdm';
options.model.spharm_rpdm.components = {'nuc', 'cell'};
else
options.model.spharm_rpdm.components = {'cell'};
options.model.name = 'SPHARM-RPDM-CellShapeModel';
end

tic; answer = img2slml( '3D', dnaImagesDirectoryPath, ...
cellImagesDirectoryPath, [], options ); toc,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if exist( [pwd filesep options.model.filename] )
answer = slml2info( {[pwd filesep options.model.filename]}, options );

if exist( ['./' options.model.name '-report'])
rmdir(['./' options.model.name '-report'],'s')
end

try
movefile( './report' , ['./' options.model.name '-report']);
web(['./' options.model.name '-report' filesep 'index.html'])
catch
disp('Couldn''t rename report folder and open report in browser');
end
else
disp ('Failed to find the model file. Exiting application.' );
answer = false;
end
end%img2shapespace
Loading

0 comments on commit fbb28dc

Please sign in to comment.