convertToIrreversible

PURPOSE ^

convertToIrreversible Convert model to irreversible format

SYNOPSIS ^

function [modelIrrev,matchRev,rev2irrev,irrev2rev] = convertToIrreversible(model)

DESCRIPTION ^

convertToIrreversible Convert model to irreversible format

 [modelIrrev,matchRev,rev2irrev,irrev2rev] = convertToIrreversible(model)

INPUT
 model         COBRA model structure

OUTPUTS
 modelIrrev    Model in irreversible format
 matchRev      Matching of forward and backward reactions of a reversible
               reaction
 rev2irrev     Matching from reversible to irreversible reactions
 irrev2rev     Matching from irreversible to reversible reactions

 Uses the reversible list to construct a new model with reversible
 reactions separated into forward and backward reactions.  Separated
 reactions are appended with '_f' and '_b' and the reversible list tracks
 these changes with a '1' corresponding to separated forward reactions.
 Reactions entirely in the negative direction will be reversed and
 appended with '_r'.

 written by Gregory Hannum 7/9/05

 Modified by Markus Herrgard 7/25/05
 Modified by Jan Schellenberger 9/9/09 for speed.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [modelIrrev,matchRev,rev2irrev,irrev2rev] = convertToIrreversible(model)
0002 %convertToIrreversible Convert model to irreversible format
0003 %
0004 % [modelIrrev,matchRev,rev2irrev,irrev2rev] = convertToIrreversible(model)
0005 %
0006 %INPUT
0007 % model         COBRA model structure
0008 %
0009 %OUTPUTS
0010 % modelIrrev    Model in irreversible format
0011 % matchRev      Matching of forward and backward reactions of a reversible
0012 %               reaction
0013 % rev2irrev     Matching from reversible to irreversible reactions
0014 % irrev2rev     Matching from irreversible to reversible reactions
0015 %
0016 % Uses the reversible list to construct a new model with reversible
0017 % reactions separated into forward and backward reactions.  Separated
0018 % reactions are appended with '_f' and '_b' and the reversible list tracks
0019 % these changes with a '1' corresponding to separated forward reactions.
0020 % Reactions entirely in the negative direction will be reversed and
0021 % appended with '_r'.
0022 %
0023 % written by Gregory Hannum 7/9/05
0024 %
0025 % Modified by Markus Herrgard 7/25/05
0026 % Modified by Jan Schellenberger 9/9/09 for speed.
0027 
0028 %declare variables
0029 modelIrrev.S = spalloc(size(model.S,1),0,2*nnz(model.S));
0030 modelIrrev.rxns = [];
0031 modelIrrev.rev = zeros(2*length(model.rxns),1);
0032 modelIrrev.lb = zeros(2*length(model.rxns),1);
0033 modelIrrev.ub = zeros(2*length(model.rxns),1);
0034 modelIrrev.c = zeros(2*length(model.rxns),1);
0035 matchRev = zeros(2*length(model.rxns),1);
0036 
0037 nRxns = size(model.S,2);
0038 irrev2rev = zeros(2*length(model.rxns),1);
0039 
0040 %loop through each column/rxn in the S matrix building the irreversible
0041 %model
0042 cnt = 0;
0043 for i = 1:nRxns
0044     cnt = cnt + 1;
0045     
0046     %expand the new model (same for both irrev & rev rxns
0047     modelIrrev.rev(cnt) = model.rev(i);
0048     irrev2rev(cnt) = i;
0049 
0050     % Check if reaction is declared as irreversible, but bounds suggest
0051     % reversible (i.e., having both positive and negative bounds
0052     if (model.ub(i) > 0 && model.lb(i) < 0) && model.rev(i) == false
0053         model.rev(i) = true;
0054         warning(cat(2,'Reaction: ',model.rxns{i},' is classified as irreversible, but bounds are positive and negative!'))
0055 
0056     end
0057    
0058     % Reaction entirely in the negative direction
0059     if (model.ub(i) <= 0 && model.lb(i) < 0)
0060         % Retain original bounds but reversed
0061         modelIrrev.ub(cnt) = -model.lb(i);
0062         modelIrrev.lb(cnt) = -model.ub(i);
0063         % Reverse sign
0064         modelIrrev.S(:,cnt) = -model.S(:,i);
0065         modelIrrev.c(cnt) = -model.c(i);
0066         modelIrrev.rxns{cnt} = [model.rxns{i} '_r'];
0067         model.rev(i) = false;
0068         modelIrrev.rev(cnt) = false;
0069     else
0070         % Keep positive upper bound
0071         modelIrrev.ub(cnt) = model.ub(i);
0072         %if the lb is less than zero, set the forward rxn lb to zero
0073         if model.lb(i) < 0
0074             modelIrrev.lb(cnt) = 0;
0075         else
0076             modelIrrev.lb(cnt) = model.lb(i);
0077         end
0078         modelIrrev.S(:,cnt) = model.S(:,i);
0079         modelIrrev.c(cnt) = model.c(i);
0080         modelIrrev.rxns{cnt} = model.rxns{i};
0081 
0082     end
0083 
0084    
0085     %if the reaction is reversible, add a new rxn to the irrev model and
0086     %update the names of the reactions with '_f' and '_b'
0087     if model.rev(i) == true
0088         cnt = cnt + 1;
0089         matchRev(cnt) = cnt - 1;
0090         matchRev(cnt-1) = cnt;
0091         modelIrrev.rxns{cnt-1} = [model.rxns{i} '_f'];
0092         modelIrrev.S(:,cnt) = -model.S(:,i);
0093         modelIrrev.rxns{cnt} = [model.rxns{i} '_b'];
0094         modelIrrev.rev(cnt) = true;
0095         modelIrrev.lb(cnt) = 0;
0096         modelIrrev.ub(cnt) = -model.lb(i);
0097         modelIrrev.c(cnt) = 0;
0098         rev2irrev{i} = [cnt-1 cnt];
0099         irrev2rev(cnt) = i;
0100     else
0101         matchRev(cnt) = 0;
0102         rev2irrev{i} = cnt;
0103     end
0104 end
0105 
0106 rev2irrev = columnVector(rev2irrev);
0107 irrev2rev = irrev2rev(1:cnt);
0108 irrev2rev = columnVector(irrev2rev);
0109 
0110 % Build final structure
0111 modelIrrev.S = modelIrrev.S(:,1:cnt);
0112 modelIrrev.ub = columnVector(modelIrrev.ub(1:cnt));
0113 modelIrrev.lb = columnVector(modelIrrev.lb(1:cnt));
0114 modelIrrev.c = columnVector(modelIrrev.c(1:cnt));
0115 modelIrrev.rev = modelIrrev.rev(1:cnt);
0116 modelIrrev.rev = columnVector(modelIrrev.rev == 1);
0117 modelIrrev.rxns = columnVector(modelIrrev.rxns); 
0118 modelIrrev.mets = model.mets;
0119 matchRev = columnVector(matchRev(1:cnt));
0120 modelIrrev.match = matchRev;
0121 if (isfield(model,'b'))
0122     modelIrrev.b = model.b;
0123 end
0124 if isfield(model,'description')
0125     modelIrrev.description = [model.description ' irreversible'];
0126 end
0127 if isfield(model,'subSystems')
0128     modelIrrev.subSystems = model.subSystems(irrev2rev);
0129 end
0130 if isfield(model,'genes')
0131     modelIrrev.genes = model.genes;
0132     genemtxtranspose = model.rxnGeneMat';
0133     modelIrrev.rxnGeneMat = genemtxtranspose(:,irrev2rev)';
0134     modelIrrev.rules = model.rules(irrev2rev);
0135 end
0136 modelIrrev.reversibleModel = false;
0137

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003