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 if nargin<4
0024 returnLogical=false;
0025 end
0026
0027 if ~islogical(objects) && ~isnumeric(objects)
0028 objects=convertCharArray(objects);
0029 end
0030 type=char(type);
0031
0032 indexes=[];
0033
0034 switch type
0035 case 'rxns'
0036 searchIn=model.rxns;
0037 case 'mets'
0038 searchIn=model.mets;
0039 case 'genes'
0040 searchIn=model.genes;
0041 case 'metnames'
0042 searchIn=model.metNames;
0043 case 'metcomps'
0044
0045
0046 mets=regexprep(objects,'(^.+)\[(.+)\]$','$1');
0047 comps=regexprep(objects,'(^.+)\[(.+)\]$','$2');
0048 indexes=zeros(1,numel(objects));
0049 for i=1:numel(objects)
0050 index=find(strcmp(mets(i),model.metNames));
0051 index=index(strcmp(comps(i),model.comps(model.metComps(index))));
0052 if ~isempty(index)
0053 indexes(i)=index;
0054 else
0055 error(['Could not find object ' objects{i} ' in the model']);
0056 end
0057 end
0058 indexes=indexes(:);
0059 if returnLogical==true
0060 tempIndexes=false(numel(model.mets),1);
0061 tempIndexes(indexes)=true;
0062 indexes=tempIndexes;
0063 end
0064 return
0065 otherwise
0066 if contains(objects,{'rxns','mets','metnames','metcomps','genes'})
0067 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'' or ''genes'').')
0068 else
0069 error('Incorrect value of the ''type'' parameter. Allowed values are ''rxns'', ''mets'', ''metnames'', ''metcomps'' or ''genes''.');
0070 end
0071 end
0072
0073 if iscell(objects)
0074 for i=1:numel(objects)
0075 index=find(strcmp(objects(i),searchIn));
0076 if strcmpi(type,'metnames')
0077 indexes{i}=index;
0078 elseif ~isempty(index)
0079 indexes(i)=index;
0080 else
0081 error(['Could not find object ''' objects{i} ''' in the model']);
0082 end
0083 end
0084 else
0085
0086
0087 if all(objects)
0088
0089 indexes=objects;
0090 else
0091 indexes=find(objects);
0092 end
0093 end
0094
0095 if returnLogical==true
0096 tempIndexes=false(numel(searchIn),1);
0097 tempIndexes(indexes)=true;
0098 indexes=tempIndexes;
0099 end
0100
0101 indexes=indexes(:);
0102 if iscell(indexes) && length(indexes)==1
0103 indexes=indexes{1};
0104 end
0105 end