Home > RAVEN > getIndexes.m

getIndexes

PURPOSE ^

getIndexes

SYNOPSIS ^

function indexes=getIndexes(model,objects, type, returnLogical)

DESCRIPTION ^

 getIndexes
   Retrieves the indexes for a list of reactions or metabolites

   model           a model structure
   objects         either a cell array of IDs, a logical vector with the 
                   same number of elements as metabolites in the model,
                   of a vector of indexes
   type            'rxns', 'mets', or 'genes' depending on what to retrieve
   returnLogical   Sets whether to return a logical array or an array with
                   the indexes (opt, default false)

   indexes         can be a logical array or a double array depending on
                   the value of returnLogical

     Usage: indexes=getIndexes(model,objects, type, returnLogical)

   Rasmus Agren, 2013-02-18

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function indexes=getIndexes(model,objects, type, returnLogical)
0002 % getIndexes
0003 %   Retrieves the indexes for a list of reactions or metabolites
0004 %
0005 %   model           a model structure
0006 %   objects         either a cell array of IDs, a logical vector with the
0007 %                   same number of elements as metabolites in the model,
0008 %                   of a vector of indexes
0009 %   type            'rxns', 'mets', or 'genes' depending on what to retrieve
0010 %   returnLogical   Sets whether to return a logical array or an array with
0011 %                   the indexes (opt, default false)
0012 %
0013 %   indexes         can be a logical array or a double array depending on
0014 %                   the value of returnLogical
0015 %
0016 %     Usage: indexes=getIndexes(model,objects, type, returnLogical)
0017 %
0018 %   Rasmus Agren, 2013-02-18
0019 %
0020 
0021 if nargin<4
0022     returnLogical=false;
0023 end
0024 
0025 %If the supplied object is a character array, then convert it to a cell
0026 %array
0027 if ischar(objects)
0028     objects={objects};
0029 end
0030 
0031 indexes=[];
0032 
0033 if strcmpi(type,'rxns')
0034     searchIn=model.rxns;
0035 else
0036     if strcmpi(type,'mets')
0037         searchIn=model.mets;
0038     else
0039         if strcmpi(type,'genes')
0040             searchIn=model.genes;
0041         else
0042             throw(MException('','Incorrect value of the "type" parameter. Allowed values are "rxns", "mets" or "genes".')); 
0043         end
0044     end
0045 end
0046 
0047 if iscell(objects)
0048     for i=1:numel(objects)
0049         index=find(strcmp(objects(i),searchIn),1);
0050         if ~isempty(index)
0051             indexes(i)=index;
0052         else
0053             throw(MException('',['Could not find object ' objects{i} ' in the model.']));
0054         end
0055     end
0056 else
0057     %Now it's either a logical (or 0/1) array or an array with indexes.
0058     %We want it to be an array with indexes.
0059     if all(objects)
0060         %This gets weird if it's all 1
0061         indexes=objects;
0062     else
0063         indexes=find(objects);
0064     end
0065 end
0066 
0067 if returnLogical==true
0068     tempIndexes=false(numel(searchIn),1);
0069     tempIndexes(indexes)=true;
0070     indexes=tempIndexes;
0071 end
0072 
0073 indexes=indexes(:);

Generated on Tue 23-Apr-2013 15:18:37 by m2html © 2005