setParam Sets parameters for reactions model a model structure paramType the type of parameter to set: 'lb' Lower bound 'ub' Upper bound 'eq' Both upper and lower bound (equality constraint) 'obj' Objective coefficient 'rev' Reversibility rxnList a cell array of reaction IDs or a vector with their corresponding indexes params a vector of the corresponding values model an updated model structure Usage: model=setParam(model, paramType, rxnList, params) Rasmus Agren, 2013-02-21
0001 function model=setParam(model, paramType, rxnList, params) 0002 % setParam 0003 % Sets parameters for reactions 0004 % 0005 % model a model structure 0006 % paramType the type of parameter to set: 0007 % 'lb' Lower bound 0008 % 'ub' Upper bound 0009 % 'eq' Both upper and lower bound (equality 0010 % constraint) 0011 % 'obj' Objective coefficient 0012 % 'rev' Reversibility 0013 % rxnList a cell array of reaction IDs or a vector with their 0014 % corresponding indexes 0015 % params a vector of the corresponding values 0016 % 0017 % model an updated model structure 0018 % 0019 % Usage: model=setParam(model, paramType, rxnList, params) 0020 % 0021 % Rasmus Agren, 2013-02-21 0022 % 0023 0024 %Allow to set several parameters to the same value 0025 if numel(rxnList)~=numel(params) && numel(params)~=1 0026 throw(MException('','The number of parameter values and the number of reactions must be the same.')); 0027 end 0028 0029 if isnumeric(rxnList) 0030 rxnList=model.rxns(rxnList); 0031 end 0032 0033 %If it's a char array 0034 rxnList=cellstr(rxnList); 0035 0036 %Find the indexes for the reactions in rxnList 0037 %I do not use getIndexes since I don't want to throw errors if you don't 0038 %get matches 0039 indexes=zeros(numel(rxnList),1); 0040 0041 for i=1:numel(rxnList) 0042 index=find(strcmp(rxnList{i},model.rxns),1); 0043 if ~isempty(index) 0044 indexes(i)=index; 0045 else 0046 indexes(i)=-1; 0047 fprintf('WARNING: Reaction %s is not present in the reaction list\n',rxnList{i}); 0048 end 0049 end 0050 0051 %Remove the reactions that weren't found 0052 params(indexes==-1)=[]; 0053 indexes(indexes==-1)=[]; 0054 0055 %Change the parameters 0056 if ~isempty(indexes) 0057 if strcmpi(paramType,'eq') 0058 model.lb(indexes)=params; 0059 model.ub(indexes)=params; 0060 end 0061 if strcmpi(paramType,'lb') 0062 model.lb(indexes)=params; 0063 end 0064 if strcmpi(paramType,'ub') 0065 model.ub(indexes)=params; 0066 end 0067 if strcmpi(paramType,'obj') 0068 %NOTE: The objective is changed to the new parameters, they are not 0069 %added 0070 model.c=zeros(numel(model.c),1); 0071 model.c(indexes)=params; 0072 end 0073 if strcmpi(paramType,'rev') 0074 %Non-zero values are interpreted as reversible 0075 model.rev(indexes)=params~=0; 0076 end 0077 end 0078 end