Skip to content

Commit

Permalink
Merge pull request #1399 from tpfau/MOMAFix
Browse files Browse the repository at this point in the history
BugFix and test update
  • Loading branch information
laurentheirendt authored Dec 3, 2018
2 parents 4946d88 + c2cde51 commit 3b3f8b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/analysis/MOMA/MOMA.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@

if minNormFlag
QPproblem = buildLPproblemFromModel(modelDel);
QPproblem.c(1:nRxns) = -2*solutionWT.x;
QPproblem.c(1:nRxns1) = -2*solutionWT.x;
QPproblem.F = sparse(size(QPproblem.A,2));
QPproblem.F(1:nRxns2,1:nRxns2) = 2*speye(nRxns2);

Expand Down
68 changes: 37 additions & 31 deletions test/verifiedTests/analysis/testMOMA/testMOMA.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,50 @@
model = getDistributedModel('ecoli_core_model.mat');

% test solver packages
solverPkgs = {'mosek', 'ibm_cplex', 'tomlab_cplex', 'gurobi'};
solverPkgs = prepareTest('needsLP', true, 'needsQP', true, 'excludeSolvers', 'pdco');

% define solver tolerances
QPtol = 0.02;
LPtol = 0.0001;

for k = 1:length(solverPkgs)
fprintf(' -- Running testMOMA using the solver interface: %s ... ', solverPkgs{k});

solverQPOK = changeCobraSolver(solverPkgs{k}, 'QP', 0);
solverLPOK = changeCobraSolver(solverPkgs{k}, 'LP', 0);

if solverLPOK && solverQPOK
% test deleteModelGenes
[modelOut, hasEffect, constrRxnNames, deletedGenes] = deleteModelGenes(model, 'b3956'); % gene for reaction PPC

% run MOMA
sol = MOMA(model, modelOut);

if sol.stat == 1
assert(abs(0.8463 - sol.f) < QPtol)
end

% run linearMOMA
sol = linearMOMA(model, modelOut);

assert(abs(0.8608 - sol.f) < LPtol)

%run linear moma with minimal fluxes
solMin = linearMOMA(model, modelOut,'max',1);
assert(abs(0.8608 - solMin.f) < LPtol)

%We know that at least in this case, the flux sum is actually
%smaller.
assert(sum(abs(sol.x)) > sum(abs(solMin.x)))
for k = 1:length(solverPkgs.QP)
% select the same solver for QP and LP (if available)
if ~any(ismember(solverPkgs.QP{k},solverPkgs.LP))
lpSolver = solverPkgs.LP{1};
else
fprintf('\nMOMA requires a QP solver to be installed. QPNG does not work.\n');
lpSolver = solverPkgs.QP{k};
end
fprintf(' -- Running testMOMA using the solver %s for QP and %s for LP ... ', solverPkgs.QP{k}, lpSolver);

solverQPOK = changeCobraSolver(solverPkgs.QP{k}, 'QP', 0);
solverLPOK = changeCobraSolver(lpSolver, 'LP', 0);

% test deleteModelGenes
[modelOut, hasEffect, constrRxnNames, deletedGenes] = deleteModelGenes(model, 'b3956'); % gene for reaction PPC

% run MOMA
sol = MOMA(model, modelOut);

assert(abs(0.8463 - sol.f) < QPtol)

% run MOMA with minNormFlag
sol = MOMA(model, modelOut, 'max', 0, true);

assert(abs(sol.f - 0.8392) < QPtol)

% run linearMOMA
sol = linearMOMA(model, modelOut);

assert(abs(0.8608 - sol.f) < LPtol)


%run linear moma with minimal fluxes
solMin = linearMOMA(model, modelOut,'max',1);
assert(abs(0.8608 - solMin.f) < LPtol)

%We know that at least in this case, the flux sum is actually
%smaller.
assert(sum(abs(sol.x)) > sum(abs(solMin.x)))

% output a success message
fprintf('Done.\n');
Expand Down

0 comments on commit 3b3f8b2

Please sign in to comment.