Home > core > setParam.m

setParam

PURPOSE ^

setParam

SYNOPSIS ^

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

DESCRIPTION ^

 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 (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%).

   model       an updated model structure

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

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

Generated by m2html © 2005