0001 function model=setParam(model, paramType, rxnList, params, var)
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
0030
0031
0032 paramType=convertCharArray(paramType);
0033 if ~any(strcmpi(paramType,{'lb','ub','eq','obj','rev','var','unc'}))
0034 EM=['Incorrect parameter type: "' paramType{1} '"'];
0035 dispEM(EM);
0036 end
0037 if isnumeric(rxnList) || islogical(rxnList)
0038 rxnList=model.rxns(rxnList);
0039 else
0040 rxnList=convertCharArray(rxnList);
0041 end
0042 if isempty(rxnList)
0043 return;
0044 end
0045
0046
0047 if numel(rxnList)~=numel(params) && numel(params)~=1
0048 EM='The number of parameter values and the number of reactions must be the same';
0049 dispEM(EM);
0050 end
0051
0052 if length(rxnList)>1
0053 if length(paramType)==1
0054 paramType(1:length(rxnList))=paramType;
0055 end
0056 if length(params)==1
0057 params(1:length(rxnList))=params;
0058 end
0059 end
0060
0061
0062
0063 indexes=zeros(numel(rxnList),1);
0064
0065 [Lia,Locb] = ismember(rxnList,model.rxns);
0066 indexes(Lia) = Locb;
0067 if any(~Lia)
0068 params(~Lia)=[];
0069 indexes(~Lia)=[];
0070 paramType(~Lia)=[];
0071 dispEM('Reactions not present in model, will be ignored:',false,rxnLise(~Lia));
0072 end
0073
0074
0075 if ~isempty(indexes)
0076 if contains(paramType,'obj')
0077 model.c=zeros(numel(model.c),1);
0078 end
0079 for j=1:length(paramType)
0080 if strcmpi(paramType{j},'eq')
0081 model.lb(indexes(j))=params(j);
0082 model.ub(indexes(j))=params(j);
0083 end
0084 if strcmpi(paramType{j},'lb')
0085 model.lb(indexes(j))=params(j);
0086 end
0087 if strcmpi(paramType{j},'ub')
0088 model.ub(indexes(j))=params(j);
0089 end
0090 if strcmpi(paramType{j},'obj')
0091 model.c(indexes(j))=params(j);
0092 end
0093 if strcmpi(paramType{j},'rev')
0094
0095 model.rev(indexes(j))=params(j)~=0;
0096 end
0097 if strcmpi(paramType{j},'var')
0098 if params(j) < 0
0099 model.lb(indexes(j)) = params(j) * (1+var/200);
0100 model.ub(indexes(j)) = params(j) * (1-var/200);
0101 else
0102 model.lb(indexes(j)) = params(j) * (1-var/200);
0103 model.ub(indexes(j)) = params(j) * (1+var/200);
0104 end
0105 end
0106 if strcmpi(paramType{j},'unc')
0107 if isfield(model.annotation,'defaultLB')
0108 lb = model.annotation.defaultLB;
0109 else
0110 lb = -1000;
0111 end
0112 if isfield(model.annotation,'defaultUB')
0113 ub = model.annotation.defaultUB;
0114 else
0115 ub = 1000;
0116 end
0117 model.lb(indexes(j)) = lb;
0118 model.ub(indexes(j)) = ub;
0119 end
0120 end
0121 end
0122 if any(ismember(paramType,{'lb','ub','unc'}))
0123 invalidBound = model.lb(indexes) > model.ub(indexes);
0124 if any(invalidBound)
0125 error(['Invalid set of bounds for reaction(s): ', strjoin(model.rxns(indexes(invalidBound)),', '), '.'])
0126 end
0127 end