0001 function indexes=getIndexes(model, objects, type, returnLogical)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 if nargin<4
0030 returnLogical=false;
0031 end
0032
0033 if ~islogical(objects) && ~isnumeric(objects)
0034 objects=convertCharArray(objects);
0035 end
0036 type=char(type);
0037
0038 indexes=[];
0039
0040 switch type
0041 case 'rxns'
0042 searchIn=model.rxns;
0043 case 'mets'
0044 searchIn=model.mets;
0045 case 'genes'
0046 searchIn=model.genes;
0047 case 'metnames'
0048 searchIn=model.metNames;
0049 case 'metcomps'
0050
0051
0052 mets=regexprep(objects,'(^.+)\[(.+)\]$','$1');
0053 comps=regexprep(objects,'(^.+)\[(.+)\]$','$2');
0054 indexes=zeros(1,numel(objects));
0055 for i=1:numel(objects)
0056 index=find(strcmp(mets(i),model.metNames));
0057 index=index(strcmp(comps(i),model.comps(model.metComps(index))));
0058 if ~isempty(index)
0059 indexes(i)=index;
0060 else
0061 error(['Could not find object ' objects{i} ' in the model']);
0062 end
0063 end
0064 indexes=indexes(:);
0065 if returnLogical==true
0066 tempIndexes=false(numel(model.mets),1);
0067 tempIndexes(indexes)=true;
0068 indexes=tempIndexes;
0069 end
0070 return
0071 case 'ecrxns'
0072 if ~isfield(model,'ec')
0073 error('Type %s cannot be used if no model.ec structure is present.',type)
0074 end
0075 searchIn=model.ec.rxns;
0076 case 'ecenzymes'
0077 if ~isfield(model,'ec')
0078 error('Type %s cannot be used if no model.ec structure is present.',type)
0079 end
0080 searchIn=model.ec.enzymes;
0081 case 'ecgenes'
0082 if ~isfield(model,'ec')
0083 error('Type %s cannot be used if no model.ec structure is present.',type)
0084 end
0085 searchIn=model.ec.genes;
0086 otherwise
0087 if contains(objects,{'rxns','mets','metnames','metcomps','genes','ecgenes','ecenzymes','ecrxns'})
0088 error('The second and third parameter provided to run getIndexes are likely switched. Note that the second parameter is the object to find the index for, while the third parameter is the object type (''rxns'', ''mets'', ''metnames'', ''metcomps'', ''genes'', ''ecgenes'', ''ecenzymes'' or ''ecrxns'').')
0089 else
0090 error('Incorrect value of the ''type'' parameter. Allowed values are ''rxns'', ''mets'', ''metnames'', ''metcomps'', ''genes'', ''ecgenes'', ''ecenzymes'' or ''ecrxns''.');
0091 end
0092 end
0093
0094 if iscell(objects)
0095 for i=1:numel(objects)
0096 index=find(strcmp(objects(i),searchIn));
0097 if strcmpi(type,'metnames')
0098 indexes{i}=index;
0099 elseif ~isempty(index)
0100 if length(index) > 1
0101 error('There are multiple instances of object "%s" in the model, while "%s" type should be unique', objects{i}, type)
0102 end
0103 indexes(i)=index;
0104 else
0105 error(['Could not find object ''' objects{i} ''' in the model']);
0106 end
0107 end
0108 else
0109
0110
0111 if all(objects)
0112
0113 indexes=objects;
0114 else
0115 indexes=find(objects);
0116 end
0117 end
0118
0119 if returnLogical==true
0120 tempIndexes=false(numel(searchIn),1);
0121 tempIndexes(indexes)=true;
0122 indexes=tempIndexes;
0123 end
0124
0125 indexes=indexes(:);
0126 if iscell(indexes) && length(indexes)==1
0127 indexes=indexes{1};
0128 end
0129 end