0001 function equationStrings=constructEquations(model,rxns,useComps,sortRevRxns,sortMetNames)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 if nargin<2
0026 rxns=model.rxns;
0027 end
0028 if nargin<3
0029 useComps=true;
0030 end
0031 if nargin<4
0032 sortRevRxns=false;
0033 end
0034 if nargin<5
0035 sortMetNames=false;
0036 end
0037 if isempty(rxns)
0038 rxns=model.rxns;
0039 end
0040
0041
0042 if sortRevRxns==true
0043 model=sortModel(model);
0044 end
0045
0046
0047 if sortMetNames==true
0048 model=sortModel(model,false,true);
0049 end
0050
0051 indexes=getIndexes(model,rxns,'rxns');
0052
0053 equationStrings=cell(numel(indexes),1);
0054
0055 for i=1:numel(indexes)
0056 reactants=find(model.S(:,indexes(i))<0);
0057 products=find(model.S(:,indexes(i))>0);
0058 eqn='';
0059
0060 for j=1:numel(reactants)
0061 if j==1
0062 plusString='';
0063 else
0064 plusString=' + ';
0065 end
0066
0067 stoich=num2str(model.S(reactants(j),indexes(i))*-1);
0068
0069 if str2double(stoich)==1
0070 stoich='';
0071 else
0072 stoich=[stoich ' '];
0073 end
0074
0075 if useComps==true
0076 eqn=[eqn plusString stoich model.metNames{reactants(j)} '[' model.comps{model.metComps(reactants(j))} ']'];
0077 else
0078 eqn=[eqn plusString stoich model.metNames{reactants(j)}];
0079 end
0080 end
0081
0082 if model.rev(indexes(i))==0
0083 eqn=[eqn ' => '];
0084 else
0085 eqn=[eqn ' <=> '];
0086 end
0087
0088 for j=1:numel(products)
0089 if j==1
0090 plusString='';
0091 else
0092 plusString=' + ';
0093 end
0094
0095 stoich=num2str(model.S(products(j),indexes(i)));
0096
0097 if str2double(stoich)==1
0098 stoich='';
0099 else
0100 stoich=[stoich ' '];
0101 end
0102
0103 if useComps==true
0104 eqn=[eqn plusString stoich model.metNames{products(j)} '[' model.comps{model.metComps(products(j))} ']'];
0105 else
0106 eqn=[eqn plusString stoich model.metNames{products(j)}];
0107 end
0108 end
0109 equationStrings{i}=eqn;
0110 end
0111 end