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 if isempty(rxnList)
0043     return;
0044 end
0045 
0046 %Allow to set several parameters to the same value
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 %Find the indexes for the reactions in rxnList. Do not use getIndexes
0062 %as we do not want to throw errors if matches fail
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 %Change the parameters
0075 if ~isempty(indexes)
0076     if contains(paramType,'obj')
0077         model.c=zeros(numel(model.c),1); % parameter is changed, not added
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             %Non-zero values are interpreted as reversible
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

Generated by m2html © 2005