## The examples here require the package glpkAPI to be
## installed. If that package is not available, you have to set
## the argument 'solver' (the default is: solver = "glpk").
## load the example data set
data(Ec_core)
lowbnd(Ec_core)[react_id(Ec_core)=='EX_glc(e)']=-10;
lowbnd(Ec_core)[react_id(Ec_core)=='EX_o2(e)']=-18;
## run dynamicFBA(), Ec_df will be an object of class \code{\link{optsol_dynamicFBA}}
Ec_df <- dynamicFBA(Ec_core,substrateRxns={'EX_glc(e)'},initConcentrations=10,initBiomass=.035,timeStep=.25,nSteps=20,verbose=3)
## plot biomass and reactions
plot(Ec_df,plotRxns=c('EX_glc(e)','EX_ac(e)'));
## The function is currently defined as
function (model, substrateRxns, initConcentrations, initBiomass,
timeStep, nSteps, exclUptakeRxns, solver = SYBIL_SETTINGS("SOLVER"),
method = SYBIL_SETTINGS("METHOD"),
lpdir = SYBIL_SETTINGS("OPT_DIRECTION"), fld = FALSE,
verboseMode = 2, ...)
{
if (!is(model, "modelorg")) {
stop("needs an object of class modelorg!")
}
if (missing(exclUptakeRxns)) {
exclUptakeRxns = c("EX_co2(e)", "EX_o2(e)", "EX_h2o(e)",
"EX_h(e)")
if (verboseMode > 2) {
print("Default extra cellular uptake reactions will be used: ")
print(exclUptakeRxns)
}
}
excReact = findExchReact(model)
excReactInd = (react_id(model) %in% react_id(excReact$exchange))
exclUptakeRxnsInd = is.element(react_id(model), exclUptakeRxns)
excReactInd = excReactInd & !exclUptakeRxnsInd
excRxnNames = react_id(model)[excReactInd]
substrateRxnsInd = (react_id(model) %in% substrateRxns)
missingSub = substrateRxnsInd & !excReactInd
if (sum(missingSub) != 0) {
print(sum(missingSub))
print(react_id(model)[missingSub])
print("Invalid substrate uptake reaction!")
}
concentrations = rep(0, length(react_id(model)))
concentrations[substrateRxnsInd] = initConcentrations
originalBound = -lowbnd(model)
noInitConcentration = (concentrations == 0) & (lowbnd(model) < 0)
concentrations[noInitConcentration] = 1000
biomass = initBiomass
uptakeBound = concentrations/(biomass * timeStep)
aboveOriginal = (uptakeBound > originalBound) & (originalBound > 0)
uptakeBound[aboveOriginal] = originalBound[aboveOriginal]
lowbnd(model)[excReactInd] = -uptakeBound[excReactInd]
concentrationMatrix = concentrations[excReactInd]
biomassVec = biomass
timeVec = 0
lpmod <- prepProbObj(model, nCols = react_num(model), nRows = met_num(model),
alg = "FBA", solver = solver, method = method, lpdir = lpdir)
if (verboseMode > 2)
print("Step number Biomass\n")
if (verboseMode == 2)
progr <- .progressBar()
for (stepNo in 1:nSteps) {
if (verboseMode == 2)
progr <- .progressBar(stepNo, nSteps, progr)
sol = simpleFBA(lpmod, fld = T)
mu = sol$obj
if (sol$stat != 5) {
print("No feasible solution - nutrients exhausted\n")
break
}
uptakeFlux = sol$fluxes[excReactInd]
biomass = biomass * exp(mu * timeStep)
biomassVec = c(biomassVec, biomass)
concentrations[excReactInd] = concentrations[excReactInd] -
uptakeFlux/mu * biomass * (1 - exp(mu * timeStep))
concentrations[concentrations <= 0] = 0
concentrationMatrix = c(concentrationMatrix, concentrations[excReactInd])
uptakeBound[excReactInd] = concentrations[excReactInd]/(biomass *
timeStep)
uptakeBound[uptakeBound > 1000] = 1000
aboveOriginal = (uptakeBound > originalBound) & (originalBound > 0)
uptakeBound[aboveOriginal] = originalBound[aboveOriginal]
uptakeBound = ifelse(abs(uptakeBound) < 1e-09, 0, uptakeBound)
uppb_tmp <- getColsUppBnds(lpmod, which(excReactInd))
changeColsBnds(lpmod, which(excReactInd), lb = -uptakeBound[excReactInd],
ub = uppb_tmp)
if (verboseMode > 2)
print(paste(stepNo, sep = " ", biomass))
timeVec = c(timeVec, stepNo * timeStep)
}
return(optsol_dynamicFBA(solver = solver, method = method,
nprob = stepNo, lpdir = lpdir, ncols = react_num(model),
nrows = met_num(model), objf = printObjFunc(model), fld = fld,
concmat = concentrationMatrix, exRxn = excRxnNames, tmVec = timeVec,
bmVec = biomassVec))
}Run the code above in your browser using DataLab