Home > cellorganizer > img2slml.m

img2slml

PURPOSE ^

IMG2SLML Trains a generative model of protein subcellular location from a

SYNOPSIS ^

function answer = img2slml( varargin )

DESCRIPTION ^

 IMG2SLML Trains a generative model of protein subcellular location from a
 collection of microscope images and saves the model as an SLML instance. An SLML model
 consists of four components, a (optional) documentation component, a nuclear pattern model,
 a cell pattern model and a protein pattern model. The input argument param holds the valid
 options for these components.

 Arguments                   Description
 ---------                   ------------
 dimensionality              2D/3D
 dnaImagesDirectoryPath      DNA images collection directory
 cellImagesDirectoryPath     Cell images collection directory
 proteinImagesDirectoryPath  Protein images collection directory
 param                       Parameter structure

 The shape of param is described

 List Of Parameters        Descriptions
 ------------------        ------------
 documentation (optional)
 ------------------------
 This is an optional structure with multiple elements that holds documentation about this model.

 documentation.<name>      Holds the value of variable <name>. This is meant to be meta information. Default is empty.

 generic model options
 ---------------------
 model.name                (optional) Holds the name of the model. Default is empty.
 model.id                  (optional) Holds the id of the model. Default is empty.
 model.filename            Holds the output filename.
 model.resolution          Model resolution (in microns per pixel). This
                           the resolution of the dataset used to train the model
 model.downsampling        Downsampling vector used during preprocessing. Default value is
                           [5 5 1]. Final model resolution will be resolution * downsampling
                           vector and will be saved in the model as well

 nuclear shape model options
 ---------------------------
 nucleus.type              Holds the nuclear model type. Default is "medial axis".
 nucleus.name              (optional) Holds the name of the nuclear model. Default is empty.
 nucleus.id                (optional) Holds the id of the nuclear model. Default is empty.

 cell shape model options
 ------------------------
 cell.type                 Holds the cell model type. Default is "ratio".
 cell.name                 (optional) Holds the name of the cell model. Default is empty.
 cell.id                   (optional) Holds the id the cell model. Default is empty.

 protein shape model options
 ---------------------------
 protein.type              (optional) Holds the protein model type. The default is "vesicle".
 protein.name              (optional) Holds the name of the protein model. The default is empty.
 protein.id                (optional) Holds the id of the protein model. The default is empty.
 protein.class             Holds the protein class, e.g. lysosome, endosome.
 protein.cytonuclearflag   (optional) Determines whether the protein pattern will be generated in
                           the cytosolic space ('cyto'), nuclear space ('nuc') or everywhere ('all').
                           Default is cyto.

 other options
 -------------
 verbose                   (optional) Displays messages to screen. Default is true.
 debug                     (optional) Reports errors and warnings. Default is false.
 train.flag                (optional) Selects what model is going to be trained ('nuclear',
                           'framework', or 'all'). Default is 'all'.
 masks                     (optional) A string with

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function answer = img2slml( varargin )
0002 % IMG2SLML Trains a generative model of protein subcellular location from a
0003 % collection of microscope images and saves the model as an SLML instance. An SLML model
0004 % consists of four components, a (optional) documentation component, a nuclear pattern model,
0005 % a cell pattern model and a protein pattern model. The input argument param holds the valid
0006 % options for these components.
0007 %
0008 % Arguments                   Description
0009 % ---------                   ------------
0010 % dimensionality              2D/3D
0011 % dnaImagesDirectoryPath      DNA images collection directory
0012 % cellImagesDirectoryPath     Cell images collection directory
0013 % proteinImagesDirectoryPath  Protein images collection directory
0014 % param                       Parameter structure
0015 %
0016 % The shape of param is described
0017 %
0018 % List Of Parameters        Descriptions
0019 % ------------------        ------------
0020 % documentation (optional)
0021 % ------------------------
0022 % This is an optional structure with multiple elements that holds documentation about this model.
0023 %
0024 % documentation.<name>      Holds the value of variable <name>. This is meant to be meta information. Default is empty.
0025 %
0026 % generic model options
0027 % ---------------------
0028 % model.name                (optional) Holds the name of the model. Default is empty.
0029 % model.id                  (optional) Holds the id of the model. Default is empty.
0030 % model.filename            Holds the output filename.
0031 % model.resolution          Model resolution (in microns per pixel). This
0032 %                           the resolution of the dataset used to train the model
0033 % model.downsampling        Downsampling vector used during preprocessing. Default value is
0034 %                           [5 5 1]. Final model resolution will be resolution * downsampling
0035 %                           vector and will be saved in the model as well
0036 %
0037 % nuclear shape model options
0038 % ---------------------------
0039 % nucleus.type              Holds the nuclear model type. Default is "medial axis".
0040 % nucleus.name              (optional) Holds the name of the nuclear model. Default is empty.
0041 % nucleus.id                (optional) Holds the id of the nuclear model. Default is empty.
0042 %
0043 % cell shape model options
0044 % ------------------------
0045 % cell.type                 Holds the cell model type. Default is "ratio".
0046 % cell.name                 (optional) Holds the name of the cell model. Default is empty.
0047 % cell.id                   (optional) Holds the id the cell model. Default is empty.
0048 %
0049 % protein shape model options
0050 % ---------------------------
0051 % protein.type              (optional) Holds the protein model type. The default is "vesicle".
0052 % protein.name              (optional) Holds the name of the protein model. The default is empty.
0053 % protein.id                (optional) Holds the id of the protein model. The default is empty.
0054 % protein.class             Holds the protein class, e.g. lysosome, endosome.
0055 % protein.cytonuclearflag   (optional) Determines whether the protein pattern will be generated in
0056 %                           the cytosolic space ('cyto'), nuclear space ('nuc') or everywhere ('all').
0057 %                           Default is cyto.
0058 %
0059 % other options
0060 % -------------
0061 % verbose                   (optional) Displays messages to screen. Default is true.
0062 % debug                     (optional) Reports errors and warnings. Default is false.
0063 % train.flag                (optional) Selects what model is going to be trained ('nuclear',
0064 %                           'framework', or 'all'). Default is 'all'.
0065 % masks                     (optional) A string with
0066 
0067 % Author: Ivan E. Cao-Berg (icaoberg@cmu.edu)
0068 %
0069 % Copyright (C) 2007-2013 Murphy Lab
0070 % Lane Center for Computational Biology
0071 % School of Computer Science
0072 % Carnegie Mellon University
0073 %
0074 % March 9, 2012 I. Cao-Berg Added documentation and updated license file
0075 % March 9, 2012 I. Cao-Berg Added new input argument list for CellOrganizer but also
0076 %               kept backward compatibility with SLML Toolbox
0077 % March 9, 2012 I. Cao-Berg Removed output argument model.
0078 % March 28, 2012 I. Cao-Berg Added a control structure under which if img2model returns
0079 %                            an empty model structure, the method exits
0080 % March 28, 2012 I. Cao-Berg Removed saving of temporary models for debugging purposes and
0081 %                            added backward compatibility mode message to screen
0082 % March 28, 2012 I. Cao-Berg Added verification of input arguments when running in compatibility
0083 %                            mode (compatible with SLML Tools)
0084 % March 28, 2012 I. Cao-Berg Added verification of input arguments when running in default
0085 %                            mode (CellOrganizer)
0086 % April 11, 2012 I. Cao-Berg Added debug flag to parameter structure and set the default value
0087 %                            to false
0088 % April 17, 2012 I. Cao-Berg Added cytonuclearflag to the protein model
0089 % July 3, 2012   M. Mackie   Added train.flag to the parameter structure
0090 %                            with the default value of 'all'
0091 % July 5, 2012 I. Cao-Berg   Fixed a bug where the default value was not set properly
0092 % July 9, 2012 I. Cao-Berg   Updated code so that when debug flag is set true, it saves the model as a mat file
0093 %                            Fixed bug that replaced the model.id and model.name to the default values
0094 %                            Updated code to include all possible options of the input parameter structure
0095 % Nov 9, 2012 D. Sullivan    Fixed bug in the param try catch that set
0096 %                            model.cellShapeModel.type to param.nucleus.type instead of param.cell.type
0097 % Jan 20, 2013 I. Cao-Berg   Removed examples 1 and 2 from documentation.
0098 %                            Users should refer to demos for examples.
0099 % Jan 28, 2013 I. Cao-Berg   Updated method so that models are saved as mat
0100 %                            files instead of XML models
0101 % Jan 30, 2013 I. Cao-Berg   Updated code so that parameter display is
0102 %                            always false
0103 % Feb. 1, 2013 I. Cao-Berg   Method requires model resolution as part of
0104 %                            the parameter structure
0105 % Feb 22, 2013 D. Sullivan   Changed call to img2model to accept the
0106 %                            updated param structure
0107 % Feb 24, 2013 D. Sullivan   Added param.model.protein_resolution from
0108 %                            param.model.original_resolution so it can be
0109 %                            adjusted later.
0110 % May 2, 2013 I. Cao-Berg    Fixed method so that it uses default value
0111 %                            when param.train.flag not recognized
0112 % May 9, 2013 I. Cao-Berg    Updated method so that if will save the
0113 %                            metadata of the model iff a model exists. This prevents inclusion of
0114 %                            empty model fields
0115 % May 17, 2013 I. Cao-Berg   Updated methods so that they will save empty fields to SLML instance
0116 %
0117 % This program is free software; you can redistribute it and/or modify
0118 % it under the terms of the GNU General Public License as published
0119 % by the Free Software Foundation; either version 2 of the License,
0120 % or (at your option) any later version.
0121 %
0122 % This program is distributed in the hope that it will be useful, but
0123 % WITHOUT ANY WARRANTY; without even the implied warranty of
0124 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0125 % General Public License for more details.
0126 %
0127 % You should have received a copy of the GNU General Public License
0128 % along with this program; if not, write to the Free Software
0129 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0130 % 02110-1301, USA.
0131 %
0132 % For additional information visit http://murphylab.web.cmu.edu or
0133 % send email to murphy@cmu.edu
0134 
0135 %icaoberg 7/3/2013
0136 answer = false;
0137 
0138 %icaoberg moved upward so it is accesible to all methods
0139 
0140 %checks the contents of the structure holding the parameters
0141 try
0142     param = varargin{5};
0143     if ~isa( param, 'struct' )
0144         warning('CellOrganizer: Input parameter list must be a structure.');
0145     end
0146     param.slml.level = '1';
0147     param.slml.version = '1.1';
0148 catch
0149     param = [];
0150     param.slml.level = '1';
0151     param.slml.version = '1.1';
0152     param.display = false;
0153     param.debug = false;
0154     param.verbose = true;
0155 end
0156 
0157 try
0158     verbose = param.verbose;
0159     if ~isa( verbose, 'logical' )
0160         verbose = true;
0161     end
0162 catch
0163     verbose = true;
0164 end
0165 
0166 %D. Sullivan 6/4/13 fixed assignment mismatch bug-verbose was being set
0167 %instead of display
0168 try
0169     display = param.display;
0170     if ~isa( display, 'logical' )
0171         dislpay = false;
0172     end
0173 catch
0174     display = false;
0175     param.display = display;
0176 end
0177 
0178 try
0179     debug = param.debug;
0180     if ~isa( debug, 'logical' )
0181         param.debug = false;
0182         debug = false;
0183     end
0184 catch
0185     param.debug = false;
0186     debug = false;
0187 end
0188 
0189 %CHECK INPUT ARGUMENTS
0190 if length(varargin) == 5
0191     %icaoberg march 28, 2012
0192     dimensionality = varargin{1};
0193     if ~(strcmpi( dimensionality, '2d' ) || ...
0194             strcmpi( dimensionality, '3d' ))
0195         
0196         %icaoberg 7/3/2013
0197         warning('Unrecognized or unsupported dimensionality. Exiting method.');
0198         return
0199     else
0200         %icaoberg 9/16/2013
0201         param.dimensionality = dimensionality;
0202     end
0203     
0204     dnaImagesDirectoryPath = varargin{2};
0205     cellImagesDirectoryPath = varargin{3};
0206     proteinImagesDirectoryPath = varargin{4};
0207     
0208     %check the contents of param.model
0209     try
0210         temp = param.model.name;
0211         %icaoberg 7/9/2012
0212         if ~isa( temp, 'char' )
0213             warning(['CellOrganizer: Optional input argument param.model.name must be a string. ' ...
0214                 'Changing to default value']);
0215             param.model.name = '';
0216         end
0217     catch
0218         param.model.name = '';
0219     end
0220     
0221     try
0222         temp = param.model.id;
0223         %icaoberg 7/9/2012
0224         if ~isa( temp, 'char' )
0225             warning(['CellOrganizer: Optional input argument param.model.id must be a string. ' ...
0226                 'Changing to default value']);
0227             param.model.id = '';
0228         end
0229     catch
0230         param.model.id = '';
0231     end
0232     
0233     %icaoberg 06/02/2013
0234     try
0235         downsampling = param.model.downsampling;
0236     catch
0237         if strcmpi( dimensionality, '3D' )
0238             downsampling = [5 5 1];
0239         else
0240             downsampling = [1 1];
0241         end
0242     end
0243     
0244     % model.resolution
0245     try
0246         param.model.original_resolution = param.model.resolution;
0247         %D. Sullivan 2/24/13 added param.model.protein_resolution
0248         param.model.protein_resolution = param.model.original_resolution;
0249         
0250         param.model.downsampling = downsampling;
0251         param.model.resolution = param.model.resolution .* downsampling;
0252         clear downsampling
0253     catch
0254         disp('Model resolution not set. Exiting method.');
0255         
0256         answer = false;
0257         return
0258     end
0259     
0260     try
0261         temp = param.model.filename;
0262         if ~isa( temp, 'char' )
0263             error('CellOrganizer: Input parameter filename must be a string.');
0264         end
0265     catch err
0266         error( 'CellOrganizer: Unable to set output filename' );
0267     end
0268     
0269     %check the contents of param.nucleus, param.cell and param.protein
0270     compartments = { 'nucleus', 'cell', 'protein' };
0271     fields = { 'type', 'name', 'id' };
0272     for c=1:1:length(compartments)
0273         compartment = [ 'param.' compartments{c} ];
0274         for f=1:1:length(fields)
0275             field = [ compartment '.' fields{f} ];
0276             try
0277                 eval(['temp=' field ';']);
0278                 if ~isa( temp, 'char' )
0279                     eval([field '=''''' ';']);
0280                 end
0281             catch
0282                 eval([field '=''''' ';']);
0283             end
0284         end
0285     end
0286     
0287     try
0288         documentation = param.documentation;
0289         if ~isa( documentation, 'struct' )
0290             error('CellOrganizer: Documentation must be a structure.');
0291         end
0292     catch
0293         param.documentation = [];
0294     end
0295     
0296     %mmackie july 3, 2012
0297     %checking the training flag
0298     try
0299         trainFlag = param.train.flag;
0300         if ~isa( trainFlag, 'char' );
0301             error('CellOrganizer: training flag must be a string');
0302         end
0303     catch
0304         param.train.flag = 'all';
0305         %icaoberg july 5, 2012
0306         trainFlag = param.train.flag;
0307     end
0308     
0309     %icaoberg july 5, 2012
0310     if ~strcmpi( trainFlag, 'nuclear') && ...
0311             ~strcmpi( trainFlag, 'framework') && ...
0312             ~strcmpi( trainFlag, 'all')
0313         if debug
0314             disp('CellOrganizer: unrecognized training flag. Using default value.');
0315         end
0316         trainFlag = 'all';
0317     end
0318     
0319 elseif length(varargin) == 10
0320     %icaoberg march 28, 2012
0321     if verbose
0322         fprintf( 1, '%s', 'Entering backward compatibility mode' );
0323     end
0324     
0325     dimensionality = varargin{1};
0326     if ~strcmpi( dimensionality, '2D' ) || ...
0327             ~strcmpi( dimensionality, '3D' )
0328         error('CellOrganizer: Unknown or unsupported dimensionality');
0329     end
0330     
0331     dnaImagesDirectoryPath = varargin{2};
0332     if ~exist( dnaImagesDirectory, 'dir' )
0333         error('CellOrganizer: DNA images directory does not exist.')
0334     end
0335     
0336     cellImagesDirectoryPath = varargin{3};
0337     if ~exist( cellImagesDirectory, 'dir' )
0338         error('CellOrganizer: Cell images directory does not exist.')
0339     end
0340     
0341     proteinImagesDirectoryPath = varargin{4};
0342     if ~exist( proteinImagesDirectory, 'dir' )
0343         error('CellOrganizer: Protein images directory does not exist.')
0344     end
0345     
0346     modelName = varargin{5};
0347     if ~isa( modelName, 'char' )
0348         error('CellOrganizer: Model name must be a string.');
0349     end
0350     
0351     cellName = varargin{6};
0352     if ~isa( cellName, 'char' )
0353         error('CellOrganizer: Cell name must be a string.');
0354     end
0355     
0356     compartmentName = varargin{7};
0357     if ~isa( compartmentName, 'char' )
0358         error('CellOrganizer: Compartment name must be a string.');
0359     end
0360     
0361     proteinName = varargin{8};
0362     if ~isa( proteinName, 'char' )
0363         error('CellOrganizer: Protein name must be a string.');
0364     end
0365     
0366     documentation = varargin{9};
0367     if isempty( documentation )
0368         warning('CellOrganizer: Documentation is empty.');
0369     elseif ~isa( documentation, 'struct' )
0370         error('CellOrganizer: Documentation must be a structure');
0371     end
0372     
0373     filename = varargin{10};
0374     if isempty( filename )
0375         error( 'CellOrganizer: Filename for output SLML instance cannot be empty.');
0376     elseif ~isa( filename, 'char' );
0377         error( 'CellOrganizer: Filename for output SLML instance must be a string.');
0378     end
0379 else
0380     %there can only be 5 or 10 input arguments
0381     error('CellOrganizer: Wrong number of input arguments.');
0382 end
0383 
0384 if verbose
0385     fprintf( 1, '%s\n', 'Checking the existence of temporary folder' );
0386 end
0387 
0388 dimensionality = varargin{1};
0389 
0390 %TRAIN THE GENERATIVE MODEL
0391 if strcmpi( dimensionality, '2D' )
0392     % Train a generative model from a set of images
0393     model = img2model( dimensionality, ...
0394         dnaImagesDirectoryPath, ...
0395         cellImagesDirectoryPath, ...
0396         proteinImagesDirectoryPath, param );
0397     
0398     %icaoberg march 28, 2012
0399     if isempty( model )
0400         disp('CellOrganizer: img2model returned an empty model. Exiting program.')
0401         return
0402     end
0403 elseif strcmpi( dimensionality, '3D' )
0404     
0405     %D. Sullivan, 2/22/13 changed varargin{5} to updated param structure
0406     %D. Sullivan 5/3/13 changed varargin{2}-nuc to varargin{3}-cell so that
0407     %nuclear holefinding will still work
0408     %     model = img2model( dimensionality, varargin{2},...
0409     %         param );
0410     dnaImagesDirectoryPath = varargin{2};
0411     cellImagesDirectoryPath = varargin{3};
0412     proteinImagesDirectoryPath = varargin{4};
0413     
0414     model = img2model( dimensionality, ...
0415         dnaImagesDirectoryPath, ...
0416         cellImagesDirectoryPath, ...
0417         proteinImagesDirectoryPath, ...
0418         param );
0419     
0420     %icaoberg march 28, 2012
0421     if isempty( model )
0422         warning( ['CellOrganizer: img2model returned an empty model. ' ...
0423             'Exiting program.']);
0424         return
0425     end
0426 else
0427     error(['CellOrganizer: Unknown dimensionality ' dimensionality ]);
0428 end
0429 
0430 %PARSE GENERATIVE MODEL INTO SLML INSTANCE
0431 filename = param.model.filename;
0432 if strcmpi( dimensionality, '2D' );
0433     % Convert the trained model into SLML format
0434     
0435     %model2slml( model, modelName, cellName, ...
0436     %    compartmentName, proteinName, ...
0437     %    documentation, filename );
0438     %July 27, 2012 Y.Yu Added the dimensionality field to the model
0439     if ~isfield(model,'dimensionality')
0440         model.dimensionality = '2D';
0441     end
0442     
0443     %July 27, 2012 Y.Yu Used the new model2slml method to save slml file
0444     %model2slml( model, filename );
0445     
0446     % model.name                (optional) Holds the name of the model. Default is empty.
0447     try
0448         if ~isempty( param.model.name )
0449             model.name = param.model.name;
0450         end
0451     catch
0452         if debug
0453             disp('Model name not set. Ignoring meta data field.')
0454         end
0455     end
0456     
0457     % model.id                  (optional) Holds the id of the model. Default is empty.
0458     try
0459         if ~isempty( param.model.id )
0460             model.id = param.model.id;
0461         end
0462     catch
0463         
0464         if debug
0465             disp('Model ID not set. Ignoring meta data field.')
0466         end
0467     end
0468     
0469     % model.filename            Holds the output filename.
0470     try
0471         if ~isempty( param.model.filename )
0472             model.filename = param.model.filename;
0473         end
0474     catch
0475         
0476         if debug
0477             disp('Model filename not set. Ignoring meta data field.')
0478         end
0479     end
0480     
0481     % nucleus
0482     % nucleus.name              (optional) Holds the name of the nuclear model. Default is empty.
0483     try
0484         if ~isempty( param.nucleus.name )
0485             model.nuclearShapeModel.name = param.nucleus.name;
0486         end
0487     catch
0488         if debug
0489             disp('Nuclear shape model name not set. Ignoring meta data field.')
0490         end
0491     end
0492     
0493     % nucleus.id                (optional) Holds the id of the nuclear model. Default is empty.
0494     try
0495         if ~isempty( param.nucleus.id )
0496             model.nuclearShapeModel.id = param.nucleus.id;
0497         end
0498     catch
0499         if debug
0500             disp('Nuclear shape model ID not set. Ignoring meta data field.')
0501         end
0502     end
0503     
0504     % nucleus.type              Holds the nuclear model type. Default is "medial axis"
0505     try
0506         if ~isempty( param.nucleus.type )
0507             model.nuclearShapeModel.type = param.nucleus.type;
0508         else
0509              model.nuclearShapeModel.type = 'medial axis';
0510         end
0511     catch
0512         if debug
0513             disp('Nuclear shape model type not set. Using default: medial axis.')
0514             model.nuclearShapeModel.type = 'medial axis';
0515         end
0516     end
0517     
0518     %at this point the param.model.resolution has been checked and is not
0519     %empty and it exists
0520     model.nuclearShapeModel.resolution = param.model.resolution;
0521     
0522     % cell
0523     % cell.name                 (optional) Holds the name of the cell model. Default is empty.
0524     if strcmpi( param.train.flag, 'framework' ) || strcmpi( param.train.flag, 'all' )
0525         try
0526             if ~isempty( param.cell.name )
0527                 model.cellShapeModel.name = param.cell.name;
0528             end
0529         catch
0530             if debug
0531                 disp('Cell shape model name not set. Ignoring meta data field.')
0532             end
0533         end
0534         
0535         % cell.id                   (optional) Holds the id the cell model. Default is empty.
0536         try
0537             if ~isempty( param.cell.id )
0538                 model.cellShapeModel.id = param.cell.id;
0539             end
0540         catch
0541             if debug
0542                 disp('Cell shape model ID not set. Ignoring meta data field.')
0543             end
0544         end
0545         
0546         % cell.type                 Holds the cell model type. Default is "ratio".
0547         try
0548             %DPS 11/9/12 fixed bug setting model.cellShapeModel.type to nucleuse
0549             %instead of cell.
0550             if ~isempty( para.cell.type )
0551                 model.cellShapeModel.type = param.cell.type;
0552             else
0553                 model.cellShapeModel.type = 'ratio';
0554             end
0555         catch
0556             if debug
0557                 disp('Cell shape model type not set. Using default: ratio.')
0558                 model.cellShapeModel.type = 'ratio';
0559             end
0560         end
0561         
0562         %at this point the param.model.resolution has been checked and is not
0563         %empty and it exists
0564         model.cellShapeModel.resolution = param.model.resolution;
0565     end
0566     
0567     % protein
0568     % protein.name              (optional) Holds the name of the protein model. The default is empty.
0569     if strcmpi( param.train.flag, 'all' )
0570         try
0571             if ~isempty( param.protein.name )
0572                 model.proteinModel.name = param.protein.name;
0573             end
0574         catch
0575             if debug
0576                 disp('Protein shape model name not set. Ignoring meta data field.')
0577             end
0578         end
0579         
0580         % protein.id  (optional) Holds the id of the protein model. The default is empty.
0581         try
0582             if ~isempty( param.protein.id )
0583                 model.proteinModel.id = param.protein.id;
0584             end
0585         catch
0586             if debug
0587                 disp('Protein shape model ID not set. Ignoring meta data field.')
0588             end
0589         end
0590         
0591         % protein.type              (optional) Holds the protein model type. The default is "vesicle".
0592         try
0593             if ~isempty( param.protein.type )
0594                 model.proteinModel.type = param.protein.type;
0595             end
0596         catch
0597             if debug
0598                 disp('Protein shape model type not set. Using default: vesicle.')
0599                 model.proteinModel.type = 'vesicle';
0600             end
0601         end
0602         
0603         %at this point the param.model.resolution has been checked and is not
0604         %empty and it exists
0605         model.proteinModel.resolution = param.model.resolution;
0606      end
0607     
0608     %icaoberg 9/10/2013
0609     %this helper method transforms the files in the temporary folder into
0610     %intermediate results
0611     disp( 'Building intermediate results' );
0612     make_intermediate_results_from_temp_folder( param );
0613     
0614     %icaoberg 9/10/2013
0615     %removes temp folder if debug set to true
0616     if ~debug
0617         disp( 'Removing temporary folder' );
0618         rmdir( [ pwd filesep 'temp' ], 's'  );
0619     end
0620     
0621     %July 26, 2012 Y.Yu Save the result as mat file instead of xml file
0622     save( [filename(1:end-3) 'mat'], 'model' );
0623     answer = true;
0624 else
0625     % Conversion of the trained model into SLML format
0626     % unsupported for 3D models in the current version.
0627     model.dimensionality = dimensionality;
0628     
0629     % model.name                (optional) Holds the name of the model. Default is empty.
0630     try
0631         model.name = param.model.name;
0632     catch
0633         if debug
0634             disp('Model name not set. Ignoring meta data field.')
0635         end
0636     end
0637     
0638     % model.id                  (optional) Holds the id of the model. Default is empty.
0639     try
0640         model.id = param.model.id;
0641     catch
0642         if debug
0643             disp('Model ID not set. Ignoring meta data field.')
0644         end
0645     end
0646     
0647     % model.filename            Holds the output filename.
0648     try
0649         model.filename = param.model.filename;
0650     catch
0651         if debug
0652             disp('Model filename not set. Ignoring meta data field.')
0653         end
0654     end
0655     
0656     % nucleus
0657     % nucleus.name              (optional) Holds the name of the nuclear model. Default is empty.
0658     try
0659         model.nuclearShapeModel.name = param.nucleus.name;
0660     catch
0661         if debug
0662             disp('Nuclear shape model name not set. Ignoring meta data field.')
0663         end
0664     end
0665     
0666     
0667     % nucleus.id                (optional) Holds the id of the nuclear model. Default is empty.
0668     try
0669         model.nuclearShapeModel.id = param.nucleus.id;
0670     catch
0671         if debug
0672             disp('Nuclear shape model ID not set. Ignoring meta data field.')
0673         end
0674     end
0675     
0676     % nucleus.type              Holds the nuclear model type. Default is "medial axis"
0677     try
0678         model.nuclearShapeModel.type = param.nucleus.type;
0679     catch
0680         if debug
0681             disp('Nuclear shape model type not set. Using default: medial axis.')
0682             model.nuclearShapeModel.type = 'medial axis';
0683         end
0684     end
0685     
0686     if strcmpi( trainFlag, 'framework' ) || strcmpi( trainFlag, 'all' )
0687         % cell
0688         % cell.name                 (optional) Holds the name of the cell model. Default is empty.
0689         try
0690             model.cellShapeModel.name = param.cell.name;
0691         catch
0692             if debug
0693                 disp('Cell shape model name not set. Ignoring meta data field.')
0694             end
0695         end
0696         
0697         % cell.id                   (optional) Holds the id the cell model. Default is empty.
0698         try
0699             model.cellShapeModel.id = param.cell.id;
0700         catch
0701             if debug
0702                 disp('Cell shape model ID not set. Ignoring meta data field.')
0703             end
0704         end
0705         
0706         % cell.type                 Holds the cell model type. Default is "ratio".
0707         try
0708             %DPS 11/9/12 fixed bug setting model.cellShapeModel.type to nucleuse
0709             %instead of cell.
0710             model.cellShapeModel.type = param.cell.type;
0711         catch
0712             if debug
0713                 disp('Cell shape model type not set. Using default: ratio.')
0714                 model.cellShapeModel.type = 'ratio';
0715             end
0716         end
0717     end
0718     
0719     if strcmpi( trainFlag, 'all' )
0720         % protein
0721         % protein.name              (optional) Holds the name of the protein model. The default is empty.
0722         try
0723             if isfield( param.protein, 'name' ) && ~isempty( param.protein.name )
0724                 model.proteinShape.name = param.protein.name;
0725             end
0726         catch
0727             if debug
0728                 disp('Protein shape model name not set. Ignoring meta data field.')
0729             end
0730         end
0731         
0732         % protein.id  (optional) Holds the id of the protein model. The default is empty.
0733         try
0734             model.proteinShape.id = param.protein.id;
0735         catch
0736             if debug
0737                 disp('Protein shape model ID not set. Ignoring meta data field.')
0738             end
0739         end
0740         
0741         % protein.type              (optional) Holds the protein model type. The default is "vesicle".
0742         try
0743             model.proteinShape.type = param.protein.type;
0744         catch
0745             if debug
0746                 disp('Protein shape model type not set. Using default: vesicle.')
0747                 model.proteinShapeModel.type = 'vesicle';
0748             end
0749         end
0750         
0751         % protein.class             Holds the protein class, e.g. lysosome, endosome.
0752         try
0753             model.proteinShape.class = param.protein.class;
0754         catch
0755             if debug
0756                 disp('Protein shape model class not set. Ignoring meta data field.')
0757             end
0758         end
0759         
0760         % protein.cytonuclearflag   (optional) Determines whether the protein pattern will be generated in
0761         %                           the cytosolic space ('cyto'), nuclear space ('nuc') or everywhere ('all').
0762         %                           Default is cyto.
0763         try
0764             flag = param.protein.cytonuclearflag;
0765             if ~strcmpi( flag, 'cyto' ) && ~strcmpi( flag, 'nuc' ) ...
0766                     ... & ~strcmpi( flag, 'all' )
0767                     if debug
0768                     warning('Protein shape model cytonuclear flag is unrecognized. Using default: cyto.');
0769                     end
0770                     flag = 'cyto';
0771             end
0772             
0773             model.proteinShape.cytonuclearflag = flag;
0774             clear flag;
0775         catch
0776             if debug
0777                 warning( 'Protein shape model cytonuclear flag not set. Using default: cyto.');
0778             end
0779             model.proteinShape.cytonuclearflag = 'cyto';
0780         end
0781         
0782         %set model dimensionality
0783         model.proteinShape.dimensionality = dimensionality;
0784         
0785         %D. Sullivan 2/24/13
0786         %There are no assumptions of similar resolution, therefore there
0787         %must be separate resolutions tracked for framework and protein
0788         model.nuclearShapeModel.resolution = param.model.resolution;
0789         model.cellShapeModel.resolution = param.model.resolution;
0790     end
0791     
0792     try
0793         model.documentation = param.documentation;
0794         model.documentation.date = date;
0795     catch
0796         model.documentation.date = date;
0797     end
0798     
0799     %icaoberg 9/10/2013
0800     %this helper method transforms the files in the temporary folder into
0801     %intermediate results
0802     make_intermediate_results_from_temp_folder( param );
0803     
0804     %icaoberg 9/10/2013
0805     %removes temp folder if debug set to true
0806     if ~debug
0807         disp( 'Removing temporary folder' );
0808         rmdir( [ pwd filesep 'temp' ], 's'  );
0809     end
0810     
0811     %icaoberg 1/28/2012
0812     save( [filename(1:end-3) 'mat'], 'model' );
0813     answer = true;
0814 end%3D
0815 end%img2slml

Generated on Sun 29-Sep-2013 18:44:06 by m2html © 2005