Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: constructEquations #202

Merged
merged 6 commits into from
Mar 29, 2019
33 changes: 24 additions & 9 deletions core/constructEquations.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function equationStrings=constructEquations(model,rxns,useComps,sortRevRxns,sortMetNames,useMetID)
function equationStrings=constructEquations(model,rxns,useComps,sortRevRxns,sortMetNames,useMetID,useFormula)
% constructEquations
% Construct equation strings for reactions
%
% Input:
% model a model structure
% rxns either a cell array of reaction IDs, a logical vector with the
% same number of elements as reactions in the model, or a vector
Expand All @@ -13,15 +14,22 @@
% sortMetNames sort the metabolite names in the equation. Uses
% compartment even if useComps is false (opt, default
% false)
% useMetID use metabolite ID in generated equations, otherwise metNames are
% used (opt, default false)
% useMetID use metabolite ID in generated equations (opt,
% default false)
% useFormula use metabolite formula in generated equations (opt,
% default false)
%
% Outut:
% equationStrings a cell array with equations
%
% Usage: equationStrings=constructEquations(model,rxns,useComps,...
% sortRevRxns,sortMetNames,useMetID)
% NOTE: Reactions in a model should be organized in their forward direction
% (e.g. ub = 1000 and lb = -1000/0) so that their equations can be correctly
% constructed by this function.
%
% Hao Wang, 2017-05-15
% Usage: equationStrings=constructEquations(model,rxns,useComps,...
% sortRevRxns,sortMetNames,useMetID,useFormula)
%
% Hao Wang, 2019-03-05
% Benjamin Sanchez, 2018-08-22
%

Expand All @@ -40,6 +48,9 @@
if nargin<6
useMetID=false;
end
if nargin<7
useFormula=false;
end
if isempty(rxns) && nargin>2
rxns=model.rxns;
end
Expand All @@ -60,9 +71,13 @@

for i=1:numel(Rindexes)
Mindexes=find(model.S(:,Rindexes(i)));
%Define metabolites by id or name, and with or without compartment:
if useMetID==true
%Define metabolites by id, formula or name, and with or without compartment:
if useMetID==true && useFormula==false
mets = model.mets(Mindexes);
elseif useMetID==false && useFormula==true
mets = strcat('[',model.metFormulas(Mindexes),']');
elseif useMetID==true && useFormula==true
error('Arguments useMetID and useFormula cannot be both TRUE!');
else
mets = model.metNames(Mindexes);
end
Expand All @@ -72,7 +87,7 @@
end
%Define stoich coeffs and reversibility:
stoichCoeffs = model.S(Mindexes,Rindexes(i));
isrev = model.rev(Rindexes(i))==1;
isrev = model.lb(Rindexes(i))<0 & model.ub(Rindexes(i))>0;

%Construct equation:
equationStrings{i} = buildEquation(mets,stoichCoeffs,isrev);
Expand Down