@@ -95,7 +95,7 @@ function preFBA!(model, solver, optPercentage::Float64=0.0, osenseStr::String="m
95
95
hasObjective = false
96
96
fbaSol = NaN
97
97
end
98
-
98
+
99
99
# add a condition if the LP has an extra condition based on the FBA solution
100
100
if hasObjective
101
101
if printLevel > 0
@@ -204,7 +204,8 @@ function splitRange(model, rxnsList, nWorkers::Int=1, strategy::Int=0, printLeve
204
204
205
205
# loop through the number of reactions and determine the column density
206
206
for i in 1 : NrxnsList
207
- cdVect[i] = nnz (model. S[:, rxnsList[i]]) / Nmets * 100.0
207
+ S_sparseVector = sparsevec (model. S[:, rxnsList[i]])
208
+ cdVect[i] = nnz (S_sparseVector) / Nmets * 100.0
208
209
end
209
210
210
211
# initialize counter vectors
@@ -341,8 +342,8 @@ See also: `distributeFBA()`, `MathProgBase.HighLevelInterface`
341
342
342
343
"""
343
344
344
- function loopFBA (m, rxnsList, nRxns:: Int , rxnsOptMode= 2 .+ zeros (Int, length (rxnsList)), iRound:: Int = 0 , pid:: Int = 1 ,
345
- resultsDir:: String = joinpath (dirname ( pathof ( COBRA) ), " .." )* " /results" , logFiles:: Bool = false , onlyFluxes:: Bool = false , printLevel:: Int = 1 )
345
+ function loopFBA (m, x, c, rxnsList, nRxns:: Int , rxnsOptMode= 2 .+ zeros (Int, length (rxnsList)), iRound:: Int = 0 , pid:: Int = 1 ,
346
+ resultsDir:: String = joinpath (mkpath ( " COBRA" ), " .." )* " /results" , logFiles:: Bool = false , onlyFluxes:: Bool = false , printLevel:: Int = 1 )
346
347
347
348
# initialize vectors and counters
348
349
retObj = zeros (nRxns)
@@ -365,30 +366,28 @@ function loopFBA(m, rxnsList, nRxns::Int, rxnsOptMode=2 .+ zeros(Int, length(rxn
365
366
else
366
367
performOptim = false
367
368
end
368
-
369
+
369
370
if performOptim
371
+
372
+ # Set the objective vector coefficients
373
+ c = zeros (nRxns)
374
+ c[rxnsList[k]] = 1000.0 # set the coefficient of the current FBA to 1000
375
+
370
376
# change the sense of the optimization
371
377
if j == 1
372
378
if iRound == 0
373
- MathProgBase . HighLevelInterface . setsense! (m, : Min )
379
+ @objective (m, Min, c ' * x )
374
380
if printLevel > 0
375
381
println (" -- Minimization (iRound = $iRound ). Block $pid [$(length (rxnsList)) /$nRxns ]." )
376
382
end
377
383
else
378
- MathProgBase . HighLevelInterface . setsense! (m, : Max )
384
+ @objective (m, Max, c ' * x )
379
385
if printLevel > 0
380
386
println (" -- Maximization (iRound = $iRound ). Block $pid [$(length (rxnsList)) /$nRxns ]." )
381
387
end
382
388
end
383
389
end
384
-
385
- # Set the objective vector coefficients
386
- c = zeros (nRxns)
387
- c[rxnsList[k]] = 1000.0 # set the coefficient of the current FBA to 1000
388
-
389
- # set the objective of the CPLEX model
390
- MathProgBase. HighLevelInterface. setobj! (m, c)
391
-
390
+
392
391
if logFiles
393
392
# save individual logFiles with the CPLEX solver
394
393
if isdefined (m, :inner ) && string (typeof (m. inner)) == " CPLEX.Model"
@@ -397,34 +396,34 @@ function loopFBA(m, rxnsList, nRxns::Int, rxnsOptMode=2 .+ zeros(Int, length(rxn
397
396
end
398
397
399
398
# solve the model using the general MathProgBase interface
400
- solutionLP = MathProgBase . HighLevelInterface . solvelp (m)
399
+ status, objval, sol = solvelp (m, x )
401
400
402
401
# retrieve the solution status
403
- statLP = solutionLP . status
404
-
402
+ statLP = status
403
+
405
404
# output the solution, save the minimum and maximum fluxes
406
- if statLP == :Optimal
405
+ if statLP == MathOptInterface . TerminationStatusCode ( 1 )
407
406
# retrieve the objective value
408
- retObj[rxnsList[k]] = solutionLP . objval / 1000.0 # solutionLP.sol[rxnsList[k]]
407
+ retObj[rxnsList[k]] = objval / 1000.0 # solutionLP.sol[rxnsList[k]]
409
408
410
409
# retrieve the solution vector
411
410
if ! onlyFluxes
412
- retFlux[:, k] = solutionLP . sol
411
+ retFlux[:, k] = sol
413
412
end
414
413
415
414
# return the solution status
416
415
retStat[rxnsList[k]] = 1 # LP problem is optimal
417
416
418
- elseif statLP == :Infeasible
417
+ elseif statLP == MathOptInterface . TerminationStatusCode ( 2 )
419
418
retStat[rxnsList[k]] = 0 # LP problem is infeasible
420
419
421
- elseif statLP == :Unbounded
420
+ elseif statLP == MathOptInterface . TerminationStatusCode ( 6 )
422
421
retStat[rxnsList[k]] = 2 # LP problem is unbounded
423
422
424
- elseif statLP == :UserLimit
423
+ elseif statLP == MathOptInterface . TerminationStatusCode ( 11 )
425
424
retStat[rxnsList[k]] = 3 # Solver for the LP problem has hit a user limit
426
425
427
- elseif statLP == :InfeasibleOrUnbounded
426
+ elseif statLP == MathOptInterface . TerminationStatusCode ( 6 )
428
427
retStat[rxnsList[k]] = 4 # LP problem is infeasible or unbounded
429
428
430
429
else
@@ -523,7 +522,7 @@ See also: `preFBA!()`, `splitRange()`, `buildCobraLP()`, `loopFBA()`, or `fetch(
523
522
524
523
function distributedFBA (model, solver; nWorkers:: Int = 1 , optPercentage:: Union{Float64, Int64} = 0.0 , objective:: String = " max" ,
525
524
rxnsList= 1 : length (model. rxns), strategy:: Int = 0 , rxnsOptMode= 2 .+ zeros (Int, length (model. rxns)),
526
- preFBA:: Bool = false , saveChunks:: Bool = false , resultsDir:: String = joinpath (dirname ( pathof ( COBRA) ), " .." )* " /results" ,
525
+ preFBA:: Bool = false , saveChunks:: Bool = false , resultsDir:: String = joinpath (mkpath ( " COBRA" ), " .." )* " /results" ,
527
526
logFiles:: Bool = false , onlyFluxes:: Bool = false , printLevel:: Int = 1 )
528
527
529
528
# convert type of optPercentage
@@ -736,13 +735,13 @@ function distributedFBA(model, solver; nWorkers::Int=1, optPercentage::Union{Flo
736
735
737
736
# perform maximizations and minimizations sequentially
738
737
else
739
- m = buildCobraLP (model, solver)
738
+ m, x, c = buildCobraLP (model, solver)
740
739
741
740
# adjust the solver parameters based on the model
742
741
autoTuneSolver (m, nMets, nRxns, solver)
743
742
744
- minFlux, fvamin, statussolmin = loopFBA (m, rxnsList, nRxns, rxnsOptMode, 0 , 1 , resultsDir, logFiles, onlyFluxes, printLevel)
745
- maxFlux, fvamax, statussolmax = loopFBA (m, rxnsList, nRxns, rxnsOptMode, 1 , 1 , resultsDir, logFiles, onlyFluxes, printLevel)
743
+ minFlux, fvamin, statussolmin = loopFBA (m, x, c, rxnsList, nRxns, rxnsOptMode, 0 , 1 , resultsDir, logFiles, onlyFluxes, printLevel)
744
+ maxFlux, fvamax, statussolmax = loopFBA (m, x, c, rxnsList, nRxns, rxnsOptMode, 1 , 1 , resultsDir, logFiles, onlyFluxes, printLevel)
746
745
end
747
746
748
747
return minFlux, maxFlux, optSol, fbaSol, fvamin, fvamax, statussolmin, statussolmax
0 commit comments