Home > core > setParam.m

setParam

PURPOSE ^

setParam

SYNOPSIS ^

function model=setParam(model, paramType, rxnList, params, var)

DESCRIPTION ^

 setParam
   Sets parameters for reactions

 Input:
   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 (only changes the model.rev fields,
                       does not affect model.lb and model.ub) 
               'var'   variance around measured bound
               'unc'   unconstrained, set lower and upper bound to the
                       default values (-1000 and 1000, or any other values
                       that are defined in model.annotation.defaultLB and
                       .defaultUB)
   rxnList     a cell array of reaction IDs or a vector with their
               corresponding indexes
   params      a vector of the corresponding values
   var         percentage of variance around measured value, if 'var' is
               set as paramType. Defining 'var' as 5 results in lb and ub
               at 97.5% and 102.5% of the provide params value (if params
               value is negative, then lb and ub are 102.5% and 97.5%).

 Output:
   model       an updated model structure

 Usage: model = setParam(model, paramType, rxnList, params, var)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function model=setParam(model, paramType, rxnList, params, var)
0002 % setParam
0003 %   Sets parameters for reactions
0004 %
0005 % Input:
0006 %   model       a model structure
0007 %   paramType   the type of parameter to set:
0008 %               'lb'    lower bound
0009 %               'ub'    upper bound
0010 %               'eq'    both upper and lower bound (equality constraint)
0011 %               'obj'   objective coefficient
0012 %               'rev'   reversibility (only changes the model.rev fields,
0013 %                       does not affect model.lb and model.ub)
0014 %               'var'   variance around measured bound
0015 %               'unc'   unconstrained, set lower and upper bound to the
0016 %                       default values (-1000 and 1000, or any other values
0017 %                       that are defined in model.annotation.defaultLB and
0018 %                       .defaultUB)
0019 %   rxnList     a cell array of reaction IDs or a vector with their
0020 %               corresponding indexes
0021 %   params      a vector of the corresponding values
0022 %   var         percentage of variance around measured value, if 'var' is
0023 %               set as paramType. Defining 'var' as 5 results in lb and ub
0024 %               at 97.5% and 102.5% of the provide params value (if params
0025 %               value is negative, then lb and ub are 102.5% and 97.5%).
0026 %
0027 % Output:
0028 %   model       an updated model structure
0029 %
0030 % Usage: model = setParam(model, paramType, rxnList, params, var)
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 
0043 %Allow to set several parameters to the same value
0044 if numel(rxnList)~=numel(params) && numel(params)~=1
0045     EM='The number of parameter values and the number of reactions must be the same';
0046     dispEM(EM);
0047 end
0048 
0049 if length(rxnList)>1
0050     if length(paramType)==1
0051         paramType(1:length(rxnList))=paramType;
0052     end
0053     if length(params)==1
0054         params(1:length(rxnList))=params;
0055     end
0056 end
0057 
0058 %Find the indexes for the reactions in rxnList. Do not use getIndexes
0059 %as we do not want to throw errors if matches fail
0060 indexes=zeros(numel(rxnList),1);
0061 
0062 for i=1:numel(rxnList)
0063     index=find(strcmp(rxnList{i},model.rxns),1);
0064     if ~isempty(index)
0065         indexes(i)=index;
0066     else
0067         indexes(i)=-1;
0068         EM=['Reaction ' rxnList{i} ' is not present in the reaction list'];
0069         dispEM(EM,false);
0070     end
0071 end
0072 
0073 %Remove the reactions that were not found
0074 params(indexes==-1)=[];
0075 indexes(indexes==-1)=[];
0076 paramType(indexes==-1)=[];
0077 %Change the parameters
0078 
0079 if ~isempty(indexes)
0080     if contains(paramType,'obj')
0081         model.c=zeros(numel(model.c),1); % parameter is changed, not added
0082     end
0083     for j=1:length(paramType)
0084         if strcmpi(paramType{j},'eq')
0085             model.lb(indexes(j))=params(j);
0086             model.ub(indexes(j))=params(j);
0087         end
0088         if strcmpi(paramType{j},'lb')
0089             model.lb(indexes(j))=params(j);
0090         end
0091         if strcmpi(paramType{j},'ub')
0092             model.ub(indexes(j))=params(j);
0093         end
0094         if strcmpi(paramType{j},'obj')
0095             model.c(indexes(j))=params(j);
0096         end
0097         if strcmpi(paramType{j},'rev')
0098             %Non-zero values are interpreted as reversible
0099             model.rev(indexes(j))=params(j)~=0;
0100         end
0101         if strcmpi(paramType{j},'var')
0102             if params(j) < 0
0103                 model.lb(indexes(j)) = params(j) * (1+var/200);
0104                 model.ub(indexes(j)) = params(j) * (1-var/200);
0105             else
0106                 model.lb(indexes(j)) = params(j) * (1-var/200);
0107                 model.ub(indexes(j)) = params(j) * (1+var/200);
0108             end
0109         end
0110         if strcmpi(paramType{j},'unc')
0111             if isfield(model.annotation,'defaultLB')
0112                 lb = model.annotation.defaultLB;
0113             else
0114                 lb = -1000;
0115             end
0116             if isfield(model.annotation,'defaultUB')
0117                 ub = model.annotation.defaultUB;
0118             else
0119                 ub = 1000;
0120             end
0121             model.lb(indexes(j)) = lb;
0122             model.ub(indexes(j)) = ub;
0123         end
0124     end
0125 end
0126 end

Generated by m2html © 2005