From ce28f8a505215adaab8d072b9508ab18ed1c542c Mon Sep 17 00:00:00 2001 From: Claus Jonathan Fritzemeier <clausjonathan.fritzemeier@hhu.de> Date: Wed, 17 Dec 2014 14:11:05 +0100 Subject: [PATCH] initial commit of version 1.2.9. --- DESCRIPTION | 60 + NAMESPACE | 32 + R/addAlgorithm.R | 49 + R/addExchReact.R | 86 ++ R/addReact.R | 390 +++++++ R/addSolver.R | 77 ++ R/blockedReact.R | 220 ++++ R/bracket_pairs.R | 90 ++ R/ceilValues.R | 41 + R/changeBounds.R | 77 ++ R/changeGPR.R | 99 ++ R/changeObjFunc.R | 55 + R/checkAlgorithm.R | 36 + R/checkDefaultMethod.R | 126 +++ R/checkEmptyField.R | 48 + R/checkReactId.R | 138 +++ R/check_brackets.R | 49 + R/checksolClass.R | 192 ++++ R/createReactionString.R | 158 +++ R/deadEndMetabolite.R | 149 +++ R/doInRound.R | 75 ++ R/doubleFluxDel.R | 202 ++++ R/doubleGeneDel.R | 283 +++++ R/doubleReact.R | 250 +++++ R/editEnvir.R | 58 + R/findExchReact.R | 105 ++ R/floorValues.R | 41 + R/fluxDistributionClass.R | 295 +++++ R/fluxVar.R | 90 ++ R/geneDel.R | 162 +++ R/geneDeletion.R | 129 +++ R/generateFluxdels.R | 47 + R/generateModKey.R | 40 + R/generateWT.R | 83 ++ R/generics.R | 952 ++++++++++++++++ R/getsybilenv.R | 108 ++ R/makeLPcompatible.R | 43 + R/mod2irrev.R | 287 +++++ R/modelorg2ExPA.R | 187 ++++ R/modelorg2text.R | 118 ++ R/modelorg2tsv.R | 211 ++++ R/modelorgClass.R | 1088 ++++++++++++++++++ R/modelorg_irrevClass.R | 139 +++ R/multiDel.R | 269 +++++ R/netFluxClass.R | 121 ++ R/oneFluxDel.R | 72 ++ R/oneGeneDel.R | 95 ++ R/onlyChangeGPR.R | 124 ++ R/onlyCheckGPR.R | 190 ++++ R/optObjClass.R | 169 +++ R/optObj_basicfunc.R | 147 +++ R/optObj_clpAPIClass.R | 711 ++++++++++++ R/optObj_cplexAPIClass.R | 1154 +++++++++++++++++++ R/optObj_glpkAPIClass.R | 965 ++++++++++++++++ R/optObj_lpSolveAPIClass.R | 779 +++++++++++++ R/optObj_lpSolveAPIcompat.R | 99 ++ R/optObj_pointer.R | 84 ++ R/optimizer.R | 459 ++++++++ R/optsolClass.R | 580 ++++++++++ R/optsol_blockedReactClass.R | 96 ++ R/optsol_fluxVarClass.R | 350 ++++++ R/optsol_fluxdelClass.R | 269 +++++ R/optsol_genedelClass.R | 117 ++ R/optsol_optimizeProbClass.R | 115 ++ R/optsol_phppClass.R | 142 +++ R/optsol_robAnaClass.R | 106 ++ R/parseBoolean.R | 218 ++++ R/phpp.R | 125 +++ R/ppProcClass.R | 106 ++ R/ppProcessing.R | 134 +++ R/prepareSubSysMatrix.R | 66 ++ R/printLogComment.R | 48 + R/printNamedList.R | 38 + R/progress.R | 125 +++ R/promptSysBiolAlg.R | 179 +++ R/reactIdClass.R | 189 ++++ R/reactId_ExchClass.R | 235 ++++ R/readTEXTmod.R | 546 +++++++++ R/readTSVmod.R | 1378 +++++++++++++++++++++++ R/reassignFwBwMatch.R | 55 + R/recodeMatrix.R | 52 + R/rmReact.R | 219 ++++ R/robAna.R | 110 ++ R/settings.R | 130 +++ R/singletonMetabolite.R | 86 ++ R/summaryOptsolClass.R | 314 ++++++ R/sybilErrorClass.R | 132 +++ R/sybilLogClass.R | 676 +++++++++++ R/sybilStack.R | 162 +++ R/sysBiolAlgClass.R | 469 ++++++++ R/sysBiolAlg_fbaClass.R | 165 +++ R/sysBiolAlg_fvClass.R | 192 ++++ R/sysBiolAlg_lmomaClass.R | 362 ++++++ R/sysBiolAlg_momaClass.R | 229 ++++ R/sysBiolAlg_mtfClass.R | 333 ++++++ R/sysBiolAlg_roomClass.R | 424 +++++++ R/validmodelorg.R | 168 +++ R/validoptsol.R | 84 ++ R/validreactId.R | 52 + R/validreactId_Exch.R | 52 + R/validsysBiolAlg.R | 43 + R/ypd.R | 134 +++ R/zzz.R | 131 +++ build/vignette.rds | Bin 0 -> 230 bytes data/Ec_core.RData | Bin 0 -> 6640 bytes inst/CITATION | 20 + inst/NEWS.Rd | 1273 +++++++++++++++++++++ inst/doc/sybil.R | 565 ++++++++++ inst/doc/sybil.Rnw | 1494 +++++++++++++++++++++++++ inst/extdata/Ec_core_desc.tsv | 2 + inst/extdata/Ec_core_met.tsv | 55 + inst/extdata/Ec_core_react.tsv | 96 ++ man/Ec_core.Rd | 31 + man/SYBIL_SETTINGS.Rd | 181 +++ man/addAlgorithm.Rd | 36 + man/addCols-methods.Rd | 66 ++ man/addColsToProb-methods.Rd | 86 ++ man/addExchReact.Rd | 79 ++ man/addReact.Rd | 137 +++ man/addRows-methods.Rd | 66 ++ man/addRowsCols-methods.Rd | 69 ++ man/addRowsToProb-methods.Rd | 98 ++ man/addSolver.Rd | 50 + man/applyChanges-methods.Rd | 141 +++ man/backupProb-methods.Rd | 71 ++ man/blockedReact.Rd | 86 ++ man/changeBounds.Rd | 65 ++ man/changeColsBnds-methods.Rd | 74 ++ man/changeColsBndsObjCoefs-methods.Rd | 82 ++ man/changeGPR.Rd | 32 + man/changeMatrixRow-methods.Rd | 71 ++ man/changeObjCoefs-methods.Rd | 72 ++ man/changeObjFunc.Rd | 57 + man/changeRowsBnds-methods.Rd | 78 ++ man/changeUptake-methods.Rd | 69 ++ man/checkAkgorithm.Rd | 36 + man/checkDefaultMethod.Rd | 76 ++ man/checkOptSol-methods.Rd | 70 ++ man/checkReactId.Rd | 58 + man/checksol-class.Rd | 133 +++ man/deadEndMetabolites-methods.Rd | 54 + man/delProb-methods.Rd | 72 ++ man/deprecated.Rd | 28 + man/doubleFluxDel.Rd | 99 ++ man/doubleGeneDel.Rd | 125 +++ man/doubleReact.Rd | 74 ++ man/editEnvir.Rd | 44 + man/findExchReact.Rd | 73 ++ man/fluxDistribution-class.Rd | 91 ++ man/fluxVar.Rd | 79 ++ man/geneDel.Rd | 58 + man/geneDeletion.Rd | 128 +++ man/getColPrim-methods.Rd | 70 ++ man/getColsLowBnds-methods.Rd | 70 ++ man/getColsNames-methods.Rd | 69 ++ man/getColsUppBnds-methods.Rd | 70 ++ man/getFluxDist-methods.Rd | 95 ++ man/getNumCols-methods.Rd | 67 ++ man/getNumNnz-methods.Rd | 62 + man/getNumRows-methods.Rd | 67 ++ man/getObjCoefs-methods.Rd | 70 ++ man/getObjDir-methods.Rd | 68 ++ man/getObjVal-methods.Rd | 69 ++ man/getRedCosts-methods.Rd | 67 ++ man/getRowsLowBnds-methods.Rd | 71 ++ man/getRowsNames-methods.Rd | 69 ++ man/getRowsUppBnds-methods.Rd | 71 ++ man/getSolStat-methods.Rd | 70 ++ man/getSolverParm-methods.Rd | 71 ++ man/getsybilenv.Rd | 57 + man/initProb-methods.Rd | 90 ++ man/loadLPprob-methods.Rd | 219 ++++ man/loadQobj-methods.Rd | 56 + man/makeOptsolMO.Rd | 35 + man/mod2irrev.Rd | 64 ++ man/modelorg-class.Rd | 457 ++++++++ man/modelorg2ExPA.Rd | 76 ++ man/modelorg2tsv.Rd | 161 +++ man/modelorg_irrev-class.Rd | 109 ++ man/multiDel.Rd | 82 ++ man/netFlux-class.Rd | 91 ++ man/oneFluxDel.Rd | 81 ++ man/oneGeneDel.Rd | 90 ++ man/onlyChangeGPR.Rd | 32 + man/onlyCheckGPR.Rd | 30 + man/optObj-class.Rd | 292 +++++ man/optObj.Rd | 71 ++ man/optObj_clpAPI-class.Rd | 60 + man/optObj_cplexAPI-class.Rd | 60 + man/optObj_glpkAPI-class.Rd | 60 + man/optObj_lpSolveAPI-class.Rd | 75 ++ man/optimizeProb-methods.Rd | 343 ++++++ man/optimizer.Rd | 253 +++++ man/optsol-class.Rd | 338 ++++++ man/optsol_blockedReact-class.Rd | 147 +++ man/optsol_fluxVar-class.Rd | 222 ++++ man/optsol_fluxdel-class.Rd | 209 ++++ man/optsol_genedel-class.Rd | 184 +++ man/optsol_optimizeProb-class.Rd | 141 +++ man/optsol_phpp-class.Rd | 218 ++++ man/optsol_robAna-class.Rd | 179 +++ man/phpp.Rd | 107 ++ man/ppProc-class.Rd | 92 ++ man/printMetabolite-methods.Rd | 77 ++ man/printReaction-methods.Rd | 96 ++ man/promptSysBiolAlg.Rd | 74 ++ man/reactId-class.Rd | 119 ++ man/reactId_Exch-class.Rd | 196 ++++ man/readProb-methods.Rd | 82 ++ man/readTSVmod.Rd | 393 +++++++ man/resetChanges-methods.Rd | 58 + man/rmReact.Rd | 58 + man/robAna.Rd | 114 ++ man/scaleProb-methods.Rd | 66 ++ man/sensitivityAnalysis-methods.Rd | 60 + man/setColsNames-methods.Rd | 74 ++ man/setObjDir-methods.Rd | 115 ++ man/setRhsZero-methods.Rd | 64 ++ man/setRowsNames-methods.Rd | 74 ++ man/setSolverParm-methods.Rd | 76 ++ man/shrinkMatrix-methods.Rd | 83 ++ man/singletonMetabolites-methods.Rd | 59 + man/solveLp-methods.Rd | 63 ++ man/summaryOptsol-class.Rd | 168 +++ man/summaryOptsol.Rd | 68 ++ man/sybil-internal.Rd | 23 + man/sybil-package.Rd | 88 ++ man/sybilError-class.Rd | 74 ++ man/sybilLog-class.Rd | 282 +++++ man/sybilStack.Rd | 105 ++ man/sysBiolAlg-class.Rd | 266 +++++ man/sysBiolAlg.Rd | 86 ++ man/sysBiolAlg_fba-class.Rd | 162 +++ man/sysBiolAlg_fv-class.Rd | 190 ++++ man/sysBiolAlg_lmoma-class.Rd | 258 +++++ man/sysBiolAlg_moma-class.Rd | 183 +++ man/sysBiolAlg_mtf-class.Rd | 217 ++++ man/sysBiolAlg_room-class.Rd | 221 ++++ man/writeProb-methods.Rd | 81 ++ man/ypd.Rd | 137 +++ vignettes/sybil.Rnw | 1494 +++++++++++++++++++++++++ vignettes/sybil.bib | 224 ++++ 242 files changed, 41444 insertions(+) create mode 100644 DESCRIPTION create mode 100644 NAMESPACE create mode 100644 R/addAlgorithm.R create mode 100644 R/addExchReact.R create mode 100644 R/addReact.R create mode 100644 R/addSolver.R create mode 100644 R/blockedReact.R create mode 100644 R/bracket_pairs.R create mode 100644 R/ceilValues.R create mode 100644 R/changeBounds.R create mode 100644 R/changeGPR.R create mode 100644 R/changeObjFunc.R create mode 100644 R/checkAlgorithm.R create mode 100644 R/checkDefaultMethod.R create mode 100644 R/checkEmptyField.R create mode 100644 R/checkReactId.R create mode 100644 R/check_brackets.R create mode 100644 R/checksolClass.R create mode 100644 R/createReactionString.R create mode 100644 R/deadEndMetabolite.R create mode 100644 R/doInRound.R create mode 100644 R/doubleFluxDel.R create mode 100644 R/doubleGeneDel.R create mode 100644 R/doubleReact.R create mode 100644 R/editEnvir.R create mode 100644 R/findExchReact.R create mode 100644 R/floorValues.R create mode 100644 R/fluxDistributionClass.R create mode 100644 R/fluxVar.R create mode 100644 R/geneDel.R create mode 100644 R/geneDeletion.R create mode 100644 R/generateFluxdels.R create mode 100644 R/generateModKey.R create mode 100644 R/generateWT.R create mode 100644 R/generics.R create mode 100644 R/getsybilenv.R create mode 100644 R/makeLPcompatible.R create mode 100644 R/mod2irrev.R create mode 100644 R/modelorg2ExPA.R create mode 100644 R/modelorg2text.R create mode 100644 R/modelorg2tsv.R create mode 100644 R/modelorgClass.R create mode 100644 R/modelorg_irrevClass.R create mode 100644 R/multiDel.R create mode 100644 R/netFluxClass.R create mode 100644 R/oneFluxDel.R create mode 100644 R/oneGeneDel.R create mode 100644 R/onlyChangeGPR.R create mode 100644 R/onlyCheckGPR.R create mode 100644 R/optObjClass.R create mode 100644 R/optObj_basicfunc.R create mode 100644 R/optObj_clpAPIClass.R create mode 100644 R/optObj_cplexAPIClass.R create mode 100644 R/optObj_glpkAPIClass.R create mode 100644 R/optObj_lpSolveAPIClass.R create mode 100644 R/optObj_lpSolveAPIcompat.R create mode 100644 R/optObj_pointer.R create mode 100644 R/optimizer.R create mode 100644 R/optsolClass.R create mode 100644 R/optsol_blockedReactClass.R create mode 100644 R/optsol_fluxVarClass.R create mode 100644 R/optsol_fluxdelClass.R create mode 100644 R/optsol_genedelClass.R create mode 100644 R/optsol_optimizeProbClass.R create mode 100644 R/optsol_phppClass.R create mode 100644 R/optsol_robAnaClass.R create mode 100644 R/parseBoolean.R create mode 100644 R/phpp.R create mode 100644 R/ppProcClass.R create mode 100644 R/ppProcessing.R create mode 100644 R/prepareSubSysMatrix.R create mode 100644 R/printLogComment.R create mode 100644 R/printNamedList.R create mode 100644 R/progress.R create mode 100644 R/promptSysBiolAlg.R create mode 100644 R/reactIdClass.R create mode 100644 R/reactId_ExchClass.R create mode 100644 R/readTEXTmod.R create mode 100644 R/readTSVmod.R create mode 100644 R/reassignFwBwMatch.R create mode 100644 R/recodeMatrix.R create mode 100644 R/rmReact.R create mode 100644 R/robAna.R create mode 100644 R/settings.R create mode 100644 R/singletonMetabolite.R create mode 100644 R/summaryOptsolClass.R create mode 100644 R/sybilErrorClass.R create mode 100644 R/sybilLogClass.R create mode 100644 R/sybilStack.R create mode 100644 R/sysBiolAlgClass.R create mode 100644 R/sysBiolAlg_fbaClass.R create mode 100644 R/sysBiolAlg_fvClass.R create mode 100644 R/sysBiolAlg_lmomaClass.R create mode 100644 R/sysBiolAlg_momaClass.R create mode 100644 R/sysBiolAlg_mtfClass.R create mode 100644 R/sysBiolAlg_roomClass.R create mode 100644 R/validmodelorg.R create mode 100644 R/validoptsol.R create mode 100644 R/validreactId.R create mode 100644 R/validreactId_Exch.R create mode 100644 R/validsysBiolAlg.R create mode 100644 R/ypd.R create mode 100644 R/zzz.R create mode 100644 build/vignette.rds create mode 100644 data/Ec_core.RData create mode 100644 inst/CITATION create mode 100644 inst/NEWS.Rd create mode 100644 inst/doc/sybil.R create mode 100644 inst/doc/sybil.Rnw create mode 100644 inst/extdata/Ec_core_desc.tsv create mode 100644 inst/extdata/Ec_core_met.tsv create mode 100644 inst/extdata/Ec_core_react.tsv create mode 100644 man/Ec_core.Rd create mode 100644 man/SYBIL_SETTINGS.Rd create mode 100644 man/addAlgorithm.Rd create mode 100644 man/addCols-methods.Rd create mode 100644 man/addColsToProb-methods.Rd create mode 100644 man/addExchReact.Rd create mode 100644 man/addReact.Rd create mode 100644 man/addRows-methods.Rd create mode 100644 man/addRowsCols-methods.Rd create mode 100644 man/addRowsToProb-methods.Rd create mode 100644 man/addSolver.Rd create mode 100644 man/applyChanges-methods.Rd create mode 100644 man/backupProb-methods.Rd create mode 100644 man/blockedReact.Rd create mode 100644 man/changeBounds.Rd create mode 100644 man/changeColsBnds-methods.Rd create mode 100644 man/changeColsBndsObjCoefs-methods.Rd create mode 100644 man/changeGPR.Rd create mode 100644 man/changeMatrixRow-methods.Rd create mode 100644 man/changeObjCoefs-methods.Rd create mode 100644 man/changeObjFunc.Rd create mode 100644 man/changeRowsBnds-methods.Rd create mode 100644 man/changeUptake-methods.Rd create mode 100644 man/checkAkgorithm.Rd create mode 100644 man/checkDefaultMethod.Rd create mode 100644 man/checkOptSol-methods.Rd create mode 100644 man/checkReactId.Rd create mode 100644 man/checksol-class.Rd create mode 100644 man/deadEndMetabolites-methods.Rd create mode 100644 man/delProb-methods.Rd create mode 100644 man/deprecated.Rd create mode 100644 man/doubleFluxDel.Rd create mode 100644 man/doubleGeneDel.Rd create mode 100644 man/doubleReact.Rd create mode 100644 man/editEnvir.Rd create mode 100644 man/findExchReact.Rd create mode 100644 man/fluxDistribution-class.Rd create mode 100644 man/fluxVar.Rd create mode 100644 man/geneDel.Rd create mode 100644 man/geneDeletion.Rd create mode 100644 man/getColPrim-methods.Rd create mode 100644 man/getColsLowBnds-methods.Rd create mode 100644 man/getColsNames-methods.Rd create mode 100644 man/getColsUppBnds-methods.Rd create mode 100644 man/getFluxDist-methods.Rd create mode 100644 man/getNumCols-methods.Rd create mode 100644 man/getNumNnz-methods.Rd create mode 100644 man/getNumRows-methods.Rd create mode 100644 man/getObjCoefs-methods.Rd create mode 100644 man/getObjDir-methods.Rd create mode 100644 man/getObjVal-methods.Rd create mode 100644 man/getRedCosts-methods.Rd create mode 100644 man/getRowsLowBnds-methods.Rd create mode 100644 man/getRowsNames-methods.Rd create mode 100644 man/getRowsUppBnds-methods.Rd create mode 100644 man/getSolStat-methods.Rd create mode 100644 man/getSolverParm-methods.Rd create mode 100644 man/getsybilenv.Rd create mode 100644 man/initProb-methods.Rd create mode 100644 man/loadLPprob-methods.Rd create mode 100644 man/loadQobj-methods.Rd create mode 100644 man/makeOptsolMO.Rd create mode 100644 man/mod2irrev.Rd create mode 100644 man/modelorg-class.Rd create mode 100644 man/modelorg2ExPA.Rd create mode 100644 man/modelorg2tsv.Rd create mode 100644 man/modelorg_irrev-class.Rd create mode 100644 man/multiDel.Rd create mode 100644 man/netFlux-class.Rd create mode 100644 man/oneFluxDel.Rd create mode 100644 man/oneGeneDel.Rd create mode 100644 man/onlyChangeGPR.Rd create mode 100644 man/onlyCheckGPR.Rd create mode 100644 man/optObj-class.Rd create mode 100644 man/optObj.Rd create mode 100644 man/optObj_clpAPI-class.Rd create mode 100644 man/optObj_cplexAPI-class.Rd create mode 100644 man/optObj_glpkAPI-class.Rd create mode 100644 man/optObj_lpSolveAPI-class.Rd create mode 100644 man/optimizeProb-methods.Rd create mode 100644 man/optimizer.Rd create mode 100644 man/optsol-class.Rd create mode 100644 man/optsol_blockedReact-class.Rd create mode 100644 man/optsol_fluxVar-class.Rd create mode 100644 man/optsol_fluxdel-class.Rd create mode 100644 man/optsol_genedel-class.Rd create mode 100644 man/optsol_optimizeProb-class.Rd create mode 100644 man/optsol_phpp-class.Rd create mode 100644 man/optsol_robAna-class.Rd create mode 100644 man/phpp.Rd create mode 100644 man/ppProc-class.Rd create mode 100644 man/printMetabolite-methods.Rd create mode 100644 man/printReaction-methods.Rd create mode 100644 man/promptSysBiolAlg.Rd create mode 100644 man/reactId-class.Rd create mode 100644 man/reactId_Exch-class.Rd create mode 100644 man/readProb-methods.Rd create mode 100644 man/readTSVmod.Rd create mode 100644 man/resetChanges-methods.Rd create mode 100644 man/rmReact.Rd create mode 100644 man/robAna.Rd create mode 100644 man/scaleProb-methods.Rd create mode 100644 man/sensitivityAnalysis-methods.Rd create mode 100644 man/setColsNames-methods.Rd create mode 100644 man/setObjDir-methods.Rd create mode 100644 man/setRhsZero-methods.Rd create mode 100644 man/setRowsNames-methods.Rd create mode 100644 man/setSolverParm-methods.Rd create mode 100644 man/shrinkMatrix-methods.Rd create mode 100644 man/singletonMetabolites-methods.Rd create mode 100644 man/solveLp-methods.Rd create mode 100644 man/summaryOptsol-class.Rd create mode 100644 man/summaryOptsol.Rd create mode 100644 man/sybil-internal.Rd create mode 100644 man/sybil-package.Rd create mode 100644 man/sybilError-class.Rd create mode 100644 man/sybilLog-class.Rd create mode 100644 man/sybilStack.Rd create mode 100644 man/sysBiolAlg-class.Rd create mode 100644 man/sysBiolAlg.Rd create mode 100644 man/sysBiolAlg_fba-class.Rd create mode 100644 man/sysBiolAlg_fv-class.Rd create mode 100644 man/sysBiolAlg_lmoma-class.Rd create mode 100644 man/sysBiolAlg_moma-class.Rd create mode 100644 man/sysBiolAlg_mtf-class.Rd create mode 100644 man/sysBiolAlg_room-class.Rd create mode 100644 man/writeProb-methods.Rd create mode 100644 man/ypd.Rd create mode 100644 vignettes/sybil.Rnw create mode 100644 vignettes/sybil.bib diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..0e5529b --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,60 @@ +Package: sybil +Type: Package +Title: sybil - Efficient Constrained Based Modelling in R +Version: 1.2.9 +Date: 2014-11-19 +Authors@R: c(person("Gabriel", "Gelius-Dietrich", role = c("aut", "cre"), email = "geliudie@uni-duesseldorf.de"), + person(c("C.", "Jonathan"), "Fritzemeier", role = "ctb"), + person("Rajen", "Piernikarczyk", role = "ctb"), + person(c("Marc", "Andre"), "Daxer", role = "ctb"), + person("Benjamin", "Braasch", role = "ctb"), + person("Abdelmoneim", "Desouki", role = "ctb"), + person(c("Martin", "J."), "Lercher", role = "ctb")) +Maintainer: Gabriel Gelius-Dietrich <geliudie@uni-duesseldorf.de> +Depends: R (>= 2.14.2), Matrix, lattice +Imports: methods +Suggests: glpkAPI (>= 1.2.8), cplexAPI (>= 1.2.4), clpAPI (>= 1.2.4), + lpSolveAPI (>= 5.5.2.0), parallel, grid +URL: + http://www.cs.hhu.de/en/research-groups/bioinformatics/software/sybil.html +Description: The package sybil is a Systems Biology Library for R, implementing algorithms for constraint based analyses of metabolic networks (e.g. flux-balance analysis (FBA), minimization of metabolic adjustment (MOMA), regulatory on/off minimization (ROOM), robustness analysis and flux variability analysis). +LazyLoad: yes +License: GPL-3 +Collate: generics.R validmodelorg.R validoptsol.R validreactId.R + validreactId_Exch.R validsysBiolAlg.R addAlgorithm.R + addExchReact.R addReact.R addSolver.R blockedReact.R + bracket_pairs.R ceilValues.R changeBounds.R changeGPR.R + changeObjFunc.R checkAlgorithm.R checkDefaultMethod.R + checkEmptyField.R checkReactId.R check_brackets.R + createReactionString.R deadEndMetabolite.R doInRound.R + doubleFluxDel.R doubleGeneDel.R doubleReact.R editEnvir.R + findExchReact.R floorValues.R fluxVar.R geneDel.R + geneDeletion.R generateFluxdels.R generateModKey.R generateWT.R + getsybilenv.R makeLPcompatible.R mod2irrev.R modelorg2ExPA.R + modelorg2text.R modelorg2tsv.R multiDel.R oneFluxDel.R + oneGeneDel.R onlyChangeGPR.R onlyCheckGPR.R optObj_basicfunc.R + optObj_lpSolveAPIcompat.R optimizer.R parseBoolean.R phpp.R + ppProcessing.R prepareSubSysMatrix.R printLogComment.R + printNamedList.R progress.R promptSysBiolAlg.R recodeMatrix.R + readTEXTmod.R readTSVmod.R reassignFwBwMatch.R rmReact.R + robAna.R settings.R singletonMetabolite.R sybilStack.R ypd.R + zzz.R modelorgClass.R modelorg_irrevClass.R optObj_pointer.R + optObjClass.R optObj_clpAPIClass.R optObj_cplexAPIClass.R + optObj_glpkAPIClass.R optObj_lpSolveAPIClass.R + sybilErrorClass.R ppProcClass.R netFluxClass.R + fluxDistributionClass.R reactIdClass.R reactId_ExchClass.R + optsolClass.R optsol_blockedReactClass.R + optsol_optimizeProbClass.R optsol_fluxVarClass.R + optsol_fluxdelClass.R optsol_robAnaClass.R optsol_phppClass.R + optsol_genedelClass.R checksolClass.R summaryOptsolClass.R + sysBiolAlgClass.R sysBiolAlg_fbaClass.R sysBiolAlg_fvClass.R + sysBiolAlg_lmomaClass.R sysBiolAlg_momaClass.R + sysBiolAlg_mtfClass.R sysBiolAlg_roomClass.R sybilLogClass.R +Packaged: 2014-11-19 20:39:37 UTC; gabriel +Author: Gabriel Gelius-Dietrich [aut, cre], + C. Jonathan Fritzemeier [ctb], + Rajen Piernikarczyk [ctb], + Marc Andre Daxer [ctb], + Benjamin Braasch [ctb], + Abdelmoneim Desouki [ctb], + Martin J. Lercher [ctb] diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..b968cef --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,32 @@ +importFrom("graphics", plot) + +import(methods) +import(Matrix) +import(lattice) + +exportPattern("^[^\\.]") + +exportClass( +checksol, +fluxDistribution, +modelorg_irrev, +modelorg, +optObj_clpAPI, +optObj_cplexAPI, +optObj_glpkAPI, +optObj_lpSolveAPI, +optObj, +optsol_blockedReact, +optsol_fluxdel, +optsol_fluxVar, +optsol_genedel, +optsol_optimizeProb, +optsol_robAna, +optsol, +pointerToProb, +ppProc, +reactId, +sybilError, +sybilLog +) + diff --git a/R/addAlgorithm.R b/R/addAlgorithm.R new file mode 100644 index 0000000..69267d0 --- /dev/null +++ b/R/addAlgorithm.R @@ -0,0 +1,49 @@ +# addAlgorithm.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: addAlgorithm +# +# +# + +addAlgorithm <- function(alg, purpose) { + + stopifnot(inherits(alg, "character"), + inherits(purpose, "character"), + (length(alg) == 1), + (length(purpose) == 1)) + + + if (alg %in% .SYBILenv$algorithm[[purpose]]) { + stop("algorithm ", sQuote(alg), " already exists") + } + else { + .SYBILenv$algorithm[[purpose]] <- append(.SYBILenv$algorithm[[purpose]], alg) + } + + return(invisible(NULL)) + +} + diff --git a/R/addExchReact.R b/R/addExchReact.R new file mode 100644 index 0000000..b459ef6 --- /dev/null +++ b/R/addExchReact.R @@ -0,0 +1,86 @@ +# addExchReact.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: addExchReact +# +# +# The function addExchReact() is inspired by the function +# addExchangeRxn() contained in the COBRA Toolbox. +# The algorithm is (more or less) the same. + + +addExchReact <- function(model, met, lb, ub) { + + + # ------------------------------------------------------------------------ # + # check arguments + # ------------------------------------------------------------------------ # + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg") + } + + if ( (length(met) < 1) || (met == "") ) { + stop("at least one metabolite is required") + } + + if (missing(lb)) { + Clb <- rep(0, length(met)) + } + else { + Clb <- lb + } + + if (missing(ub)) { + Cub <- rep(SYBIL_SETTINGS("MAXIMUM"), length(met)) + } + else { + Cub <- ub + } + + if ( (length(met) != length(Clb)) || (length(met) != length(Cub)) ) { + stop("arguments 'met', 'lb' and 'ub' must have the same length") + } + + Crev <- rep(FALSE, length(met)) + Crev[Clb < 0] <- TRUE + + exRid <- paste("Ex_", met, sep = "") + + mod_out <- model + + for (i in seq(along = met)) { + mod_out <- addReact(model = mod_out, + id = exRid[i], + met = met[i], + Scoef = -1, + reversible = Crev[i], + lb = Clb[i], + ub = Cub[i]) + } + + return(mod_out) +} + diff --git a/R/addReact.R b/R/addReact.R new file mode 100644 index 0000000..3c6ab34 --- /dev/null +++ b/R/addReact.R @@ -0,0 +1,390 @@ +# addReact.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: addReact +# +# +# The function addReact() is inspired by the function +# addReaction() contained in the COBRA Toolbox. +# The algorithm is (more or less) the same. + + +addReact <- function(model, + id, + met, + Scoef, + reversible = FALSE, + lb = 0, + ub = SYBIL_SETTINGS("MAXIMUM"), + obj = 0, + subSystem = NA, + gprAssoc = NA, + reactName = NA, + metName = NA, + metComp = NA) { + + + # ------------------------------------------------------------------------ # + # check arguments + # ------------------------------------------------------------------------ # + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (length(met) != length(Scoef)) { + stop("arguments 'met' and 'Scoef' must have the same length") + } + + if (length(id) > 1) { + stop("add/change one reaction") + } + + if ( ( (ub > 0) && (lb < 0) ) && (!isTRUE(reversible)) ) { + Crev <- TRUE + warning(paste("'lb' and 'ub' are signed different,", + "set reversible to 'TRUE'")) + } + else { + Crev <- reversible + } + + + # ------------------------------------------------------------------------ # + # check, if we need to add columns and/or rows + # ------------------------------------------------------------------------ # + + # reaction + colInd <- match(id, react_id(model)) + addCol <- FALSE + nCols <- react_num(model) + if (is.na(colInd)) { + # new reaction + colInd <- react_num(model) + 1 + addCol <- TRUE + nCols <- nCols + 1 + } + + + # metabolites + rowInd <- match(met, met_id(model)) + + newM <- which(is.na(rowInd)) + nRows <- met_num(model) # number of rows in the model + nNewRows <- length(newM) # number of new rows + addRow <- FALSE + + for (i in seq(along = newM)) { + addRow <- TRUE + nRows <- nRows + 1 + rowInd[newM[i]] <- nRows + } + + + if ( (isTRUE(addCol)) || (isTRUE(addRow)) ) { + + # -------------------------------------------------------------------- # + # make a new model + # -------------------------------------------------------------------- # + + # -------------------------------------------------------------------- # + # data structures + + newmet_num <- met_num(model) + newmet_id <- met_id(model) + newmet_name <- met_name(model) + newmet_comp <- met_comp(model) + newmet_single <- met_single(model) + newmet_de <- met_de(model) + + newreact_num <- react_num(model) + newreact_rev <- react_rev(model) + newreact_id <- react_id(model) + newreact_name <- react_name(model) + newreact_single <- react_single(model) + newreact_de <- react_de(model) + newlowbnd <- lowbnd(model) + newuppbnd <- uppbnd(model) + newobj_coef <- obj_coef(model) + + newgprRules <- gprRules(model) + newgenes <- genes(model) + newgpr <- gpr(model) + newallGenes <- allGenes(model) + newrxnGeneMat <- rxnGeneMat(model) + newsubSys <- subSys(model) + + newS <- S(model) + + + if (isTRUE(addRow)) { + + # new number of metabolites + newmet_num <- nRows + + # new metabolite id's + newmet_id <- append(met_id(model), met[newM]) + + # new metabolite names + if (any(is.na(metName))) { + newmet_name <- append(met_name(model), met[newM]) + } + else { + newmet_name <- append(met_name(model), metName[newM]) + } + + # new metabolite compartments + if (any(is.na(metComp))) { + newmet_comp <- append(met_comp(model), rep(NA, nNewRows)) + } + else { + if (is(metComp, "numeric")) { + newmet_comp <- append(met_comp(model), metComp[newM]) + } + else { + newmet_comp <- append(met_comp(model), + match(metComp[newM], + mod_compart(model))) + } + } + + # singleton and dead end metabolites (not checked!) + newmet_single <- append(met_single(model), rep(NA, nNewRows)) + newmet_de <- append(met_de(model), rep(NA, nNewRows)) + + # new rows in stoichiometric matrix + newRows <- Matrix::Matrix(0, + nrow = nNewRows, + ncol = react_num(model)) + newS <- Matrix::rBind(newS, newRows) + } + + if (isTRUE(addCol)) { # we add at most one column + # new number of reactions + newreact_num <- nCols + + # new reaction id + newreact_id <- append(react_id(model), id) + + # new reaction name + if (is.na(reactName)) { + newreact_name <- append(react_name(model), id) + } + else { + newreact_name <- append(react_name(model), reactName) + } + + # reaction contains singleton or dead end metabolites (not checked!) + newreact_single <- append(react_single(model), NA) + newreact_de <- append(react_de(model), NA) + + # reversibility, lower and upper bounds, objective coefficient + newreact_rev <- append(react_rev(model), Crev) + newlowbnd <- append(lowbnd(model), lb) + newuppbnd <- append(uppbnd(model), ub) + newobj_coef <- append(obj_coef(model), obj) + + # new column in stoichiometric matrix + newS <- cBind(newS, rep(0, nrow(newS))) + + # subsystems + if (any(is.na(subSystem))) { + newsubSys <- rBind(subSys(model), + rep(FALSE, ncol(subSys(model)))) + } + else { + if (is(subSystem, "logical")) { + newsubSys <- rBind(subSys(model), subSystem) + } + else { + nSubsRow <- colnames(subSys(model)) %in% subSystem + newsubSys <- rBind(subSys(model), nSubsRow) + } + } + + + # gpr association + if (ncol(rxnGeneMat(model)) > 0) { + newrxnGeneMat <- rBind(rxnGeneMat(model), + rep(FALSE, ncol(rxnGeneMat(model)))) + } + else if (nrow(rxnGeneMat(model)) > 0) { + newrxnGeneMat <- rxnGeneMat(model) + dim(newrxnGeneMat) <- c(nrow(newrxnGeneMat)+1, + ncol(newrxnGeneMat)) + } + else { + newrxnGeneMat <- rxnGeneMat(model) + } + + if ( (is.na(gprAssoc)) || (gprAssoc == "") ) { + if ((length(gprRules(model)) > 0)) { + newgprRules <- append(gprRules(model), "") + newgenes <- append(genes(model), "") + newgpr <- append(gpr(model), "") + } + } + else { + gene_rule <- .parseBoolean(gprAssoc) + + geneInd <- match(gene_rule$gene, allGenes(model)) + + # indices of new genes + new_gene <- which(is.na(geneInd)) + + # if we have new gene(s), add a column in rxnGeneMat and + # gene name(s) to allGenes + if (length(new_gene) > 0) { + newallGenes <- append(allGenes(model), + gene_rule[["gene"]][new_gene]) + + # update geneInd + geneInd <- match(gene_rule[["gene"]], newallGenes) + + # if we have an empty modelorg object, we need to + # initialize rxnGeneMat + if (ncol(newrxnGeneMat) == 0) { + newrxnGeneMat <- Matrix::Matrix(FALSE, + nCols, max(geneInd)) + } + else { + for (i in seq(along = gene_rule[["gene"]][new_gene])) { + newrxnGeneMat <- cBind(newrxnGeneMat, + rep(FALSE, nrow(newrxnGeneMat))) + } +# print("arsch") + } + } + +# print(newrxnGeneMat) +# print(nCols) +# print(geneInd) + + # rxnGeneMat + newrxnGeneMat[nCols, geneInd] <- TRUE + + # new rule + newgpr <- append(gpr(model), gprAssoc) + + # genes per reaction + newgenes <- append(genes(model), list(gene_rule$gene)) + newrule <- gene_rule$rule + + for (j in 1 : length(geneInd)) { + pat <- paste("x(", j, ")", sep = "") + repl <- paste("x[", geneInd[j], "]", sep = "") + + newrule <- gsub(pat, repl, newrule, fixed = TRUE) + } + + newgprRules <- append(gprRules(model), newrule) + } + } + + # values for stoichiometric matrix + newS[ , colInd] <- 0 + newS[rowInd, colInd] <- Scoef + +# for (i in seq(along = rowInd)) { +# newS[rowInd[i], colInd] <- Scoef[i] +# } + + # -------------------------------------------------------------------- # + # new model + # -------------------------------------------------------------------- # + + if (is(model, "modelorg_irrev")) { + mod_out <- modelorg_irrev(mod_id(model), mod_name(model)) + irrev(mod_out) <- TRUE + matchrev(mod_out) <- append(matchrev(model), 0) + + revReactId <- max(irrev2rev(model))+1 + irrev2rev(mod_out) <- append(irrev2rev(model), revReactId) + rev2irrev(mod_out) <- rbind(rev2irrev(model), c(nCols, nCols)) + } + else { + mod_out <- modelorg(mod_id(model), mod_name(model)) + } + + mod_desc(mod_out) <- mod_desc(model) + mod_compart(mod_out) <- mod_compart(model) + + + met_num(mod_out) <- as.integer(newmet_num) + met_id(mod_out) <- newmet_id + met_name(mod_out) <- newmet_name + met_comp(mod_out) <- as.integer(newmet_comp) + met_single(mod_out) <- newmet_single + met_de(mod_out) <- newmet_de + + react_num(mod_out) <- as.integer(newreact_num) + react_rev(mod_out) <- newreact_rev + react_id(mod_out) <- newreact_id + react_name(mod_out) <- newreact_name + react_single(mod_out) <- newreact_single + react_de(mod_out) <- newreact_de + lowbnd(mod_out) <- newlowbnd + uppbnd(mod_out) <- newuppbnd + obj_coef(mod_out) <- newobj_coef + + gprRules(mod_out) <- newgprRules + genes(mod_out) <- newgenes + gpr(mod_out) <- newgpr + allGenes(mod_out) <- newallGenes + rxnGeneMat(mod_out) <- newrxnGeneMat + subSys(mod_out) <- newsubSys + + S(mod_out) <- newS + + } + else { + + # -------------------------------------------------------------------- # + # modify old model + # -------------------------------------------------------------------- # + + mod_out <- model + + react_rev(mod_out)[colInd] <- Crev + lowbnd(mod_out)[colInd] <- lb + uppbnd(mod_out)[colInd] <- ub + obj_coef(mod_out)[colInd] <- obj + S(mod_out)[ , colInd] <- 0 + S(mod_out)[rowInd, colInd] <- Scoef + + } + + + check <- validObject(mod_out, test = TRUE) + + if (check != TRUE) { + msg <- paste("Validity check failed:", check, sep = "\n ") + warning(msg) + } + + return(mod_out) + +} + diff --git a/R/addSolver.R b/R/addSolver.R new file mode 100644 index 0000000..7198ad8 --- /dev/null +++ b/R/addSolver.R @@ -0,0 +1,77 @@ +# addSolver.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: addSolver +# +# +# + +addSolver <- function(solver, method, probType) { + + stopifnot(inherits(solver, "character"), + inherits(method, "character"), + inherits(probType, "list"), + (length(solver) == 1L), + length(probType) == length(method)) + + + # -------------------------------------------------------------------- # + # solver + if (solver %in% .SYBILenv$solvers) { + return(invisible(FALSE)) + } + else { + .SYBILenv$solvers <- append(.SYBILenv$solvers, solver) + } + + + # -------------------------------------------------------------------- # + # method + .SYBILenv$solverMethods[[solver]] <- method + .SYBILenv$solverCtrlParm[[solver]] <- vector(length = length(method), + mode = "list") + + names(.SYBILenv$solverCtrlParm[[solver]]) <- method + + for (i in seq(along = method)) { + .SYBILenv$solverCtrlParm[[solver]][[i]] <- as.data.frame(NA) + } + + + # -------------------------------------------------------------------- # + # problem type + for (i in seq(along = method)) { + pt <- unique(probType[[i]]) + stopifnot(inherits(pt, "character")) + prtp <- pt %in% names(.SYBILenv$ptype) + for (j in seq(along = pt[prtp])) { + .SYBILenv$ptype[[pt[prtp][j]]][[solver]] <- append(.SYBILenv$ptype[[pt[prtp][j]]][[solver]], method[i]) + } + } + + return(invisible(TRUE)) + +} + diff --git a/R/blockedReact.R b/R/blockedReact.R new file mode 100644 index 0000000..c0b553e --- /dev/null +++ b/R/blockedReact.R @@ -0,0 +1,220 @@ +# blockedReact.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: blockedReact +# +# This function finds blocked reactions in a specified IO-environment. +# +# + + +blockedReact <- function(model, + tol = SYBIL_SETTINGS("TOLERANCE"), + exex = TRUE, + fld = FALSE, + retOptSol = FALSE, + verboseMode = 2, + ... + ) { + + .Deprecated(new = "fluxVar") + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + modIrr <- ifelse(is(model, "modelorg_irrev"), TRUE, FALSE) + + intReact <- NA + + # remove exchange reactions from analysis + if (isTRUE(exex)) { + exchReact <- findExchReact(model) + ex <- react_pos(exchReact) + intReact <- 1:react_num(model) + intReact <- intReact[-ex] + + if (length(intReact) < 1) { + stop("model contains no internal reactions!") + } + } + else { + intReact <- 1:react_num(model) + } + + # memory for results + nObj <- ifelse(isTRUE(modIrr), length(intReact), 2 * length(intReact)) + blocked_react <- logical(react_num(model)) + + if (isTRUE(retOptSol)) { + obj <- numeric(nObj) + ok <- integer(nObj) + stat <- integer(nObj) + if (isTRUE(fld)) { + flux <- Matrix::Matrix(0, nrow = react_num(model), ncol = nObj) + } + else { + flux <- NA + } + } + + obj_mod <- obj_coef(model) + obj_coef(model) <- as.integer(rep(0, react_num(model))) + + lpmod <- sysBiolAlg(model, algorithm = "fv", tol = tol, ...) + + +#------------------------------------------------------------------------------# +# finding blocked reactions # +#------------------------------------------------------------------------------# + + if (verboseMode > 0) { message("calculating blocked reactions ...") } + + obj_max <- 0 + obj_min <- 0 + + if (verboseMode > 1) { progr <- .progressBar() } + + for (i in seq(along = intReact)) { + + solpl <- ifelse(isTRUE(modIrr), i+1, 2*i) + +# if (uppbnd(model)[intReact[i]] > 0) { + + #print(intReact[i]) + sol <- optimizeProb(lpmod, lpdir = "max", + react = intReact[i], obj_coef = 1) + obj_max <- sol$obj + if (isTRUE(retOptSol)) { + obj[(solpl-1)] <- sol$obj + ok[(solpl-1)] <- sol$ok + stat[(solpl-1)] <- sol$stat + if (isTRUE(fld)) { + flux[,(solpl-1)] <- sol$fluxes + } + } +# } +# else { +# obj_max <- 0 +# if (isTRUE(retOptSol)) { +# obj[(i*2-1)] <- 0 +# ok[(i*2-1)] <- NA +# stat[(i*2-1)] <- NA +# if (isTRUE(fld)) { +# flux[,(i*2-1)] <- NA +# } +# } +# } + +# if (lowbnd(model)[intReact[i]] < 0) { + if (!is(model, "modelorg_irrev")) { + + sol <- optimizeProb(lpmod, lpdir = "min", + react = intReact[i], obj_coef = 1) + obj_min <- sol$obj + if (isTRUE(retOptSol)) { + obj[solpl] <- sol$obj + ok[solpl] <- sol$ok + stat[solpl] <- sol$stat + if (isTRUE(fld)) { + flux[,solpl] <- sol$fluxes + } + } + } +# } +# else { +# obj_min <- 0 +# if (isTRUE(retOptSol)) { +# obj[(i*2)] <- 0 +# ok[(i*2)] <- NA +# stat[(i*2)] <- NA +# if (isTRUE(fld)) { +# flux[,(i*2)] <- NA +# } +# } +# } + + #print(paste("i", i)) + #print(paste("max", obj_max)) + #print(paste("min", obj_min)) + #print(" ") + + if (is(model, "modelorg_irrev")) { + blocked_react[intReact[i]] <- ifelse(abs(obj_max) < tol, TRUE, FALSE) + } + else { + if ( (abs(obj_max) < tol) && (abs(obj_min) < tol) ) { + blocked_react[intReact[i]] <- TRUE + } + else { + blocked_react[intReact[i]] <- FALSE + } + } + + if (verboseMode > 1) { + progr <- .progressBar(i, length(intReact), progr) + } + + } + + #print(nObj) + #print(obj) + #print(ok) + #print(blocked_react) + + if (isTRUE(retOptSol)) { + optsol <- new("optsol_blockedReact", + mod_id = mod_id(model), + mod_key = mod_key(model), + solver = solver(problem(lpmod)), + method = method(problem(lpmod)), + algorithm = algorithm(lpmod), + num_of_prob = as.integer(nObj), + lp_num_cols = nc(lpmod), + lp_num_rows = nr(lpmod), + lp_obj = as.numeric(obj), + lp_ok = as.integer(ok), + lp_stat = as.integer(stat), + lp_dir = factor(rep(c("max", "min"), length(intReact))), + obj_coef = obj_mod, + fldind = fldind(lpmod), + fluxdist = fluxDistribution(flux), + + blocked = blocked_react, + react = new("reactId", + mod_id = mod_id(model), + mod_key = mod_key(model), + pnt = intReact, + id = react_id(model)[intReact]) + ) + } + else { + optsol <- blocked_react + } + + return(optsol) + +} + diff --git a/R/bracket_pairs.R b/R/bracket_pairs.R new file mode 100644 index 0000000..ce32f3c --- /dev/null +++ b/R/bracket_pairs.R @@ -0,0 +1,90 @@ +# bracket_pairs.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .bracket_pairs +# +# +# + + +# ---------------------------------------------------------------------------- # + +# This function finds corresponding pairs of brackets in a logical rule. +# It returns a matrix with three columns. Each row containing one bracket +# pair, the first value is the position of the opening bracket in the +# string, the second value is the position of the closing bracket and the +# third element is the length of the text between the brackets (excluding +# the brackets). +# Argument rule is a character vector, each element being one letter of +# the original text string. + +.bracket_pairs <- function(rule) { + + if (!any(is.na(rule))) { + + # stack for opening brackets + #s_open <- stapel() + st <- "s_open" + stinit(st) + + pairc <- 0 # counter for pairs + + # positions of opening brackets + nop <- length(grep("(", rule, fixed = TRUE)) + + # result matrix, nop is the number of bracket pairs + bpair <- matrix(0, nrow = nop, ncol = 3) + + + # push each the position of each '(' onto the stack + for (i in seq(along = rule)) { + if (rule[i] == "(") { + #push(s_open, i) + stpush(st, i) + } + # if we find a ')' the '(' on top of the stack is the + # corrseponding bracket. + else if (rule[i] == ")") { + pairc <- pairc + 1 + #ob <- as.integer(pop(s_open)) + ob <- as.integer(stpop(st)) + bpair[pairc,] <- c(ob, i, i-ob-1) + } + } + + colnames(bpair) <- c("open", "close", "length") + + # sort the pairs according to their length + bpair <- bpair[order(bpair[, "length"]), , drop = FALSE] + + + } + else { + bpair <- NA + } + + return(bpair) + +} diff --git a/R/ceilValues.R b/R/ceilValues.R new file mode 100644 index 0000000..3e01096 --- /dev/null +++ b/R/ceilValues.R @@ -0,0 +1,41 @@ +# ceilValues.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .ceilValues +# +# +# + +.ceilValues <- function(val, tol = SYBIL_SETTINGS("TOLERANCE")) { + + if (!is(val, "numeric")) { + stop( c("Argument val has to be numeric!") ) + } + + ceilVal <- ceiling(val/tol)*tol + + return(ceilVal) + +} diff --git a/R/changeBounds.R b/R/changeBounds.R new file mode 100644 index 0000000..54dac86 --- /dev/null +++ b/R/changeBounds.R @@ -0,0 +1,77 @@ +# changeBounds.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: changeBounds +# +# +# +# + +changeBounds <- function(model, react, lb = NULL, ub = NULL) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + checkedIds <- checkReactId(model, react) + if (!is(checkedIds, "reactId")) { + stop("argument react is wrong") + } + + if ( (is.null(lb)) && (is.null(ub)) ) { + lowbnd(model)[react_pos(checkedIds)] <- rep(0, length(checkedIds)) + uppbnd(model)[react_pos(checkedIds)] <- rep(0, length(checkedIds)) + } + else { + # set upper bound + if (!is.null(ub)) { + stopifnot(is(ub, "numeric")) + if (length(ub) == 1) { + ubnd <- rep(ub, length(checkedIds)) + } + else { + stopifnot(length(ub) == length(checkedIds)) + ubnd <- ub + } + uppbnd(model)[react_pos(checkedIds)] <- ubnd + } + + if (!is.null(lb)) { + stopifnot(is(lb, "numeric")) + if (length(lb) == 1) { + lbnd <- rep(lb, length(checkedIds)) + } + else { + stopifnot(length(lb) == length(checkedIds)) + lbnd <- lb + } + lowbnd(model)[react_pos(checkedIds)] <- lbnd + } + } + + return(model) + +} + diff --git a/R/changeGPR.R b/R/changeGPR.R new file mode 100644 index 0000000..529f4d6 --- /dev/null +++ b/R/changeGPR.R @@ -0,0 +1,99 @@ +# changeGPR.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: changeGPR +# +# +# +# +# model must be an object of modelorg +# react stands for the reaction, which will be changed +# (Instance of checkReactId, positions or names) +# gprRules stands for the new logical Expressions (GPR Rules) + +changeGPR <- function(model, react, gprRules = "logicalExpression", verboseMode = 1) { + + # is the chosen model type of modelorg? + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + # is the gprRules field empty? + if (missing(gprRules)) { + stop("please input an expression!") + } + + if (any(!is.na(match(gprRules,"")))) { + stop("\"\" is no valid logical expression!") + } + + # check the reaction + if (is(react, "reactId")) { + + reactNr <- react_pos(react) + + } + else { + + if (!is(checkReactId(model, react), "reactId")) { + + stop("At least one reaction does not exist in the model!") + + } + else { + + reactNr <- react_pos(checkReactId(model, react)) + + } + + } + + if ( !identical(length(reactNr), length(gprRules)) ) { + stop("not as many logical expressions as reactions!") + } + + ###### is the logical Expression correct? ###### + + checkV <- onlyCheckGPR(model, gprRules, reactNr, verboseMode=verboseMode) + + if (verboseMode > 1) { cat("Updating ... ") } + + ###### the expression is correct. Now change ###### + + model <- onlyChangeGPR(model, gprRules, reactNr, verboseMode=verboseMode) + + #for (anz in seq(1, length(checkV), by = 1)) { + # if (checkV[anz]) { model <- onlyChangeGPR(model, gprRules[anz], + # reactNr[anz], verboseMode=verboseMode) } + #} + + if (verboseMode > 1) { cat("OK.\n") } + + if (verboseMode > 0) { cat("Finished.\n") } + + + return(model) + +} diff --git a/R/changeObjFunc.R b/R/changeObjFunc.R new file mode 100644 index 0000000..45fe2e6 --- /dev/null +++ b/R/changeObjFunc.R @@ -0,0 +1,55 @@ +# changeObjFunc.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: changeObjFunc +# +# +# +# + +changeObjFunc <- function(model, react, obj_coef = rep(1, length(react))) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (length(react) != length(obj_coef)) { + stop("react and obj_coef must have the same length!") + } + + checkedIds <- checkReactId(model, react) + if (!is(checkedIds, "reactId")) { + stop("Check your reaction Id's") + } + + # set all objective coefficients to zero + obj_coef(model) <- numeric(react_num(model)) + + obj_coef(model)[react_pos(checkedIds)] <- obj_coef + + return(model) + +} + diff --git a/R/checkAlgorithm.R b/R/checkAlgorithm.R new file mode 100644 index 0000000..c422b6e --- /dev/null +++ b/R/checkAlgorithm.R @@ -0,0 +1,36 @@ +# checkAlgorithm.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: checkAlgorithm +# +# +# + +checkAlgorithm <- function(alg, purpose) { + + return(alg %in% .SYBILenv$algorithm[[purpose]]) + +} + diff --git a/R/checkDefaultMethod.R b/R/checkDefaultMethod.R new file mode 100644 index 0000000..2cfe8b3 --- /dev/null +++ b/R/checkDefaultMethod.R @@ -0,0 +1,126 @@ +# checkDefaultMethod.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +checkDefaultMethod <- function(solver, method, probType, loadPackage = TRUE) { + + stopifnot(is(solver, "character"), + is(method, "character"), + is(probType, "character")) + +# # -------------------------------------------------------------- # +# # load solver package +# +# if (isTRUE(loadPackage)) { +# checkPackage <- require(solver, character.only = TRUE) +# +# if(!isTRUE(checkPackage)) { +# stop("package ", sQuote(solver), " not found") +# } +# } + + # -------------------------------------------------------------- # + # validate solver + + val_solver_ind <- match(solver, .SYBILenv$solvers) + + if (is.na(val_solver_ind)) { + cmd <- paste(solver, ".onAttach()", sep = ":::") + slv <- tryCatch(eval(parse(text = cmd)), error = function(e) e) + if (isTRUE(slv)) { + val_solver_ind <- match(solver, .SYBILenv$solvers) + } + + if (is.na(val_solver_ind)) { + val_solver_ind <- 1L + warning("solver ", sQuote(solver), + " not found, using default: ", + sQuote(.SYBILenv$solvers[val_solver_ind])) + } + } + + val_solver <- .SYBILenv$solvers[val_solver_ind] + + + # -------------------------------------------------------------- # + # validate method + + val_method_ind <- match(method, .SYBILenv$solverMethods[[val_solver]]) + + if (is.na(val_method_ind)) { + val_method <- .SYBILenv$solverMethods[[val_solver]][1] + } + else { + val_method <- .SYBILenv$solverMethods[[val_solver]][val_method_ind] + } + + + # -------------------------------------------------------------- # + # validate method with problem type + + if (probType %in% names(.SYBILenv$ptype)) { + if (val_solver %in% names(.SYBILenv$ptype[[probType]])) { + meth_tmp <- match(val_method, .SYBILenv$ptype[[probType]][[val_solver]]) + if (is.na(meth_tmp)) { + val_method <- .SYBILenv$ptype[[probType]][[val_solver]][1] + } + } + else { + stop("solver ", sQuote(val_solver), + " can not handle problems of type ", sQuote(probType)) + } + } + + + # -------------------------------------------------------------- # + # solver parameters + + ctrl_parm <- .SYBILenv$solverCtrlParm[[val_solver]][[val_method]] + + if (is.null(ctrl_parm)) { + ctrl_parm <- as.data.frame(NA) + } + + + # -------------------------------------------------------------- # + # load solver package + + if (isTRUE(loadPackage)) { + checkPackage <- require(val_solver, character.only = TRUE) + + if(!isTRUE(checkPackage)) { + stop("package ", sQuote(val_solver), " not found") + } + } + + # -------------------------------------------------------------- # + # done + + return(list(sol = as.character(val_solver), + met = as.character(val_method), + parm = ctrl_parm + ) + ) + +} + diff --git a/R/checkEmptyField.R b/R/checkEmptyField.R new file mode 100644 index 0000000..661d518 --- /dev/null +++ b/R/checkEmptyField.R @@ -0,0 +1,48 @@ +# checkEmptyField.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .checkEmptyField +# +# +# + +.checkEmptyField <- function(vec, name) { + + nalines <- which(is.na(vec) | nchar(vec, allowNA = TRUE) == 0) + if (length(nalines) > 0) { + msg <- sprintf(ngettext(length(nalines), + paste(" for", sQuote(name), "in %d line: %s"), + paste("s for", sQuote(name), "in %d lines: %s")), + length(nalines), paste(nalines+1, collapse = ", ")) + msg <- paste("empty field", msg, "\n", sep = "") + out <- list(nalines = nalines, msg = msg) + } + else { + out <- NULL + } + + return(out) + +} diff --git a/R/checkReactId.R b/R/checkReactId.R new file mode 100644 index 0000000..d6b91d6 --- /dev/null +++ b/R/checkReactId.R @@ -0,0 +1,138 @@ +# checkReactId.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: checkReactId +# +# +# +# + +checkReactId <- function(model, react) { + + if (is(react, "reactId")) { + return(react) + } + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + checkedIds <- NULL + + +#------------------------------------------------------------------------------# +# if "react" is numeric # +#------------------------------------------------------------------------------# + +# If react is numeric (or integer), we only need to check, whether no element of +# react is larger than the number of reactions and if all elements are positive. + + if (is.numeric(react) || is.integer(react)) { + + if ( (max(react) > react_num(model)) || (min(react) < 1) ) { + #if ( (max(react) > react_num(model)) || (!all(react > 0)) ) { + warning("reaction numbers must be in between 1 and ", react_num(model)) + } + else { + checkedIds <- new("reactId", + mod_id = mod_id(model), + mod_key = mod_key(model), + pnt = react, + id = react_id(model)[react]) + } + #return(checkedIds) + + } + +#------------------------------------------------------------------------------# +# if "react" is character # +#------------------------------------------------------------------------------# + + if (is(react, "character")) { + reaction_ids <- react_id(model) + + # find the vector indices in the model of react + pos <- match(react, reaction_ids, nomatch = 0) + if (all(pos != 0)) { + checkedIds <- new("reactId", + mod_id = mod_id(model), + mod_key = mod_key(model), + pnt = pos, + id = react) + #return(checkedIds) + #return(list(id = react, pos = pos)) + } + + # if we cannot find some entries in react, we try grep + else { + #print(pos) + # only those, we could not find above + pos_null <- which(pos == 0) + + # the grep + react_null <- sapply(pos_null, function(x) grep(react[x], reaction_ids, ignore.case = TRUE, value = TRUE)) + + #react <- sapply(react, function(x) grep(x, Dmodel@react_id, ignore.case = TRUE, value = TRUE)) + + # check whether all results are unique + #print(is(react_null)) + #print(react_null) + len <- sapply(react_null, length) + n_uniq <- which(len != 1) + + #print(len) + + if ((length(n_uniq) != 0) || (is(react_null, "matrix"))) { + warning("some reaction id's were not found or are ambiguous", call. = FALSE) + #print(n_uniq) + #return(FALSE) + #return(NA) + } + else { + pos_react <- match(react_null, reaction_ids) + #print(pos_null) + #print(pos_react) + #print(react_null) + + pos[pos_null] <- pos_react + react[pos_null] <- react_null + #print(pos) + #print(react) + #pos <- match(react, model@react_id) + + checkedIds <- new("reactId", + mod_id = mod_id(model), + mod_key = mod_key(model), + pnt = pos, + id = react) + #return(checkedIds) + #return(list(id = react, pos = pos)) + } + } + } + + return(checkedIds) + +} diff --git a/R/check_brackets.R b/R/check_brackets.R new file mode 100644 index 0000000..48528fc --- /dev/null +++ b/R/check_brackets.R @@ -0,0 +1,49 @@ +# check_brackets.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .check_brackets +# +# +# + + +# check, whether we have the same number of '(' and ')'. +.check_brackets <- function(rule) { + + i <- 1 + nb <- 0 + nc <- length(rule) + + while ( (nb >= 0) && (i <= nc) ) { + switch(rule[i], + "(" = { nb <- nb + 1 }, + ")" = { nb <- nb - 1 } + ) + i <- i + 1 + } + + return( ifelse(nb == 0, TRUE, FALSE) ) + +} diff --git a/R/checksolClass.R b/R/checksolClass.R new file mode 100644 index 0000000..8659abf --- /dev/null +++ b/R/checksolClass.R @@ -0,0 +1,192 @@ +# checksolClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# checksolClass + + +#------------------------------------------------------------------------------# +# definition of the class checksol # +#------------------------------------------------------------------------------# + +setClass("checksol", + representation( + num_of_prob = "integer", + exit_code = "integer", + exit_num = "integer", + exit_meaning = "character", + status_code = "integer", + status_num = "integer", + status_meaning = "character" + ) +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +checksol <- function() { + new("checksol") +} + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# num_of_prob +setMethod("num_of_prob", signature(object = "checksol"), + function(object) { + return(object@num_of_prob) + } +) + +setReplaceMethod("num_of_prob", signature = (object = "checksol"), + function(object, value) { + object@num_of_prob <- value + return(object) + } +) + + +# exit_code +setMethod("exit_code", signature(object = "checksol"), + function(object) { + return(object@exit_code) + } +) + +setReplaceMethod("exit_code", signature = (object = "checksol"), + function(object, value) { + object@exit_code <- value + return(object) + } +) + + +# exit_num +setMethod("exit_num", signature(object = "checksol"), + function(object) { + return(object@exit_num) + } +) + +setReplaceMethod("exit_num", signature = (object = "checksol"), + function(object, value) { + object@exit_num <- value + return(object) + } +) + + +# exit_meaning +setMethod("exit_meaning", signature(object = "checksol"), + function(object) { + return(object@exit_meaning) + } +) + +setReplaceMethod("exit_meaning", signature = (object = "checksol"), + function(object, value) { + object@exit_meaning <- value + return(object) + } +) + + +# status_code +setMethod("status_code", signature(object = "checksol"), + function(object) { + return(object@status_code) + } +) + +setReplaceMethod("status_code", signature = (object = "checksol"), + function(object, value) { + object@status_code <- value + return(object) + } +) + + +# status_num +setMethod("status_num", signature(object = "checksol"), + function(object) { + return(object@status_num) + } +) + +setReplaceMethod("status_num", signature = (object = "checksol"), + function(object, value) { + object@status_num <- value + return(object) + } +) + + + +# status_meaning +setMethod("status_meaning", signature(object = "checksol"), + function(object) { + return(object@status_meaning) + } +) + +setReplaceMethod("status_meaning", signature = (object = "checksol"), + function(object, value) { + object@status_meaning <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("show", signature(object = "checksol"), + function(object) { + cat("Return code:\n") + cat(" Code # meaning\n") + tmp <- sprintf(" %-8i%-8i%s\n", + exit_code(object), + exit_num(object), + exit_meaning(object)) + cat(tmp, sep = "") + + cat("\n") + cat("Solution status:\n") + cat(" Code # meaning\n") + + tmp <- sprintf(" %-8i%-8i%s\n", + status_code(object), + status_num(object), + status_meaning(object)) + cat(tmp, sep = "") + num <- num_of_prob(object) + if (num > 1) { + cat("\n", num, " optimizations were performed.\n", sep = "") + } + } +) diff --git a/R/createReactionString.R b/R/createReactionString.R new file mode 100644 index 0000000..cfb13a1 --- /dev/null +++ b/R/createReactionString.R @@ -0,0 +1,158 @@ +# createReactionString.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .createReactionString +# +# +# + +.createReactionString <- function(model, + makeClosedNetwork, + entrydelim = ", ", + extMetFlag = "b") { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + # required data structures + equat <- vector(mode = "character", length = react_num(model)) + compat <- vector(mode = "character", length = react_num(model)) + + revers <- ifelse(react_rev(model), "Reversible", "Irreversible") + arrow <- ifelse(react_rev(model), "<==>", "-->") + + + # remove compartment flag if existing + metab <- sub("\\[\\w+\\]$", "", met_id(model)) + metcp <- sub(".+(\\[\\w+\\])$", "\\1", met_id(model)) + + for (j in 1:react_num(model)) { + column <- S(model)[,j] + + # row indices + constr_ind <- which(column != 0) + # stoichiometric coefficients + stcoef <- column[constr_ind] + + # check if reaction is empty + if (length(constr_ind) > 0) { + + comp <- unique(mod_compart(model)[met_comp(model)[constr_ind]]) + + # reaction involves more than one compartment + if (length(comp) > 1) { + if (metcp[constr_ind[1]] == metab[constr_ind[1]]) { + metr <- paste(met_id(model)[constr_ind], + "[", + mod_compart(model)[met_comp(model)[constr_ind]], + "]", + sep = "") + } + else { + metr <- met_id(model)[constr_ind] + } + compat[j] <- paste(comp, collapse = entrydelim) + compflag <- "" + } else { + # Check if the current reaction is an exchange reaction. + # In order to build a closed network, we need to add a 'boundary' + # metabolite [b]. + if ( (isTRUE(makeClosedNetwork)) && (length(constr_ind) == 1) ) { + if (metcp[constr_ind[1]] == metab[constr_ind[1]]) { + metIN <- paste(met_id(model)[constr_ind], + "[", + mod_compart(model)[met_comp(model)[constr_ind[1]]], + "]", + sep = "") + } + else { + metIN <- met_id(model)[constr_ind] + } + metr <- c(metIN, + paste(metab[constr_ind], + "[", extMetFlag, "]",sep = "")) + constr_ind <- c(constr_ind, constr_ind) + stcoef <- c(stcoef, (stcoef * -1)) + compat[j] <- comp + compflag <- "" + } + else { + metr <- metab[constr_ind] + compat[j] <- comp + # if yes, the metabolite id does not contain the metabolite + # compartment + if (metcp[constr_ind[1]] == metab[constr_ind[1]]) { + compflag <- paste("[", + mod_compart(model)[met_comp(model)[constr_ind[1]]], + "]", + sep = "") + } + else { + compflag <- metcp[constr_ind[1]] + } + } + } + + educt <- vector(mode = "list") + product <- vector(mode = "list") + + for (i in seq(along = constr_ind)) { + if (stcoef[i] > 0) { + stoich <- ifelse(stcoef[i] != 1, + paste("(", stcoef[i], ") ", sep = ""), + "") + product[metr[i]] <- paste(stoich, metr[i], sep = "") + } + else { + stoich <- ifelse(stcoef[i] != -1, + paste("(", (stcoef[i] * -1), ") ", sep = ""), + "") + educt[metr[i]] <- paste(stoich, metr[i], sep = "") + } + } + + + equattmp <- paste(paste(educt, collapse = " + "), + arrow[j], + paste(product, collapse = " + ")) + + if (compflag == "") { + equat[j] <- equattmp + } + else { + equat[j] <- paste(compflag, equattmp, sep = " : ") + } + + } + + } + + return(list(equat = equat, + compat = compat, + revers = revers, + metab = metab)) + +} diff --git a/R/deadEndMetabolite.R b/R/deadEndMetabolite.R new file mode 100644 index 0000000..f74c8c5 --- /dev/null +++ b/R/deadEndMetabolite.R @@ -0,0 +1,149 @@ +# deadEndMetabolite.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .deadEndMetabolite +# +# +# The function .deadEndMetabolite() is inspired by the functions +# detectDeadEnds() and removeDeadEnds contained in the COBRA Toolbox. +# The algorithm is basically the same. + + +.deadEndMetabolite <- function(mat, + lb, + exclM, + exclR, + tol = SYBIL_SETTINGS("TOLERANCE")) { + + # candM and candR can be used for singleton metabolites + if ( (missing(exclM)) || (any(is.na(exclM))) ) { + deCandM <- logical(nrow(mat)) + } + else { + deCandM <- exclM + } + + if ( (missing(exclR)) || (any(is.na(exclR))) ) { + deCandR <- logical(ncol(mat)) + } + else { + deCandR <- exclR + } + + # generate smaller matrix without singleton metabolites + indMatM <- c(1:nrow(mat))[!deCandM] + indMatR <- c(1:ncol(mat))[!deCandR] + + tmp_mat <- mat[!deCandM, , drop = FALSE] + tmp_mat <- tmp_mat[ , !deCandR, drop = FALSE] + + check <- TRUE + DEreact <- logical(ncol(tmp_mat)) + DEmet <- logical(nrow(tmp_mat)) + + + # check is set to FALSE, if no more dead end metabolites can be found + while (isTRUE(check)) { + + temp_dem <- rep(FALSE, nrow(tmp_mat)) + + # metabolites + i <- 1 + while(i <= nrow(tmp_mat)) { + + # isDE is FALSE, if metabolite i is not dead end + isDE <- NA + + # reactions (non-zero elements in row i) + nz <- which(abs(tmp_mat[i, ]) > tol) + + j <- 1 + while(j <= length(nz)) { + + if ( (!is.na(isDE)) && (isTRUE(isDE)) ) { + break + } + + if (is.na(isDE)) { + + # assume, metabolite i is dead end for reaction j + isDE <- TRUE + + # check, if metabolite i can be excluded from the + # dead end list: test all reactions k > j + k <- j+1 + while (k <= length(nz)) { + if ( (tmp_mat[i, nz[k]] != tmp_mat[i, nz[j]]) || + (lb[nz[k]] < 0) || + (lb[nz[j]] < 0) ) { + #print(paste(i,":",k)) + isDE <- FALSE + break + } + else { + k <- k+1 + } + } + } + + # if isDE stays TRUE, metabolite i is dead end + if (isTRUE(isDE)) { + temp_dem[i] <- TRUE + break + } + else { + j <- j + 1 + } + } + + i <- i+1 + + } + + if (sum(temp_dem) == 0) { + check <- FALSE + } + else { + DEmet[temp_dem] <- TRUE + matb <- abs(tmp_mat) > tol + crs <- which(colSums(matb[temp_dem, , drop = FALSE]) != 0) + tmp_mat[ , crs] <- 0 + DEreact[crs] <- TRUE + } + + } + + + # put DEmet and DEreact to their original size + # (if arguments exclR or exclM were used) + DEMret <- logical(nrow(mat)) + DERret <- logical(ncol(mat)) + + DEMret[indMatM] <- DEmet + DERret[indMatR] <- DEreact + + return(list(dem = DEMret, der = DERret)) + +} diff --git a/R/doInRound.R b/R/doInRound.R new file mode 100644 index 0000000..eac4ff7 --- /dev/null +++ b/R/doInRound.R @@ -0,0 +1,75 @@ +# doInRound.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .doInRound +# +# +# + + +.doInRound <- function(indRounds, maxRounds) { + + if (maxRounds < 1) { + stop("Argument 'maxRounds' must be > 0") + } + + if (is.null(indRounds)) { + runPP <- c(1:maxRounds) + } + else { + if (is(indRounds, "character")) { + + # make indRounds integer values + DIR <- as.integer(indRounds) + + # first value is treated as offset, if indRounds + # contains two elements (more than two elements are ignored) + if (length(DIR) > 1) { + offs <- DIR[1] + DIR <- ifelse(DIR[2] < 1, 1L, abs(DIR[2])) + } + else { + offs <- 0L + DIR <- ifelse(DIR[1] < 1, 1L, abs(DIR[1])) + } + + # when we will run pre/post processing + runPP <- seq(from = (DIR+offs), to = maxRounds, by = DIR) + runPP <- runPP[runPP > 0] + + } + else if (is(indRounds, "numeric")) { + runPP <- sort(as.integer(indRounds[indRounds > 0])) + } + else { + warning("Argument 'indRounds' must be numeric or character") + runPP <- c(1:maxRounds) + } + } + + return(runPP) + +} + diff --git a/R/doubleFluxDel.R b/R/doubleFluxDel.R new file mode 100644 index 0000000..ba4361e --- /dev/null +++ b/R/doubleFluxDel.R @@ -0,0 +1,202 @@ +# doubleFluxDel.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: doubleFluxDel +# +# This function performs a "double gene deletion analysis". +# In each iteration one gene is switched of (vi = 0) +# and the objective function will be computed. + + +doubleFluxDel <- function(model, react1, react2, lb = NULL, ub = NULL, + allComb = FALSE, exex = FALSE, + checkOptSolObj = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + ex <- 0 + + if (missing(react1)) { + ex <- 1 + react1 <- checkReactId(model, 1:react_num(model)) + } + else { + if (!is(react1, "reactId")) { + react1 <- checkReactId(model, react1) + } + } + + if (missing(react2)) { + ex <- 2 + react2 <- checkReactId(model, 1:react_num(model)) + } + else { + if (!is(react2, "reactId")) { + react2 <- checkReactId(model, react2) + } + } + + react1 <- sort(react_pos(react1)) + react2 <- sort(react_pos(react2)) + + +#------------------------------------------------------------------------------# +# remove exchange reactions # +#------------------------------------------------------------------------------# + + if ((ex == 2) && (exex == TRUE)) { + + exch <- findExchReact(model) + exch <- react_pos(exch) + + react1 <- react1[-exch] + react2 <- react2[-exch] + + } + + num_react1 <- length(react1) + num_react2 <- length(react2) + + if ((!isTRUE(allComb)) && (num_react1 != num_react2)) { + stop("react1 and react2 must have the same length") + } + + +#------------------------------------------------------------------------------# +# calculate the number of optimizations (num_opt) # +#------------------------------------------------------------------------------# + +# print(react1) +# print(react2) + + if (isTRUE(allComb)) { + + # Compute Boolean matrix with TRUE in the upper triangonal + # (the maximum number of comparisons) + tmpMAT <- upper.tri(matrix(nrow = react_num(model), + ncol = react_num(model))) + + # The next step is, to compute the differences between the two fields. + # If an element of react1 is not in react2, we have to set the + # corresponding row to TRUE and vice versa. + tmpDIFF <- setdiff(react2, react1) + # print(tmpDIFF) + + if (length(tmpDIFF) != 0) { + tmpMAT[,tmpDIFF] <- TRUE + } + + tmpDIFF <- setdiff(react1, react2) + # print(tmpDIFF) + + if (length(tmpDIFF) != 0) { + tmpMAT[tmpDIFF,] <- TRUE + } + + # Exclude everything from tmpMAT we do not need. + tmpMAT <- tmpMAT[react1, react2] + + # We need this, if the resulting matrix is no longer 2 dimensional + if (is.null(dim(tmpMAT))) { + tmpMAT <- as.matrix(tmpMAT, byrow = TRUE) + if (num_react1 < num_react2) { + tmpMAT <- t(tmpMAT) + } + } + # The number of TRUE's in tmpMAT is equal to the number of optimizations + num_opt <- sum(tmpMAT == TRUE) + + } + else { + + tmpMAT <- matrix(FALSE, nrow = react_num(model), + ncol = react_num(model)) + for (i in 1:num_react1) { + tmpMAT[react1[i], react2[i]] <- TRUE + } + #tmpMAT[geneList1, geneList2] <- TRUE + num_opt <- num_react1 + tmpMAT <- tmpMAT[react1, react2] + + } + + rownames(tmpMAT) <- react1 + colnames(tmpMAT) <- react2 + + + # The number of TRUE's in tmpMAT is equal to the number of optimizations + # print(num_opt) + + +#------------------------------------------------------------------------------# +# run optimization # +#------------------------------------------------------------------------------# + + deletions <- which(tmpMAT == TRUE, arr.ind = TRUE) + + koreactID <- cbind(react1[deletions[,"row"]], + react2[deletions[,"col"]]) + koreact <- lapply(seq_len(nrow(koreactID)), function(x) koreactID[x, ]) + + if (is.null(lb)) { + lb <- rep(0, length(koreact)) + } + else { + if (length(lb) != length(koreact)) { + stop("lb must be of length ", length(koreact)) + } + } + if (is.null(ub)) { + ub <- rep(0, length(koreact)) + } + else { + if (length(ub) != length(koreact)) { + stop("ub must be of length ", length(koreact)) + } + } + + sol <- optimizer(model = model, lb = lb, ub = ub, react = koreact, ...) + + + # ------------------------------------------------------------------------ # + + optsol <- new("optsol_fluxdel") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + chlb(optsol) <- as.numeric(lb) + chub(optsol) <- as.numeric(ub) + dels(optsol) <- matrix(react_id(model)[koreactID], ncol = 2) + + if (isTRUE(checkOptSolObj)) { + checkOptSol(optsol, onlywarn = TRUE) + } + + return(optsol) + +} + diff --git a/R/doubleGeneDel.R b/R/doubleGeneDel.R new file mode 100644 index 0000000..84b3ac7 --- /dev/null +++ b/R/doubleGeneDel.R @@ -0,0 +1,283 @@ +# doubleGeneDel.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: doubleGeneDel +# +# This function performs a "double gene deletion analysis". +# In each iteration one gene is switched of (vi = 0) +# and the objective function will be computed. +# +# The function doubleGeneDel() is inspired by the function +# doubleGeneDeletion() contained in the COBRA Toolbox. + + +doubleGeneDel <- function(model, geneList1, geneList2, lb = NULL, ub = NULL, + allComb = FALSE, exLethal = TRUE, + tol = SYBIL_SETTINGS("TOLERANCE"), + checkOptSolObj = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + + # maybe we need here something like checkGeneId + + if (missing(geneList1)) { + geneList1 <- allGenes(model) + } + else { + if (is.na(all(match(geneList1, allGenes(model))))) { + stop("check genelist1!") + } + } + + if (missing(geneList2)) { + geneList2 <- allGenes(model) + } + else { + if (is.na(all(match(geneList2, allGenes(model))))) { + stop("check genelist2!") + } + } + + if (length(geneList1) < 1) { + stop("Argument 'geneList1' must contain at least one gene!") + } + if (length(geneList2) < 1) { + stop("Argument 'geneList2' must contain at least one gene!") + } + + #geneList1 <- sort(match(geneList1, allGenes(model))) + #geneList2 <- sort(match(geneList2, allGenes(model))) + geneList1 <- match(geneList1, allGenes(model)) + geneList2 <- match(geneList2, allGenes(model)) + + + num_geneList1 <- length(geneList1) + num_geneList2 <- length(geneList2) + + if ((!isTRUE(allComb)) && (num_geneList1 != num_geneList2)) { + stop("geneList1 and geneList2 must have the same length") + } + + num_genes <- length(allGenes(model)) + + +#------------------------------------------------------------------------------# +# remove lethal genes # +#------------------------------------------------------------------------------# + + if (isTRUE(exLethal)) { + + # all different genes from list1 and list2 + unGenes <- sort(unique(c(geneList1, geneList2))) + + ca <- match.call() + if ("solver" %in% names(ca)) { + # It is necessary to test, whether argument solver has a variable, + # or not. If it is a variable, it needs to be evaluated. + testslv <- tryCatch(eval(parse(text = ca["solver"])), + error = function(e) e) + if (is(testslv, "simpleError")) { + slv <- as.character(ca["solver"]) + } + else { + slv <- as.character(testslv) + } + } + else { + slv <- SYBIL_SETTINGS("SOLVER") + } + + wtobj <- optimizeProb(model, retOptSol = FALSE, + algorithm = "fba", solver = slv, lpdir = "max") + + unSol <- oneGeneDel(model, geneList = unGenes, solver = slv, + lpdir = rep("max", length(unGenes)), + fld = "none", algorithm = "fba") + + # solution id of lethal genes + letid <- lethal(unSol, wtobj$obj) + + # check wether some of the 'essential' genes result in + # an unsuccessfull solution + statNok <- checkStat(unSol[letid]) + + lethal <- letid + #lethal <- letid[-statNok] + + # lethalGeneIds contain the ids of the lethal genes + lethalGeneIds <- unGenes[lethal] + + l1 <- which(geneList1 %in% lethalGeneIds) + l2 <- which(geneList2 %in% lethalGeneIds) + + if (isTRUE(allComb)) { + + if (length(l1) > 0) { + geneList1 <- geneList1[-l1] + } + if (length(l2) > 0) { + geneList2 <- geneList2[-l2] + } + + } + else { + l12 <- sort(unique(c(l1, l2))) + if (length(l12) > 0) { + geneList1 <- geneList1[-l12] + geneList2 <- geneList2[-l12] + } + } + remove(unSol) + } + else { + lethalGeneIds <- as.integer(NA) + } + + +#------------------------------------------------------------------------------# +# calculate the number of optimizations (num_opt) # +#------------------------------------------------------------------------------# + + # m <- outer(mystring, mystring, paste, sep="") + # m[upper.tri(m)] + + + # use merge() or expand.grid() or combn() here!! + + if (isTRUE(allComb)) { + + # Compute Boolean matrix with TRUE in the upper triangonal + # (the maximum number of comparisons) + tmpMAT <- upper.tri(matrix(nrow = num_genes, + ncol = num_genes), diag = FALSE) + + # The next step is, to compute the differences between the two fields. + # If an element of react1 is not in react2, we have to set the + # corresponding row to TRUE and vice versa. + tmpDIFF <- setdiff(geneList2, geneList1) + #print(tmpDIFF) + + if (length(tmpDIFF) != 0) { + tmpMAT[,tmpDIFF] <- TRUE + } + + tmpDIFF <- setdiff(geneList1, geneList2) + #print(tmpDIFF) + + if (length(tmpDIFF) != 0) { + tmpMAT[tmpDIFF,] <- TRUE + } + + # Exclude everything from tmpMAT we do not need. + #tmpMAT <- tmpMAT[geneList1, geneList2, drop = FALSE] + + } + else { + + tmpMAT <- matrix(FALSE, nrow = num_genes, ncol = num_genes) + #diag(tmpMAT) <- TRUE + for (i in seq(along = geneList1)) { + tmpMAT[geneList1[i], geneList2[i]] <- TRUE + } + } + + geneList11 <- geneList1 + geneList22 <- geneList2 + + geneList1 <- unique(geneList1) + geneList2 <- unique(geneList2) + + # Exclude everything from tmpMAT we do not need. + tmpMAT <- tmpMAT[geneList1, geneList2, drop = FALSE] + + # The number of TRUE's in tmpMAT is equal to the number of optimizations + num_opt <- sum(tmpMAT == TRUE) + + + rownames(tmpMAT) <- geneList1 + colnames(tmpMAT) <- geneList2 + #print(tmpMAT) + #print(num_opt) + + +#------------------------------------------------------------------------------# +# run optimization # +#------------------------------------------------------------------------------# + + deletions <- which(tmpMAT == TRUE, arr.ind = TRUE) + + kogenesID <- cbind(geneList1[deletions[,"row"]], + geneList2[deletions[,"col"]]) + kogenes <- lapply(seq_len(nrow(kogenesID)), function(x) kogenesID[x, ]) + + fd <- .generateFluxdels(model, kogenes) + + if (is.null(lb)) { + lb <- rep(0, length(kogenes)) + } + else { + if (length(lb) != length(kogenes)) { + stop("lb must be of length ", length(kogenes)) + } + } + if (is.null(ub)) { + ub <- rep(0, length(kogenes)) + } + else { + if (length(ub) != length(kogenes)) { + stop("ub must be of length ", length(kogenes)) + } + } + + sol <- optimizer(model = model, + react = fd[["react"]], + lb = lb, + ub = ub, + ...) + + + # ------------------------------------------------------------------------ # + + optsol <- new("optsol_genedel") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + chlb(optsol) <- as.numeric(lb) + chub(optsol) <- as.numeric(ub) + dels(optsol) <- matrix(allGenes(model)[kogenesID], ncol = 2) + fluxdels(optsol) <- fd[["fd"]] + hasEffect(optsol) <- fd[["heff"]] + + if (isTRUE(checkOptSolObj)) { + checkOptSol(optsol, onlywarn = TRUE) + } + + return(optsol) + +} + diff --git a/R/doubleReact.R b/R/doubleReact.R new file mode 100644 index 0000000..69b6c54 --- /dev/null +++ b/R/doubleReact.R @@ -0,0 +1,250 @@ +# doubleReact.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: doubleReact +# +# Returns a list with identical reactions: +# The every list element contains two entries: +# 1) the number of metabolites of the reactions, +# 2) an integer vector containing the reaction id's. +# +# So the final result is grouped in classes of reactions; +# a class is defined by the number of corresponding +# metabolites. + + +doubleReact <- function(model, checkRev = TRUE, linInd = FALSE) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + # test, if there are any duplicated columns +# dup <- duplicated(as.matrix(S(model)), MARGIN = 2) +# if (sum(dup) == 0) { +# return(FALSE) +# } +# else { +# # mat: stoichiometric matrix +# # nnzpc: number of non-zeros per column +# # remc: reaction types (in terms of number of metabolites) +# mat <- as(S(model), "CsparseMatrix") +# nnzpc <- mat@p[-1] - mat@p[-length(mat@p)] +# remc <- sort(unique(nnzpc[dup])) +# } +# +# print(sum(dup)) +# #print(nnzpc) +# print(remc) +# print(nnzpc[dup]) +# +# return(shrinkMatrix(model, j = (1:react_num(model))[dup])) +# +# return(TRUE) +#------------------------------------------------------------------------------# +# reaction adjacency matrix # +#------------------------------------------------------------------------------# + + # binary matrix of S + Sbin <- S(model) != 0 + + # diagonal of reaction adjacency matrix, number of compounds in each reaction + #Sbindiag <- diag(t(Sbin) %*% Sbin) + Sbindiag <- diag(crossprod(Sbin)) + + +#------------------------------------------------------------------------------# +# Next, we compute a vector containing all different numbers of compunds in the +# reactions, e.g.: +# Sbindiag <- c(3, 6, 3, 4, 4, 3) +# so recatlength will be +# reactlength <- c(3, 4, 6) +#------------------------------------------------------------------------------# + + # vector with all different reaction length + # (length in the meaning of "number of metabolites") + reactlength <- sort(unique(Sbindiag)) + + + # columns in S corresponding to reactlength + # get the columns of S having a unique reactlength[i] <- j + columns <- sapply(reactlength, function(x) which(x == Sbindiag)) + + +#------------------------------------------------------------------------------# +# compare the columns of S # +#------------------------------------------------------------------------------# + + double_tmp <- integer(0) # a vector where all identical reactions are stored + double <- list() # the main list + clm <- integer(1) # counter for the main list (reactions with m metabolites) + clr <- integer(1) # counter for the sub lists (identical reactions) + checked <- logical(1) + + clm <- 0 + + for (i in 1:length(reactlength)) { + + # number of reactions containing reactlength[i] metabolites + numr <- length(columns[[i]]) + + # only if columns[[i]] contains more than one recation (column index) + if (numr > 1) { + #print("next") + message( + sprintf(ngettext(reactlength[i], + "processing %s reactions with one metabolite ...", + "processing %s reactions with %s metabolites ..." + ), numr, reactlength[i] + ) + ) + + # Put the columns of S into a new matrix, which contain the same + # number of metabolites + Stmp <- cBind(S(model)[, columns[[i]] ]) + + # translate Stmp into a matrix with the row indices of the + # non zero elements + Stmp_rows <- matrix( + apply( + Stmp, 2, function(x) + which(x != 0, arr.ind = TRUE) + ) + , nrow = reactlength[i] + ) + #print(Stmp_rows) + + # A (temporary) list for identical reactions with + # reactlength[i] metabolites + double_react <- list() + #clr <- 1 + clr <- 0 + + # walk through Stmp + for (k in 1:(numr-1)) { + + .progressDots(10, k, (numr-1)) + + # a vector containing the column indices of S of reactions + # that are identical to reaction k in Stmp + ident_react <- integer(0) + + l <- k + 1 + while(l <= numr) { + checked <- FALSE + + # If both columns were already compared with some + # other column, they are the same and need not to + # be checked again. Uses double_tmp. + if (all( match( + c(columns[[i]][k], columns[[i]][l]), + double_tmp, nomatch = 0 + ) + != 0) + ) { + + l <- l + 1 + next + } + + # First, we only check whether the row indices of the + # non zero entries in columns k and l are the same (the + # columns are much smaller if we only take the row indices). + if (identical(Stmp_rows[, k],Stmp_rows[, l])) { + + # If they are the same, the stiochiometric coeficients + # are checked. If they are also the same, the two columns + # k and l (reactions) are considered to be the same. + + if (isTRUE(linInd)) { + # We only chack for linear independence, if all + # stoichiometric coefficients heve the same sign, + # otherwise (-1, 1) and (1, -1) are the same. + a <- Stmp[Stmp_rows[, k], k] + b <- Stmp[Stmp_rows[, l], l] + if (identical(sign(a), sign(b))) { + decomp <- qr(cbind(Stmp[Stmp_rows[, k], k], Stmp[Stmp_rows[, l], l])) + checkIdent <- decomp$rank != 2 # rank == 2 means 2 vectors are linear independent + } + else { + checkIdent <- FALSE + } + } + else { + checkIdent <- identical(Stmp[Stmp_rows[, k], k], Stmp[Stmp_rows[, l], l]) + } + + #if (identical(Stmp[Stmp_rows[, k], k], Stmp[Stmp_rows[, l], l])) { + if (isTRUE(checkIdent)) { + + # check the reversibilities + if (checkRev == TRUE) { + if (identical(react_rev(model)[columns[[i]][k]], react_rev(model)[columns[[i]][l]])) { + checked <- TRUE + } + } + else { + checked <- TRUE + } + + if (checked == TRUE) { + double_tmp <- c(double_tmp, columns[[i]][k], columns[[i]][l]) + ident_react <- c(ident_react, columns[[i]][k], columns[[i]][l]) + } + } + } + + l <- l + 1 + } + + # if ident_react contains something, we put it into the + # list double_react (only different entries - unique) + if (length(ident_react != 0)) { + clr <- clr + 1 + double_react[[clr]] <- unique(ident_react) + } + } + + # if double_react contains something, we put it into the + # main list double + if (length(double_react) != 0) { + clm <- clm + 1 + #double_react[[1]] <- reactlength[i] + #double[[clm]] <- double_react + double <- append(double, double_react) + } + } + } + + # Return FALSE if there are no double recations, + # otherwise return a list with double reactions. + if (length(double) != 0) { + return(double) + } + else { + return(FALSE) + } + +} diff --git a/R/editEnvir.R b/R/editEnvir.R new file mode 100644 index 0000000..d875ce8 --- /dev/null +++ b/R/editEnvir.R @@ -0,0 +1,58 @@ +# editEnvir.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: editEnvir +# +# +# + +editEnvir <- function(model, newKey = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("model must be of class modelorg") + } + + ex <- findExchReact(model) + exid <- react_pos(ex) + + exfr <- data.frame("reaction_id" = react_id(model)[exid], + "lower_bound" = lowbnd(model)[exid], + "upper_bound" = uppbnd(model)[exid], + "reaction_name" = react_name(model)[exid]) + + exfr <- edit(exfr, ...) + + lowbnd(model)[exid] <- exfr[["lower_bound"]] + uppbnd(model)[exid] <- exfr[["upper_bound"]] + + if (isTRUE(newKey)) { + mod_key(model) <- .generateModKey() + } + + validObject(model) + + return(model) + +} diff --git a/R/findExchReact.R b/R/findExchReact.R new file mode 100644 index 0000000..4715a58 --- /dev/null +++ b/R/findExchReact.R @@ -0,0 +1,105 @@ +# findExchReact.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: findExchReact +# +# The function findExchReact() is inspired by the function +# findExcRxns() contained in the COBRA Toolbox. +# The algorithm is the same. + + +findExchReact <- function(model) { + + if ( (!is(model, "modelorg")) && + !( (is(model, "Matrix")) || (is(model, "matrix")) ) ) { + stop("needs an object of class modelorg, Matrix or matrix!") + } + + if (is(model, "modelorg")) { + St <- S(model) + } + else { + St <- model + } + + # columns with only one entry + oneEntry <- apply(St, 2, function(x) sum(x != 0) == 1) + + if (sum(oneEntry) > 0) { + # exchange reactions -- with a -1 or 1 + exchangeReact <- apply(St[ , oneEntry, drop = FALSE], 2, function(x) (sum(x == 1) == 1) | (sum(x == -1) == 1)) + + # vector with the reaction id's of the exchange reactions + ex <- c(1 : dim(St)[2])[oneEntry[exchangeReact]] + + # uptake reactions + up <- NA + if (is(model, "modelorg_irrev")) { + up <- apply(St[,oneEntry], 2, function(x) (sum(x == 1) == 1)) + } + + if ((is(model, "modelorg")) && (!is(model, "modelorg_irrev"))) { + up <- lowbnd(model)[ex] < 0 + } + + if (is(model, "modelorg")) { + + # get the row id's of S containing the non-zeros of the exchange reactions + #exMet <- which(Matrix::rowSums(abs(S(model)[, ex])) == 1) + + # must be '> 0', because irreversible models (including exchange + # reactions) have 2 entries per row, if the exchange reaction is + # reversible + exMet <- which(Matrix::rowSums(abs(S(model)[, ex, drop = FALSE])) > 0) + + # get the rows in the correct order + # (if exchange reactions are not in main diagonal) + + ### as(S(model), "CsparseMatrix") ### + metabolite <- exMet[S(model)[exMet, ex, drop = FALSE]@i+1] + + react <- new("reactId_Exch", + mod_id = mod_id(model), + mod_key = mod_key(model), + rpnt = ex, + rid = react_id(model)[ex], + upt = up, + mpnt = metabolite, + mid = met_id(model)[metabolite], + lb = lowbnd(model)[ex], + ub = uppbnd(model)[ex]) + } + else { + react <- oneEntry[exchangeReact] + } + } + else { + warning("no exchange reaction found") + react <- NULL + } + + return(react) + +} diff --git a/R/floorValues.R b/R/floorValues.R new file mode 100644 index 0000000..c34ee05 --- /dev/null +++ b/R/floorValues.R @@ -0,0 +1,41 @@ +# floorValues.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .floorValues +# +# +# + +.floorValues <- function(val, tol = SYBIL_SETTINGS("TOLERANCE")) { + + if (!is(val, "numeric")) { + stop( c("Argument val has to be numeric!") ) + } + + floorVal <- floor(val/tol)*tol + + return(floorVal) + +} diff --git a/R/fluxDistributionClass.R b/R/fluxDistributionClass.R new file mode 100644 index 0000000..cba1573 --- /dev/null +++ b/R/fluxDistributionClass.R @@ -0,0 +1,295 @@ +# fluxDistributionClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# fluxDistributionClass + +#------------------------------------------------------------------------------# +# definition of the class fluxDistribution # +#------------------------------------------------------------------------------# + +setClass("fluxDistribution", + representation( + fluxes = "Matrix", + num_of_fluxes = "integer" + ) +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +fluxDistribution <- function(fluxes = NA, nrow = 1, ncol = 1) { + + if (is(fluxes, "matrix")) { + Mfluxes <- as(fluxes, "Matrix") + } + else if (is(fluxes, "Matrix")) { + Mfluxes <- fluxes + } + else { + Mfluxes <- Matrix::Matrix(fluxes, nrow = nrow, ncol = ncol) + } + + num_of_fluxes <- length(Mfluxes) + + obj <- new("fluxDistribution", + fluxes = Mfluxes, + num_of_fluxes = as.integer(num_of_fluxes)) + return(obj) +} + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# fluxes +setMethod("fluxes", signature(object = "fluxDistribution"), + function(object) { + return(object@fluxes) + } +) + +setReplaceMethod("fluxes", signature = (object = "fluxDistribution"), + function(object, value) { + object@fluxes <- value + return(object) + } +) + + +# number of fluxes +setMethod("num_of_fluxes", signature(object = "fluxDistribution"), + function(object) { + return(object@num_of_fluxes) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +# nnzero +setMethod("nnzero", signature(x = "fluxDistribution"), + function(x) { + + nnz <- Matrix::nnzero(fluxes(x)) + return(nnz) + + } +) + + +# nvar +setMethod("nvar", signature(object = "fluxDistribution"), + function(object) { + + nr <- nrow(fluxes(object)) + return(nr) + + } +) + + +# [ +setMethod("[", signature(x = "fluxDistribution"), + function(x, i, j, ..., drop = FALSE) { + + if (missing(i)) { + i <- c(1:nrow(x@fluxes)) + } + + if (missing(j)) { + j <- c(1:ncol(x@fluxes)) + } + + + newfld <- fluxDistribution(x@fluxes[i,j], + nrow = length(i), + ncol = length(j)) + + return(newfld) + + } + +) + + +setMethod("plot", signature(x = "fluxDistribution", y = "missing"), + function(x, y, ordReact, ordMut, todo = "absdev", ...) { + + if (any(is.na(fluxes(x)))) { + stop("fluxdistribution is required.") + } + + checkPackage <- require("lattice") + if(!isTRUE(checkPackage)) { + stop("Package lattice not found.") + } + checkPackage <- require("grid") + if(!isTRUE(checkPackage)) { + stop("Package grid not found.") + } + +#g <- apply(subSys(bla), 1, function(x) colnames(subSys(bla))[x]) +#order(g) + + # Arguments ordReact and ordMut can be numeric vectors or lists: + # + # numeric vectors: + # a vector of length n (number of reactions) if ordReact, or + # a vector of length number of mutations (number of problems to + # solve, minus wild type). + # The vector contains a desired permutation of indices. + # + # list containing two elements 'cat' and 'bin': + # Element 'cat' is a character vector containing category names. + # Element 'bin' is a numeric vector connecting the elements in + # 'cat' with the reactions or mutations. + + + if (missing(ordReact)) { + cat <- NA + fld <- fluxes(x) + } + else { + if (is.list(ordReact)) { + cat <- ordReact$cat[ordReact$bin] + fld <- fluxes(x)[ordReact$bin, ] + } + else if (is.numeric(ordReact)) { + cat <- NA + fld <- fluxes(x)[ordReact, ] + } + else { + stop("argument 'ordReact' must be numeric or list.") + } + } + + + # first column is always wild type + ref <- fld[, 1] + bin <- fld[ ,(2 : ncol(fld)-1)] + #print(is(mat)) + + mat <- switch(todo, + "reldev" = { + bin <- abs(ref) < SYBIL_SETTINGS("TOLERANCE") + }, + "absdev" = { + fld - ref + }, + { + fld + } + ) + + + #nz <- abs(mat) < SYBIL_SETTINGS("TOLERANCE") + #mat[nz] <- 0 + + # 20 breaks + br <- c(-1e+03, -1e+02, -1e+01, -1e+00, + -1e-01, -1e-02, -1e-03, -1e-04, -1e-05, -1e-06, + #0e+00, + 1e-06, 1e-05, 1e-04, 1e-03, 1e-02, 1e-01, + 1e+00, 1e+01, 1e+02, 1e+03) + + + + ylabels = c(expression(-10^3), + expression(-10^2), + expression(-10^1), + expression(-10^0), + expression(-10^-1), + expression(-10^-2), + expression(-10^-3), + expression(-10^-4), + expression(-10^-5), + expression(-10^-6), + expression(~~10^-6), + expression(~~10^-5), + expression(~~10^-4), + expression(~~10^-3), + expression(~~10^-2), + expression(~~10^-1), + expression(~~10^0), + expression(~~10^1), + expression(~~10^2), + expression(~~10^3) + ) + + + # + ## colors are from RColorBrewer: + ## rev(brewer.pal(9, "Blues")) for negative values + ## brewer.pal(9, "Reds") for positive values + + # colors: blue negative vale, red positive value + neg <- c("#08306B", "#08519C", "#2171B5", "#4292C6", "#6BAED6", + "#9ECAE1", "#C6DBEF", "#DEEBF7", "#F7FBFF") + + # green + #neg <- c("#00441B", "#006D2C", "#238B45", "#41AB5D", "#74C476", + # "#A1D99B", "#C7E9C0", "#E5F5E0", "#F7FCF5") + + pos <- c("#FFF5F0", "#FEE0D2", "#FCBBA1", "#FC9272", "#FB6A4A", + "#EF3B2C", "#CB181D", "#A50F15", "#67000D") + + colors <- c(neg, "#FFFFFF", pos) + + + #layout(matrix(c(1, 2), ncol = 2), widths = c(1,4)) + #image(z = t(ref), axes = FALSE, breaks = br, col = colors, ...) + #image(z = t(mat), breaks = br, col = colors, ...) + + levelplot(x = mat, + xlab = "Reaction No.", + ylab = "Gene/Flux No.", + at = br, + col.regions = colors, + colorkey = list(at = seq(-1e+03, 1e+03, length = 20), + labels = ylabels + ), + panel = function(...) { + +# grid.segments(x0 = c(2, 2, 10), y0 = c(1, 5, 5), +# x1 = c(2, 10, 10), y1 = c(5, 5, 1), +# default.units = "native") + + grid.points(5, 5, pch = 16, size=unit(5, "mm")) +# default.units = "native") + + panel.levelplot(...) + + }, + + + ...) + + + } +) diff --git a/R/fluxVar.R b/R/fluxVar.R new file mode 100644 index 0000000..390e9c7 --- /dev/null +++ b/R/fluxVar.R @@ -0,0 +1,90 @@ +# fluxVar.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: fluxVar +# +# Performs a flux vaiability Analysis +# +# The function fluxVar() is inspired by the function +# fluxVariability() contained in the COBRA Toolbox. +# The algorithm is the same. + + +fluxVar <- function(model, react = c(1:react_num(model)), exex = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + # remove exchange reactions from analysis + if (isTRUE(exex)) { + exchReact <- findExchReact(model) + ex <- react_pos(exchReact) + intReact <- 1:react_num(model) + intReact <- intReact[-ex] + + if (length(intReact) < 1) { + stop("model contains no internal reactions!") + } + } + else { + intReact <- react + } + + creact <- checkReactId(model, intReact) + + if (!is(creact, "reactId")) { + stop("check argument react") + } + + +#------------------------------------------------------------------------------# +# optimizations # +#------------------------------------------------------------------------------# + + sol <- optimizer(model, + react = as.list(c(react_pos(creact), react_pos(creact))), + obj_coef = rep(1, (2*length(creact))), + lpdir = c(rep("min", length(creact)), + rep("max", length(creact))), + algorithm = "fv", ...) + + +#------------------------------------------------------------------------------# +# save the results # +#------------------------------------------------------------------------------# + + optsol <- new("optsol_fluxVar") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + react(optsol) <- creact + + return(optsol) + +} + + + diff --git a/R/geneDel.R b/R/geneDel.R new file mode 100644 index 0000000..f69dad5 --- /dev/null +++ b/R/geneDel.R @@ -0,0 +1,162 @@ +# geneDel.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: geneDel +# +# +# The function geneDel() is inspired by the function +# deleteModelGenes() contained in the COBRA Toolbox. + + +geneDel <- function(model, genes, checkId = FALSE) { +#geneDel <- function(model, genes, lpmodel, solver = SYBIL_SETTINGS("SOLVER")) { + + #if (missing(lpmodel)) { + # solver = "none" + #} + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (isTRUE(checkId)) { + if (is(genes, "character")) { + # Check if all genes are there + geneExist <- which(is.na(match(genes, allGenes(model)))) + + # if thats not the case ... + if (length(geneExist) != 0) { + stop(sprintf(ngettext(length(geneExist), + "gene %s does not exist", + "genes %s do not exist" + ), paste(sQuote(genes[geneExist]), collapse = ", ") + ) + ) + } + + geneInd <- match(genes, allGenes(model)) + } + else { + if (max(genes) > length(allGenes(model))) { + stop("indices in argument genes do not exist") + } + else { + geneInd <- genes + } + } + } + else { + if (is(genes, "numeric")) { + geneInd <- genes + } + else { + stop("argument genes must be numeric, if checkId is FALSE") + } + } + + # Get the reaction id's of reactions in the gene list. Returns a list + # Perhaps we find something better here. +# reactInd <- as.list(apply( +# as.matrix(rxnGeneMat(model)[,geneInd]), 2, function(x) +# which(x != 0) +# +# )) + reactInd <- apply(rxnGeneMat(model)[,geneInd, drop = FALSE], 2, function(x) which(x != 0) ) + + + # print(reactInd) + #print(unlist(reactInd)) + + reactInd <- unlist(reactInd) +#return(reactInd) + +#print(reactInd) + + #x <- logical(length(allGenes(model))) + x <- rep(TRUE, length(allGenes(model))) + #print(x) + x[geneInd] <- FALSE + constReact <- logical(length(reactInd)) +#print(constReact) + + + # also do better here + + # Constrain a reaction if the corresponding gpr rule is FALSE. + # If that's the case, the reaction needs gene bla. + + ru <- gprRules(model)[reactInd] + for(i in 1:length(reactInd)) { + #print(reactInd[i]) + #print(ru[i]) + #ev <- eval(parse(text = ru[i])) + ev <- tryCatch(eval(parse(text = ru[i])), error = function(e) e) + if (is(ev, "simpleError")) { + stop("wrong gene association:", + "\nreaction no. ", reactInd[i], + "\nreaction id: ", react_id(model)[reactInd[i]], + "\ngpr: ", gpr(model)[reactInd[i]]) + } + if (any(is.na(ev))) { + warning("reference to non existing gene id in gene association:", + "\nreaction no. ", reactInd[i], + "\nreaction id: ", react_id(model)[reactInd[i]], + "\nignoring gpr ", sQuote(gpr(model)[reactInd[i]])) + } + else { + #if (eval(parse(text = gprRules(model)[reactInd[i]])) == FALSE) { + #if (eval(parse(text = ru[i])) == FALSE) { + if (ev == FALSE) { + #print(reactInd[i]) + #print("cool") + constReact[i] <- TRUE + } + } + } + +# print(reactInd) +# print(constReact) +# print(reactInd[constReact]) + + if (any(constReact)) { + + #if (solver == "none") { + # model <- changeBounds(model, reactInd[constReact]) + # + #} + + #if (solver == "glpkAPI") { + # model <- changeBounds(lpmodel, reactInd[constReact], solver = solver) + #} + + #return(model) + + return(unique(reactInd[constReact])) + } + + #return(as.numeric(NA)) + return(NULL) + +} diff --git a/R/geneDeletion.R b/R/geneDeletion.R new file mode 100644 index 0000000..80c94f5 --- /dev/null +++ b/R/geneDeletion.R @@ -0,0 +1,129 @@ +# geneDeletion.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: geneDeletion +# +# This function performs a "n gene deletion analysis". +# In each iteration m genes are switched of (vi = 0) +# and the objective function will be computed. +# +# The function geneDeletion() is inspired by the functions singleGeneDeletion() +# and doubleGeneDeletion() contained in the COBRA Toolbox. + + +geneDeletion <- function(model, genes, combinations = 1, + lb = NULL, ub = NULL, checkOptSolObj = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + num_genes <- length(allGenes(model)) + + # delGenes containes pointers to gene id's in allGenes(model) + if (missing(genes)) { + delGenes <- num_genes + } + else { + delGenes <- genes + } + + # make deletion matrix + if (!is(delGenes, "matrix")) { + delGenes <- combn(x = delGenes, m = combinations) + } + + if (typeof(delGenes) == "character") { + # check the id's + dimdg <- dim(delGenes) + delGenes <- match(delGenes, allGenes(model)) + if (any(is.na(delGenes))) { + stop("some gene id's are unknown, check argument genes") + } + else { + attr(delGenes, which = "dim") <- dimdg + } + } + else { + if (any(delGenes > num_genes)) { + #if ( (max(delGenes) > num_genes) || (min(delGenes) < 0) ) { + stop("values of genes must be in [0, length(allGenes(model))]") + } + } + + # number of optimizations + num_opt <- ncol(delGenes) + +#------------------------------------------------------------------------------# +# run optimization # +#------------------------------------------------------------------------------# + + kogenes <- lapply(seq_len(ncol(delGenes)), function(x) delGenes[ , x]) + + fd <- .generateFluxdels(model, kogenes) + + if (is.null(lb)) { + lb <- rep(0, length(kogenes)) + } + else { + if (length(lb) != length(kogenes)) { + stop("lb must be of length ", length(kogenes)) + } + } + if (is.null(ub)) { + ub <- rep(0, length(kogenes)) + } + else { + if (length(ub) != length(kogenes)) { + stop("ub must be of length ", length(kogenes)) + } + } + + sol <- optimizer(model = model, + react = fd[["react"]], + lb = lb, + ub = ub, + ...) + + # ------------------------------------------------------------------------ # + + optsol <- new("optsol_genedel") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + chlb(optsol) <- as.numeric(lb) + chub(optsol) <- as.numeric(ub) + dels(optsol) <- matrix(allGenes(model)[t(delGenes)], nrow = ncol(delGenes)) + fluxdels(optsol) <- fd[["fd"]] + hasEffect(optsol) <- fd[["heff"]] + + if (isTRUE(checkOptSolObj)) { + checkOptSol(optsol, onlywarn = TRUE) + } + + return(optsol) + +} + diff --git a/R/generateFluxdels.R b/R/generateFluxdels.R new file mode 100644 index 0000000..34f1c22 --- /dev/null +++ b/R/generateFluxdels.R @@ -0,0 +1,47 @@ +# generateFluxdels.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .generateFluxdels +# +# +# + +.generateFluxdels <- function(model, geneList) { + + message("compute affected fluxes ... ", appendLF = FALSE) + + react <- mapply(geneDel, geneList, + MoreArgs = list(model = model), SIMPLIFY = FALSE) +# react <- as.list(1:length(geneList)) + heff <- ! sapply(react, is.null, simplify = TRUE, USE.NAMES = FALSE) + + fd <- vector(mode = "list", length = length(react)) + fd[heff] <- lapply(react[heff], function(x) react_id(model)[x]) + + message("OK") + + return(list(react = react, heff = heff, fd = fd)) + +} diff --git a/R/generateModKey.R b/R/generateModKey.R new file mode 100644 index 0000000..5108399 --- /dev/null +++ b/R/generateModKey.R @@ -0,0 +1,40 @@ +# generateModKey.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .generateModKey +# +# +# + +.generateModKey <- function() { + + # maybe use MD5 hash here? + key <- paste(sample(letters, size = 2), + sample(c(letters, 0:9), size = 8, replace = FALSE), + collapse = "", sep = "") + + return(key) + +} diff --git a/R/generateWT.R b/R/generateWT.R new file mode 100644 index 0000000..16cf50a --- /dev/null +++ b/R/generateWT.R @@ -0,0 +1,83 @@ +# generateWT.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .generateWT +# +# +# + +.generateWT <- function(model, react = NULL, lb = NULL, ub = NULL, ...) { + + ca <- match.call() + + if ("solver" %in% names(ca)) { + + # It is necessary to test, whether argument solver has a variable, + # or not. If it is a variable, it needs to be evaluated. + testslv <- tryCatch(eval(parse(text = ca["solver"])), + error = function(e) e) + if (is(testslv, "simpleError")) { + slv <- as.character(ca["solver"]) + } + else { + slv <- as.character(testslv) + } + + } + else { + slv <- SYBIL_SETTINGS("SOLVER") + } + + me <- checkDefaultMethod(solver = slv, + method = "NA", + probType = "lp", + loadPackage = FALSE) + + + if (is(react, "list")) { + message("calculating fba solutions ... ", appendLF = FALSE) + suppressMessages( + tmp <- optimizer(model, algorithm = "fba", + lpdir = rep("max", length(react)), + react = react, lb = lb, ub = ub, verboseMode = 0, + solver = me[["sol"]], method = me[["met"]], + solverParm = as.data.frame(NA)) + ) + message("OK") + } + else { + tmp <- optimizeProb(model, + react = react, lb = lb, ub = ub, + retOptSol = FALSE, + algorithm = "fba", + lpdir = "max", + solver = me[["sol"]], + method = me[["met"]], + solverParm = as.data.frame(NA)) + } + + return(tmp) + +} diff --git a/R/generics.R b/R/generics.R new file mode 100644 index 0000000..e249177 --- /dev/null +++ b/R/generics.R @@ -0,0 +1,952 @@ +# generics.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# generics # +#------------------------------------------------------------------------------# + +# from graphics +setGeneric("plot") + +# sybil +setGeneric(name = "addCols", + def = function(lp, ncols, ...) { standardGeneric("addCols") } +) + +setGeneric(name = "addColsToProb", + def = function(lp, ...) { standardGeneric("addColsToProb") } +) + +setGeneric(name = "addRows", + def = function(lp, nrows, ...) { standardGeneric("addRows") } +) + +setGeneric(name = "addRowsCols", + def = function(lp, nrows, ncols, ...) { standardGeneric("addRowsCols") } +) + +setGeneric(name = "addRowsToProb", + def = function(lp, ...) { standardGeneric("addRowsToProb") } +) + +setGeneric(name = "algorithm", + def = function(object) { standardGeneric("algorithm") } +) +setGeneric(name = "algorithm<-", + def = function(object, value) { standardGeneric("algorithm<-") } +) + +setGeneric(name = "alg_par", + def = function(object) { standardGeneric("alg_par") } +) +setGeneric(name = "alg_par<-", + def = function(object, value) { standardGeneric("alg_par<-") } +) + +setGeneric(name = "allGenes", + def = function(object) { standardGeneric("allGenes") } +) +setGeneric(name = "allGenes<-", + def = function(object, value) { standardGeneric("allGenes<-") } +) + +setGeneric(name = "applyChanges", + def = function(object, del, obj, ld, react, lb, ub, obj_coef, fldind, lpdir) { standardGeneric("applyChanges") } +) + +setGeneric(name = "backupProb", + def = function(lp) { standardGeneric("backupProb") } +) + +setGeneric(name = "blocked", + def = function(object) { standardGeneric("blocked") } +) +setGeneric(name = "blocked<-", + def = function(object, value) { standardGeneric("blocked<-") } +) + +setGeneric(name = "blReact", + def = function(object, tol = SYBIL_SETTINGS("TOLERANCE")) { standardGeneric("blReact") } +) + +setGeneric(name = "changeColsBnds", + def = function(lp, ...) { standardGeneric("changeColsBnds") } +) + +setGeneric(name = "changeColsBndsObjCoefs", + def = function(lp, ...) { standardGeneric("changeColsBndsObjCoefs") } +) + +setGeneric(name = "changeMatrixRow", + def = function(lp, i, j, val) { standardGeneric("changeMatrixRow") } +) + +setGeneric(name = "changeMaxObj", + def = function(object, ...) { standardGeneric("changeMaxObj") } +) + +setGeneric(name = "changeObjCoefs", + def = function(lp, ...) { standardGeneric("changeObjCoefs") } +) + +setGeneric(name = "changeRowsBnds", + def = function(lp, ...) { standardGeneric("changeRowsBnds") } +) + +setGeneric(name = "changeUptake", + def = function(object, ...) { standardGeneric("changeUptake") } +) + +setGeneric(name = "checkOptSol", + def = function(opt, ...) { standardGeneric("checkOptSol") } +) + +setGeneric(name = "checkStat", + def = function(opt) { standardGeneric("checkStat") } +) + +setGeneric(name = "chlb", + def = function(object) { standardGeneric("chlb") } +) +setGeneric(name = "chlb<-", + def = function(object, value) { standardGeneric("chlb<-") } +) + +setGeneric(name = "chub", + def = function(object) { standardGeneric("chub") } +) +setGeneric(name = "chub<-", + def = function(object, value) { standardGeneric("chub<-") } +) + +setGeneric(name = "cmd", + def = function(object) { standardGeneric("cmd") } +) +setGeneric(name = "cmd<-", + def = function(object, value) { standardGeneric("cmd<-") } +) + +setGeneric(name = "ctrlfl", + def = function(object) { standardGeneric("ctrlfl") } +) +setGeneric(name = "ctrlfl<-", + def = function(object, value) { standardGeneric("ctrlfl<-") } +) + +setGeneric(name = "ctrlr", + def = function(object) { standardGeneric("ctrlr") } +) +setGeneric(name = "ctrlr<-", + def = function(object, value) { standardGeneric("ctrlr<-") } +) + +setGeneric(name = "deleted", + def = function(object, ...) { standardGeneric("deleted") } +) + +setGeneric(name = "deadEndMetabolites", + def = function(object, ...) { standardGeneric("deadEndMetabolites") } +) +# setGeneric(name = "deleted<-", +# def = function(object, value) { standardGeneric("deleted<-") } +# ) + +setGeneric(name = "delProb", + def = function(lp, ...) { standardGeneric("delProb") } +) + +setGeneric(name = "dels", + def = function(object) { standardGeneric("dels") } +) +setGeneric(name = "dels<-", + def = function(object, value) { standardGeneric("dels<-") } +) + +setGeneric(name = "didFoot", + def = function(object) { standardGeneric("didFoot") } +) +setGeneric(name = "didFoot<-", + def = function(object, value) { standardGeneric("didFoot<-") } +) + +setGeneric(name = "emsg", + def = function(object) { standardGeneric("emsg") } +) +setGeneric(name = "emsg<-", + def = function(object, value) { standardGeneric("emsg<-") } +) + +setGeneric(name = "enum", + def = function(object) { standardGeneric("enum") } +) +setGeneric(name = "enum<-", + def = function(object, value) { standardGeneric("enum<-") } +) + +setGeneric(name = "exit_code", + def = function(object) { standardGeneric("exit_code") } +) +setGeneric(name = "exit_code<-", + def = function(object, value) { standardGeneric("exit_code<-") } +) + +setGeneric(name = "exit_meaning", + def = function(object) { standardGeneric("exit_meaning") } +) +setGeneric(name = "exit_meaning<-", + def = function(object, value) { standardGeneric("exit_meaning<-") } +) + +setGeneric(name = "exit_num", + def = function(object) { standardGeneric("exit_num") } +) +setGeneric(name = "exit_num<-", + def = function(object, value) { standardGeneric("exit_num<-") } +) + +setGeneric(name = "ex_met", + def = function(object) { standardGeneric("ex_met") } +) + +setGeneric(name = "ex_val", + def = function(object) { standardGeneric("ex_val") } +) + +setGeneric(name = "fenc", + def = function(object) { standardGeneric("fenc") } +) +setGeneric(name = "fenc<-", + def = function(object, value) { standardGeneric("fenc<-") } +) + +setGeneric(name = "fh", + def = function(object) { standardGeneric("fh") } +) +setGeneric(name = "fh<-", + def = function(object, value) { standardGeneric("fh<-") } +) + +setGeneric(name = "fldind", + def = function(object) { standardGeneric("fldind") } +) +setGeneric(name = "fldind<-", + def = function(object, value) { standardGeneric("fldind<-") } +) + +setGeneric(name = "fluxdels", + def = function(object) { standardGeneric("fluxdels") } +) +setGeneric(name = "fluxdels<-", + def = function(object, value) { standardGeneric("fluxdels<-") } +) + +setGeneric(name = "fluxdist", + def = function(object) { standardGeneric("fluxdist") } +) +setGeneric(name = "fluxdist<-", + def = function(object, value) { standardGeneric("fluxdist<-") } +) + +setGeneric(name = "fluxes", + def = function(object) { standardGeneric("fluxes") } +) +setGeneric(name = "fluxes<-", + def = function(object, value) { standardGeneric("fluxes<-") } +) + +setGeneric(name = "fname", + def = function(object) { standardGeneric("fname") } +) +setGeneric(name = "fname<-", + def = function(object, value) { standardGeneric("fname<-") } +) + +setGeneric(name = "fpath", + def = function(object) { standardGeneric("fpath") } +) +setGeneric(name = "fpath<-", + def = function(object, value) { standardGeneric("fpath<-") } +) + +setGeneric(name = "genes", + def = function(object) { standardGeneric("genes") } +) +setGeneric(name = "genes<-", + def = function(object, value) { standardGeneric("genes<-") } +) + +setGeneric(name = "getColPrim", + def = function(lp, j) { standardGeneric("getColPrim") } +) + +setGeneric(name = "getColsLowBnds", + def = function(lp, j) { standardGeneric("getColsLowBnds") } +) + +setGeneric(name = "getColsNames", + def = function(lp, j) { standardGeneric("getColsNames") } +) + +setGeneric(name = "getColsUppBnds", + def = function(lp, j) { standardGeneric("getColsUppBnds") } +) + +setGeneric(name = "getFluxDist", + def = function(lp, ...) { standardGeneric("getFluxDist") } +) + +setGeneric(name = "getNumCols", + def = function(lp) { standardGeneric("getNumCols") } +) + +setGeneric(name = "getNumNnz", + def = function(lp) { standardGeneric("getNumNnz") } +) + +setGeneric(name = "getNumRows", + def = function(lp) { standardGeneric("getNumRows") } +) + +setGeneric(name = "getObjCoefs", + def = function(lp, j) { standardGeneric("getObjCoefs") } +) + +setGeneric(name = "getObjDir", + def = function(lp) { standardGeneric("getObjDir") } +) + +setGeneric(name = "getObjVal", + def = function(lp) { standardGeneric("getObjVal") } +) + +setGeneric(name = "getRedCosts", + def = function(lp) { standardGeneric("getRedCosts") } +) + +setGeneric(name = "getRowsLowBnds", + def = function(lp, i) { standardGeneric("getRowsLowBnds") } +) + +setGeneric(name = "getRowsNames", + def = function(lp, i) { standardGeneric("getRowsNames") } +) + +setGeneric(name = "getRowsUppBnds", + def = function(lp, i) { standardGeneric("getRowsUppBnds") } +) + +setGeneric(name = "getSolStat", + def = function(lp) { standardGeneric("getSolStat") } +) + +setGeneric(name = "getSolverParm", + def = function(lp) { standardGeneric("getSolverParm") } +) + +setGeneric(name = "gpr", + def = function(object) { standardGeneric("gpr") } +) +setGeneric(name = "gpr<-", + def = function(object, value) { standardGeneric("gpr<-") } +) + +setGeneric(name = "gprRules", + def = function(object) { standardGeneric("gprRules") } +) +setGeneric(name = "gprRules<-", + def = function(object, value) { standardGeneric("gprRules<-") } +) + +setGeneric(name = "hasEffect", + def = function(object) { standardGeneric("hasEffect") } +) +setGeneric(name = "hasEffect<-", + def = function(object, value) { standardGeneric("hasEffect<-") } +) + +setGeneric(name = "ind", + def = function(object) { standardGeneric("ind") } +) +setGeneric(name = "ind<-", + def = function(object, value) { standardGeneric("ind<-") } +) + +#setGeneric(name = "ind2id", +# def = function(object, ...) { standardGeneric("ind2id") } +#) + +setGeneric(name = "initProb", + def = function(lp, ...) { standardGeneric("initProb") } +) + +setGeneric(name = "irrev", + def = function(object) { standardGeneric("irrev") } +) +setGeneric(name = "irrev<-", + def = function(object, value) { standardGeneric("irrev<-") } +) + +setGeneric(name = "irrev2rev", + def = function(object) { standardGeneric("irrev2rev") } +) +setGeneric(name = "irrev2rev<-", + def = function(object, value) { standardGeneric("irrev2rev<-") } +) + +setGeneric(name = "lethal", + def = function(object, wt, tol) { standardGeneric("lethal") } +) + +setGeneric(name = "loadLPprob", + def = function(lp, ...) { standardGeneric("loadLPprob") } +) + +setGeneric(name = "loadQobj", + def = function(lp, mat) { standardGeneric("loadQobj") } +) + +setGeneric(name = "logCall", + def = function(object, nog) { standardGeneric("logCall") } +) +# setGeneric(name = "logCall", +# def = function(object, func, fargl, thdargs) { standardGeneric("logCall") } +# ) +setGeneric(name = "logClose<-", + def = function(object, value) { standardGeneric("logClose<-") } +) +setGeneric(name = "logComment", + def = function(object, cmt, cmtChar) { standardGeneric("logComment") } +) +setGeneric(name = "logError", + def = function(object, msg, num) { standardGeneric("logError") } +) +setGeneric(name = "logFoot<-", + def = function(object, value) { standardGeneric("logFoot<-") } +) +setGeneric(name = "logFH", + def = function(object) { standardGeneric("logFH") } +) +setGeneric(name = "logHead", + def = function(object) { standardGeneric("logHead") } +) +setGeneric(name = "logMessage", + def = function(object, appendEllipsis, ...) { standardGeneric("logMessage") } +) +setGeneric(name = "logOptimization", + def = function(object, ...) { standardGeneric("logOptimization") } +) +setGeneric(name = "logOptimizationTH", + def = function(object) { standardGeneric("logOptimizationTH") } +) +setGeneric(name = "logStep<-", + def = function(object, value) { standardGeneric("logStep<-") } +) +setGeneric(name = "lstname", + def = function(object) { standardGeneric("lstname") } +) +setGeneric(name = "logWarning", + def = function(object, ...) { standardGeneric("logWarning") } +) + +setGeneric(name = "loglevel", + def = function(object) { standardGeneric("loglevel") } +) +setGeneric(name = "loglevel<-", + def = function(object, value) { standardGeneric("loglevel<-") } +) + +setGeneric(name = "lowbnd", + def = function(object) { standardGeneric("lowbnd") } +) +setGeneric(name = "lowbnd<-", + def = function(object, value) { standardGeneric("lowbnd<-") } +) + +setGeneric(name = "lp_dir", + def = function(object) { standardGeneric("lp_dir") } +) +setGeneric(name = "lp_dir<-", + def = function(object, value) { standardGeneric("lp_dir<-") } +) + +setGeneric(name = "lp_num_cols", + def = function(object) { standardGeneric("lp_num_cols") } +) +setGeneric(name = "lp_num_cols<-", + def = function(object, value) { standardGeneric("lp_num_cols<-") } +) + +setGeneric(name = "lp_num_rows", + def = function(object) { standardGeneric("lp_num_rows") } +) +setGeneric(name = "lp_num_rows<-", + def = function(object, value) { standardGeneric("lp_num_rows<-") } +) + +setGeneric(name = "lp_obj", + def = function(object) { standardGeneric("lp_obj") } +) +setGeneric(name = "lp_obj<-", + def = function(object, value) { standardGeneric("lp_obj<-") } +) + +setGeneric(name = "lp_ok", + def = function(object) { standardGeneric("lp_ok") } +) +setGeneric(name = "lp_ok<-", + def = function(object, value) { standardGeneric("lp_ok<-") } +) + +setGeneric(name = "lp_stat", + def = function(object) { standardGeneric("lp_stat") } +) +setGeneric(name = "lp_stat<-", + def = function(object, value) { standardGeneric("lp_stat<-") } +) + +setGeneric(name = "matchrev", + def = function(object) { standardGeneric("matchrev") } +) +setGeneric(name = "matchrev<-", + def = function(object, value) { standardGeneric("matchrev<-") } +) + +setGeneric(name = "maxSol", + def = function(object, ...) { standardGeneric("maxSol") } +) + +setGeneric(name = "met_comp", + def = function(object) { standardGeneric("met_comp") } +) +setGeneric(name = "met_comp<-", + def = function(object, value) { standardGeneric("met_comp<-") } +) + +setGeneric(name = "met_de", + def = function(object) { standardGeneric("met_de") } +) +setGeneric(name = "met_de<-", + def = function(object, value) { standardGeneric("met_de<-") } +) + +setGeneric(name = "met_id", + def = function(object) { standardGeneric("met_id") } +) +setGeneric(name = "met_id<-", + def = function(object, value) { standardGeneric("met_id<-") } +) + +setGeneric(name = "met_name", + def = function(object) { standardGeneric("met_name") } +) +setGeneric(name = "met_name<-", + def = function(object, value) { standardGeneric("met_name<-") } +) + +setGeneric(name = "met_num", + def = function(object) { standardGeneric("met_num") } +) +setGeneric(name = "met_num<-", + def = function(object, value) { standardGeneric("met_num<-") } +) + +setGeneric(name = "met_pos", + def = function(object) { standardGeneric("met_pos") } +) +setGeneric(name = "met_pos<-", + def = function(object, value) { standardGeneric("met_pos<-") } +) + +setGeneric(name = "met_single", + def = function(object) { standardGeneric("met_single") } +) +setGeneric(name = "met_single<-", + def = function(object, value) { standardGeneric("met_single<-") } +) + +setGeneric(name = "method", + def = function(object) { standardGeneric("method") } +) +setGeneric(name = "method<-", + def = function(object, value) { standardGeneric("method<-") } +) + +setGeneric(name = "minSol", + def = function(object, ...) { standardGeneric("minSol") } +) + +setGeneric(name = "mod_compart", + def = function(object) { standardGeneric("mod_compart") } +) +setGeneric(name = "mod_compart<-", + def = function(object, value) { standardGeneric("mod_compart<-") } +) + +setGeneric(name = "mod_desc", + def = function(object) { standardGeneric("mod_desc") } +) +setGeneric(name = "mod_desc<-", + def = function(object, value) { standardGeneric("mod_desc<-") } +) + +setGeneric(name = "mod_id", + def = function(object) { standardGeneric("mod_id") } +) +setGeneric(name = "mod_id<-", + def = function(object, value) { standardGeneric("mod_id<-") } +) + +setGeneric(name = "mod_key", + def = function(object) { standardGeneric("mod_key") } +) +setGeneric(name = "mod_key<-", + def = function(object, value) { standardGeneric("mod_key<-") } +) + +setGeneric(name = "mod_name", + def = function(object) { standardGeneric("mod_name") } +) +setGeneric(name = "mod_name<-", + def = function(object, value) { standardGeneric("mod_name<-") } +) + +setGeneric(name = "mod_obj", + def = function(object) { standardGeneric("mod_obj") } +) +setGeneric(name = "mod_obj<-", + def = function(object, value) { standardGeneric("mod_obj<-") } +) + +setGeneric(name = "nc", + def = function(object) { standardGeneric("nc") } +) +setGeneric(name = "nc<-", + def = function(object, value) { standardGeneric("nc<-") } +) + +setGeneric(name = "nfluxes", + def = function(object) { standardGeneric("nfluxes") } +) + +setGeneric(name = "nr", + def = function(object) { standardGeneric("nr") } +) +setGeneric(name = "nr<-", + def = function(object, value) { standardGeneric("nr<-") } +) + +setGeneric(name = "nvar", + def = function(object) { standardGeneric("nvar") } +) + +setGeneric(name = "nzeros", + def = function(object) { standardGeneric("nzeros") } +) + +setGeneric(name = "num_of_fluxes", + def = function(object) { standardGeneric("num_of_fluxes") } +) + +setGeneric(name = "num_of_prob", + def = function(object) { standardGeneric("num_of_prob") } +) +setGeneric(name = "num_of_prob<-", + def = function(object, value) { standardGeneric("num_of_prob<-") } +) + +setGeneric(name = "obj_coef", + def = function(object) { standardGeneric("obj_coef") } +) +setGeneric(name = "obj_coef<-", + def = function(object, value) { standardGeneric("obj_coef<-") } +) + +setGeneric(name = "obj_func", + def = function(object) { standardGeneric("obj_func") } +) +setGeneric(name = "obj_func<-", + def = function(object, value) { standardGeneric("obj_func<-") } +) + +setGeneric(name = "optimizeProb", + def = function(object, ...) { standardGeneric("optimizeProb") } +) + +setGeneric(name = "pa", + def = function(object) { standardGeneric("pa") } +) +setGeneric(name = "pa<-", + def = function(object, value) { standardGeneric("pa<-") } +) + +setGeneric(name = "postProc", + def = function(object) { standardGeneric("postProc") } +) +setGeneric(name = "postProc<-", + def = function(object, value) { standardGeneric("postProc<-") } +) + +setGeneric(name = "plotRangeVar", + def = function(object, ...) { standardGeneric("plotRangeVar") } +) + +setGeneric(name = "preProc", + def = function(object) { standardGeneric("preProc") } +) +setGeneric(name = "preProc<-", + def = function(object, value) { standardGeneric("preProc<-") } +) + +setGeneric(name = "printExchange", + def = function(object, ...) { standardGeneric("printExchange") } +) + +setGeneric(name = "printMetabolite", + def = function(object, ...) { standardGeneric("printMetabolite") } +) + +setGeneric(name = "printObjFunc", + def = function(object) { standardGeneric("printObjFunc") } +) + +setGeneric(name = "printReaction", + def = function(object, ...) { standardGeneric("printReaction") } +) +setGeneric(name = "printReaction", + def = function(object, mod, ...) { standardGeneric("printReaction") } +) + +setGeneric(name = "problem", + def = function(object) { standardGeneric("problem") } +) +#setGeneric(name = "problem<-", +# def = function(object, value) { standardGeneric("problem<-") } +#) + +setGeneric(name = "probType", + def = function(object) { standardGeneric("probType") } +) + +setGeneric(name = "rate", + def = function(object) { standardGeneric("rate") } +) + +setGeneric(name = "react", + def = function(object) { standardGeneric("react") } +) +setGeneric(name = "react<-", + def = function(object, value) { standardGeneric("react<-") } +) + +setGeneric(name = "react_de", + def = function(object) { standardGeneric("react_de") } +) +setGeneric(name = "react_de<-", + def = function(object, value) { standardGeneric("react_de<-") } +) + +setGeneric(name = "react_id", + def = function(object) { standardGeneric("react_id") } +) +setGeneric(name = "react_id<-", + def = function(object, value) { standardGeneric("react_id<-") } +) + +setGeneric(name = "react_name", + def = function(object) { standardGeneric("react_name") } +) +setGeneric(name = "react_name<-", + def = function(object, value) { standardGeneric("react_name<-") } +) + +setGeneric(name = "react_num", + def = function(object) { standardGeneric("react_num") } +) +setGeneric(name = "react_num<-", + def = function(object, value) { standardGeneric("react_num<-") } +) + +setGeneric(name = "react_pos", + def = function(object) { standardGeneric("react_pos") } +) +setGeneric(name = "react_pos<-", + def = function(object, value) { standardGeneric("react_pos<-") } +) + +setGeneric(name = "react_rev", + def = function(object) { standardGeneric("react_rev") } +) +setGeneric(name = "react_rev<-", + def = function(object, value) { standardGeneric("react_rev<-") } +) + +setGeneric(name = "react_single", + def = function(object) { standardGeneric("react_single") } +) +setGeneric(name = "react_single<-", + def = function(object, value) { standardGeneric("react_single<-") } +) + +setGeneric(name = "readProb", + def = function(lp, fname, ff = "lp", ...) { standardGeneric("readProb") } +) + +setGeneric(name = "resetChanges", + def = function(object, old_val) { standardGeneric("resetChanges") } +) + +setGeneric(name = "rev2irrev", + def = function(object) { standardGeneric("rev2irrev") } +) +setGeneric(name = "rev2irrev<-", + def = function(object, value) { standardGeneric("rev2irrev<-") } +) + +setGeneric(name = "rxnGeneMat", + def = function(object) { standardGeneric("rxnGeneMat") } +) +setGeneric(name = "rxnGeneMat<-", + def = function(object, value) { standardGeneric("rxnGeneMat<-") } +) + +setGeneric(name = "S", + def = function(object) { standardGeneric("S") } +) +setGeneric(name = "S<-", + def = function(object, value) { standardGeneric("S<-") } +) + +setGeneric(name = "scaleProb", + def = function(lp, ...) { standardGeneric("scaleProb") } +) + +setGeneric(name = "shrinkMatrix", + def = function(X, ...) { standardGeneric("shrinkMatrix") } +) + +setGeneric(name = "sensitivityAnalysis", + def = function(lp, ...) { standardGeneric("sensitivityAnalysis") } +) + +setGeneric(name = "setColsNames", + def = function(lp, j, names) { standardGeneric("setColsNames") } +) + +setGeneric(name = "setObjDir", + def = function(lp, lpdir) { standardGeneric("setObjDir") } +) + +setGeneric(name = "setRhsZero", + def = function(lp) { standardGeneric("setRhsZero") } +) + +setGeneric(name = "setRowsNames", + def = function(lp, i, names) { standardGeneric("setRowsNames") } +) + +setGeneric(name = "setSolverParm", + def = function(lp, solverParm) { standardGeneric("setSolverParm") } +) + +setGeneric(name = "singletonMetabolites", + def = function(object, ...) { standardGeneric("singletonMetabolites") } +) + +setGeneric(name = "Snnz", + def = function(object) { standardGeneric("Snnz") } +) + +setGeneric(name = "solveLp", + def = function(lp) { standardGeneric("solveLp") } +) + +setGeneric(name = "solver", + def = function(object) { standardGeneric("solver") } +) +setGeneric(name = "solver<-", + def = function(object, value) { standardGeneric("solver<-") } +) + +setGeneric(name = "status_code", + def = function(object) { standardGeneric("status_code") } +) +setGeneric(name = "status_code<-", + def = function(object, value) { standardGeneric("status_code<-") } +) + +setGeneric(name = "status_meaning", + def = function(object) { standardGeneric("status_meaning") } +) +setGeneric(name = "status_meaning<-", + def = function(object, value) { standardGeneric("status_meaning<-") } +) + +setGeneric(name = "status_num", + def = function(object) { standardGeneric("status_num") } +) +setGeneric(name = "status_num<-", + def = function(object, value) { standardGeneric("status_num<-") } +) + +setGeneric(name = "subSys", + def = function(object) { standardGeneric("subSys") } +) +setGeneric(name = "subSys<-", + def = function(object, value) { standardGeneric("subSys<-") } +) + +setGeneric(name = "uppbnd", + def = function(object) { standardGeneric("uppbnd") } +) +setGeneric(name = "uppbnd<-", + def = function(object, value) { standardGeneric("uppbnd<-") } +) + +setGeneric(name = "uptake", + def = function(object) { standardGeneric("uptake") } +) +setGeneric(name = "uptake<-", + def = function(object, value) { standardGeneric("uptake<-") } +) + +setGeneric(name = "uptReact", + def = function(object) { standardGeneric("uptReact") } +) + +setGeneric(name = "uptMet", + def = function(object) { standardGeneric("uptMet") } +) + +setGeneric(name = "verblevel", + def = function(object) { standardGeneric("verblevel") } +) +setGeneric(name = "verblevel<-", + def = function(object, value) { standardGeneric("verblevel<-") } +) + +setGeneric(name = "writeProb", + def = function(lp, fname, ff = "lp", ...) { standardGeneric("writeProb") } +) + + diff --git a/R/getsybilenv.R b/R/getsybilenv.R new file mode 100644 index 0000000..5b771b9 --- /dev/null +++ b/R/getsybilenv.R @@ -0,0 +1,108 @@ +# getsybilenv.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +getsybilenv <- function(part) { + + + # ------------------------------------------------------------------------ # + + printsolvers <- function() { + cat("\n# --------------------------------------------------------- #\n") + cat("solver packages:\n") + cat(paste(.SYBILenv[["solvers"]]), sep = ", ") + cat("\n\n") + } + + + # ------------------------------------------------------------------------ # + + printmethods <- function() { + cat("\n# --------------------------------------------------------- #\n") + cat("methods included in the solver packages:\n") + slv <- names(.SYBILenv[["solverMethods"]]) + for(i in seq(along = slv)) { + cat(slv[i], ":\n", sep = "") + cat(paste(.SYBILenv[["solverMethods"]][[slv[i]]]), sep = ", ") + cat("\n\n") + } + cat("\n") + } + + + # ------------------------------------------------------------------------ # + + printptype <- function() { + cat("\n# --------------------------------------------------------- #\n") + cat("methods used for problem types:\n") + ptype <- names(.SYBILenv[["ptype"]]) + for(i in seq(along = ptype)) { + cat(ptype[i], ":\n", sep = "") + slv <- names(.SYBILenv[["ptype"]][[ptype[i]]]) + for(j in seq(along = slv)) { + cat(" ", slv[j], ":\n ", sep = "") + cat(paste(.SYBILenv[["ptype"]][[ptype[i]]][[slv[j]]]), sep = ", ") + cat("\n\n") + } + } + cat("\n") + } + + + # ------------------------------------------------------------------------ # + + printpurpose <- function() { + cat("\n# --------------------------------------------------------- #\n") + cat("algorithms for this purpose:\n") + fkt <- names(.SYBILenv[["algorithm"]]) + for(i in seq(along = fkt)) { + cat(fkt[i], ":\n", sep = "") + cat(paste(.SYBILenv[["algorithm"]][[fkt[i]]]), sep = ", ") + cat("\n\n") + } + cat("\n") + } + + + # ------------------------------------------------------------------------ # + + if (missing(part)) { + printsolvers() + printmethods() + printptype() + printpurpose() + #print(.SYBILenv[["solverCtrlParm"]]) + } + else { + cmd <- paste("print", part, "()", sep = "") + err <- tryCatch(eval(parse(text = cmd)), error = function(e) e) + if (is(err, "simpleError")) { + stop(sQuote(part), " is not available in the sybil environment") + } + } + + return(invisible(NULL)) + +} + + diff --git a/R/makeLPcompatible.R b/R/makeLPcompatible.R new file mode 100644 index 0000000..d50c1bb --- /dev/null +++ b/R/makeLPcompatible.R @@ -0,0 +1,43 @@ +# makeLPcompatible.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .makeLPcompatible +# +# generates names, compatible to CPLEX LP file format: +# a name must not start with a period or digit and must not contain +# square brackets + +.makeLPcompatible <- function(name, prefix, sep = "") { + + nameLP <- sub("[", "(", name, fixed = TRUE) + nameLP <- sub("]", ")", nameLP, fixed = TRUE) + nameLP <- sub("^([0-9\\.])", paste(prefix, "\\1", sep = sep), + nameLP, perl = TRUE) + + #nameLP <- paste(prefix, nameLP, sep = sep) # prefix = "M_" or "R_" + + return(nameLP) + +} diff --git a/R/mod2irrev.R b/R/mod2irrev.R new file mode 100644 index 0000000..0d63548 --- /dev/null +++ b/R/mod2irrev.R @@ -0,0 +1,287 @@ +# mod2irrev.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: mod2irrev +# +# +# The function mod2irrev() is inspired by the function +# convertToIrreversible() contained in the COBRA Toolbox. +# The algorithm is the same. + + +mod2irrev <- function(model, exex = FALSE) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (is(model, "modelorg_irrev")) { + return(model) + } + + # set the reversible flag of the exchange reactions to FALSE + if (isTRUE(exex)) { + exch <- findExchReact(model) + ex <- react_pos(exch) + react_rev(model)[ex] <- FALSE + } + + +#------------------------------------------------------------------------------# +# data structures # +#------------------------------------------------------------------------------# + + modelIr <- modelorg_irrev(mod_id(model), mod_name(model)) + + irrev(modelIr) <- TRUE + + # number of reactions in the irrev model + irrev_react_num <- react_num(model) + sum(react_rev(model) == TRUE) + + + # data structures not different from the rev model + mod_name(modelIr) <- mod_name(model) + mod_id(modelIr) <- mod_id(model) + mod_compart(modelIr) <- mod_compart(model) + met_id(modelIr) <- met_id(model) + met_num(modelIr) <- met_num(model) + met_name(modelIr) <- met_name(model) + met_comp(modelIr) <- met_comp(model) + + met_single(modelIr) <- met_single(model) + met_de(modelIr) <- met_de(model) + + mod_desc(modelIr) <- paste(mod_desc(model), "irreversible") + #if (!is.na(match("description", slotNames(model)))) { + # description(modelIr) <- paste(description(model), "irreversible") + #} + + # data structures different from the rev model + react_num(modelIr) <- irrev_react_num + react_rev(modelIr) <- logical(irrev_react_num) + react_id(modelIr) <- character(irrev_react_num) + react_name(modelIr) <- character(irrev_react_num) + lowbnd(modelIr) <- numeric(irrev_react_num) + uppbnd(modelIr) <- numeric(irrev_react_num) + obj_coef(modelIr) <- numeric(irrev_react_num) + + matchrev(modelIr) <- integer(irrev_react_num) + rev2irrev(modelIr) <- matrix(0, nrow = react_num(model), ncol = 2) + irrev2rev(modelIr) <- integer(irrev_react_num) + #irrev2rev <- integer(irrev_react_num) + + Sr <- S(model) + Si <- Matrix::Matrix(0, + nrow = met_num(model), + ncol = irrev_react_num, + sparse = TRUE) + #print(dim(Si)) + +#------------------------------------------------------------------------------# +# build the new model # +#------------------------------------------------------------------------------# + + # counter for the reactions in the irrev model + + counti <- 0 + + message("building the new model ...") + progr <- .progressBar() # initialize the progressbar + + for (i in 1 : react_num(model)) { + + progr <- .progressBar(i, react_num(model), progr) + + counti <- counti + 1 + + react_rev(modelIr)[counti] <- react_rev(model)[i] + irrev2rev(modelIr)[counti] <- i + + # Reaction in negative direction in the rev model + if ((uppbnd(model)[i] <= 0) && (lowbnd(model)[i] < 0)) { + + # turn the reaction in positive direction + + # the constraints + #uppbnd(modelIr)[counti] <- (uppbnd(model)[i] * -1) + #lowbnd(modelIr)[counti] <- (lowbnd(model)[i] * -1) + uppbnd(modelIr)[counti] <- (lowbnd(model)[i] * -1) + lowbnd(modelIr)[counti] <- (uppbnd(model)[i] * -1) + + # the stiochiometric coefficients + Si[,counti] <- (Sr[,i] * -1) + #Si[,counti] <- (S(model)[,i] * -1) + + # the objective coefficient + obj_coef(modelIr)[counti] <- (obj_coef(model)[i] * -1) + + # reaction name and id + react_name(modelIr)[counti] <- react_name(model)[i] + react_id(modelIr)[counti] <- paste(react_id(model)[i], "_r", sep = "") + react_rev(modelIr)[counti] <- FALSE + react_single(modelIr)[counti] <- react_single(model)[i] + react_de(modelIr)[counti] <- react_de(model)[i] + + # set reaction in rev model to irreversible + react_rev(model)[i] <- FALSE + } + + # Reaction is in positive direction in rev model + else { + + + # the contraints + uppbnd(modelIr)[counti] <- uppbnd(model)[i] + if (lowbnd(model)[i] < 0) { + lowbnd(modelIr)[counti] <- 0 + } + else { + lowbnd(modelIr)[counti] <- lowbnd(model)[i] + } + + # the stiochiometric coefficients + Si[,counti] <- Sr[,i] + #Si[,counti] <- S(model)[,i] + + # the objective coefficient + obj_coef(modelIr)[counti] <- obj_coef(model)[i] + + # reaction name and id + react_name(modelIr)[counti] <- react_name(model)[i] + react_id(modelIr)[counti] <- react_id(model)[i] + #react_rev(modelIr)[counti] <- FALSE + react_single(modelIr)[counti] <- react_single(model)[i] + react_de(modelIr)[counti] <- react_de(model)[i] + } + + # current reaction is reversible + if (react_rev(model)[i] == TRUE) { + + # ++ irreversible counter + counti <- counti + 1 + + # gedoens + matchrev(modelIr)[counti] <- as.integer(counti - 1) + matchrev(modelIr)[counti-1] <- as.integer(counti) + rev2irrev(modelIr)[i,] <- c((counti - 1), counti) + irrev2rev(modelIr)[counti] <- i#as.integer(counti) + #irrev2rev[counti] <- i + + # reaction name + react_name(modelIr)[(counti-1):counti] <- react_name(model)[i] + + # reaction id with forward, reverse indicator + react_id(modelIr)[counti-1] <- paste(react_id(model)[i], "_f", sep = "") + react_id(modelIr)[counti] <- paste(react_id(model)[i], "_b", sep = "") + + # react_single/react_de + react_single(modelIr)[counti] <- react_single(model)[i] + react_single(modelIr)[counti-1] <- react_single(model)[i] + react_de(modelIr)[counti] <- react_de(model)[i] + react_de(modelIr)[counti-1] <- react_de(model)[i] + + # stoichiometric coefficients + Si[,counti] <- (Sr[,i] * -1) + #Si[,counti] <- (S(model)[,i] * -1) + + # reverse inticator + react_rev(modelIr)[counti] <- TRUE + #react_rev(modelIr)[i] <- TRUE + + # lower bound + lowbnd(modelIr)[counti] <- 0 + + # upper bound + uppbnd(modelIr)[counti] <- (lowbnd(model)[i] * -1) + + # objective coefficient + obj_coef(modelIr)[counti] <- 0 + } + else { + matchrev(modelIr)[counti] <- as.integer(0) + rev2irrev(modelIr)[i,] <- as.integer(c(counti, counti)) + react_single(modelIr)[counti] <- react_single(model)[i] + } + + } + + message("cleaning up ...") + + if (length(subSys(model)) > 0) { + subSys(modelIr) <- subSys(model)[irrev2rev(modelIr), , drop = FALSE] + #subSys(modelIr) <- subSys(model)[irrev2rev] + } + + if (length(genes(model)) > 0) { + genes(modelIr) <- genes(model)[irrev2rev(modelIr)] + gprRules(modelIr) <- gprRules(model)[irrev2rev(modelIr)] + gpr(modelIr) <- gpr(model)[irrev2rev(modelIr)] + #genes(modelIr) <- genes(model)[irrev2rev] + #gprRules(modelIr) <- gprRules(model)[irrev2rev] + #gpr(modelIr) <- gpr(model)[irrev2rev] + + allGenes(modelIr) <- allGenes(model) + + rxnG_temp <- rxnGeneMat(model) + rxnG_temp <- rxnG_temp[irrev2rev(modelIr),] + #rxnG_temp <- rxnG_temp[irrev2rev,] + rxnGeneMat(modelIr) <- rxnG_temp + + #modeli@rxnGeneMat <- model@rxnGeneMat[modeli@irrev2rev,] + } + + + if (irrev_react_num > counti) { + react_num(modelIr) <- as.integer(counti) + react_rev(modelIr) <- react_rev(modelIr)[1:counti] + react_id(modelIr) <- react_id(modelIr)[1:counti] + react_name(modelIr) <- react_name(modelIr)[1:counti] + lowbnd(modelIr) <- lowbnd(modelIr)[1:counti] + uppbnd(modelIr) <- uppbnd(modelIr)[1:counti] + obj_coef(modelIr) <- obj_coef(modelIr)[1:counti] + + matchrev(modelIr) <- matchrev(modelIr)[1:counti] + irrev2rev(modelIr) <- irrev2rev(modelIr)[1:counti] + Si <- Si[,1:counti] + } + + S(modelIr) <- Si + + # reset the reversible flag of the exchange reactions to TRUE + if (exex == TRUE) { + ex_new <- which(irrev2rev(modelIr) %in% ex) + react_rev(modelIr)[ex_new] <- TRUE + } + + + check <- validObject(modelIr, test = TRUE) + + if (check != TRUE) { + warning(paste("Validity check failed:", check, sep = "\n "), call. = FALSE) + } + + return(modelIr) + +} diff --git a/R/modelorg2ExPA.R b/R/modelorg2ExPA.R new file mode 100644 index 0000000..53f0c6b --- /dev/null +++ b/R/modelorg2ExPA.R @@ -0,0 +1,187 @@ +# modelorg2ExPA.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: modelorg2ExPA +# +# +# +# +# original function buildExpaFileFromModelorg by C. Jonathan Fritzemeier + + +modelorg2ExPA <- function(model, + fname = NULL, + exIntReact = NULL, + filepath = ".", + suffix = "expa", + tol = SYBIL_SETTINGS("TOLERANCE")) { + + on.exit( closeAllConnections() ) + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + #expa <- ifelse (missing(fname), mod_id(model), fname) + if (is.null(fname)) { + expa <- paste(mod_id(model), suffix, sep = ".") + } + else { + expa <- fname + } + + tofile <- file.path(filepath, expa) + + fh <- try(file(tofile, "wt"), silent = TRUE) + + if (is(fh, "try-error")) { + warning("cannot write ExPA file!") + fh <- FALSE + } + + # exclude reactions + if (is.null(exIntReact)) { + exInt <- NA + } + else { + exInt <- checkReactId(model, exIntReact) + } + + # ------------------------------------------------------------------------ # + # exchange reactions/excluded internal reactions + # ------------------------------------------------------------------------ # + + exch <- findExchReact(model) + ex <- logical(react_num(model)) + ex[react_pos(exch)] <- TRUE + if (is(exInt, "reactId")) { + ex[react_pos(exInt)] <- TRUE + } + + # ------------------------------------------------------------------------ # + # internal reactions + # ------------------------------------------------------------------------ # + + cat("(Internal Fluxes)\n", file = fh) + + for (j in seq(along = react_id(model))) { + + if (isTRUE(ex[j])) { + next + } + + # direction + ri <- ifelse(isTRUE(react_rev(model)[j]), "R", "I") + + scol <- S(model)[ ,j] + met <- which(abs(scol) > tol) + + nint <- abs(scol[met] - round(scol[met])) > .Machine$double.eps^0.5 + if (any(nint)) { + msg <- sprintf(ngettext(length(met_id(model)[met[nint]]), + "reaction %s contains %d non-integer stoichiometric coefficient, check metabolite %s", + "reaction %s contains %d non-integer stoichiometric coefficients, check metabolites\n\t%s"), + sQuote(react_id(model)[j]), length(met_id(model)[met[nint]]), + paste(sQuote(met_id(model)[met[nint]]), collapse = "\n\t")) + warning(msg, call. = FALSE) + } + + react <- character(length(met)) + + # stoichiometric coefficient must not be rational, only integers + # are valid for ExPA + for (i in seq(along = met)) { + + if (sign(scol[met[i]]) == 1) { + stoich <- paste("+", scol[met[i]], sep = "") + } + else { + stoich <- scol[met[i]] + } + + react[i] <- paste(stoich, met_id(model)[met[i]]) + } + + # reaction string + rstr <- paste(react_id(model)[j], + ri, + paste(react, collapse = " "), + sep = "\t") + + cat(rstr, "\n", sep = "", file = fh, append = TRUE) + + } + + + # ------------------------------------------------------------------------ # + # transport reactions + # ------------------------------------------------------------------------ # + + cat("(Exchange Fluxes)\n", file = fh, append = TRUE) + + exInd <- react_pos(exch) + + for (i in seq(along = exInd)) { + + scol <- S(model)[ ,exInd[i]] + met <- which(scol != 0) + + if (length(met) != 1) { + warning("error in reaction id", react_id(exch)[i]) + next + } + + if ( (lowbnd(model)[exInd[i]] < 0) && (uppbnd(model)[exInd[i]] > 0) ) { + exdir <- "Free" + } + else { + if (lowbnd(model)[exInd[i]] < 0) { + exdir <- "Input" + } + else { + exdir <- "Output" + } + } + + estr <- paste(met_id(model)[met], exdir, sep = "\t") + cat(estr, "\n", sep = "", file = fh, append = TRUE) + + } + + + # ------------------------------------------------------------------------ # + + if (is(fh, "file")) { + close(fh) + } + + #--------------------------------------------------------------------------# + # end + #--------------------------------------------------------------------------# + + return(invisible(TRUE)) + +} + diff --git a/R/modelorg2text.R b/R/modelorg2text.R new file mode 100644 index 0000000..bb61ce3 --- /dev/null +++ b/R/modelorg2text.R @@ -0,0 +1,118 @@ +# modelorg2text.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: modelorg2text +# +# +# + +modelorg2text <- function(model, prefix, suffix, extMetFlag = "b", + fielddelim = "\t", genedelim = "/", + makeClosedNetwork = FALSE, + fpath = SYBIL_SETTINGS("PATH_TO_MODEL"), + ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + # filenames + if (missing(prefix)) { + prefix <- gsub("\\s+", "_", mod_id(model)) + } + + if (missing(suffix)) { + suffix <- switch(fielddelim, + "\t" = { "tsv" }, + ";" = { "csv" }, + "," = { "csv" }, + "|" = { "dsv" }, + { "dsv" } + ) + } + + fname <- paste(prefix, suffix, sep = ".") + + # path to output file + textfile <- file.path(fpath, fname) + + + #--------------------------------------------------------------------------# + # some functions + #--------------------------------------------------------------------------# + + prepareRuleStrings <- function(rule, bp, no) { + + + } + + + #--------------------------------------------------------------------------# + # reactions list + #--------------------------------------------------------------------------# + + rstr <- .createReactionString(model, makeClosedNetwork) + + # rule abbreviation equation lowbnd uppbnd obj_coef + + gprFRule <- gsub("&&?|and", "AND", gpr(model), perl = TRUE) + gprFRule <- gsub("\\|\\|?|or", "OR", gprFRule, perl = TRUE) + + gpr_list <- strsplit(gprFRule, "", fixed = TRUE) + + check_bp <- mapply(.check_brackets, gpr_list, SIMPLIFY = TRUE) + + if ( sum(check_bp) != length(check_bp) ) { + warning(paste("Wrong gpr rules detected, setting to \"\". ", + "Check rule(s) no. ", + paste((1:react_num(model))[!check_bp], collapse = ", "), + ".", sep = "")) + gpr_list[!check_bp] <- "" + } + + gpr_bp <- mapply(.bracket_pairs, gpr_list, SIMPLIFY = FALSE) + + gpr_str <- mapply(prepareRuleStrings, + gprFRule, gpr_bp, c(1:react_num(model)), + SIMPLIFY = FALSE) + + +# write.table(x = data.frame( +# equation = rstr$equat, +# lowbnd = lowbnd(model), +# uppbnd = uppbnd(model), +# obj_coef = obj_coef(model), +# ), +# row.names = FALSE, file = tsvfileR, sep = fielddelim, ...) + + + + #--------------------------------------------------------------------------# + # end + #--------------------------------------------------------------------------# + + return(TRUE) + +} diff --git a/R/modelorg2tsv.R b/R/modelorg2tsv.R new file mode 100644 index 0000000..e266531 --- /dev/null +++ b/R/modelorg2tsv.R @@ -0,0 +1,211 @@ +# modelorg2tsv.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: modelorg2tsv +# +# +# + +modelorg2tsv <- function(model, prefix, suffix, extMetFlag = "b", + fielddelim = "\t", entrydelim = ", ", + makeClosedNetwork = FALSE, + onlyReactionList = FALSE, + minimalSet = FALSE, + fpath = SYBIL_SETTINGS("PATH_TO_MODEL"), + ...) { + + ## on.exit( closeAllConnections() ) + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + # validate model structure before writing + validObject(model) + + # filenames + if (missing(prefix)) { + prefix <- gsub("\\s+", "_", mod_id(model)) + } + + if (missing(suffix)) { + suffix <- switch(fielddelim, + "\t" = { "tsv" }, + ";" = { "csv" }, + "," = { "csv" }, + "|" = { "dsv" }, + { "dsv" } + ) + } + + fnameR <- paste(paste(prefix, "react", sep = "_"), suffix, sep = ".") + fnameM <- paste(paste(prefix, "met", sep = "_"), suffix, sep = ".") + fnameD <- paste(paste(prefix, "desc", sep = "_"), suffix, sep = ".") + + # path to output file + tsvfileR <- file.path(fpath, fnameR) + tsvfileM <- file.path(fpath, fnameM) + tsvfileD <- file.path(fpath, fnameD) + + + #--------------------------------------------------------------------------# + # reactions list + #--------------------------------------------------------------------------# + + # create reaction strings + rstr <- .createReactionString(model, + makeClosedNetwork, + entrydelim, + extMetFlag) + + if (isTRUE(onlyReactionList)) { + write.table(x = data.frame(equation = rstr$equat), + row.names = FALSE, file = tsvfileR, sep = fielddelim, ...) + } + else if (isTRUE(minimalSet)) { + write.table(x = data.frame( + abbreviation = react_id(model), + equation = rstr$equat, + lowbnd = lowbnd(model), + uppbnd = uppbnd(model), + obj_coef = obj_coef(model)), + row.names = FALSE, file = tsvfileR, sep = fielddelim, ...) + } + else { + + # some optional entries + if (length(gpr(model)) != react_num(model)) { + gp <- character(react_num(model)) + } + else { + gp <- gpr(model) + } + + if (nrow(subSys(model)) != react_num(model)) { + sys <- character(react_num(model)) + } + else { + sys_tmp <- subSys(model) + ssys_names <- colnames(sys_tmp) + + if ( (length(ssys_names) == 1) && is.na(ssys_names) ) { + sys <- character(react_num(model)) + } + else { + sys <- apply(sys_tmp, 1, + function(x) paste(ssys_names[x], collapse = ", ")) + } + } + + write.table(x = data.frame( + abbreviation = react_id(model), + name = react_name(model), + equation = rstr$equat, + reversible = rstr$revers, + compartment = rstr$compat, + lowbnd = lowbnd(model), + uppbnd = uppbnd(model), + obj_coef = obj_coef(model), + rule = gp, + subsystem = sys), + row.names = FALSE, file = tsvfileR, sep = fielddelim, ...) + } + + + #--------------------------------------------------------------------------# + # metabolites list + #--------------------------------------------------------------------------# + + if ( (!isTRUE(onlyReactionList)) && (!isTRUE(minimalSet)) ) { + + metunq <- sort(unique(rstr$metab)) + + mpos <- lapply(metunq, function(x) rstr$metab %in% x) + + # metabolite names + metNames <- lapply(mpos, function(x) unique(met_name(model)[x])) + metNames <- unlist(lapply(metNames, paste, collapse = entrydelim)) + + # metabolite compartments + metCompart <- lapply(mpos, + function(x) mod_compart(model)[met_comp(model)[x]]) + metCompart <- unlist(lapply(metCompart, paste, collapse = entrydelim)) + + write.table(x = data.frame( + abbreviation = metunq, + name = metNames, + compartment = metCompart), + row.names = FALSE, file = tsvfileM, sep = fielddelim, ...) + + } + + + #--------------------------------------------------------------------------# + # model description + #--------------------------------------------------------------------------# + + if ( (!isTRUE(onlyReactionList)) && (!isTRUE(minimalSet)) ) { + + # get id's of metabolites in different compartments + # (one per compartment) + metDiffComp <- match(mod_compart(model), + mod_compart(model)[met_comp(model)]) + + metAbbrevComp <- character(length(metDiffComp)) + + # get the compartment abbreviations + metALl <- grepl("^.+(\\[\\w+\\])$", met_id(model)[metDiffComp]) + + metAbbrevComp[metALl] <- sub("^.+(\\[\\w+\\])$", "\\1", + met_id(model)[metDiffComp[metALl]]) + + metAbbrevComp[!metALl] <- mod_compart(model)[!metALl] + + # generate output format + ma <- paste(metAbbrevComp, collapse = entrydelim) + mc <- paste(mod_compart(model), collapse = entrydelim) + + write.table(x = data.frame( + name = mod_name(model), + id = mod_id(model), + description = mod_desc(model), + compartment = mc, + abbreviation = ma, + Nmetabolites = met_num(model), + Nreactions = react_num(model), + Ngenes = length(allGenes(model)), + Nnnz = Snnz(model)), + row.names = FALSE, file = tsvfileD, sep = fielddelim, ...) + + } + + + #--------------------------------------------------------------------------# + # end + #--------------------------------------------------------------------------# + + return(TRUE) + +} diff --git a/R/modelorgClass.R b/R/modelorgClass.R new file mode 100644 index 0000000..9f8702a --- /dev/null +++ b/R/modelorgClass.R @@ -0,0 +1,1088 @@ +# modelorgClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# modelorgClass + + +#------------------------------------------------------------------------------# +# definition of the class modelorg # +#------------------------------------------------------------------------------# + +# The class modelorg (the data part) is inspired by the data structure used +# in the COBRA Toolbox for the same purpose. + +setClass("modelorg", + representation( + mod_desc = "character", + mod_name = "character", # model name + mod_id = "character", # model id + mod_key = "character", # model key (unique character string) + mod_compart = "character", # vector compartments + met_num = "integer", # number of metabolites + met_id = "character", # vector metabolite id's + met_name = "character", # vector metabolite names + met_comp = "integer", # vector the metabolites compartment + met_single = "logical", # metabolites appearing only once in S + met_de = "logical", # dead end metabolites + react_num = "integer", # number of reactions + react_rev = "logical", # vector reversibilities + react_id = "character", # vector reaction id's + react_name = "character", # vector reaction names + react_single = "logical", # reactions using metabolites appearing only once in S + react_de = "logical", # reactions using dead end metabolites + S = "Matrix", # matrix S + lowbnd = "numeric", # vector reactions lower bounds + uppbnd = "numeric", # vector reactions upper bounds + obj_coef = "numeric", # vector objective coefficients + gprRules = "character", + genes = "list", + gpr = "character", + allGenes = "character", + rxnGeneMat = "Matrix", + subSys = "Matrix" + + ), + validity = .validmodelorg +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +modelorg <- function(id, name, subSys = NULL, compartment = NULL) { + if (missing(id) || missing(name)) { + stop("Creating an object of class model needs name and id!") + } + idP <- as.character(id) + nameP <- as.character(name) + if (is.null(subSys)) { + subSysP <- NULL + } + else { + subSysP <- as.character(subSys) + } + if (is.null(compartment)) { + compartmentP <- NULL + } + else { + compartmentP <- as.character(compartment) + } + obj <- new("modelorg", id = idP, name = nameP, + subSys = subSysP, compartment = compartmentP) + return(obj) +} + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +setMethod(f = "initialize", + signature = "modelorg", + definition = function(.Object, id, name, + subSys = NULL, compartment = NULL) { + + if ( (!missing(id)) || (!missing(name)) ) { + .Object@mod_id <- as.character(id) + .Object@mod_name <- as.character(name) + .Object@mod_key <- as.character(.generateModKey()) + .Object@react_num <- as.integer(0) + .Object@met_num <- as.integer(0) + .Object@S <- Matrix::Matrix(0, 0, 0) + .Object@rxnGeneMat <- Matrix::Matrix(0, 0, 0) + .Object@subSys <- Matrix::Matrix(0, 0, length(subSys)) + if (!is.null(subSys)) { + colnames(.Object@subSys) <- as.character(subSys) + } + if (!is.null(compartment)) { + .Object@mod_compart <- as.character(compartment) + } + } + + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# model id +setMethod("mod_id", signature(object = "modelorg"), + function(object) { + return(object@mod_id) + } +) + +setReplaceMethod("mod_id", signature = (object = "modelorg"), + function(object, value) { + object@mod_id <- value + return(object) + } +) + + +# model key +setMethod("mod_key", signature(object = "modelorg"), + function(object) { + return(object@mod_key) + } +) + +setReplaceMethod("mod_key", signature = (object = "modelorg"), + function(object, value) { + object@mod_key <- value + return(object) + } +) + + +# model name +setMethod("mod_name", signature(object = "modelorg"), + function(object) { + return(object@mod_name) + } +) + +setReplaceMethod("mod_name", signature = (object = "modelorg"), + function(object, value) { + object@mod_name <- value + return(object) + } +) + + +# model description +setMethod("mod_desc", signature(object = "modelorg"), + function(object) { + return(object@mod_desc) + } +) + +setReplaceMethod("mod_desc", signature = (object = "modelorg"), + function(object, value) { + object@mod_desc <- value + return(object) + } +) + + +# model compartments +setMethod("mod_compart", signature(object = "modelorg"), + function(object) { + return(object@mod_compart) + } +) + +setReplaceMethod("mod_compart", signature(object = "modelorg"), + function(object, value) { + object@mod_compart <- value + return(object) + } +) + + +# number of metabolites +setMethod("met_num", signature(object = "modelorg"), + function(object) { + return(object@met_num) + } +) + +setReplaceMethod("met_num", signature(object = "modelorg"), + function(object, value) { + object@met_num <- value + return(object) + } +) + + +# metabolite id's +setMethod("met_id", signature(object = "modelorg"), + function(object) { + return(object@met_id) + } +) + +setReplaceMethod("met_id", signature(object = "modelorg"), + function(object, value) { + object@met_id <- value + return(object) + } +) + + +# metabolite names +setMethod("met_name", signature(object = "modelorg"), + function(object) { + return(object@met_name) + } +) + +setReplaceMethod("met_name", signature(object = "modelorg"), + function(object, value) { + object@met_name <- value + return(object) + } +) + + +# metabolites compartments +setMethod("met_comp", signature(object = "modelorg"), + function(object) { + return(object@met_comp) + } +) + +setReplaceMethod("met_comp", signature(object = "modelorg"), + function(object, value) { + object@met_comp <- value + return(object) + } +) + + +# singletons +setMethod("met_single", signature(object = "modelorg"), + function(object) { + return(object@met_single) + } +) + +setReplaceMethod("met_single", signature(object = "modelorg"), + function(object, value) { + object@met_single <- value + return(object) + } +) + + +# dead ends +setMethod("met_de", signature(object = "modelorg"), + function(object) { + return(object@met_de) + } +) + +setReplaceMethod("met_de", signature(object = "modelorg"), + function(object, value) { + object@met_de <- value + return(object) + } +) + + +# number of reactions +setMethod("react_num", signature(object = "modelorg"), + function(object) { + return(object@react_num) + } +) + +setReplaceMethod("react_num", signature(object = "modelorg"), + function(object, value) { + object@react_num <- value + return(object) + } +) + + +# reversibilities +setMethod("react_rev", signature(object = "modelorg"), + function(object) { + return(object@react_rev) + } +) + +setReplaceMethod("react_rev", signature(object = "modelorg"), + function(object, value) { + object@react_rev <- value + return(object) + } +) + + +# reaction id's +setMethod("react_id", signature(object = "modelorg"), + function(object) { + return(object@react_id) + } +) + +setReplaceMethod("react_id", signature(object = "modelorg"), + function(object, value) { + object@react_id <- value + return(object) + } +) + + +# reaction names +setMethod("react_name", signature(object = "modelorg"), + function(object) { + return(object@react_name) + } +) + +setReplaceMethod("react_name", signature(object = "modelorg"), + function(object, value) { + object@react_name <- value + return(object) + } +) + + +# singletons +setMethod("react_single", signature(object = "modelorg"), + function(object) { + return(object@react_single) + } +) + +setReplaceMethod("react_single", signature(object = "modelorg"), + function(object, value) { + object@react_single <- value + return(object) + } +) + + +# dead ends +setMethod("react_de", signature(object = "modelorg"), + function(object) { + return(object@react_de) + } +) + +setReplaceMethod("react_de", signature(object = "modelorg"), + function(object, value) { + object@react_de <- value + return(object) + } +) + + +# stoichiometric matrix +setMethod("S", signature(object = "modelorg"), + function(object) { + return(object@S) + } +) + +setReplaceMethod("S", signature(object = "modelorg"), + function(object, value) { + object@S <- value + return(object) + } +) + +# number of non zero elements in S +setMethod("Snnz", signature(object = "modelorg"), + function(object) { + return(length(object@S@x)) + } +) + +# slot dimension of stoichiometric matrix (SparseM) +setMethod("dim", signature(x = "modelorg"), + function(x) { + return(dim(x@S)) + } +) + + +# lower bounds +setMethod("lowbnd", signature(object = "modelorg"), + function(object) { + return(object@lowbnd) + } +) + +setReplaceMethod("lowbnd", signature(object = "modelorg"), + function(object, value) { + object@lowbnd <- value + return(object) + } +) + + +# upper bounds +setMethod("uppbnd", signature(object = "modelorg"), + function(object) { + return(object@uppbnd) + } +) + +setReplaceMethod("uppbnd", signature(object = "modelorg"), + function(object, value) { + object@uppbnd <- value + return(object) + } +) + + +# objective coefficient +setMethod("obj_coef", signature(object = "modelorg"), + function(object) { + return(object@obj_coef) + } +) + +setReplaceMethod("obj_coef", signature(object = "modelorg"), + function(object, value) { + object@obj_coef <- value + return(object) + } +) + + +# gprRules +setMethod("gprRules", signature(object = "modelorg"), + function(object) { + return(object@gprRules) + } +) + +setReplaceMethod("gprRules", signature(object = "modelorg"), + function(object, value) { + object@gprRules <- value + return(object) + } +) + + +# genes +setMethod("genes", signature(object = "modelorg"), + function(object) { + return(object@genes) + } +) + +setReplaceMethod("genes", signature(object = "modelorg"), + function(object, value) { + object@genes <- value + return(object) + } +) + + +# gpr associations +setMethod("gpr", signature(object = "modelorg"), + function(object) { + return(object@gpr) + } +) + +setReplaceMethod("gpr", signature(object = "modelorg"), + function(object, value) { + object@gpr <- value + return(object) + } +) + + +# list of all genes +setMethod("allGenes", signature(object = "modelorg"), + function(object) { + return(object@allGenes) + } +) + +setReplaceMethod("allGenes", signature(object = "modelorg"), + function(object, value) { + object@allGenes <- value + return(object) + } +) + + +# reaction to gene mapping +setMethod("rxnGeneMat", signature(object = "modelorg"), + function(object) { + return(object@rxnGeneMat) + } +) + +setReplaceMethod("rxnGeneMat", signature(object = "modelorg"), + function(object, value) { + object@rxnGeneMat <- value + return(object) + } +) + + +# reaction sub systems +setMethod("subSys", signature(object = "modelorg"), + function(object) { + return(object@subSys) + } +) + +setReplaceMethod("subSys", signature(object = "modelorg"), + function(object, value) { + object@subSys <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("show", signature(object = "modelorg"), + function(object) { + cat("model name: ", mod_name(object), "\n") + cat("number of compartments ", length(mod_compart(object)), "\n") + lapply(mod_compart(object), function(x) + cat(" ", x, "\n") + ) + cat("number of reactions: ", react_num(object), "\n") + cat("number of metabolites: ", met_num(object), "\n") + if (length(allGenes) > 0) { + cat("number of unique genes:", length(allGenes(object)), "\n") + } + cat("objective function: ", printObjFunc(object), "\n") + } +) + + +#------------------------------------------------------------------------------# + +setMethod("optimizeProb", signature(object = "modelorg"), + function(object, + algorithm = SYBIL_SETTINGS("ALGORITHM"), + gene = NULL, + react = NULL, + lb = NULL, + ub = NULL, + retOptSol = TRUE, + obj_coef = NULL, + lpdir = NULL, + mtfobj = NULL, + fldind = TRUE, + prCmd = NA, poCmd = NA, + prCil = NA, poCil = NA, ...) { + + + if (!is.null(gene)) { + if (!is.null(react)) { + warning("ignoring argument 'react'") + } + react <- geneDel(object, gene, checkId = TRUE) + lb <- rep(lb[1], length(react)) + ub <- rep(ub[1], length(react)) + } + + # check the argument react + # if object is of class "modelorg", react is given by the user + if (!is.null(react)) { + check <- checkReactId(object, react = react) + if (is(check, "reactId")) { + react <- react_pos(check) + if (length(lb) == 1) { + lb <- rep(lb[1], length(react)) + } + if (length(ub) == 1) { + ub <- rep(ub[1], length(react)) + } + if (length(obj_coef) == 1) { + obj_coef <- rep(obj_coef[1], length(react)) + } + } + else { + stop("check argument react") + } + } + + + # -------------------------------------------------------------- # + # run optimization + # -------------------------------------------------------------- # + + if (algorithm == "mtf") { + if (is.null(mtfobj)) { + lpmod <- sysBiolAlg(model = object, algorithm = "mtf", + react = react, lb = lb, ub = ub, ...) + } + else { + lpmod <- sysBiolAlg(model = object, + algorithm = "mtf", wtobj = mtfobj, ...) + } + } + else { + lpmod <- sysBiolAlg(model = object, algorithm = algorithm, ...) + } + +# MoreArgs[["object"]] <- lpmod +# MoreArgs[["react"]] <- react +# MoreArgs[["lb"]] <- lb +# MoreArgs[["ub"]] <- ub +# +# sol <- do.call("optimizeProb", args = MoreArgs) + sol <- optimizeProb(lpmod, + react = react, + lb = lb, + ub = ub, + obj_coef = obj_coef, + lpdir = lpdir, + fldind = fldind, + resetChanges = FALSE, + prCmd = prCmd, poCmd = poCmd, + prCil = prCil, poCil = poCil) + + + # -------------------------------------------------------------- # + # store solution + # -------------------------------------------------------------- # + + if (isTRUE(retOptSol)) { + + # solution object + optsol <- new("optsol_optimizeProb", + mod_id = mod_id(object), + mod_key = mod_key(object), + solver = solver(problem(lpmod)), + method = method(problem(lpmod)), + algorithm = algorithm(lpmod), + num_of_prob = 1L, + lp_dir = factor(getObjDir(problem(lpmod))), + lp_num_rows = nr(lpmod), + lp_num_cols = nc(lpmod), + lp_ok = as.integer(sol[["ok"]]), + lp_obj = sol$obj, + lp_stat = as.integer(sol[["stat"]]), + obj_coef = obj_coef(object), + obj_func = printObjFunc(object), + fldind = fldind(lpmod), + fluxdist = fluxDistribution(fluxes = sol[["fluxes"]], + nrow = length(sol[["fluxes"]]), + ncol = 1L), + alg_par = alg_par(lpmod)) + + if (is(sol$preP, "ppProc")) { + preProc(optsol) <- sol[["preP"]] + } + + if (is(sol$postP, "ppProc")) { + postProc(optsol) <- sol[["postP"]] + } + + check <- validObject(optsol, test = TRUE) + + if (check != TRUE) { + warning(paste("Validity check failed:", check, sep = "\n "), + call. = FALSE + ) + } + + checkOptSol(optsol, onlywarn = TRUE) + } + else { + optsol <- sol + optsol[["fldind"]] <- fldind(lpmod) + } + + delProb(problem(lpmod)) + remove(lpmod) + + return(optsol) + + } +) + + +#------------------------------------------------------------------------------# + +# print objective function +setMethod("printObjFunc", signature(object = "modelorg"), + function(object) { + cInd <- obj_coef(object) != 0 + + # check if there is an objective function + if (sum(cInd) == 0) { + of <- "no objective function" + } + else { + obj <- gsub("^([^-])", "+\\1", + obj_coef(object)[cInd], perl = TRUE) + of <- paste(paste(obj, react_id(object)[cInd]), + collapse = " ") + } + + return(of) + } +) + + +#------------------------------------------------------------------------------# + +# print reactions +setMethod("printReaction", signature(object = "modelorg"), + function(object, react, printOut = TRUE, ...) { + + check <- checkReactId(object, react = react) + if (is(check, "reactId")) { + cind <- react_pos(check) + } + else { + stop("check argument react") + } + + mat <- S(object)[, cind, drop = FALSE] + nnz <- apply(mat, 2, "!=", 0) + reaction <- character(length(cind)) + + for (j in seq(along = cind)) { + + met <- met_id(object)[nnz[, j]] + nzv <- mat[, j][nnz[, j]] + + ed <- nzv < 0 + pd <- nzv > 0 + + if (sum(ed) > 0) { + educt <- paste(paste("(", abs(nzv[ed]), ")", sep = ""), + met[ed], collapse = " + ") + } + else { + educt = "" + } + + if (sum(pd) > 0) { + product <- paste(paste("(", nzv[pd], ")", sep = ""), + met[pd], collapse = " + ") + } + else { + product = "" + } + + arrow <- ifelse(react_rev(object)[cind[j]], " <==> ", " --> ") + + reaction[j] <- paste(react_id(check)[j], + paste(educt, product, sep = arrow), sep = "\t") + } + + if (isTRUE(printOut)) { + cat("abbreviation\tequation", reaction, sep = "\n", ...) + } + + return(invisible(reaction)) + + } +) + + +#------------------------------------------------------------------------------# + +# print metabolites +setMethod("printMetabolite", signature(object = "modelorg"), + function(object, met, FBAlp = FALSE, printOut = TRUE, ...) { + + if ( (missing(met)) || (isTRUE(FBAlp)) ) { + mid <- met_id(object) + rind <- c(1:met_num(object)) + } + else { + if (is(met, "numeric")) { + mid <- met_id(object)[met] + rind <- met + } + else if (is(met, "character")) { + rind <- match(met, met_id(object)) + if (any(is.na(rind))) { + stop("check argument met") + } + else { + mid <- met + } + } + else { + stop("argument met must be character or numeric") + } + } + + # format metabolite id's to be compatible with CPLEX LP format + midbr <- .makeLPcompatible(name = mid, prefix = "r", sep = "") + + # format reaction id's to be compatible with CPLEX LP format + reaction_id <- .makeLPcompatible(name = react_id(object), + prefix = "x", sep = "") + + mat <- S(object)[rind, , drop = FALSE] + nnz <- apply(mat, 1, "!=", 0) + metabolite <- character(length(rind)) + + + for (i in seq(along = rind)) { + + react <- reaction_id[nnz[, i]] + nzv <- mat[i, ][nnz[, i]] + + nm <- nzv != 0 + + if (sum(nm) > 0) { + nz <- gsub("^([^-])", "+\\1", nzv[nm], perl = TRUE) + bal <- paste(nz, react[nm], collapse = " ") + } + else { + bal = "" + } + + metabolite[i] <- paste(paste(" ", midbr[i], ":", sep = ""), + bal, sep = "\t") + } + + if (isTRUE(FBAlp)) { + obj <- c("Maximize", + paste(" obj:", printObjFunc(object)), + "", + "Subject To") + bnds <- c("", + "Bounds", + paste(paste("", lowbnd(object)), + reaction_id, uppbnd(object), sep = " <= "), + "", + "End") + + tof <- c(obj, paste(metabolite, "", sep = " = 0"), bnds) + } + else { + tof <- metabolite + } + + if (isTRUE(printOut)) { + cat(tof, sep = "\n", ...) + } + + return(invisible(tof)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("shrinkMatrix", signature(X = "modelorg"), + function(X, i = NULL, j = NULL, tol = SYBIL_SETTINGS("TOLERANCE")) { + + stopifnot(xor(is.null(i), is.null(j))) + + # look for reactions --> j + if (is.null(i)) { + # translate reaction id's to indices + cj <- checkReactId(X, react = j) + if (!is(cj, "reactId")) { + stop("check argument j") + } + else { + cn <- react_pos(cj) + } + met <- NULL + } + + + # look for metabolites --> i + if (is.null(j)) { + # translate reaction id's to indices + if (is(i, "character")) { + met <- which(met_id(X) %in% i) + } + else if (is(i, "reactId_Exch")) { + met <- met_pos(i) + } + else if (is(i, "numeric")) { + met <- i + } + else { + stop("check argument i") + } + + matB <- abs(S(X)[met, , drop = FALSE]) > tol + + cn <- colSums(matB) > 0 + } + + # generate new matrix + mat <- S(X)[, cn, drop = FALSE] + + # binary matrix + matB <- abs(mat) > tol + + if (is.null(met)) { + rn <- rowSums(matB) > 0 + } + else { + nzm <- which(rowSums(matB) > 0) + ord <- nzm %in% met + rn <- c(nzm[ord], nzm[!ord]) + } + + mat <- mat[rn, , drop = FALSE] + + colnames(mat) <- react_id(X)[cn] + rownames(mat) <- met_id(X)[rn] + + return(mat) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeUptake", signature(object = "modelorg"), + function(object, off = NULL, on = NULL, + rate = SYBIL_SETTINGS("MAXIMUM") * -1) { + + ex <- findExchReact(object) + + if (! is(off, "logical")) { + if (is.null(off)) { + reactOFF <- react_pos(ex)[uptake(ex)] + } + else { + # metabolite id + if (is(off, "character")) { + met <- which(met_id(ex) %in% off) + reactOFF <- react_pos(ex)[met] + } + # metabolite index in S + else if (is(off, "numeric")) { + met <- which(met_pos(ex) %in% off) + reactOFF <- react_pos(ex)[met] + } + # exchange reactions + else if (is(off, "reactId_Exch")) { + reactOFF <- react_pos(off) + } + else { + stop("check argument off") + } + + if (length(reactOFF) < 1) { + stop("can not find ", + ngettext(is(off, "reactId_Exch"), + "exchange reaction id ", + "an exchange reaction for metabolite id "), + paste(sQuote(off), collapse = ", ")) + } + } + + lowbnd(object)[reactOFF] <- 0 + } + + if (!is.null(on)) { + # metabolite id + if (is(on, "character")) { + met <- which(met_id(ex) %in% on) + reactON <- react_pos(ex)[met] + } + # metabolite index in S + else if (is(on, "numeric")) { + met <- which(met_pos(ex) %in% on) + reactON <- react_pos(ex)[met] + } + # exchange reactions + else if (is(on, "reactId_Exch")) { + reactON <- react_pos(on) + } + else { + stop("check argument on") + } + + if (length(reactON) < 1) { + stop("can not find ", + ngettext(is(on, "reactId_Exch"), + "exchange reaction id ", + "an exchange reaction for metabolite id "), + paste(sQuote(on), collapse = ", ")) + } + + lowbnd(object)[reactON] <- rate + } + + return(object) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("deadEndMetabolites", signature(object = "modelorg"), + function(object, retIds = TRUE) { + + demr <- .deadEndMetabolite(mat = S(object), lb = lowbnd(object)) + + if (isTRUE(retIds)) { + dem <- list(dem = met_id(object)[demr[["dem"]]], + der = react_id(object)[demr[["der"]]]) + } + else { + dem <- demr + } + + return(dem) + + } +) + +#------------------------------------------------------------------------------# + +setMethod("singletonMetabolites", signature(object = "modelorg"), + function(object, tol = SYBIL_SETTINGS("TOLERANCE"), retIds = TRUE) { + + Sb <- abs(S(object)) > tol + + singleton <- .singletonMetabolite(mat = Sb) + + if (isTRUE(retIds)) { + sg <- list(smet = met_id(object)[singleton[["smet"]]], + sreact = react_id(object)[singleton[["sreact"]]]) + } + else { + sg <- singleton + } + + return(sg) + + } +) + + + + + + + + + + + + + + diff --git a/R/modelorg_irrevClass.R b/R/modelorg_irrevClass.R new file mode 100644 index 0000000..9c1850b --- /dev/null +++ b/R/modelorg_irrevClass.R @@ -0,0 +1,139 @@ +# modelorg_irrevClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# modelorg_irrevClass + + +#------------------------------------------------------------------------------# +# definition of the class modelorg_irrev # +#------------------------------------------------------------------------------# + +setClass("modelorg_irrev", + representation( + irrev = "logical", + matchrev = "integer", + rev2irrev = "matrix", + irrev2rev = "integer" + ), + contains = "modelorg" +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +modelorg_irrev <- function(id, name) { + if (missing(id) || missing(name)) { + stop("Creating an object of class modelorg_irrev needs name and id!") + } + id <- as.character(id) + name <- as.character(name) + obj <- new("modelorg_irrev", id = id, name = name) + return(obj) +} + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +setMethod(f = "initialize", + signature = "modelorg_irrev", + definition = function(.Object, id, name) { + + if (!missing(id) || !missing(name)) { + .Object <- callNextMethod(.Object, id = id, name = name) + } + + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# irrev +setMethod("irrev", signature(object = "modelorg_irrev"), + function(object) { + return(object@irrev) + } +) + +setReplaceMethod("irrev", signature = (object = "modelorg_irrev"), + function(object, value) { + object@irrev <- value + return(object) + } +) + + +# matchrev +setMethod("matchrev", signature(object = "modelorg_irrev"), + function(object) { + return(object@matchrev) + } +) + +setReplaceMethod("matchrev", signature = (object = "modelorg_irrev"), + function(object, value) { + object@matchrev <- value + return(object) + } +) + + +# rev2irrev +setMethod("rev2irrev", signature(object = "modelorg_irrev"), + function(object) { + return(object@rev2irrev) + } +) + +setReplaceMethod("rev2irrev", signature = (object = "modelorg_irrev"), + function(object, value) { + object@rev2irrev <- value + return(object) + } +) + + +# irrev2rev +setMethod("irrev2rev", signature(object = "modelorg_irrev"), + function(object) { + return(object@irrev2rev) + } +) + +setReplaceMethod("irrev2rev", signature = (object = "modelorg_irrev"), + function(object, value) { + object@irrev2rev<- value + return(object) + } +) + + + diff --git a/R/multiDel.R b/R/multiDel.R new file mode 100644 index 0000000..fdc8f6f --- /dev/null +++ b/R/multiDel.R @@ -0,0 +1,269 @@ +# multiDel.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: multDel +# +# +# +# + +multiDel <- function(model, nProc = 2, + todo = "oneGeneDel", + del1 = NA, del2 = NA, ...) { +# #unlistResult = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (nProc < 2) { + stop("argument nProc must be equal or greater than 2!") + } + + #--------------------------------------------------------------# + # split delX to a list of length numCo + #--------------------------------------------------------------# + spDel <- function(del) { + if(is(del, "matrix")) { + nd <- ncol(del) + splitmat <- TRUE + } + else { + nd <- length(del) + splitmat <- FALSE + } + + if (numCo > nd) { + numCo <- nd + } + + if (isTRUE(splitmat)) { + gs <- floor(seq(1, nd, length.out = numCo+1)) + dL <- vector(mode = "list", length = numCo) + + for (i in seq(along = gs[1:numCo])) { + en <- ifelse(i == numCo, gs[i+1], gs[i+1]-1) + dL[[i]] <- del[, gs[i]:en, drop = FALSE] + #dL[[i]] <- c(gs[i], en) + } + } + else { + gs <- floor(seq(0, nd, length.out = numCo+1)) + + # convert to factor + spf <- cut(1:nd, gs) + # use spf as factor for split() + dL <- split(del, spf) + } + + return(dL) + } + + #--------------------------------------------------------------# + + + # load library 'parallel' + if(!isTRUE(require("parallel"))) { + stop("package parallel not found.") + } + + # number of cores + ncore <- parallel::detectCores() + + numCo <- ifelse(nProc > ncore, as.integer(ncore), as.integer(nProc)) + + + #--------------------------------------------------------------# + # split input into lists of size numCo + + if (any(is.na(del1))) { + dL1 <- spDel(allGenes(model)) + } + else { + dL1 <- spDel(del1) + } + + if (any(is.na(del2))) { + dL2 <- as.list(rep(NA, length(dL1))) + } + else { + if (length(del1) != length(del2)) { + stop(paste("if argument del2 is not NA,", + "del1 and del2 must have same length!")) + } + dL2 <- spDel(del2) + cdL <- vector("list", length(dL1)) + for (i in seq(along = cdL)) { + cdL[[i]] <- c(dL1[i], dL2[i]) + } + } + + + #--------------------------------------------------------------# + # run optimizations + + sol <- switch(todo, + "oneGeneDel" = { + parallel::mclapply(dL1, + function(x) oneGeneDel(model, + geneList = x, + verboseMode = 0, ...), + mc.cores = nProc) + + }, + "doubleGeneDel" = { + parallel::mclapply(cdL, function(x) doubleGeneDel(model, + geneList1 = x[[1]], + geneList2 = x[[2]], + verboseMode = 0, ...), + mc.cores = nProc) + }, + "oneFluxDel" = { + parallel::mclapply(dL1, function(x) oneFluxDel(model, + react = x, + verboseMode = 0, ...), + mc.cores = nProc) + }, + "doubleFluxDel" = { + parallel::mclapply(cdL, function(x) doubleFluxDel(model, + react1 = x[[1]], + react2 = x[[2]], + verboseMode = 0, ...), + mc.cores = nProc) + }, + "fluxVar" = { + parallel::mclapply(dL1, function(x) fluxVar(model, + react = x, + verboseMode = 0, ...), + mc.cores = nProc) + }, + "geneDeletion" = { + parallel::mclapply(dL1, function(x) geneDeletion(model, + genes = x, + verboseMode = 0, ...), + mc.cores = nProc) + }, + { + stop("argument todo is not valid!") + } + ) + +# if ( (isTRUE(unlistResult)) && (is(sol, "list")) ) { +# ## maybe we can use something like unlist here +# sv <- solver(sol[[1]]) +# nc <- lp_num_cols(sol[[1]]) +# nr <- lp_num_rows(sol[[1]]) +# of <- obj_function(sol[[1]]) +# np <- sum(mapply(num_of_prob, sol)) - (numCo-1) +# +# +# # generate an index-vector of elements we want to use from sol +# # every first element is the wild-type solution and this should be +# # excluded, except for the first one +# +# npL <- mapply(num_of_prob, sol, SIMPLIFY = FALSE, USE.NAMES = FALSE) +# np <- sum(unlist(npL)) - (numCo-1) +# +# indL <- mapply(rep, npL, MoreArgs = list(x=TRUE), SIMPLIFY = FALSE) +# +# for (i in seq(along = indL)[-1]) { +# indL[[i]][1] <- FALSE +# } +# +# newSol <- switch(todo, +# "oneGeneDel" = { +# optsol_geneDel(solver, +# nprob, +# lpdir, +# ncols, +# nrows, +# objf, +# fld, +# comb = 1) +# +# }, +# "doubleGeneDel" = { +# optsol_doublegenedel(solver, +# nprob, +# lpdir, +# nrows, +# ncols, +# delrows, +# delcols, +# objf, +# fld) +# }, +# "oneFluxDel" = { +# optsol_fluxdel(solver, +# nprob, +# lpdir, +# ncols, +# nrows, +# objf, +# fld, +# comb = 1) +# }, +# "doubleFluxDel" = { +# optsol_doublefluxdel(solver, +# nprob, +# lpdir, +# nrows, +# ncols, +# delrows, +# delcols, +# objf, +# fld) +# }, +# "fluxVar" = { +# optsol_fluxVar(solver, +# method, +# nprob, +# lpdir, +# ncols, +# nrows, +# objf, +# fld, +# rc) +# }, +# "geneDeletion" = { +# optsol_geneDel(solver, +# nprob, +# lpdir, +# ncols, +# nrows, +# objf, +# fld, +# comb = 1) +# }, +# { +# stop("argument todo is not valid!") +# } +# ) +# +# } + + return(sol) + +} diff --git a/R/netFluxClass.R b/R/netFluxClass.R new file mode 100644 index 0000000..624bf6c --- /dev/null +++ b/R/netFluxClass.R @@ -0,0 +1,121 @@ +# netFluxClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# netFluxClass + + +#------------------------------------------------------------------------------# +# class definitions # +#------------------------------------------------------------------------------# + +setClass("netFlux", + representation( + uptake = "logical", + product = "logical", + unused = "logical", + react_id = "character", + rate = "numeric" + ), +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +getNetFlux <- function(rates, tol = SYBIL_SETTINGS("TOLERANCE")) { + + id <- names(rates) + names(rates) <- NULL + + upt <- rates < tol * -1 + prd <- rates > tol + uusd <- logical(length(rates)) + uusd[!upt] <- TRUE + uusd[!prd] <- TRUE + + nf <- new("netFlux", + react_id = as.character(id), + rate = as.numeric(rates), + uptake = upt, product = prd, unused = uusd) + + return(nf) +} + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# react_id +setMethod("react_id", signature(object = "netFlux"), + function(object) { + return(object@react_id) + } +) + +setReplaceMethod("react_id", signature = (object = "netFlux"), + function(object, value) { + object@react_id <- value + return(object) + } +) + + +# rate +setMethod("rate", signature(object = "netFlux"), + function(object) { + return(object@rate) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + + + +# consider using sprintf here +setMethod("show", signature(object = "netFlux"), + function(object) { + ri <- react_id(object) + rr <- rate(object) + cat("uptake reaction rates (absolute values):\n") + cat(sprintf(" %-20s%10f\n", ri[object@uptake], abs(rr[object@uptake])), sep = "") + cat("\nexcretion reaction rates (absolute values):\n") + cat(sprintf(" %-20s%10f\n", ri[object@product], rr[object@product]), sep = "") + cat("\nunused exchange reactions [abs(rate) < ", SYBIL_SETTINGS("TOLERANCE"), "]:\n", sep = "") + print(ri[object@unused]) + } +) + + +# length of an object of class optsol +setMethod("length", signature = signature(x = "netFlux"), + function(x) { + return(length(rate(x))) + } +) + diff --git a/R/oneFluxDel.R b/R/oneFluxDel.R new file mode 100644 index 0000000..d2a7a68 --- /dev/null +++ b/R/oneFluxDel.R @@ -0,0 +1,72 @@ +# oneFluxDel.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: oneFluxDel +# +# This function performs a "gene deletion analysis". +# In each iteration one gene is switched of (vi = 0) +# and the objective function will be computed. +# +# The function oneGeneDel() is inspired by the function +# singleRxnDeletion() contained in the COBRA Toolbox. + + +oneFluxDel <- function(model, react = c(1:react_num(model)), + lb = rep(0, length(react)), + ub = rep(0, length(react)), + checkOptSolObj = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + creact <- checkReactId(model, react) + if (!is(creact, "reactId")) { + stop("check argument react") + } + + creact <- sort(react_pos(creact)) + + sol <- optimizer(model = model, lb = lb, ub = ub, + react = as.list(creact), ...) + + # ------------------------------------------------------------------------ # + + optsol <- new("optsol_fluxdel") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + chlb(optsol) <- as.numeric(lb) + chub(optsol) <- as.numeric(ub) + dels(optsol) <- matrix(react_id(model)[creact], ncol = 1) + + if (isTRUE(checkOptSolObj)) { + checkOptSol(optsol, onlywarn = TRUE) + } + + return(optsol) + +} + diff --git a/R/oneGeneDel.R b/R/oneGeneDel.R new file mode 100644 index 0000000..be46907 --- /dev/null +++ b/R/oneGeneDel.R @@ -0,0 +1,95 @@ +# oneGeneDel.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: oneGeneDel +# +# This function performs a "gene deletion analysis". +# In each iteration all reactions corresponding to a +# gene were switched of (vi = 0) and the objective +# function will be computed. +# +# The function oneGeneDel() is inspired by the function +# singleGeneDeletion() contained in the COBRA Toolbox. + + +oneGeneDel <- function(model, geneList, + lb = rep(0, length(geneList)), + ub = rep(0, length(geneList)), + checkOptSolObj = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (missing(geneList)) { + if (length(allGenes(model)) < 1) { + stop("Argument 'geneList' must contain at least one gene!") + } + else { + geneList <- c(1:length(allGenes(model))) + } + } + + # translate the gene List in indices of allGenes(model) + if (is(geneList, "character")) { + geneList <- match(geneList, allGenes(model)) + if (any(is.na(geneList))) { + stop("check genelist!") + } + } + + #geneList <- sort(geneList) + + + # ------------------------------------------------------------------------ # + + fd <- .generateFluxdels(model, geneList) + + sol <- optimizer(model = model, + react = fd[["react"]], lb = lb, ub = ub, ...) + + + # ------------------------------------------------------------------------ # + + optsol <- new("optsol_genedel") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + chlb(optsol) <- as.numeric(lb) + chub(optsol) <- as.numeric(ub) + dels(optsol) <- matrix(allGenes(model)[geneList], ncol = 1) + fluxdels(optsol) <- fd[["fd"]] + hasEffect(optsol) <- fd[["heff"]] + + if (isTRUE(checkOptSolObj)) { + checkOptSol(optsol, onlywarn = TRUE) + } + + return(optsol) + +} + + + diff --git a/R/onlyChangeGPR.R b/R/onlyChangeGPR.R new file mode 100644 index 0000000..4e2fbf0 --- /dev/null +++ b/R/onlyChangeGPR.R @@ -0,0 +1,124 @@ +# onlyChangeGPR.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: onlyChangeGPR +# +# +# +# +# model must be an object of modelorg +# gprRules stands for the new logical Expressions (GPR Rules) +# reactNr must be numeric + +onlyChangeGPR <- function(model,gprRules,reactNr,verboseMode = 0) { + + # is the chosen model type of modelorg? + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (!missing(reactNr)) { + if (!is(reactNr, "numeric")) { + stop("argument reactNr must be numeric!") + } + } + + # allowed logical symbols are stored in logSymb + logSymb <- c("and", "or", "not", "AND", "OR", "NOT", "&", "|", "!") + + #if (verboseMode > 1) { cat("Updating ... ") } + + for (anz in seq(1, length(gprRules), by = 1)) { + + #check <- tolower(gprRules[anz]) + #check <- gsub("[()]","", check) + check <- gsub("[()]","", gprRules[anz]) + check <- strsplit(check, "\\s+") + check <- unlist(check) + + if (check[1] == "") { + check <- check[-1] + } + + # update gpr() + + gpr(model)[reactNr[anz]] <- gprRules[anz] + #print(gprRules) + + # update genes(), rxnGeneMat() and gprRules() + + genes(model)[[reactNr[anz]]] <- "" + rxnGeneMat(model)[reactNr[anz],] <- 0 + gprRules(model)[reactNr[anz]] <- .parseBoolean(gprRules[anz])[[2]] + gprRules_tmp <- as.numeric(unlist(strsplit(gprRules(model)[reactNr[anz]], "\\D+", perl = TRUE))[-1]) + #print(gprRules_tmp) + #print(gprRules(model)[reactNr[anz]]) + #print(gprRules(model)[reactNr]) + #print(.parseBoolean(gprRules)[[2]]) + + j <- 1 + + for (i in seq(1, length(check), by = 2)) { + + genes(model)[[reactNr[anz]]][j] <- check[i] + rxnGeneMat(model)[reactNr[anz],match(check[i], allGenes(model))] <- 1 + #print(gprRules(model)[reactNr[anz]]) +# gprRules(model)[reactNr[anz]] <- gsub( paste("\\(", deparse(j), "\\)", sep = ""), +# paste("[", deparse(as.double(match(check[i], allGenes(model)))),"]", sep = ""), +# gprRules(model)[reactNr[anz]], fixed = TRUE +# ) + gprRules(model)[reactNr[anz]] <- gsub( paste("\\(", gprRules_tmp[j], "\\)", sep = ""), + paste("[", match(check[i], allGenes(model)),"]", sep = ""), + gprRules(model)[reactNr[anz]] + ) + #print(gprRules(model)[reactNr[anz]]) + #print(paste("\\(", deparse(j), "\\)", sep = "")) + #print(paste("[", match(check[i], allGenes(model)),"]", sep = "")) + #print(check[i]) + j <- j + 1 + + } + + genes(model)[[reactNr[anz]]] <- unique(genes(model)[[reactNr[anz]]]) + + # edit the expression to make it look better ;).. + # ..add blanks; add brackets around the expression + + if (length(check) > 1) { + + gpr(model)[reactNr[anz]] <- gsub(" "," ",gpr(model)[reactNr[anz]]) + gprRules(model)[reactNr[anz]] <- gsub(" "," ",gprRules(model)[reactNr[anz]]) + gpr(model)[reactNr[anz]] <- paste("(",gpr(model)[reactNr[anz]],")") + gprRules(model)[reactNr[anz]] <- paste("(",gprRules(model)[reactNr[anz]],")") + + } + + #if (verboseMode > 1) { cat("OK. \n") } + + } + + return(model) + +} diff --git a/R/onlyCheckGPR.R b/R/onlyCheckGPR.R new file mode 100644 index 0000000..ddc62ce --- /dev/null +++ b/R/onlyCheckGPR.R @@ -0,0 +1,190 @@ +# onlyCheckGPR.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: onlyCheckGPR +# +# +# +# +# model must be an object of modelorg +# gprRules stands for the logical Expressions (GPR Rules) +# reactNr must be numeric + +onlyCheckGPR <- function(model,gprRules,reactNr,verboseMode = 1) { + + # is the chosen model type of modelorg? + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (!missing(reactNr)) { + if (!is(reactNr, "numeric")) { + stop("argument reactNr must be numeric!") + } + } + + ###### is the logical Expression correct? ###### + + # allowed logical symbols are stored in logSymb + #logSymb <- c("and", "or", "not", "&", "|", "!") + logSymb <- c("and", "or", "not", "AND", "OR", "NOT", "&", "|", "!") + + ### check every expression and change.. + for (anz in seq(1, length(gprRules), by = 1)) { + + if (verboseMode > 1 && !missing(reactNr)) { + cat(paste("Checking logical expression for reaction", + react_id(model)[reactNr[anz]],"... "), sep="" ) } + #check <- tolower(gprRules[anz]) + #check <- gsub("[()]","", check) + check <- gsub("[()]","", gprRules[anz]) + check <- strsplit(check, "\\s+") + check <- unlist(check) + + if (check[1] == "") { + check <- check[-1] + } + + #print(check) + + # now start the checking + if ( identical((length(check) %% 2), 0) ) { + + if (verboseMode > 0) {stop("=> Wrong logical expression!\n") } + #errors <- TRUE + #changeVector <- c(changeVector, FALSE) + #next + + } + # only one gene? + if ( identical(length(check),as.integer(1)) ) { + + if (!any(!is.na(match(logSymb, check[1])))) { + + # do nothing here if the logical expression contains a Gene. Else stop + if ( any(is.na(match(check[1], allGenes(model)))) ) { + + if (verboseMode > 0) {stop(paste("=> Gene ", check[1] , + " does not exist in the model!\n", sep="")) } + #errors <- TRUE + #changeVector <- c(changeVector, FALSE) + #next + + } + + } + else { + + if (verboseMode > 0) {stop("=> Wrong logical expression!\n") } + #errors <- TRUE + #changeVector <- c(changeVector, FALSE) + #next + + } + + } + + #print(check) + + # go here if there is more than one splitted string. Check the logical expression + else { + + x <- FALSE + + for (i in seq(2, length(check), by = 2)) { + + if (any(!is.na(match(logSymb, check[i-1])))) { + + if (verboseMode > 0) {stop("=> Wrong logical expression!\n") } + #errors <- TRUE + #x <- TRUE + #next + + } + + if ( any(is.na(match(check[i-1], allGenes(model)))) ) { + + if (verboseMode > 0) { stop(paste("=> Gene ", check[i-1] , + " does not exist in the model!\n", sep="")) } + #errors <- TRUE + #x <- TRUE + #next + + } + + if ((i+1) <= length(check)) { + + if (any(!is.na(match(logSymb, check[i+1])))) { + + if (verboseMode > 0) { stop("=> Wrong logical expression!\n") } + #errors <- TRUE + #x <- TRUE + #next + + } + + if ( any(is.na(match(check[i+1], allGenes(model)))) ) { + + if (verboseMode > 0) { stop(paste("=> Gene ", check[i+1] , + " does not exist in the model!\n", sep="")) } + #errors <- TRUE + #x <- TRUE + #next + + } + + } + + if (!any(!is.na(match(logSymb, check[i])))) { + + if (verboseMode > 0) { stop("=> Wrong logical expression!\n") } + #errors <- TRUE + #x <- TRUE + #next + + } + + } + + # next, if an error occured + #if (x) { + # changeVector <- c(changeVector, FALSE) + # next + #} + + } + + #changeVector <- c(changeVector, TRUE) + #if ( (verboseMode > 1) && !missing(reactNr) ) { cat("OK. \n") } + + } + + #if (errors) { cat("Check logical expression(s)! \n") } + + #if (!errors && (verboseMode > 0)) { cat("OK. \n") } + + #return(changeVector) + +} diff --git a/R/optObjClass.R b/R/optObjClass.R new file mode 100644 index 0000000..942acd2 --- /dev/null +++ b/R/optObjClass.R @@ -0,0 +1,169 @@ +# optObjClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class optObj # +#------------------------------------------------------------------------------# + +setClass(Class = "optObj", + representation( + oobj = "pointerToProb", + solver = "character", + method = "character", + probType = "character" + ), + contains = "VIRTUAL" +) + +# derivatives +#setClass(Class = "optObj_boot", contains = "optObj") + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +optObj <- function(solver = SYBIL_SETTINGS("SOLVER"), + method = SYBIL_SETTINGS("METHOD"), + pType = "lp", prefix = "optObj", sep = "_") { + + validSoMe <- checkDefaultMethod(solver, method, pType) + + obj <- new(paste(prefix, validSoMe$sol, sep = sep), + sv = validSoMe$sol, + mt = validSoMe$met, + pt = as.character(pType)) + + return(obj) +} + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class optObj +setMethod(f = "initialize", + signature = "optObj", + definition = function(.Object, sv, mt, pt) { + + if ( (!missing(sv)) && (!missing(mt)) && (!missing(pt)) ) { + + .Object@solver <- as.character(sv) + .Object@method <- as.character(mt) + .Object@probType <- as.character(pt) + + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# getters # +#------------------------------------------------------------------------------# + +# solver +setMethod("solver", signature(object = "optObj"), + function(object) { + return(object@solver) + } +) + + +# method +setMethod("method", signature(object = "optObj"), + function(object) { + return(object@method) + } +) + + +# probType +setMethod("probType", signature(object = "optObj"), + function(object) { + return(object@probType) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +# get the current dimension of the constraint matrix +setMethod("dim", "optObj", + + function(x) { + + out <- c(0, 0) + out[1] <- getNumRows(x) + out[2] <- getNumCols(x) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("show", signature(object = "optObj"), + function(object) { + if (length(probType(object)) > 0) { + switch (probType(object), + "lp" = { + cat("linear programming problem object\n") + }, + "mip" = { + cat("mixed integer linear programming problem object\n") + }, + "qp" = { + cat("continuous problem object with quadratic objective\n") + }, + { + cat("problem object of type ", probType(object),"\n") + } + ) + cat("solver:", solver(object), "\n") + cat("method:", method(object), "\n") + size <- tryCatch(dim(object), error = function(e) NA) + if (any(is.na(size))) { + cat("problem is not initialized\n") + } + else if (all(size == 0)) { + cat("problem is currently empty\n") + } + else { + cat("problem has", size[2], + ngettext(size[2], "variable", "variables")) + cat(" and", size[1], + ngettext(size[1], "constraint", "constraints"), "\n") + } + } + else { + cat("empty problem object\n") + } + } +) + diff --git a/R/optObj_basicfunc.R b/R/optObj_basicfunc.R new file mode 100644 index 0000000..1913fdd --- /dev/null +++ b/R/optObj_basicfunc.R @@ -0,0 +1,147 @@ +# optObj_basicfunc.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# + +# print a warning +wrong_type_msg <- function(lp) { + warning(paste("Slot oobj of", lp@solver, + "is not a valid pointer to a valid solver." + ) + ) +} + + +wrong_solver_msg <- function(lp, method, printOut = TRUE) { + if (isTRUE(printOut)) { + warning(paste("Requested method", method, + "is not available for solver", lp@solver + ) + ) + } +} + + +#------------------------------------------------------------------------------# + +# which optimizations did not end successful +checkSolStat <- function(stat, solver = SYBIL_SETTINGS("SOLVER")) { + + out <- FALSE + switch(solver, + "glpkAPI" = { + out <- which(stat != 5) + }, + "clpAPI" = { + out <- which(stat != 0) + }, + "lpSolveAPI" = { + out <- which(stat != 0) + }, + "cplexAPI" = { + # CPLEX: 101 optimal integer solution + # CPLEX: 102 Optimal solution with the tolerance defined by epgap or epagap + out <- which(stat != 1 & stat != 101 & stat != 102) + }, + { + cmd <- paste(solver,"::checkSolutionStatus(stat)", sep = "") + out <- tryCatch(eval(parse(text = cmd)), error = function(e) NA) + #warning("not a valid solver") + } + ) + return(out) +} + + +#------------------------------------------------------------------------------# + +getMeanReturn <- function(code, solver = SYBIL_SETTINGS("SOLVER")) { + + out <- FALSE + switch(solver, + "glpkAPI" = { + out <- glpkAPI::return_codeGLPK(code) + }, + "clpAPI" = { + out <- clpAPI::return_codeCLP(code) + }, + "lpSolveAPI" = { + out <- return_codeLPSOLVE(code) + }, + "cplexAPI" = { + out <- cplexAPI::return_codeCPLEX(code) + }, + { + cmd <- paste(solver,"::getReturnString(code)", sep = "") + out <- tryCatch(eval(parse(text = cmd)), + error = function(e) as.character(NA)) + #warning("not a valid solver") + } + ) + return(out) +} + + +#------------------------------------------------------------------------------# + +getMeanStatus <- function(code, + solver = SYBIL_SETTINGS("SOLVER"), env = NULL) { + out <- FALSE + switch(solver, + "glpkAPI" = { + out <- glpkAPI::status_codeGLPK(code) + }, + "clpAPI" = { + out <- clpAPI::status_codeCLP(code) + }, + "lpSolveAPI" = { + #out <- "see return code" + out <- getMeanReturn(code, solver) + }, + "cplexAPI" = { + if (is.null(env)) { + cenv <- cplexAPI::openEnvCPLEX() + } + else { + cenv <- env + } + out <- cplexAPI::status_codeCPLEX(cenv, code) + if (is.null(env)) { + cplexAPI::closeEnvCPLEX(cenv) + } + rm(cenv) + }, + { + cmd <- paste(solver,"::getStatusString(code)", sep = "") + out <- tryCatch(eval(parse(text = cmd)), + error = function(e) as.character(NA)) + #warning("not a valid solver") + } + ) + return(out) +} + + +#TIMEOUT <- "timeout" +#INFINITE <- "infinite" diff --git a/R/optObj_clpAPIClass.R b/R/optObj_clpAPIClass.R new file mode 100644 index 0000000..be6050b --- /dev/null +++ b/R/optObj_clpAPIClass.R @@ -0,0 +1,711 @@ +# optObj_clpAPIClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class optObj_clpAPI # +#------------------------------------------------------------------------------# + +setClass(Class = "optObj_clpAPI", contains = "optObj") + + +#------------------------------------------------------------------------------# +# methods # +#------------------------------------------------------------------------------# + +setMethod("delProb", signature(lp = "optObj_clpAPI"), + + function(lp, ...) { + + clpAPI::delProbCLP(lp@oobj) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("initProb", signature(lp = "optObj_clpAPI"), + + function(lp, to = NULL, ...) { + + lp@oobj <- clpAPI::initProbCLP() + + if (is.null(to)) { + clpAPI::setLogLevelCLP(lp@oobj, 0) + } + else { + stopifnot(is(to, "numeric")) + clpAPI::setLogLevelCLP(lp@oobj, to) + } + + return(lp) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("backupProb", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- FALSE + np <- FALSE + + fname <- tempfile(pattern = "CLP_PROB_", fileext = ".tmp") + ft <- clpAPI::saveModelCLP(lp@oobj, fname) + if (ft != 0) { + stop("cannot save model") + } + + # create new lp problem + np <- clpAPI::initProbCLP() + clpAPI::setLogLevelCLP(np, 0) + ft <- clpAPI::restoreModelCLP(np, fname) + if (ft != 0) { + stop("cannot read model") + } + else { + unlink(fname) + } + + # create new optObj object + if (!identical(np, FALSE)) { + out <- new("optObj_clpAPI", lp@solver, lp@method, lp@probType) + out@oobj <- np + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + + +setMethod("setSolverParm", signature(lp = "optObj_clpAPI"), + + function(lp, solverParm) { + + out <- FALSE + + wrong_solver_msg(lp, "setSolverParm") + +# if ( ! ((is.data.frame(solverParm)) || (is.list(solverParm))) ) { +# stop(sQuote(solverParm), " must be list or data.frame") +# } +# +# if (any(is.na(solverParm))) { +# stop(sQuote(solverParm), " contains NA values") +# } + + # no parameters in COIN-OR CLP yet. + # lp@oobj <- clpAPI::initProbCLP() + # clpAPI::setLogLevelCLP(lp@oobj, 0) + + return(out) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolverParm", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- FALSE + + wrong_solver_msg(lp, "getSolverParm") + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_clpAPI", lpdir = "character"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == "max", -1, 1) + clpAPI::setObjDirCLP(lp@oobj, dr) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_clpAPI", lpdir = "numeric"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == -1, -1, 1) + clpAPI::setObjDirCLP(lp@oobj, dr) + + } +) + +#------------------------------------------------------------------------------# + +setMethod("getObjDir", signature(lp = "optObj_clpAPI"), + + function(lp) { + + dr <- clpAPI::getObjDirCLP(lp@oobj) + if (dr == -1) { + out <- "max" + } + else if (dr == 1) { + out <- "min" + } + else { + out <- FALSE + } + return(out) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRows", signature(lp = "optObj_clpAPI", nrows = "numeric"), + + function(lp, nrows) { + + ncols <- clpAPI::getNumColsCLP(lp@oobj) + out <- clpAPI::resizeCLP(lp@oobj, nrows, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addCols", signature(lp = "optObj_clpAPI", ncols = "numeric"), + + function(lp, ncols) { + + nrows <- clpAPI::getNumRowsCLP(lp@oobj) + out <- clpAPI::resizeCLP(lp@oobj, nrows, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsCols", signature(lp = "optObj_clpAPI", + nrows = "numeric", ncols = "numeric"), + + function(lp, nrows, ncols) { + + out <- clpAPI::resizeCLP(lp@oobj, nrows, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumRows", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- clpAPI::getNumRowsCLP(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumCols", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- clpAPI::getNumColsCLP(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addColsToProb", signature(lp = "optObj_clpAPI"), + + # j: vector containing the new column indices (must be ascending) + # rind: list, containing the row indices of the new nz elements + # nzval: list, containing the new nz elements + # + # j, obj, lb, rind and nzval must have the same length + + function(lp, j, obj, lb, ub, rind, nzval) { + + cst <- c(0, cumsum(unlist(lapply(rind, length)))) + print(cst) + print(unlist(rind)-1) + print(unlist(nzval)) + out <- clpAPI::addColsCLP(lp@oobj, length(j), lb, ub, obj, + cst, unlist(rind)-1, unlist(nzval)) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsToProb", signature(lp = "optObj_clpAPI"), + + # i: vector containing the new row indices (must be ascending) + # cind: list, containing the column indices of the new nz elements + # nzval: list, containing the new nz elements + # + # i, type, lb, ub, cind and nzval must have the same length + # + # type can be one of the following: + # "F" = free variable -INF < x < INF + # "L" = variable with lower bound lb <= x < INF + # "U" = variable with upper bound -INF < x <= ub + # "D" = double-bounded variable lb <= x <= ub + # "E" = fixed variable lb = x = ub + + function(lp, i, type, lb, ub, cind, nzval, rnames = NULL) { + + stopifnot(length(lb) == length(ub)) + cub <- ub + ebc <- type == "E" + cub[ebc] <- lb[ebc] + + cst <- c(0, cumsum(unlist(lapply(cind, length)))) + + out <- clpAPI::addRowsCLP(lp@oobj, length(i), lb, cub, + cst, unlist(cind)-1, unlist(nzval)) + + #if (!is.null(rnames)) { + # for (rind in seq(along = i)) { + # clpAPI::rowNameCLP(lp@oobj, i = i[rind], rname = rnames[rind]) + # } + #} + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBnds", signature(lp = "optObj_clpAPI"), + + function(lp, j, lb, ub) { + + tmp_lb <- clpAPI::getColLowerCLP(lp@oobj) + tmp_ub <- clpAPI::getColUpperCLP(lp@oobj) + tmp_lb[j] <- lb + tmp_ub[j] <- ub + clpAPI::chgColLowerCLP(lp@oobj, tmp_lb) + clpAPI::chgColUpperCLP(lp@oobj, tmp_ub) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBndsObjCoefs", signature(lp = "optObj_clpAPI"), + + function(lp, j, lb, ub, obj_coef) { + + # usable only for model creation! + clpAPI::chgColLowerCLP(lp@oobj, lb) + clpAPI::chgColUpperCLP(lp@oobj, ub) + clpAPI::chgObjCoefsCLP(lp@oobj, obj_coef) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsLowBnds", signature(lp = "optObj_clpAPI", j = "numeric"), + + function(lp, j) { + + out <- clpAPI::getColLowerCLP(lp@oobj)[j] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsUppBnds", signature(lp = "optObj_clpAPI", j = "numeric"), + + function(lp, j) { + + out <- clpAPI::getColUpperCLP(lp@oobj)[j] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeRowsBnds", signature(lp = "optObj_clpAPI"), + + function(lp, i, lb, ub) { + + tmp_lb <- clpAPI::getRowLowerCLP(lp@oobj) + tmp_ub <- clpAPI::getRowUpperCLP(lp@oobj) + tmp_lb[i] <- lb + tmp_ub[i] <- ub + clpAPI::chgRowLowerCLP(lp@oobj, tmp_lb) + clpAPI::chgRowUpperCLP(lp@oobj, tmp_ub) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setRhsZero", signature(lp = "optObj_clpAPI"), + + function(lp) { + + nrows <- clpAPI::getNumRowsCLP(lp@oobj) + zeros <- rep(0, nrows) + clpAPI::chgRowLowerCLP(lp@oobj, zeros) + clpAPI::chgRowUpperCLP(lp@oobj, zeros) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsLowBnds", signature(lp = "optObj_clpAPI", i = "numeric"), + + function(lp, i) { + + out <- clpAPI::getRowLowerCLP(lp@oobj)[i] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsUppBnds", signature(lp = "optObj_clpAPI", i = "numeric"), + + function(lp, i) { + + out <- clpAPI::getRowUpperCLP(lp@oobj)[i] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeObjCoefs", signature(lp = "optObj_clpAPI"), + + function(lp, j, obj_coef) { + + tmp_obj_coef <- clpAPI::getObjCoefsCLP(lp@oobj) + tmp_obj_coef[j] <- obj_coef + clpAPI::chgObjCoefsCLP(lp@oobj, tmp_obj_coef) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjCoefs", signature(lp = "optObj_clpAPI", j = "numeric"), + + function(lp, j) { + + out <- clpAPI::getObjCoefsCLP(lp@oobj)[j] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("loadLPprob", signature(lp = "optObj_clpAPI"), + + function(lp, nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL, + defLowerBnd = SYBIL_SETTINGS("MAXIMUM") * -1, + defUpperBnd = SYBIL_SETTINGS("MAXIMUM")) { + + stopifnot(is(mat, "Matrix")) + + if (!is.null(ctype)) { + warning("argument ", sQuote(ctype), " is currently ignored") + } + + if (is.null(rub)) { + stopifnot(is(defLowerBnd, "numeric"), is(defUpperBnd, "numeric")) + ##crub <- numeric(nRows) + # Default value for upper bound is SYBIL_SETTINGS("MAXIMUM"). + + # If a constraint has an upper bound (type "U"), the corresponding + # value is copied from rlb to crub and crlb get's the default + # lower bound SYBIL_SETTINGS("MAXIMUM") * -1. + + # If a constraint is equality (type "E"), the corresponding + # value is copied from rlb to crub. + + crub <- rep(defUpperBnd, nRows) + crlb <- rlb + ubc <- rtype == "U" + crub[ubc] <- rlb[ubc] + crlb[ubc] <- defLowerBnd + ebc <- rtype == "E" + crub[ebc] <- rlb[ebc] + } + else { + stopifnot(length(rub) == length(rlb)) + crub <- rub + crlb <- rlb + ebc <- rtype == "E" + crub[ebc] <- crlb[ebc] + } + + # optimization direction + setObjDir(lp, lpdir = lpdir) + + # load problem + TMPmat <- as(mat, "CsparseMatrix") + clpAPI::loadProblemCLP(lp@oobj, + ncols = nCols, + nrows = nRows, + ia = TMPmat@i, + ja = TMPmat@p, + ra = TMPmat@x, + lb = lb, + ub = ub, + obj_coef = obj, + rlb = crlb, + rub = crub) + + # row and column names + if ( (!is.null(rnames)) && (!is.null(cnames)) ) { + clpAPI::copyNamesCLP(lp@oobj, cnames = cnames, rnames = rnames) + } + + # problem name + if (!is.null(rnames)) { + clpAPI::probNameCLP(lp@oobj, pname = pname) + } + } +) + + +#------------------------------------------------------------------------------# + +setMethod("scaleProb", signature(lp = "optObj_clpAPI"), + + function(lp, opt) { + + clpAPI::scaleModelCLP(lp@oobj, opt) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("solveLp", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- FALSE + switch(lp@method, + "inidual" = { + out <- clpAPI::solveInitialDualCLP(lp@oobj) + }, + "iniprimal" = { + out <- clpAPI::solveInitialPrimalCLP(lp@oobj) + }, + "inibarrier" = { + out <- clpAPI::solveInitialBarrierCLP(lp@oobj) + }, + "inibarriernoc" = { + out <- clpAPI::solveInitialBarrierNoCrossCLP(lp@oobj) + }, + "dual" = { + out <- clpAPI::dualCLP(lp@oobj) + }, + "primal" = { + out <- clpAPI::primalCLP(lp@oobj) + }, + "idiot" = { + clpAPI::idiotCLP(lp@oobj) # idiotCLP has no return value + out <- 0 + }, + { + out <- clpAPI::solveInitialCLP(lp@oobj) + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjVal", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- clpAPI::getObjValCLP(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRedCosts", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- clpAPI::getColDualCLP(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolStat", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- clpAPI::getSolStatusCLP(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getFluxDist", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- clpAPI::getColPrimCLP(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColPrim", signature(lp = "optObj_clpAPI", j = "numeric"), + + function(lp, j) { + + out <- clpAPI::getColPrimCLP(lp@oobj)[j] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumNnz", signature(lp = "optObj_clpAPI"), + + function(lp) { + + out <- clpAPI::getNumNnzCLP(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("writeProb", signature(lp = "optObj_clpAPI", fname = "character"), + + function(lp, fname, ff = "lp") { + + out <- clpAPI::saveModelCLP(lp@oobj, fname = fname) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("readProb", signature(lp = "optObj_clpAPI", fname = "character"), + + function(lp, fname, ff = "mps", ...) { + + switch(ff, + "mps" = { + fl <- clpAPI::readMPSCLP(lp@oobj, fname = fname, ...) + }, + "clp" = { + fl <- clpAPI::restoreModelCLP(lp@oobj, fname = fname) + }, + { + message("wrong format!") + fl <- 1 + } + ) + out <- ifelse(fl == 0, TRUE, fl) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + diff --git a/R/optObj_cplexAPIClass.R b/R/optObj_cplexAPIClass.R new file mode 100644 index 0000000..8f6d0ed --- /dev/null +++ b/R/optObj_cplexAPIClass.R @@ -0,0 +1,1154 @@ +# optObj_cplexAPIClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class optObj_cplexAPI # +#------------------------------------------------------------------------------# + +setClass(Class = "optObj_cplexAPI", contains = "optObj") + + +#------------------------------------------------------------------------------# +# methods # +#------------------------------------------------------------------------------# + +setMethod("delProb", signature(lp = "optObj_cplexAPI"), + + function(lp, closeEnv = TRUE) { + + if (isTRUE(closeEnv)) { + cplexAPI::closeProbCPLEX(list(env = lp@oobj@env, + lp = lp@oobj@lp)) + } else { + cplexAPI::delProbCPLEX(lp@oobj@env, lp@oobj@lp) + } + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("initProb", signature(lp = "optObj_cplexAPI"), + + function(lp, to = FALSE, ...) { + + #lp@oobj <- cplexAPI::openProbCPLEX() + tmp <- cplexAPI::openProbCPLEX() + lp@oobj <- new("cplexPointer", + en = tmp[["env"]], + pr = tmp[["lp"]]) + + if (is.null(to)) { + too <- FALSE + } + else { + too <- to + } + + if (isTRUE(too)) { + cplexAPI::setIntParmCPLEX(lp@oobj@env, + cplexAPI::CPX_PARAM_SCRIND, + cplexAPI::CPX_ON) + } + else { + cplexAPI::setIntParmCPLEX(lp@oobj@env, + cplexAPI::CPX_PARAM_SCRIND, + cplexAPI::CPX_OFF) + } + + return(lp) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("backupProb", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + out <- FALSE + np <- FALSE + + np <- cplexAPI::cloneProbCPLEX(lp@oobj@env, lp@oobj@lp) + + # create new optObj object + if (!identical(np, FALSE)) { + out <- new("optObj_cplexAPI", lp@solver, lp@method, lp@probType) + out@oobj <- new("cplexPointer", en = lp@oobj@env, pr = np) + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + + +setMethod("setSolverParm", signature(lp = "optObj_cplexAPI"), + + function(lp, solverParm) { + + out <- FALSE + + if ( ! ((is.data.frame(solverParm)) || (is.list(solverParm))) ) { + stop(sQuote(solverParm), " must be list or data.frame") + } + + if (any(is.na(solverParm))) { + stop(sQuote(solverParm), " contains NA values") + } + + intdbl <- sapply(solverParm, is.integer) + strparm <- sapply(solverParm, is.numeric) + int <- solverParm[intdbl] + dbl <- solverParm[intdbl == FALSE & strparm == TRUE] + char <- solverParm[strparm == FALSE] + + if (length(int) > 0) { + intp <- sapply(names(int), function(x) eval(parse(text = x))) + intv <- unlist(int) + for (i in seq(along = int)) { + out <- cplexAPI::setIntParmCPLEX(lp@oobj@env, intp[i], intv[i]) + } + } + + if (length(dbl) > 0) { + dblp <- sapply(names(dbl), function(x) eval(parse(text = x))) + dblv <- unlist(dbl) + for (i in seq(along = dbl)) { + out <- cplexAPI::setDblParmCPLEX(lp@oobj@env, dblp[i], dblv[i]) + } + } + + if (length(char) > 0) { + charp <- sapply(names(char), function(x) eval(parse(text = x))) + charv <- unlist(char) + for (i in seq(along = char)) { + out <- cplexAPI::setStrParmCPLEX(lp@oobj@env, + charp[i], charv[i]) + } + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolverParm", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + out <- cplexAPI::writeParmCPLEX(lp@oobj@env, + "cplex_parameters.prm") + message("Wrote the file 'cplex_parameters.prm'.") + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_cplexAPI", lpdir = "character"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == "max", + cplexAPI::CPX_MAX, + cplexAPI::CPX_MIN) + cplexAPI::setObjDirCPLEX(lp@oobj@env, lp@oobj@lp, dr) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_cplexAPI", lpdir = "integer"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == cplexAPI::CPX_MAX, + cplexAPI::CPX_MAX, + cplexAPI::CPX_MIN) + cplexAPI::setObjDirCPLEX(lp@oobj@env, lp@oobj@lp, dr) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_cplexAPI", lpdir = "numeric"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == -1, + cplexAPI::CPX_MAX, + cplexAPI::CPX_MIN) + cplexAPI::setObjDirCPLEX(lp@oobj@env, lp@oobj@lp, dr) + } +) + +#------------------------------------------------------------------------------# + +setMethod("getObjDir", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + dr <- cplexAPI::getObjDirCPLEX(lp@oobj@env, lp@oobj@lp) + if (dr == cplexAPI::CPX_MAX) { + out <- "max" + } + else if (dr == cplexAPI::CPX_MIN) { + out <- "min" + } + else { + out <- FALSE + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRows", signature(lp = "optObj_cplexAPI", nrows = "numeric"), + + function(lp, nrows) { + + out <- cplexAPI::newRowsCPLEX(lp@oobj@env, lp@oobj@lp, nrows) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addCols", signature(lp = "optObj_cplexAPI", ncols = "numeric"), + + function(lp, ncols) { + + out <- cplexAPI::newColsCPLEX(lp@oobj@env, lp@oobj@lp, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsCols", signature(lp = "optObj_cplexAPI", + nrows = "numeric", ncols = "numeric"), + + function(lp, nrows, ncols) { + + outi <- cplexAPI::newRowsCPLEX(lp@oobj@env, lp@oobj@lp, nrows) + outj <- cplexAPI::newColsCPLEX(lp@oobj@env, lp@oobj@lp, ncols) + out <- c(outi, outj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumRows", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + out <- cplexAPI::getNumRowsCPLEX(lp@oobj@env, lp@oobj@lp) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumCols", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + out <- cplexAPI::getNumColsCPLEX(lp@oobj@env, lp@oobj@lp) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addColsToProb", signature(lp = "optObj_cplexAPI"), + + # j: vector containing the new column indices (must be ascending) + # rind: list, containing the row indices of the new nz elements + # nzval: list, containing the new nz elements + # + # j, obj, lb, rind and nzval must have the same length + + function(lp, j, obj, lb, ub, rind, nzval) { + + beg <- c(0, cumsum(unlist(lapply(rind, length)))) + out <- cplexAPI::addColsCPLEX(lp@oobj@env, lp@oobj@lp, + length(j), length(unlist(nzval)), obj, + beg, unlist(rind)-1, unlist(nzval), + lb, ub) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +#setMethod("addRowsToProb", signature(lp = "optObj_cplexAPI"), +# +# # i: vector containing the new row indices (must be ascending) +# # cind: list, containing the column indices of the new nz elements +# # nzval: list, containing the new nz elements +# # +# # i, type, lb, cind and nzval must have the same length +# # +# # type can be one of the following: +# # "F" = free variable -INF < x < INF +# # "L" = variable with lower bound lb <= x < INF +# # "U" = variable with upper bound -INF < x <= ub +# # "D" = double-bounded variable lb <= x <= ub +# # "E" = fixed variable lb = x = ub +# # "R" = ranged constraint +# +# function(lp, i, type, lb, ub, cind, nzval, rnames = NULL) { +# +# cptype = character(length(type)) +# for (l in seq(along = type)) { +# cptype[l] <- switch(type[l], +# "L" = { "G" }, +# "U" = { "L" }, +# "E" = { "E" }, +# "R" = { "R" }, +# { "E" } +# ) +# } +# +# beg <- c(0, cumsum(unlist(lapply(cind, length)))) +# out <- cplexAPI::addRowsCPLEX(env = lp@oobj@env, lp = lp@oobj@lp, +# ncols = 0, nrows = length(i), +# nnz = length(unlist(nzval)), +# matbeg = beg, matind = unlist(cind)-1, +# matval = unlist(nzval), rhs = lb, +# sense = cptype, rnames = rnames) +# +# return(out) +# } +#) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsToProb", signature(lp = "optObj_cplexAPI"), + + # i: vector containing the new row indices (must be ascending) + # cind: list, containing the column indices of the new nz elements + # nzval: list, containing the new nz elements + # + # i, type, lb, ub, cind and nzval must have the same length + # + # type can be one of the following: + # "F" = free variable -INF < x < INF + # "L" = variable with lower bound lb <= x < INF + # "U" = variable with upper bound -INF < x <= ub + # "D" = double-bounded variable lb <= x <= ub + # "E" = fixed variable lb = x = ub + + function(lp, i, type, lb, ub, cind, nzval, rnames = NULL) { + + cptype = character(length(type)) + for (l in seq(along = type)) { + cptype[l] <- switch(type[l], + "L" = { "G" }, + "U" = { "L" }, + "D" = { "R" }, + "E" = { "E" }, + { "E" } + ) + } + + stopifnot(length(lb) == length(ub)) + rng <- cptype == "R" + cub <- abs(ub[rng] - lb[rng]) # range + + ubc <- cptype == "L" + clb <- lb + clb[ubc] <- ub[ubc] + + beg <- c(0, cumsum(unlist(lapply(cind, length)))) + out <- cplexAPI::addRowsCPLEX(env = lp@oobj@env, lp = lp@oobj@lp, + ncols = 0, nrows = length(i), + nnz = length(unlist(nzval)), + matbeg = beg, matind = unlist(cind)-1, + matval = unlist(nzval), rhs = clb, + sense = cptype, rnames = rnames) + + # set ranged (double bounded constraints) + if (sum(rng) > 0) { + #print(i[rng]) + cplexAPI::chgRngValCPLEX(env = lp@oobj@env, lp = lp@oobj@lp, + nrows = sum(rng), + ind = i[rng]-1, + val = cub) + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBnds", signature(lp = "optObj_cplexAPI"), + + function(lp, j, lb, ub) { + + out <- cplexAPI::chgColsBndsCPLEX(lp@oobj@env, + lp@oobj@lp, j-1, lb, ub) + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBndsObjCoefs", signature(lp = "optObj_cplexAPI"), + + function(lp, j, lb, ub, obj_coef) { + + outb <- cplexAPI::chgColsBndsCPLEX(lp@oobj@env, + lp@oobj@lp, j-1, lb, ub) + outo <- cplexAPI::chgObjCPLEX(lp@oobj@env, lp@oobj@lp, + length(j), j-1, obj_coef) + out <- c(outb, outo) + # usable only for model creation! + # out <- cplexAPI::newColsCPLEX(lp@oobj@env, lp@oobj@lp, + # length(j), obj_coef, lb, ub) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsLowBnds", signature(lp = "optObj_cplexAPI", j = "numeric"), + + function(lp, j) { + + out <- cplexAPI::getLowBndsIdsCPLEX(lp@oobj@env, lp@oobj@lp, j-1) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsUppBnds", signature(lp = "optObj_cplexAPI", j = "numeric"), + + function(lp, j) { + + out <- cplexAPI::getUppBndsIdsCPLEX(lp@oobj@env, lp@oobj@lp, j-1) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeRowsBnds", signature(lp = "optObj_cplexAPI"), + + function(lp, i, lb, ub) { + +# out <- cplexAPI::chgRhsCPLEX(lp@oobj@env, lp@oobj@lp, +# length(i), i-1, lb) + + stopifnot(length(lb) == length(ub)) + clb <- lb + + ct <- mapply(cplexAPI::getSenseCPLEX, i-1, i-1, + MoreArgs = list(env = lp@oobj@env, lp = lp@oobj@lp)) + + # If a constraint is a ranged constraint, the range is build as ub - lb. + # For a constraint with an upper bound ('lower than'), the bound in rb + # is used. For equality constraints, lb is used. + + rng <- ct == "R" + lbc <- ct == "L" + clb[lbc] <- ub[lbc] + + out <- cplexAPI::chgRhsCPLEX(lp@oobj@env, lp@oobj@lp, + length(i), i-1, clb) + + if (sum(rng) > 0) { + rngv <- abs(ub[rng] - lb[rng]) + out <- chgRngValCPLEX(lp@oobj@env, lp@oobj@lp, + sum(rng), i[rng]-1, rngv) + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setRhsZero", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + nrows <- cplexAPI::getNumRowsCPLEX(lp@oobj@env, lp@oobj@lp) + zeros <- rep(0, nrows) + indic <- c(0:(nrows-1)) + outb <- cplexAPI::chgRhsCPLEX(lp@oobj@env, lp@oobj@lp, + nrows, indic, zeros) + outt <- cplexAPI::chgSenseCPLEX(lp@oobj@env, lp@oobj@lp, + nrows, indic, rep("E", nrows)) + out <- c(outb, outt) + # usable only for model creation! + # ( Variable nrows has to be argument of setRhsZero()! ) + # out <- cplexAPI::newRowsCPLEX(lp@oobj@env, lp@oobj@lp, nrows, + # rep(0, nrows), rep("E", nrows)) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsLowBnds", signature(lp = "optObj_cplexAPI", i = "numeric"), + + function(lp, i) { + + wrong_solver_msg(lp, "getRowsLowBnds", printOut = TRUE) + return(FALSE) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsUppBnds", signature(lp = "optObj_cplexAPI", i = "numeric"), + + function(lp, i) { + + wrong_solver_msg(lp, "getRowsUppBnds", printOut = TRUE) + return(FALSE) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeObjCoefs", signature(lp = "optObj_cplexAPI"), + + function(lp, j, obj_coef) { + + out <- cplexAPI::chgObjCPLEX(lp@oobj@env, lp@oobj@lp, + length(j), j-1, obj_coef) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjCoefs", signature(lp = "optObj_cplexAPI", j = "numeric"), + + function(lp, j) { + + if (length(j) > 1) { + b <- min(j) - 1 + e <- max(j) - 1 + } + else { + b <- j - 1 + e <- j - 1 + } + out <- cplexAPI::getObjCPLEX(lp@oobj@env, lp@oobj@lp, b, e) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeMatrixRow", signature(lp = "optObj_cplexAPI"), + + function(lp, i, j, val) { + + cplexAPI::chgCoefListCPLEX(lp@oobj@env, lp@oobj@lp, + length(val), rep(i-1, length(val)), j-1, val) + + } +) + + +#------------------------------------------------------------------------------# + +#setMethod("loadLPprob", signature(lp = "optObj_cplexAPI"), +# +# function(lp, nCols, nRows, mat, ub, lb, obj, rlb, rtype, +# lpdir = "max", rub = NULL, ctype = NULL, +# cnames = NULL, rnames = NULL) { +# +# stopifnot(is(mat, "Matrix")) +# +# crtype <- sapply(rtype, +# function(x) switch(x, +# "L" = { "G" }, +# "U" = { "L" }, +# "E" = { "E" }, +# "R" = { "R" }, +# { "E" })) +# +# # ranged constraints +# if (is.null(rub)) { +# crub <- NULL +# } +# else { +# #rng <- rtype == "R" +# rng <- rtype %in% "R" +# crub <- numeric(nRows) +# crub[rng] <- rlb[rng] - rlb[rng] +# crub[!rng] <- 0 +# } +# +## +## # problem type +## ptype <- switch(lp@probType, +## "lp" = { CPXPROB_LP }, +## "mip" = { CPXPROB_MILP }, +## { CPXPROB_LP } +## ) +## cplexAPI::chgProbTypeCPLEX(lp@oobj@env, lp@oobj@lp, ptype) +# +# +## +## # load problem +## TMPmat <- as(mat, "CsparseMatrix") +## cplexAPI::copyLpCPLEX(lp@oobj@env, lp@oobj@lp, +## nCols = nCols, +## nRows = nRows, +## lpdir = ifelse(lpdir == "max", +## cplexAPI::CPX_MAX, +## cplexAPI::CPX_MIN), +## objf = obj, +## rhs = rlb, +## sense = crtype, +## matbeg = TMPmat@p, +## matcnt = colSums(mat != 0), +## matind = TMPmat@i, +## matval = TMPmat@x, +## lb = lb, +## ub = ub, +## rngval = crub) +## +## if (!is.null(ctype)) { +## cplexAPI::chgColTypeCPLEX(lp@oobj@env, lp@oobj@lp, +## ncols = nCols, +## ind = c(1:nCols), +## xctype = ctype) +## } +## +# +# # optimization direction +# setObjDir(lp, lpdir = lpdir) +# +# # constraints and right hand side +# cplexAPI::newRowsCPLEX(lp@oobj@env, lp@oobj@lp, +# nrows = nRows, +# rhs = rlb, +# sense = crtype, +# rngval = crub, +# rnames = rnames) +# +# # variables, bounds and objective function +# cplexAPI::newColsCPLEX(lp@oobj@env, lp@oobj@lp, +# ncols = nCols, +# obj = obj, +# lb = lb, +# ub = ub, +# cnames = cnames) +# +# # constraint matrix +# TMPmat <- as(mat, "TsparseMatrix") +# cplexAPI::chgCoefListCPLEX(lp@oobj@env, lp@oobj@lp, +# nnz = length(TMPmat@x), +# ia = TMPmat@i, +# ja = TMPmat@j, +# ra = TMPmat@x) +# +# if (!is.null(ctype)) { +# cplexAPI::copyColTypeCPLEX(lp@oobj@env, lp@oobj@lp, +# xctype = ctype) +# } +# } +#) + + +#------------------------------------------------------------------------------# + +setMethod("loadLPprob", signature(lp = "optObj_cplexAPI"), + + function(lp, nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL) { + + stopifnot(is(mat, "Matrix")) + + crtype <- sapply(rtype, + function(x) switch(x, + "L" = { "G" }, + "U" = { "L" }, + "D" = { "R" }, + "E" = { "E" }, + { "E" })) + + # ranged constraints + if (is.null(rub)) { + crub <- NULL + crlb <- rlb + } + else { + # CPLEX only has a right-hand-side (rhs) and a so called range value + # for reanged constraints. The value in rub is used to calculate the + # range value (if required). + # Range for constraint i is abs(rub[i] - rlb[i]) The interval for + # constraint i then is [ rlb[i] , rlb[i] + range ] . + # For constraints with an upper bound, the value in rub is copied + # to rlb. + + stopifnot(length(rlb) == length(rub)) + rng <- crtype == "R" + crub <- numeric(nRows) + crub[rng] <- abs(rub[rng] - rlb[rng]) # range + + ubc <- crtype == "L" + crlb <- rlb + crlb[ubc] <- rub[ubc] + } + +# +# # problem type +# ptype <- switch(lp@probType, +# "lp" = { CPXPROB_LP }, +# "mip" = { CPXPROB_MILP }, +# { CPXPROB_LP } +# ) +# cplexAPI::chgProbTypeCPLEX(lp@oobj@env, lp@oobj@lp, ptype) + + +# +# # load problem +# TMPmat <- as(mat, "CsparseMatrix") +# cplexAPI::copyLpCPLEX(lp@oobj@env, lp@oobj@lp, +# nCols = nCols, +# nRows = nRows, +# lpdir = ifelse(lpdir == "max", +# cplexAPI::CPX_MAX, +# cplexAPI::CPX_MIN), +# objf = obj, +# rhs = rlb, +# sense = crtype, +# matbeg = TMPmat@p, +# matcnt = colSums(mat != 0), +# matind = TMPmat@i, +# matval = TMPmat@x, +# lb = lb, +# ub = ub, +# rngval = crub) +# +# if (!is.null(ctype)) { +# cplexAPI::chgColTypeCPLEX(lp@oobj@env, lp@oobj@lp, +# ncols = nCols, +# ind = c(1:nCols), +# xctype = ctype) +# } +# + + # optimization direction + setObjDir(lp, lpdir = lpdir) + + # constraints and right hand side + cplexAPI::newRowsCPLEX(lp@oobj@env, lp@oobj@lp, + nrows = nRows, + rhs = crlb, + sense = crtype, + rngval = crub, + rnames = rnames) + + # variables, bounds and objective function + cplexAPI::newColsCPLEX(lp@oobj@env, lp@oobj@lp, + ncols = nCols, + obj = obj, + lb = lb, + ub = ub, + cnames = cnames) + + # constraint matrix + TMPmat <- as(mat, "TsparseMatrix") + cplexAPI::chgCoefListCPLEX(lp@oobj@env, lp@oobj@lp, + nnz = length(TMPmat@x), + ia = TMPmat@i, + ja = TMPmat@j, + ra = TMPmat@x) + + if (!is.null(ctype)) { + cplexAPI::copyColTypeCPLEX(lp@oobj@env, lp@oobj@lp, + xctype = ctype) + } + + # problem name + if (!is.null(pname)) { + cplexAPI::chgProbNameCPLEX(lp@oobj@env, lp@oobj@lp, + probname = pname) + } + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("loadQobj", signature(lp = "optObj_cplexAPI", mat = "Matrix"), + + function(lp, mat) { + + TMPmat <- as(mat, "CsparseMatrix") + cplexAPI::copyQuadCPLEX(lp@oobj@env, lp@oobj@lp, + qmatbeg = TMPmat@p, + qmatcnt = colSums(mat != 0), + qmatind = TMPmat@i, + qmatval = TMPmat@x) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("loadQobj", signature(lp = "optObj_cplexAPI", mat = "numeric"), + + function(lp, mat) { + + cplexAPI::copyQPsepCPLEX(lp@oobj@env, lp@oobj@lp, qsepvec = mat) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("scaleProb", signature(lp = "optObj_cplexAPI"), + + function(lp, opt) { + + out <- cplexAPI::setIntParmCPLEX(lp@oobj@env, + cplexAPI::CPX_PARAM_REDUCE, + opt) + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("solveLp", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + out <- FALSE + switch(lp@method, + "primopt" = { + out <- cplexAPI::primoptCPLEX(lp@oobj@env, lp@oobj@lp) + }, + "dualopt" = { + out <- cplexAPI::dualoptCPLEX(lp@oobj@env, lp@oobj@lp) + }, + "baropt" = { + out <- cplexAPI::baroptCPLEX(lp@oobj@env, lp@oobj@lp) + }, + "hybbaropt" = { + out <- cplexAPI::hybbaroptCPLEX(lp@oobj@env, lp@oobj@lp, + method = 0) + }, + "hybnetopt" = { + out <- cplexAPI::hybnetoptCPLEX(lp@oobj@env, lp@oobj@lp, + method = cplexAPI::CPX_ALG_PRIMAL) + }, + "siftopt" = { + out <- cplexAPI::siftoptCPLEX(lp@oobj@env, lp@oobj@lp) + }, + "mipopt" = { + out <- cplexAPI::mipoptCPLEX(lp@oobj@env, lp@oobj@lp) + }, + "qpopt" = { + out <- cplexAPI::qpoptCPLEX(lp@oobj@env, lp@oobj@lp) + }, + { + out <- cplexAPI::lpoptCPLEX(lp@oobj@env, lp@oobj@lp) + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjVal", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + obj <- cplexAPI::getObjValCPLEX(lp@oobj@env, lp@oobj@lp) + + if (is(obj, "cplexError")) { + if (probType(lp) == "mip") { + out <- cplexAPI::getBestObjValCPLEX(lp@oobj@env, lp@oobj@lp) + } + else { + out <- as.numeric(NA) + #out <- 0 + } + } + else { + out <- obj + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRedCosts", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + nr <- cplexAPI::getNumRowsCPLEX(lp@oobj@env, lp@oobj@lp) + out <- cplexAPI::getDjCPLEX(lp@oobj@env, lp@oobj@lp, 0, nr-1) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolStat", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + out <- cplexAPI::getStatCPLEX(lp@oobj@env, lp@oobj@lp) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getFluxDist", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + ncols <- cplexAPI::getNumColsCPLEX(lp@oobj@env, lp@oobj@lp) + fluxd <- cplexAPI::getProbVarCPLEX(lp@oobj@env, lp@oobj@lp, 0, ncols-1) + + if (is(fluxd, "cplexError")) { + out <- numeric(ncols) + } + else { + out <- fluxd + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColPrim", signature(lp = "optObj_cplexAPI", j = "numeric"), + + function(lp, j) { + + out <- cplexAPI::getProbVarCPLEX(lp@oobj@env, lp@oobj@lp, j-1, j-1) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumNnz", signature(lp = "optObj_cplexAPI"), + + function(lp) { + + out <- cplexAPI::getNumNnzCPLEX(lp@oobj@env, lp@oobj@lp) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("writeProb", signature(lp = "optObj_cplexAPI", fname = "character"), + + function(lp, fname, ff = "lp") { + + tp <- ifelse(is.null(ff), NULL, toupper(ff)) + fl <- cplexAPI::writeProbCPLEX(lp@oobj@env, lp@oobj@lp, + fname = fname, ftype = tp) + out <- ifelse(fl == 0, TRUE, fl) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("readProb", signature(lp = "optObj_cplexAPI", fname = "character"), + + function(lp, fname, ff = "lp") { + + tp <- ifelse(is.null(ff), NULL, toupper(ff)) + fl <- cplexAPI::readCopyProbCPLEX(lp@oobj@env, lp@oobj@lp, + fname = fname, ftype = tp) + out <- ifelse(fl == 0, TRUE, fl) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("sensitivityAnalysis", signature(lp = "optObj_cplexAPI"), + + function(lp, ...) { + + # number of columns and rows + nc <- cplexAPI::getNumColsCPLEX(lp@oobj@env, lp@oobj@lp) + nr <- cplexAPI::getNumRowsCPLEX(lp@oobj@env, lp@oobj@lp) + + out <- vector(mode = "list", length = 3) + names(out) <- c("bound", "obj", "rhs") + + out[["bound"]] <- cplexAPI::boundSaCPLEX(lp@oobj@env, + lp@oobj@lp, 0, nc-1) + out[["obj"]] <- cplexAPI::objSaCPLEX(lp@oobj@env, + lp@oobj@lp, 0, nc-1) + out[["rhs"]] <- cplexAPI::rhsSaCPLEX(lp@oobj@env, + lp@oobj@lp, 0, nr-1) + + return(out) + } +) + +#------------------------------------------------------------------------------# + + +setMethod("setRowsNames", signature(lp = "optObj_cplexAPI", + i = "numeric", names = "character"), + + function(lp, i, names) { + + invisible(cplexAPI::chgRowNameCPLEX(lp@oobj@env, lp@oobj@lp, + length(i), i-1, names)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setColsNames", signature(lp = "optObj_cplexAPI", + j = "numeric", names = "character"), + + function(lp, j, names) { + + invisible(cplexAPI::chgColNameCPLEX(lp@oobj@env, lp@oobj@lp, + length(j), j-1, names)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsNames", signature(lp = "optObj_cplexAPI", i = "numeric"), + + function(lp, i) { + + rn <- mapply(cplexAPI::getRowNameCPLEX, begin = i-1, end = i-1, + MoreArgs = list(env = lp@oobj@env, lp = lp@oobj@lp), + SIMPLIFY = TRUE, USE.NAMES = FALSE) + return(unlist(rn)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsNames", signature(lp = "optObj_cplexAPI", j = "numeric"), + + function(lp, j) { + + cn <- mapply(cplexAPI::getColNameCPLEX, begin = j-1, end = j-1, + MoreArgs = list(env = lp@oobj@env, lp = lp@oobj@lp), + SIMPLIFY = TRUE, USE.NAMES = FALSE) + return(unlist(cn)) + + } +) + + +#------------------------------------------------------------------------------# + diff --git a/R/optObj_glpkAPIClass.R b/R/optObj_glpkAPIClass.R new file mode 100644 index 0000000..325f47e --- /dev/null +++ b/R/optObj_glpkAPIClass.R @@ -0,0 +1,965 @@ +# optObj_glpkAPIClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class optObj_glpkAPI # +#------------------------------------------------------------------------------# + +setClass(Class = "optObj_glpkAPI", contains = "optObj") + + +#------------------------------------------------------------------------------# +# methods # +#------------------------------------------------------------------------------# + +setMethod("delProb", signature(lp = "optObj_glpkAPI"), + + function(lp, ...) { + + glpkAPI::delProbGLPK(lp@oobj) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("initProb", signature(lp = "optObj_glpkAPI"), + + function(lp, to = FALSE, ...) { + + lp@oobj <- glpkAPI::initProbGLPK() + + if (is.null(to)) { + too <- FALSE + } + else { + too <- to + } + + if (isTRUE(too)) { + glpkAPI::termOutGLPK(glpkAPI::GLP_ON) + } + else { + glpkAPI::termOutGLPK(glpkAPI::GLP_OFF) + } + + return(lp) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("backupProb", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + out <- FALSE + np <- FALSE + + # reset parameters!!! Parameters are reset to default when + # doing initProbGLPK() !!! + np <- glpkAPI::initProbGLPK() + glpkAPI::copyProbGLPK(lp@oobj, np) + + # create new optObj object + if (!identical(np, FALSE)) { + out <- new("optObj_glpkAPI", lp@solver, lp@method, lp@probType) + out@oobj <- np + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setSolverParm", signature(lp = "optObj_glpkAPI"), + + function(lp, solverParm) { + + if ( ! ((is.data.frame(solverParm)) || (is.list(solverParm))) ) { + stop(sQuote(solverParm), " must be list or data.frame") + } + + if (any(is.na(solverParm))) { + stop(sQuote(solverParm), " contains NA values") + } + + parm <- sapply(names(solverParm), function(x) eval(parse(text = x))) + val <- unlist(solverParm) + + switch(lp@method, + "interior" = { + glpkAPI::setInteriorParmGLPK(parm, val) + }, + "mip" = { + glpkAPI::setMIPParmGLPK(parm, val) + }, + { + glpkAPI::setSimplexParmGLPK(parm, val) + } + ) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolverParm", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + out <- FALSE + + switch(lp@method, + "interior" = { + out <- glpkAPI::getInteriorParmGLPK() + }, + "mip" = { + out <- glpkAPI::getMIPParmGLPK() + }, + { + out <- glpkAPI::getSimplexParmGLPK() + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_glpkAPI", lpdir = "character"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == "max", glpkAPI::GLP_MAX, glpkAPI::GLP_MIN) + glpkAPI::setObjDirGLPK(lp@oobj, dr) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_glpkAPI", lpdir = "integer"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == glpkAPI::GLP_MAX, + glpkAPI::GLP_MAX, + glpkAPI::GLP_MIN) + glpkAPI::setObjDirGLPK(lp@oobj, dr) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_glpkAPI", lpdir = "numeric"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == -1, + glpkAPI::GLP_MAX, + glpkAPI::GLP_MIN) + glpkAPI::setObjDirGLPK(lp@oobj, dr) + } +) + +#------------------------------------------------------------------------------# + +setMethod("getObjDir", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + dr <- glpkAPI::getObjDirGLPK(lp@oobj) + if (dr == glpkAPI::GLP_MAX) { + out <- "max" + } + else if (dr == glpkAPI::GLP_MIN) { + out <- "min" + } + else { + out <- FALSE + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRows", signature(lp = "optObj_glpkAPI", nrows = "numeric"), + + function(lp, nrows) { + + out <- glpkAPI::addRowsGLPK(lp@oobj, nrows) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addCols", signature(lp = "optObj_glpkAPI", ncols = "numeric"), + + function(lp, ncols) { + + out <- glpkAPI::addColsGLPK(lp@oobj, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsCols", signature(lp = "optObj_glpkAPI", + nrows = "numeric", ncols = "numeric"), + + function(lp, nrows, ncols) { + + outi <- glpkAPI::addRowsGLPK(lp@oobj, nrows) + outj <- glpkAPI::addColsGLPK(lp@oobj, ncols) + out <- all(outi, outj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumRows", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + out <- glpkAPI::getNumRowsGLPK(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumCols", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + out <- glpkAPI::getNumColsGLPK(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addColsToProb", signature(lp = "optObj_glpkAPI"), + + # j: vector containing the new column indices (must be ascending) + # rind: list, containing the row indices of the new nz elements + # nzval: list, containing the new nz elements + # + # j, obj, lb, rind and nzval must have the same length + + function(lp, j, obj, lb, ub, rind, nzval) { + + ord <- glpkAPI::addColsGLPK(lp@oobj, length(j)) + for (k in seq(along = j)) { + glpkAPI::setMatColGLPK(lp@oobj, j[k], + length(rind[[k]]), + rind[[k]], nzval[[k]]) + } + out <- glpkAPI::setColsBndsGLPK(lp@oobj, j, lb, ub) + out <- glpkAPI::setObjCoefsGLPK(lp@oobj, j, obj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsToProb", signature(lp = "optObj_glpkAPI"), + + # i: vector containing the new row indices (must be ascending) + # cind: list, containing the column indices of the new nz elements + # nzval: list, containing the new nz elements + # + # i, type, lb, ub, cind and nzval must have the same length + # + # type can be one of the following: + # "F" = free variable -INF < x < INF + # "L" = variable with lower bound lb <= x < INF + # "U" = variable with upper bound -INF < x <= ub + # "D" = double-bounded variable lb <= x <= ub + # "E" = fixed variable lb = x = ub + + function(lp, i, type, lb, ub, cind, nzval, rnames = NULL) { + + ord <- glpkAPI::addRowsGLPK(lp@oobj, length(i)) + gtype = integer(length(type)) + for (k in seq(along = i)) { + gtype[k] <- switch(type[k], + "F" = { glpkAPI::GLP_FR }, + "L" = { glpkAPI::GLP_LO }, + "U" = { glpkAPI::GLP_UP }, + "D" = { glpkAPI::GLP_DB }, + "E" = { glpkAPI::GLP_FX }, + { glpkAPI::GLP_FX } + ) + glpkAPI::setMatRowGLPK(lp@oobj, i[k], + length(cind[[k]]), + cind[[k]], nzval[[k]]) + } + stopifnot(length(lb) == length(ub)) + out <- glpkAPI::setRowsBndsGLPK(lp@oobj, i, lb, ub, gtype) + + # row names + if (!is.null(rnames)) { + glpkAPI::setRowsNamesGLPK(lp@oobj, i = i, rnames = rnames) + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBnds", signature(lp = "optObj_glpkAPI"), + + function(lp, j, lb, ub) { + + glpkAPI::setColsBndsGLPK(lp@oobj, j, lb, ub) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBndsObjCoefs", signature(lp = "optObj_glpkAPI"), + + function(lp, j, lb, ub, obj_coef) { + + glpkAPI::setColsBndsObjCoefsGLPK(lp@oobj, j, lb, ub, obj_coef) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsLowBnds", signature(lp = "optObj_glpkAPI", j = "numeric"), + + function(lp, j) { + + out <- glpkAPI::getColsLowBndsGLPK(lp@oobj, j) + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsUppBnds", signature(lp = "optObj_glpkAPI", j = "numeric"), + + function(lp, j) { + + out <- glpkAPI::getColsUppBndsGLPK(lp@oobj, j) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeRowsBnds", signature(lp = "optObj_glpkAPI"), + + function(lp, i, lb, ub) { + + ct <- glpkAPI::getRowsTypesGLPK(lp@oobj, i) + glpkAPI::setRowsBndsGLPK(lp@oobj, i, lb, ub, type = ct) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setRhsZero", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + glpkAPI::setRhsZeroGLPK(lp@oobj) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsLowBnds", signature(lp = "optObj_glpkAPI", i = "numeric"), + + function(lp, i) { + + out <- glpkAPI::getRowsLowBndsGLPK(lp@oobj, i) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsUppBnds", signature(lp = "optObj_glpkAPI", i = "numeric"), + + function(lp, i) { + + out <- glpkAPI::getRowsUppBndsGLPK(lp@oobj, i) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeObjCoefs", signature(lp = "optObj_glpkAPI"), + + function(lp, j, obj_coef) { + + glpkAPI::setObjCoefsGLPK(lp@oobj, j, obj_coef) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjCoefs", signature(lp = "optObj_glpkAPI", j = "numeric"), + + function(lp, j) { + + out <- glpkAPI::getObjCoefsGLPK(lp@oobj, j) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeMatrixRow", signature(lp = "optObj_glpkAPI"), + + function(lp, i, j, val) { + + glpkAPI::setMatRowGLPK(lp@oobj, i, length(val), j, val) + + } +) + + +#------------------------------------------------------------------------------# + +#setMethod("loadLPprob", signature(lp = "optObj_glpkAPI"), +# +# function(lp, nCols, nRows, mat, ub, lb, obj, rlb, rtype, +# lpdir = "max", rub = NULL, ctype = NULL, +# cnames = NULL, rnames = NULL) { +# +# stopifnot(is(mat, "Matrix")) +# +# crtype <- sapply(rtype, +# function(x) switch(x, +# "F" = { glpkAPI::GLP_FR }, +# "L" = { glpkAPI::GLP_LO }, +# "U" = { glpkAPI::GLP_UP }, +# "D" = { glpkAPI::GLP_DB }, +# "E" = { glpkAPI::GLP_FX }, +# { glpkAPI::GLP_FX })) +# +# # optimization direction +# setObjDir(lp, lpdir = lpdir) +# +# # problem dimensions +# glpkAPI::addColsGLPK(lp@oobj, ncols = nCols) +# glpkAPI::addRowsGLPK(lp@oobj, nrows = nRows) +# +# # constraint matrix +# TMPmat <- as(mat, "TsparseMatrix") +# glpkAPI::loadMatrixGLPK(lp@oobj, +# ne = length(TMPmat@x), +# ia = TMPmat@i + 1, +# ja = TMPmat@j + 1, +# ra = TMPmat@x) +# +# # column (variable) bounds and objective function +# glpkAPI::setColsBndsObjCoefsGLPK(lp@oobj, +# j = c(1:nCols), +# lb = lb, +# ub = ub, +# obj_coef = obj) +# +# # variable type +# if (!is.null(ctype)) { +# cctype <- sapply(ctype, +# function(x) switch(x, +# "C" = { glpkAPI::GLP_CV }, +# "I" = { glpkAPI::GLP_IV }, +# "B" = { glpkAPI::GLP_BV }, +# { glpkAPI::GLP_CV })) +# +# glpkAPI::setColsKindGLPK(lp@oobj, j = c(1:nCols), kind = cctype) +# } +# +# # right hand side +# glpkAPI::setRowsBndsGLPK(lp@oobj, +# i = c(1:nRows), +# lb = rlb, +# ub = rub, +# type = crtype) +# +# # row names +# if (!is.null(rnames)) { +# glpkAPI::setRowsNamesGLPK(lp@oobj, i = c(1:nRows), rnames = rnames) +# } +# +# # column names +# if (!is.null(cnames)) { +# glpkAPI::setColsNamesGLPK(lp@oobj, j = c(1:nCols), cnames = cnames) +# } +# +# if (!is.null(rnames) || !is.null(cnames)) { +# glpkAPI::createIndexGLPK(lp@oobj) +# } +# } +#) + + +#------------------------------------------------------------------------------# + +setMethod("loadLPprob", signature(lp = "optObj_glpkAPI"), + + function(lp, nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL) { + + stopifnot(is(mat, "Matrix")) + + crtype <- sapply(rtype, + function(x) switch(x, + "F" = { glpkAPI::GLP_FR }, + "L" = { glpkAPI::GLP_LO }, + "U" = { glpkAPI::GLP_UP }, + "D" = { glpkAPI::GLP_DB }, + "E" = { glpkAPI::GLP_FX }, + { glpkAPI::GLP_FX })) + + + # optimization direction + setObjDir(lp, lpdir = lpdir) + + # problem dimensions + glpkAPI::addColsGLPK(lp@oobj, ncols = nCols) + glpkAPI::addRowsGLPK(lp@oobj, nrows = nRows) + + # constraint matrix + TMPmat <- as(mat, "TsparseMatrix") + glpkAPI::loadMatrixGLPK(lp@oobj, + ne = length(TMPmat@x), + ia = TMPmat@i + 1, + ja = TMPmat@j + 1, + ra = TMPmat@x) + + # column (variable) bounds and objective function + glpkAPI::setColsBndsObjCoefsGLPK(lp@oobj, + j = c(1:nCols), + lb = lb, + ub = ub, + obj_coef = obj) + + # variable type + if (!is.null(ctype)) { + cctype <- sapply(ctype, + function(x) switch(x, + "C" = { glpkAPI::GLP_CV }, + "I" = { glpkAPI::GLP_IV }, + "B" = { glpkAPI::GLP_BV }, + { glpkAPI::GLP_CV })) + + glpkAPI::setColsKindGLPK(lp@oobj, j = c(1:nCols), kind = cctype) + } + + # right hand side + if (is.null(rub)) { + # The values in rlb will be copied to rub. GLPK ignores rlb and rub, + # depending on the constraint type (e.g. an upper bound, if the + # constraint type says, it has a lower bound): + # Constraint type "L": ignore rub + # Constraint type "U": ignore rlb + # Constraint type "E": ignore rub + # Constraint type "F": ignore rlb and rub + + crub <- rlb + } + else { + crub <- rub + } + stopifnot(length(rlb) == length(crub)) + glpkAPI::setRowsBndsGLPK(lp@oobj, + i = c(1:nRows), + lb = rlb, + ub = crub, + type = crtype) + + # row names + if (!is.null(rnames)) { + glpkAPI::setRowsNamesGLPK(lp@oobj, i = c(1:nRows), rnames = rnames) + } + + # column names + if (!is.null(cnames)) { + glpkAPI::setColsNamesGLPK(lp@oobj, j = c(1:nCols), cnames = cnames) + } + + # problem name + if (!is.null(pname)) { + glpkAPI::setProbNameGLPK(lp@oobj, pname = pname) + } + + if (!is.null(rnames) || !is.null(cnames) || !is.null(pname)) { + glpkAPI::createIndexGLPK(lp@oobj) + } + } +) + + +#------------------------------------------------------------------------------# + +setMethod("scaleProb", signature(lp = "optObj_glpkAPI"), + + function(lp, opt) { + + # check if tryCatch works here!! + glpkAPI::scaleProbGLPK(lp@oobj, opt) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("solveLp", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + out <- FALSE +# if (glpkAPI::bfExistsGLPK(lp@oobj) != 0) { +# if (glpkAPI::bfUpdatedGLPK(lp@oobj) != 0) { +# basis <- glpkAPI::factorizeGLPK(lp@oobj) +# #print(basis) +# } +# } + switch(lp@method, + "interior" = { + out <- glpkAPI::solveInteriorGLPK(lp@oobj) + }, + "exact" = { + out <- glpkAPI::solveSimplexExactGLPK(lp@oobj) + }, + "mip" = { + out <- glpkAPI::solveMIPGLPK(lp@oobj) + }, + { + out <- glpkAPI::solveSimplexGLPK(lp@oobj) + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjVal", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + switch(lp@method, + "interior" = { + out <- glpkAPI::getObjValIptGLPK(lp@oobj) + }, + "mip" = { + out <- glpkAPI::mipObjValGLPK(lp@oobj) + }, + { + out <- glpkAPI::getObjValGLPK(lp@oobj) + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRedCosts", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + if (lp@method == "interior") { + out <- glpkAPI::getColsDualIptGLPK(lp@oobj) + } + else { + out <- glpkAPI::getColsDualGLPK(lp@oobj) + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolStat", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + switch(lp@method, + "interior" = { + out <- glpkAPI::getSolStatIptGLPK(lp@oobj) + }, + "mip" = { + out <- glpkAPI::mipStatusGLPK(lp@oobj) + }, + { + out <- glpkAPI::getSolStatGLPK(lp@oobj) + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getFluxDist", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + switch(lp@method, + "interior" = { + out <- glpkAPI::getColsPrimIptGLPK(lp@oobj) + }, + "mip" = { + out <- glpkAPI::mipColsValGLPK(lp@oobj) + }, + { + out <- glpkAPI::getColsPrimGLPK(lp@oobj) + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColPrim", signature(lp = "optObj_glpkAPI", j = "numeric"), + + function(lp, j) { + + switch(lp@method, + "interior" = { + out <- glpkAPI::getColPrimIptGLPK(lp@oobj, j) + }, + "mip" = { + out <- glpkAPI::mipColValGLPK(lp@oobj, j) + }, + { + out <- glpkAPI::getColPrimGLPK(lp@oobj, j) + } + ) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumNnz", signature(lp = "optObj_glpkAPI"), + + function(lp) { + + out <- glpkAPI::getNumNnzGLPK(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("writeProb", signature(lp = "optObj_glpkAPI", fname = "character"), + + function(lp, fname, ff = "lp", ...) { + + switch(ff, + "lp" = { + fl <- glpkAPI::writeLPGLPK(lp@oobj, fname = fname) + }, + "mps" = { + fl <- glpkAPI::writeMPSGLPK(lp@oobj, fname = fname, ...) + }, + "glpk" = { + fl <- glpkAPI::writeProbGLPK(lp@oobj, fname = fname) + }, + { + message("wrong format!") + fl <- 1 + } + ) + out <- ifelse(fl == 0, TRUE, fl) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("readProb", signature(lp = "optObj_glpkAPI", fname = "character"), + + function(lp, fname, ff = "lp", ...) { + + switch(ff, + "lp" = { + fl <- glpkAPI::readLPGLPK(lp@oobj, fname = fname) + }, + "mps" = { + fl <- glpkAPI::readMPSGLPK(lp@oobj, fname = fname, ...) + }, + "glpk" = { + fl <- glpkAPI::readProbGLPK(lp@oobj, fname = fname) + }, + { + message("wrong format!") + fl <- 1 + } + ) + out <- ifelse(fl == 0, TRUE, fl) + + return(fl) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("sensitivityAnalysis", signature(lp = "optObj_glpkAPI"), + + function(lp, ...) { + + out <- glpkAPI::printRangesGLPK(lp@oobj, ...) + if (out == 0) { + message("wrote the file 'sar.txt'") + } + else { + warning("sensitivity analysis failed") + } + + return(out) + } +) + +#------------------------------------------------------------------------------# + + +setMethod("setRowsNames", signature(lp = "optObj_glpkAPI", + i = "numeric", names = "character"), + + function(lp, i, names) { + + invisible(glpkAPI::setRowsNamesGLPK(lp@oobj, i, names)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setColsNames", signature(lp = "optObj_glpkAPI", + j = "numeric", names = "character"), + + function(lp, j, names) { + + invisible(glpkAPI::setColsNamesGLPK(lp@oobj, j, names)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsNames", signature(lp = "optObj_glpkAPI", i = "numeric"), + + function(lp, i) { + + rn <- mapply(glpkAPI::getRowNameGLPK, i, MoreArgs = list(lp = lp@oobj), + SIMPLIFY = TRUE, USE.NAMES = FALSE) + return(unlist(rn)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsNames", signature(lp = "optObj_glpkAPI", j = "numeric"), + + function(lp, j) { + + cn <- mapply(glpkAPI::getColNameGLPK, j, MoreArgs = list(lp = lp@oobj), + SIMPLIFY = TRUE, USE.NAMES = FALSE) + return(unlist(cn)) + + } +) + + +#------------------------------------------------------------------------------# + diff --git a/R/optObj_lpSolveAPIClass.R b/R/optObj_lpSolveAPIClass.R new file mode 100644 index 0000000..2ce80c5 --- /dev/null +++ b/R/optObj_lpSolveAPIClass.R @@ -0,0 +1,779 @@ +# optObj_lpSolveAPIClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class optObj_lpSolveAPI # +#------------------------------------------------------------------------------# + +setClass(Class = "optObj_lpSolveAPI", contains = "optObj") + + +#------------------------------------------------------------------------------# +# methods # +#------------------------------------------------------------------------------# + +setMethod("delProb", signature(lp = "optObj_lpSolveAPI"), + + function(lp, ...) { + + #finalizeLpSolveProb(lp@oobj) + #lpSolveAPI::delete.lp(lp@oobj) + #lp@oobj <- NULL + lp <- new("optObj_lpSolveAPI") + + return(lp) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("initProb", signature(lp = "optObj_lpSolveAPI"), + + function(lp, to = NULL, nrows = 0, ncols = 0) { + + lp@oobj <- lpSolveAPI::make.lp(nrow = nrows, ncol = ncols) + #reg.finalizer(lp@oobj, finalizeLpSolveProb, TRUE) + + if (is.null(to)) { + setSolverParm(lp, list(verbose = "neutral")) + } + else { + setSolverParm(lp, list(verbose = as.character(to))) + } + + return(lp) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("backupProb", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- FALSE + np <- FALSE + + fname <- tempfile(pattern = "LPSOLVE_PROB_", fileext = ".tmp") + lpSolveAPI::write.lp(lp@oobj, filename = fname, type = "lp") + if (isTRUE(file.exists(fname))) { + np <- lpSolveAPI::read.lp(fname, type = "lp") + unlink(fname) + } + else { + stop("cannot read model") + } + + # create new optObj object + if (!identical(np, FALSE)) { + out <- new("optObj_lpSolveAPI", lp@solver, lp@method, lp@probType) + out@oobj <- np + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setSolverParm", signature(lp = "optObj_lpSolveAPI"), + + function(lp, solverParm) { + + if ( ! ((is.data.frame(solverParm)) || (is.list(solverParm))) ) { + stop(sQuote(solverParm), " must be list or data.frame") + } + + if (any(is.na(solverParm))) { + stop(sQuote(solverParm), " contains NA values") + } + + pname <- names(solverParm) + for (i in seq(along = solverParm)) { + command <- paste("lpSolveAPI::lp.control(lp@oobj, ", + pname[i], "='" , solverParm[[i]], "')", sep = "") + #print(command) + eval(parse(text = command)) + } + #print(lp.control(lp@oobj)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolverParm", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + lpSolveAPI::lp.control(lp@oobj) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_lpSolveAPI", lpdir = "character"), + + function(lp, lpdir) { + + lpSolveAPI::lp.control(lp@oobj, sense = lpdir) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setObjDir", signature(lp = "optObj_lpSolveAPI", lpdir = "numeric"), + + function(lp, lpdir) { + + dr <- ifelse(lpdir == -1, "max", "min") + lpSolveAPI::lp.control(lp@oobj, sense = dr) + + } +) + +#------------------------------------------------------------------------------# + +setMethod("getObjDir", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- lpSolveAPI::lp.control(lp@oobj)[["sense"]] + + return(out) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRows", signature(lp = "optObj_lpSolveAPI", nrows = "numeric"), + + function(lp, nrows) { + + ncols <- dim(lp@oobj)[2] + out <- lpSolveAPI::resize.lp(lp@oobj, nrows, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addCols", signature(lp = "optObj_lpSolveAPI", ncols = "numeric"), + + function(lp, ncols) { + + nrows <- dim(lp@oobj)[1] + out <- lpSolveAPI::resize.lp(lp@oobj, nrows, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsCols", signature(lp = "optObj_lpSolveAPI", + nrows = "numeric", ncols = "numeric"), + + function(lp, nrows, ncols) { + + out <- lpSolveAPI::resize.lp(lp@oobj, nrows, ncols) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumRows", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- dim(lp@oobj)[1] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getNumCols", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- dim(lp@oobj)[2] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addColsToProb", signature(lp = "optObj_lpSolveAPI"), + + # j: vector containing the new column indices (must be ascending) + # rind: list, containing the row indices of the new nz elements + # nzval: list, containing the new nz elements + # + # j, obj, lb, rind and nzval must have the same length + + function(lp, j, obj, lb, ub, rind, nzval) { + + nrc <- dim(lp@oobj) + obc <- getObjCoefs(lp, 1:nrc[2]) + + ord <- lpSolveAPI::resize.lp(lp@oobj, nrc[1], (nrc[2]+length(j))) + for (k in seq(along = j)) { + lpSolveAPI::add.column(lp@oobj, nzval[[k]], rind[[k]]) + } + out <- lpSolveAPI::set.bounds(lp@oobj, lb, ub, j) + out <- lpSolveAPI::set.objfn(lp@oobj, c(obc, obj)) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("addRowsToProb", signature(lp = "optObj_lpSolveAPI"), + + # i: vector containing the new row indices (must be ascending) + # cind: list, containing the column indices of the new nz elements + # nzval: list, containing the new nz elements + # + # i, type, lb, ub, cind and nzval must have the same length + # + # type can be one of the following: + # "F" = free variable -INF < x < INF + # "L" = variable with lower bound lb <= x < INF + # "U" = variable with upper bound -INF < x <= ub + # "D" = double-bounded variable lb <= x <= ub + # "E" = fixed variable lb = x = ub + + function(lp, i, type, lb, ub, cind, nzval, rnames = NULL) { + + stopifnot(length(lb) == length(ub)) + for (k in seq(along = i)) { + ltype <- switch(type[k], + "L" = { 2 }, + "U" = { 1 }, + "D" = { 1 }, + "E" = { 3 }, + { 3 } + ) + + + if (type[k] == "D") { + out <- lpSolveAPI::add.constraint(lp@oobj, nzval[[k]], + ltype, ub[k], cind[[k]], lb[k]) + } + else { + clb <- ifelse(type[k] == "U", ub[k], lb[k]) + out <- lpSolveAPI::add.constraint(lp@oobj, nzval[[k]], + ltype, clb, cind[[k]]) + } + } + + # row names + if (!is.null(rnames)) { + rrnames <- sub("(", "_", rnames, fixed = TRUE) + rrnames <- sub(")", "_", rrnames, fixed = TRUE) + rownames(lp@oobj)[i] <- rrnames + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBnds", signature(lp = "optObj_lpSolveAPI"), + + function(lp, j, lb, ub) { + + out <- lpSolveAPI::set.bounds(lp@oobj, lb, ub, j) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeColsBndsObjCoefs", signature(lp = "optObj_lpSolveAPI"), + + function(lp, j, lb, ub, obj_coef) { + + outb <- lpSolveAPI::set.bounds(lp@oobj, lb, ub, j) + outo <- lpSolveAPI::set.objfn(lp@oobj, obj_coef, j) + out <- c(outb, outo) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsLowBnds", signature(lp = "optObj_lpSolveAPI", j = "numeric"), + + function(lp, j) { + + out <- lpSolveAPI::get.bounds(lp@oobj, j)[["lower"]] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsUppBnds", signature(lp = "optObj_lpSolveAPI", j = "numeric"), + + function(lp, j) { + + out <- lpSolveAPI::get.bounds(lp@oobj, j)[["upper"]] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeRowsBnds", signature(lp = "optObj_lpSolveAPI"), + + function(lp, i, lb, ub) { + + out <- lpSolveAPI::set.constr.value(lp@oobj, rhs = lb, lhs = ub, + constraints = i) + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setRhsZero", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + nrows <- dim(lp@oobj)[1] + outb <- lpSolveAPI::set.constr.value(lp@oobj, + rhs = rep(0, nrows), + lhs = NULL, + constraints = c(1:nrows)) + outt <- lpSolveAPI::set.constr.type(lp@oobj, + rep(3, nrows), c(1:nrows)) + out <- c(outb, outt) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsLowBnds", signature(lp = "optObj_lpSolveAPI", i = "numeric"), + + function(lp, i) { + + out <- lpSolveAPI::get.constr.value(lp@oobj, + side = "lhs", + constraints = i) + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsUppBnds", signature(lp = "optObj_lpSolveAPI", i = "numeric"), + + function(lp, i) { + + out <- lpSolveAPI::get.constr.value(lp@oobj, + side = "rhs", + constraints = i) + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeObjCoefs", signature(lp = "optObj_lpSolveAPI"), + + function(lp, j, obj_coef) { + + out <- lpSolveAPI::set.objfn(lp@oobj, obj_coef, j) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjCoefs", signature(lp = "optObj_lpSolveAPI", j = "numeric"), + + function(lp, j) { + + #wrong_solver_msg(lp, "getObjCoefs", printOut = TRUE) + out <- numeric(length(j)) + for (i in seq(along = j)) { + out[i] <- lpSolveAPI::get.column(lp@oobj, j[i])$column[1] + } + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("changeMatrixRow", signature(lp = "optObj_lpSolveAPI"), + + function(lp, i, j, val) { + + lpSolveAPI::set.row(lp@oobj, row = i, xt = val, indices = j) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("loadLPprob", signature(lp = "optObj_lpSolveAPI"), + + function(lp, nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL) { + + stopifnot(is(mat, "Matrix")) + + # problem size is already specified in optObj_lpSolveAPI constructor + + crtype <- sapply(rtype, + function(x) switch(x, + "L" = { 2 }, + "U" = { 1 }, + "D" = { 1 }, + "E" = { 3 }, + { 3 })) + + # constraints with double bound + if (is.null(rub)) { + crub <- NULL + crlb <- rlb + } + else { + # Package lpSolveAPI uses rhs and lhs for constraints, but -- as far + # as I can see -- lhs does not work. + # If there is a maximization problem, the values from rub for double + # bounded constraints and constraints with upper bounds are + # exchanged for the corresponding values in rlb. + # If there is a minimization problem, the values from rub + # constraints with only upper bounds are exchanged for the + # corresponding values in rlb. For constraints with double bounds, + # the constraint type is changed to a constraint with lower bound + # (the upper bound should not be reached, because of the + # minimization). + # Now, rlb is used as rhs and rub as rls for lpSolveAPI. + + stopifnot(length(rlb) == length(rub)) + crub <- rub + crlb <- rlb + + # for a max problem: the constraining bound is the upper bound + # for a min problem: the constraining bound is the lower bound + + if (lpdir == "max") { + dbc <- crtype == 1 # double bound and upper bound + } + else { + dbc <- rtype == "U" # only upper bounds + dbl <- rtype == "D" + crtype[dbl] <- 2 + } + tmp <- crlb[dbc] + crlb[dbc] <- crub[dbc] + crub[dbc] <- tmp + } + + # optimization direction + lpSolveAPI::lp.control(lp@oobj, sense = lpdir) + + # constraint matrix + loadMatrixPerColumnLPSOLVE(lp@oobj, constMat = as(mat, "CsparseMatrix")) + + # column (variable) bounds + lpSolveAPI::set.bounds(lp@oobj, + lower = lb, + upper = ub, + columns = c(1:nCols)) + + # objective function + lpSolveAPI::set.objfn(lp@oobj, obj = obj, indices = c(1:nCols)) + + # constraints (right hand side) + lpSolveAPI::set.constr.value(lp@oobj, + rhs = crlb, + lhs = crub, + constraints = c(1:nRows)) + + # type of constraint + lpSolveAPI::set.constr.type(lp@oobj, + type = crtype, + constraints = c(1:nRows)) + + # variable type + if (!is.null(ctype)) { + cont <- which(ctype %in% "C") + int <- which(ctype %in% "I") + bin <- which(ctype %in% "B") + + if (length(cont) > 0) { + lpSolveAPI::set.type(lp@oobj, columns = cont, type = "real") + } + + if (length(int) > 0) { + lpSolveAPI::set.type(lp@oobj, columns = int, type = "integer") + } + + if (length(bin) > 0) { + lpSolveAPI::set.type(lp@oobj, columns = bin, type = "binary") + } + } + + # row and column names + if ( (!is.null(rnames)) && (!is.null(cnames)) ) { + rrnames <- sub("(", "_", rnames, fixed = TRUE) + rrnames <- sub(")", "_", rrnames, fixed = TRUE) + ccnames <- sub("(", "_", cnames, fixed = TRUE) + ccnames <- sub(")", "_", ccnames, fixed = TRUE) + dimnames(lp@oobj) <- list(rrnames, ccnames) + } + + # problem name + if (!is.null(pname)) { + ppname <- sub("(", "_", pname, fixed = TRUE) + ppname <- sub(")", "_", ppname, fixed = TRUE) + lpSolveAPI::name.lp(lp@oobj, ppname) + } + } +) + + +#------------------------------------------------------------------------------# + +setMethod("scaleProb", signature(lp = "optObj_lpSolveAPI"), + + function(lp, opt) { + + invisible(lpSolveAPI::lp.control(lp@oobj, scaling = opt)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("solveLp", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- solve(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getObjVal", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- lpSolveAPI::get.objective(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRedCosts", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- lpSolveAPI::get.dual.solution(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getSolStat", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- NA + + wrong_solver_msg(lp, "getSolStat", printOut = FALSE) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getFluxDist", signature(lp = "optObj_lpSolveAPI"), + + function(lp) { + + out <- lpSolveAPI::get.variables(lp@oobj) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColPrim", signature(lp = "optObj_lpSolveAPI", j = "numeric"), + + function(lp, j) { + + out <- lpSolveAPI::get.variables(lp@oobj)[j] + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("writeProb", signature(lp = "optObj_lpSolveAPI", fname = "character"), + + function(lp, fname, ff = "lp", ...) { + + out <- lpSolveAPI::write.lp(lp@oobj, filename = fname, type = ff, ...) + + return(out) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("readProb", signature(lp = "optObj_lpSolveAPI", fname = "character"), + + function(lp, fname, ff = "lp", ...) { + + lp@oobj <- lpSolveAPI::read.lp(filename = fname, type = ff, ...) + + return(lp) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setRowsNames", signature(lp = "optObj_lpSolveAPI", + i = "numeric", names = "character"), + + function(lp, i, names) { + + invisible(dimnames(lp@oobj)[[1]][i] <- names) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("setColsNames", signature(lp = "optObj_lpSolveAPI", + j = "numeric", names = "character"), + + function(lp, j, names) { + + invisible(dimnames(lp@oobj)[[2]][j] <- names) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getRowsNames", signature(lp = "optObj_lpSolveAPI", i = "numeric"), + + function(lp, i) { + + rn <- dimnames(lp@oobj)[[1]][i] + return(rn) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("getColsNames", signature(lp = "optObj_lpSolveAPI", j = "numeric"), + + function(lp, j) { + + cn <- dimnames(lp@oobj)[[2]][j] + return(cn) + + } +) + + +#------------------------------------------------------------------------------# + + diff --git a/R/optObj_lpSolveAPIcompat.R b/R/optObj_lpSolveAPIcompat.R new file mode 100644 index 0000000..09fd869 --- /dev/null +++ b/R/optObj_lpSolveAPIcompat.R @@ -0,0 +1,99 @@ +# optObj_lpSolveAPIcompat.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# This is for compatibility with lpSolveAPI. +# lpSolveAPI only has a return code, which also acts as status code. + +return_codeLPSOLVE <- function(code) { + if (code == 0) { return( "optimal solution found" ) } + else if (code == 1) { return( "the model is sub-optimal" ) } + else if (code == 2) { return( "the model is infeasible" ) } + else if (code == 3) { return( "the model is unbounded" ) } + else if (code == 4) { return( "the model is degenerate" ) } + else if (code == 5) { return( "numerical failure encountered" ) } + else if (code == 6) { return( "process aborted" ) } + else if (code == 7) { return( "timeout" ) } + else if (code == 9) { return( "the model was solved by presolve" ) } + else if (code == 10) { return( "the branch and bound routine failed" ) } + else if (code == 11) { return( paste("the branch and bound was stopped", + "because of a break-at-first", + "or break-at-value" + ) + ) + } + else if (code == 12) { return( paste("a feasible branch and bound", + "solution was found" + ) + ) + } + else if (code == 13) { return( paste("no feasible branch and bound", + "solution was found" + ) + ) + } + else { return(paste("Failed to obtain solution", + "unknown error code:", code + ) + ) + } +} + + +#------------------------------------------------------------------------------# + +loadMatrixPerColumnLPSOLVE <- function(lpmod, constMat) { + + stopifnot(is(constMat, "Matrix")) + + x <- constMat@x + p <- constMat@p + 1 + i <- constMat@i + 1 + + k <- 1 + while (k <= ncol(constMat)) { + lpSolveAPI::set.column(lpmod, + column = k, + x = x[(p[k]):(p[k+1]-1)], + indices = i[(p[k]):(p[k+1]-1)]) + k <- k + 1 + } + +} + + +#------------------------------------------------------------------------------# + +# finalizeLpSolveProb <- function(lprec) { +# +# if (is(lprec, "lpExtPtr")) { +# #tryCatch(#.Call("RlpSolve_delete_lp", lprec, PACKAGE = "lpSolveAPI"), +# # lpSolveAPI::delete.lp(lprec), +# # warning = function(e) FALSE) +# capture.output(lpSolveAPI::delete.lp(lprec), file = "/dev/null") +# } +# invisible(lprec) +# } + + diff --git a/R/optObj_pointer.R b/R/optObj_pointer.R new file mode 100644 index 0000000..2733b43 --- /dev/null +++ b/R/optObj_pointer.R @@ -0,0 +1,84 @@ +# optObj_pointer.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# class definitions for pointers to problem objects # +#------------------------------------------------------------------------------# + +setClass(Class = "lpExtPtr", contains = "VIRTUAL") # lpSolveAPI +setClass(Class = "glpkPtr", contains = "VIRTUAL") # glpkAPI +setClass(Class = "clpPtr", contains = "VIRTUAL") # clpAPI +setClass(Class = "cplexPtr", contains = "VIRTUAL") # cplexAPI + + +#------------------------------------------------------------------------------# +# definition of the class cplexPointer # +#------------------------------------------------------------------------------# + +setClass(Class = "cplexPointer", + representation( + env = "cplexPtr", + lp = "cplexPtr" + ), +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class cplexPointer +setMethod(f = "initialize", + signature = "cplexPointer", + definition = function(.Object, en, pr) { + + if ( (!missing(en)) || (!missing(pr)) ) { + if ( (cplexAPI::isCPLEXenvPointer(en)) && + (cplexAPI::isCPLEXprobPointer(pr)) ) { + + .Object@env <- en + .Object@lp <- pr + + } + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# definition of the class pointerToProb # +#------------------------------------------------------------------------------# + +# pointer representation in class optObj +setClassUnion(name = "pointerToProb", + members = c("externalptr", + "lpExtPtr", + "glpkPtr", + "clpPtr", + "cplexPointer" + ) +) + + diff --git a/R/optimizer.R b/R/optimizer.R new file mode 100644 index 0000000..b7dc30a --- /dev/null +++ b/R/optimizer.R @@ -0,0 +1,459 @@ +# optimizer.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: optimizer +# +# +# + + +optimizer <- function(model, react, + lb = NULL, + ub = NULL, + obj_coef = NULL, + lpdir = NULL, + algorithm = SYBIL_SETTINGS("ALGORITHM"), + mtfobj = NULL, + setToZero = FALSE, + rebuildModel = FALSE, + fld = "none", + prCmd = NA, poCmd = NA, + prDIR = NULL, poDIR = NULL, + verboseMode = 2, + ...) { + + + stopifnot(length(fld) == 1) + + #--------------------------------------------------------------------------# + # verboseMode + + on.exit(expr = { + if (exists("logObj")) { + logClose(logObj) <- NA + } + } ) + + # start logging + logObj <- sybilLog(filename = "", + loglevel = -1, + verblevel = verboseMode) + + + #--------------------------------------------------------------------------# + # check arguments + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg") + } + + if (!is(react, "list")) { + stop("needs an object of class list") + } + + # number of optimizations + nObj <- length(react) + + # parameters modifying the model + if (!is.null(lb)) { + stopifnot((length(lb) == nObj || nrow(lb) == nObj), + (is(lb, "numeric") || is(lb, "list") || is(lb, "matrix"))) + } + if (!is.null(ub)) { + stopifnot((length(ub) == nObj || nrow(ub) == nObj), + (is(ub, "numeric") || is(ub, "list") || is(ub, "matrix"))) + } + if (!is.null(obj_coef)) { + stopifnot((length(obj_coef) == nObj || nrow(obj_coef) == nObj), + (is(obj_coef, "numeric") || + is(obj_coef, "list") || + is(obj_coef, "matrix"))) + } + if (!is.null(lpdir)) { + stopifnot(length(lpdir) == nObj, is(lpdir, "character")) + } + + # flux distribution + if (isTRUE(fld)) { + fdist <- "all" + } + else if (identical(fld, FALSE)) { + fdist <- "none" + } + else { + fdist <- fld + } + + + #--------------------------------------------------------------------------# + # convenient function + + gEl <- function(el, num, pos) { + + if (is.null(el)) { + return(el) + } + + stopifnot(length(pos) == 1) + + if (is.list(el)) { + ret <- el[[pos]] + } + else if (is.matrix(el)) { + ret <- el[pos, , drop = TRUE] + } + else { + ret <- rep(el[pos], num) + } + + stopifnot(length(ret) == num) + return(ret) + + } +# gEl <- function(el, num) { +# +# if (is.null(el)) { +# return(el) +# } +# +# stopifnot(length(el) == 1) +# +# if (is.list(el)) { +# ret <- unlist(el) +# stopifnot(length(el) == num) +# } +# else { +# ret <- rep(el, num) +# } +# +# return(ret) +# +# } + + + #--------------------------------------------------------------------------# + # prepare problem object + #--------------------------------------------------------------------------# + + if (algorithm == "mtf") { + if (fdist == "none") { + fdist <- "fluxes" + } + if (is.null(mtfobj)) { + lpmod <- sysBiolAlg(model, algorithm = "mtf", + react = react, lb = lb, ub = ub, ...) + } + else { + stopifnot(is(mtfobj, "numeric"), length(mtfobj) == nObj) + lpmod <- sysBiolAlg(model, algorithm = "mtf", wtobj = mtfobj, ...) + } + } + else { + lpmod <- sysBiolAlg(model, algorithm = algorithm, ...) + } + + # check, if we use an algorithm performing genetic perturbations + pert <- checkAlgorithm(algorithm, "pert") + + + #--------------------------------------------------------------------------# + # data structures for simulation results + #--------------------------------------------------------------------------# + + obj <- numeric(nObj) + mobj <- numeric(nObj) + ok <- integer(nObj) + stat <- integer(nObj) + flux <- switch(fdist, + "all" = { + Matrix::Matrix(0, nrow = nc(lpmod), ncol = nObj) + }, + "fluxes" = { + Matrix::Matrix(0, nrow = length(fldind(lpmod)), ncol = nObj) + }, + { + NA + } + ) + + + #--------------------------------------------------------------------------# + # pre and post processing + + runPrPl <- logical(nObj) + runPoPl <- logical(nObj) + runPrPcn <- 1 + runPoPcn <- 1 + + if (all(!is.na(prCmd))) { + do_pr <- TRUE + prPcmd <- NULL + runPrP <- .doInRound(prDIR, nObj) + prPpa <- vector(mode = "list", length = length(runPrP)) + runPrPl[runPrP] <- TRUE + } + else { + do_pr <- FALSE + } + if (all(!is.na(poCmd))) { + do_po <- TRUE + poPcmd <- NULL + runPoP <- .doInRound(poDIR, nObj) + poPpa <- vector(mode = "list", length = length(runPoP)) + runPoPl[runPoP] <- TRUE + } + else { + do_po <- FALSE + } + + +#------------------------------------------------------------------------------# +# optimizations # +#------------------------------------------------------------------------------# + + message("calculating ", nObj, " optimizations ... ", appendLF = FALSE) + if (verboseMode > 1) { cat("\n") } + if (verboseMode == 2) { + progr <- .progressBar() + #progr <- txtProgressBar(min = 2, max = nObj, initial = 2, style = 3) + } + + logOptimizationTH(logObj) + + + fi <- fldind(lpmod) + objcTMP <- integer(react_num(model)) + + + for (i in 1:nObj) { + + if (verboseMode == 2) { + progr <- .progressBar(i, nObj, progr) + #setTxtProgressBar(progr, i) + } + + # pre/post processing + if (isTRUE(runPrPl[i])) { + prCmd_tmp <- prCmd + did_pr <- TRUE + } + else { + prCmd_tmp <- NA + did_pr <- FALSE + } + + if (isTRUE(runPoPl[i])) { + poCmd_tmp <- poCmd + did_po <- TRUE + } + else { + poCmd_tmp <- NA + did_po <- FALSE + } + + # solution i + if (isTRUE(rebuildModel)) { + sol <- optimizeProb(model, + react = react[[i]], +# lb = rep(lb[i], length(react[[i]])), +# ub = rep(ub[i], length(react[[i]])), +# obj_coef = obj_coef[i], +# lb = gEl(lb[i], length(react[[i]])), +# ub = gEl(ub[i], length(react[[i]])), +# obj_coef = gEl(obj_coef[i], length(react[[i]])), + lb = gEl(lb, length(react[[i]]), i), + ub = gEl(ub, length(react[[i]]), i), + obj_coef = gEl(obj_coef, length(react[[i]]), i), + lpdir = lpdir[i], + #lpdir = getObjDir(problem(lpmod)), + retOptSol = FALSE, + prCmd = prCmd_tmp, poCmd = poCmd_tmp, + prCil = runPrPcn, poCil = runPoPcn, + algorithm = algorithm, ...) + } + else { + if (algorithm == "mtf") { + changeMaxObj(lpmod, i) + } + + sol <- optimizeProb(lpmod, + react = react[[i]], +# lb = rep(lb[i], length(react[[i]])), +# ub = rep(ub[i], length(react[[i]])), +# obj_coef = obj_coef[i], +# lb = gEl(lb[i], length(react[[i]])), +# ub = gEl(ub[i], length(react[[i]])), +# obj_coef = gEl(obj_coef[i], length(react[[i]])), + lb = gEl(lb, length(react[[i]]), i), + ub = gEl(ub, length(react[[i]]), i), + obj_coef = gEl(obj_coef, length(react[[i]]), i), + lpdir = lpdir[i], + prCmd = prCmd_tmp, poCmd = poCmd_tmp, + prCil = runPrPcn, poCil = runPoPcn) + } + + #obj[i] <- sum(obj_coef(model) * sol$fluxes[fi]) + #mobj[i] <- crossprod(obj_coef(model), sol$fluxes[fi]) + #obj[i] <- sol$obj + ok[i] <- sol$ok + stat[i] <- sol$stat + if (fdist == "none") { + if (isTRUE(pert)) { + #obj[i] <- crossprod(obj_coef(model), sol$fluxes[fi]) + if (is.null(obj_coef)) { + obj[i] <- crossprod(obj_coef(model), sol$fluxes[fi]) + } + else { + objcTMP[react[[i]]] <- gEl(obj_coef, length(react[[i]]), i) + obj[i] <- crossprod(objcTMP, sol$fluxes[fi]) + } + } + else { + obj[i] <- sol$obj + } + } + else { + obj[i] <- sol$obj + if (fdist == "fluxes") { + flux[,i] <- sol$fluxes[fi] + } + else { + flux[,i] <- sol$fluxes + } + } + + # pre/post processing + if (isTRUE(did_pr)) { + if ( (runPrPcn == 1) && (is.null(prPcmd)) ) { + prPcmd <- cmd(sol$preP) + } + prPpa[[runPrPcn]] <- pa(sol$preP) + runPrPcn <- runPrPcn+1 + did_pr <- FALSE + } + if (isTRUE(did_po)) { + if ( (runPoPcn == 1) && (is.null(poPcmd)) ) { + poPcmd <- cmd(sol$postP) + } + poPpa[[runPoPcn]] <- pa(sol$postP) + runPoPcn <- runPoPcn+1 + did_po <- FALSE + } + + logOptimization(logObj, sol$ok, sol$stat, obj[i], lpdir[i], obj_coef[i], react[[i]], i) + + remove(sol) + #close(progr) + } + + message("OK") + + +#------------------------------------------------------------------------------# +# save the results # +#------------------------------------------------------------------------------# + + # slot fldind + if (fdist == "fluxes") { + fli <- 1:length(fi) + } + else if(fdist == "none") { + fli <- NA + } + else { + fli <- fi + } + + # pre and post processing + if (isTRUE(do_pr)) { + prAna <- ppProc(prPcmd) + pa(prAna) <- prPpa + ind(prAna) <- runPrP + } + else { + prAna <- NULL + } + + if (isTRUE(do_po)) { + poAna <- ppProc(poPcmd) + pa(poAna) <- poPpa + ind(poAna) <- runPoP + } + else { + poAna <- NULL + } + + # solution list + optsol <- list(solver = solver(problem(lpmod)), + method = method(problem(lpmod)), + algorithm = algorithm(lpmod), + lp_num_cols = nc(lpmod), + lp_num_rows = nr(lpmod), + obj = obj, + ok = ok, + stat = stat, + lp_dir = factor(getObjDir(problem(lpmod))), + fldind = fli, + fluxdist = fluxDistribution(flux), + prAna = prAna, + poAna = poAna, + alg_par = alg_par(lpmod)) + + +#------------------------------------------------------------------------------# + + if (isTRUE(setToZero)) { + do_again <- checkSolStat(stat, solver(problem(lpmod))) + num_new <- length(do_again) + optsol[["obj"]][do_again] <- as.numeric(0) + + message("setting ", num_new, " objective values to zero") + + for (i in seq(along = do_again)) { + logOptimization(logObj, + optsol[["ok"]][do_again[i]], + optsol[["stat"]][do_again[i]], 0, + lpdir[[do_again[i]]], obj_coef[[do_again[i]]], + react[[do_again[i]]], do_again[i]) + } + } + + +#------------------------------------------------------------------------------# +# return solution object # +#------------------------------------------------------------------------------# + + delProb(problem(lpmod)) + remove(lpmod) + + logFoot(logObj) <- TRUE + logClose(logObj) <- NA + + return(optsol) + +} + + + diff --git a/R/optsolClass.R b/R/optsolClass.R new file mode 100644 index 0000000..1311b71 --- /dev/null +++ b/R/optsolClass.R @@ -0,0 +1,580 @@ +# optsolClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsolClass + + +#------------------------------------------------------------------------------# +# class definitions # +#------------------------------------------------------------------------------# + +setClass("optsol", + representation( + mod_id = "character", # model id of the original model + mod_key = "character", # model key of the original model + solver = "character", # the used lp solver + method = "character", # the used method + algorithm = "character", # the used algorithm + num_of_prob = "integer", # number of problems to solve + lp_num_cols = "integer", # number of reactions + lp_num_rows = "integer", # number of metabolites + lp_obj = "numeric", # solution of the objective function + lp_ok = "integer", # exit status of the lp solver + lp_stat = "integer", # solution status + lp_dir = "factor", # direction of optimization(s) + obj_coef = "numeric", # objective coefficients in model + obj_func = "character", # objective function (printObjFunc) + fldind = "integer", # indices of fluxes + fluxdist = "fluxDistribution", # the flux distribution + alg_par = "list" # parameters to the algorithm + ), + contains = "VIRTUAL", + #validity = .validoptsol +) + + +#------------------------------------------------------------------------------# +# user constructors # +#------------------------------------------------------------------------------# + +optsol <- function(solver) { + if (missing(solver)) { + stop("Creating an object of class optsol needs a valid solver!") + } + solver <- as.character(solver) + new("optsol", solver = solver) +} + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# mod_id +setMethod("mod_id", signature(object = "optsol"), + function(object) { + return(object@mod_id) + } +) + +setReplaceMethod("mod_id", signature = (object = "optsol"), + function(object, value) { + object@mod_id <- value + return(object) + } +) + + +# mod_key +setMethod("mod_key", signature(object = "optsol"), + function(object) { + return(object@mod_key) + } +) + +setReplaceMethod("mod_key", signature = (object = "optsol"), + function(object, value) { + object@mod_key <- value + return(object) + } +) + + +# solver +setMethod("solver", signature(object = "optsol"), + function(object) { + return(object@solver) + } +) + +setReplaceMethod("solver", signature = (object = "optsol"), + function(object, value) { + object@solver <- value + return(object) + } +) + + +# method +setMethod("method", signature(object = "optsol"), + function(object) { + return(object@method) + } +) + +setReplaceMethod("method", signature = (object = "optsol"), + function(object, value) { + object@method <- value + return(object) + } +) + + +# method +setMethod("algorithm", signature(object = "optsol"), + function(object) { + return(object@algorithm) + } +) + +setReplaceMethod("algorithm", signature = (object = "optsol"), + function(object, value) { + object@algorithm <- value + return(object) + } +) + + +# num_of_prob +setMethod("num_of_prob", signature(object = "optsol"), + function(object) { + return(object@num_of_prob) + } +) + +setReplaceMethod("num_of_prob", signature = (object = "optsol"), + function(object, value) { + object@num_of_prob <- value + return(object) + } +) + + +# lp_num_cols +setMethod("lp_num_cols", signature(object = "optsol"), + function(object) { + return(object@lp_num_cols) + } +) + +setReplaceMethod("lp_num_cols", signature = (object = "optsol"), + function(object, value) { + object@lp_num_cols <- value + return(object) + } +) + + +# lp_num_rows +setMethod("lp_num_rows", signature(object = "optsol"), + function(object) { + return(object@lp_num_rows) + } +) + +setReplaceMethod("lp_num_rows", signature = (object = "optsol"), + function(object, value) { + object@lp_num_rows <- value + return(object) + } +) + + +# lp_dir +setMethod("lp_dir", signature(object = "optsol"), + function(object) { + return(object@lp_dir) + } +) + +setReplaceMethod("lp_dir", signature(object = "optsol", value = "factor"), + function(object, value) { + object@lp_dir <- value + return(object) + } +) + +setReplaceMethod("lp_dir", signature(object = "optsol", value = "character"), + function(object, value) { + if (all(value == "min" | value == "max")) { + object@lp_dir <- factor(value) + } + else { + warning("only 'min' (1) and 'max' (-1) are allowed") + } + return(object) + } +) + +setReplaceMethod("lp_dir", signature(object = "optsol", value = "numeric"), + function(object, value) { + if (all(value == 1 | value == -1)) { + fc <- value + fc[fc == 1] <- "min" + fc[fc == -1] <- "max" + object@lp_dir <- factor(fc) + } + else { + warning("only '1' (min) and '-1' (max) are allowed") + } + return(object) + } +) + + +# lp_obj +setMethod("lp_obj", signature(object = "optsol"), + function(object) { + return(object@lp_obj) + } +) + +setReplaceMethod("lp_obj", signature = (object = "optsol"), + function(object, value) { + object@lp_obj <- value + return(object) + } +) + + +# lp_ok +setMethod("lp_ok", signature(object = "optsol"), + function(object) { + return(object@lp_ok) + } +) + +setReplaceMethod("lp_ok", signature = (object = "optsol"), + function(object, value) { + object@lp_ok <- value + return(object) + } +) + + +# lp_stat +setMethod("lp_stat", signature(object = "optsol"), + function(object) { + return(object@lp_stat) + } +) + +setReplaceMethod("lp_stat", signature = (object = "optsol"), + function(object, value) { + object@lp_stat <- value + return(object) + } +) + + +# objective coefficient +setMethod("obj_coef", signature(object = "optsol"), + function(object) { + return(object@obj_coef) + } +) + +setReplaceMethod("obj_coef", signature(object = "optsol"), + function(object, value) { + object@obj_coef <- value + return(object) + } +) + + +# objective function +setMethod("obj_func", signature(object = "optsol"), + function(object) { + return(object@obj_func) + } +) + +setReplaceMethod("obj_func", signature(object = "optsol"), + function(object, value) { + object@obj_func <- value + return(object) + } +) + + +# fldind +setMethod("fldind", signature(object = "optsol"), + function(object) { + return(object@fldind) + } +) + +setReplaceMethod("fldind", signature = (object = "optsol"), + function(object, value) { + object@fldind <- value + return(object) + } +) + + +# fluxdist +setMethod("fluxdist", signature(object = "optsol"), + function(object) { + return(object@fluxdist) + } +) + +setReplaceMethod("fluxdist", signature = (object = "optsol"), + function(object, value) { + object@fluxdist <- value + return(object) + } +) + + +# fluxes +setMethod("fluxes", signature(object = "optsol"), + function(object) { + return(fluxes(object@fluxdist)) + } +) + +setReplaceMethod("fluxes", signature = (object = "optsol"), + function(object, value) { + fluxes(object@fluxdist) <- value + return(object) + } +) + + +# alg_par +setMethod("alg_par", signature(object = "optsol"), + function(object) { + return(object@alg_par) + } +) + +setReplaceMethod("alg_par", signature = (object = "optsol"), + function(object, value) { + object@alg_par <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +# mod_obj +setMethod("mod_obj", signature(object = "optsol"), + function(object) { + if ( (is.na(fldind(object)[1L])) || + (is.na(fluxes(object)[1L, 1L])) ) { + val <- lp_obj(object) + } + else { + val <- crossprod(obj_coef(object), + fluxes(object)[fldind(object), ])[1L, ] + } + return(val) + } +) + + +# number of fluxes +setMethod("nfluxes", signature(object = "optsol"), + function(object) { + return(num_of_fluxes(object@fluxdist)) + } +) + + +# check solution status +setMethod("checkStat", signature(opt = "optsol"), + function(opt) { + ng <- checkSolStat(opt@lp_stat, opt@solver) + return(ng) + } +) + + +# get part of the flux distribution +setMethod("getFluxDist", signature(lp = "optsol"), + function(lp, react = NULL, opt = NULL, drop = TRUE) { + + if (num_of_fluxes(fluxdist(lp)) == 1) { + return(fluxes(lp)) + } + + # cr: row indices (reactions) + # nr: row names (reaction id's, or row indices) + # cc: column indices (optimizations) + # nc: number of optimization + + if (is.null(react)) { + cr <- fldind(lp) + nr <- cr + } + else { + if (is(react, "reactId")) { + stopifnot(identical(mod_id(lp), mod_id(react))) + + cr <- fldind(lp)[react_pos(react)] + nr <- react_id(react) + } + else if (is(react, "numeric")) { + if (max(react) > nvar(fluxdist(lp))) { + stop("react must be in [1,", nvar(fluxdist(lp)),"]") + } + else { + cr <- react + nr <- react + } + } + else { + stop("react must be numeric or of class reactId") + } + } + + if (is.null(opt)) { + cc <- 1:ncol(fluxes(lp)) + nc <- cc + } + else { + if (is(opt, "numeric")) { + if (max(opt) > ncol(fluxes(lp))) { + stop("opt must be in [1,", ncol(fluxes(lp)),"]") + } + else { + cc <- opt + nc <- cc + } + } + else { + stop("opt must be numeric") + } + } + + + fl <- fluxes(lp)[cr, cc, drop = drop] + if (is.null(dim(fl))) { + if (length(nr) == length(fl)) { + names(fl) <- nr + } + } + else { + rownames(fl) <- nr + colnames(fl) <- nc + #colnames(fl) <- paste("[", 1:num_of_prob(lp), "]", sep = "") + } + + return(fl) + } +) + + +# consider using sprintf here +setMethod("show", signature(object = "optsol"), + function(object) { + cat(sprintf("%-42s%s\n", "solver:", solver(object))) + cat(sprintf("%-42s%s\n", "method:", method(object))) + cat(sprintf("%-42s%s\n", "algorithm:", algorithm(object))) + cat(sprintf("%-42s%s\n", "number of variables:", lp_num_cols(object))) + cat(sprintf("%-42s%s\n", "number of constraints:", lp_num_rows(object))) + if (num_of_prob(object) == 1) { + cat(sprintf("%-42s%s\n", "return value of solver:", getMeanReturn(lp_ok(object), solver(object)))) + cat(sprintf("%-42s%s\n", "solution status:", getMeanStatus(lp_stat(object), solver(object)))) + cat(sprintf("%s%-14s%f\n", "value of objective function ", paste("(", algorithm(object), "):", sep = ""), lp_obj(object))) + cat(sprintf("%-42s%f\n", "value of objective function (model):", mod_obj(object))) + if ( (algorithm(object) == "moma") && (!is.null(alg_par(object)[["wtflux"]])) ) { + cat(sprintf("%-42s%f\n", "euclidean distance between wt and v:", + sqrt(crossprod(alg_par(object)[["wtflux"]] - getFluxDist(object))))) + } + } + else { + cat(sprintf("%-42s%s\n", "number of problems to solve:", num_of_prob(object))) + ok <- sum(lp_ok(object) == 0, na.rm = TRUE) + cat(sprintf("%-42s%s\n", "number of successful solution processes:", ok)) + } + } +) + + +# length of an object of class optsol +setMethod("length", signature = signature(x = "optsol"), + function(x) { + return(num_of_prob(x)) + } +) + + +# draw a histogramm (package lattice) +setMethod("plot", signature(x = "optsol", y = "missing"), + function(x, y, + col = "grey", + xlab = "value of objective function", ...) { + + histogram(x = mod_obj(x), col = col, xlab = xlab, ...) + + } +) + + +# checkOptSol +setMethod("checkOptSol", signature(opt = "optsol"), + function(opt, onlywarn = FALSE) { + + lp_check <- FALSE + + if (isTRUE(onlywarn)) { + if (sum(lp_ok(opt) != 0) != 0) { + msg <- paste("some optimizations did not end successful", + "check results with checkOptSol()", sep = "\n") + warning(msg, call. = FALSE) + } + else { + lp_check <- TRUE + } + } + else { + lp_check <- checksol() + + if (solver(opt) == "cplexAPI") { + TEMP_ENV <- cplexAPI::openEnvCPLEX() + } + else { + TEMP_ENV <- NULL + } + + num_of_prob(lp_check) <- length(opt) + + ec <- table(lp_ok(opt)) + sc <- table(lp_stat(opt)) + + exit_code(lp_check) <- as.integer(rownames(ec)) + exit_num(lp_check) <- as.integer(ec) + exit_meaning(lp_check) <- mapply(getMeanReturn, exit_code(lp_check), + MoreArgs = list(solver = solver(opt))) + + status_code(lp_check) <- as.integer(rownames(sc)) + status_num(lp_check) <- as.integer(sc) + status_meaning(lp_check) <- mapply(getMeanStatus, status_code(lp_check), + MoreArgs = list(solver = solver(opt), + env = TEMP_ENV)) + + if (!is.null(TEMP_ENV)) { + cplexAPI::closeEnvCPLEX(TEMP_ENV) + } + } + + return(lp_check) + +} +) diff --git a/R/optsol_blockedReactClass.R b/R/optsol_blockedReactClass.R new file mode 100644 index 0000000..37e6970 --- /dev/null +++ b/R/optsol_blockedReactClass.R @@ -0,0 +1,96 @@ +# optsol_blockedReactClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsol_blockedReactClass + + +#------------------------------------------------------------------------------# +# definition of the class optsol_blockedReact # +#------------------------------------------------------------------------------# + +# slot obj_function is used here for the optimized reaction +setClass("optsol_blockedReact", + representation( + blocked = "logical", # blocked reaction (yes/no) + react = "reactId" # checked reaction id's + ), + contains = "optsol" +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# blocked +setMethod("blocked", signature(object = "optsol_blockedReact"), + function(object) { + return(object@blocked) + } +) + +setReplaceMethod("blocked", signature = (object = "optsol_blockedReact"), + function(object, value) { + object@blocked <- value + return(object) + } +) + + +# react +setMethod("react", signature(object = "optsol_blockedReact"), + function(object) { + return(object@react) + } +) + +setReplaceMethod("react", signature = (object = "optsol_blockedReact"), + function(object, value) { + object@react <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("maxSol", signature(object = "optsol_blockedReact"), + function(object, slot) { + odds <- seq(1, num_of_prob(object), 2) + command <- paste(deparse(substitute(slot)), "(", deparse(substitute(object)), ")[odds]", sep = "") + minimalSolutions <- eval(parse(text = command)) + return(minimalSolutions) + } +) + +setMethod("minSol", signature(object = "optsol_blockedReact"), + function(object, slot) { + odds <- seq(2, num_of_prob(object), 2) + command <- paste(deparse(substitute(slot)), "(", deparse(substitute(object)), ")[odds]", sep = "") + minimalSolutions <- eval(parse(text = command)) + return(minimalSolutions) + } +) diff --git a/R/optsol_fluxVarClass.R b/R/optsol_fluxVarClass.R new file mode 100644 index 0000000..5ad34c5 --- /dev/null +++ b/R/optsol_fluxVarClass.R @@ -0,0 +1,350 @@ +# optsol_fluxVarClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsol_fluxVarClass + + +#------------------------------------------------------------------------------# +# definition of the class optsol_fluxVar # +#------------------------------------------------------------------------------# + +setClass("optsol_fluxVar", + representation( + react = "reactId" # reactions to be analyzed + ), + contains = "optsol_optimizeProb" +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# react +setMethod("react", signature(object = "optsol_fluxVar"), + function(object) { + return(object@react) + } +) + +setReplaceMethod("react", signature = (object = "optsol_fluxVar"), + function(object, value) { + object@react <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +### +# use barplot? or better hist allow user to set plot to false +### +#setGeneric("plotRangeVar", function(object, ...) standardGeneric("plotRangeVar")) +setMethod("plotRangeVar", signature(object = "optsol_fluxVar"), + function(object, ...) { + range <- ( + (abs(maxSol(object, lp_obj)) - abs(minSol(object, lp_obj))) + /abs(maxSol(object, lp_obj)) + ) + #range <- (abs(maxSol(object, lp_obj)) - abs(minSol(object, lp_obj))) + #blubber <- hist(range, breaks = 500, ...) + blubber <- hist(range, ...) + #barplot(range, + # names.arg = react_id(react(object)), + # las = 2, + # ...) + #return(blubber) + return(range) + } +) + + +setMethod("blReact", signature(object = "optsol_fluxVar"), + function(object, tol = SYBIL_SETTINGS("TOLERANCE")) { + + bl <- abs(minSol(object, "lp_obj")) < tol & + abs(maxSol(object, "lp_obj")) < tol + + return(bl) + } +) + + +setMethod("minSol", signature(object = "optsol_fluxVar"), + function(object, slot) { + + if (missing(slot)) { + stop("argument 'slot' is missing") + } + + np <- num_of_prob(object) + + if (np > 1) { + ms <- 1 : floor(np/2) + } + else { + stop("not enough optimization problems") + } + + #ms <- seq(1, num_of_prob(object), 2) + + command <- paste("is(", + deparse(substitute(slot)), + "(", + deparse(substitute(object)), + "))", sep = "") + slottype <- eval(parse(text = command)) + + if (is.na(match("Matrix", slottype))) { + command <- paste(deparse(substitute(slot)), + "(", + deparse(substitute(object)), + ")[ms]", sep = "") + } + else { + command <- paste(deparse(substitute(slot)), + "(", + deparse(substitute(object)), + ")[,ms]", sep = "") + } + minimalSolutions <- eval(parse(text = command)) + return(minimalSolutions) + } +) + + +setMethod("maxSol", signature(object = "optsol_fluxVar"), + function(object, slot) { + + if (missing(slot)) { + stop("argument 'slot' is missing") + } + + np <- num_of_prob(object) + + if (np > 1) { + ms <- ceiling((np/2+1) : np) + } + else { + stop("not enough optimization problems") + } + + #ms <- seq(2, num_of_prob(object), 2) + + command <- paste("is(", + deparse(substitute(slot)), + "(", + deparse(substitute(object)), + "))", sep = "") + slottype <- eval(parse(text = command)) + + if (is.na(match("Matrix", slottype))) { + command <- paste(deparse(substitute(slot)), + "(", + deparse(substitute(object)), + ")[ms]", sep = "") + } + else { + command <- paste(deparse(substitute(slot)), + "(", + deparse(substitute(object)), + ")[,ms]", sep = "") + } + maximalSolutions <- eval(parse(text = command)) + return(maximalSolutions) + } +) + + +#setMethod("[", signature = signature(x = "optsol_fluxVar"), +# function(x, i, j, ..., drop = FALSE) { +# +# if ((missing(i)) || (length(i) == 0)) { +# return(x) +# } +# +# if (max(i) > length(x)) { +# stop("subscript out of bounds") +# } +# +# slots <- slotNames(x) +# +# isO <- is(x)[1] +# +# newClass <- paste(isO, "(", +# "solver = \"", solver(x), "\"", +# sep = "") +# +# +# newClass <- paste(newClass, ", ", +# "nprob = length(i)-1, ", +# "lpdir = \"lp_dir(x)\", ", +# "ncols = lp_num_cols(x), ", +# "nrows = lp_num_rows(x), ", +# "objf = \"obj_function(x)\", ", +# "fld = ", +# sep = "") +# +# NC_fl <- FALSE +# if (nfluxes(x) > 1) { +# NC_fl <- TRUE +# newClass <- paste(newClass, TRUE, sep = "") +# } +# else { +# newClass <- paste(newClass, FALSE, sep = "") +# } +# +# if ("delmat" %in% slots) { +# dimdel <- dim(delmat(x)) +# newClass <- paste(newClass, ", delrows = ", dimdel[1], ", delcols = ", dimdel[2], sep = "") +# } +# else { +# NC_delmat <- NA +# } +# +# newClass <- paste(newClass, ")", sep = "") +# +# newSol <- eval(parse(text = newClass)) +# +# method(newSol) <- method(x)[i] +# algorithm(newSol) <- algorithm(x) +# lp_obj(newSol) <- lp_obj(x)[i] +# lp_ok(newSol) <- lp_ok(x)[i] +# lp_stat(newSol) <- lp_stat(x)[i] +# react_id(newSol) <- react_id(x) +# allGenes(newSol) <- allGenes(x) +# chlb(newSol) <- chlb(x)[i] +# chub(newSol) <- chub(x)[i] +# dels(newSol) <- dels(x)[i, , drop = FALSE] +# +# if (isTRUE(NC_fl)) { +# fluxes(newSol) <- fluxes(x)[,i, drop = FALSE] +# } +# +# if ("fluxdels" %in% slots) { +# fluxdels(newSol) <- fluxdels(x)[i] +# } +# +# if ("hasEffect" %in% slots) { +# hasEffect(newSol) <- hasEffect(x)[i] +# } +# +# if ("delmat" %in% slots) { +# if (all(is.na(dels(newSol)[1,]))) { +# delmi <- dels(newSol)[-1,1] +# delmj <- dels(newSol)[-1,2] +# } +# else { +# delmi <- dels(newSol)[,1] +# delmj <- dels(newSol)[,2] +# } +# +# delmat(newSol) <- delmat(x)[ +# as.character(delmi), +# as.character(delmj), +# drop = FALSE +# ] +# } +# +# return(newSol) +# +# +# } +#) + + +setMethod("plot", signature(x = "optsol_fluxVar", y = "missing"), + function(x, y, + ylim, + xlab = "reaction no.", + ylab = "flux rate", + pch = 20, + col = "black", + collower, colupper, pchupper, pchlower, + dottedline = FALSE, + baseline = 0, + connect = TRUE, + colconnect = "black", + ...) { + + if (missing(ylim)) { + largest <- ceiling(max(lp_obj(x))) + smallest <- floor(min(lp_obj(x))) + ylim <- c(smallest, largest) + } + else { + largest <- ylim[2] + smallest <- ylim[1] + } + + if (missing(collower)) { + collower <- col + } + + if (missing(colupper)) { + colupper <- col + } + + if (missing(pchlower)) { + pchlower <- pch + } + + if (missing(pchupper)) { + pchupper <- pch + } + + np <- num_of_prob(x) + num_dots <- np/2 + + xdat <- rep(1:num_dots, 2) + #minfl <- lp_obj(x)[c(seq(1, num_of_prob(x), 2))] + #maxfl <- lp_obj(x)[c(seq(2, num_of_prob(x), 2))] + minfl <- lp_obj(x)[1:(np/2)] + maxfl <- lp_obj(x)[(np/2+1):np] + + plot(xdat, c(minfl, maxfl), xlab = xlab, ylab = ylab, ylim = ylim, + col = c(collower, colupper), + pch = c(pchlower, pchupper), ...) + + if (isTRUE(connect)) { + arrows(1:num_dots, minfl, 1:num_dots, maxfl, + length = 0, col = colconnect) + } + + if (dottedline == TRUE) { + segments(c(1:num_dots), rep(smallest, num_dots), + c(1:num_dots), minfl, + lty = "dotted") + } + + if (!is.na(baseline)) { + points(c(1, num_dots), c(baseline, baseline), + type = "s", lty = "dashed") + } + + } +) diff --git a/R/optsol_fluxdelClass.R b/R/optsol_fluxdelClass.R new file mode 100644 index 0000000..1017db2 --- /dev/null +++ b/R/optsol_fluxdelClass.R @@ -0,0 +1,269 @@ +# optsol_fluxdelClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsol_fluxdelClass + + +#------------------------------------------------------------------------------# +# definition of the class optsol_fluxdel # +#------------------------------------------------------------------------------# + +setClass("optsol_fluxdel", + representation( + chlb = "numeric", # lower bound of changed fluxes/genes + chub = "numeric", # upper bound of changed fluxes/genes + dels = "matrix" # id's of deleted fluxes + ), + contains = "optsol_optimizeProb" +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# chlb +setMethod("chlb", signature(object = "optsol_fluxdel"), + function(object) { + return(object@chlb) + } +) + +setReplaceMethod("chlb", signature = (object = "optsol_fluxdel"), + function(object, value) { + object@chlb <- value + return(object) + } +) + + +# chub +setMethod("chub", signature(object = "optsol_fluxdel"), + function(object) { + return(object@chub) + } +) + +setReplaceMethod("chub", signature = (object = "optsol_fluxdel"), + function(object, value) { + object@chub <- value + return(object) + } +) + + +# dels +setMethod("dels", signature(object = "optsol_fluxdel"), + function(object) { + return(object@dels) + } +) + +setReplaceMethod("dels", signature = (object = "optsol_fluxdel"), + function(object, value) { + object@dels <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +# lethal +setMethod("lethal", signature(object = "optsol_fluxdel"), + function(object, wt, tol) { + + stopifnot(is(wt, "numeric"), length(wt) == 1) + + if (missing(tol)) { + tol <- SYBIL_SETTINGS("TOLERANCE") + } + + letid <- which(abs(mod_obj(object)/wt) < tol) + let <- logical(num_of_prob(object)) + let[letid] <- TRUE + + return(let) + } +) + + +#setMethod("ind2id", signature = (object = "optsol_fluxdel"), +# function(object, slotN) { +# out <- NULL +# switch (slotN, +# +# "dels" = { +# out <- apply(dels(object), 2, +# function(x) allGenes(object)[x] +# ) +# }, +# +# { +# warning(paste("'", slotN, "' is not a valid slot!", +# sep = "" +# ) +# ) +# } +# +# ) +# +# return(out) +# } +#) + + +setMethod("deleted", signature = (object = "optsol_fluxdel"), + function(object, i) { + value <- dels(object)[i, ] + return(value) + } +) + + +setMethod("[", "optsol_fluxdel", function(x, i, j, ..., drop = FALSE) { + + if ((missing(i)) || (length(i) == 0)) { + return(x) + } + + if (max(i) > length(x)) { + stop("subscript out of bounds") + } + + slots <- slotNames(x) + + isO <- is(x)[1] + + newSol <- new(isO, + mod_id = x@mod_id, + mod_key = x@mod_key, + solver = x@solver, + method = x@method, + algorithm = x@algorithm, + num_of_prob = length(i), + lp_num_cols = x@lp_num_cols, + lp_num_rows = x@lp_num_rows, + lp_obj = x@lp_obj[i], + lp_ok = x@lp_ok[i], + lp_stat = x@lp_stat[i], + lp_dir = x@lp_dir, + obj_coef = x@obj_coef, + obj_func = x@obj_func, + fldind = x@fldind, + chlb = x@chlb[i], + chub = x@chub[i], + dels = x@dels[i, , drop = FALSE] + ) + + if (nfluxes(x) > 1) { + NC_fl <- TRUE + } + else { + NC_fl <- FALSE + } + + if (isTRUE(NC_fl)) { + newSol@fluxdist <- fluxDistribution(x@fluxes[ , i, drop = FALSE]) + } + + if ("fluxdels" %in% slots) { + newSolfluxdels <- x@fluxdels[i] + } + + if ("hasEffect" %in% slots) { + newSol@hasEffect <- x@hasEffect[i] + } + + return(newSol) + + +# if ("num_of_prob" %in% slots) { +# NC_num_of_prob <- length(i) +# newClass <- paste(newClass, ", nprob = ", length(i)-1, sep = "") +# } +# else { +# NC_num_prob <- NA +# } +# +# if ("lp_dir" %in% slots) { +# NC_lp_dir <- lp_dir(x) +# newClass <- paste(newClass, ", lpdir = \"", lp_dir(x), "\"", sep = "") +# } +# else { +# NC_lp_dir <- NA +# } +# +# if ("lp_num_cols" %in% slots) { +# NC_lp_num_cols <- lp_num_cols(x) +# newClass <- paste(newClass, ", ncols = ", lp_num_cols(x), sep = "") +# } +# else { +# NC_lp_num_cols <- NA +# } +# +# if ("lp_num_rows" %in% slots) { +# NC_lp_num_rows <- lp_num_rows(x) +# newClass <- paste(newClass, ", nrows = ", lp_num_rows(x), sep = "") +# } +# else { +# NC_lp_num_rows <- NA +# } +# +# if ("obj_function" %in% slots) { +# NC_obj_function <- obj_function(x) +# newClass <- paste(newClass, ", objf = \"", obj_function(x), "\"", sep = "") +# } +# else { +# NC_obj_function <- NA +# } +# +# if ("fluxdist" %in% slots) { +# if (is.na(fluxes(x))) { +# NC_fluxdist <- FALSE +# newClass <- paste(newClass, ", fld = ", FALSE, sep = "") +# } +# else { +# NC_fluxdist <- TRUE +# newClass <- paste(newClass, ", fld = ", TRUE, sep = "") +# } +# } +# else { +# NC_fluxdist <- NA +# } +# +# if ("delmat" %in% slots) { +# NC_delmat <- delmat(x) +# dimdel <- dim(NC_delmat) +# newClass <- paste(newClass, ", delrows = ", dimdel[1], ", delcols = ", dimdel[2], sep = "") +# } +# else { +# NC_delmat <- NA +# } + } +) + + diff --git a/R/optsol_genedelClass.R b/R/optsol_genedelClass.R new file mode 100644 index 0000000..d58f040 --- /dev/null +++ b/R/optsol_genedelClass.R @@ -0,0 +1,117 @@ +# optsol_genedelClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsol_genedelClass + + +#------------------------------------------------------------------------------# +# definition of the class optsol_genedel # +#------------------------------------------------------------------------------# + +setClass("optsol_genedel", + representation( + fluxdels = "list", + hasEffect = "logical" + ), + contains = "optsol_fluxdel" +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# reactions +setMethod("fluxdels", signature(object = "optsol_genedel"), + function(object) { + return(object@fluxdels) + } +) + +setReplaceMethod("fluxdels", signature = (object = "optsol_genedel"), + function(object, value) { + object@fluxdels <- value + return(object) + } +) + + +# hasEffect +setMethod("hasEffect", signature(object = "optsol_genedel"), + function(object) { + return(object@hasEffect) + } +) + +setReplaceMethod("hasEffect", signature = (object = "optsol_genedel"), + function(object, value) { + object@hasEffect <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +#setMethod("ind2id", signature = (object = "optsol_genedel"), +# function(object, slotN) { +# out <- NULL +# switch (slotN, +# +# "dels" = { +# out <- apply(dels(object), 2, +# function(x) allGenes(object)[x] +# ) +# }, +# +# "fluxdels" = { +# out <- lapply(fluxdels(object), +# function(x) react_id(object)[x] +# ) +# }, +# +# { +# warning(paste("'", slotN, "' is not a valid slot!", +# sep = "" +# ) +# ) +# } +# +# ) +# +# return(out) +# } +#) + + +setMethod("deleted", signature = (object = "optsol_genedel"), + function(object, i) { + value <- fluxdels(object)[[i]] + return(value) + } +) + + diff --git a/R/optsol_optimizeProbClass.R b/R/optsol_optimizeProbClass.R new file mode 100644 index 0000000..3c45d48 --- /dev/null +++ b/R/optsol_optimizeProbClass.R @@ -0,0 +1,115 @@ +# optsol_optimizeProbClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsol_optimizeProbClass + + +#------------------------------------------------------------------------------# +# definition of the class optsol_optimizeProb # +#------------------------------------------------------------------------------# + +setClass("optsol_optimizeProb", + representation( + preProc = "ppProc", # preprocessing lp result + postProc = "ppProc" # postprocessing lp result + ), + contains = "optsol" +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +makeOptsolMO <- function(mod, sol) { + + # mod is of class modelorg + # sol is the return value of optimizer() + + stopifnot(is(mod, "modelorg"), is(sol, "list")) + + opt <- new("optsol_optimizeProb", + mod_id = mod_id(mod), + mod_key = mod_key(mod), + solver = sol[["solver"]], + method = sol[["method"]], + algorithm = sol[["algorithm"]], + num_of_prob = as.integer(length(sol[["obj"]])), + lp_num_cols = as.integer(sol[["lp_num_cols"]]), + lp_num_rows = as.integer(sol[["lp_num_rows"]]), + lp_obj = as.numeric(sol[["obj"]]), + lp_ok = as.integer(sol[["ok"]]), + lp_stat = as.integer(sol[["stat"]]), + lp_dir = sol[["lp_dir"]], + obj_coef = obj_coef(mod), + obj_func = printObjFunc(mod), + fldind = as.integer(sol[["fldind"]]), + fluxdist = sol[["fluxdist"]], + alg_par = sol[["alg_par"]]) + + + if (!is.null(sol$prAna)) { + preProc(opt) <- sol[["prAna"]] + } + + if (!is.null(sol$poAna)) { + postProc(opt) <- sol[["poAna"]] + } + + return(opt) +} + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# preProc +setMethod("preProc", signature(object = "optsol_optimizeProb"), + function(object) { + return(object@preProc) + } +) + +setReplaceMethod("preProc", signature = (object = "optsol_optimizeProb"), + function(object, value) { + object@preProc <- value + return(object) + } +) + + +# postProc +setMethod("postProc", signature(object = "optsol_optimizeProb"), + function(object) { + return(object@postProc) + } +) + +setReplaceMethod("postProc", signature = (object = "optsol_optimizeProb"), + function(object, value) { + object@postProc <- value + return(object) + } +) diff --git a/R/optsol_phppClass.R b/R/optsol_phppClass.R new file mode 100644 index 0000000..9d788ff --- /dev/null +++ b/R/optsol_phppClass.R @@ -0,0 +1,142 @@ +# optsol_phppClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsol_phppClass + + +#------------------------------------------------------------------------------# +# definition of the class optsol_phpp # +#------------------------------------------------------------------------------# + +setClass("optsol_phpp", + representation( + ctrlflm = "matrix", # fixed flux values of control reactions + redCosts = "matrix" # reduced costs + ), + contains = "optsol_robAna" +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + + +# ctrlfl +setMethod("ctrlfl", signature(object = "optsol_phpp"), + function(object) { + return(object@ctrlflm) + } +) + +setReplaceMethod("ctrlfl", signature = (object = "optsol_phpp"), + function(object, value) { + object@ctrlflm <- value + return(object) + } +) + + +# redCost +setMethod("getRedCosts", signature(lp = "optsol_phpp"), + function(lp) { + return(lp@redCosts) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("plot", signature(x = "optsol_phpp", y = "missing"), + function(x, y, + xlab = list(label = react_id(ctrlr(x)[1]), + rot = 30, + cex = 0.8), + ylab = list(label = react_id(ctrlr(x)[2]), + rot = -40, + cex = 0.8), + zlab = list(label = obj_func(x), + rot = 90, + cex = 0.8), + scales = list(arrows = FALSE, + cex = 0.6, + font = 3, + tck = 1, + col = "black"), + par.settings = list(axis.line = list(col = "transparent")), + shade = TRUE, + shade.colors = function(irr, ref, height, w = 0.75) { + grey(w * irr + (1 - w) * (1-(1-ref)^0.75)) }, + ...) { + + pic <- wireframe(lp_obj(x) ~ ctrlfl(x)[,1] * ctrlfl(x)[,2], + scales = scales, + shade = shade, + par.settings = par.settings, + shade.colors = shade.colors, + xlab = xlab, ylab = ylab, zlab = zlab, ...) + return(pic) + + } +) + +#------------------------------------------------------------------------------# + + +# value for col.regions are the Greys from RColorBrewer: +# brewer.pal(9, "Greys") +# c("#FFFFFF", "#F0F0F0", "#D9D9D9", "#BDBDBD", "#969696", "#737373", +# "#525252", "#252525", "#000000") + +setMethod("plot", signature(x = "optsol_phpp", y = "character"), + function(x, y, #rcbp = "Greys", + main = paste("Reduced Costs:", y), + xlab = react_id(ctrlr(x)[1]), + ylab = react_id(ctrlr(x)[2]), + shrink = c(0.95, 0.95), + #col.regions = colorRampPalette(brewer.pal(brewer.pal.info[rcbp, ][["maxcolors"]], rcbp))(100), + col.regions = colorRampPalette(c("#FFFFFF", "#F0F0F0", + "#D9D9D9", "#BDBDBD", "#969696", "#737373", + "#525252", "#252525", "#000000"))(100), + ...) { + + if (any(is.na(getRedCosts(x)))) { + warning("solution object does not contain reduced costs") + pic <- NA + } + else { + pic <- levelplot( + getRedCosts(x)[ ,y] ~ ctrlfl(x)[,1] * ctrlfl(x)[,2], + xlab = xlab, + ylab = ylab, + main = main, + col.regions = col.regions, + shrink = shrink, ...) + } + return(pic) + } +) + diff --git a/R/optsol_robAnaClass.R b/R/optsol_robAnaClass.R new file mode 100644 index 0000000..18ca689 --- /dev/null +++ b/R/optsol_robAnaClass.R @@ -0,0 +1,106 @@ +# optsol_robAnaClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# optsol_robAnaClass + + +#------------------------------------------------------------------------------# +# definition of the class optsol_robAna # +#------------------------------------------------------------------------------# + +setClass("optsol_robAna", + representation( + ctrlr = "reactId", # id of the control reaction, + ctrlfl = "numeric" # fixed flux values of control reaction + ), + contains = "optsol_optimizeProb" +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# ctrlr +setMethod("ctrlr", signature(object = "optsol_robAna"), + function(object) { + return(object@ctrlr) + } +) + +setReplaceMethod("ctrlr", signature = (object = "optsol_robAna"), + function(object, value) { + object@ctrlr <- value + return(object) + } +) + + +# ctrlfl +setMethod("ctrlfl", signature(object = "optsol_robAna"), + function(object) { + return(object@ctrlfl) + } +) + +setReplaceMethod("ctrlfl", signature = (object = "optsol_robAna"), + function(object, value) { + object@ctrlfl <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("plot", signature(x = "optsol_robAna", y = "missing"), + function(x, y, + xlab = paste("Control Flux:", react_id(ctrlr(x))), + ylab = paste("Objective Function:", obj_func(x)), + type = "b", + pch = 20, + fillColorBg = "grey", + fillBg = TRUE, + absCtrl = TRUE, + ...) { + + if (isTRUE(absCtrl)) { + cr <- abs(x@ctrlfl) + } + else { + cr <- x@ctrlfl + } + + plot(cr, x@lp_obj, type = "n", xlab = xlab, ylab = ylab) + if (isTRUE(fillBg)) { + polygon(c(cr[1], cr, cr[length(cr)]), + c(min(x@lp_obj), x@lp_obj, min(x@lp_obj)), + col = fillColorBg, border = NA) + } + points(cr, x@lp_obj, type = type, pch = pch, ...) + } +) + diff --git a/R/parseBoolean.R b/R/parseBoolean.R new file mode 100644 index 0000000..2e4c77c --- /dev/null +++ b/R/parseBoolean.R @@ -0,0 +1,218 @@ +# parseBoolean.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .parseBoolean +# +# +# The function .parseBoolean() is inspired by the function +# parseBoolean() contained in the COBRA Toolbox. +# The algorithm is the same. + + +.parseBoolean <- function(gprRule, tokens = "()&|~") { + +#.parseBoolean <- function(gprRule, +# tokens = "()&|~", +# allowedElementChars = "[A-Za-z0-9_\\.\\-]") { + + # quit, if there is no gene association + if ( is.na(gprRule) || (gprRule == "") ) { + return(list(gene = "", rule = "")) + } + + # quit, if there is no gene association +# if ( (gprRule == "UNKNOWN") || (gprRule == "SPONTANEOUS") ) { +# return(list(gene = "", rule = "")) +# } + + #print(c("rule: ", gpr)) + +# str <- gpr + gpr <- gsub("and ", "& ", gprRule, ignore.case = TRUE) + gpr <- gsub("or ", "| ", gpr, ignore.case = TRUE) + gpr <- gsub("not ", "~ ", gpr, ignore.case = TRUE) + gpr <- gsub("[", "", gpr, fixed = TRUE) + gpr <- gsub("]", "", gpr, fixed = TRUE) + rule <- gpr + + #print(gpr) + + +# endStr <- str1 + #tmpRule <- matrix() + + + # split the rule into the gene names + genes_tmp <- strsplit(gpr, paste("[", tokens, "]", sep = "")) + + # remove trailing and leading whitespaces + genes_tmp <- gsub("(^\\s+)|(\\s+$)", "", genes_tmp[[1]], perl = TRUE) + + # remove empty entries in genes_tmp + not_empty <- which(nchar(genes_tmp) > 0 ) + genes <- genes_tmp[not_empty] + + # number of entries + num_genes <- length(genes) + + # a unique vector with all genes + gene_uniq <- unique(genes) + + newTok <- match(genes, gene_uniq) + newTok <- sapply(newTok, function(x) paste("x(", x, ")", sep = "")) + +# rule <- + + #bla <- rbind(genes, newTok) + #print("gedoens") + #rule <- apply(bla, 2, function(x) gsub(x[1], x[2], rule, fixed = TRUE)) + #apply(bla, 1, function(x) print(x[1])) + + for (i in 1:num_genes) { + + rule <- sub(genes[i], newTok[i], rule, fixed = TRUE) + #start <- gregexpr(genes[i], gpr, fixed = TRUE) + #start <- start[[1]] + + #end <- start + attr(start, "match.length") + +#print(gpr) +#print(start) +#print(end) + #for (j in 1:length(start)) { + + # print(newTok[i]) + # substr(rule, start[j], (end[j])) <- paste(newTok[i], "") + + #} + + # if () + + } + + + #print("bla") + #print(genes) + #print(genes) + #print(newTok) + #print(rule) + +# cnt <- 0 + +# replace_v <- logical(0) + + + + +# for (i in 1:num_genes) { + +# current_tok <- genes[i] + + # propably we do not need this here, because we did it before + #current_tok <- gsub("[", "", current_tok, fixed = TRUE) + #current_tok <- gsub("]", "", current_tok, fixed = TRUE) + +# start <- gregexpr(current_tok, rule, fixed = TRUE) +# start <- start[[1]] + +# end <- start + attr(start, "match.length") + +# print(c(start, end)) +# print(c("bla", current_tok, genes)) + +# replace <- logical(length(start)) + +# for (j in 1:length(start)) { + # only one token +# if (num_genes == 1) { +# replace[i] <- TRUE +# next +# } +# else { + # token at the beginning +# if (match()) + +# } + +# } + + + + + +# } + + + + + + + + + + + + + + + + + +# for (i in 1:length(genes[[1]])) { +# #current_tok <- gsub("(^\\s+)|(\\s+$)", "", genes[[1]][i], perl = TRUE) +# current_tok <- genes[[1]][i] +# for (i in 1:length(genes)) { + #current_tok <- gsub("(^\\s+)|(\\s+$)", "", genes[[1]][i], perl = TRUE) +# current_tok <- genes[i] +# if (nchar(current_tok) > 0) { + #current_tok <- tokens[[1]][i] + +# if(!match(current_tok, gene, nomatch = 0)) { +# cnt <- cnt + 1 + #gene <- c(gene, current_tok) +# gene[length(gene)+1] <- current_tok +# } + + # the replacement token +# newTok <- paste("x(", cnt, ")", sep = "") + #print(newTok) + + #print(c(current_tok, rule)) + #start <- gregexpr(paste("\\Q", current_tok, "\\E", sep = ""), rule, perl = TRUE) +# } + +# } + + + #tempe <- gregexpr(tokens, endStr) + #temp <- substr(endStr, tokens) +#print(temp) + +# gene = "bla" +# rule = "blubber" + return(list(gene = gene_uniq, rule = rule)) + +} + diff --git a/R/phpp.R b/R/phpp.R new file mode 100644 index 0000000..52496ef --- /dev/null +++ b/R/phpp.R @@ -0,0 +1,125 @@ +# phpp.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: phpp +# +# +# The function phpp() is inspired by the function +# phenotypePhasePlane() contained in the COBRA Toolbox. +# The algorithm is the same. + + +phpp <- function(model, ctrlreact, rng = c(0, 0, 20, 20), + numP = 50, setToZero = TRUE, redCosts = FALSE, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (length(ctrlreact) != 2) { + stop("Please enter two control reactions.") + } + + tmp <- checkReactId(model, ctrlreact) + + if (!is(tmp, "reactId")) { + stop("Check control reaction!") + } + + ctrlr <- react_pos(tmp) + + if (length(rng) != 4) { + stop("rng must have length 4") + } + + rngA <- seq(rng[1], rng[3], length.out = numP) + rngB <- seq(rng[2], rng[4], length.out = numP) + ctrlfl <- as.matrix(expand.grid(rngA, rngB)) + colnames(ctrlfl) <- react_id(tmp) + + num_of_prob <- numP ** 2 + + # reduced costs + ca <- match.call() + if ("poCmd" %in% names(ca)) { + rccmd <- ca[["poCmd"]] + } + else { + if (isTRUE(redCosts)) { + rccmd <- list("getRedCosts") + } + else { + rccmd <- list(NA) + } + } + +#------------------------------------------------------------------------------# +# optimizations # +#------------------------------------------------------------------------------# + + sol <- optimizer(model, + react = rep(list(ctrlr), num_of_prob), + lb = -1*abs(ctrlfl), + ub = -1*abs(ctrlfl), + algorithm = "fba", + setToZero = setToZero, + poCmd = rccmd, ...) + + +#------------------------------------------------------------------------------# +# save the results # +#------------------------------------------------------------------------------# + + optsol <- new("optsol_phpp") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + ctrlr(optsol) <- tmp + ctrlfl(optsol) <- as.matrix(ctrlfl) + + if (isTRUE(redCosts)) { + rc <- pa(postProc(optsol)) + src <- matrix(unlist(rc), + nrow = length(rc), byrow = TRUE)[, ctrlr, drop = FALSE] + if (isTRUE(setToZero)) { + tz <- checkStat(optsol) + src[tz, ] <- 0 + } + colnames(src) <- react_id(tmp) + optsol@redCosts <- src + np <- ppProc(list(NA)) + pa(np) <- list(NA) + postProc(optsol) <- np + } + else { + optsol@redCosts <- as.matrix(NA) + } + + return(optsol) + +} + + + diff --git a/R/ppProcClass.R b/R/ppProcClass.R new file mode 100644 index 0000000..a38a122 --- /dev/null +++ b/R/ppProcClass.R @@ -0,0 +1,106 @@ +# ppProcClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# ppProcClass + + +#------------------------------------------------------------------------------# +# definition of the class ppProc # +#------------------------------------------------------------------------------# + +setClass("ppProc", + representation( + #cmd = "character", + cmd = "list", + pa = "list", + ind = "integer" + ) +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +ppProc <- function(cmd) { + if (missing(cmd)) { + stop("Creating an object of class ppProc needs a list of commands!") + } + + if(is(cmd, "list")) { + cmd <- as.list(cmd) + } + + obj <- new("ppProc", cmd = cmd) + return(obj) +} + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# cmd +setMethod("cmd", signature(object = "ppProc"), + function(object) { + return(object@cmd) + } +) + +setReplaceMethod("cmd", signature = (object = "ppProc"), + function(object, value) { + object@cmd <- value + return(object) + } +) + + +# pa +setMethod("pa", signature(object = "ppProc"), + function(object) { + return(object@pa) + } +) + +setReplaceMethod("pa", signature = (object = "ppProc"), + function(object, value) { + object@pa <- value + return(object) + } +) + + +# ind +setMethod("ind", signature(object = "ppProc"), + function(object) { + return(object@ind) + } +) + +setReplaceMethod("ind", signature = (object = "ppProc"), + function(object, value) { + object@ind <- value + return(object) + } +) diff --git a/R/ppProcessing.R b/R/ppProcessing.R new file mode 100644 index 0000000..fe1f724 --- /dev/null +++ b/R/ppProcessing.R @@ -0,0 +1,134 @@ +# ppProcessing.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: ppProcessing +# +# do some kind of post or pre processing +# +# + + +.ppProcessing <- function(lpprob, ppCmd, loopvar = NA) { + + #----------------------------------------------------------------------# + # run the pre/post processing command + #----------------------------------------------------------------------# + + .runPPcommand <- function(ppCommand) { + + pAnaR <- NA + + if(!is(ppCommand, "character")) { + warning("Each command must be passed as character vector.") + ppC <- NA + } + + if (nchar(ppCommand[1]) < 1) { + warning("The first element of 'ppC' must contain a function name.") + ppC <- NA + } + else { + ppC <- ppCommand + } +# else { +# if(!isTRUE(is.function(eval(parse(text = ppC[1]))))) { +# warning(paste("The first element of 'ppC' must contain a valid", +# "function name." +# ) +# ) +# ppC <- NA +# } +# } + + if (!is.na(ppC[1])) { + narg <- length(ppC) + if (narg == 1) { + ppC <- paste(ppC, "(lpprob)", sep = "") + } + else { + if (!is.na(loopvar)) { + ppC <- gsub("LOOP_VAR", loopvar, ppC, fixed = TRUE) + } + ppC <- gsub("LP_PROB", "lpprob", ppC, fixed = TRUE) + ppC <- paste(ppC[1], "(", + paste(ppC[-1], collapse = ", "), + ")", sep = "" + ) + } + + # run the command + pAnaR <- tryCatch(eval(parse(text = ppC)), error = function(x) x) + if (is(pAnaR, "simpleError")) { + pAnaR <- sybilError(pAnaR) + } + + ppC <- gsub("lpprob", "LP_PROB", ppC, fixed = TRUE) + if (!is.na(loopvar)) { + ppC <- gsub(loopvar, "LOOP_VAR", ppC, fixed = TRUE) + } + + } + + return(list(com = ppC, res = pAnaR)) + } + + +#------------------------------------------------------------------------------# + + + # cmdList: list of commands + # resList: list of results for each command + # instance of class ppProc, if successfull, otherwise NA + + cmdList <- list(NA) + resList <- list(NA) + pAna <- NA + + if (all(!is.na(ppCmd))) { + if (!is(ppCmd, "list")) { + warning("Argument 'ppCmd' must be a list.") + } + else { + tmp_res <- NULL + nCmd <- length(ppCmd) + resList <- vector(mode = "list", length = nCmd) + cmdList <- vector(mode = "list", length = nCmd) + for (i in seq(along = ppCmd)) { + tmp_res <- .runPPcommand(ppCmd[[i]]) + resList[[i]] <- tmp_res[["res"]] + cmdList[[i]] <- tmp_res[["com"]] + tmp_res <- NULL + } + } + + pAna <- ppProc(cmdList) + pa(pAna) <- resList + + } + + return(pAna) +} + + diff --git a/R/prepareSubSysMatrix.R b/R/prepareSubSysMatrix.R new file mode 100644 index 0000000..73215fa --- /dev/null +++ b/R/prepareSubSysMatrix.R @@ -0,0 +1,66 @@ +# prepareSubSysMatrix.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .prepareSubSysMatrix +# +# +# + +.prepareSubSysMatrix <- function(reactSUBS, nreact, entrydelim = NA) { + + if (!is.null(reactSUBS)) { + + reactSsys <- as.character(reactSUBS) + + ssys_tmp <- strsplit(reactSsys, entrydelim, fixed = TRUE) + + sys_names <- unique(unlist(ssys_tmp)) + ssys <- Matrix::Matrix(FALSE, + nrow = length(reactSUBS), + ncol = length(sys_names), + sparse = TRUE) + + colnames(ssys) <- sys_names + + ssys_id <- mapply(match, + ssys_tmp, + MoreArgs = list(sys_names), + SIMPLIFY = FALSE) + + for (i in seq(along = ssys_id)) { + if (length(ssys_id[[i]]) > 0) { + ssys[i, ssys_id[[i]]] <- TRUE + } + } + + } + else { + ssys <- Matrix::Matrix(FALSE, nrow = nreact, ncol = 1, sparse = TRUE) + colnames(ssys) <- NA + } + + return(ssys) + +} diff --git a/R/printLogComment.R b/R/printLogComment.R new file mode 100644 index 0000000..cb24a67 --- /dev/null +++ b/R/printLogComment.R @@ -0,0 +1,48 @@ +# printLogComment.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .printLogComment +# +# +# +# + + +.printLogComment <- function(reason) { + + # log comment will look like this: + + # -------------------------------------------------------- # + ## log <reason>: Day Mon D hh:mm:ss Year + # -------------------------------------------------------- # + + lc1 <- paste("#", paste(rep("-", 56), collapse = ""), "#", collapse = " ") + lc2 <- paste("## log", as.character(reason), date()) + + lc <- paste(lc1, lc2, lc1, "\n", sep = "\n") + + return(lc) + +} diff --git a/R/printNamedList.R b/R/printNamedList.R new file mode 100644 index 0000000..ec65673 --- /dev/null +++ b/R/printNamedList.R @@ -0,0 +1,38 @@ +# printNamedList.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .printNamedList +# +# +# +# + + +.printNamedList <- function(nList, ...) { + na <- names(nList) + for (i in seq(along = na)) { + cat(sprintf("%-20s", na[i]), deparse(nList[[i]]), "\n", ...) + } +} diff --git a/R/progress.R b/R/progress.R new file mode 100644 index 0000000..102495e --- /dev/null +++ b/R/progress.R @@ -0,0 +1,125 @@ +# progress.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Functions for a progress bar and similar stuff +# +# .progressDots: Prints one dot per x loops to +# the standard output. +# Arguments: x the number of loops per dot +# i the current value of the +# loop variable +# total the maximum nuber of loops +# Usage: For example in a for loop: +# for (i in 1:n) { +# .progressDots(x = 10, i, total = n) +# # something time consuming +# } + +# .progressBar: Prints a progress bar to the +# standard output. +# Arguments: i the current value of the +# loop variable +# total the maximum nuber of loops +# symb_drawn the number of printed +# symbols for the bar +# Usage: for example in a for loop: +# progr <- .progressBar() +# for (i in 1:n) { +# progr <- .progressBar(i, total = n, symb_drawn = progr) +# # something time consuming +# } + +.progressDots <- function(x, i, total, symb = ".", num = 40, nl = "\n") { + + # x: one dot per x loops + # i: loop variable + # total: maximum value of i + # symb: printed symbol + # num: maximum number of dots per line + # nl: newline character + + if (i %% x == 0) { # print symb after x loops + cat(symb) + if (i %% 5 == 0) { + cat(" ") + } + if (i %% (x * num) == 0) { # print a newline after num symbs + cat(nl) + } + } + if (i == total) { # print a newline after the last symb + cat(nl) + } + +} + + +.progressBar <- function (i, total, symb_drawn = 0, symb = "=", nl = "\n") { + + # i: loop variable + # total: maximum value of i + # symb_drawn: number of printet symbs + # symb: printed symbol + # nl: newline character + + symb_drawnNEW <- symb_drawn + + if (missing(i) && missing(total)) { + init = TRUE + } + else { + init = FALSE + } + + if (isTRUE(init)) { + # print a timeline + cat("| : | : | 100 %", nl, "|", sep = "") + } + else { + # print(paste("imax " , total, "nSymbols: ", symb_drawn, "i ", i)) + if (symb_drawn < 51) { + + #progress <- round((i/total) * 51, digits = 0) - symb_drawn + progress <- floor((i/total) * 51) - symb_drawn + #print(progress) + symb_drawnNEW <- progress + symb_drawn + + cat(rep(symb, progress)) + #while (progress > 0) { + # cat(symb); + # progress <- progress - 1 + #} + + #return(symb_drawn) + } + #else { + if (i >= total) { + cat("| :-) \n") + } + #} + } + + return(symb_drawnNEW) +} diff --git a/R/promptSysBiolAlg.R b/R/promptSysBiolAlg.R new file mode 100644 index 0000000..a2a0564 --- /dev/null +++ b/R/promptSysBiolAlg.R @@ -0,0 +1,179 @@ +# promptSysBiolAlg.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: promptSysBiolAlg +# +# +# + +promptSysBiolAlg <- function(algorithm, + prefix = "sysBiolAlg", + sep = "_", + suffix = "R", + fpath = ".", + ...) { + + stopifnot(is(algorithm, "character")) + + on.exit( closeAllConnections() ) + + # classname + cname <- paste(prefix, algorithm, sep = sep) + + # filename + fname <- paste(paste(cname, "Class", sep = ""), suffix, sep = ".") + + # path to output file + sbfile <- file.path(fpath, fname) + + sbfh <- try(file(description = sbfile, open = "wt", ...), silent = TRUE) + + if (is(sbfh, "try-error")) { + stop("can not write to file ", sQuote(sbfh)) + } + + #--------------------------------------------------------------------------# + # write file + #--------------------------------------------------------------------------# + + cat("#",rep("-", 78), "#\n", + "# definition of class ", cname, "\n", + "#",rep("-", 78), "#\n", + "\n", + "setClass(Class = \"", cname, "\",\n", + " contains = \"sysBiolAlg\"\n", + ")", + "\n\n", + "#",rep("-", 78), "#\n", + "# default constructor\n", + "#",rep("-", 78), "#\n", + "\n", + "# contructor for class ", cname, "\n", + sep = "", file = sbfh) + + cat("setMethod(f = \"initialize\",\n", + " signature = \"", cname, "\",\n", + " definition = function(.Object,\n", + " model,\n", + "## PLACE FURTHER ARGUMENTS TO CONSTRUCTOR HERE ##\n", + "## ARGUMENT '...' SHOULD BE LEFT FOR ARGUMENTS ##\n", + "## 'solver', 'method', 'solverParm', 'termOut' AND 'retAlgPar' ##\n", + " useNames = SYBIL_SETTINGS(\"USE_NAMES\"),\n", + " cnames = NULL,\n", + " rnames = NULL,\n", + " pname = NULL,\n", + " scaling = NULL,\n", + " writeProbToFileName = NULL, ...) {\n\n", + sep = "", file = sbfh, append = TRUE) + + + + + cat(" if ( ! missing(model) ) {\n", + "\n", + " stopifnot(is(model, \"modelorg\"),\n", + "## PLACE FURTHER ARGUMENT TESTS HERE ##\n", + " )\n\n", + sep = "", file = sbfh, append = TRUE) + + + cat("## GENERATE ROW AND COLUMN NAMES FOR ##\n", + "## THE PROBLEM OBJECT (OPTIONALLY) ##\n", + sep = "", file = sbfh, append = TRUE) + + cat(" if (isTRUE(useNames)) {\n", + " # you maybe want to do something more fancy here:\n", + " # e.g. use .makeLPcompatible() for a default value\n", + " colNames <- cnames\n", + " rowNames <- rnames\n", + " probName <- pname\n", + " }\n", + " else {\n", + " colNames <- NULL\n", + " rowNames <- NULL\n", + " probName <- NULL\n", + " }\n\n", + sep = "", file = sbfh, append = TRUE) + + cat("## GENERATE DATA STRUCTURES TO USE FOR ##\n", + "## BUILDING THE PROBLEM OBJECT VIA THE DEFAULT ##\n", + "## CONSTRUCTOR FOR CLASS sysBiolAlg ##\n", + sep = "", file = sbfh, append = TRUE) + + + cat("\n", sep = "", file = sbfh, append = TRUE) + + cat(" # use the default constructor for class sysBiolAlg\n", + " .Object <- callNextMethod(.Object,\n", + " sbalg = \"", algorithm, "\",\n", + " pType = \n", + " scaling = scaling,\n", + " fi = \n", + " nCols = \n", + " nRows = \n", + " mat = \n", + " ub = \n", + " lb = \n", + " obj = \n", + " rlb = \n", + " rtype = \n", + " lpdir = \n", + " rub = \n", + " ctype = \n", + " cnames = colNames,\n", + " rnames = rowNames,\n", + " pnames = probName,\n", + " algPar = list(),\n", + " ...)\n\n", + sep = "", file = sbfh, append = TRUE) + + cat(" # write problem to lp file\n", + " if (!is.null(writeToFileName)) {\n", + " writeProb(problem(.Object),\n", + " fname = as.character(writeProbToFileName))\n", + " }\n\n", + sep = "", file = sbfh, append = TRUE) + + cat(" validObject(.Object)\n", + sep = "", file = sbfh, append = TRUE) + + cat(" }\n", sep = "", file = sbfh, append = TRUE) + cat(" return(.Object)\n", sep = "", file = sbfh, append = TRUE) + cat(" }\n", sep = "", file = sbfh, append = TRUE) + cat(")\n", sep = "", file = sbfh, append = TRUE) + + #--------------------------------------------------------------------------# + # end + #--------------------------------------------------------------------------# + + if ( (is(sbfh, "file")) && (isOpen(sbfh)) ) { + close(sbfh) + } + + message("created file ", sQuote(sbfile)) + + return(invisible(NULL)) + +} diff --git a/R/reactIdClass.R b/R/reactIdClass.R new file mode 100644 index 0000000..ca6b6d5 --- /dev/null +++ b/R/reactIdClass.R @@ -0,0 +1,189 @@ +# reactIdClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# reactIdClass + + +#------------------------------------------------------------------------------# +# definition of the class reactId # +#------------------------------------------------------------------------------# + +setClass("reactId", + representation( + mod_id = "character", + mod_key = "character", + react_pos = "integer", + react_id = "character", + react_num = "integer" + ), + validity = .validreactId +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +setMethod(f = "initialize", + signature = "reactId", + definition = function(.Object, mod_id, pnt, id = NULL, mod_key = "") { + + if ( (!missing(mod_id)) || (!missing(pnt)) ) { + + nr <- length(pnt) + + .Object@mod_id <- as.character(mod_id) + .Object@mod_key <- as.character(mod_key) + .Object@react_pos <- as.integer(pnt) + .Object@react_id <- as.character(id) + .Object@react_num <- as.integer(nr) + validObject(.Object) + } + + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# mod_id +setMethod("mod_id", signature(object = "reactId"), + function(object) { + return(object@mod_id) + } +) + +setReplaceMethod("mod_id", signature = (object = "reactId"), + function(object, value) { + object@mod_id <- value + return(object) + } +) + + +# mod_key +setMethod("mod_key", signature(object = "reactId"), + function(object) { + return(object@mod_key) + } +) + +setReplaceMethod("mod_key", signature = (object = "reactId"), + function(object, value) { + object@mod_key <- value + return(object) + } +) + + +# position +setMethod("react_pos", signature(object = "reactId"), + function(object) { + return(object@react_pos) + } +) + +setReplaceMethod("react_pos", signature = (object = "reactId"), + function(object, value) { + object@react_pos <- value + return(object) + } +) + + +# react_id +setMethod("react_id", signature(object = "reactId"), + function(object) { + return(object@react_id) + } +) + +setReplaceMethod("react_id", signature = (object = "reactId"), + function(object, value) { + object@react_id <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("show", signature(object = "reactId"), + function(object) { + wcn <- trunc(log10(length(object))) + 3 + cn <- paste("[", 1:length(object), "]", sep = "") + cat(sprintf(paste("%", wcn, "s ", "%-11s%s\n", sep = ""), + "# " ,"position", "reaction id")) + cat(sprintf(paste("%", wcn, "s ", "%-11s%s", sep = ""), + cn, react_pos(object), react_id(object)), sep = "\n") + cat("\nnumber of reactions: ", length(object), "\n", sep = "") + } +) + + +# length of an object of class reactId +setMethod("length", signature(x = "reactId"), + function(x) { + return(x@react_num) + } +) + + +# [ +setMethod("[", signature(x = "reactId"), + function(x, i, j, ..., drop = FALSE) { + + if ( (missing(i)) || (length(i) == 0) ) { + return(x) + } + + if (is(i, "character")) { + ind <- match(i, react_id(x)) + } +# else if (is(i, "reactId")) { +# ind <- which(react_pos(x) %in% react_pos(i)) +# } + else { + ind <- i + } + + if (max(ind, na.rm = TRUE) > length(x)) { + stop("subscript out of bounds") + } + + newRI <- new("reactId", + mod_id = x@mod_id, + pnt = x@react_pos[ind], + id = x@react_id[ind]) + + return(newRI) + + } +) + diff --git a/R/reactId_ExchClass.R b/R/reactId_ExchClass.R new file mode 100644 index 0000000..a09be51 --- /dev/null +++ b/R/reactId_ExchClass.R @@ -0,0 +1,235 @@ +# reactId_ExchClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# reactId_ExchClass + + +#------------------------------------------------------------------------------# +# definition of the class reactId_Exch # +#------------------------------------------------------------------------------# + +setClass("reactId_Exch", + representation( + uptake = "logical", + met_pos = "integer", + met_id = "character", + lowbnd = "numeric", + uppbnd = "numeric" + ), + contains = "reactId", + validity = .validreactId_Exch +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +setMethod(f = "initialize", + signature = "reactId_Exch", + definition = function(.Object, mod_id, mod_key = "", + rpnt, rid, upt, mpnt, mid, lb, ub) { + + if ( (!missing(mod_id)) || + (!missing(mod_key)) || + (!missing(rpnt)) || + (!missing(rid)) || + (!missing(upt)) || + (!missing(mpnt)) || + (!missing(mid)) || + (!missing(lb)) || + (!missing(ub)) ) { + + tmp <- new("reactId", + mod_id = mod_id, + mod_key = mod_key, + pnt = rpnt, + id = rid) + as(.Object, "reactId_Exch") <- tmp + + .Object@uptake <- as.logical(upt) + .Object@met_pos <- as.integer(mpnt) + .Object@met_id <- as.character(mid) + .Object@lowbnd <- as.numeric(lb) + .Object@uppbnd <- as.numeric(ub) + validObject(.Object) + } + + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# position +setMethod("met_pos", signature(object = "reactId_Exch"), + function(object) { + return(object@met_pos) + } +) + +setReplaceMethod("met_pos", signature = (object = "reactId_Exch"), + function(object, value) { + object@met_pos <- value + return(object) + } +) + + +# met_id +setMethod("met_id", signature(object = "reactId_Exch"), + function(object) { + return(object@met_id) + } +) + +setReplaceMethod("met_id", signature = (object = "reactId_Exch"), + function(object, value) { + object@met_id <- value + return(object) + } +) + + +# lowbnd +setMethod("lowbnd", signature(object = "reactId_Exch"), + function(object) { + return(object@lowbnd) + } +) + +setReplaceMethod("lowbnd", signature = (object = "reactId_Exch"), + function(object, value) { + object@lowbnd <- value + return(object) + } +) + + +# uppbnd +setMethod("uppbnd", signature(object = "reactId_Exch"), + function(object) { + return(object@uppbnd) + } +) + +setReplaceMethod("uppbnd", signature = (object = "reactId_Exch"), + function(object, value) { + object@uppbnd <- value + return(object) + } +) + + +# uptake +setMethod("uptake", signature(object = "reactId_Exch"), + function(object) { + return(object@uptake) + } +) + +setReplaceMethod("uptake", signature = (object = "reactId_Exch"), + function(object, value) { + object@uptake <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("show", signature(object = "reactId_Exch"), + function(object) { + wcn <- trunc(log10(length(object))) + 3 + cn <- paste("[", 1:length(object), "]", sep = "") + lb <- ifelse(lowbnd(object) <= SYBIL_SETTINGS("MAXIMUM")*-1, -Inf, lowbnd(object)) + ub <- ifelse(uppbnd(object) >= SYBIL_SETTINGS("MAXIMUM"), Inf, uppbnd(object)) + cat(sprintf(paste("%", wcn, "s ", "%-6s%-22s%-23s%-7s%6s %6s\n", sep = ""), + "# ", "pos.", "reaction id", "metabolite id", "uptake", "lb", "ub")) + cat(sprintf(paste("%", wcn, "s ", "%-6s%-22s%-23s%-7s%6s %6s", sep = ""), + cn, react_pos(object), react_id(object), + met_id(object), uptake(object), lb, ub), sep = "\n") + cat("\nnumber of exchange reactions: ", length(object), "\n", sep = "") + } +) + + +# uptReact +setMethod("uptReact", signature(object = "reactId_Exch"), + function(object) { + return(object@react_id[object@uptake]) + } +) + + +# uptMet +setMethod("uptMet", signature(object = "reactId_Exch"), + function(object) { + return(object@met_id[object@uptake]) + } +) + + +# [ +setMethod("[", signature(x = "reactId_Exch"), + function(x, i, j, ..., drop = FALSE) { + + if ( (missing(i)) || (length(i) == 0) ) { + return(x) + } + + if (is(i, "character")) { + ind <- match(i, react_id(x)) + } +# else if (is(i, "reactId")) { +# ind <- which(react_pos(x) %in% react_pos(i)) +# } + else { + ind <- i + } + + if (max(ind, na.rm = TRUE) > length(x)) { + stop("subscript out of bounds") + } + + newRI <- new("reactId_Exch", + mod_id = x@mod_id, + mod_key = x@mod_key, + rpnt = x@react_pos[ind], + rid = x@react_id[ind], + upt = x@uptake[ind], + mpnt = x@met_pos[ind], + mid = x@met_id[ind], + lb = x@lowbnd[ind], + ub = x@uppbnd[ind]) + + return(newRI) + + } +) diff --git a/R/readTEXTmod.R b/R/readTEXTmod.R new file mode 100644 index 0000000..8746664 --- /dev/null +++ b/R/readTEXTmod.R @@ -0,0 +1,546 @@ +# readTEXTmod.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: readTEXTmod +# +# +# + +readTEXTmod <- function(filename, + description, + def_bnd = SYBIL_SETTINGS("MAXIMUM")) { + +if ( file.exists(filename) == FALSE ) { + stop( c("cannot open file ", filename) ) +} + +if (missing(description)) { + description <- filename +} + + +#------------------------------------------------------------------------------# +# some functions # +#------------------------------------------------------------------------------# + +parse_metabolites <- function(reactands, fwbw) { + + new_met <- character(0) + + stoichnum <- gregexpr("\\b[0-9]+(\\.[0-9]*)?\\b", reactands) + + # the metabolites -> \w{2,} so we do not get the "+" + #print(ed_prod[1]) + metabolites <- gregexpr("([0-9]+(\\.[0-9]*)?\\s)?\\w{2,}\\b", reactands) + #print(metabolites) + + + for (l in 1:length(metabolites[[1]])) { + metabolite <- substr(reactands, metabolites[[1]][l], metabolites[[1]][l] + attr(metabolites[[1]], "match.length")[l] - 1) + print(metabolite) + + + stoich_met <- unlist(strsplit(metabolite, " ", fixed = TRUE)) + if (length(stoich_met) == 1) { + stoich <- 1 * fwbw + met <- stoich_met + } + else { + stoich <- as.numeric(stoich_met[1]) * fwbw + met <- stoich_met[2] + } + + # exclude external metabolites + if (regexpr("ex$", met) != -1) { + next + } + + met_number <- which(met_id %in% met) + print(met_number) + # new metabolite + if (length(met_number) == 0) { + # add a new row to S + if (length(met_id) > 0) { + S <- rbind(S, numeric(dim(S)[2])) + } + met_id <- c(met_id, met) + S[length(met_id), num_react] <- stoich + } + + # existing metabolite + if (length(met_number) == 1) { + S[met_number, num_react] <- stoich + } + + # existing metabolite + if (length(met_number) > 1) { + stop(paste("Error in line ", i, ": check metabolite ", met, "!", sep = "")) + } + + } + +} + +#------------------------------------------------------------------------------# + +parse_genes <- function(gene) { + + if (length(gene) == 0) { + return(list(gpr_str = "", rules_str = "", gene_vec = "")) + } + + # for the gpr slot and gprRules slot + gene_pos <- which(allGenes %in% gene) + if (length(gene) > 1) { + gpr_string <- paste("(", paste(gene, sep = "", collapse = " and "), ")") + rules_string <- paste("x[", gene_pos, "]", sep = "") + rules_string <- paste("(", paste(rules_string, sep = "", collapse = " & "), ")") + } + else { + gpr_string <- gene + rules_string <- paste("x[", gene_pos, "]", sep = "") + } +# print(gpr_string) +# print(rules_string) + return(list(gpr_str = gpr_string, rules_str = rules_string, gene_vec = gene)) + +} + +#------------------------------------------------------------------------------# + +get_stoich_met <- function(reactand) { + + stoich_met <- unlist(strsplit(reactand, " ", fixed = TRUE)) + + if (length(stoich_met) == 2) { + if(is.na(as.numeric(stoich_met[1]))) { + print(reactand) + stop(paste("Something went wrong in line", i, "with a stoichiometric number!")) + } + + stoich <- as.numeric(stoich_met[1]) + met <- stoich_met[2] + } + if (length(stoich_met) == 1) { + stoich <- 1 + met <- stoich_met[1] + } + if (length(stoich_met) > 2) { + stop(paste("Something went wrong in line", i)) + } + + return(list(stoich = stoich, met = met)) + +} + + +#------------------------------------------------------------------------------# +# reading the model # +#------------------------------------------------------------------------------# + +message("reading the model ...", appendLF = FALSE) + +ModelTmp <- readLines(filename) +num_lines <- length(ModelTmp) + +# The new model +Model <- modelorg(filename, filename) +mod_desc(Model) <- filename + +message(" OK.") + + +# needed variables + +met_id <- character(0) +react_id <- character(0) +react_name <- character(0) +react_rev <- logical(0) +num_react <- 0 +num_met <- 0 + +ext_met <- character(0) + +S <- matrix(0) + +genes <- list() +rules <- character(0) +gpr <- character(0) +allGenes <- character(0) + +lowbnd <- numeric(0) +uppbnd <- numeric(0) + +external_metabolites <- character(0) + +message("parsing reactions ...", appendLF = FALSE) + +last_reactions <- character(0) +reactions <- strsplit(ModelTmp, "\t|[ ]{4}") +#reactions <- strsplit(ModelTmp, "\t") + +for (i in 1 : num_lines) { + +# print(i) +# print(length(gpr)) +# print(length(genes)) +# print("") + + current_genes <- character(0) + + # ignore empty lines + if (length(reactions[[i]]) == 0) {next} + + # Lines beginning with a # are treated as comment lines. + if (substr(reactions[[i]][1], 0, 1) == "#") {next} + + # Do here somethin with the first line + + + #print(reactions[[i]][3]) + #print("last") + #print(last_reactions) + + + # reactions we already have + # We should do here the same as in doubleGenes(): check S for that task. + # That will be more safer to typos. + lrids <- which(last_reactions %in% reactions[[i]][3]) + #print(lrids) + if (length(lrids) == 1) { + + # react_name slot + tmp_name <- unlist(strsplit(react_name[lrids], ":", fixed = TRUE)) + tmp_name[1] <- paste(tmp_name[1], reactions[[i]][2], sep = "|") + react_name[lrids] <- paste(tmp_name[1], tmp_name[2], sep = ":") + + + current_genes <- unlist(strsplit(reactions[[i]][1], "/", fixed = TRUE)) + + # allGenes slot + allGenes <- unlist(union(allGenes, current_genes)) + + gene_list <- parse_genes(current_genes) + + # genes slot + genes[[lrids]] <- c(genes[[lrids]], gene_list$gene_vec) + + if (gpr[lrids] == "") { + gpr[lrids] <- gene_list$gpr_str + rules[lrids] <- gene_list$rules_str + } + else { + gpr[lrids] <- paste(gpr[lrids], gene_list$gpr_str, sep = " or ") + rules[lrids] <- paste(rules[lrids], gene_list$rules_str, sep = " | ") + } + + next + } + + if (length(lrids) > 1) { + stop(paste("Error!", i)) + } + + num_react <- num_react + 1 + + exchange_reaction <- FALSE + + # add a new column to S + if (dim(S)[1] != 1) { + S <- cbind(S, numeric(dim(S)[1])) + } + + # react_id slot + react_id <- c(react_id, paste("v", num_react, sep = "")) + + # react_name slot + react_name <- c(react_name, paste(reactions[[i]][2], reactions[[i]][3], sep = ": ")) + + current_genes <- unlist(strsplit(reactions[[i]][1], "/", fixed = TRUE)) + + # allGenes slot + allGenes <- unlist(union(allGenes, current_genes)) + + + gene_list <- parse_genes(current_genes) + + # genes slot + genes[[length(genes) + 1]] <- gene_list$gene_vec + gpr <- c(gpr, gene_list$gpr_str) + rules <- c(rules, gene_list$rules_str) + + # parse reactions + + # get the reaction arrow (maybe there is a more elegant way to do this) + #dir_coord <- regexpr("[<>-]+", reactions[[i]][3]) + dir_coord <- regexpr("(<-+)|(-+>)|(<-+>)", reactions[[i]][3]) + direction <- substr(reactions[[i]][3], dir_coord[1], dir_coord[1] + attr(dir_coord, "match.length") - 1) + +# print(reactions[[i]][3]) + + ed_prod <- unlist(strsplit(reactions[[i]][3], direction, fixed = TRUE)) + if (length(ed_prod) != 2) { + #print(reactions[[i]]) + #print(ed_prod) + stop(paste("Reaction in line", i, "is strange!")) + } +# print(ed_prod) + + + # check direction of reaction + check <- logical(2) + + # backward + if (regexpr("^<", direction) != -1) { + check[1] <- TRUE + } + + # forward + if (regexpr(">$", direction) != -1) { + check[2] <- TRUE + } + + # reaction is reversible + if (all(check == TRUE)) { + react_rev <- c(react_rev, TRUE) + } + else { + if (all(check == FALSE)) { + stop(paste("Maybe no reaction arrow in line", i, "?")) + } + + # backward + if (check[1] == TRUE) { + react_rev <- c(react_rev, FALSE) + ed_prod <- rev(ed_prod) + } + + # forward + if (check[2] == TRUE) { + react_rev <- c(react_rev, FALSE) + } + } + + ## Here some work is still to do --> create functions + + # The Educts + + + reactands <- unlist(strsplit(ed_prod[1], " + ", fixed = TRUE)) + reactands <- sub("^\\s|\\s+$", "", reactands) + + for (l in 1:length(reactands)) { + + st_me_list <- get_stoich_met(reactands[l]) + + stoich <- st_me_list$stoich * -1 + met <- st_me_list$met + + if (regexpr("xt$", met) != -1) { + ext_met <- c(ext_met, met) + } + + met_number <- which(met_id %in% met) + #print(met_number) + # new metabolite + if (length(met_number) == 0) { + num_met <- num_met + 1 + # add a new row to S + if (length(met_id) > 0) { + S <- rbind(S, numeric(dim(S)[2])) + } + met_id <- c(met_id, met) + S[num_met, num_react] <- stoich + } + + # existing metabolite + if (length(met_number) == 1) { + S[met_number, num_react] <- stoich + } + + # existing metabolite + if (length(met_number) > 1) { + stop(paste("Error in line ", i, ": check metabolite ", met, "!", sep = "")) + } + + + } + + + # The Products + + reactands <- unlist(strsplit(ed_prod[2], " + ", fixed = TRUE)) + reactands <- sub("^\\s|\\s+$", "", reactands) + + for (l in 1:length(reactands)) { + + st_me_list <- get_stoich_met(reactands[l]) + + stoich <- st_me_list$stoich + met <- st_me_list$met + + if (regexpr("xt$", met) != -1) { + ext_met <- c(ext_met, met) + } + + met_number <- which(met_id %in% met) + #print(met_number) + # new metabolite + if (length(met_number) == 0) { + num_met <- num_met + 1 + # add a new row to S + if (length(met_id) > 0) { + S <- rbind(S, numeric(dim(S)[2])) + } + met_id <- c(met_id, met) + S[num_met, num_react] <- stoich + } + + # existing metabolite + if (length(met_number) == 1) { + S[met_number, num_react] <- stoich + } + + # existing metabolite + if (length(met_number) > 1) { + stop(paste("Error in line ", i, ": check metabolite ", met, "!", sep = "")) + } + + + } + + # the lower and upper bounds + + # lower + + if (length(reactions[[i]]) > 3) { + lowbnd <- c(lowbnd, as.numeric(reactions[[i]][4])) + } + else { + if (all(check == TRUE)) { + lowbnd <- c(lowbnd, def_bnd * -1) + } + else { + lowbnd <- c(lowbnd, 0) + } + } + + + # upper + + if (length(reactions[[i]]) > 4) { + uppbnd <- c(uppbnd, as.numeric(reactions[[i]][5])) + } + else { + uppbnd <- c(uppbnd, def_bnd) + } + + last_reactions <- c(last_reactions, reactions[[i]][3]) + +} + +message(" OK.") + + +# exchange reactions + +if (length(ext_met) > 0) { + + message("exchange reactions ...", appendLF = FALSE) + + ext_met <- unique(ext_met) + num_ext_met <- length(ext_met) + ext_met_ids <- which(met_id %in% ext_met) + + + S <- cbind(S, matrix(0, num_met, num_ext_met)) + #apply(as.matrix(c(1:num_ext_met)), 1, function(x) S[ext_met_ids[x], (num_react + x)] <- -1) + for (i in 1:num_ext_met) { + S[ext_met_ids[i], (num_react + i)] <- -1 + } + + num_react <- num_react + num_ext_met + + react_id <- c(react_id, paste("b", c(1:num_ext_met), sep = "")) + react_name <- c(react_name, paste(ext_met, "exchange", sep = "_")) + react_rev <- c(react_rev, rep(TRUE, num_ext_met)) + + uppbnd <- c(uppbnd, rep(def_bnd, num_ext_met)) + lowbnd <- c(lowbnd, rep(0, num_ext_met)) + + gpr <- c(gpr, rep("", num_ext_met)) + rules <- c(rules, rep("", num_ext_met)) + genes[length(genes):num_react] <- "" + + + message(" Ok.") + +} + + + +# rxnGeneMat + +message("GPR mapping ...", appendLF = FALSE) +genes_ind <- lapply(genes, function(x) allGenes %in% x) + +rxnGeneMat <- matrix(0, num_react, length(allGenes)) + +for (i in seq(along = genes_ind)) { + rxnGeneMat[i, genes_ind[[i]]] <- 1 +} +message(" Ok.") + + + + +met_id(Model) <- met_id +react_id(Model) <- react_id +react_name(Model) <- react_name +react_rev(Model) <- react_rev +react_num(Model) <- as.integer(num_react) +met_num(Model) <- as.integer(num_met) + +S(Model) <- S + +genes(Model) <- genes +gprRules(Model) <- rules +gpr(Model) <- gpr +allGenes(Model) <- allGenes +rxnGeneMat(Model) <- rxnGeneMat + +obj_coef(Model) <- integer(num_react) + +uppbnd(Model) <- uppbnd +lowbnd(Model) <- lowbnd +# uppbnd(Model) <- rep(def_bnd, num_react) +# lowbnd(Model) <- integer(num_react) +# lowbnd(Model)[react_rev] <- def_bnd * -1 + +return(Model) + + + +} diff --git a/R/readTSVmod.R b/R/readTSVmod.R new file mode 100644 index 0000000..f66c1bd --- /dev/null +++ b/R/readTSVmod.R @@ -0,0 +1,1378 @@ +# readTSVmod.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: readTSVmod +# +# +# + +readTSVmod <- function(prefix, suffix, + reactList, metList = NA, modDesc = NA, + fielddelim = "\t", entrydelim = ", ", extMetFlag = "b", + excludeComments = TRUE, + oneSubSystem = TRUE, + mergeMet = TRUE, + balanceReact = TRUE, + remUnusedMetReact = TRUE, + singletonMet = FALSE, + deadEndMet = FALSE, + remMet = FALSE, + constrMet = FALSE, + tol = SYBIL_SETTINGS("TOLERANCE"), + fpath = SYBIL_SETTINGS("PATH_TO_MODEL"), + def_bnd = SYBIL_SETTINGS("MAXIMUM"), + arrowlength = NULL, + quoteChar = "", + commentChar = "", + ...) { + + + #--------------------------------------------------------------------------# + + if (missing(suffix)) { + fnEXT <- switch(fielddelim, + "\t" = { "tsv" }, + ";" = { "csv" }, + "," = { "csv" }, + "|" = { "dsv" }, + { "dsv" } + ) + } + else { + fnEXT <- suffix + } + + # if argument prefix is empty, at least reactList must be not empty. + if (missing(prefix)) { + if (missing(reactList)) { + stop("missing argument 'reactList' is required") + } + else { + fnRL <- reactList + fnML <- metList + fnMD <- modDesc + } + } + else { + # filename + fnRL <- paste(paste(prefix, "react", sep = "_"), fnEXT, sep = ".") + fnML <- paste(paste(prefix, "met", sep = "_"), fnEXT, sep = ".") + fnMD <- paste(paste(prefix, "desc", sep = "_"), fnEXT, sep = ".") + } + + # file path + fpRL <- file.path(fpath, fnRL) + fpML <- file.path(fpath, fnML) + fpMD <- file.path(fpath, fnMD) + + + if (!isTRUE(file.exists(fpRL))) { + stop("failed to open reaction list ", sQuote(fpRL)) + } + + if (!isTRUE(file.exists(fpML))) { + fpML <- NULL + } + + if (!isTRUE(file.exists(fpMD))) { + fpMD <- NULL + } + + + #--------------------------------------------------------------------------# + # some regular expressions + #--------------------------------------------------------------------------# + + # delimiter for the compartment flag (round or square bracket) + #compartDelimL <- "\\[" + #compartDelimR <- "\\]" + compartDelimL <- "(\\[|\\()" + compartDelimR <- "(\\]|\\))" + compartCharSet <- "(\\w+)" + + # regular expression for the compartment flag + compartRegEx <- paste(compartDelimL, compartCharSet, compartDelimR, sep = "") + compartRegExEnd <- paste(compartRegEx, "$", sep = "") + + # regular expression to identify external metabolites + extMetRegEx <- paste(compartDelimL, extMetFlag, compartDelimR, sep = "") + #extMetRegEx <- paste("\\[", extMetFlag, "\\]$", sep = "") + + + # regular expression to identify the reaction arrow + if (is.null(arrowlength)) { + arrowregex <- "<?[-=]+>" + } + else { + stopifnot(length(arrowlength) == 1) + if (is.numeric(arrowlength)) { + arrowregex <- paste("<?[-=]{", arrowlength, "}>", sep = "") + } + else if (is.character(arrowlength)) { + arrowregex <- paste("<?[-=]", arrowlength, ">", sep = "") + } + } + + + #--------------------------------------------------------------------------# + # some functions + #--------------------------------------------------------------------------# + + prepReact <- function(metabolites, educts, rowind) { + + components <- unlist(strsplit(metabolites, "+", fixed = TRUE)) + nc <- length(components) + + # data structures + nNewMet <- logical(nc) + newMetId <- character(nc) + newMetCo <- character(nc) + + newRowIA <- integer(nc) + newRowRA <- integer(nc) + + # column indices (reactions, lines in the input file) in S + newRowJA <- as.integer(rep(rowind, nc)) + + # FALSE if a metabolite is not used, e.g. external metabolites, + # or metabolites which are used more than once as educt or product. + USE_MET <- logical(nc) + + CURR_MET <- character(nc) # metabolites in components + + for (j in seq(along = components)) { + + components[j] <- paste(components[j], compfl, sep = "") + + # exclude external metabolites + if (regexpr(extMetRegEx, components[j], + perl = TRUE, ignore.case = TRUE) == -1) { + + USE_MET[j] <- TRUE + + # stoichiometric coefficient must be in round bracket + stoichpos <- regexpr("^\\([^)]+\\)", components[j], perl = TRUE) + #stoichpos <- regexpr("^\\(.+\\)", components[j], perl = TRUE) + if (stoichpos == 1) { + st_str <- substr(components[j], 2, + (-1+attr(stoichpos, "match.length"))) + stoich <- as.numeric(st_str) + + # the stoichiometric coefficient must be a number + if (is.na(stoich)) { + msg <- paste("reaction no.", rowind, + dQuote(reactABBR[rowind]), + "stoichiometric coefficient", + dQuote(st_str), "in file", dQuote(fpRL), + "is not numeric, set to '1'.") + warning(msg, call. = FALSE) + stoich <- 1 + } + + currentMet <- substr(components[j], + (1+attr(stoichpos, "match.length")), + nchar(components[j])) + } + else { + stoich <- 1 + currentMet <- components[j] + } + + + # put the compartment flag into a square bracket + CURR_MET[j] <- sub(compartRegExEnd, "[\\2]", currentMet, perl = TRUE) + #CURR_MET[j] <- currentMet + + stoich <- ifelse(isTRUE(educts), (stoich * -1), stoich) + + + # cid contains the compartment abbreviation for the current + # metabolite (excluding '[]') + cidpos <- regexpr(compartRegExEnd, components[j], perl = TRUE) + #cidpos <- regexpr("\\[\\w+\\]$", components[j], perl = TRUE) + if (cidpos < 0) { + cid <- "unknown" + } + else { + cid <- substr(components[j], (cidpos+1), + (cidpos+attr(cidpos, "match.length")-2)) + } + + + # check if the metabolite is used more than once in + # the current reaction as educt or product + if (isTRUE(mergeMet)) { + met_indexCURR <- match(CURR_MET[j], CURR_MET[-j]) + } + else { + met_indexCURR <- NA + } + + if (is.na(met_indexCURR)) { + + # the non zero element in S for the current metabolite + newRowRA[j] <- stoich + + # check if we have a new metabolite + met_index <- match(CURR_MET[j], Rmet) + if (is.na(met_index)) { + + # new metabolite: new row in S + nNewMet[j] <- TRUE + newMetId[j] <- CURR_MET[j] + newMetCo[j] <- paste("[", cid, "]", sep = "") + newRowIA[j] <- as.integer(sum(nNewMet) + NRmet) + } + else { + # existing metabolite + nNewMet[j] <- FALSE + newRowIA[j] <- as.integer(met_index) + } + + } + else { + # e.g.: if we have a + a, we merge it to (2) a + USE_MET[j] <- FALSE + newRowRA[met_indexCURR] <- newRowRA[met_indexCURR] + stoich + msg <- paste("reaction no.", rowind, + dQuote(reactABBR[rowind]), + "metabolite no.", j, dQuote(CURR_MET[j]), + "was merged") + warning(msg, call. = FALSE) + } + + + } + else { + + } + } + + return(list(nNewMet = sum(nNewMet), + newMetId = newMetId[nNewMet], + newMetCo = newMetCo[nNewMet], + + newRowIA = newRowIA[USE_MET], + newRowJA = newRowJA[USE_MET], + newRowRA = newRowRA[USE_MET])) + + } + + + #--------------------------------------------------------------------------# + # model description + #--------------------------------------------------------------------------# + + newModelName <- sub("(_react)?\\.[^.]+$", "", basename(fpRL), perl = TRUE) + + if (is.null(fpMD)) { + + modNM <- newModelName # name + modID <- newModelName # id + modDC <- "" # description + modCO <- NULL # compartments + modCA <- NULL # compartment abbreviations + modNmet <- NULL # number of metabolites + modNreact <- NULL # number of reactions + modNgenes <- NULL # number of genes + modNnnz <- NULL # number of non-zero elements in S + } + else { + message("reading model description, ... ", appendLF = FALSE) + + md <- read.table(fpMD, + header = TRUE, + sep = fielddelim, + quote = quoteChar, + comment.char = commentChar, ...) + + # The first line containing data (second line in file) is used. + # Everything else will be ignored. + modNM <- try(as.character(md[ ,"name"]), silent = TRUE) + modID <- try(as.character(md[ ,"id"]), silent = TRUE) + modDC <- try(as.character(md[ ,"description"]), silent = TRUE) + modCO <- try(as.character(md[ ,"compartment"]), silent = TRUE) + modCA <- try(as.character(md[ ,"abbreviation"]), silent = TRUE) + modNmet <- try(as.integer(md[ ,"Nmetabolites"]), silent = TRUE) + modNreact <- try(as.integer(md[ ,"Nreactions"]), silent = TRUE) + modNgenes <- try(as.integer(md[ ,"Ngenes"]), silent = TRUE) + modNnnz <- try(as.integer(md[ ,"Nnnz"]), silent = TRUE) + + if (is(modNM, "try-error")) { + warning("field 'name' is obligatory in model description") + modNM <- newModelName + } + else { + nal <- .checkEmptyField(modNM, "name") + if (!is.null(nal)) { + #stop(nal[["msg"]], call. = FALSE) + modNM <- newModelName + } + } + + if (is(modID, "try-error")) { + warning("field 'id' is obligatory in model description.") + modID <- newModelName + } + else { + nal <- .checkEmptyField(modID, "id") + if (!is.null(nal)) { + #stop(nal[["msg"]], call. = FALSE) + modID <- newModelName + } + } + + if (is(modDC, "try-error")) { + modDC <- "" + } + else { + nal <- .checkEmptyField(modDC, "description") + if (!is.null(nal)) { + modDC <- "" + } + } + + if (is(modCO, "try-error")) { + modCO <- NULL + } + else { + nal <- .checkEmptyField(modCO, "compartment") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + modCO <- unlist(strsplit(modCO[1], entrydelim, fixed = TRUE)) + } + + if (is(modCA, "try-error")) { + modCA <- NULL + } + else { + nal <- .checkEmptyField(modCA, "abbreviation") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + modCA <- unlist(strsplit(modCA[1], entrydelim, fixed = TRUE)) + } + + if (is(modNmet, "try-error")) { + modNmet <- NULL + } + else { + nal <- .checkEmptyField(modNmet, "Nmetabolites") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + modNmet <- modNmet[1] + } + + if (is(modNreact, "try-error")) { + modNreact <- NULL + } + else { + nal <- .checkEmptyField(modNreact, "Nreactions") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + modNreact <- modNreact[1] + } + + if (is(modNgenes, "try-error")) { + modNgenes <- NULL + } + else { + nal <- .checkEmptyField(modNgenes, "Ngenes") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + modNgenes <- modNgenes[1] + } + + if (is(modNnnz, "try-error")) { + modNnnz <- NULL + } + else { + nal <- .checkEmptyField(modNnnz, "Nnnz") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + modNnnz <- modNnnz[1] + } + + remove(md) + + message("OK") + + } + + + #--------------------------------------------------------------------------# + # new instance of class modelorg + #--------------------------------------------------------------------------# + + model <- modelorg(modID[1], modNM[1]) + mod_desc(model) <- as.character(modDC[1]) + + + #--------------------------------------------------------------------------# + # metabolites list + #--------------------------------------------------------------------------# + + if (is.null(fpML)) { + metABBR <- NULL + metNAME <- NULL + metCOMP <- NULL + } + else { + message("reading metabolite list ... ", appendLF = FALSE) + + ml <- read.table(fpML, + header = TRUE, + sep = fielddelim, + quote = quoteChar, + comment.char = commentChar, ...) + + metABBR <- try(as.character(ml[ ,"abbreviation"]), silent = TRUE) + metNAME <- try(as.character(ml[ ,"name"]), silent = TRUE) + metCOMP <- try(as.character(ml[ ,"compartment"]), silent = TRUE) + + if (is(metABBR, "try-error")) { + metABBR <- NULL + } + else { + nal <- .checkEmptyField(metABBR, "abbreviation") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + + # [...] containing leading whitespace(s), are treated as comments + if (isTRUE(excludeComments)) { + metABBR <- sub("\\s+\\[.+\\]$", "", metABBR, perl = TRUE) + } + else { + metABBR <- gsub("\\s+", "", metABBR, perl = TRUE) + } + #metABBR <- gsub(" ", "", metABBR, fixed = TRUE) + } + + if (is(metNAME, "try-error")) { + warning("field 'name' does not exist in metabolite list") + metNAME <- NULL + } + else { + nal <- .checkEmptyField(metNAME, "name") + if (!is.null(nal)) { + metNAME[nal[["nalines"]]] <- "" + } + } + + if (is(metCOMP, "try-error")) { + metCOMP <- NULL + } + else { + nal <- .checkEmptyField(metCOMP, "compartment") + if (!is.null(nal)) { + metCOMP[nal[["nalines"]]] <- "" + } + } + + remove(ml) + + message("OK") + } + + + #--------------------------------------------------------------------------# + # reactions list + #--------------------------------------------------------------------------# + + message("parsing reaction list ... ", appendLF = FALSE) + + rl <- read.table(fpRL, + header = TRUE, + sep = fielddelim, + quote = quoteChar, + comment.char = commentChar, ...) + + # obligatory + reactEQU <- try(as.character(rl[ ,"equation"]), silent = TRUE) + + if (is(reactEQU, "try-error")) { + stop("field 'equation' does not exist in the reactions list") + } + else { + nal <- .checkEmptyField(reactEQU, "equation") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + + nreact <- length(reactEQU) # number of reactions n + + if (!is.null(modNreact)) { + if (nreact != modNreact) { + msg <- paste(nreact," reactions detected,", modNreact, + "reactions expected, according to model", + "description file", dQuote(fpMD)) + warning(msg, call. = FALSE) + } + } + } + + # optionally + reactABBR <- try(as.character(rl[ ,"abbreviation"]), silent = TRUE) + reactNAME <- try(as.character(rl[ ,"name"]), silent = TRUE) + reactREV <- try(as.character(rl[ ,"reversible"]), silent = TRUE) + reactCOMP <- try(as.character(rl[ ,"compartment"]), silent = TRUE) + reactLOW <- try(as.numeric(rl[ ,"lowbnd"]), silent = TRUE) + reactUPP <- try(as.numeric(rl[ ,"uppbnd"]), silent = TRUE) + reactQBJ <- try(as.numeric(rl[ ,"obj_coef"]), silent = TRUE) + reactRULE <- try(as.character(rl[ ,"rule"]), silent = TRUE) + reactSUBS <- try(as.character(rl[ ,"subsystem"]), silent = TRUE) + + + if (is(reactABBR, "try-error")) { + msg <- paste("field 'abbreviation' does not", + "exist in reaction list") + warning(msg, call. = FALSE) + # If there is no field 'abbreviation', we use v1, v2, ..., vn as id's. + reactABBR <- paste(rep("v", nreact), 1:nreact, sep = "") + } + else { + nal <- .checkEmptyField(reactABBR, "abbreviation") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + + # [...] containing leading whitespace(s), are treated as comments + if (isTRUE(excludeComments)) { + reactABBR <- sub("\\s+\\[.+\\]$", "", reactABBR, perl = TRUE) + } + } + + if (is(reactNAME, "try-error")) { + reactNAME <- NULL + } + else { + nal <- .checkEmptyField(reactNAME, "name") + if (!is.null(nal)) { + reactNAME[nal[["nalines"]]] <- "" + } + } + + if (is(reactREV, "try-error")) { # if empty, use arrow symbol + reactREV <- NULL # in reactEQU + } + else { + nal <- .checkEmptyField(reactREV, "reversible") + if (!is.null(nal)) { + stop(nal[["msg"]], call. = FALSE) + } + } + + if (is(reactCOMP, "try-error")) { + reactCOMP <- NULL + } + else { + nal <- .checkEmptyField(reactCOMP, "compartment") + if (!is.null(nal)) { + #stop(nal[["msg"]], call. = FALSE) + reactCOMP[nal[["nalines"]]] <- "" + } + } + + if (is(reactLOW, "try-error")) { # If lowbnd and|or uppbnd is empty, + reactLOW <- NULL # we use for irreversible reactions: + } # [0, SYBIL_SETTINGS("MAXIMUM")] + else { + nal <- .checkEmptyField(reactLOW, "lowbnd") + if (!is.null(nal)) { + #stop(nal[["msg"]], call. = FALSE) + reactLOW[nal[["nalines"]]] <- -1 * def_bnd + } + } + + if (is(reactUPP, "try-error")) { # and for reversible reactions + reactUPP <- NULL # [-SYBIL_SETTINGS("MAXIMUM"), + } # SYBIL_SETTINGS("MAXIMUM")] + else { + nal <- .checkEmptyField(reactUPP, "uppbnd") + if (!is.null(nal)) { + #stop(nal[["msg"]], call. = FALSE) + reactUPP[nal[["nalines"]]] <- def_bnd + } + } + + if (is(reactQBJ, "try-error")) { + reactQBJ <- rep(0, nreact) + } + else { + nal <- .checkEmptyField(reactQBJ, "obj_coef") + if (!is.null(nal)) { + #stop(nal[["msg"]], call. = FALSE) + reactQBJ[nal[["nalines"]]] <- 0 + } + } + + if (is(reactRULE, "try-error")) { + reactRULE <- rep("", nreact) + } + else { + nal <- .checkEmptyField(reactRULE, "rule") + if (!is.null(nal)) { + reactRULE[nal[["nalines"]]] <- "" + } + } + + if (is(reactSUBS, "try-error")) { + reactSUBS <- NULL + } + else { + nal <- .checkEmptyField(reactSUBS, "subsystem") + if (!is.null(nal)) { + reactSUBS[nal[["nalines"]]] <- "none" + } + } + + remove(rl) + + + #--------------------------------------------------------------------------# + # parse reactions + #--------------------------------------------------------------------------# + + # data structures + Rrev <- logical(nreact) + #Rcomp <- character(nreact) + Rlow <- numeric(nreact) + Rupp <- numeric(nreact) + Rgenes <- vector(mode = "list", length = nreact) + Rrules <- character(nreact) + RruleL <- logical(nreact) + + allGenes <- character(0) + + NRmet <- 0 # number of detected metabolites + NRnnz <- 0 # number of current non-zero elements + + if (is.null(modNmet)) { + Rmet <- character(0) # metabolite id's + RmetC <- integer(0) # metabolite compartments + } + else { + Rmet <- character(modNmet) + RmetC <- integer(modNmet) + } + + if (is.null(modNreact)) { + RmatIA <- integer(0) # row indices + RmatJA <- integer(0) # column indices + RmatRA <- numeric(0) # non zero elements + } + else { + RmatIA <- integer(modNnnz) + RmatJA <- integer(modNnnz) + RmatRA <- numeric(modNnnz) + } + + SKIP_REACTION <- rep(TRUE, nreact) + + + # exclude comments from metabolite id's in reaction strings + if (isTRUE(excludeComments)) { + requatC <- gsub("(\\w+)\\s+\\[[^]]+\\]", "\\1", reactEQU, perl = TRUE) + } + else { + requatC <- reactEQU + } + + # remove whitespaces from reaction string + requatW <- gsub("\\s+", "", requatC, perl = TRUE) + + # check for possible transport reaction + transpR <- regexpr(paste("^", compartRegEx, ":", sep = ""), requatW, perl = TRUE) + #transpR <- regexpr("^\\[\\w+\\]:", requatW, perl = TRUE) + + + # indices for the next metabolite, next nnz element + nextMet <- 1 + nextNnz <- 1 + + for (i in seq(along = reactEQU)) { + + # get the compartment flag + if (transpR[i] > 0) { + #equat <- substr(requatW[i], 5, nchar(requatW[i])) + #compfl <- substr(requatW[i], 1, 3) + + equat <- substr(requatW[i], + (1+attr(transpR, "match.length")[i]), + nchar(requatW[i])) + compfl <- substr(requatW[i], + 1, (attr(transpR, "match.length")[i]-1)) + } + else { + equat <- requatW[i] + compfl <- "" + + } + + # The reaction arrow splits the equation string into educts (on the + # left) and products (on the right). Each reaction string must contain + # exactly one reaction arrow. The last sign of the arrow must be a '>', + # meaning the reaction is written in direction to products. + # Reversible reactions can begin with a '<' sign. + + # get the position of the arrow symbol + arrowpos <- gregexpr(arrowregex, equat, perl = TRUE)[[1]] + + if (length(arrowpos) > 1) { + msg <- paste("more than one arrow symbols found, skipping", + "reaction no.", i, dQuote(reactABBR[i])) + warning(msg, call. = FALSE) + SKIP_REACTION[i] <- FALSE + next + } + + if (arrowpos < 0) { + msg <- paste("no reaction arrow found, skipping reaction no.", + i, dQuote(reactABBR[i])) + warning(msg, call. = FALSE) + SKIP_REACTION[i] <- FALSE + next + } + + arrowsymb <- substr(equat, arrowpos, + (arrowpos+attr(arrowpos, "match.length"))-1) + + + # If reactREV is empty, the reaction arrow is used to determine + # reversibility. + + if (is.null(reactREV)) { + if (substr(arrowsymb, 1, 1) == "<") { + Rrev[i] <- TRUE + } + } + else { + if ( (isTRUE(reactREV[i])) || (reactREV[i] == "Reversible") ) { + Rrev[i] <- TRUE + } + } + + + # The current reaction is treated as 'reversible', if the arrowsymbol + # starts with a '<' (assuming the arrow is like <==>). If not and + # 'reactREV' is not empty, the entry on reactREV[i] will be checked. + +# if (substr(arrowsymb, 1, 1) == "<") { +# Rrev[i] <- TRUE +# } +# else { +# if ( (!is.null(reactREV)) && ( +# (isTRUE(reactREV[i])) || (reactREV[i] == "Reversible") ) ) { +# Rrev[i] <- TRUE +# } +# } + + + # Split reaction string in educts and products + edprod <- unlist(strsplit(equat, arrowsymb, fixed = TRUE)) + + if ( (length(edprod) > 2) || (length(edprod) < 1) ) { + msg <- paste("something went wrong here, skipping reaction no.", + i, dQuote(reactABBR[i])) + warning(msg) + SKIP_REACTION[i] <- FALSE + next + } + + # Educts + if (nchar(edprod[1]) > 0) { + newR <- prepReact(edprod[1], educts = TRUE, rowind = i) + if (length(newR$newRowRA) > 0) { + NRmet <- NRmet + newR$nNewMet + NRnnz <- NRnnz + length(newR$newRowRA) + + if (is.null(modNmet)) { + Rmet <- c(Rmet, newR$newMetId) + RmetC <- c(RmetC, newR$newMetCo) + } + else { + if (newR$nNewMet > 0) { + Rmet[nextMet:NRmet] <- newR$newMetId + RmetC[nextMet:NRmet] <- newR$newMetCo + + nextMet <- NRmet + 1 + } + } + + if (is.null(modNnnz)) { + RmatIA <- c(RmatIA, newR$newRowIA) + RmatJA <- c(RmatJA, newR$newRowJA) + RmatRA <- c(RmatRA, newR$newRowRA) + } + else { + RmatIA[nextNnz:NRnnz] <- newR$newRowIA + RmatJA[nextNnz:NRnnz] <- newR$newRowJA + RmatRA[nextNnz:NRnnz] <- newR$newRowRA + + nextNnz <- NRnnz + 1 + } + } + } + + # Products + if ( (length(edprod) == 2) && (nchar(edprod[2]) > 0) ) { + newR <- prepReact(edprod[2], educts = FALSE, rowind = i) + if (length(newR$newRowRA) > 0) { + NRmet <- NRmet + newR$nNewMet + NRnnz <- NRnnz + length(newR$newRowRA) + + if (is.null(modNmet)) { + Rmet <- c(Rmet, newR$newMetId) + RmetC <- c(RmetC, newR$newMetCo) + } + else { + if (newR$nNewMet > 0) { + Rmet[nextMet:NRmet] <- newR$newMetId + RmetC[nextMet:NRmet] <- newR$newMetCo + + nextMet <- NRmet + 1 + } + } + + if (is.null(modNnnz)) { + RmatIA <- c(RmatIA, newR$newRowIA) + RmatJA <- c(RmatJA, newR$newRowJA) + RmatRA <- c(RmatRA, newR$newRowRA) + } + else { + RmatIA[nextNnz:NRnnz] <- newR$newRowIA + RmatJA[nextNnz:NRnnz] <- newR$newRowJA + RmatRA[nextNnz:NRnnz] <- newR$newRowRA + + nextNnz <- NRnnz + 1 + } + } + } + + + # upper and lower bounds + if (is.null(reactLOW)) { + Rlow[i] <- ifelse(isTRUE(Rrev[i]), (def_bnd * -1), 0) + } + else { + bound <- as.numeric(reactLOW[i]) + if (abs(bound) > def_bnd) { + Rlow[i] <- ifelse(bound < 0, def_bnd * -1, def_bnd) + } + else { + Rlow[i] <- bound + } + # Rlow[i] <- as.numeric(reactLOW[i]) + } + + if (is.null(reactUPP)) { + Rupp[i] <- def_bnd + } + else { + bound <- as.numeric(reactUPP[i]) + if (abs(bound) > def_bnd) { + Rupp[i] <- ifelse(bound < 0, def_bnd * -1, def_bnd) + } + else { + Rupp[i] <- bound + } + # Rupp[i] <- as.numeric(reactUPP[i]) + } + + + # gpr association + gene_rule <- .parseBoolean(reactRULE[i]) + Rgenes[[i]] <- gene_rule$gene # list of involved genes + Rrules[i] <- gene_rule$rule # the rule string + if (gene_rule$rule != "") { + allGenes <- c(allGenes, gene_rule$gene) + RruleL[i] <- TRUE + } + + } + + message("OK") + + + #--------------------------------------------------------------------------# + # gene to reaction mapping + #--------------------------------------------------------------------------# + + message("GPR mapping ... ", appendLF = FALSE) + + allGenes <- unique(allGenes) + + if (!is.null(modNgenes)) { + if (modNgenes != length(allGenes)) { + msg <- paste(length(allGenes), "genes detected,", modNgenes, + "genes expected, according to model description file", + dQuote(fpMD)) + warning(msg, call. = FALSE) + } + } + + rxnGeneMat <- Matrix::Matrix(FALSE, + nrow = nreact, + ncol = length(allGenes), + sparse = TRUE) + + for (i in 1 : nreact) { + + if (isTRUE(RruleL[i])) { + geneInd <- match(Rgenes[[i]], allGenes) + rxnGeneMat[i, geneInd] <- TRUE + + for (j in 1 : length(geneInd)) { + pat <- paste("x(", j, ")", sep = "") + repl <- paste("x[", geneInd[j], "]", sep = "") + + Rrules[i] <- gsub(pat, repl, Rrules[i], fixed = TRUE) + } + } + + } + + message("OK") + + + #--------------------------------------------------------------------------# + # subsystems + #--------------------------------------------------------------------------# + + message("sub systems ... ", appendLF = FALSE) + + subSysdelim <- ifelse(isTRUE(oneSubSystem), NA, entrydelim) + ssys <- .prepareSubSysMatrix(reactSUBS, + nreact, + entrydelim = subSysdelim) + + message("OK") + + + #--------------------------------------------------------------------------# + # prepare modelorg + #--------------------------------------------------------------------------# + + message("prepare modelorg object ... ", appendLF = FALSE) + + if (!is.null(modNmet)) { + if (modNmet != NRmet) { + msg <- paste(NRmet, "metabolites detected,", modNmet, + "metabolites expected, according to model", + "description file", dQuote(fpMD)) + warning(msg, call. = FALSE) + } + } + + + # Set compartment slot. If modCO is empty (NULL), use the compartment flags + # from the reaction equation (the abbreviations). + if (is.null(modCO)) { + mod_compart(model) <- unique(RmetC) + } + else { + mod_compart(model) <- as.character(modCO) + } + + + #--------------------------------------------------------------------------# + # stoichiometric matrix + + ## this takes long, try to improve that!! ## + RmatM <- Matrix::Matrix(0, nrow = NRmet, ncol = nreact, sparse = TRUE) + + for (k in seq(along = RmatRA)) { + if (isTRUE(SKIP_REACTION[RmatJA[k]])) { + + if (isTRUE(balanceReact)) { + if (RmatM[RmatIA[k], RmatJA[k]] != 0) { + msg <- paste("reaction no.", RmatJA[k], + dQuote(reactABBR[RmatJA[k]]), "metabolite no.", + RmatIA[k], dQuote(Rmet[RmatIA[k]]), + "was balanced") + warning(msg, call. = FALSE) + } + + # add up stoichiometric coefficients --> balancing + RmatM[RmatIA[k], RmatJA[k]] <- RmatM[RmatIA[k], RmatJA[k]] + RmatRA[k] + } + else { + RmatM[RmatIA[k], RmatJA[k]] <- RmatRA[k] + } + + } + } + + + #--------------------------------------------------------------------------# + # search for unused metabolites and unused reactions + + # binary matrix + #RmatMb <- RmatM != 0 + RmatMb <- abs(RmatM) > tol + + SKIP_METABOLITE <- Matrix::rowSums(RmatMb) != 0 # TRUE, if a metabolite is used + UNUSED_REACTION <- Matrix::colSums(RmatMb) != 0 # TRUE, if a reaction is used + + if (isTRUE(remUnusedMetReact)) { + did <- "and therefore removed from S:" + } + else { + did <- "in S:" + } + + + #--------------------------------------------------------------------------# + # empty rows + + if (any(SKIP_METABOLITE == FALSE)) { + met_list <- paste(dQuote(Rmet[!SKIP_METABOLITE]), collapse = "\n\t") + nmet_list <- sum(!SKIP_METABOLITE) + msg_part <- paste("not used in any reaction", did) + msg <- sprintf(ngettext(nmet_list, + "%d metabolite is %s %s", + "%d metabolites are %s\n\t%s"), + nmet_list, msg_part, met_list) + warning(msg, call. = FALSE) + } + + + #--------------------------------------------------------------------------# + # empty columns + + if (sum(!UNUSED_REACTION) > 0) { + ur_list <- paste(dQuote(reactABBR[!UNUSED_REACTION]), + collapse = "\n\t") + nur_list <- sum(!UNUSED_REACTION) + msg_part <- paste("not used", did) + msg <- sprintf(ngettext(nur_list, + "%d reaction is %s %s", + "%d reactions are %s\n\t%s"), + nur_list, msg_part, ur_list) + warning(msg, call. = FALSE) + } + + + #--------------------------------------------------------------------------# + # correct SKIP... + + if (!isTRUE(remUnusedMetReact)) { + SKIP_METABOLITE[!SKIP_METABOLITE] <- TRUE + #UNUSED_REACTION[!UNUSED_REACTION] <- TRUE + SKIP_REACTION[!UNUSED_REACTION] <- TRUE + } + else { + SKIP_REACTION[!UNUSED_REACTION] <- FALSE + } + + + #--------------------------------------------------------------------------# + # single metabolites + + sing_met <- rep(NA, nrow(RmatM)) + sing_react <- rep(NA, ncol(RmatM)) + + if (isTRUE(singletonMet)) { + + message("identifying reactions containing single metabolites ... ", + appendLF = FALSE) + + singleton <- .singletonMetabolite(mat = RmatMb) + + sing_met[!singleton$smet] <- FALSE + sing_react[!singleton$sreact] <- FALSE + sing_met[singleton$smet] <- TRUE + sing_react[singleton$sreact] <- TRUE + + # singleton metabolites found? + if (sum(singleton$smet) > 0) { + + if ( xor(isTRUE(constrMet), isTRUE(remMet)) ) { + + if (isTRUE(constrMet)) { + # set to zero + did_watm <- "identified" + did_watr <- "constrained" + } + else { + # remove + SKIP_METABOLITE[singleton$smet] <- FALSE + SKIP_REACTION[singleton$sreact] <- FALSE + did_watm <- "removed" + did_watr <- "removed" + } + + met_list <- paste(dQuote(Rmet[singleton$smet]), + collapse = "\n\t") + nmet_list <- sum(singleton$smet) + react_list <- paste(dQuote(reactABBR[singleton$sreact]), + collapse = "\n\t") + nreact_list <- sum(singleton$sreact) + + msgm <- sprintf(ngettext(nmet_list, + "%s %d singleton metabolite: %s", + "%s %d singleton metabolites:\n\t%s"), + did_watm, nmet_list, met_list) + + msgr <- sprintf(ngettext(nreact_list, + "%s %d reaction containing singleton metabolites: %s", + "%s %d reactions containing singleton metabolites:\n\t%s"), + did_watr, nreact_list, react_list) + + #warning(paste(msgm, msgr, sep = "\n\t "), call. = FALSE) + warning(msgm, call. = FALSE) + warning(msgr, call. = FALSE) + + } + else { + + met_list <- paste(dQuote(Rmet[singleton$smet]), + collapse = "\n\t") + nmet_list <- sum(singleton$smet) + msg <- sprintf(ngettext(nmet_list, + "%d metabolite is singleton in S: %s", + "%d metabolites are singletons in S:\n\t%s"), + nmet_list, met_list) + warning(msg, call. = FALSE) + } + } + else { + message("nothing found ... ", appendLF = FALSE) + sing_met <- logical(nrow(RmatM)) + sing_react <- logical(ncol(RmatM)) + } + } + + + #--------------------------------------------------------------------------# + # dead end metabolites + + de_met <- rep(NA, nrow(RmatM)) + de_react <- rep(NA, ncol(RmatM)) + + if (isTRUE(deadEndMet)) { + + message("identifying reactions containing dead end metabolites ... ", + appendLF = FALSE) + + demr <- .deadEndMetabolite(mat = RmatM, + lb = Rlow, + exclM = sing_met, + exclR = sing_react, + tol = tol) + + de_met[!demr$dem] <- FALSE + de_react[!demr$der] <- FALSE + de_met[demr$dem] <- TRUE + de_react[demr$der] <- TRUE + + # dead end metabolites found? + if (sum(demr$dem) > 0) { + + if ( xor(isTRUE(constrMet), isTRUE(remMet)) ) { + + if (isTRUE(constrMet)) { + # set to zero + did_watm <- "identified" + did_watr <- "constrained" + } + else { + # remove + SKIP_METABOLITE[demr$dem] <- FALSE + SKIP_REACTION[demr$der] <- FALSE + did_watm <- "removed" + did_watr <- "removed" + } + + met_list <- paste(dQuote(Rmet[demr$dem]), + collapse = "\n\t") + nmet_list <- sum(demr$dem) + react_list <- paste(dQuote(reactABBR[demr$der]), + collapse = "\n\t") + nreact_list <- sum(demr$der) + + msgm <- sprintf(ngettext(nmet_list, + "%s %d dead end metabolite: %s", + "%s %d dead end metabolites:\n\t%s"), + did_watm, nmet_list, met_list) + + msgr <- sprintf(ngettext(nreact_list, + "%s %d reaction containing dead end metabolites: %s", + "%s %d reactions containing dead end metabolites:\n\t%s"), + did_watr, nreact_list, react_list) + + warning(msgm, call. = FALSE) + warning(msgr, call. = FALSE) + + } + else { + + met_list <- paste(dQuote(Rmet[demr$dem]), + collapse = "\n\t") + nmet_list <- sum(demr$dem) + msg <- sprintf(ngettext(nmet_list, + "%d dead end metabolite in S: %s", + "%d dead end metabolites in S:\n\t%s"), + nmet_list, met_list) + warning(msg, call. = FALSE) + } + + } + else { + message("nothing found ... ", appendLF = FALSE) + de_met <- logical(nrow(RmatM)) + de_react <- logical(ncol(RmatM)) + } + } + + + #--------------------------------------------------------------------------# + # S + + RmatM <- RmatM[SKIP_METABOLITE, , drop = FALSE] + RmatM <- RmatM[ , SKIP_REACTION, drop = FALSE] + + S(model) <- RmatM + + + #--------------------------------------------------------------------------# + # metabolites + + NRmet <- NRmet - sum(!SKIP_METABOLITE) + Rmet <- Rmet[SKIP_METABOLITE] + + met_id(model) <- Rmet[1:NRmet] # use only detected metabolites + met_num(model) <- as.integer(NRmet) + + met_single(model) <- sing_met[SKIP_METABOLITE] + met_de(model) <- de_met[SKIP_METABOLITE] + + + # If there is a column with metabolite abbreviations, the corresponding + # metabolite name should also exist. If not, the abbreviation will be used + # as metabolite name. + if (is.null(metABBR)) { + met_name(model) <- Rmet[1:NRmet] + } + else { + metAb <- sub(compartRegExEnd, "", Rmet[1:NRmet], perl = TRUE) + #metAb <- sub("\\[\\w+\\]$", "", Rmet[1:NRmet], perl = TRUE) + #metAb <- sub("^0+", "", metAb, perl = TRUE) # remove leading zeros + metId <- match(metAb, metABBR) + met_name(model) <- metNAME[metId] + if (any(is.na(metId))) { + msg <- paste("did not find some metabolite id's in the", + "list of metabolite names", dQuote(fpML), + "set to", sQuote(NA)) + warning(msg, call. = FALSE) + } + } + + # Set the metabolite <-> compartment accociations. If modCA is empty (NULL), + # use the compartment flags from the reaction equation (the abbreviations). + # is not empty. + if (is.null(modCA)) { + met_comp(model) <- match(RmetC[1:NRmet], mod_compart(model)) + } + else { + met_comp(model) <- match(RmetC[1:NRmet], modCA) + } + + + #--------------------------------------------------------------------------# + # reactions + + react_id(model) <- as.character(reactABBR[SKIP_REACTION]) + react_rev(model) <- Rrev[SKIP_REACTION] + react_num(model) <- as.integer(sum(SKIP_REACTION)) + if (is.null(reactNAME)) { + react_name(model) <- as.character(reactABBR[SKIP_REACTION]) + } + else { + react_name(model) <- as.character(reactNAME[SKIP_REACTION]) + } + + react_single(model) <- sing_react[SKIP_REACTION] + react_de(model) <- de_react[SKIP_REACTION] + + if (isTRUE(constrMet)) { + Rupp[sing_react] <- 0 + Rlow[sing_react] <- 0 + Rupp[de_react] <- 0 + Rlow[de_react] <- 0 + } + else {} + + uppbnd(model) <- Rupp[SKIP_REACTION] + lowbnd(model) <- Rlow[SKIP_REACTION] + obj_coef(model) <- as.numeric(reactQBJ[SKIP_REACTION]) + + + #--------------------------------------------------------------------------# + # genes + + allGenes(model) <- allGenes + genes(model) <- Rgenes[SKIP_REACTION] + gprRules(model) <- Rrules[SKIP_REACTION] + gpr(model) <- reactRULE[SKIP_REACTION] + rxnGeneMat(model) <- rxnGeneMat[SKIP_REACTION, , drop = FALSE] + + #subSys(model) <- as.character(reactSUBS[SKIP_REACTION]) + subSys(model) <- ssys[SKIP_REACTION, , drop = FALSE] + + + message("OK") + + + #--------------------------------------------------------------------------# + # validate model + #--------------------------------------------------------------------------# + + message("validating object ... ", appendLF = FALSE) + + check <- validObject(model, test = TRUE) + + if (check != TRUE) { + msg <- paste("Validity check failed:", check, sep = "\n ") + warning(msg) + } + + message("OK") + + + #--------------------------------------------------------------------------# + # return model + #--------------------------------------------------------------------------# + + + return(model) + +} diff --git a/R/reassignFwBwMatch.R b/R/reassignFwBwMatch.R new file mode 100644 index 0000000..9931526 --- /dev/null +++ b/R/reassignFwBwMatch.R @@ -0,0 +1,55 @@ +# reassignFwBwMatch.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .reassignFwBwmatch +# +# +# The function .reassignFwBwmatch() is inspired by the function +# reassingFwBwMatch() contained in the COBRA Toolbox. +# The algorithm is the same. + + +.reassignFwBwMatch <- function(matchrev, keep) { + + ind <- keep * 1 + ind[keep == TRUE] <- 1:sum(ind) + + num_match <- sum(keep == TRUE) + match <- integer(num_match) + j <- 0 + + for (i in 1:length(matchrev)) { + if (keep[i] == TRUE) { + j <- j + 1 + if (matchrev[i] > 0) { + if (keep[matchrev[i]] == TRUE) { + match[j] <- ind[matchrev[i]] + } + } + } + } + + return(as.integer(match)) +} diff --git a/R/recodeMatrix.R b/R/recodeMatrix.R new file mode 100644 index 0000000..451b6e7 --- /dev/null +++ b/R/recodeMatrix.R @@ -0,0 +1,52 @@ +# recodeMatrix.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .recodeMatrix +# +# arguments: +# +# mat: the matrix to recode (class Matrix) +# signs: character vector of length three: +# mat[i, j] > tol --> signs[3] +# mat[i, j] < tol --> signs[1] +# mat[i, j] == tol --> signs[2] +# tol: tolerance value + + +.recodeMatrix <- function(mat, + signs = c("-", " ", "+"), + tol = SYBIL_SETTINGS("TOLERANCE")) { + + stopifnot(is(mat, "Matrix"), length(signs) == 3) + + mat <- apply(mat, 2, + function(x) { + ifelse(x > tol, signs[3], ifelse(abs(x) > tol, + signs[1], signs[2])) + }) + + return(mat) + +} diff --git a/R/rmReact.R b/R/rmReact.R new file mode 100644 index 0000000..c2cc8ce --- /dev/null +++ b/R/rmReact.R @@ -0,0 +1,219 @@ +# rmReact.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: rmReact +# +# +# The function rmReact() is inspired by the function +# removeRxns() contained in the COBRA Toolbox. +# The algorithm is the same. + + +rmReact <- function(model, react, rm_met = TRUE) { + + +#------------------------------------------------------------------------------# +# check model and react # +#------------------------------------------------------------------------------# + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + + # check this, propably working wrong + if (is.na(match(is(react)[1], c("reactId", "numeric", "integer", "character")))) { + stop("argument react must be numeric, character, or of class reactId. Use checkReactId!") + } + + # argument react comes from the function checkReactId() + if (is(react, "reactId")) { + rmReact <- react_pos(react) + } + else { + checked_react <- checkReactId(model, react) + #print(is(checked_react)) + if (!is(checked_react, "reactId")) { + stop("Check your reaction Id's") + } + else { + rmReact <- react_pos(checked_react) + } + } + + +# if ((is(react, "numeric")) || (is(react, "integer"))) { +# if (max(react) > react_num(model)) { +# stop("check your reaction Id's!") +# } +# else { +# rmReact <- react +# } +# } + +# if (is(react, "character")) { +# checked_react <- checkReactId(model, react) +# if ((is.logical(checked_react)) && (checked_react == FALSE)) { +# stop("check your reaction Id's!") +# } +# else { +# rmReact <- react_pos(checked_react) +# } +# } + + +#------------------------------------------------------------------------------# +# logical vector # +#------------------------------------------------------------------------------# + + # logical vector: length = number of reactions, positions to be deleted + # are set to FALSE + #(numeric(react_num(model)) == 0) + keepReact <- rep(react_num(model), x=TRUE) + keepReact[rmReact] <- FALSE + + +#------------------------------------------------------------------------------# +# construct the new model # +#------------------------------------------------------------------------------# + + if (is(model, "modelorg_irrev")) { + mod_out <- modelorg_irrev(mod_id(model), mod_name(model)) + + irrev(mod_out) <- TRUE + + for (i in 1:length(rmReact)) { + remInd <- rmReact[i] + if (matchrev(model)[remInd] > 0) { + revInd <- matchrev(model)[remInd] + react_rev(model)[revInd] <- FALSE + + #react_id(model)[revInd] <- substr(react_id(model)[revInd], 1, (nchar(react_id(model)[revInd]) - 2)) + react_id(model)[revInd] <- sub("_[bfr]$", "", react_id(model)[revInd]) + } + } + } + else { + mod_out <- modelorg(mod_id(model), mod_name(model)) + } + + # model description + mod_desc(mod_out) <- mod_desc(model) + mod_compart(mod_out) <- mod_compart(model) + + # reactions + react_rev(mod_out) <- react_rev(model)[keepReact] + react_id(mod_out) <- react_id(model)[keepReact] + react_name(mod_out) <- react_name(model)[keepReact] + lowbnd(mod_out) <- lowbnd(model)[keepReact] + uppbnd(mod_out) <- uppbnd(model)[keepReact] + obj_coef(mod_out) <- obj_coef(model)[keepReact] + react_single(mod_out) <- react_single(model)[keepReact] + react_de(mod_out) <- react_de(model)[keepReact] + + react_num(mod_out) <- length(react_id(mod_out)) + + # stoichiometric matrix + S(mod_out) <- S(model)[ , keepReact, drop = FALSE] + + # GPR stuff + if (!is.na(match("genes", slotNames(model)))) { + + gprRules(mod_out) <- gprRules(model)[keepReact] + genes(mod_out) <- genes(model)[keepReact] + gpr(mod_out) <- gpr(model)[keepReact] + rxnGeneMat(mod_out) <- rxnGeneMat(model)[keepReact, , drop = FALSE] + subSys(mod_out) <- subSys(model)[keepReact, , drop = FALSE] + + ag <- unique(unlist(genes(mod_out))) + ncag <- nchar(ag) + allGenes(mod_out) <- ag[which(ncag != 0)] + + # reaction to gene mapping + #SrGMbin <- rxnGeneMat(mod_out) != 0 + + #SrGMbindiag <- diag(crossprod(SrGMbin)) + + #keepGenes <- ifelse(SrGMbindiag == 0, FALSE, TRUE) + keepGenes <- sapply(allGenes(model), function(x) match(x, allGenes(mod_out))) + keepGenes <- ifelse(is.na(keepGenes), FALSE, TRUE) + #print(keepGenes) + + rxnGeneMat(mod_out) <- rxnGeneMat(mod_out)[, keepGenes] + #print(dim(rxnGeneMat)) + } + + + # check what to do with the reversible match stuff (model in irrev format) + if (is(model, "modelorg_irrev")) { + + matchrev(mod_out) <- .reassignFwBwMatch(matchrev(model), + keepReact) + + # propably we do not need this: + react_rev(mod_out)[matchrev(mod_out) == 0] <- FALSE + + #rev2irrev(mod_out) <- integer(irrev_react_num) + #irrev2rev(mod_out) <- integer(irrev_react_num) + } + + +#------------------------------------------------------------------------------# +# removed unused metabolites # +#------------------------------------------------------------------------------# + + if (rm_met == TRUE) { + + # binary matrix of S + Sbin <- S(mod_out) != 0 + + Sbindiag <- diag(tcrossprod(Sbin)) + + keepMet <- ifelse(Sbindiag == 0, FALSE, TRUE) + + S(mod_out) <- S(mod_out)[keepMet, ] + met_num(mod_out) <- sum(keepMet == TRUE) + met_id(mod_out) <- met_id(model)[keepMet] + met_name(mod_out) <- met_name(model)[keepMet] + met_comp(mod_out) <- met_comp(model)[keepMet] + met_single(mod_out) <- met_single(model)[keepMet] + met_de(mod_out) <- met_de(model)[keepMet] + } + else { + met_num(mod_out) <- met_num(model) + met_id(mod_out) <- met_id(model) + met_comp(mod_out) <- met_comp(model) + } + + check <- validObject(mod_out, test = TRUE) + + if (check != TRUE) { + warning(paste("Validity check failed:", check, sep = "\n "), call. = FALSE) + } + + return(mod_out) + +} + diff --git a/R/robAna.R b/R/robAna.R new file mode 100644 index 0000000..e73e5c4 --- /dev/null +++ b/R/robAna.R @@ -0,0 +1,110 @@ +# robAna.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: robAna +# +# +# The function robAna() is inspired by the function +# robustnessAnalysis() contained in the COBRA Toolbox. +# The algorithm is the same. + + +robAna <- function(model, ctrlreact, rng = NULL, + numP = 20, verboseMode = 1, ...) { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (length(ctrlreact) != 1) { + stop("Please enter exactly one control reaction.") + } + + tmp <- checkReactId(model, ctrlreact) + + if (!is(tmp, "reactId")) { + stop("Check control reaction!") + } + + ctrlr <- react_pos(tmp) + + +#------------------------------------------------------------------------------# +# minimum and maximum solution # +#------------------------------------------------------------------------------# + + if (is.null(rng)) { + suppressMessages( + fvmm <- fluxVar(model, + react = ctrlr, + fixObjVal = FALSE, + verboseMode = 0, ...) + ) + if (length(checkStat(fvmm)) > 0) { + stop("Optimization for min/max solution ended not successfull!") + } + else { + mm <- c(minSol(fvmm, "lp_obj"), maxSol(fvmm, "lp_obj")) + } + } + else { + stopifnot(length(rng) == 2, is(rng, "numeric")) + mm <- sort(rng) + } + + # sequence of numP numbers between lpmin and lpmax, + # all with the same distance + ctrlfl <- seq(mm[1], mm[2], length.out = numP) + + +#------------------------------------------------------------------------------# +# optimization # +#------------------------------------------------------------------------------# + + sol <- optimizer(model, + react = as.list(rep(ctrlr, numP)), + lb = ctrlfl, + ub = ctrlfl, + algorithm = "fba", + verboseMode = verboseMode, ...) + + +#------------------------------------------------------------------------------# +# save the results # +#------------------------------------------------------------------------------# + + optsol <- new("optsol_robAna") + opt <- makeOptsolMO(model, sol) + as(optsol, "optsol_optimizeProb") <- opt + + ctrlr(optsol) <- tmp + ctrlfl(optsol) <- as.numeric(ctrlfl) + + return(optsol) + +} + + + diff --git a/R/settings.R b/R/settings.R new file mode 100644 index 0000000..da9dc9e --- /dev/null +++ b/R/settings.R @@ -0,0 +1,130 @@ +# settings.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + + +SYBIL_SETTINGS <- function(parm, value, ...) { + + if ( (missing(parm)) && (missing(value)) ) { + return(.SYBILenv$settings) + } + + if (missing(value)) { + if (!parm %in% names(.SYBILenv$settings)) { + stop("unknown parameter ", sQuote(parm)) + } + return(.SYBILenv$settings[[parm]]) + } + + if ( (length(parm) != 1) || + ( (length(value) != 1) && (! (parm == "SOLVER_CTRL_PARM") ) ) ) { + stop("arguments 'parm' and 'value' must have a length of 1") + } + + switch(parm, + + "SOLVER" = { + + chmet <- checkDefaultMethod(solver = value, + method = "", + probType = "", ...) + .SYBILenv$settings[["SOLVER"]] <- chmet$sol + .SYBILenv$settings[["METHOD"]] <- chmet$met + .SYBILenv$settings[["SOLVER_CTRL_PARM"]] <- chmet$parm + }, + + "METHOD" = { + chmet <- checkDefaultMethod(solver = SYBIL_SETTINGS("SOLVER"), + method = value, + probType = "", ...) + .SYBILenv$settings[["SOLVER"]] <- chmet$sol + .SYBILenv$settings[["METHOD"]] <- chmet$met + .SYBILenv$settings[["SOLVER_CTRL_PARM"]] <- chmet$parm + }, + + "TOLERANCE" = { + .SYBILenv$settings[["TOLERANCE"]] <- as.numeric(value) + }, + + "MAXIMUM" = { + .SYBILenv$settings[["MAXIMUM"]] <- as.numeric(value) + }, + + "ALGORITHM" = { +# if ( (value == "FBA") || +# (value == "linearMOMA") || +# (value == "linearMOMA_COBRA") ) { +# .SYBILenv$settings[["ALGORITHM"]] <- as.character(value) +# } +# else { +# stop("ALGORITHM can be either 'FBA', ", +# "'linearMOMA' or 'linearMOMA_COBRA'") +# } + .SYBILenv$settings[["ALGORITHM"]] <- as.character(value) + }, + + "OPT_DIRECTION" = { + if ( (value == "max") || (value == "min") ) { + .SYBILenv$settings[["OPT_DIRECTION"]] <- as.character(value) + } + else { + stop("OPT_DIRECTION can be either 'max' or 'min'") + } + }, + + "USE_NAMES" = { + .SYBILenv$settings[["USE_NAMES"]] <- as.logical(value) + }, + + "PATH_TO_MODEL" = { + if (file.exists(value)) { + .SYBILenv$settings[["PATH_TO_MODEL"]] <- as.character(value) + } + else { + stop("directory ", sQuote(value), " does not exist") + } + }, + + "SOLVER_CTRL_PARM" = { + if ( (is.data.frame(value)) || (is.list(value)) ) { + if ("NA" %in% names(SYBIL_SETTINGS("SOLVER_CTRL_PARM"))) { + .SYBILenv$settings[["SOLVER_CTRL_PARM"]] <- value + } + else { + pn <- names(value) + for (i in seq(along = value)) { + .SYBILenv$settings[["SOLVER_CTRL_PARM"]][[pn[i]]] <- value[[pn[i]]] + } + } + } + else { + stop("SOLVER_CTRL_PARM must be data.frame or list") + } + }, + + { + stop("unknown parameter: ", sQuote(parm)) + } + ) +} + diff --git a/R/singletonMetabolite.R b/R/singletonMetabolite.R new file mode 100644 index 0000000..8fee3e7 --- /dev/null +++ b/R/singletonMetabolite.R @@ -0,0 +1,86 @@ +# singletonMetabolite.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .singletonMetabolite +# +# +# + + +.singletonMetabolite <- function(mat, exclM, exclR) { + + if ( (missing(exclM)) || (any(is.na(exclM))) ) { + deCandM <- logical(nrow(mat)) + } + else { + deCandM <- exclM + } + + if ( (missing(exclR)) || (any(is.na(exclR))) ) { + deCandR <- logical(ncol(mat)) + } + else { + deCandR <- exclR + } + + # generate smaller matrix without singleton metabolites + indMatM <- c(1:nrow(mat))[!deCandM] + indMatR <- c(1:ncol(mat))[!deCandR] + + tmp_mat <- mat[!deCandM, , drop = FALSE] + tmp_mat <- tmp_mat[ , !deCandR, drop = FALSE] + + check <- TRUE + sreact <- logical(ncol(tmp_mat)) + smet <- logical(nrow(tmp_mat)) + + while(isTRUE(check)) { + + rs <- rowSums(tmp_mat) + + # row indices of reactions used only once in S + rrs <- which(rs == 1) + smet[rrs] <- TRUE + + if (length(rrs) > 0) { + # get reactions (columns) using singleton metabolites + crs <- which(colSums(tmp_mat[rrs, , drop = FALSE]) != 0) + tmp_mat[ , crs] <- FALSE + sreact[crs] <- TRUE + } + else { + check <- FALSE + } + } + + SMret <- logical(nrow(mat)) + SRret <- logical(ncol(mat)) + + SMret[indMatM] <- smet + SRret[indMatR] <- sreact + + return(list(smet = SMret, sreact = SRret)) + +} diff --git a/R/summaryOptsolClass.R b/R/summaryOptsolClass.R new file mode 100644 index 0000000..ef779e9 --- /dev/null +++ b/R/summaryOptsolClass.R @@ -0,0 +1,314 @@ +# summaryOptsolClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# summaryOptsolClass + + +#------------------------------------------------------------------------------# +# class definitions # +#------------------------------------------------------------------------------# + +setClass("summaryOptsol", + representation( + mod_id = "character", # model id + mod_key = "character", # model key + nzeros = "integer", # number of zeros in fld + nnonzero = "integer", # number of non-zeros in fld + mod_obj = "numeric", # objective coefficients of org. model %*% flux + ex_met = "character", # metabolite id of exchange reaction + ex_val = "Matrix", # flux value + react_id = "list", # id's of limiting reactions + chksol = "checksol" # solution status values + ) +) + + +#------------------------------------------------------------------------------# +# user constructors # +#------------------------------------------------------------------------------# + +summaryOptsol <- function(opt, + mod, + perc = 1, + tol = SYBIL_SETTINGS("TOLERANCE")) { + + stopifnot(is(opt, "optsol"), + is(mod, "modelorg"), + identical(mod_id(opt), mod_id(mod)), + length(perc) == 1, + (perc <= 1 || perc >= 0)) + + if (any(is.na(fluxes(opt)))) { + #cat("\noptimal values of model objective function:\n") + os <- summary(mod_obj(opt)) + } + else { + # zero and non-zero elements + zeros <- nnzero(fluxdist(opt)) + nzero <- num_of_fluxes(fluxdist(opt)) - nnzero(fluxdist(opt)) + + # exchange fluxes + exch <- findExchReact(mod) + + # limiting reactions + fl <- fluxes(opt)[fldind(opt), , drop = FALSE] + + lt <- apply(fl, 2, function(x) which( ( (x <= (lowbnd(mod)*perc)) | + (x >= (uppbnd(mod)*perc)) ) + & abs(x) > tol ) ) + + ltstr <- lapply(lt, function(x) react_id(mod)[x]) + + # summary object + os <- new("summaryOptsol", + mod_id = mod_id(opt), + mod_key = mod_key(opt), + mod_obj = mod_obj(opt), + nnonzero = nzero, + nzeros = zeros, + ex_met = met_id(exch), + ex_val = fluxes(opt)[fldind(opt)[react_pos(exch)], , drop = FALSE], + react_id = ltstr, + chksol = checkOptSol(opt)) + } + + return(os) +} + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# mod_id +setMethod("mod_id", signature(object = "summaryOptsol"), + function(object) { + return(object@mod_id) + } +) + +setReplaceMethod("mod_id", signature = (object = "summaryOptsol"), + function(object, value) { + object@mod_id <- value + return(object) + } +) + + +# mod_key +setMethod("mod_key", signature(object = "summaryOptsol"), + function(object) { + return(object@mod_key) + } +) + +setReplaceMethod("mod_key", signature = (object = "summaryOptsol"), + function(object, value) { + object@mod_key <- value + return(object) + } +) + + +# mod_obj +setMethod("mod_obj", signature(object = "summaryOptsol"), + function(object) { + return(object@mod_obj) + } +) + +setReplaceMethod("mod_obj", signature = (object = "summaryOptsol"), + function(object, value) { + object@mod_obj <- value + return(object) + } +) + + +# nzeros +setMethod("nzeros", signature(object = "summaryOptsol"), + function(object) { + return(object@nzeros) + } +) + +# nnzero +setMethod("nnzero", signature(x = "summaryOptsol"), + function(x) { + return(x@nnonzero) + } +) + +# ex_met +setMethod("ex_met", signature(object = "summaryOptsol"), + function(object) { + return(object@ex_met) + } +) + +# ex_val +setMethod("ex_val", signature(object = "summaryOptsol"), + function(object) { + return(object@ex_val) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +# show +setMethod("show", signature(object = "summaryOptsol"), + function(object) { + + nf <- ncol(ex_val(object)) + + cat("flux distribution:\n") + cat(" number of elements: ", nnzero(object) + nzeros(object), "\n") + cat(" number of zeros: ", nnzero(object), "\n") + cat(" number of non zero elements:", nzeros(object), "\n\n") + cat("exchange metabolites:\n") + print(ex_met(object), quote = FALSE, justify = "right") + cat("\nsubstrates (-) and products (+):\n") + if (nf < 21) { + printExchange(object, dense = FALSE) + } + else if (nf < 66) { + printExchange(object, dense = TRUE) + } + else { + cat(" use method ", sQuote("printExchange()"), "\n", sep = "") + } + cat("\nlimiting reactions:\n") + avglt <- floor(sum(sapply(object@react_id, length))/length(object@react_id)) + msg <- sprintf(ngettext(avglt, + " there is about one limiting reaction per optimization;\n", + " there are about %s limiting reactions per optimization;\n"), avglt) + cat(msg) + cat(" use method", sQuote("printReaction()"), "to see more details\n") + cat("\noptimal values of model objective function:\n") + show(summary(mod_obj(object))) + cat("\nsummary of optimization process:\n") + show(object@chksol) + } +) + + +# draw a histogramm (package lattice) +setMethod("plot", signature(x = "summaryOptsol", y = "missing"), + function(x, y, + col = "grey", + main = "", + xlab = "optimal values of model objective function", + ...) { + + histogram(mod_obj(x), col = col, main = main, xlab = xlab, ...) + + } +) + + +# printMetabolite +setMethod("printReaction", signature(object = "summaryOptsol", + mod = "modelorg"), + function(object, mod, j, ...) { + + stopifnot(identical(mod_id(object), mod_id(mod))) + + if (missing(j)) { + j <- 1:length(object@react_id) + } + + ltstr <- lapply(object@react_id[j], + function(x) { + msg <- sprintf(ngettext(length(x), + "\none reaction:\n", + "\n%s reactions:\n"), length(x)) + cat(msg) + printReaction(mod, react = x, ...) + }) + names(ltstr) <- j + + return(invisible(ltstr)) + } +) + + +# printExchange +setMethod("printExchange", signature(object = "summaryOptsol"), + function(object, i, j, dense = FALSE) { + + if(missing(i)) { + i <- 1:nrow(object@ex_val) + } + if(missing(j)) { + j <- 1:ncol(object@ex_val) + } + + mat <- .recodeMatrix(object@ex_val[i, j, drop = FALSE]) + rownames(mat) <- sprintf("%10s", object@ex_met[i]) + cw <- paste("%-", floor(log10(ncol(mat)))+1, "i", sep = "") + colnames(mat) <- sprintf(cw, j) + + if (isTRUE(dense)) { + vec <- apply(mat, 1, paste, collapse = "", sep = "") + dm <- sprintf("%10s %s", rownames(mat), vec) + cat(dm, sep = "\n") + } + else { + print(mat, quote = FALSE) + } + + return(invisible(mat)) + } +) + + +# image +setMethod("image", signature(x = "summaryOptsol"), + function(x, + cuts = 2, + xlab = "optimization no.", + ylab = "exchange reaction no.", + useAbs = TRUE, + sub = NULL, + printOut = TRUE, ...) { + + mat <- .recodeMatrix(x@ex_val, signs = c(-1, 0, 1)) + + imgmat <- image(Matrix(mat), + cuts = 2, + xlab = xlab, + ylab = ylab, + useAbs = useAbs, + sub = sub, ...) + + if (isTRUE(printOut)) { + print(imgmat) + } + + return(invisible(imgmat)) + } +) diff --git a/R/sybilErrorClass.R b/R/sybilErrorClass.R new file mode 100644 index 0000000..4c07a8a --- /dev/null +++ b/R/sybilErrorClass.R @@ -0,0 +1,132 @@ +# sybilErrorClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# sybilErrorClass + + +#------------------------------------------------------------------------------# +# definition of the class sybilError # +#------------------------------------------------------------------------------# + +setClass("sybilError", + representation( + emsg = "character", + enum = "integer" + ) +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +sybilError <- function(errmsg = "", number = NA) { + + msg <- paste(errmsg, collapse = " ") + + obj <- new(Class = "sybilError", + emsg = as.character(msg), + enum = as.integer(number) + ) + + return(obj) +} + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +setMethod(f = "initialize", + signature = "sybilError", + definition = function(.Object, emsg, enum) { + + if (missing(emsg)) { + stop("creation of instances of class sybilError needs a message") + } + else {} + + if (missing(enum)) { + enum <- NA + } + else {} + + .Object@emsg = as.character(emsg) + .Object@enum = as.integer(enum) + + validObject(.Object) + return(.Object) +} +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# msg +setMethod(f = "emsg", + signature = "sybilError", + definition = function(object) { + return(object@emsg) + } +) + +setReplaceMethod(f = "emsg", + signature = "sybilError", + definition = function(object, value) { + object@emsg <- value + return(object) + } +) + + +# num +setMethod(f = "enum", + signature = "sybilError", + definition = function(object) { + return(object@enum) + } +) + +setReplaceMethod(f = "enum", + signature = "sybilError", + definition = function(object, value) { + object@enum <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("show", signature(object = "sybilError"), + function(object) { + cat("error no.:", enum(object), "\n") + cat(emsg(object), "\n") + } +) + diff --git a/R/sybilLogClass.R b/R/sybilLogClass.R new file mode 100644 index 0000000..564c787 --- /dev/null +++ b/R/sybilLogClass.R @@ -0,0 +1,676 @@ +# sybilLogClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + +# sybilLogClass + + +#------------------------------------------------------------------------------# +# definition of the class sybilLog # +#------------------------------------------------------------------------------# + +setOldClass("file") + +setClass(Class = "sybilLog", + representation( + fh = "file", + fname = "character", + fpath = "character", + fenc = "character", + loglevel = "integer", + verblevel = "integer", + lastStep = "list", + lstname = "character", + didFoot = "logical" + ) +) + +# derivatives +#setClass(Class = "sybilLog_MODEL", contains = "sybilLog") + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +# sybilLog <- function(loglevel, verblevel) { +# if ( (missing(fluxes)) || (missing(verblevel)) ) { +# stop("creating instance of class sybilLog needs loglevel and verblevel!") +# } +# +# new("sybilLog", loglevel = loglevel, verblevel = verblevel) +# } + + +sybilLog <- function(filename = NA, + filepath = ".", + loglevel = -1, + verblevel = 0, + logfileEnc = NA, + ...) { + + new(Class = "sybilLog", + filename = as.character(filename), + filepath = as.character(filepath), + loglevel = as.integer(loglevel), + verblevel = as.integer(verblevel), + logfileEnc = as.character(logfileEnc), + ... + ) +} + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +setMethod(f = "initialize", + signature = "sybilLog", + definition = function(.Object, + filename, + filepath, + loglevel, + verblevel, + logfileEnc, ...) { + + if ( (missing(loglevel)) || (missing(verblevel)) ) { + warning("creation of instances of class sybilLog need \ + 'loglevel' and 'logverb'; set to -1 and 0 respectively") + loglevel <- -1 + verblevel <- 0 + } + + if (missing(filename)) { + filename <- NA + } + + if (missing(filepath)) { + filepath <- "." + } + + if (missing(logfileEnc)) { + logFileEnc <- NA + } + + tst <- strftime(Sys.time(), format = "%Y%m%d%H%M%OS6") + if (is.na(filename)) { + filename <- paste("sybil_", tst, ".log", sep = "") + } + + if (loglevel > -1) { + tofile <- file.path(filepath, filename) + + if (is.na(logfileEnc)) { + fenc <- getOption("encoding") + } + else { + fenc <- logfileEnc + options(useFancyQuotes = FALSE) + } + + fh <- try(file(description = tofile, open = "wt", + encoding = fenc, ...), silent = TRUE) + + if (is(fh, "try-error")) { + warning("can not write logfile") + fh <- NA + } + } + else { + fh <- NA + fenc <- NA + } + + if (!is.na(fh)) { + .Object@fh = fh + } + .Object@fname = as.character(filename) + .Object@fpath = as.character(filepath) + .Object@fenc = as.character(fenc) + .Object@loglevel = as.integer(loglevel) + .Object@verblevel = as.integer(verblevel) + .Object@lastStep = stinit(tst) + .Object@lstname = as.character(tst) + #validObject(.Object) + return(.Object) +} +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# fh +setMethod(f = "fh", + signature = "sybilLog", + definition = function(object) { + return(object@fh) + } +) + +setReplaceMethod(f = "fh", + signature = "sybilLog", + definition = function(object, value) { + object@fh <- value + return(object) + } +) + + +# fname +setMethod(f = "fname", + signature = "sybilLog", + definition = function(object) { + return(object@fname) + } +) + +setReplaceMethod(f = "fname", + signature = "sybilLog", + definition = function(object, value) { + object@fname <- value + return(object) + } +) + + +# fpath +setMethod(f = "fpath", + signature = "sybilLog", + definition = function(object) { + return(object@fpath) + } +) + +setReplaceMethod(f = "fpath", + signature = "sybilLog", + definition = function(object, value) { + object@fpath <- value + return(object) + } +) + + +# fenc +setMethod(f = "fenc", + signature = "sybilLog", + definition = function(object) { + return(object@fenc) + } +) + +setReplaceMethod(f = "fenc", + signature = "sybilLog", + definition = function(object, value) { + object@fenc <- value + return(object) + } +) + + +# loglevel +setMethod(f = "loglevel", + signature = "sybilLog", + definition = function(object) { + return(object@loglevel) + } +) + +setReplaceMethod(f = "loglevel", + signature = "sybilLog", + definition = function(object, value) { + object@loglevel <- value + return(object) + } +) + + +# verblevel +setMethod(f = "verblevel", + signature = "sybilLog", + definition = function(object) { + return(object@verblevel) + } +) + +setReplaceMethod(f = "verblevel", + signature = "sybilLog", + definition = function(object, value) { + object@verblevel <- value + return(object) + } +) + + +# lstname +setMethod(f = "lstname", + signature = "sybilLog", + definition = function(object) { + return(object@lstname) + } +) + + +# didFoot +setMethod(f = "didFoot", + signature = "sybilLog", + definition = function(object) { + return(object@didFoot) + } +) + +setReplaceMethod(f = "didFoot", + signature = "sybilLog", + definition = function(object, value) { + object@didFoot <- value + return(object) + } +) + + +# ---------------------------------------------------------------------------- # +# start/stop logging methods +# ---------------------------------------------------------------------------- # + +# close log file +setReplaceMethod(f = "logClose", + signature = "sybilLog", + definition = function(object, value) { + + if (is(object@fh, "file")) { + + if (!isTRUE(didFoot(object))) { + lc <- .printLogComment("end unexpected:") + cat("\n", lc, sep = "", file = object@fh, append = TRUE) + } + + check <- try(isOpen(object@fh), silent = TRUE) + if ( ! is(check, "try-error")) { + close(object@fh) + } + } + + if (stexists(object@lstname)) { + stclear(object@lstname) + } + + return(object) + +} +) + + +# log file header +setMethod(f = "logHead", + signature = "sybilLog", + definition = function(object) { + + if (!is(object@fh, "file")) { + return(FALSE) + } + + lc <- .printLogComment("start:") + cat(lc, file = object@fh, append = TRUE) + + return(TRUE) +} +) + + +# log file footer +setReplaceMethod(f = "logFoot", + signature = "sybilLog", + definition = function(object, value) { + + if (object@verblevel > 1) { + message("Done.") + } + + if (!is(object@fh, "file")) { + return(object) + } + + lc <- .printLogComment("end:") + cat("\n", lc, sep = "", file = object@fh, append = TRUE) + + object@didFoot <- value + + return(object) +} +) + + +# ---------------------------------------------------------------------------- # +# errors, warnings and messages +# ---------------------------------------------------------------------------- # + +# error message +setMethod(f = "logError", + signature = "sybilLog", + definition = function(object, msg, num) { + + errmsg <- gettext(paste(msg, collapse = " ")) + + if (is(object@fh, "file")) { + cat("E\t", errmsg, "\t", date(), file = object@fh, append = TRUE) + } + + err <- sybilError(errmsg = errmsg) + + return(err) +} +) + +# error message +setMethod(f = "logError", + signature(object = "sybilLog", num = "numeric"), + definition = function(object, msg, num) { + + errmsg <- gettext(paste(msg, collapse = " ")) + + if (is(object@fh, "file")) { + cat("E\t", num, "\t", errmsg, "\t", date(), + file = object@fh, append = TRUE) + } + else {} + + err <- sybilError(errmsg = errmsg, number = num) + + return(err) +} +) + + +# warning +setMethod(f = "logWarning", + signature = "sybilLog", + definition = function(object, ...) { + + msg <- gettext(paste(..., collapse = " ")) + + if (object@verblevel > 0) { + warning(msg, call. = FALSE) + } + else {} + + if (object@loglevel > 0) { + if (is(object@fh, "file")) { + cat("W\t", msg, "\n", file = object@fh, append = TRUE) + } + else {} + } + else {} + + return(TRUE) +} +) + + +# message +setMethod(f = "logMessage", + signature = "sybilLog", + definition = function(object, appendEllipsis = FALSE, ...) { + + msg <- gettext(paste(..., collapse = " ")) + + if (object@verblevel > 1) { + if (isTRUE(appendEllipsis)) { + message(msg, " ... ", appendLF = FALSE) + } + else { + message(msg, appendLF = FALSE) + } + } + + if (object@loglevel > 1) { + if (is(object@fh, "file")) { + cat("M\t", msg, "\n", file = object@fh, append = TRUE) + } + } + + return(TRUE) +} +) + + +# ---------------------------------------------------------------------------- # +# other logging methods +# ---------------------------------------------------------------------------- # + +# return TRUE if object@fh is a connection (file) +setMethod(f = "logFH", + signature = "sybilLog", + definition = function(object) { + + out <- is(object@fh, "file") + + return(out) +} +) + + +# comments to the logfile +setMethod(f = "logComment", + signature = "sybilLog", + definition = function(object, cmt, cmtChar) { + + msg <- gettext(paste(cmt, collapse = " ")) + + if (missing(cmtChar)) { + cmtChar <- "# " + } + + if (object@verblevel > 2) { + cat(cmtChar, msg, "\n", sep = "") + } + + if (object@loglevel > 2) { + if (is(object@fh, "file")) { + cat(cmtChar, msg, "\n", + sep = "", file = object@fh, append = TRUE) + } + } + + return(TRUE) +} +) + + +# results of optimization +setMethod(f = "logOptimizationTH", + signature = "sybilLog", + definition = function(object) { + + th <- "opt no. | ret | stat | obj value | dir | obj c | flux no. \n" + + if (object@verblevel > 2) { + cat(th) + } + + if (object@loglevel > 2) { + if (is(object@fh, "file")) { + cat(th, file = object@fh, append = TRUE) + } + } + + return(TRUE) +} +) + + +# results of optimization +setMethod(f = "logOptimization", + signature = "sybilLog", + definition = function(object, ok, stat, obj, dir, objc, del, i) { + + if ( (object@verblevel > 2) || (object@loglevel > 2) ) { + fi <- sprintf(" %-6s", paste("[", i, "]", sep = "")) + fok <- sprintf("%-3i", ok) + fstat <- sprintf("%-4i", stat) + fobj <- sprintf("%9.3f", obj) + if (is.null(dir)) { + fdir <- " " + } + else { + fdir <- sprintf("%3s", dir) + } + if (is.null(objc)) { + fobjc <- " " + } + else { + fobjc <- sprintf("%5.1f", objc) + } + fdel <- paste(del, collapse = " ") + + prstr <- paste(fi, fok, fstat, fobj, fdir, fobjc, fdel, sep = " | ") + + if (object@verblevel > 2) { + cat(prstr, "\n", sep = "") + } + + if (object@loglevel > 2) { + if (is(object@fh, "file")) { + cat(prstr, "\n", sep = "", file = object@fh, append = TRUE) + } + } + } + + return(invisible(TRUE)) +} +) + + +# performing step foo +setReplaceMethod(f = "logStep", + signature = "sybilLog", + definition = function(object, value) { + + if (is.na(value)) { + didstep <- stpop(object@lstname) + if (object@verblevel > 1) { + if (stlength(object@lstname) < 1) { + message("OK") + } + } + + if (object@loglevel > 1) { + if (is(object@fh, "file")) { + write(paste("# done", didstep), + file = object@fh, append = TRUE) + } + } + + } + else { + + msg <- gettext(paste(value, collapse = " ")) + stpush(object@lstname, msg) + + if (object@verblevel > 1) { + if (pmatch(gettext("FAILED"), msg, nomatch = 0) == 1) { + message(msg, appendLF = TRUE) + } + else { + message(paste(msg, "... "), appendLF = FALSE) + } + } + + if (object@loglevel > 1) { + if (is(object@fh, "file")) { + write(paste("#", msg), file = object@fh, append = TRUE) + } + } + } + + return(object) +} +) + + +# log function call +setMethod(f = "logCall", + signature = "sybilLog", + definition = function(object, nog) { + + if (missing(nog)) { + nog <- 1 + } + else {} + + if (object@loglevel > 2) { + if (is(object@fh, "file")) { + fc <- sys.call(sys.parent(n = nog)) + cat("# call to function", dQuote(fc[[1]]), + "with arguments:\n", file = object@fh, append = TRUE) + .printNamedList(nList = as.list(fc)[-1], + file = object@fh, append = TRUE) + } + else {} + } + else {} + + return(TRUE) +} +) + + +# setMethod("logCall", signature(object = "sybilLog"), +# function(object, func, fargl, thdargs) { +# if (object@loglevel > 2) { +# if (is(object@fh, "file")) { +# fc <- as.character(func) +# cat("# formal arguments to ", fc, "()\n", +# sep = "", file = object@fh, append = TRUE) +# .printNamedList(fargl, file = object@fh, append = TRUE) +# +# if ( (length(thdargs) > 0) && (!is.na(thdargs)) ) { +# cat("# further arguments to", fc, "(...)\n", +# file = object@fh, append = TRUE) +# if (length(thdargs) > 0) { +# .printNamedList(thdargs, +# file = object@fh, append = TRUE) +# } +# else { +# cat("none\n", file = object@fh, append = TRUE) +# } +# } +# } +# } +# +# return(TRUE) +# } +# ) + +## !! required for the above method !! ## +# # log function call +# if (loglevel > 2) { +# fargs <- formals() +# for (na in names(fargs)) { +# val <- try(eval(parse(text=na)), silent = TRUE) +# if (!is(val, "try-error")) { +# fargs[na] <- val +# } +# } +# print(match.call()) +# logCall(logObj, sys.call(), fargs, list(...)) +# } diff --git a/R/sybilStack.R b/R/sybilStack.R new file mode 100644 index 0000000..a14cc4b --- /dev/null +++ b/R/sybilStack.R @@ -0,0 +1,162 @@ +# sybilStack.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# initialize stack + +stinit <- function(stname) { + + .SYBILenv$sybilStack[[stname]] <- vector(mode = "list", length = 0) + +} + + +#------------------------------------------------------------------------------# +# remove stack + +stclear <- function(stname) { + +# if (!(stname %in% names(.SYBILenv$sybilStack))) { +# stop("stack ", sQuote(stname), " does not exist") +# } + stopifnot(stexists(stname)) + .SYBILenv$sybilStack[stname] <- NULL + +} + + +#------------------------------------------------------------------------------# +# add element at last position + +stpush <- function(stname, value) { + + stopifnot(stexists(stname)) + + .SYBILenv$sybilStack[[stname]] <- append(.SYBILenv$sybilStack[[stname]], + value, + after = length(.SYBILenv$sybilStack[[stname]])) +} + + +#------------------------------------------------------------------------------# +# remove last element and return invisibly + +stpop <- function(stname) { + + stopifnot(stexists(stname)) + + lg <- length(.SYBILenv$sybilStack[[stname]]) + value <- .SYBILenv$sybilStack[[stname]][lg] + length(.SYBILenv$sybilStack[[stname]]) <- lg - 1 + return(invisible(value)) + +} + + +#------------------------------------------------------------------------------# +# add element at first position + +stunshift <- function(stname, value) { + + stopifnot(stexists(stname)) + + .SYBILenv$sybilStack[[stname]] <- append(.SYBILenv$sybilStack[[stname]], + value, after = 0) + +} + +#------------------------------------------------------------------------------# +# remove first element and return invisibly + +stshift <- function(stname) { + + stopifnot(stexists(stname)) + + value <- .SYBILenv$sybilStack[[stname]][1] + .SYBILenv$sybilStack[[stname]] <- .SYBILenv$sybilStack[[stname]][-1] + return(invisible(value)) + +} + + +#------------------------------------------------------------------------------# +# return last element, not removed + +stseek <- function(stname) { + + stopifnot(stexists(stname)) + + lg <- length(.SYBILenv$sybilStack[[stname]]) + value <- .SYBILenv$sybilStack[[stname]][lg] + return(value) + +} + + +#------------------------------------------------------------------------------# +# return first element, not removed + +stfirst <- function(stname) { + + stopifnot(stexists(stname)) + + value <- .SYBILenv$sybilStack[[stname]][1] + return(value) + +} + + +#------------------------------------------------------------------------------# +# return complete stack as list + +stlist <- function(stname) { + + stopifnot(stexists(stname)) + + return(.SYBILenv$sybilStack[[stname]]) + +} + + +#------------------------------------------------------------------------------# +# return number of elements in stack + +stlength <- function(stname) { + + stopifnot(stexists(stname)) + + return(length(.SYBILenv$sybilStack[[stname]])) + +} + + +#------------------------------------------------------------------------------# +# return TRUE is stack stname exists, FALSE otherwise + +stexists <- function(stname) { + + return(stname %in% names(.SYBILenv$sybilStack)) + +} + diff --git a/R/sysBiolAlgClass.R b/R/sysBiolAlgClass.R new file mode 100644 index 0000000..44a6b56 --- /dev/null +++ b/R/sysBiolAlgClass.R @@ -0,0 +1,469 @@ +# sysBiolAlgClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class sysBiolAlg # +#------------------------------------------------------------------------------# + +setClass(Class = "sysBiolAlg", + representation( + problem = "optObj", + algorithm = "character", + nr = "integer", + nc = "integer", + fldind = "integer", + alg_par = "list" + ), + contains = "VIRTUAL", + validity = .validsysBiolAlg +) + + +#------------------------------------------------------------------------------# +# user constructor # +#------------------------------------------------------------------------------# + +sysBiolAlg <- function(model, + algorithm = SYBIL_SETTINGS("ALGORITHM"), + prefix = "sysBiolAlg", sep = "_", + ...) { + + stopifnot(is(model, "modelorg"), is(algorithm, "character")) + + prob <- tryCatch(new(paste(prefix, algorithm, sep = sep), model, ...), + error = function(e) e) + + if (is(prob, "simpleError")) { + stop(prob) + } + + return(prob) + +} + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +setMethod(f = "initialize", + signature = "sysBiolAlg", + definition = function(.Object, + solver = SYBIL_SETTINGS("SOLVER"), + method = SYBIL_SETTINGS("METHOD"), + solverParm = SYBIL_SETTINGS("SOLVER_CTRL_PARM"), + termOut = NULL, + sbalg, pType = "lp", scaling = NULL, fi, nCols, + nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL, + retAlgPar = TRUE, algPar = list(NULL)) { + + if ( (!missing(solver)) || + (!missing(method)) || + (!missing(sbalg)) ) { + + stopifnot(is(solver, "character"), + is(method, "character"), + is(sbalg, "character"), + is(pType, "character"), + is(fi, "numeric"), + is(nCols, "numeric"), + is(nRows, "numeric"), + is(mat, "Matrix"), + is(ub, "numeric"), + is(lb, "numeric"), + is(obj, "numeric"), + is(rlb, "numeric"), + is(rtype, "character"), + is(lpdir, "character"), + is(retAlgPar, "logical"), + is(algPar, "list")) + + + # --------------------------------------------- + # build problem object + # --------------------------------------------- + + lp <- optObj(solver = solver, method = method, pType = pType) + lp <- initProb(lp, nrows = nRows, ncols = nCols, to = termOut) + + # --------------------------------------------- + # set control parameters + # --------------------------------------------- + + if (!any(is.na(solverParm))) { + setSolverParm(lp, solverParm) + } + + + # --------------------------------------------- + # load problem data + # --------------------------------------------- + + loadLPprob(lp, + nCols = nCols, + nRows = nRows, + mat = mat, + ub = ub, + lb = lb, + obj = obj, + rlb = rlb, + rtype = rtype, + lpdir = lpdir, + rub = rub, + ctype = ctype, + cnames = cnames, + rnames = rnames, + pname = pname) + + + # --------------------------------------------- + # scaling + # --------------------------------------------- + + if (!is.null(scaling)) { + scaleProb(lp, scaling) + } + + .Object@problem <- lp + .Object@algorithm <- sbalg + .Object@nr <- as.integer(nRows) + .Object@nc <- as.integer(nCols) + .Object@fldind <- as.integer(fi) + if (isTRUE(retAlgPar)) { + .Object@alg_par <- algPar + } + else { + .Object@alg_par <- list(NULL) + } + validObject(.Object) + + } + + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# setters and getters # +#------------------------------------------------------------------------------# + +# problem +setMethod("problem", signature(object = "sysBiolAlg"), + function(object) { + return(object@problem) + } +) + + +# algorithm +setMethod("algorithm", signature(object = "sysBiolAlg"), + function(object) { + return(object@algorithm) + } +) + +setReplaceMethod("algorithm", signature = (object = "sysBiolAlg"), + function(object, value) { + object@algorithm <- value + return(object) + } +) + + +# nr +setMethod("nr", signature(object = "sysBiolAlg"), + function(object) { + return(object@nr) + } +) + +setReplaceMethod("nr", signature = (object = "sysBiolAlg"), + function(object, value) { + object@nr <- value + return(object) + } +) + + +# nc +setMethod("nc", signature(object = "sysBiolAlg"), + function(object) { + return(object@nc) + } +) + +setReplaceMethod("nc", signature = (object = "sysBiolAlg"), + function(object, value) { + object@nc <- value + return(object) + } +) + + +# fldind +setMethod("fldind", signature(object = "sysBiolAlg"), + function(object) { + return(object@fldind) + } +) + +setReplaceMethod("fldind", signature = (object = "sysBiolAlg"), + function(object, value) { + object@fldind <- value + return(object) + } +) + + +# alg_par +setMethod("alg_par", signature(object = "sysBiolAlg"), + function(object) { + return(object@alg_par) + } +) + +setReplaceMethod("alg_par", signature = (object = "sysBiolAlg"), + function(object, value) { + object@alg_par <- value + return(object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("show", signature(object = "sysBiolAlg"), + function(object) { + cat("Algorithm type: ", algorithm(object), "\n", sep = "") + cat("Slot problem:\n") + show(problem(object)) + cat("Slot fldind:\n") + str(fldind(object)) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("optimizeProb", signature(object = "sysBiolAlg"), + function(object, react = NULL, + lb = NULL, + ub = NULL, + obj_coef = NULL, + lpdir = NULL, + fldind = TRUE, + resetChanges = TRUE, + #prCmd = NULL, poCmd = NULL, + prCmd = NA, poCmd = NA, + prCil = NA, poCil = NA) { + + + # check the argument react + if (is.null(react)) { + del <- FALSE + obj <- FALSE + } + else { + # if model is of class "sysBiolAlg", react is given by a + # preceeding function + stopifnot(is(react, "numeric")) + + if ( (is.null(lb)) || (is.null(ub)) ) { + del <- FALSE + } + else { + del <- TRUE + stopifnot(is(lb, "numeric"), + is(ub, "numeric"), + length(lb) == length(react), + length(ub) == length(react)) + } + + # check argument obj_coef + if (is.null(obj_coef)) { + obj <- FALSE + } + else { + if ( (is(obj_coef, "numeric")) && + (length(obj_coef) == length(react)) ) { + obj <- TRUE + } + else { + stop("argument ", sQuote("obj_coef"), "must be numeric ", + " and of same length as argument react") + } + } + } + + # check argument lpdir + if ( (length(lpdir) > 1L) || (is.null(lpdir)) ) { + ld <- FALSE + } + else { + ld <- TRUE + lpdir <- ifelse(lpdir == "max", "max", "min") + } + + + # -------------------------------------------------------------- # + # optimization + # -------------------------------------------------------------- # + + # modifications to problem object + tmp_val <- applyChanges(object, del = del, obj = obj, ld = ld, + react = react, lb = lb, ub = ub, + obj_coef = obj_coef, fldind = fldind, lpdir = lpdir) + + lpmod <- problem(object) + + # do some kind of preprocessing + preP <- .ppProcessing(lpprob = lpmod, + ppCmd = prCmd, + loopvar = prCil) + + lp_ok <- solveLp(lpmod) + lp_stat <- getSolStat(lpmod) + if (is.na(lp_stat)) { + lp_stat <- lp_ok + } + + lp_obj <- getObjVal(lpmod) + lp_fluxes <- getFluxDist(lpmod) + + # do some kind of postprocessing + postP <- .ppProcessing(lpprob = lpmod, + ppCmd = poCmd, + loopvar = poCil) + + # reset modifications + if (isTRUE(resetChanges)) { + resetChanges(object, old_val = tmp_val) + } + + + # -------------------------------------------------------------- # + # store solution + # -------------------------------------------------------------- # + + return(list(ok = lp_ok, + obj = lp_obj, + stat = lp_stat, + fluxes = lp_fluxes, + preP = preP, + postP = postP)) + + } +) + + +#------------------------------------------------------------------------------# + +setMethod("applyChanges", signature(object = "sysBiolAlg"), + function(object, del, obj, ld, + react = NULL, + lb = NULL, + ub = NULL, + obj_coef = NULL, + fldind = TRUE, + lpdir = NULL) { + + if (isTRUE(fldind)) { + fi <- fldind(object)[react] + } + else { + fi <- react + } + + if (any(is.na(fi))) { + stop("argument ", sQuote("react"), " must contain reactions only") + } + + tmp_val <- list("fi" = fi, "lb" = NULL, "ub" = NULL, + "obj_coef" = NULL, "lpdir" = NULL) + + lpmod <- problem(object) + + if (isTRUE(del)) { + # store default lower and upper bounds + tmp_val[["lb"]] <- getColsLowBnds(lpmod, fi) + tmp_val[["ub"]] <- getColsUppBnds(lpmod, fi) + + # change bounds of fluxes in react + check <- changeColsBnds(lpmod, fi, lb, ub) + } + + if (isTRUE(obj)) { + # store default objective function + tmp_val[["obj_coef"]] <- getObjCoefs(lpmod, fi) + + # change objective function + check <- changeObjCoefs(lpmod, fi, obj_coef) + } + + if (isTRUE(ld)) { + # store default optimization direction + tmp_val[["lpdir"]] <- getObjDir(lpmod) + + # change objective function + check <- setObjDir(lpmod, lpdir) + } + + return(tmp_val) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("resetChanges", signature(object = "sysBiolAlg"), + function(object, old_val) { + + lpmod <- problem(object) + + if ( (!is.null(old_val[["lb"]])) || (!is.null(old_val[["ub"]])) ) { + check <- changeColsBnds(lpmod, + old_val[["fi"]], + old_val[["lb"]], old_val[["ub"]]) + } + + # reset the default objective function + if (!is.null(old_val[["obj_coef"]])) { + check <- changeObjCoefs(lpmod, + old_val[["fi"]], + old_val[["obj_coef"]]) + } + + # reset the default optimization direction + if (!is.null(old_val[["lpdir"]])) { + check <- setObjDir(lpmod, old_val[["lpdir"]]) + } + + return(invisible(TRUE)) + } +) diff --git a/R/sysBiolAlg_fbaClass.R b/R/sysBiolAlg_fbaClass.R new file mode 100644 index 0000000..c03f64f --- /dev/null +++ b/R/sysBiolAlg_fbaClass.R @@ -0,0 +1,165 @@ +# sysBiolAlg_fbaClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class sysBiolAlg_fba # +#------------------------------------------------------------------------------# + +setClass(Class = "sysBiolAlg_fba", + contains = "sysBiolAlg" +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class sysBiolAlg_fba +setMethod(f = "initialize", + signature = "sysBiolAlg_fba", + definition = function(.Object, + model, + lpdir = SYBIL_SETTINGS("OPT_DIRECTION"), + useNames = SYBIL_SETTINGS("USE_NAMES"), + cnames = NULL, + rnames = NULL, + pname = NULL, + scaling = NULL, + writeProbToFileName = NULL, ...) { + + if ( ! missing(model) ) { + + stopifnot(is(model, "modelorg"), + is(lpdir, "character")) + + # problem dimensions + nCols <- react_num(model) + nRows <- met_num(model) + + # row and column names for the problem object + if (isTRUE(useNames)) { + if (is.null(cnames)) { + colNames <- .makeLPcompatible(react_id(model), + prefix = "x") + } + else { + stopifnot(is(cnames, "character"), + length(cnames) == nCols) + colNames <- cnames + } + + if (is.null(rnames)) { + rowNames <- .makeLPcompatible(met_id(model), + prefix = "r") + } + else { + stopifnot(is(rnames, "character"), + length(rnames) == nRows) + rowNames <- rnames + } + + if (is.null(pname)) { + probName <- .makeLPcompatible( + paste("FBA", mod_id(model), sep = "_"), + prefix = "") + } + else { + stopifnot(is(pname, "character"), + length(pname) == 1) + probName <- pname + } + } + else { + colNames <- NULL + rowNames <- NULL + probName <- NULL + } + + # generate problem object + .Object <- callNextMethod(.Object, + sbalg = "fba", + pType = "lp", + scaling = scaling, + fi = 1:nCols, + nCols = nCols, + nRows = nRows, + mat = S(model), + ub = uppbnd(model), + lb = lowbnd(model), + obj = obj_coef(model), + rlb = rep(0, nRows), + rtype = rep("E", nRows), + lpdir = lpdir, + rub = NULL, + ctype = NULL, + cnames = colNames, + rnames = rowNames, + pname = probName, + ...) + + if (!is.null(writeProbToFileName)) { + writeProb(problem(.Object), + fname = as.character(writeProbToFileName)) + } +# +# # make problem object +# lp <- optObj(solver = solver, method = method) +# lp <- initProb(lp, nrows = nRows, ncols = nCols) +# +# # set parameters +# if (!any(is.na(solverParm))) { +# setSolverParm(lp, solverParm) +# } +# +# loadLPprob(lp, +# nCols = nCols, +# nRows = nRows, +# mat = S(model), +# ub = uppbnd(model), +# lb = lowbnd(model), +# obj = obj_coef(model), +# rlb = rep(0, nRows), +# rub = NULL, +# rtype = rep("E", nRows), +# lpdir = lpdir +# ) +# +# if (!is.null(scaling)) { +# scaleProb(lp, scaling) +# } +# +# .Object@problem <- lp +# .Object@algorithm <- "fba" +# .Object@nr <- as.integer(nRows) +# .Object@nc <- as.integer(nCols) +# .Object@fldind <- as.integer(c(1:nCols)) +# validObject(.Object) + + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# diff --git a/R/sysBiolAlg_fvClass.R b/R/sysBiolAlg_fvClass.R new file mode 100644 index 0000000..0db3ac3 --- /dev/null +++ b/R/sysBiolAlg_fvClass.R @@ -0,0 +1,192 @@ +# sysBiolAlg_fvClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class sysBiolAlg_fv # +#------------------------------------------------------------------------------# + +setClass(Class = "sysBiolAlg_fv", + contains = "sysBiolAlg" +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class sysBiolAlg_fv +setMethod(f = "initialize", + signature = "sysBiolAlg_fv", + definition = function(.Object, + model, + percentage = 100, + Zopt = NULL, + fixObjVal = TRUE, + tol = SYBIL_SETTINGS("TOLERANCE"), + lpdir = SYBIL_SETTINGS("OPT_DIRECTION"), + useNames = SYBIL_SETTINGS("USE_NAMES"), + cnames = NULL, + rnames = NULL, + pname = NULL, + scaling = NULL, + writeProbToFileName = NULL, ...) { + + if ( ! missing(model) ) { + + stopifnot(is(model, "modelorg"), + (is.null(Zopt) || is(Zopt, "numeric")), + is(tol, "numeric"), + is(percentage, "numeric"), + is(lpdir, "character")) + + # problem dimensions + nCols <- react_num(model) + nRows <- met_num(model) + + # row and column names for the problem object + if (isTRUE(useNames)) { + if (is.null(cnames)) { + colNames <- .makeLPcompatible(react_id(model), + prefix = "x") + } + else { + stopifnot(is(cnames, "character"), + length(cnames) == nCols) + colNames <- cnames + } + + if (is.null(rnames)) { + rowNames <- .makeLPcompatible(met_id(model), + prefix = "r") + } + else { + stopifnot(is(rnames, "character"), + length(rnames) == nRows) + rowNames <- rnames + } + + if (is.null(pname)) { + probName <- .makeLPcompatible( + paste("FV", mod_id(model), sep = "_"), + prefix = "") + } + else { + stopifnot(is(pname, "character"), + length(pname) == 1) + probName <- pname + } + } + else { + colNames <- NULL + rowNames <- NULL + probName <- NULL + } + + .Object <- callNextMethod(.Object, + sbalg = "fv", + pType = "lp", + scaling = scaling, + fi = 1:nCols, + nCols = nCols, + nRows = nRows, + mat = S(model), + ub = uppbnd(model), + lb = lowbnd(model), + obj = rep(0, nCols), + rlb = rep(0, nRows), + rtype = rep("E", nRows), + lpdir = lpdir, + rub = NULL, + ctype = NULL, + cnames = colNames, + rnames = rowNames, + pname = probName, + algPar = list("percentage" = percentage, + "Zopt" = Zopt), + ...) + + # objective value + if ( (isTRUE(fixObjVal)) && (any(obj_coef(model) != 0)) ) { + if (is.null(Zopt)) { + optimal <- optimizeProb(model, + retOptSol = FALSE, + algorithm = "fba", + lpdir = lpdir, + scaling = scaling, ...) + + if (optimal$ok == 0) { + if (lpdir == "max") { + obj <- .floorValues(optimal$obj, + tol = tol)*percentage/100 + } + else { + obj <- .ceilValues(optimal$obj, + tol = tol)*percentage/100 + } + } + else { + stop("No optimal solution!") + } + } + else { + #obj <- Zopt + obj <- Zopt * (percentage/100) + } + + # add a row to the problem + #type <- ifelse(lpdir == "max", "L", "U") + if (lpdir == "max") { + type <- "L" + lowb <- obj + uppb <- SYBIL_SETTINGS("MAXIMUM") + } + else { + type <- "U" + lowb <- SYBIL_SETTINGS("MAXIMUM") * -1 + uppb <- obj + } + oind <- which(obj_coef(model) != 0) + oval <- obj_coef(model)[oind] + addRowsToProb(lp = problem(.Object), + i = met_num(model)+1, + type = type, lb = lowb, ub = uppb, + cind = list(oind), nzval = list(oval), + rnames = "Z") + .Object@nr <- .Object@nr + 1L + .Object@alg_par[["Zopt"]] <- obj + + } + + if (!is.null(writeProbToFileName)) { + writeProb(problem(.Object), + fname = as.character(writeProbToFileName)) + } + + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# diff --git a/R/sysBiolAlg_lmomaClass.R b/R/sysBiolAlg_lmomaClass.R new file mode 100644 index 0000000..cba013b --- /dev/null +++ b/R/sysBiolAlg_lmomaClass.R @@ -0,0 +1,362 @@ +# sysBiolAlg_lmomaClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class sysBiolAlg_lmoma # +#------------------------------------------------------------------------------# + +setClass(Class = "sysBiolAlg_lmoma", + contains = "sysBiolAlg" +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class sysBiolAlg_lmoma +setMethod(f = "initialize", + signature = "sysBiolAlg_lmoma", + definition = function(.Object, + model, + wtflux, + COBRAflag = FALSE, + wtobj = NULL, + wtobjLB = TRUE, + obj_coefD = NULL, + absMAX = SYBIL_SETTINGS("MAXIMUM"), + useNames = SYBIL_SETTINGS("USE_NAMES"), + cnames = NULL, + rnames = NULL, + pname = NULL, + scaling = NULL, + writeProbToFileName = NULL, ...) { + + if ( ! missing(model) ) { + + if (missing(wtflux)) { + tmp <- .generateWT(model, ...) + wtflux <- tmp$fluxes[tmp$fldind] + wtobj <- tmp$obj + } + + stopifnot(is(model, "modelorg"), + is(COBRAflag, "logical"), + is(wtobjLB, "logical"), + is(wtflux, "numeric"), + is(absMAX, "numeric")) + + stopifnot(length(wtflux) == react_num(model)) + + # the problem: minimize + # + # | | | ] + # Swt | 0 | 0 | = 0 ] left out if not COBRA + # | | | ] + # ------------------------- + # | | | + # 0 | Sdel | 0 | = 0 + # | | | + # ------------------------- + # | | | + # v1 - v2 |delta-| >= 0 + # v2 - v1 |delta+| >= 0 + # | | | + # ------------------------- + # c_wt | 0 | 0 | >= c^T * v_wt ] left out if not COBRA + # | | | + # lb v_wt |del_lb| 0 | + # ub v_wt |del_ub|10000 | + # | | | + # | | | + # obj 0 | 0 | 1 | + + + # --------------------------------------------- + # problem dimensions + # --------------------------------------------- + + nc <- react_num(model) + nr <- met_num(model) + + nCols <- 4*nc + nRows <- ifelse(isTRUE(COBRAflag), + 2*nr + 2*nc + 1, + nr + 2*nc) + + if (is.null(obj_coefD)) { + deltaobj <- rep(1, 2*nc) + } + else { + stopifnot(length(obj_coefD) == 2*nc) + deltaobj <- obj_coefD + } + + + # --------------------------------------------- + # constraint matrix + # --------------------------------------------- + + # the initial matrix dimensions + LHS <- Matrix::Matrix(0, + nrow = nr + 2*nc, + ncol = nCols, + sparse = TRUE) + + # rows for the wild type strain + LHS[1:nr,(nc+1):(2*nc)] <- S(model) + + # location of the wild type strain + fi <- c((nc+1):(2*nc)) + + # rows for the delta match matrix + diag(LHS[(nr+1) :(nr+2*nc),1 :(2*nc)]) <- -1 + diag(LHS[(nr+1) :(nr+2*nc),(2*nc+1):(4*nc)]) <- 1 + diag(LHS[(nr+1) :(nr+nc) ,(nc+1) :(2*nc)]) <- 1 + diag(LHS[(nr+nc+1):(nr+2*nc),1 :nc ]) <- 1 + + + # contraint matrix for linearMOMA, COBRA version + if (isTRUE(COBRAflag)) { + + # rows for the wild type strain + LHSwt <- Matrix::Matrix(0, + nrow = nr, + ncol = nCols, + sparse = TRUE) + LHSwt[1:nr,1:nc] <- S(model) + + # fix the value of the objective function + crow <- Matrix::Matrix(c(obj_coef(model), rep(0, 3*nc)), + nrow = 1, + ncol = nCols, + sparse = TRUE) + + # the final contraint matrix + LHS <- rBind(LHSwt, LHS, crow) + + subalg <- "lmoma_cobra" + } + else { + subalg <- "lmoma" + } + + + # --------------------------------------------- + # lower and upper bounds + # --------------------------------------------- + + if (isTRUE(COBRAflag)) { + # Here we calculate wild type and deletion strain + # simultaineously, so we need upper and lower bounds + # for both, the wild type and the deletion strain. + # All the delta's are positive. + lower <- c(lowbnd(model), + lowbnd(model), + rep(0, 2*nc)) + upper <- c(uppbnd(model), + uppbnd(model), + rep(absMAX, 2*nc)) + + + rlower <- c(rep(0, nRows-1), wtobj) + rupper <- c(rep(0, 2*nr), rep(absMAX, 2*nc), wtobj) + #rupper <- rlower + #rupper <- c(rep(0, 2*nr), rep(0, 2*nc), 0) + } + else { + # Here, we keep the wild type flux distribution fixed. + lower <- c(wtflux, lowbnd(model), rep(0, 2*nc)) + upper <- c(wtflux, uppbnd(model), rep(absMAX, 2*nc)) + rlower <- c(rep(0, nRows)) + rupper <- c(rep(0, nr), rep(absMAX, 2*nc)) + } + + # --------------------------------------------- + # constraint type + # --------------------------------------------- + + if (isTRUE(COBRAflag)) { + rtype <- c(rep("E", 2*nr), rep("L", 2*nc)) + if (isTRUE(wtobjLB)) { + rtype <- append(rtype, "L") + } + else { + rtype <- append(rtype, "U") + } + } + else { + rtype <- c(rep("E", nr), rep("L", 2*nc)) + } + + + # --------------------------------------------- + # objective function + # --------------------------------------------- + + cobj <- c(rep(0, 2*nc), deltaobj) + + + # --------------------------------------------- + # row and column names for the problem object + # --------------------------------------------- + + if (isTRUE(useNames)) { + if (is.null(cnames)) { + cn <- c(paste("wt", react_id(model), sep = "_"), + paste("del", react_id(model), sep = "_"), + paste("dM", react_id(model), sep = "_"), + paste("dP", react_id(model), sep = "_") + ) + colNames <- .makeLPcompatible(cn, + prefix = "x") + } + else { + stopifnot(is(cnames, "character"), + length(cnames) == nCols) + colNames <- cnames + } + + if (is.null(rnames)) { + if (isTRUE(COBRAflag)) { + rn <- c(paste("wt", met_id(model), sep = "_"), + paste("del", met_id(model), sep = "_"), + paste("deltaM", 1:nc, sep = "_"), + paste("deltaP", 1:nc, sep = "_"), + "obj_wt" + ) + } + else { + rn <- c(paste("del", met_id(model), sep = "_"), + paste("deltaM", 1:nc, sep = "_"), + paste("deltaP", 1:nc, sep = "_") + ) + } + rowNames <- .makeLPcompatible(rn, + prefix = "r") + } + else { + stopifnot(is(rnames, "character"), + length(rnames) == nRows) + rowNames <- rnames + } + + if (is.null(pname)) { + probName <- .makeLPcompatible( + paste(toupper(subalg), mod_id(model), sep = "_"), + prefix = "") + } + else { + stopifnot(is(pname, "character"), + length(pname) == 1) + probName <- pname + } + } + else { + colNames <- NULL + rowNames <- NULL + probName <- NULL + } + + + # --------------------------------------------- + # build problem object + # --------------------------------------------- + + .Object <- callNextMethod(.Object, + sbalg = subalg, + pType = "lp", + scaling = scaling, + fi = fi, + nCols = nCols, + nRows = nRows, + mat = LHS, + ub = upper, + lb = lower, + obj = cobj, + rlb = rlower, + rub = rupper, + rtype = rtype, + lpdir = "min", + ctype = NULL, + cnames = colNames, + rnames = rowNames, + pname = probName, + algPar = list("wtflux" = wtflux, + "wtobj" = wtobj), + ...) + + if (!is.null(writeProbToFileName)) { + writeProb(problem(.Object), + fname = as.character(writeProbToFileName)) + } + + +# # --------------------------------------------- +# # build problem object +# # --------------------------------------------- +# +# lp <- optObj(solver = solver, method = method) +# lp <- initProb(lp, nrows = nRows, ncols = nCols) +# +# # --------------------------------------------- +# # set control parameters +# # --------------------------------------------- +# +# if (!any(is.na(solverParm))) { +# setSolverParm(lp, solverParm) +# } +# +# +# loadLPprob(lp, +# nCols = nCols, +# nRows = nRows, +# mat = LHS, +# ub = upper, +# lb = lower, +# obj = cobj, +# rlb = rlower, +# rub = rupper, +# rtype = rtype, +# lpdir = "min" +# ) +# +# if (!is.null(scaling)) { +# scaleProb(lp, scaling) +# } +# +# .Object@problem <- lp +# .Object@algorithm <- subalg +# .Object@nr <- as.integer(nRows) +# .Object@nc <- as.integer(nCols) +# .Object@fldind <- as.integer(fi) +# validObject(.Object) + + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# diff --git a/R/sysBiolAlg_momaClass.R b/R/sysBiolAlg_momaClass.R new file mode 100644 index 0000000..1291184 --- /dev/null +++ b/R/sysBiolAlg_momaClass.R @@ -0,0 +1,229 @@ +# sysBiolAlg_momaClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class sysBiolAlg_moma # +#------------------------------------------------------------------------------# + +setClass(Class = "sysBiolAlg_moma", + contains = "sysBiolAlg" +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class sysBiolAlg_moma +setMethod(f = "initialize", + signature = "sysBiolAlg_moma", + definition = function(.Object, + model, + wtflux = NULL, + Qmat = NULL, + scaleDist = NULL, + useNames = SYBIL_SETTINGS("USE_NAMES"), + cnames = NULL, + rnames = NULL, + pname = NULL, + scaling = NULL, + writeProbToFileName = NULL, ...) { + + if ( ! missing(model) ) { + + # wild type or given flux distribution + if (is.null(wtflux)) { + tmp <- .generateWT(model, ...) + wtsol <- tmp$fluxes[tmp$fldind] + } + else { + wtsol <- wtflux + } + + stopifnot(is(model, "modelorg"), + is(wtsol, "numeric"), + length(wtsol) == react_num(model), + is.null(scaleDist) || + length(scaleDist) == react_num(model)) + + # the problem: minimize + # + # | + # S | = 0 + # | + # ----------- + # lb_del + # ub_del + # + # obj sum(v_wt - v_del)^2 + + + # problem dimensions + nCols <- react_num(model) + nRows <- met_num(model) + + if (is.null(scaleDist)) { + sdf <- rep(1, nCols) + } + else { + stopifnot(is(scaleDist, "numeric")) + sdf <- scaleDist + } + + if (is.null(Qmat)) { + Q <- rep(2, nCols) + } + else { + Q <- Qmat + } + + # scaling of particular reactions in the objective function + Q <- Q * sdf + + # row and column names for the problem object + if (isTRUE(useNames)) { + if (is.null(cnames)) { + colNames <- .makeLPcompatible(react_id(model), + prefix = "x") + } + else { + stopifnot(is(cnames, "character"), + length(cnames) == nCols) + colNames <- cnames + } + + if (is.null(rnames)) { + rowNames <- .makeLPcompatible(met_id(model), + prefix = "r") + } + else { + stopifnot(is(rnames, "character"), + length(rnames) == nRows) + rowNames <- rnames + } + + if (is.null(pname)) { + probName <- .makeLPcompatible( + paste("MOMA", mod_id(model), sep = "_"), + prefix = "") + } + else { + stopifnot(is(pname, "character"), + length(pname) == 1) + probName <- pname + } + } + else { + colNames <- NULL + rowNames <- NULL + probName <- NULL + } + + + # --------------------------------------------- + # build problem object + # --------------------------------------------- + + .Object <- callNextMethod(.Object, + sbalg = "moma", + pType = "qp", + scaling = scaling, + fi = 1:nCols, + nCols = nCols, + nRows = nRows, + mat = S(model), + ub = uppbnd(model), + lb = lowbnd(model), + #obj = -2 * wtsol, + obj = (-2 * wtsol) * sdf, + rlb = rep(0, nRows), + rtype = rep("E", nRows), + lpdir = "min", + rub = NULL, + ctype = NULL, + cnames = colNames, + rnames = rowNames, + pname = probName, + algPar = list("wtflux" = wtsol, + "Qmat" = Q, + "scaleDist" = sdf), + ...) + + # add quadratic part of objective function + loadQobj(.Object@problem, Q) + #loadQobj(.Object@problem, rep(2, nCols)) + #loadQobj(.Object@problem, 2 * Diagonal(nCols)) + + if (!is.null(writeProbToFileName)) { + writeProb(problem(.Object), + fname = as.character(writeProbToFileName)) + } + + +# # make problem object +# lp <- optObj(solver = solver, method = method, pType = "qp") +# lp <- initProb(lp, nrows = nRows, ncols = nCols) +# +# # set parameters +# if (!any(is.na(solverParm))) { +# setSolverParm(lp, solverParm) +# } +# +# # load problem data +# loadLPprob(lp, +# nCols = nCols, +# nRows = nRows, +# mat = S(model), +# ub = uppbnd(model), +# lb = lowbnd(model), +# obj = -2 * wtsol, +# rlb = rep(0, nRows), +# rub = NULL, +# rtype = rep("E", nRows), +# lpdir = "min" +# ) +# +# # load quadratic part of the objctive function +# loadQobj(lp, 2 * Diagonal(nCols)) +# +# # scaling +# if (!is.null(scaling)) { +# scaleProb(lp, scaling) +# } +# +# +# .Object@problem <- lp +# .Object@algorithm <- "moma" +# .Object@nr <- as.integer(nRows) +# .Object@nc <- as.integer(nCols) +# .Object@fldind <- as.integer(c(1:nCols)) +# validObject(.Object) + + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# diff --git a/R/sysBiolAlg_mtfClass.R b/R/sysBiolAlg_mtfClass.R new file mode 100644 index 0000000..362d339 --- /dev/null +++ b/R/sysBiolAlg_mtfClass.R @@ -0,0 +1,333 @@ +# sysBiolAlg_mtfClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +#------------------------------------------------------------------------------# +# definition of the class sysBiolAlg_mtf # +#------------------------------------------------------------------------------# + +setClass(Class = "sysBiolAlg_mtf", + representation( + maxobj = "numeric" + ), + contains = "sysBiolAlg" +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class sysBiolAlg_mtf +setMethod(f = "initialize", + signature = "sysBiolAlg_mtf", + definition = function(.Object, + model, + wtobj = NULL, + react = NULL, lb = NULL, ub = NULL, + costcoefbw = NULL, + costcoeffw = NULL, + absMAX = SYBIL_SETTINGS("MAXIMUM"), + useNames = SYBIL_SETTINGS("USE_NAMES"), + cnames = NULL, + rnames = NULL, + pname = NULL, + scaling = NULL, + writeProbToFileName = NULL, ...) { + + if ( ! missing(model) ) { + + if (is.null(wtobj)) { + tmp <- .generateWT(model, react, lb, ub, ...) + wtobj <- tmp[["obj"]] + } + + stopifnot(is(model, "modelorg"), + is(wtobj, "numeric"), + is(absMAX, "numeric")) + + # If wtobj is longer than 1, mtf algorithm has to run several + # times. In that case, wtobj is not written in the problem + # object, it is written separately (maxobj) and used for + # each iteration. + + if (length(wtobj) > 1) { + maxobj <- wtobj + currmo <- 0 + } + else { + maxobj <- NULL + currmo <- wtobj[1] + } + + + # the problem: minimize: + # + # | | | + # S | 0 | 0 | = b + # | | | + # ------------------------- + # | | | + # 1 | 1 | 0 | >= 0 + # | | | + # ------------------------- + # | | | + # -1 | 0 | 1 | >= 0 + # | | | + # ------------------------- + # c_wt | 0 | 0 | >= c^T * v_wt + # | | | + # lb wt_lb| 0 | 0 | + # ub wt_ub|10000 |10000 | + # | | | + # obj 0 | 1 | 1 | + + + # --------------------------------------------- + # problem dimensions + # --------------------------------------------- + + nc <- react_num(model) + nr <- met_num(model) + + nCols <- 3*nc + nRows <- nr + 2*nc + 1 + + + # --------------------------------------------- + # constraint matrix + # --------------------------------------------- + + # the initial matrix dimensions + LHS <- Matrix::Matrix(0, + nrow = nRows, + ncol = nCols, + sparse = TRUE) + + # rows for the mutant strain + LHS[1:nr,1:nc] <- S(model) + + # location of the mutant strain + fi <- c(1:nc) + + # rows for the delta match matrix + diag(LHS[(nr+1) :(nr+nc) ,1 :nc ]) <- 1 + diag(LHS[(nr+1) :(nr+nc) ,(nc+1) :(2*nc)]) <- 1 + diag(LHS[(nr+nc+1):(nr+2*nc),1 :nc ]) <- -1 + diag(LHS[(nr+nc+1):(nr+2*nc),(2*nc+1):(3*nc)]) <- 1 + + # fix the value of the objective function + LHS[(nr+2*nc+1),1:nc] <- obj_coef(model) + + + # --------------------------------------------- + # columns + # --------------------------------------------- + + lower <- c(lowbnd(model), rep(0, 2*nc)) + upper <- c(uppbnd(model), rep(absMAX, 2*nc)) + + + # --------------------------------------------- + # rows + # --------------------------------------------- + + #rlower <- c(rhs(model), rep(0, 2*nc), currmo) + #rupper <- c(rhs(model), rep(absMAX, 2*nc + 1)) + rlower <- c(rep(0, nr), rep(0, 2*nc), currmo) + rupper <- c(rep(0, nr), rep(absMAX, 2*nc + 1)) + rtype <- c(rep("E", nr), rep("L", 2*nc + 1)) + + # --------------------------------------------- + # objective function + # --------------------------------------------- + + if (is.null(costcoeffw)) { + fw <- rep(1, nc) + } + else { + stopifnot(is(costcoeffw, "numeric"), + (length(costcoeffw) == nc)) + fw <- costcoeffw + } + + if (is.null(costcoefbw)) { + bw <- fw + } + else { + stopifnot(is(costcoefbw, "numeric"), + (length(costcoefbw) == nc)) + bw <- costcoefbw + } + + + cobj <- c(rep(0, nc), bw, fw) + + + # --------------------------------------------- + # row and column names for the problem object + # --------------------------------------------- + + if (isTRUE(useNames)) { + if (is.null(cnames)) { + cn <- c(react_id(model), + paste("bw", react_id(model), sep = "_"), + paste("fw", react_id(model), sep = "_") + ) + colNames <- .makeLPcompatible(cn, prefix = "x") + } + else { + stopifnot(is(cnames, "character"), + length(cnames) == nCols) + colNames <- cnames + } + + if (is.null(rnames)) { + rn <- c(met_id(model), + paste("bw", 1:nc, sep = "_"), + paste("fw", 1:nc, sep = "_"), + "obj_wt" + ) + rowNames <- .makeLPcompatible(rn, prefix = "r") + } + else { + stopifnot(is(rnames, "character"), + length(rnames) == nRows) + rowNames <- rnames + } + + if (is.null(pname)) { + probName <- .makeLPcompatible( + paste("MTF", mod_id(model), sep = "_"), + prefix = "") + } + else { + stopifnot(is(pname, "character"), + length(pname) == 1) + probName <- pname + } + } + else { + colNames <- NULL + rowNames <- NULL + probName <- NULL + } + + + # --------------------------------------------- + # build problem object + # --------------------------------------------- + + .Object <- callNextMethod(.Object, + sbalg = "mtf", + pType = "lp", + scaling = scaling, + fi = fi, + nCols = nCols, + nRows = nRows, + mat = LHS, + ub = upper, + lb = lower, + obj = cobj, + rlb = rlower, + rub = rupper, + rtype = rtype, + lpdir = "min", + ctype = NULL, + cnames = colNames, + rnames = rowNames, + pname = probName, + algPar = list("wtobj" = wtobj, + "costcoefbw" = bw, + "costcoeffw" = fw), + ...) + + .Object@maxobj <- as.numeric(maxobj) + + if (!is.null(writeProbToFileName)) { + writeProb(problem(.Object), + fname = as.character(writeProbToFileName)) + } +# +# # --------------------------------------------- +# # build problem object +# # --------------------------------------------- +# +# lp <- optObj(solver = solver, method = method) +# lp <- initProb(lp, nrows = nRows, ncols = nCols) +# +# # --------------------------------------------- +# # set control parameters +# # --------------------------------------------- +# +# if (!any(is.na(solverParm))) { +# setSolverParm(lp, solverParm) +# } +# +# +# loadLPprob(lp, +# nCols = nCols, +# nRows = nRows, +# mat = LHS, +# ub = upper, +# lb = lower, +# obj = cobj, +# rlb = rlower, +# rub = rupper, +# rtype = rtype, +# lpdir = "min" +# ) +# +# if (!is.null(scaling)) { +# scaleProb(lp, scaling) +# } +# +# .Object@problem <- lp +# .Object@algorithm <- "mtf" +# .Object@nr <- as.integer(nRows) +# .Object@nc <- as.integer(nCols) +# .Object@fldind <- as.integer(fi) +# validObject(.Object) + + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("changeMaxObj", signature(object = "sysBiolAlg_mtf"), + function(object, j) { + + if (!is.null(object@maxobj)) { + changeRowsBnds(problem(object), i = nr(object), + lb = object@maxobj[j], ub = SYBIL_SETTINGS("MAXIMUM")) + } + + return(invisible(TRUE)) + } +) + diff --git a/R/sysBiolAlg_roomClass.R b/R/sysBiolAlg_roomClass.R new file mode 100644 index 0000000..f5aa7d7 --- /dev/null +++ b/R/sysBiolAlg_roomClass.R @@ -0,0 +1,424 @@ +# sysBiolAlg_roomClass.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +# Original code written by Marc Andre Daxer during his bachelor thesis: +# "Analysis of Gene Defects with Mixed Integer Linear Programming" (2011 +# at the Heinrich-Heine-University Duesseldorf, Dpt. for Bioinformatics). +# He wrote the package sybilROOM. + + +#------------------------------------------------------------------------------# +# definition of the class sysBiolAlg_room # +#------------------------------------------------------------------------------# + +setClass(Class = "sysBiolAlg_room", + representation( + wu = "numeric", + wl = "numeric", + fnc = "integer", + fnr = "integer" + ), + contains = "sysBiolAlg" +) + + +#------------------------------------------------------------------------------# +# default constructor # +#------------------------------------------------------------------------------# + +# contructor for class sysBiolAlg_room +setMethod(f = "initialize", + signature = "sysBiolAlg_room", + definition = function(.Object, + model, + wtflux, + delta = 0.03, + epsilon = 0.001, + LPvariant = FALSE, + absMAX = SYBIL_SETTINGS("MAXIMUM"), + useNames = SYBIL_SETTINGS("USE_NAMES"), + cnames = NULL, + rnames = NULL, + pname = NULL, + scaling = NULL, + writeProbToFileName = NULL, ...) { + + if ( ! missing(model) ) { + + if (missing(wtflux)) { + tmp <- .generateWT(model, ...) + wtflux <- tmp$fluxes[tmp$fldind] + } + + stopifnot(is(model, "modelorg"), + is(wtflux, "numeric"), + is(delta, "numeric"), + is(epsilon, "numeric"), + is(LPvariant, "logical"), + is(absMAX, "numeric")) + + stopifnot(length(wtflux) == react_num(model)) + + # the problem: minimize + # + # | | + # S | 0 | = 0 + # | | + # ------------------------- + # 1 | | + # 1 | -vwl | >= wl + # 1 | | + # ------------------------- + # 1 | | + # 1 | -vwu | <= wu + # 1 | | + # ------------------------- + # + # lb | 0 + # ub | 1 + # ctype: C | B + # obj: 0 | 1 + + + # --------------------------------------------- + # problem dimensions + # --------------------------------------------- + + nc <- react_num(model) + nr <- met_num(model) + + nCols <- (2 * nc) + nRows <- (nr + 2 * nc) + + + # --------------------------------------------- + # constraint matrix + # --------------------------------------------- + + # ROOM-Boundaries + + # if we use the formulation as linear program, delta and + # epsilon are set to zero (see Shlomi et al.) + #if (isTRUE(LPvariant)) { + # wu <- wtflux + # wl <- wtflux + #} + #else { + wu <- wtflux + delta * abs(wtflux) + epsilon + wl <- wtflux - delta * abs(wtflux) - epsilon + #} + + vwu <- uppbnd(model) - wu + vwl <- lowbnd(model) - wl + + + # the initial matrix dimensions + LHS <- Matrix::Matrix(0, + nrow = nRows, + ncol = nCols, + sparse = TRUE) + + # rows for the flux variables + LHS[1:nr,1:nc] <- S(model) + + # location of the wild type strain + fi <- c(1:nc) + + # constraint-matrix for ROOM + diag(LHS[(nr+1) :(nr+nc),1 :nc ]) <- 1 + diag(LHS[(nr+nc+1) :nRows ,1 :nc ]) <- 1 + diag(LHS[(nr+1) :(nr+nc),(nc+1):nCols]) <- vwl * -1 + diag(LHS[(nr+nc+1) :nRows ,(nc+1):nCols]) <- vwu * -1 + + + # --------------------------------------------- + # columns + # --------------------------------------------- + + clower <- c(lowbnd(model), rep(0, nc)) + cupper <- c(uppbnd(model), rep(1, nc)) + + if (isTRUE(LPvariant)) { + ctype <- NULL + pt <- "lp" + } + else { + ctype <- c(rep("C", nc), rep("B", nc)) + pt <- "mip" + } + + # --------------------------------------------- + # rows + # --------------------------------------------- + + #rlower <- c(rhs(model), wl, wu) + #rupper <- c(rhs(model), rep(absMAX, nc), wu) + rlower <- c(rep(0, nr), wl, wu) + rupper <- c(rep(0, nr), rep(absMAX, nc), wu) + rtype <- c(rep("E", nr), rep("L", nc), rep("U", nc)) + + + # --------------------------------------------- + # objective function + # --------------------------------------------- + + cobj <- c(rep(0, nc), rep(1, nc)) + + + # --------------------------------------------- + # row and column names for the problem object + # --------------------------------------------- + + if (isTRUE(useNames)) { + if (is.null(cnames)) { + cn <- c(react_id(model), + paste("oo", react_id(model), sep = "_") + ) + colNames <- .makeLPcompatible(cn, + prefix = "x") + } + else { + stopifnot(is(cnames, "character"), + length(cnames) == nCols) + colNames <- cnames + } + + if (is.null(rnames)) { + rn <- c(met_id(model), + paste("wl", react_id(model), sep = "_"), + paste("wu", react_id(model), sep = "_") + ) + rowNames <- .makeLPcompatible(rn, + prefix = "r") + } + else { + stopifnot(is(rnames, "character"), + length(rnames) == nRows) + rowNames <- rnames + } + + if (is.null(pname)) { + probName <- .makeLPcompatible( + paste("ROOM", toupper(pt), mod_id(model), sep = "_"), + prefix = "") + } + else { + stopifnot(is(pname, "character"), + length(pname) == 1) + probName <- pname + } + } + else { + colNames <- NULL + rowNames <- NULL + probName <- NULL + } + + + # --------------------------------------------- + # build problem object + # --------------------------------------------- + + .Object <- callNextMethod(.Object, + sbalg = "room", + pType = pt, + scaling = scaling, + fi = fi, + nCols = nCols, + nRows = nRows, + mat = LHS, + ub = cupper, + lb = clower, + obj = cobj, + rlb = rlower, + rub = rupper, + rtype = rtype, + ctype = ctype, + lpdir = "min", + cnames = colNames, + rnames = rowNames, + pname = probName, + algPar = list("wtflux" = wtflux, + "delta" = delta, + "epsilon" = epsilon), + ...) + + .Object@wu <- as.numeric(wu) + .Object@wl <- as.numeric(wl) + .Object@fnr <- as.integer(nr) + .Object@fnc <- as.integer(nc) + + if (!is.null(writeProbToFileName)) { + writeProb(problem(.Object), + fname = as.character(writeProbToFileName)) + } + +# # --------------------------------------------- +# # build problem object +# # --------------------------------------------- +# +# lp <- optObj(solver = solver, method = method, pType = "mip") +# lp <- initProb(lp, nrows = nRows, ncols = nCols) +# +# # --------------------------------------------- +# # set control parameters +# # --------------------------------------------- +# +# if (!any(is.na(solverParm))) { +# setSolverParm(lp, solverParm) +# } +# +# +# loadLPprob(lp, +# nCols = nCols, +# nRows = nRows, +# mat = LHS, +# ub = cupper, +# lb = clower, +# obj = cobj, +# rlb = rlower, +# rub = rupper, +# rtype = rtype, +# ctype = ctype, +# lpdir = "min" +# ) +# +# if (!is.null(scaling)) { +# scaleProb(lp, scaling) +# } +# +# .Object@problem <- lp +# .Object@algorithm <- "room" +# .Object@nr <- as.integer(nRows) +# .Object@nc <- as.integer(nCols) +# .Object@fldind <- as.integer(fi) +# .Object@wu <- as.numeric(wu) +# .Object@wl <- as.numeric(wl) +# .Object@fnr <- as.integer(nr) +# .Object@fnc <- as.integer(nc) +# validObject(.Object) + + } + return(.Object) + } +) + + +#------------------------------------------------------------------------------# +# other methods # +#------------------------------------------------------------------------------# + +setMethod("applyChanges", signature(object = "sysBiolAlg_room"), + function(object, del, obj, ld, + react = NULL, + lb = NULL, + ub = NULL, + obj_coef = NULL, + fldind = TRUE, + lpdir = NULL) { + + if (!isTRUE(fldind)) { + warning("argument ", sQuote("fldind"), " is currently not used for ROOM") + } + + fi <- fldind(object)[react] + + if (any(is.na(fi))) { + stop("argument ", sQuote("react"), " must contain reactions only") + } + + tmp_val <- list("fi" = react, "lb" = NULL, "ub" = NULL) + + wu <- object@wu + wl <- object@wl + lpmod <- problem(object) + + if (isTRUE(del)) { + # store default lower and upper bounds + tmp_val[["lb"]] <- getColsLowBnds(lpmod, fi) + tmp_val[["ub"]] <- getColsUppBnds(lpmod, fi) + + # change bounds of fluxes in react + check <- changeColsBnds(lpmod, fi, lb, ub) + + # change constraint matrix and objective coefficients + vwu <- (ub - wu[fi]) * -1 + vwl <- (lb - wl[fi]) * -1 + + ri <- react + object@fnr + ci <- react + object@fnc + for (i in seq(along = react)) { + changeMatrixRow(lpmod, ri[i], c(react[i], ci[i]), c(1, vwl[i])) + changeMatrixRow(lpmod, + ri[i]+object@fnc, + c(react[i], ci[i]), + c(1, vwu[i])) + } + + #changeObjCoefs(lpmod, ci, rep(0, length(react))) + + tmp_val[["ri"]] <- ri + tmp_val[["ci"]] <- ci + } + + return(tmp_val) + } +) + + +#------------------------------------------------------------------------------# + +setMethod("resetChanges", signature(object = "sysBiolAlg_room"), + function(object, old_val) { + + fi <- fldind(object) + wu <- object@wu + wl <- object@wl + lpmod <- problem(object) + + if ( (!is.null(old_val[["lb"]])) || (!is.null(old_val[["ub"]])) ) { + check <- changeColsBnds(lpmod, + fi[old_val[["fi"]]], + old_val[["lb"]], old_val[["ub"]]) + + vwu <- (old_val[["ub"]] - wu[fi[old_val[["react"]]]]) * -1 + vwl <- (old_val[["lb"]] - wl[fi[old_val[["react"]]]]) * -1 + + for (i in seq(along = old_val[["fi"]])) { + changeMatrixRow(lpmod, + old_val[["ri"]][i], + c(old_val[["fi"]][i], old_val[["ci"]][i]), + c(1, vwl[i])) + changeMatrixRow(lpmod, + old_val[["ri"]][i]+object@fnc, + c(old_val[["fi"]][i], old_val[["ci"]][i]), + c(1, vwu[i])) + } + + #changeObjCoefs(lpmod, old_val[["ci"]], rep(1, length(react))) + } + + return(invisible(TRUE)) + } +) diff --git a/R/validmodelorg.R b/R/validmodelorg.R new file mode 100644 index 0000000..aba3fc6 --- /dev/null +++ b/R/validmodelorg.R @@ -0,0 +1,168 @@ +# validmodelorg.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .validmodelorg +# +# Validity checking of an object of class modelorg. +# +# Returns TRUE if the model is valid, otherwise +# a character String containing a description of +# the error. + + +.validmodelorg <- function(object) { + + if (!is(object, "modelorg")) { + return("needs an object of class modelorg!") + } + + if ((length(mod_id(object)) != 1) || (length(mod_name(object)) != 1)) { + return("mod_id and mod_name must have a length of 1!") + } + + if (length(mod_desc(object)) == 0) { + + if (length(mod_name(object)) != 1) { + return("mod_name must have a length of 1!") + } + if (length(mod_id(object)) != 1) { + return("mod_id must have a length of 1!") + } + + } + else { + + # model describing stuff + if (length(mod_desc(object)) != 1) { + return("description must have a length of 1!") + } + if (length(mod_name(object)) != 1) { + return("mod_name must have a length of 1!") + } + if (length(mod_id(object)) != 1) { + return("mod_id must have a length of 1!") + } + if (length(mod_compart(object)) != length(unique(mod_compart(object)))) { + dup <- duplicated(met_id(object)) + return(paste("mod_compart must be unique! Check ", paste(mod_compart(object)[dup], collapse = ", "), ".", sep = "")) + } + + # metabolite stuff + if (length(met_num(object)) != 1) { + return("met_num must have a length of 1!") + } + met <- met_num(object) + if (met != length(met_id(object))) { + return("Wrong number of metabolite id's!") + } + if (met != length(unique(met_id(object)))) { + dup <- duplicated(met_id(object)) + return(paste("met_id must be unique! Check ", paste(met_id(object)[dup], collapse = ", "), ".", sep = "")) + } + if (met != length(met_name(object))) { + return("Wrong number of metabolite names!") + } + if (met != length(met_comp(object))) { + return("Wrong number of metabolite compartments!") + } + if (met != length(met_single(object))) { + return("Wrong length of met_single!") + } + if (met != length(met_de(object))) { + return("Wrong length of met_de!") + } + + # reactions stuff + if (length(react_num(object)) != 1) { + return("react_num must have a length of 1!") + } + react <- react_num(object) + if (react != length(react_id(object))) { + return("Wrong number of reaction id's!") + } + if (react != length(unique(react_id(object)))) { + dup <- duplicated(react_id(object)) + return(paste("reaction_id must be unique! Check ", paste(react_id(object)[dup], collapse = ", "), ".", sep = "")) + } + if (react != length(react_name(object))) { + return("Wrong number of reaction names!") + } + if (react != length(react_rev(object))) { + return("Wrong number of reversibilities!") + } + if (react != length(obj_coef(object))) { + return("Wrong length of lower bounds!") + } + if (react != length(lowbnd(object))) { + return("Wrong length of lower bounds!") + } + if (react != length(uppbnd(object))) { + return("Wrong length of upper bounds!") + } + if (react != length(react_single(object))) { + return("Wrong length of react_single!") + } + if (react != length(react_de(object))) { + return("Wrong length of react_de!") + } + + # stoichiometric matrix + if (identical(dim(S(object)), c(met, react)) == FALSE) { + return("Wrong dimension of S!") + } + + # GPR stuff + if (length(gprRules(object)) != 0) { + + if (react != length(gprRules(object))) { + return("Wrong length of gprRules!") + } + if (react != length(genes(object))) { + return("Wrong length of genes!") + } + if (react != length(gpr(object))) { + return("Wrong length of GPR associations!") + } + if (react != nrow(subSys(object))) { + return("Wrong number of sub systems!") + } + + # It is possible, that the number of unique genes is smaller than + # the number of reactions. So, I commented the following out. + ##print(react) + ##print(length(allGenes(object))) + #if (react > length(allGenes(object))) { + # return("Wrong number of unique genes!") + #} + + #print(dim(rxnGeneMat(object))) + #print(c(react, length(allGenes(object)))) + if (identical(dim(rxnGeneMat(object)), c(react, length(allGenes(object)))) == FALSE) { + return("Wrong dimension of rxnGeneMat!") + } + } + } + return(TRUE) +} diff --git a/R/validoptsol.R b/R/validoptsol.R new file mode 100644 index 0000000..67493a7 --- /dev/null +++ b/R/validoptsol.R @@ -0,0 +1,84 @@ +# validoptsol.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .validoptsol +# +# Validity checking of an object of class optsol +# +# Returns TRUE if the model is valid, otherwise +# a character String containing a description of +# the error. + + +.validoptsol <- function(object) { + + if (!is(object, "optsol")) { + return("needs an object of class optsol!") + } + +# if (length(solver(object)) != 1) { +# return("solver must have a length of 1!") +# } +# # if ((length(solver(object)) != 1) || (length(method(object)) != 1)) { +# # return("solver and method must have a length of 1!") +# # } +# +# if (length(lp_dir(object)) == 0) { +# +# if (length(solver(object)) != 1) { +# return("solver must have a length of 1!") +# } +# if (length(method(object)) != 1) { +# return("method must have a length of 1!") +# } +# +# } +# else { +# +# if (length(lp_dir(object)) != 1) { +# return("lp_dir must have a length of 1!") +# } + if (length(lp_num_cols(object)) != 1) { + return("lp_num_cols must have a length of 1!") + } + if (length(lp_num_rows(object)) != 1) { + return("lp_num_rows must have a length of 1!") + } + + num_of_prob <- length(lp_obj(object)) + + if (length(lp_obj(object)) != num_of_prob) { + return("wrong length of lp_obj!") + } + if (length(lp_ok(object)) != num_of_prob) { + return("wrong length of lp_ok!") + } + if (length(lp_stat(object)) != num_of_prob) { + return("wrong length of lp_stat!") + } + +# } + return(TRUE) +} diff --git a/R/validreactId.R b/R/validreactId.R new file mode 100644 index 0000000..bc80d66 --- /dev/null +++ b/R/validreactId.R @@ -0,0 +1,52 @@ +# validreactId.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .validreactId +# +# Validity checking of an object of class reactId +# + + +.validreactId <- function(object) { + + if (!is(object, "reactId")) { + return("needs an object of class reactId!") + } + + if (length(mod_id(object)) != 1) { + return("slot mod_id must be of length 1") + } + + if (length(react_pos(object)) != length(object)) { + return(paste("slot react_pos must be of length", length(object))) + } + + if (length(react_id(object)) != length(object)) { + return(paste("slot react_id must be of length", length(object))) + } + + return(TRUE) +} + diff --git a/R/validreactId_Exch.R b/R/validreactId_Exch.R new file mode 100644 index 0000000..2656318 --- /dev/null +++ b/R/validreactId_Exch.R @@ -0,0 +1,52 @@ +# validreactId_Exch.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .validreactId_Exch +# +# +# + + +.validreactId_Exch <- function(object) { + + if (!is(object, "reactId_Exch")) { + return("needs an object of class reactId_Exch!") + } + + if (length(met_pos(object)) != length(object)) { + return(paste("slot met_pos must be of length", length(object))) + } + + if (length(met_id(object)) != length(object)) { + return(paste("slot met_id must be of length", length(object))) + } + + if (length(object@uptake) != length(object)) { + return(paste("slot uptake must be of length", length(object))) + } + + return(TRUE) +} + diff --git a/R/validsysBiolAlg.R b/R/validsysBiolAlg.R new file mode 100644 index 0000000..e9bf1ab --- /dev/null +++ b/R/validsysBiolAlg.R @@ -0,0 +1,43 @@ +# validsysBiolAlg.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: .validsysBiolAlg +# +# Validity checking of an object of class sysBiolAlg. +# + + +.validsysBiolAlg <- function(object) { + + if (!is(object, "sysBiolAlg")) { + return("needs an object of class sysBiolAlg") + } + +# if (length(fldind(object)) != 2) { +# return("slot fluxdist must have a length of 2") +# } + + return(TRUE) +} diff --git a/R/ypd.R b/R/ypd.R new file mode 100644 index 0000000..fa79adb --- /dev/null +++ b/R/ypd.R @@ -0,0 +1,134 @@ +# ypd.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +################################################ +# Function: ypd +# +# There are currently two different versions of an +# in sillico YPD medium: +# +# 1) Harrison, R.; Papp, B.; Pal, C.; Oliver, S. G. and Delnert, D.: +# "Plasticity of genetic interactions in metabolic networks of yeast." +# 2007, PNAS, 104(7):2307--2312. +# ver = harrison2007 +# +# 2) Bilu, Y.; Shlomi, T.; Barkai, N. and Ruppin, E.: +# "Conservation of expression and sequence of metabolic genes is +# reflected by activity across metabolic states." +# 2006, PLoS Comput Biol, 2(8):932--938. +# ver = bilu2006 +# +# One can choose between the two by changing the "ver" option. + + +ypd <- function(model, + def_bnd = SYBIL_SETTINGS("MAXIMUM"), + ver = "harrison2007") { + + if (!is(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if (mod_name(model) != "Sc_iND750") { + warning("use Saccharomyces cerevisiae mod_name(model) == Sc_iND750") + } + + medium <- matrix(c( + "EX_nh4(e)", def_bnd, + "EX_pi(e)", def_bnd, + "EX_so4(e)", def_bnd, + "EX_glc(e)", 20, + "EX_o2(e)", 2, + "EX_ala_L(e)", 0.5, + "EX_arg_L(e)", 0.5, + "EX_asn_L(e)", 0.5, + "EX_asp_L(e)", 0.5, + "EX_cys_L(e)", 0.5, + "EX_his_L(e)", 0.5, + "EX_leu_L(e)", 0.5, + "EX_lys_L(e)", 0.5, + "EX_met_L(e)", 0.5, + "EX_pro_L(e)", 0.5, + "EX_ser_L(e)", 0.5, + "EX_thr_L(e)", 0.5, + "EX_trp_L(e)", 0.5, + "EX_tyr_L(e)", 0.5, + "EX_dcyt(e)", 0.5, + "EX_gly(e)", 0.5, + "EX_gua(e)", 0.5, + "EX_thymd(e)", 0.5 + ), ncol = 2, byrow = TRUE) + + colnames(medium) <- c("react_id", "lowbnd") + + medium_unique = NULL + + if (ver == "bilu2006") { + medium_unique <- matrix(c( + "EX_h2o(e)", def_bnd, + "EX_na1(e)", def_bnd, + "EX_k(e)", def_bnd, + "EX_co2(e)", def_bnd, + "EX_ade(e)", 0.5, + "EX_gln_L(e)", 0.5, + "EX_ile_L(e)", 0.5, + "EX_phe_L(e)", 0.5, + "EX_val_L(e)", 0.5 + ), ncol = 2, byrow = TRUE) + } + + if (ver == "harrison2007") { + medium_unique <- matrix(c( + "EX_h(e)", def_bnd, + "EX_ura(e)", 0.5, + "EX_ttdca(e)", 0.5, + "EX_hdca(e)", 0.5, + "EX_ocdca(e)", 0.5, + "EX_glu_L(e)", 0.5, + "EX_ergst(e)", 0.5, + "EX_chol(e)", 0.5 + ), ncol = 2, byrow = TRUE) + } + + medium <- rbind(medium, medium_unique) + react <- checkReactId(model, medium[,"react_id"]) + if (!is(react, "reactId")) { + stop("model seems not compatible with ypd") + } + ex <- findExchReact(model) + + num_med <- length(react_pos(react)) + num_ex <- length(react_pos(ex)) + + modelNEW <- changeBounds(model, ex, rep(0, num_ex), rep(def_bnd, num_ex)) + + modelNEW <- changeBounds(modelNEW, + react, + -1 * as.numeric(medium[,"lowbnd"]), + rep(def_bnd, num_med)) + + return(modelNEW) + +} + diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..864d5d0 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,131 @@ +# zzz.R +# FBA and friends with R. +# +# Copyright (C) 2010-2014 Gabriel Gelius-Dietrich, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: geliudie@uni-duesseldorf.de +# +# This file is part of sybil. +# +# Sybil is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sybil is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with sybil. If not, see <http://www.gnu.org/licenses/>. + + +.SYBILenv <- new.env() + +.onLoad <- function(lib, pkg) { + + # -------------------------------------------------------------- # + # stacks and queues in sybil + + .SYBILenv$sybilStack <- vector(mode = "list", length = 0) + + + # -------------------------------------------------------------- # + # settings in sybil + + .SYBILenv$settings <- list( + SOLVER = "glpkAPI", + METHOD = "simplex", + TOLERANCE = 1E-6, + MAXIMUM = 1000, + ALGORITHM = "fba", + OPT_DIRECTION = "max", + USE_NAMES = FALSE, + PATH_TO_MODEL = ".", + SOLVER_CTRL_PARM = as.data.frame(NA) + ) + + + # -------------------------------------------------------------- # + # available solvers and methods + + # The first method in each vector is the default one, the default + # alternate method is NA. + + # solvers + .SYBILenv$solvers <- c("glpkAPI", "clpAPI", "lpSolveAPI", "cplexAPI") + + # methods + .SYBILenv$solverMethods <- list( + glpkAPI = c("simplex", "interior", "exact", "mip"), + + clpAPI = c("general_solve", "inidual", "iniprimal", "inibarrier", + "inibarriernoc", "idiot", "dual", "primal"), + + lpSolveAPI = c("lp_solve"), + + cplexAPI = c("lpopt", "primopt", "dualopt", "baropt", "hybbaropt", + "hybnetopt", "siftopt", "mipopt", "qpopt") + ) + + # default parameters + .SYBILenv$solverCtrlParm <- list( + + glpkAPI = list(simplex = as.data.frame(NA), + interior = as.data.frame(NA), + exact = as.data.frame(NA), + mip = as.data.frame(NA) + ), + + clpAPI = list(general_solve = as.data.frame(NA), + inidual = as.data.frame(NA), + iniprimal = as.data.frame(NA), + inibarrier = as.data.frame(NA), + inibarriernoc = as.data.frame(NA), + dual = as.data.frame(NA), + primal = as.data.frame(NA) + ), + + lpSolveAPI = list(lp_solve = as.data.frame(NA)), + + cplexAPI = list(lpopt = as.data.frame(NA), + primopt = as.data.frame(NA), + #primopt = data.frame( + # #CPX_PARAM_REDUCE = as.integer(1), + # CPX_PARAM_DATACHECK = as.integer(1) + #), + dualopt = as.data.frame(NA), + baropt = as.data.frame(NA), + hybbaropt = as.data.frame(NA), + hybnetopt = as.data.frame(NA), + siftopt = as.data.frame(NA), + mipopt = as.data.frame(NA), + qpopt = as.data.frame(NA) + ) + ) + + + # -------------------------------------------------------------- # + # algorithms simulation genetic perturbations + + .SYBILenv$algorithm[["pert"]] <- c("fba", "mtf", "moma", "lmoma", "room") + + + # -------------------------------------------------------------- # + # methods problem types + + .SYBILenv$ptype[["mip"]] <- list( + glpkAPI = c("mip"), + lpSolveAPI = c("lp_solve"), + cplexAPI = c("mipopt") + ) + + .SYBILenv$ptype[["qp"]] <- list( + cplexAPI = c("qpopt", "baropt") + ) + +} + + diff --git a/build/vignette.rds b/build/vignette.rds new file mode 100644 index 0000000000000000000000000000000000000000..96995892eae63d3b7a3b12961862edf17354273f GIT binary patch literal 230 zcmb2|=3oE==G?%ud`$*C_ZaFG3=JQ$eq$>5$Sbl_LfF}+Vs6e1)nWlRryW0^Bsm%w z<z8BM`}+F7vtn&pCbZ`COiXpo`YrJ6L3Tlp%#%YeUp>=GnX%#)gPE;EQ^T9hK1-Tb zcfBcEx_T1VQOTP@ydP&6>n#m1R}%63_gya{jiEbH<HYCR&&_$BMZ~8XyS|T^eWyb_ zX5+h`Kj-&HH*d1}u<YFFiN-5u@|*hUsK`H`=lXT$jpZ70L33tE)&27SvO6`d{W0I_ kcgAu8Q3k~qLxOVkUKvJRG|+Cm|FVwp!2LIY=NK6n0MaIF2LJ#7 literal 0 HcmV?d00001 diff --git a/data/Ec_core.RData b/data/Ec_core.RData new file mode 100644 index 0000000000000000000000000000000000000000..4030d203e277531c772fa49364dc271910625cde GIT binary patch literal 6640 zcmb2|=3oE==C`)dIWpHvH!t~d;qsN!o1U~Eo2aX=o4dz)^Z6rwJCrnoL^X3&v^G9I zai+jh#XRcWn(v8|Gv)m5y5CXry|lzL-m~%B;uHSznT<*sQ7bjNL>%pfwm4jvZ{})0 zsb5T&OGNj=ftQxX-|tjEJEt>!%FAPpE)O!^?d&f;Z~OdC@%cG7C1Yn-UAy)Djoo1b zww}h{3~UQ`q%-{Ul&J36TOd1gonF}9Y1t}l{#m|@U*G%mXw&U=PL(}Z`*((}kNfPd z>m<Hi&V1d&HM@W9c)9jC@8cb}KJmHtK3Ea`ZkgSht=Dw6-bq`1HKS^6^w~bM9DBai zRj+-QUlnv_ce(uFNm8ij-4iu==^HP`wm)**f6E|EnY&T1NO7~uw4S|pVrutQO|FVm zJoD^^$G)9Wyo*a)`7Ey*JQ6Z`6*BkNrYsSQ{Pk6RS@&Ou>^=5KW%kLHWwUy;(=A)> zMqM=sPkg;_o}$*(sP^P}OB3}DOOz|0&gN5poF-}ZsBDj^Y-mf^r<x~T8Isy@-iL4O z2%DaKxAdN{!PRY9#j{q|?7Miis<g1Hvv%vfh&kL_mCxPY9aTMjJOBD?<~L%pr!7z1 z^juDDlC6)N^41A_Zm;=_Ry^)nSh`#;N#lU1GjDt3O^$@@#3|g&f!A#AM4Zl=vBdg_ zZ?Z;;<h;W=$va+dl5Cr`)nJjEsrk-Tg2BamBT{VkN5ni1yLrm+S9SE=n91GQJ7OP9 zyYVh;wUyTLo81{1=W{)>cHMV5zvz#eW#8qpRhyn|ot+(*rL{Hc{+eC7`J3lu{VMf4 zE_&C`XKC6Ww-sKI6Q4Z})LLUGpY^6GJfL^^=cXB1UxH?a=&`z8{wQ@NcS%gCb=H(N zxephAZQ8wU=bq5Jc59li`c|a|7H^2kUVh3Tvv;Dj@ZB$=eAAX|Evh)-6?^wX!~MR) zVN&td5%bocc*G>?u9hu(FZ0tXQQdd5zuY<2Zhrl)h+$3EDmLz{O6l2r2AoV?!B<PN zH*dc7=~kYWbf(<QcWW$p*UR<av!A-_#;c|$i8*#g-yE;aYW%h|%G&AQqU%xbJKqJf zoY2!RyS{Tn$)70()(cNek=<%*;=5sXMBn#QZdS9NZ&>tr&2_2UD}$yat@_58zo5hF z@}o7Srcpj;UbWUvzZGY?q&}g9Pp7WC>*CHUdxGEh+E*<N`)Xx+<FV<4$(!GpCD^Wf z8nrlj?d}T-<p(S7_pO|^`_9^3r;`rs{Ks6f^R~6bqO)dEaq;bcIUECQ>=eq|wPbhf zdU(ZF{fS5)*Yd|rrOo;8_8m!yzIfJUy~NrU_ZL4JrM<U`@7~ImcR(qU<LcGatD4LC zLJn?@U9G#Y@tIQ7uKW3~uRV_Tk1L<P*L3?$PAic`-)d#~8lsZByO<qaPrN?3<b2+> z#gmW8NJ<=)ax}5ZW)aMk;mNoj_ttu?^b5!6^|x2$s{c89cK=n2wYn<%Yc=+lt=$-P z+*$nn<h1z4`ge}`9lNhb?o;2J+oZO4udX<sz}vDS!+pW0Yfo}4*^}{Q+m{x>KQB}3 zOn>#<=k562{n$7E^;P|KvGVfn#n#2&9$Dw@dFSZH{Pe``zplG>YxqxlzAR(%50CbD zr%z3u9=+=6tEsH&ExMXQva40uePhp^Xgh5jyt(MiQ^~8jJ8aA?Q*%!^a!;+ixhY`h zyrp&gF)J!x`|aL)Vw1MM{<$eDzsqqHblz_~`P$^;lVWc1j6mh!?&1@QtihMVHD*Z7 zjN4(gx<YDhUD?HzYIh5*T54quxrS~PU!AwMO?%b6rCQ${S?@h+-+f^3?y!rmvPAEG zEnvMft3C4L`=ei1>8+P))XGiT@sf}KWB!7}q5o`)D<tl`S;aMlJ6`G0*{BKz7uQ6| z2X~jOlH60Va7|aqeWQ|(uS{2p%deamr5`t2>%@-#w|di->wYc&cx+G3PQ&{f#a5=K zsKw8m6*|o#c%8@Lc{69TNNq}ecdGPi(b337Hn%RExzoGS_v+hYqSp#)gL`)_Jd;-N zjLUa3J5%YVV-LM22XCIe>GIN(mP)4Prn@!V&rE;bF;!4w^HZL4r}r9L*v}1gePvLy z)W&r7$;%lB#MYhlIuxF^`N*jSx0IVjUAGi{+@y8x<fAjHp&_zq5$u!x2Rs!Lc3x`a zS?nCxyC!D(RqoWQzb#)G##FwOQZ8O=w6^QWsTW_RCr|b<J8YLHEZ^XJHRAHsO>>GD z+JsMgdQ;PTn!bKYL?l-&<FhMC`i0+Cwy^&^x8(3Are*b+m8<g(XYO8hzwLXmz?O@8 z6((2Y&v|aYx=#0Mtnj;gQg4@CSJIUg+AjZWt(1`P)=YH|J%z8P%lA$CB)PhhcXQ1> z5lx26&lN-Ox5SyOy<2>z_4Be_)jiU`L=1(FulX5t)^N7&dgdv&X20(FZ@9<%bAH-k z?Fx-KS2((RmTd`=dw;q3*@r31=T=>f{`_i})ExzNNA4;CKk?$bD^0B~+*_ekx#N7+ z&ewU(8n%tGw`TK7bg+c&$@5;bDYr@9{Gr|17Co1bJr)bktoD{Ka$KXo^V!in<q7Xk zZ#_3_CEx1yhZ};r3!?uSP0QBSzH9bH?dC+Q4%Wc`-(IC1U%hVYp3>`I%(70OxN~XK z%r~p7kCx96EA+ZEckZXn@gDioRniBgW0r9#?wOkvpK`^gd@<MK@YJ%_<rlvk6P}fs zah5%xB<k*r6Xve3To-w)w_j!CR&_biOY|kLd&(vEe9L1&wzjvEG~Ug(6_1pWkv0_W zp5xmR?sd&YN@KU+Oe3w`%0}LT3!Pqeo)DPHcOhCXa-omh`A0JsWaas)KdM@pmhGC6 ztIf?^oL@F4dIPi6SKmz^FMm}2+FP2^TJlD{^Tw5JCfx?Dr%Im6D)4UJR3Q7uVP9rb z@WC9D;+KmV13h2OF<G*9dg9E@pF$!;*^UMEZJcMg^OkYF<n8}GCz|rN>KWY#%{;a5 zcHzttx!K+;uNf@-)av=-{<|Gh0;*F&XYGB~u4pw;uh{-#@Z>o`%u`<<H4O3*KH_Ho zaNhHGS~p9gx2i=vw7OX7Vxv64pFb(}yF%W{wQpaR_{z?W)+y_myW!tWuiJ^IRL;vB zKT!Mnpxkx8#=?zXx97$lXPLXhvd<xUZ5CTUYt6dMD;GVwWBj=m`_&$dop#9N{H$$t zJhIJ>jOPRO<ceyxKg|&pnEPps-K`z-KW*BmZL2j!ZpVTEpG9nwq#s6ARha&=Ilyvs z{qCI0^CzgO&I@Z@Ja6)+ol`0_L~Z(SW&Np|o_nBYR%JT-$Cqg)xw&C;uTA>D#PL#n zNq64E54!6Xr!6?{DnH*=kXd{2w8e)S*RHvD^VgYa9_6!jKIh!h+#bpO^7+Crl~lQl z4}Wg6xw~!e_H##jKkiys=(jjHS!aHz^A_EZ?3G6^v-EF|JT$j5&6rc#sP)^azD3QA zC$>6^o5gK1x|jW)H92pmtex7nPa(@goh6TX8r1ABQP>gBmAYCy-mvbA<=Ocm9p_o} z?q5C|&0um@W!>>V`*Z`1|17Ca;$5fA@UN5WgNg&&0imyp8Jrn@GxA9|u46K-kx<Y) zRbi|Di<evKxy%3GM<jec$O{$={Ow-!Pe8i4c;1B{3o0is`Zw3G^tsF5hKSRQj@3SA zD(x9K4jM4Zv05;Hu#omIzR3{TAauZ*<!m~`siyynoBky_PCqu?B#w*WJ==_gQq6|# z(vEtznlBzl$tTpdwVvVc+_~YcVnaKlAM+mG2Zjxs7yaL{U?$rMW)a4DY!%`MOb!$_ z1Sj29ceT{K_I1Gm-(ul^9FJ?gda5Hn{O-wcm-6rYl<Ah-KjHmkpJ{C~=AZsKchUXZ z60w&wU$Xsv-m_uf`Hru}(H1LSPI`7$GST+AOT6FwUv_#aUat?xcgrQd6=&%!biVni z^4h<a1It-@MWVIW^?ti9+;e{UjT(PW*&y3q-Oio!F1-kpJ^P<$vFl%t_FcJ)WiEtW zaO-X|ugx#2op9IY<h73rUK9tt5d6<}L*oDOZ8>YdsLXnQb@|afHT)OnDO<Tm*!~oH zb^iPEdVY<H$B$RaPv@U@U$w+4nWg$SQ?|RT-|+{(_ARi?@LS_N|5)wWl%6;b{$(?& zgFYNQu2^TI(JotlnS<v;v(t+w1}ARHCAJhK&l6<w?(D4RO5l4Sbzn1tyg^g@svq9z zH51z1e{dbpVvysj2&mzBAm$*;F#nnvgAK!zr>+fR4$=(uzIRv;v~SgCu90|<%wW&_ zVKc*gmLDPq(i!adKV&n+GyafmSkLrF@xXkhKavOHnf{m_FlYQH_TV-{J^u%OhW{)d z^cn86|1fX(&+<dQL7ric-n`JJ7@-6K&Iz7Ob4r<7W-`oFIZz<1Fr6jm2aARpqnGD_ zHjjphDhD)#7TjTxaAp#j$q=c!jzNc^VU3VJgAU^w7WQ-x!{%VqstLVUH@kgF{H9TI zaEg7`s}(Q4S1}~Y=1crzoDi}5uYBXA`?~A?7VO;@Uu|Er{IPn^kB`<%_XpdRN6VGW zmEc`he$2$`|KIoV|Ds-9sD3Z==YD_fxAyp|oTPu%`|IBv{%>P#xNYb6YuD|+ZnSRc z{&xGm<=5NwA1~eibMo!_xwTJEPrvv1)m!WJa+x(RFHgOFzh>Fb-S=;PKl3*K?wYzw ze-FvuvHTUjzWzb+{e4QuyI;>`me<)Iw&PDP=PtX-jBmg9fB*3PUB~OU@--iC&9|Rx zU-NtS{;!|%@2vVWQO5kw)${NFzq9{$_ig>(U-h=%kKh0GBJbvLS?3e(G5Pi7>5uQP z_;>%+b@S}{ciaBvPw(%1p!BtF`{(^P|2@z9d1IaIyKhycKi^H8Q?_gUyRdh=bI+H| z<<PsmZTs%4_x*lfv~+lWXm+lAd3L*X?EAdOySK`}zs6Utb(}M~`fu5)e)C=OC3Al4 zNzS?ZKJWSdXxnd-v-RuBPse}Bx_&=C=HPM_-LCy#pDoO~o9X=cfW+!MyZ2aGzAuT| z$~!mW^2&QfVPDN{+gBFnWZ1`ikBiHCP%EZZA@;sTZNde=^<S1>_n&c}<Iz63zhCy( zeX0KX{(JfJjcbqZ53JjE+I{`M{F1%5mwtEqd0%t>?ycu`Z|#12ne%;D-sY2KM_D32 z?|r@Zwf}`sfALCh`KUEjdTEdU)F$pZS^w(Fp6})F->>~5eouV$*=t+#?)oq8lYF)O zGW%rd^XYlB<PFW|ZO^-;FYztMCjav7=f@W~o4uI8tyg)IpIyA^)T3)t+ZM$ro#Izt z=&e?J+2s7Jh*Kvfm0n)b=-l8H_s%_y)p+KdbEaoM{!9`2{WPD+bcfgx(HV_Q+om*0 zY3r_&EZlnJ>OM<5zAg7HrY@MkS`=t_!u256S{cRkf*^07EYZAQH4ZB^vb?&k1&Yk? zee|1y>+HFfmb7T|t(Ny+T^HWqcbjiY7Psnc%awP3Z?M!~#r^Qrq7`~ySKIX-(-D~_ z%5|EnH8uC<Th2GrM6X&Fih7;o@;;&U_#3Zfw36?WC4NPTbD!ue`z&ML5HoE;sY%0} z8OGwq=?Mb2AL_l(%oJT@yJJg{Q<SBu?iG(X4{iM=Q^SAr{y2Bq^+#>%wNFnpJ}K5d zIeO-2Qin_D$%PZto(NP4KAe$rZ~uYThzXw`v#=W0J4W{I_vES!@>qBwTCr8h-6Gue z<W;RRK_ZhhxOQvadZZN+B*LW6HC5#3rtTzu@z%#0oF}KT?47hAJm|D7=jEw?ToWBH z=sunLD8MV}^c1d*?{05D8#FN{d!@?UoT$!66%RU>-c7r7rr^H(j>}sT^e3wwpXQl< z^2C;~y?V=EotVFjJ4^I%hxg0h5uM4Bn*W16l$FmYH9vO=2vD+q^L>G_(qf&1>Qne9 z>b4l1bZ}Ut;?Ypge{owznReAD7TKIv6ZT4q8SJPOGT8Ma!dWFKy(XyS)r9}&BMwy< zl|?D%t$utt?fLTaLOZYa%;kO0vqdveqVldx&e64d@4AVoSfty!w%A`^{zs7QNpjn- zifb2wZk;<R9y;A2OHz4`j8xY0%bBZWrr73QSm&a%dP=xS*Ug|3u?q&Xmrl4}*54A+ zd+d6URrCqBA52DFQ%eqVDYkO(YKQB%WZtmcHYaD{j;S>r>-Tz@uv(v=$mHH7bF$#b zqmHu^b=-?&G`}XOg;jFub!}O3XR(%d&ccQ%5#`7HrG8$Vnm(1QXMN4BKCWE>FOI*l z{qwFMb%)pr-<w$r6O36SEuF8=>Ydt>qI<jRi^ud!r+%!-$^30QB{tRg%t3~v!XwW( zZeA7mtU429pXSEOoyMoqPLyk$O!*{fw?6gbv=?j}i^B|qW@<iLld*Ku>%enN$<pUO z>ss7>7-U@8eIvC?N9@uW_o+!SQHGNrddyPHtWAEj>Qmr!{u+&qOE<f26$r?>qJBf{ zHJ`^7^_0u468&?wCH3_$`lSC+k9U#4-y;V&jRIG*`%Sr;`X<Th5_6m3Y(3Y$MRMN~ zqYZTqd=wO2KlSWn6TVH(TP8gBXjFFXGdR4xE3+@f0_1X!Y07^j^o#hq<}@p<o!-i@ z)aJh1O97|X(j2ROXZq*OZe){r5!v^|LWo!SjnMsI*6tq?&*V-&;+X8y*Lm&P=Ub}J z4l{KAYRrkUidgo1lIYfs5=HsD^UF@yALLn6t#_==+sCqOo5<a02c=^<n+?^Amrdx~ zReCx}y>seWQDxf$(rGgfRUgatF*P$@zh-XVFT>SGQs%MVbqN=^TVW#Dox&B?rYz=O zp(6Zv>w--uCa%zLI(wSOXl|dN@BY0E+*^MdPUyc}P{Y42(L!vCe91bqXg7<)7Sp~c z*Idq?S@%UNzxqd=&CD;4EB6Z@`{bD4@%Xr;XvcZhsZRUi_by~<aja^vnPu|VHhY#| z@=cS!FXl|;el<;p<FsnNL_d45gN|Gz=h?5OJA%I@=g(gvUvWC9@Q(hkw~~?BCnxE8 zM@F9N?SCAz+c!kad*YrY@01O__yuC5jy*q^z;llI-k%FGA%{#RJu(z9J@!QHo6+Bn zIo{h9{@&@gdb{JUb_65a_Qp?&8+d(0ABCrNN}T)kRpL|;cdLNu3;u_h`+psuTz5d~ zgvjF1$W5u5+WWaDeL1{s0b{aRq!z0x&-WD1cYT)^$nto!mKn&1y7IWqTvU^PTt@G+ zmRIZgrrd-Bn$OxYjLY5~h$}miXV7x7?S}C-<#48!MM>S$xIPstd)hOIwsBolpL%I& z;kG3<pWP*Lew7$p;NftZu=0~uU4`a1A(xV_9{CV2@8bzUnlg(#RG#J=n-#X*UH@Bg zu}tH}Bm>JMoi)XY9U3KVj7j=)e=07VqkdZ1oQIM5$zxCZZ^EBi&T4wQMk=v7?os!a zjNFuRa@x{0I!{wP&jn5?7U@3n%h}U@k#HH4yM(4~t}*NHO~PF#kIq*+bUuA){_(}G zQ>ShSm>{u!;>W`eb#BLT#K;vk7S1Y|E3tIq_sh4odhtATQDrMwB(!LIVV>R_xf}i0 zoeF1J$$vg1XK2BFjlWUSxQ6HCpDLc?Gc2b>=$-7}?^HNlDv$Gh+d(nq?!>T!#-A@f zcKzmU(mFVO)5`;Yy}6HiXx($_yzto5K4a13Bb!n@=jmmAmi7NtF>&r))ydvWOiLV` z1Y|xs?hEX6l&n)>{d21%CUM8+wcBneWL#N!J>BJ0G0y|jr58O`8GpO;cJi$$SClwU z&zP}1-^obr(M>JJpZ{k?_i(zDO;Zc`?d8vZtVOBza=6#?s#{(g7ppH$*)FTHaLTs# zMn6?{=guv;by0JFXwb>?oSs<|V<t>Fcg=FajN%>n=iKKOSFKxqzfk7f%P%&~k1v_7 znLTaU&5Ij<Cr>C06x*M=%=KlvWaaxko+hq`zMa=w;x?sjTj7>(zO@=mRi~PLZ~gD+ z_0HU2yL_pU%2tn4P8%05*P5~YPT99c#i(nIl53{r2FSdSWLowh=*jC|X<i$V=X3jh zZ8@}2Uh3fO`SFHV?#C%tNQ=I1?5deu(ZIM@(>J_kq4@r$g20%U+C0^~U#At@ADGX5 zZ~4I)41bCa3iC{AtJ?h6v&?om<G#D|ZXPo|`rxhGhh<-@dB3(*w>74&Fki&^g15A3 zk6>N2>{E~YI(yv*l8j%<%=TW~8$3hggU#+s(RVqFnbN8cs47<+{IyANPl~UB{sXQ9 zp$%LIs##)$Hz+)4Ye+Y(@H_CE^+ES-^P68=5AgL*mi@O#@Xx}(3v(y(J`}h9)@_#} z{w0;WX0q&ktK;G)UY-_7xc~3=|1YH+e}s-GyL~9ynYm)U#f9mTFTA-@qVLSR;C4ap z$90|^=eV8re+k>a?tJF5c8kj6CnZv==bjYH{aEX>?7etZTG5yJZ|VgOFh&@?d-t@W z#?bEF(ux|>l*=4(eg88X`Wb4jaKugdzeBL*&{JWz510O|cKh(?&w0i_HV5=24tjrC zFWFdEf083^#eb6n`qBrxzs_g<A#-58#6j<G@eDsg8}ylKPIAQU`d`{`pXJA<hrhMA z%>I2ckL}2>c<xvJ3AJZ#zv55$yDwqS$F%yuzjAk)B^<16JileK{8%afO26RhVf_Nz z4(5t>yZoH3yS=ZQ-!^2o{VO-$&a#DF&}!*-4z`cQ9*f(4@d#Q)7PY<L_*ig8qLEqU zcze65m1Rl9lNA~U2OJpq%SskhFf1x|VQ*t(wk$1q@gn1;fwOx1Io|zzMK=QcEORy7 zz5GOEGmdh|JmWt0PM+h%myZnY>AvS?$fs0Dd^mskf}%kp3p;~lnazafTMxf$xNvmC zLOajH_D4%1PkgCOT6a{=FTb9Dx%sp0tYU>Bb!W@&y|wU;+k0(U{#3gS4)@<!=lkWC zMEPA^dwq9l`#zUC3Hz0?t7kpU%Dp+~&YEjazsszD^nChXecSH;;wzrkzlg5uo;1n( zU%kcCtLC@2ehdB=-Xgv3`G2*wZt;uc=knEieor}?`$K+F==|qvE#_{WKG*l+!x_KU z6{I*GKh3*5vOGGDeaEu=n#(@v`lfrXt-9Q>%scMzl<e=DgL*=K?0NCszT!@^eE57x kMdMfhmoH6Fwq3!q)qHwZsq2x7zyBFzz1-exEoEQ;0Ix9e&;S4c literal 0 HcmV?d00001 diff --git a/inst/CITATION b/inst/CITATION new file mode 100644 index 0000000..ca690fa --- /dev/null +++ b/inst/CITATION @@ -0,0 +1,20 @@ +citHeader(paste("To cite package", sQuote("sybil"), "in publications use:")) + +citEntry( + key = "ggd:sybil", + entry = "Article", + author = c(person("Gabriel", "Gelius-Dietrich", role = c("aut", "cre"), email = "geliudie@uni-duesseldorf.de"), + person(c("Claus", "Jonathan"), "Fritzemeier", role = "ctb"), + person(c("Abdelmoneim", "Amer"), "Desouki", role = "ctb"), + person(c("Martin", "J"), "Lercher", role = "ctb")), + title = "sybil -- Efficient constraint-based modelling in R", + journal = "BMC Systems Biology", + volume = "7", + year = "2013", + number = "1", + pages = "125", + url = "http://www.biomedcentral.com/1752-0509/7/125", + doi = "10.1186/1752-0509-7-125", + issn = "1752-0509", + textVersion = "Gelius-Dietrich, G. et al. (2013) sybil - Efficient constraint-based modelling in R. BMC Syst Biol 7(1):125" +) diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd new file mode 100644 index 0000000..582a5b5 --- /dev/null +++ b/inst/NEWS.Rd @@ -0,0 +1,1273 @@ +%% sybil Version History + +\name{NEWS} +\title{sybil News} +\encoding{UTF-8} + +\newcommand{\CRANpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.9 2014-11-19}{ + \itemize{ + \item fixed a bug in class \code{modelorg} and function \code{addReact} when + the modelorg object is initially empty + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.8 2014-08-29}{ + \itemize{ + \item for method \code{optimizeProb} of class \code{modelorg}: if arguments + \code{lb}, \code{ub} or \code{obj_coef} are of length one, they are used + for all elements given in \code{react} + \item function \code{geneDel} returns a more illustrative error message if a gene + association is malformed + \item fixed a bug in optimizer which returns the wrong objective value in rare cases + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.7 2014-06-05}{ + \itemize{ + \item added boolean parameter \code{fldind} to methods \code{optimizeProb} + and \code{applyChanges} which controls the usage of parameter \code{react} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.6 2014-06-04}{ + \itemize{ + \item function \code{findExchReact} gives a propper warning, if no exchange + reactions can be found and returns \code{NULL} in this case + \item fixed a bug in function \code{addReact} which accours when more than + one new gene per reaction is added to the model + \item function \code{checkSolStat} recognizes return code + \code{CPXMIP_OPTIMAL_TOL (102)}: \sQuote{integer optimal, tolerance} + as \sQuote{successfully solved} + \item added parameter \code{absMAX} to the constructor methods of classes + \code{sysBiolAlg_lmoma}, \code{sysBiolAlg_mtf} and + \code{sysBiolAlg_room}, which is used as a maximum value for upper variable + and contraint bounds + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.5 2013-11-27}{ + \itemize{ + \item for method \code{optimizeProb} of class \code{modelorg}: if both + arguments \code{gene} and \code{react} are not \code{NULL}, a warning + will be given that \code{react} is ignored + \item added file \file{CITATION} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.4 2013-09-08}{ + \itemize{ + \item added methods \code{singletonMetabolites} and + \code{deadEndMetabolites} to class \code{modelorg} to find dead end + or singleton metabolites in metabolic networks + \item fixed a bug in function \code{findExchReact} which accours when a + model is in irreversible format + \item added methods \code{setRowsNames}, \code{getRowsNames}, + \code{setColsNames} and \code{getColsNames} to classes extending + class \code{optObj} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.3 2013-08-22}{ + \itemize{ + \item added function \code{phpp} for phenotypic phase plane analysis + \item added class \code{optsol_phpp} + \item added argument \code{rng} to function \code{robAna} + \item fixed a bug in function \code{optimizer} which accours when setting + arguments \code{setToZero} to \code{TRUE} and \code{verboseMode} to + a value larger than two + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.2 2013-07-18}{ + \itemize{ + \item updated function \code{promptSysBiolAlg}, including now a very basic + example how to set column, row and problem names in problem objects of + class \code{sysBiolAlg} and \code{optObj} + \item fixed a bug in function \code{addReact} which accours if the model + does not contain a GPR association + \item some adjustments in classes extending class \code{optObj}: + methods \code{loadLPprob}, \code{addRowsToProb} and + \code{changeRowsBnds} works in the same way for each solver (see the + corresponding manual pages for details) + \item added parameters \code{writeProbToFileName} and \code{pname} to + constructor methods of classes extending class \code{sysBiolAlg} + \item fixed a bug in method \code{changeRowBnds} of class + \code{optObj_lpSolveAPI} + \item suggests on \CRANpkg{glpkAPI} (version \eqn{\geq}{>=} 1.2.8) + \item suggests on \CRANpkg{clpAPI} (version \eqn{\geq}{>=} 1.2.4) + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.1 2013-07-02}{ + \itemize{ + \item added parameter \code{scaleDist} to the constructor method of class + \code{sysBiolAlg_moma}, which provides a fine tuning method of the + impact of particular reactions on the objective function of the + MOMA algorithm + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.2.0 2013-05-31}{ + \itemize{ + \item suggests on \CRANpkg{glpkAPI} (version \eqn{\geq}{>=} 1.2.7) + \item suggests on \CRANpkg{clpAPI} (version \eqn{\geq}{>=} 1.2.3) + \item variable and constraint names can now be set in objects of class + \code{sysBiolAlg} and \code{optObj} + \item added a new parameter \code{USE_NAMES} + \item added arguments \code{cnames} and \code{rnames} to method + \code{loadLPprob} for classes extending class \code{optObj} + \item added argument \code{rnames} to method \code{addRowsToProb} for + classes extending class \code{optObj} + \item added arguments \code{cnames} and \code{rnames} to method + \code{initialize} of class \code{sysBiolAlg} + \item added arguments \code{useNames}, \code{cnames} and \code{rnames} to + method \code{initialize} of classes \code{sysBiolAlg_fba}, + \code{sysBiolAlg_fv},\code{sysBiolAlg_lmoma},\code{sysBiolAlg_moma}, + \code{sysBiolAlg_mtf} and \code{sysBiolAlg_room}. + \item in method \code{printMetabolite} of class \code{modelorg}: + metabolite id's beginning with a digit or period are prefixed by the + letter \code{"r"} and reaction id's beginning with a digit or period + are prefixed by the letter \code{"x"} + \item function \code{readTSVmod} checks input files for empty fields + \item added method \code{changeUptake} to class \code{modelorg} to change + media conditions in metabolic networks + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.15 2013-04-18}{ + \itemize{ + \item fixed a bug in functions \code{.generateWT} and \code{doubleGeneDel} + which accours if argument solver was given as variable name and not + as character value directly + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.14 2013-04-15}{ + \itemize{ + \item added argument \code{termOut} to method \code{initialize} of class + \code{sysBiolAlg} enabling or disabling terminal output of the + mathematical programming software + \item function \code{checkSolStat} no longer returns an optimal MILP + solution generated by IBM ILOG CPLEX as non-optimal + \item some refinements for the regular expressions in function + \code{readTSVmod} to identify stoichiometric coefficients and + compartment flags of metabolites + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.13 2013-01-29}{ + \itemize{ + \item added argument \code{linInd} to function \code{doubleReact} + \item return value of function \code{doubleReact} is now \code{FALSE} if + no identical reactions are found, otherwise a list of id's + corresponding to the reaction id's of identical reactions + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.12 2013-01-22}{ + \itemize{ + \item default value for argument \code{wtflux} in method \code{initialize} + of class \code{sysBiolAlg_moma} is \code{NULL} + \item new parameter to the MOMA algorithm (quadratic version): argument + \code{Qmat} in method \code{initialize} of class + \code{sysBiolAlg_moma} gives the quadratic part of the objective + function + \item new parameter to the MOMA algorithm (linear version): argument + \code{obj_coefD} in method \code{initialize} of class + \code{sysBiolAlg_lmoma} contains the non-zero part of the objective + function + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.11 2013-01-18}{ + \itemize{ + \item fixed a bug in function \code{doubleGeneDel} which appears if + argument \code{exLethal} is set to \code{TRUE} + \item removed old file \file{NEWS.Rd} from top level directory + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.10 2012-12-21}{ + \itemize{ + \item fixed a bug in the calculation of default objective values in the + \code{mtf} algorithm + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.9 2012-12-21}{ + \itemize{ + \item method \code{histogram} of class \code{optsol} plots the return value + of \code{mod_obj}, not \code{lp_obj} + \item removed argument \code{MoreArgs} from method \code{optimizeProb} of + class \code{modelorg} + \item slots \code{dels} and \code{fluxdels} of class \code{optsol_fluxdel} + and class \code{optsol_genedel} are matrices of class \code{character} + \item class \code{sysBiolAlg} has new methods \code{applyChanges} and + \code{resetChanges} for altering objects of class \code{sysBiolAlg} + temporarily + \item replaced method \code{optimizeProb} of class \code{sysBiolAlg_room} by + methods \code{applyChanges} and \code{resetChanges} + \item constructor method of class \code{sysBiolAlg} has new arguments + \code{retAlgPar} and \code{algPar} used for saving algorithm specific + parameters in objects extending class \code{sysBiolAlg} + \item added slot \code{maxobj} and method \code{changeMaxObj} to class + \code{sysBiolAlg_mtf} + \item fixed a bug in algorithm \code{mtf}: modifications in the model (like + gene knock-outs) were ignored during the calculation of the optimized + objective value + \item argument algorithm to function \code{optimizer} can now also be + \code{"mtf"} or \code{"fv"} + \item added class \code{netFlux} and constructor function \code{getNetFlux} + to order exchange reaction rates according to their sign + \item function \code{optimizer} returns a list and no longer an object + extending class \code{optsol}. + \item removed method \code{logOptimizationNE} of class \code{sybilLog} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.8 2012-12-03}{ + \itemize{ + \item requires R version 2.14.2 or higher + \item method \code{getFluxDist} of class \code{optsol} get additional + argument \code{opt} to access specific optimization results + \item removed argument \code{needId} from function \code{checkReactId} + \item removed slot \code{has_id} and method \code{hasId} from + class \code{reactId} + \item removed constructor function \code{reactId} for objects of class + \code{reactId}, use function \code{checkReactId} instead + \item added function \code{editEnvir}: the environment editor for metabolic + networks + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.7 2012-11-30}{ + \itemize{ + \item method \code{shrinkMatrix} can get objects of class \code{reactId} + \item removed deprecated functions \code{simpleFBA} and \code{prepProbObj} + \item removed deprecated generics \code{loadProblemData}, + \code{loadProblemDataLM}, \code{loadProblemDataMTF} + and \code{loadMatrix} + \item removed deprecated class \code{optsol_simpleFBA} + \item some updates in the vignette + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.6 2012-11-26}{ + \itemize{ + \item class \code{reactId} is reorganized: it has new slots \code{mod_id}, + \code{mod_key}, \code{react_num} and \code{has_id} and new methods + \code{hasId} and \code{[}, also the implementation of method + \code{show} has changed + \item new class \code{reactId_Exch} extending class \code{react_id} + \item function \code{findExchReact} now returns an object of class + \code{reactId_Exch} when getting an object of class \code{modelorg} + instead of a list + \item class \code{modelorg}, class \code{reactId}, class \code{optsol} and + class \code{optsolSummary} have new slot \code{mod_key} containing a + character string functioning as a unique key to a model object + \item fixed a small bug in method \code{printObjFunc} of class + \code{modelorg} + \item fixed a small bug in function \code{fluxVar} which has occurred when + not all reactions given in a model where analyzed + \item function \code{fluxVar} has new argument \code{exex} in order to + exclude exchange reactions from the analysis + \item class \code{optsol_fluxVar} has a new method \code{blReact} which does + essentially the same as function \code{blockedReact} + \item function \code{blockedReact} is now deprecated + \item class \code{optsol} has a new slot \code{obj_func} containing the + objective function of the used model as a character string + \item method \code{optimizeProb} of class \code{modelorg} returns an object + of class \code{optsol_optimizeProb} as default behaviour (argument + \code{retOptSol} is \code{TRUE}, default) + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.5 2012-10-31}{ + \itemize{ + \item function \code{geneDel} now returns \code{NULL} instead of \code{NA} + if a gene deletion has no effect + \item default value for arguments \code{gene}, \code{react}, \code{lb}, + \code{ub} and \code{obj_coef} in methods \code{optimizeProb} is + \code{NULL} + \item in \code{optimizeProb} all changes to variable bounds must be set + explicitly, there is no default anymore + \item added method \code{shrinkMatrix} to class \code{modelorg} for + retrieving subsets of the stoichiometric matrix + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.4 2012-10-24}{ + \itemize{ + \item changed argument \code{alg} in method \code{initialize} of class + \code{sysBiolAlg} to \code{sbalg} + \item changed argument \code{alg} in function \code{optimizer} + to \code{algorithm} + } +} + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.3 2012-10-22}{ + \itemize{ + \item slot \code{lp_dir} of class \code{optsol} is now of type \code{factor} + \item solver names \code{"glpk"}, \code{"cplex"} and \code{"clp"} are not + used anymore, use \code{"glpkAPI"}, \code{"cplexAPI"} and + \code{"clpAPI"} instead + \item added method \code{readProb} to class \code{optObj} + \item removed slot \code{rhs} from class \code{modelorg}, because this + parameter is algorithm dependent and not model dependent + \item added new class \code{optsolSummary} + \item the function \code{printObjFunc} is now a generic and has a method in + class \code{modelorg} + \item the function \code{checkOptSol} is now a generic and has a method in + class \code{optsol} and class \code{optsolSummary} + \item added methods \code{printMetabolite} and \code{printReaction} to + class \code{modelorg} + \item added method \code{nnzero} to class \code{fluxDistribution} + } +} + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.2 2012-10-10}{ + \itemize{ + \item fixed a bug in backupProb methods + \item fixed a small bug in checkDefaultMethod + \item moved method \code{mod_obj} from class \code{optsol_fluxdel} to the + base class \code{optsol} + \item added deprecated class \code{optsol_simpleFBA} for compatibility + with other packages depending on \pkg{sybil} + } +} + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.1 2012-10-08}{ + \itemize{ + \item fixed file \file{DESCRIPTION} + } +} + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.1.0 2012-10-08}{ + \itemize{ + \item some performance improvements in function \code{fluxVar} + \item new function \code{modelorg2ExPA}, which writes input files for + \href{http://gcrg.ucsd.edu/Downloads/ExtremePathwayAnalysis}{ExPA} + \item some very minor improvements in sybilStack (stack [LIFO] and + queue [FIFO]) + \item solver names \code{glpk}, \code{cplex} and \code{clp} are deprecated, + use \code{glpkAPI}, \code{cplexAPI} and \code{clpAPI} instead + \item classes \code{optObj_glpk}, \code{optObj_cplex} and \code{optObj_clp} + are renamed to \code{optObj_glpkAPI}, \code{optObj_cplexAPI} and + \code{optObj_clpAPI} + \item fixed a small bug in \code{SYBIL_SETTINGS} appearing if parameters + were set several times + \item argument \code{solverParm} can be \code{list} or \code{data.frame} + \item argument \code{fmt} to the generic \code{writeProb} is now \code{ff} + \item added support for mixed interger optimization problems with + \pkg{glpkAPI} and \pkg{cplexAPI} + \item added support for quadratic optimization problems with \pkg{cplexAPI} + \item added methods \code{changeMatrixRow}, \code{loadLPprob} and + \code{loadQobj} to class \code{optObj} + \item \pkg{cplexAPI} must be version 1.2.3 or higher, if used + \item added function \code{addSolver} in order to make additional solver + packages available + \item added argument \code{arrowlength} to function \code{readTSVmod} + \item added arguments \code{probType} and \code{loadPackage} to function + \code{checkDefaultMethod} + \item class \code{optsol_doublefluxdel} and class + \code{optsol_doublegenedel} are not available anymore, class + \code{optsol_fluxdel} and class \code{optsol_genedel} are used instead + \item added new method \code{mod_obj} to class \code{optsol\_fluxdel}, which + returns + \eqn{\mbox{\boldmath$c$\unboldmath}^{\mathrm{T}}\mbox{\boldmath$v$\unboldmath}}{c^T v} + with \eqn{\mbox{\boldmath$c$\unboldmath}}{c} being the vector of + objective coefficients in the model (object of class \code{modelorg}) + and \eqn{\mbox{\boldmath$v$\unboldmath}}{v} being the flux + distribution as a result of the optimization. In contrast, method + \code{lp_obj} always returns the value of the objective function + of the used algorithm after optimization. + \item added functions \code{addAlgorithm}, \code{checkAlgorithm} and + \code{getsybilenv} + \item added a new class \code{sysBiolAlg} including a general constructor + function \code{sysBiolAlg} and subclasses \code{sysBiolAlg_fba}, + \code{sysBiolAlg_fv}, \code{sysBiolAlg_lmoma}, \code{sysBiolAlg_moma}, + \code{sysBiolAlg_mtf} and \code{sysBiolAlg_room}. These classes + contain instances of class \code{optObj}, prepared for specific + algorithms like ROOM or MOMA + \item support for algorithms MOMA and ROOM in class \code{sysBiolAlg} + \item added method \code{optimizeProb} as a replacement for function + \code{simpleFBA}: unused argument \code{checkIds} is removed, new + arguments \code{gene} and \code{MoreArgs} were added. + \item added function \code{promptSysBiolAlg} which generates a skeletal + structure for new classes inhereting from \code{sysBiolAlg} + \item functions \code{prepProbObj} and \code{simpleFBA} are deprecated and + will be removed soon, use \code{sysBiolAlg} and \code{optimizeProb} + instead + \item methods \code{loadMatrix}, \code{loadProblemData}, + \code{loadProblemDataLM} and \code{loadProblemDataMTF} are deprecated + and will be removed soon, use \code{loadLPprob} instead + \item class \code{optsol} makes now use of the package \pkg{lattice} to + plot histograms (use \code{histogram()} instead of \code{hist()}) + \item updated package vignette + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.0.2 2012-04-20}{ + \itemize{ + \item renamed parameter \code{SOLVER_CTRL_PARAM} to \code{SOLVER_CTRL_PARM} + \item renamed argument \code{param} in \code{SYBIL_SETTINGS()} to + \code{parm} + \item file \file{NEWS} is now in \file{inst/NEWS.Rd} + \item added argument \code{absCtrl} to the \code{plot} method in + class \code{optsol_robAna} + \item in \code{readTSVmod}, if a model description file is missing, the + basename of the reaction list is used as model id, not the complete + path to the file if fpath is used, or the reaction list is not in + the working directory + \item removed arguments \code{verboseMode}, \code{loglevel}, \code{logfile} + and \code{logfileEnc} from function \code{readTSVmod}; use function + \code{sink} instead + \item removed arguments \code{loglevel}, \code{logfile} and + \code{logfileEnc} from function \code{optimizer}; use function + \code{sink} instead + \item added method \code{show} to class \code{sybilError} + \item methods \code{logOptimization} and \code{logOptimizationNE} of class + \code{sybilLog} need argument \code{i} giving a consecutive number + \item methods \code{logComment}, \code{logOptimization}, + \code{logOptimizationNE} and \code{logOptimizationTH} of class + \code{sybilLog} now also write to \code{stdout} (by \code{cat}) if + \code{verblevel} is \code{> 2} + \item fixed a bug in \code{mod2irrev()}: slots \code{met_de} and + \code{react_de} of class \code{modelorg} (in the reversible model) + are no longer ignored + \item added function \code{addReact()} to add or change reactions in a + given model + \item added function \code{addExchReact()} to add exchange reactions for + metabolites to a given model + \item minor changes in \code{printObjFunc()} + \item SYBIL_SETTINGS(parm) gives an error if \code{parm} is not a valid + parameter name + \item function \code{findExchReact()} now returns indices of metabolite id's + having an exchange reaction + \item compatible to \CRANpkg{clpAPI} (version \eqn{\geq}{>=} 1.2.0) + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.0.1 2012-03-16}{ + \itemize{ + \item removed \pkg{sybilSBML} from Suggests field and removed undocumented + function \code{readModel()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 1.0.0 2012-03-16}{ + \itemize{ + \item added method \code{dim} to class \code{modelorg} + + \item renamed method \code{setColsBndsObjCoefs} to + \code{changeColsBndsObjCoefs} + + \item updated documentation + + \item depends on \CRANpkg{glpkAPI} (version \eqn{\geq}{>=} 1.2.1) + + \item needs \CRANpkg{cplexAPI} (version \eqn{\geq}{>=} 1.2.0) + + \item switched from \CRANpkg{SparseM} to \CRANpkg{Matrix} + (version \eqn{\geq}{>=} 1.0-4), a consequence is a dependency on R + (version \eqn{\geq}{>=} 2.12.0) + + \item completely new implementation of \code{SYBIL_SETTINGS} + + \item reorganization of files: one class \eqn{\rightarrow}{>=} one file + + \item use Collate field in file \file{DESCRIPTION} + + \item LIFO/FIFO (stack/queue) implementation with new functions \cr + \code{stinit()}, \code{stclear()}, \code{stpush()}, + \code{stpop()}, \cr + \code{stunshift()}, \code{stshift()}, \code{stseek()}, + \code{stfirst()}, \cr + \code{stlist()}, \code{stlength()} and \code{stexists()} + + \item a few compatibility changes in \code{readTSVmod()} for output of + \href{http://bigg.ucsd.edu/}{BiGG database}: added arguments + \code{quoteChar}, \code{commentChar} and \code{oneSubSystem} + + \item added argument \code{minimalSet} to \code{modelorg2tsv()} + + \item added function \code{geneDeletion()} for \eqn{n} gene deletions + + \item fixed a bug in \code{doubleGeneDel()} when \code{allComb = FALSE} + + \item added \code{geneDeletion} to \code{multiDel()} + + \item added argument \code{checkId} to \code{geneDel()} + + \item arguments \code{poCmd} and \code{prCmd} to \code{optimizer} and + \code{simpleFBA} must be of type \code{list} + + \item some improvements in \code{sybilLogClass} + + \item \code{optimizer()} now makes use of class \code{sybilLog} + + \item removed arguments \code{resolve} and \code{resolveParm} from + \code{optimizer()} + + \item removed \pkg{sybil} parameters \code{LP_ALT_METHOD} and \cr + \code{SOLVER_ALT_CTRL_PARAM} from \code{SYBIL_SETTINGS()} + + \item renamed \pkg{sybil} parameter \code{LP_SOLVER to SOLVER} + + \item renamed \pkg{sybil} parameter \code{LP_METHOD to METHOD} + + \item moved methods \code{length} and \code{hist} from class + \code{optsol_fluxdel} to class \code{optsol} + + \item added slot num_of_prob in class checksol + + \item fixed a bug in class \code{optObj} when setting parameters to + \CRANpkg{lpSolveAPI} + + \item added arguments \code{connect} and \code{colconnect} to the + \code{plot} mathod of class \code{optsol_fluxVar} + + \item updated package vignette + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.11 2011-12-12}{ + \itemize{ + \item fixed a bug in \code{readTSVmod()} when reading closed networks + + \item \code{.createReactionString()} now adds the compartment id to the + metabolite id if it is not already there + + \item if the metabolite id's do not contain the compartment abbreviation in + square brackets, the compartment names are used by + \code{modelorg2tsv()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.10 2011-12-09}{ + \itemize{ + \item added arguments \code{exclM} and \code{exclR} to + \code{.singletonMetabolite()} + + \item in \code{readTSVmod()}: upper and lower bounds which are larger + than \code{abs(def_bnd)} are set to \code{abs(def_bnd)} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.9 2011-08-30}{ + \itemize{ + \item added slots \code{met_de} and \code{react_de} to \code{modelorg} + + \item added Boolean arguments \code{remMet}, \code{contrMet}, + \code{singletonMet} and \code{deadEndmet} to \code{readTSVmod()}, the + two Boolean arguments \code{remSingleMet} and \code{constrSingleMet} + are removed, see \code{help("readTSVmod")} for details + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.8 2011-08-22}{ + \itemize{ + \item fixed a bug in constructor of class \code{sybilError} + + \item depends on \CRANpkg{cplexAPI} (version \eqn{\geq}{>=} 1.1.7) + + \item \code{checkOptSol()} is compatible with \CRANpkg{cplexAPI} + (version 1.1.7) in combination with IBM ILOG CPLEX (version 12.3) + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.7 2011-08-15}{ + \itemize{ + \item slots \code{met_single} and \code{react_single} of class + \code{modelorg} are initialized with \code{NA}, not \code{FALSE} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.6 2011-08-15}{ + \itemize{ + \item some minor changes in \code{readTSVmod()} according to + \CRANpkg{codetools} + + \item fixed a bug in class \code{logFileFH} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.5 2011-08-12}{ + \itemize{ + \item added slots \code{met_single} and \code{react_single} to class + \code{modelorg} + + \item new arguments for \code{readTSVmod()}: + \code{mergeMet}, \code{balanceReact}, \code{remUnusedMetReact}, + \code{remSingleMet}, \code{constrSingleMet} and \code{tol} see + \code{help("readTSVmod")} for details + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.4 2011-08-08}{ + \itemize{ + \item method \code{logError} of class \code{sybilLog} returns object of + class \code{sybilError} + + \item fixed a bug in \code{.printNamedList()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.3 2011-08-05}{ + \itemize{ + \item added class \code{sybilLog} + + \item added logging in \code{readTSVmod()}, see \code{help("readTSVmod")} + for details and new arguments + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.2 2011-07-29}{ + \itemize{ + \item added \code{NAMESPACE} + + \item fixed a minor bug in \code{findExchReact()} + \item fixed a bug in method \code{show} for class \code{SYBIL_SETTINGS} + \item fixed a bug in \code{.validModelorg()} + + \item changes in \code{readTSVmod()}: + \itemize{ + \item If a metabolite is used more than once as product or + educt of a particular reaction, it is merged: + \preformatted{a + (2) a} + is converted to + \preformatted{(3) a} + and a warning will be given. + + \item If a metabolite is used first as educt and then as + product of a particular reaction, the reaction is + balanced: + \preformatted{(2) b + a -> b + c} + is converted to + \preformatted{ b + a -> c} + + \item The stoichiometric matrix S is scanned for metabolites, which are + used only once in S. If there are some, a warning will be given. + + \item The stoichiometric matrix S is scanned for reactions, which are + not used in S. If there are some, a warning will be given and the + corresponding reactions will be removed from the model. + + \item Some improvements in parsing the reaction string: if more than one + reaction arrow is found, a warning is given and the reaction will + be removed from the model. + } + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.1 2011-07-12}{ + \itemize{ + \item support for low level interface \CRANpkg{glpkAPI} (version 1.1.2) + \item support for low level interface \CRANpkg{clpAPI} (version 1.1.1) + \item support for low level interface \CRANpkg{cplexAPI} (version 1.1.1) + + \item added new slot in class \code{optObj}: \code{probType}. + The constructor function \code{optObj()} has a new argument + \code{pType}, with \code{lp} as default value (linear programming). + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.5.0 2011-05-20}{ + \itemize{ + \item updated documentation + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.4.1 2011-05-18}{ + \itemize{ + \item slot \code{subSys} in class \code{modelorg} is now of class + \code{matrix}, so one reaction can belong to more than one subsystem, + for example: + \tabular{llll}{ + \tab \code{cytosol} \tab \code{mitochondria} \tab \code{external} \cr + \code{v_1} \tab \code{TRUE} \tab \code{FALSE} \tab \code{FALSE} \cr + \code{v_2} \tab \code{TRUE} \tab \code{TRUE} \tab \code{FALSE} \cr + \code{v_3} \tab \code{FALSE} \tab \code{TRUE} \tab \code{FALSE} \cr + \code{b_1} \tab \code{FALSE} \tab \code{FALSE} \tab \code{TRUE} \cr + \code{b_2} \tab \code{FALSE} \tab \code{FALSE} \tab \code{TRUE} \cr + } + In slot \code{subSys}, only the column names are named according to + the subsystem. The rows do not have names, the first row corresponds + to the first reaction in slot \code{react_id}, the second row to the + second reaction id, and so forth. + + \item added method \code{getRedCost} to class \code{optObj}. + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.4.0 2011-03-01}{ + \itemize{ + \item SBML compatibility is moved to the package \pkg{sybilSBML}, making + \pkg{sybil} independend from rsbml. The new package \pkg{sybilSBML} + requires a working \pkg{rsbml} installation (available from + \href{http://www.bioconductor.org/}{Bioconductor}). + + \item added functions \code{modelorg2tsv()} and \code{readTSVmod()} in order + to handle \file{tsv} files compatible to the + \href{http://bigg.ucsd.edu/}{BiGG database} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.3.6 2010-12-16}{ + \itemize{ + \item fixed a bug in \code{optimizer()} when pre/post-processing + should be performed, but no optimization was done. + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.3.5 2010-12-15}{ + \itemize{ + \item added argument \code{solverParm} in \code{fluxVar()}, argument + \code{\dots} is passed to \code{simpleFBA()} now + + \item cleaning of class \code{optObj}: + \itemize{ + \item new classes extending \code{optObj}: + \code{optObj_glpk}, \code{optObj_clp}, \code{optObj_cplex} + and \code{optObj_lpSolveAPI} + + \item methods \code{setRhsZero} and \code{setColsBndsObjCoefs} are not + usable for initial model creation (this is a feature, not a bug). + Use \code{addRows} and \code{addCols} here. + } + + \item added stack like functions + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.3.4 2010-11-05}{ + \itemize{ + + \item added function \code{multiDel()}: \code{multicore} support for + \code{oneGeneDel()}, \code{doubleGeneDel()}, \code{oneFluxDel()} + and \code{doubleFluxDel()} + + \item fixed a bug in \code{fluxVar()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.3.3 2010-09-28}{ + \itemize{ + \item removed file \file{NAMESPACE} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.3.2 2010-09-22}{ + \itemize{ + \item blockedReact() now works also for irreversible models. + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.3.1 2010-09-14}{ + \itemize{ + \item some improvements in \code{readSBMLmod()} + + \item depends on \pkg{rsbml} version \eqn{\geq}{>=} 2.4.0 + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.3.0 2010-08-20}{ + \itemize{ + \item first public beta release + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.8 2010-08-07}{ + \itemize{ + \item some things were renamed: + \itemize{ + \item class \code{postAnalysis} is now class \code{ppProc} + \item function \code{postProcessing()} is now function + \code{.ppProcessing()} + \item slot \code{postAna} in class \code{optsol_simpleFBA} is now + slot \code{postProc} + \item argument \code{ppCmd} in function \code{simpleFBA()} is now + argument \code{poCmd} + } + + \item added slot \code{preProc} in class \code{optsol_simpleFBA()} + + \item added argument \code{prCmd} in function \code{simpleFBA()}: + same purpose as argument \code{poCmd}, but the commands are + executed immideately before solving the optimization problem. + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.7 2010-08-06}{ + \itemize{ + \item added slot \code{lethal} to class \code{optsol_doublefluxdel} + + \item added method \code{ind2id()} to class \code{optsol_fluxdel}, + \code{optsol_genedel} and \code{optsol_doublegenedel} + + \item some minor improvements in \code{doubleGeneDel()} + + \item added classes \code{sybilError} and \code{postAnalysis} + + \item added function \code{postProcessing()} + + \item added slot \code{postAna} in class \code{optsol_simpleFBA} + + \item added method \code{sensitivityAnalysis} in class \code{optObj} + + \item added argument \code{ppCmd} in \code{simpleFBA()}: + + The argument \code{ppCmd} should be a character vector. If it has a + length \eqn{=} 1, it will be treated as a function name, if it has + length \eqn{>} 1, it will be treated as function name (\code{ppCmd[1]}) + plus arguments (\code{ppCmd[-1]}). Basically, \code{ppCmd} is treated as + a command, executed on the problem object (object of class \code{optObj}), + after the problem has been solved. The first element of \code{ppCmd} will + be used as function name, all other elements as arguments to that + function. The command will be joint with \code{\sQuote{,}} and + \code{\sQuote{()}}: + \preformatted{ +ppCmd[1] "(" ppCmd[-1] ")" + } + and \code{ppCmd[-1]} will be joind with \code{\sQuote{,}}. + + The string \code{\dQuote{LP_PROB}} will be used as a placeholder for the + variable name of the problem object. If \code{\dQuote{LP_PROB}} is used + in \code{ppCmd}, it will be replaced. The result of the execution of + \code{ppCmd} will be stored in an object of class \code{postAnalysis} + in the slot \code{postAna} of class \code{optsol_simpleFBA}. + + Some examples: + \itemize{ + \item perform sensitivity analysis with GLPK: + \preformatted{ +simpleFBA(<model>, ppCmd = "sensitivityAnalysis") + } + Here, \code{ppCmd} has length \eqn{=} 1, + \code{\dQuote{sensitivityAnalysis}} will be treated as a function name + and executed on the problem object. + + \item access reduced costs in conjunction with IBM ILOG CPLEX: + \preformatted{ +simpleFBA(<model>, solver = "cplex", + ppCmd = c("getDjCPLEX", + "LP_PROB@oobj$env", "LP_PROB@oobj$lp", + "0", "react_num(<model>)-1")) + } + In that example, \code{ppCmd} has length \eqn{>} 1, the first element + is the function name, the others are the arguments. For IBM ILOG CPLEX, + slot \code{oobj} of objects of class \code{optObj} is a list, + containing a pointer to the cplex environment \code{env} and a second + pointer to the problem object \code{lp}. The third and fourth argument + are \code{begin} and \code{end} for the function \code{getDjCPLEX()}. + Remember: in IBM ILOG CPLEX, the first element has index 0! + } + + Instances of class \code{postAnalysis} have two slots: + \describe{ + \item{cmd}{a single character string containing the executed command} + \item{pa}{the result of the post processing. If an error occured, + \code{pa} contains the error message and is of class + \code{sybilError}} + } + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.6 2010-06-30}{ + \itemize{ + \item fixed a bug in \code{optimizer()}: + flux distribution was not saved when argument \code{rebuildModel} is + set to \code{TRUE} and the used algorithm is + \code{\dQuote{linearMOMA}} + + \item option \code{resolve = TRUE} in \code{optimizer()} is working again. + + \item setting of parameters to lp solver with \code{SYBIL_SETTINGS} is + working again. + + \item improved function \code{blockedReact()}. + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.5 2010-06-22}{ + \itemize{ + \item fixed a bug in \code{changeObjCoefs()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.4 2010-05-19}{ + \itemize{ + \item fixed a bug in \code{onlyChangeGPR()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.3 2010-05-17}{ + \itemize{ + \item fixed a bug in \code{changeGPR()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.2 2010-05-12}{ + \itemize{ + \item added function \code{changeGPR()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.1 2010-04-28}{ + \itemize{ + \item fixed a small bug in \code{readSBMLmod()} + + \item fixed a bug in \code{optimizer()} in conjunction with IBM ILOG CPLEX + and parameter \code{copyModel = TRUE} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.2.0 2010-04-26}{ + \itemize{ + \item fixed a bug in \code{optObj_Class}: + \code{loadProblemDataML()} produced an error when + \code{solver = "lpSolveAPI"} and \code{alg = "linearMOMA_COBRA"} + + \item method \code{loadProblemDataMTF} in \code{optObj_Class} failed when + IBM ILOG CPLEX is used + + \item fixed a bug in \code{mod2irrev()}: slot \code{rev2irrev} contained + wrong entries. + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.9 2010-02-28}{ + \itemize{ + \item argument \code{resolve} in \code{optimizer()} is not working in this + version! + + \item completely rewritten function \code{simpleFBA()}; new (changed) + arguments: + \describe{ + \item{react}{(default: \code{NA}) fluxes with changed lower and upper + bounds} + \item{lb}{(default: \code{NA}) new lower bounds for fluxes in argument + \code{react}} + \item{ub}{(default: \code{NA}) new upper bounds for fluxes in argument + \code{react}} + \item{minTotalFlux}{(default: \code{FALSE}) Boolean, if set to + \code{TRUE}, after FBA, the sum of all flux rates will be minimized} + \item{minDist}{(default: \code{FALSE}) Boolean, if set to \code{TRUE}, + a minimized distance to a wild type flux distribution will be + generated} + \item{wtFluxes}{(default: \code{NA}) a single flux value (if + argument \code{minTotalFlux} is set to \code{TRUE}) for on optimized + objective function, or a flux vector (if argument \code{minDist} is + set to \code{TRUE}) for an optimized flux distribution. + If \code{wtFluxes} is \code{NA}, FBA will be performed. If arguments + \code{minDist} or \code{minTotalFlux} are TRUE and \code{wtFluxes} is + \code{NA}, the needed values will be calculated by FBA.} + } + + \item added method \code{backupProb()} in class \code{optObj}: + \describe{ + \item{glpk/cplex}{the functions + \code{copyProbGLPK()}/\code{cloneProbCPLEX()} will be used here, which + return a pointer to the new problem object} + \item{clp/lpSolveAPI}{the functions + \code{saveModelCLP()}/\code{write.lp()} will be used here, which write + the specified problem to file. That file will be deleted after + building the new problem out of those. That may cause a lot IO.} + } + \item new arguments to \code{optimizer()} [can be passed to + \code{optimizer()} by argument \code{\dots} in e.g. + \code{oneGeneDel()} or \code{doubleGeneDel()}]: + \describe{ + \item{rebuildModel}{(default: \code{FALSE}) Boolean. If set to + \code{TRUE}, the problem object will be recreated for every + optimization. That will increase the running time significantly!} + \item{copyModel}{(default: \code{FALSE}) Boolean. If set to \code{TRUE}, + the problem object will be taken from a backup copy. That backup copy + will be created prior to the very first optimization from the modelorg + object.} + } + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.8 2010-01-17}{ + \itemize{ + \item argument \code{alg} in \code{optimizer()} works now for all solvers + \item added the used algorithm in the logfile + \item added dependency on \CRANpkg{SparseM} + \item added options \code{exLethal} and \code{tol} to \code{doubleGeneDel()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.7 2009-12-07}{ + \itemize{ + \item argument \code{alg} in \code{optimizer()}: can be \code{\dQuote{FBA}} + (default), \code{\dQuote{linearMOMA}} or + \code{\dQuote{linearMOMA_COBRA}}; works only with GLPK + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.6 2009-12-03}{ + \itemize{ + \item added method \code{length} for objects of class \code{optsol_fluxdel} + + \item added method \code{\dQuote{[}} for objects of class + \code{optsol_fluxdel} + + \item added argument \code{alg} in \code{optimizer()}: can be + \code{\dQuote{FBA}} (default) or \code{\dQuote{linearMOMA}}; + works only with glpk + + \item added slot \code{algorithm} and methods \code{algorithm} and + \code{algorithm<-} for objects of class \code{optsol_fluxdel} + containing the name of the used algorithm. + + \item added slot \code{TOLERANCE} in \code{SYBIL_SETTINGS} + + \item added slot \code{MAXIMUM} in \code{SYBIL_SETTINGS} + + \item added slot \code{ALGORITHM} in \code{SYBIL_SETTINGS} + + \item added slot \code{OPT_DIRECTION} in \code{SYBIL_SETTINGS} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.5 2009-11-16}{ + \itemize{ + \item fixed a bug in \code{optObj_Class}, method \code{changeColsBnds} when + using ILOG CPLEX as solver + + \item in \code{optObj_Class} the methods \code{getColsLowBnds} and + \code{getColsUppBnds} now use \code{getLowBndsIdsCPLEX} and + \code{getUppBndsIdsCPLEX} respectively when using ILOG CPLEX as solver + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.4 2009-10-01}{ + \itemize{ + \item fixed a bug in \code{nonZeroElements()}: + empty rows and columns are now handled correctly when argument + \code{maorder} is set to \code{\dQuote{column}} or \code{\dQuote{row}} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.3 2009-07-23}{ + \itemize{ + \item added support for low level interface \pkg{sybilCPLEX} (version 0.0.2) + + \item minor changes applied to \file{uglyHack.R} in order to support + libsbml version 3.4.1 + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.2 2009-07-21}{ + \itemize{ + \item added setting \code{LP_ALT_METHOD}, used for resolve in + \code{optimizer()} and \code{refineSol()} + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.1 2009-07-14}{ + \itemize{ + \item added class \code{SYBIL_SETTINGS} which contains default settings, + currently for the default lp solver and corresponding method. + The class contains the relevant set/get methods to fit the + content to ones needs. + + \item added method \code{addRowsCols} to class \code{optObj} + + \item added support for low level interface \CRANpkg{lpSolveAPI} + (version 5.5.0.14) + + \item added support for low level interface \pkg{sybilCLP} (version 0.0.1) + + \item argument \code{resolve} in \code{oneFluxDel()}, \code{oneGeneDel()}, + \code{doubleFluxDel()} and \code{doubleGeneDel()} + \itemize{ + \item default: \code{NA} + \item if \code{resolve} is enabled, value should be a valid method + depending on the desired solver (e.g. \code{\dQuote{exact}} in + case of \code{solver = "glpk"}) + } + \item renamed optObj-method \code{setColsBnds} to \code{changeColsBnds} + + \item renamed optObj-method \code{setRowsBnds} to \code{changeRowsBnds} + + \item renamed optObj-method \code{setObjCoefs} to \code{changeObjCoefs} + + \item argument \code{resolve} in \code{optimizer()} and \code{refineSol()}: + \itemize{ + \item no longer Boolean + \item default: \code{NA} + \item if non optimal solutions should be resolved: set to method + resolve should use + } + + \item argument \code{logfile} in \code{optimizer()} and \code{refineSol()}: + \itemize{ + \item no longer Boolean + \item default: \code{NA} + \item if a logfile should printed, \code{logfile} will be the filename + } + + \item argument \code{scaling} in \code{optimizer()} and \code{refineSol()}: + \itemize{ + \item no longer Boolean + \item default: \code{NA} + \item if the model should be scaled, scaling will be the scaling method + } + + \item added \code{solver} and \code{method} in \file{logfile} + + \item added argument \code{checkOptSolObj} to function \code{optimizer()}: + print a warning, in cases where solution status \eqn{\neq}{!=} 0 + in objects of class optsol (default: \code{FALSE}) + + \item added slots \code{chlb} and \code{chub} to class \code{optsol}: + \itemize{ + \item containing lower and upper bounds of changed flux rates. + \item replace method: \code{ch?b<-} + \item get method: \code{ch?b} + } + } +} + + +% ---------------------------------------------------------------------------- % +\section{Changes in version 0.1.0 2009-07-09 (initial release)}{ + \itemize{ + \item support for low level interface \pkg{sybilGLPK} (version 0.1.0) + } +} diff --git a/inst/doc/sybil.R b/inst/doc/sybil.R new file mode 100644 index 0000000..2b46b6f --- /dev/null +++ b/inst/doc/sybil.R @@ -0,0 +1,565 @@ +### R code from vignette source 'sybil.Rnw' +### Encoding: UTF-8 + +################################################### +### code chunk number 1: sybil.Rnw:433-434 +################################################### +library(sybil) + + +################################################### +### code chunk number 2: sybil.Rnw:443-444 +################################################### +library(help = "sybil") + + +################################################### +### code chunk number 3: sybil.Rnw:448-449 +################################################### +help(doubleGeneDel) + + +################################################### +### code chunk number 4: sybil.Rnw:453-454 +################################################### +help.search("flux variability analysis") + + +################################################### +### code chunk number 5: sybil.Rnw:457-458 (eval = FALSE) +################################################### +## vignette("sybil") + + +################################################### +### code chunk number 6: sybil.Rnw:479-480 +################################################### +mp <- system.file(package = "sybil", "extdata") + + +################################################### +### code chunk number 7: sybil.Rnw:483-484 +################################################### +mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"") + + +################################################### +### code chunk number 8: sybil.Rnw:504-505 (eval = FALSE) +################################################### +## modelorg2tsv(mod, prefix = "Ec_core") + + +################################################### +### code chunk number 9: sybil.Rnw:510-511 +################################################### +data(Ec_core) + + +################################################### +### code chunk number 10: sybil.Rnw:524-525 +################################################### +ex <- findExchReact(Ec_core) + + +################################################### +### code chunk number 11: sybil.Rnw:528-530 +################################################### +upt <- uptReact(ex) +ex[upt] + + +################################################### +### code chunk number 12: sybil.Rnw:536-538 +################################################### +mod <- changeBounds(Ec_core, ex[c("EX_glc(e)", "EX_lac_D(e)")], lb = c(0, -10)) +findExchReact(mod) + + +################################################### +### code chunk number 13: sybil.Rnw:557-558 +################################################### +optL <- optimizeProb(Ec_core, algorithm = "fba", retOptSol = FALSE) + + +################################################### +### code chunk number 14: sybil.Rnw:563-564 +################################################### +opt <- optimizeProb(Ec_core, algorithm = "fba", retOptSol = TRUE) + + +################################################### +### code chunk number 15: sybil.Rnw:570-571 +################################################### +lp_obj(opt) + + +################################################### +### code chunk number 16: sybil.Rnw:575-576 +################################################### +checkOptSol(opt) + + +################################################### +### code chunk number 17: sybil.Rnw:590-591 +################################################### +fba <- optimizeProb(Ec_core, algorithm = "fba") + + +################################################### +### code chunk number 18: sybil.Rnw:594-595 +################################################### +mod_obj(fba) + + +################################################### +### code chunk number 19: sybil.Rnw:599-600 +################################################### +mtf <- optimizeProb(Ec_core, algorithm = "mtf", wtobj = mod_obj(fba)) + + +################################################### +### code chunk number 20: sybil.Rnw:603-604 +################################################### +lp_obj(mtf) + + +################################################### +### code chunk number 21: sybil.Rnw:609-611 +################################################### +nvar(fluxdist(fba)) +nvar(fluxdist(mtf)) + + +################################################### +### code chunk number 22: sybil.Rnw:616-618 +################################################### +help("sysBiolAlg_fba-class") +help("sysBiolAlg_mtf-class") + + +################################################### +### code chunk number 23: sybil.Rnw:621-623 +################################################### +?fba +?mtf + + +################################################### +### code chunk number 24: sybil.Rnw:628-630 +################################################### +fl <- getFluxDist(mtf) +length(fl) + + +################################################### +### code chunk number 25: sybil.Rnw:635-637 +################################################### +fd <- getFluxDist(mtf, ex) +getNetFlux(fd) + + +################################################### +### code chunk number 26: sybil.Rnw:642-643 +################################################### +mod_obj(mtf) + + +################################################### +### code chunk number 27: sybil.Rnw:654-655 +################################################### +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0) + + +################################################### +### code chunk number 28: sybil.Rnw:676-678 +################################################### +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0, + algorithm = "lmoma", wtflux = getFluxDist(mtf)) + + +################################################### +### code chunk number 29: sybil.Rnw:694-697 (eval = FALSE) +################################################### +## ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0, +## algorithm = "room", wtflux = getFluxDist(mtf), +## solverParm = list(PRESOLVE = GLP_ON)) + + +################################################### +### code chunk number 30: sybil.Rnw:729-730 +################################################### +opt <- oneGeneDel(Ec_core) + + +################################################### +### code chunk number 31: sybil.Rnw:744-745 +################################################### +checkOptSol(opt) + + +################################################### +### code chunk number 32: sybil.Rnw:749-750 +################################################### +plot(opt, nint = 20) + + +################################################### +### code chunk number 33: sybil.Rnw:756-759 +################################################### +opt <- oneGeneDel(Ec_core, algorithm = "lmoma", wtflux = getFluxDist(mtf)) +checkOptSol(opt) +plot(opt, nint = 20) + + +################################################### +### code chunk number 34: sybil.Rnw:765-766 +################################################### +opt <- geneDeletion(Ec_core) + + +################################################### +### code chunk number 35: sybil.Rnw:769-771 (eval = FALSE) +################################################### +## opt2 <- geneDeletion(Ec_core, combinations = 2) +## opt3 <- geneDeletion(Ec_core, combinations = 3) + + +################################################### +### code chunk number 36: sybil.Rnw:787-789 +################################################### +opt <- fluxVar(Ec_core, percentage = 80, verboseMode = 0) +plot(opt) + + +################################################### +### code chunk number 37: sybil.Rnw:817-819 +################################################### +opt <- robAna(Ec_core, ctrlreact = "EX_o2(e)", verboseMode = 0) +plot(opt) + + +################################################### +### code chunk number 38: sybil.Rnw:836-843 +################################################### +Ec_core_wo_glc <- changeUptake(Ec_core, off = "glc_D[e]") +opt <- phpp(Ec_core_wo_glc, + ctrlreact = c("EX_succ(e)", "EX_o2(e)"), + redCosts = TRUE, + numP = 25, + verboseMode = 0) +plot(opt) + + +################################################### +### code chunk number 39: phpp_rf +################################################### +plot(opt, "EX_succ(e)") + + +################################################### +### code chunk number 40: phpp_rs +################################################### +plot(opt, "EX_o2(e)") + + +################################################### +### code chunk number 41: sybil.Rnw:877-878 +################################################### +opt <- oneGeneDel(Ec_core, algorithm = "fba", fld = "all") + + +################################################### +### code chunk number 42: sybil.Rnw:881-882 +################################################### +sum <- summaryOptsol(opt, Ec_core) + + +################################################### +### code chunk number 43: sybil.Rnw:896-897 +################################################### +printExchange(sum, j = c(1:50), dense = TRUE) + + +################################################### +### code chunk number 44: sybil.Rnw:912-916 +################################################### +ref <- optimizeProb(Ec_core) +opt <- oneGeneDel(Ec_core) +let <- lethal(opt, wt = mod_obj(ref)) +nletid <- c(1:length(allGenes(Ec_core)))[! let] + + +################################################### +### code chunk number 45: sybil.Rnw:925-926 (eval = FALSE) +################################################### +## gmat <- combn(nletid, 3) + + +################################################### +### code chunk number 46: sybil.Rnw:931-932 (eval = FALSE) +################################################### +## opt <- multiDel(Ec_core, nProc = 4, todo = "geneDeletion", del1 = gmat) + + +################################################### +### code chunk number 47: sybil.Rnw:943-944 (eval = FALSE) +################################################### +## mapply(checkOptSol, opt) + + +################################################### +### code chunk number 48: sybil.Rnw:955-957 +################################################### +opt <- optimizeProb(Ec_core, poCmd = list("getRedCosts")) +postProc(opt) + + +################################################### +### code chunk number 49: sybil.Rnw:993-994 (eval = FALSE) +################################################### +## optimizeProb(Ec_core, method = "exact") + + +################################################### +### code chunk number 50: sybil.Rnw:997-998 (eval = FALSE) +################################################### +## optimizeProb(Ec_core, solver = "cplexAPI", method = "dualopt") + + +################################################### +### code chunk number 51: sybil.Rnw:1021-1024 (eval = FALSE) +################################################### +## opt <- oneGeneDel(Ec_core, +## solverParm = list(TM_LIM = 1000, +## PRESOLVE = GLP_ON)) + + +################################################### +### code chunk number 52: sybil.Rnw:1037-1041 (eval = FALSE) +################################################### +## opt <- optimizeProb(Ec_core, +## solverParm = list(CPX_PARAM_SCRIND = CPX_ON, +## CPX_PARAM_EPRHS = 1E-09), +## solver = "cplexAPI") + + +################################################### +### code chunk number 53: sybil.Rnw:1060-1064 (eval = FALSE) +################################################### +## opt <- optimizeProb(Ec_core, +## solverParm = list(verbose = "full", +## timeout = 10), +## solver = "lpSolveAPI") + + +################################################### +### code chunk number 54: sybil.Rnw:1078-1079 +################################################### +help(SYBIL_SETTINGS) + + +################################################### +### code chunk number 55: sybil.Rnw:1101-1102 (eval = FALSE) +################################################### +## SYBIL_SETTINGS("parameter name", value) + + +################################################### +### code chunk number 56: sybil.Rnw:1107-1108 (eval = FALSE) +################################################### +## SYBIL_SETTINGS("parameter name") + + +################################################### +### code chunk number 57: sybil.Rnw:1113-1114 (eval = FALSE) +################################################### +## SYBIL_SETTINGS() + + +################################################### +### code chunk number 58: sybil.Rnw:1129-1130 +################################################### +SYBIL_SETTINGS("SOLVER", "cplexAPI", loadPackage = FALSE) + + +################################################### +### code chunk number 59: sybil.Rnw:1136-1137 +################################################### +SYBIL_SETTINGS("METHOD") + + +################################################### +### code chunk number 60: sybil.Rnw:1140-1141 +################################################### +SYBIL_SETTINGS("SOLVER", "glpkAPI") + + +################################################### +### code chunk number 61: sybil.Rnw:1144-1145 +################################################### +SYBIL_SETTINGS("METHOD") + + +################################################### +### code chunk number 62: sybil.Rnw:1180-1182 +################################################### +data(Ec_core) +Ec_core + + +################################################### +### code chunk number 63: sybil.Rnw:1186-1187 +################################################### +help("modelorg") + + +################################################### +### code chunk number 64: sybil.Rnw:1194-1195 +################################################### +react_num(Ec_core) + + +################################################### +### code chunk number 65: sybil.Rnw:1198-1199 +################################################### +id <- react_id(Ec_core) + + +################################################### +### code chunk number 66: sybil.Rnw:1202-1203 +################################################### +react_id(Ec_core)[13] <- "biomass" + + +################################################### +### code chunk number 67: sybil.Rnw:1207-1209 +################################################### +cg <- gray(0:8/8) +image(S(Ec_core), col.regions = c(cg, rev(cg))) + + +################################################### +### code chunk number 68: sybil.Rnw:1222-1223 (eval = FALSE) +################################################### +## mod <- readTSVmod(reactList = "reactionList.txt") + + +################################################### +### code chunk number 69: sybil.Rnw:1247-1248 +################################################### +help("optsol") + + +################################################### +### code chunk number 70: sybil.Rnw:1252-1254 +################################################### +os <- optimizeProb(Ec_core) +is(os) + + +################################################### +### code chunk number 71: sybil.Rnw:1257-1258 +################################################### +lp_obj(os) + + +################################################### +### code chunk number 72: sybil.Rnw:1261-1262 +################################################### +getFluxDist(os) + + +################################################### +### code chunk number 73: sybil.Rnw:1307-1308 +################################################### +lp <- optObj(solver = "glpkAPI", method = "exact") + + +################################################### +### code chunk number 74: sybil.Rnw:1332-1333 +################################################### +lp <- initProb(lp) + + +################################################### +### code chunk number 75: sybil.Rnw:1337-1342 +################################################### +cm <- Matrix(c(0.5, 2, 1, 1), nrow = 2) +loadLPprob(lp, nCols = 2, nRows = 2, mat = cm, + lb = c(0, 0), ub = rep(1000, 2), obj = c(1, 1), + rlb = c(0, 0), rub = c(4.5, 9), rtype = c("U", "U"), + lpdir = "max") + + +################################################### +### code chunk number 76: sybil.Rnw:1347-1348 +################################################### +lp + + +################################################### +### code chunk number 77: sybil.Rnw:1351-1352 +################################################### +status <- solveLp(lp) + + +################################################### +### code chunk number 78: sybil.Rnw:1355-1356 +################################################### +getMeanReturn(code = status, solver = solver(lp)) + + +################################################### +### code chunk number 79: sybil.Rnw:1359-1361 +################################################### +status <- getSolStat(lp) +getMeanStatus(code = status, solver = solver(lp)) + + +################################################### +### code chunk number 80: sybil.Rnw:1365-1367 +################################################### +getObjVal(lp) +getFluxDist(lp) + + +################################################### +### code chunk number 81: sybil.Rnw:1370-1371 +################################################### +getRedCosts(lp) + + +################################################### +### code chunk number 82: sybil.Rnw:1374-1376 +################################################### +delProb(lp) +lp + + +################################################### +### code chunk number 83: sybil.Rnw:1407-1409 +################################################### +ec <- sysBiolAlg(Ec_core, algorithm = "fba") +is(ec) + + +################################################### +### code chunk number 84: sybil.Rnw:1414-1415 +################################################### +opt <- optimizeProb(ec) + + +################################################### +### code chunk number 85: sybil.Rnw:1422-1425 +################################################### +ecr <- sysBiolAlg(Ec_core, algorithm = "room", wtflux = opt$fluxes) +is(ecr) +ecr + + +################################################### +### code chunk number 86: sybil.Rnw:1474-1475 (eval = FALSE) +################################################### +## promptSysBiolAlg(algorithm = "foo") + + diff --git a/inst/doc/sybil.Rnw b/inst/doc/sybil.Rnw new file mode 100644 index 0000000..a054974 --- /dev/null +++ b/inst/doc/sybil.Rnw @@ -0,0 +1,1494 @@ +\documentclass[a4paper,headings=small,captions=tableheading]{scrartcl} +\usepackage[english]{babel} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage{textcomp,lmodern} +\typearea[current]{last} +\usepackage{fixltx2e,mparhack,mathdots} + + +\usepackage{xspace} +\usepackage{paralist} +\usepackage{footmisc} +\usepackage{booktabs} +\usepackage{natbib} +\usepackage{hyperref} + +\usepackage{microtype} + +\newcommand{\Comp}[1]{\texttt{#1}} + +\addtolength{\skip\footins}{0.5\baselineskip} +\usepackage{fnpos} + + +\hypersetup{ + pdftitle = {sybil -- Efficient Constrained Based Modelling in R}, + pdfauthor = {Gabriel Gelius-Dietrich}, + pdfsubject = {constrained based modelling}, + pdfkeywords = {Optimization, FBA, MOMA, ROOM}, + pdfborder = {0 0 0}, + pdfhighlight = {/N} +} + + +% glyphs in pdf figures +\pdfinclusioncopyfonts=1 + +\newcommand{\pkg}[1]{\emph{#1}} +\newcommand{\pkgname}{\pkg{sybil}\xspace} +\newcommand{\prgname}[1]{\textsc{#1}} + +%\newcommand{\cplex}{IBM\textregistered{} % +% ILOG\textregistered{} CPLEX\textregistered{}% +%} +\newcommand{\cplex}{IBM ILOG CPLEX} + +\title{sybil -- Efficient Constrained Based Modelling in R} +%\VignetteIndexEntry{sybil -- Efficient Constrained Based Modelling in R} +%\VignettePackage{sybil} +\author{Gabriel Gelius-Dietrich} + + +% ---------------------------------------------------------------------------- % +% entire document +% ---------------------------------------------------------------------------- % + +\begin{document} + + +\maketitle + +\tableofcontents + +% ---------------------------------------------------------------------------- % + +\section{Introduction} + +The R-package \pkgname{} is a Systems Biology Library for R, implementing +algorithms for constraint based analysis of metabolic networks. +Among other functions, \pkgname currently provides efficient methods for +flux-balance analysis (FBA), minimization of metabolic adjustment (MOMA), +regulatory on/off minimization (ROOM), flux variability Analysis and robustness +Analysis. +The package \pkgname{} makes use of the sparse matrix implementation in the +R-package \pkg{Matrix}. + + +% ---------------------------------------------------------------------------- % + +\section{Installation} + +The package \pkgname{} itself depends on an existing installation of the +package \pkg{Matrix}. In order to run optimizations, at least one of the +following additional R-packages and the corresponding libraries are required: +\pkg{glpkAPI}, \pkg{cplexAPI}, \pkg{clpAPI} or \pkg{lpSolveAPI}. +These packages are available from +CRAN\footnote{\url{http://cran.r-project.org/}\label{cranfoot}}. +Additionally, \pkg{sybilGUROBI}---supporting the Gurobi +optimizer\footnote{\url{http://www.gurobi.com}}---is available on request. + + +% ---------------------------------------------------------------------------- % + +\section{Input files} +\label{inputformats} + +Input files for \pkgname are text files containing a description of the +metabolic model to analyze. These descriptions are basically lists of +reactions. +Two fundamentally different types of text files are supported: +\begin{inparaenum}[i)] +\item in tabular form (section~\ref{tabmod}), or +\item in SBML format (section~\ref{sbmlmod}). +\end{inparaenum} + + +% ---------------------------------------------------------------------------- % + +\subsection{Tabular form} \label{tabmod} + +Models in tabular form can be read using the function \Comp{readTSVmod()} and +written using the function \Comp{modelorg2tsv()}. +Each metabolic model description consists of three tables: +\begin{enumerate} +\item A model description, containing a model name, the compartments of the + model and so on (section~\ref{moddesc}). +\item A list of all metabolites (section~\ref{metlist}). +\item A list of all reactions (section~\ref{reactlist}). +\end{enumerate} +A model must contain at least a list of all reactions. All other tables are +optional. The tables contain columns storing the required data. Some of these +columns are optional, but if a certain table exists, there must be a minimal set +of columns. The column names (the first line in each file) are used as keywords +and cannot be changed. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Field and entry delimiter} \label{delim} + +There are two important variables in connection with text based tables: The +fields (columns) of the tables are separated by the value stored in the variable +\Comp{fielddelim}. If a single entry of a field contains a list of entries, +they are separated by the value of the variable \Comp{entrydelim}. +The default values are given table~\ref{delimtab}. +\begin{table} +\centering +\caption{Field and entry delimiters and their default values.} +\label{delimtab} +\begin{tabular}{cc} +\toprule +variable & default value \\ +\midrule +\Comp{fielddelim} & \Comp{\textbackslash t} \\ +\Comp{entrydelim} & \Comp{,\textvisiblespace} \\ +\bottomrule +\end{tabular} +\end{table} +The default behavior is, that the columns of each table are separated by a +single \Comp{tab} character. If a column entry holds more than one entry, they +are separated by a comma followed by a single +whitespace \Comp{\textvisiblespace} (not a tab!). + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Model description} \label{moddesc} +Every column in this table can have at most one entry, meaning each entry will +be a single character string. If a model description file is used, there should +be at least the two columns \Comp{name} and \Comp{id}. If they are +missing---or if no model description file is used---they will be set to the file +name of the reaction list, which must be there (any file name extension and the +string \Comp{\_react} at the end of the file name, will be removed). The model +description file contains the following fields: +\begin{description} + +\item[name] +A single character string giving the model name. If this field is empty, the +filename of the reaction list is used. + +\item[id] +A single character string giving the model id. If this field is empty, the +filename of the reaction list is used. + +\item[description] +A single character string giving a model description (optional). + +\item[compartment] +A single character string containing the compartment names. The names must be +separated by the value of \Comp{fielddelim} (optional, see section~\ref{delim}). + +\item[abbreviation] +A single character string containing the compartment abbreviations. The +abbreviations must be in square brackets and separated by the value of +\Comp{fielddelim} as mentioned above (optional). + +\item[Nmetabolites] +A single integer value giving the number of metabolites in the model (optional). + +\item[Nreactions] +A single integer value giving the number of reactions in the model (optional). + +\item[Ngenes] +A single integer value giving the number of unique, independent genes in the +model (optional). + +\item[Nnnz] +A single integer value giving the number of non-zero elements in the +stoichiometric matrix of the model (optional). + +\end{description} +The file \Comp{Ec\_core\_desc.tsv} (in \Comp{extdata/}) contains an exemplarily +table for the core energy metabolism of \emph{E.~coli} +\citep{Palsson:2006fk,Orth:2010fk}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Metabolite list} \label{metlist} + +This table is used in order to match metabolite id's given in the list of +reactions to long metabolite names. This table is optional, but if it is used, +the columns \Comp{abbreviation} and \Comp{name} should not be empty. +\begin{description} + +\item[abbreviation] +A list of single character strings containing the metabolite abbreviations. + +\item[name] +A list of single character strings containing the metabolite names. + +\item[compartment] +A list of character strings containing the metabolite compartment names. Each +entry can contain more than one compartment name, separated by \Comp{fielddelim} +(optional, currently unused). + +\end{description} +The file \Comp{Ec\_core\_met.tsv} (in \Comp{extdata/}) contains an exemplarily +table for the core energy metabolism of \emph{E.~coli} +\citep{Palsson:2006fk,Orth:2010fk}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Reaction list} \label{reactlist} + +This table contains the reaction equations used in the metabolic network. +\begin{description} + +\item[abbreviation] +A list of single character strings containing the reaction abbreviations +(optional, if empty, a warning will be produced). Entries in the field +abbreviation are used as reaction id's, so they must be unique. If they are +missing, they will be set to $v_i,\ i \in \{1, \dots, n\}\ \forall i$ with +$n$ being the total number of reactions. + +\item[name] +A list of single character strings containing the reaction names (optional, if +empty, the reaction id's (abbreviations) are used as reaction names. + +\item[equation] +A list of single character strings containing the reaction equation. See +section~\ref{writeEQ} for a description of reaction equation strings. + +\item[reversible] +A list of single character strings indicating if a particular reaction is +reversible or not. If the entry is set to \Comp{Reversible} or \Comp{TRUE}, the +reaction is considered as reversible, otherwise not. If this column is not used, +the arrow symbol of the reaction string is used (optional, see +section~\ref{writeEQ}). + +\item[compartment] +A list of character strings containing the compartment names in which the +current reaction takes place. Each entry can contain more than one name, +separated by \Comp{fielddelim} (optional, currently unused). + +\item[lowbnd] +A list of numeric values containing the lower bounds of the reaction rates. +If not set, zero is used for an irreversible reaction and the value of +\Comp{def\_bnd * -1} for a reversible reaction. See documentation of the +function \Comp{readTSVmod} for the argument \Comp{def\_bnd} (optional). + +\item[uppbnd] +A list of numeric values containing the upper bounds of the reaction rates. +If not set, the value of \Comp{def\_bnd} is used. See documentation of the +function \Comp{readTSVmod} for the argument \Comp{def\_bnd} (optional). + +\item[obj\_coef] +A list of numeric values containing objective values for each reaction +(optional, if missing, zero is used). + +\item[rule] +A list of single character strings containing the gene to reaction associations +(optional). + +\item[subsystem] +A list of character strings containing the reaction subsystems. Each reaction +can belong to more than one subsystem. The entries are separated by +\Comp{fielddelim} (optional). + +\end{description} +The file \Comp{Ec\_core\_react.tsv} (in \Comp{extdata/}) contains an exemplarily +table for the core energy metabolism of \emph{E.~coli} +\citep{Palsson:2006fk,Orth:2010fk}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{How to write a reaction equation string} \label{writeEQ} + +\begin{figure}[t] +\centering +\includegraphics{net-crop} +\caption{Simple example network. A) showing a closed network, B) an open + network. Capital letters are used as metabolite id's, lower case + letters are used as compartment id's: b: boundary metabolite, + c:~cytosol and e: external metabolite. Internal reactions are named + $v_{1:7}$, transport reactions $b_{1:3}$. Reactions $v_3$ and $v_4$ are + reversible, all others are irreversible. + Metabolites A\textsubscript{b}, C\textsubscript{b} and + E\textsubscript{b} are boundary metabolites and will be removed in + order to obtain an open network.} +\label{netex} +\end{figure} + +Any reaction string can be written without space. They are not required +but showed here, in order to make the string more human readable. + +\paragraph{Compartment Flag} Each reaction string may start with a compartment +flag in square brackets followed by a colon. The compartment flag here gives the +location of all metabolites appearing in the reaction. +\begin{verbatim} +[c] : +\end{verbatim} +The compartment flag can consist of more than one letter and---if used---must be +an element of the field \Comp{abbreviation} in the model description. The letter +\Comp{b} is reserved for boundary metabolites (argument \Comp{extMetFlag} in +function \Comp{readTSVmod()}), which can be transported inside the system (those +metabolites are only used in closed systems and will be removed during file +parsing). + +If the reaction string does not start with a compartment flag, the flag may be +appended (without whitespace) to each metabolite id (e.\,g. for transport +reactions): +\begin{verbatim} +h2o[e] <==> h2o[c] +\end{verbatim} +If no compartment flag is found, it is set to \Comp{[unknown]}. + +\paragraph{Reaction Arrow} +All reactions must be written in the direction educt to product, so that all +metabolites left of the reaction arrow are considered as educts, all metabolites +on the right of the reaction arrow are products. + +The reaction arrow itself consists of one or more \Comp{=} or \Comp{-} symbols. +The last symbol must be a \Comp{>}. If a reaction arrow starts with \Comp{<}, it +is taken as reversible, if the field \Comp{reversible} in the reaction list is +empty. If the field \Comp{reversible} is set to \Comp{TRUE} or +\Comp{Reversible}, the reactions will be treated as a reversible reaction, +independent of the reaction arrow. Each reaction must contain exactly one +reaction arrow. + +\paragraph{Stoichiometric Coefficients} +Stoichiometric coefficients must be in round brackets in front of the +corresponding metabolite: +\begin{verbatim} +(2) h[c] + (0.5) o2[c] + q8h2[c] --> h2o[c] + (2) h[e] + q8[c] +\end{verbatim} +Setting the stoichiometric coefficient in brackets makes it possible for the +metabolite id to start with a number. + +\paragraph{Metabolite Id's} +The abbreviation of a metabolite name (a metabolite id) must be unique for the model and +must not contain \Comp{+}, \Comp{(} or \Comp{)} characters. + +\paragraph{Examples} + +A minimal reaction list without compartment flags for figure~\ref{netex}B +(open network): +\begin{verbatim} +equation +A --> B +B <==> D +D <==> E +B --> C + --> A +C --> +E --> +\end{verbatim} +The same as above including compartment flags and external metabolites and all +transport reactions for figure~\ref{netex}A (closed network). The reactions +which take place in only one compartment (do not include a transport of +metabolites across membranes) have their compartment flag at the beginning +of the line (\Comp{[c]} in this example). For transport reactions all +metabolites have their own compartment flag, e.\,g. in line 5 metabolite +\Comp{A} is transported from compartment \Comp{[e]} (external) to compartment +\Comp{[c]} (cytosol): +\begin{verbatim} +equation +[c]: A --> B +[c]: B <==> D +[c]: D <==> E +[c]: B --> C +A[e] --> A[c] +C[c] --> C[e] +E[c] --> E[e] +A[b] --> A[e] +C[e] --> C[b] +E[e] --> E[b] +\end{verbatim} +The same as above including reaction id's for figure~\ref{netex} (fields are +separated by tabulators): +\begin{verbatim} +abbreviation equation +v2 [c]: A --> B +v3 [c]: B <==> D +v4 [c]: D <==> E +v6 [c]: B --> C +v1 A[e] --> A[c] +v7 C[c] --> C[e] +v5 E[c] --> E[e] +b1 A[b] --> A[e] +b3 C[e] --> C[b] +b2 E[e] --> E[b] +\end{verbatim} + +% ---------------------------------------------------------------------------- % + +\subsection{SBML} \label{sbmlmod} + +In order to read model files written in systems biology markup language (SBML), +the package \pkg{sybilSBML} is required, which is available from +CRAN\footnote{\url{http://CRAN.R-project.org/package=sybilSBML}\label{sybilhome}}. + + +% ---------------------------------------------------------------------------- % + +\section{Usage} + +In the following sections, it is assumed, that package \pkg{glpkAPI} is +installed additionally to \pkgname, thus GLPK is used as optimization software. +Load \pkgname{} in a running R session: +<<>>= +library(sybil) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Documentation} + +Get a list of all functions provided with \pkgname: +<<>>= +library(help = "sybil") +@ +Get details of the usage of a particular function in \pkgname +(e.\,g. \Comp{doubleGeneDel()}): +<<>>= +help(doubleGeneDel) +@ +Search through help files for a specific topic +(e.\,g. ``flux variability analysis''): +<<>>= +help.search("flux variability analysis") +@ +Open this vignette: +<<eval=FALSE>>= +vignette("sybil") +@ +% Demo?? + + +% ---------------------------------------------------------------------------- % + +\subsection{Reading a model in tabular form} + +The package \pkgname can read metabolic network models written in tabular form +as described in section~\ref{tabmod}. A reconstruction of the central metabolism +of \emph{E. coli} \citep{Orth:2010fk,Palsson:2006fk} is included as an example +dataset. The example dataset consists of three files: +\begin{enumerate} +\item \Comp{Ec\_core\_desc.tsv} containing the model description, +\item \Comp{Ec\_core\_met.tsv} containing the metabolite list and +\item \Comp{Ec\_core\_react.tsv} containing the reaction list. +\end{enumerate} +These files are located in the directory \Comp{extdata/} in the package +\pkgname{}. The exact location of the files can be retrieved with the +\Comp{system.file()} command: +<<>>= +mp <- system.file(package = "sybil", "extdata") +@ +Now the model files can be read in by using the command \Comp{readTSVmod()}: +<<print=true>>= +mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"") +@ +If the fields in the input files for function \Comp{readTSVmod()} are quoted, +argument \Comp{quoteChar} must be used. The value of \Comp{quoteChar} is passed +to the argument \Comp{quote} of the R~function \Comp{read.table()}. Argument +\Comp{fpath} gets the path to the directory containing the model files. Argument +\Comp{prefix} can be used, if the file names of the model files end like the +file names used in the above example. All have the same base name +\Comp{"Ec\_core"} which is used for argument \Comp{prefix}. Function +\Comp{readTSVmod()} now assumes, that the model files are named as follows: +\begin{itemize} +\item the model description file (if exists): \Comp{<prefix>\_desc}\,, +\item the list of metabolites (if exists): \Comp{<prefix>\_met} and +\item the list of reactions (must be there): \Comp{<prefix>\_react}\,. +\end{itemize} +The file name suffix depends on the field delimiter. If the fields are +tab-delimited, the default is \Comp{.tsv}\,. Function \Comp{readTSVmod()} +returns an object of class \Comp{modelorg}. +Models (instances of class \Comp{modelorg}, see section~\ref{classmod}) can be +converted to files in tabular form with the command \Comp{modelorg2tsv}: +<<eval=FALSE>>= +modelorg2tsv(mod, prefix = "Ec_core") +@ +This will generate the three files shown in the list above (see also +section~\ref{tabmod}). +Load the example dataset included in \pkgname. +<<>>= +data(Ec_core) +@ +The example model is a `ready to use' model, it contains a biomass objective +function and an uptake of glucose \citep{Orth:2010fk,Palsson:2006fk}. It is the +same model as used in the text files before. + + +% ---------------------------------------------------------------------------- % + +\subsection{Media conditions} \label{envir} + +The current set of exchange reactions in the model can be accessed with the +function \Comp{findExchReact()}. +<<print=true>>= +ex <- findExchReact(Ec_core) +@ +The subset of uptake reactions can be retrieved by method \Comp{uptReact}. +<<print=true>>= +upt <- uptReact(ex) +ex[upt] +@ +Function \Comp{findExchReact()} returns an object of class \Comp{reactId\_Exch} +(extending class \Comp{reactId}) which can be used to alter reaction bounds +with function \Comp{changeBounds()}. Make lactate the main carbon source instead +of glucose: +<<>>= +mod <- changeBounds(Ec_core, ex[c("EX_glc(e)", "EX_lac_D(e)")], lb = c(0, -10)) +findExchReact(mod) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Flux-balance analysis} \label{fba} + +Perform flux-balance analysis (FBA) by using method \Comp{optimizeProb} of class +\Comp{modelorg}. +Method \Comp{optimizeProb} performs flux-balance analysis +\citep{Edwards:2002kx,Orth:2010vn}. It returns a list containing the return +value of the optimization process (\Comp{"ok"}), the solution status +(\Comp{"stat"}), the value of the objective function after optimization +(\Comp{"obj"}), the resulting flux distribution---the phenotype of the metabolic +network---(\Comp{"fluxes"}) and results of pre- and post processing commands, if +given (\Comp{"preP"} and \Comp{"postP"}). Also, a vector of integers will be +returned (\Comp{"fldind"}). The flux value \Comp{fluxes[fldind[i]]} is the flux +value of reaction \Comp{i} in the model (see section~\ref{mtf}). +<<print=true>>= +optL <- optimizeProb(Ec_core, algorithm = "fba", retOptSol = FALSE) +@ +Perform FBA, return an object of class \Comp{optsol\_optimizeProb} +(extends class \Comp{optsol}, see section~\ref{classopt}, this is the default +behavior). +<<print=true>>= +opt <- optimizeProb(Ec_core, algorithm = "fba", retOptSol = TRUE) +@ +The variable \Comp{opt} contains an object of class \Comp{optsol\_optimizeProb}, +a data structure storing all results of the optimization and providing methods +to access the data (see section~\ref{classopt}). +Retrieve the value of the objective function after optimization. +<<>>= +lp_obj(opt) +@ +Translate the return and status codes of the optimization software into human +readable strings. +<<>>= +checkOptSol(opt) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Minimize total flux} \label{mtf} + +Usually, an FBA solution is not unique. There can be many equivalent flux +distributions supporting the same objective value. A method to decide for one +out of these solutions is to compute the flux distribution minimizing the total +absolute flux (MTF) but still supporting the objective value of the FBA +solution. At first, an objective value, for example calculated via FBA, is +required: +<<>>= +fba <- optimizeProb(Ec_core, algorithm = "fba") +@ +Get the optimized value of the objective function: +<<>>= +mod_obj(fba) +@ +Now, the objective value of the solution in \Comp{fba} is used to compute a +flux distribution with a minimized total absolute flux: +<<>>= +mtf <- optimizeProb(Ec_core, algorithm = "mtf", wtobj = mod_obj(fba)) +@ +The value of the objective function for the MTF algorithm now is +<<>>= +lp_obj(mtf) +@ +which is the minimized sum of all absolute flux values. The number of variables +of the MTF problem is three times the number of the variables of the FBA +solution +<<>>= +nvar(fluxdist(fba)) +nvar(fluxdist(mtf)) +@ +which is due to the different formulations of the two optimization problems. +Consult the documentation of class \Comp{sysBiolAlg} (section~\ref{classsba}) +for more detailed information on the algorithms. +<<>>= +help("sysBiolAlg_fba-class") +help("sysBiolAlg_mtf-class") +@ +There are also shortcuts available: +<<>>= +?fba +?mtf +@ +Method \Comp{getFluxDist} can be used to get the flux distribution of the MTF +solution; the values of the variables corresponding to the reactions in the +metabolic network. +<<>>= +fl <- getFluxDist(mtf) +length(fl) +@ +The flux distribution of the exchange reactions can be retrieved in a similar +way (variable \Comp{ex} contains the exchange reactions of the \emph{E. coli} +model, see section~\ref{envir}). +<<print=true>>= +fd <- getFluxDist(mtf, ex) +getNetFlux(fd) +@ +Function \Comp{getNetFlux()} the absolute flux values of the exchange reactions +grouped by flux direction. The value of the objective function given in the +model (here: biomass production) can be accessed by method \Comp{mod\_obj}: +<<>>= +mod_obj(mtf) +@ +which is of course the same value as for the FBA algorithm. + + +% ---------------------------------------------------------------------------- % + +\subsection{Genetic perturbations} \label{komut} + +To compute the metabolic phenotypes of \emph{in silico} knock-out mutants, +argument \Comp{gene} of method \Comp{optimizeProb} can be used. +<<print=true>>= +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0) +@ +Argument \Comp{gene} gets a character vector of gene locus tags present in the +used model. The flux boundaries of reactions affected by the genes given in +argument \Comp{gene} will be set to the values of arguments \Comp{lb} and +\Comp{ub}. If both arguments are set to zero, no flux through the affected +reactions is allowed. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Minimization of metabolic adjustment (MOMA)} \label{MOMA} + +The default algorithm used by method \Comp{optimizeProb} is +FBA \citep{Edwards:2002kx,Orth:2010vn}, implying the assumption, that the +phenotype of the mutant metabolic network is independent of the wild-type +phenotype. An alternative is the MOMA algorithm described in +\citet{Segre:2002fk} minimizing the hamiltonian distance of the wild-type +phenotype and the mutant phenotype (argument \Comp{algorithm = "lmoma"} computes +a linearized version of the MOMA algorithm; \Comp{algorithm = "moma"} runs the +quadratic formulation). +<<print=true>>= +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0, + algorithm = "lmoma", wtflux = getFluxDist(mtf)) +@ +The variable \Comp{ko} contains the solution of the linearized version of the +MOMA algorithm. A wild-type flux distribution can be set via argument +\Comp{wtflux}, here, the flux distribution computed through the MTF algorithm +was used. If argument \Comp{wtflux} is not set, a flux distribution based on +FBA will be used. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Regulatory on/off minimization (ROOM)} \label{ROOM} + +Another alternative is the ROOM algorithm (regulatory on/off minimization) +described in \citet{Shlomi:2005fk}. Set argument \Comp{algorithm} to \Comp{room} +in order to run ROOM. +<<eval=FALSE>>= +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0, + algorithm = "room", wtflux = getFluxDist(mtf), + solverParm = list(PRESOLVE = GLP_ON)) +@ +ROOM is a mixed integer programming problem which requires for GLPK to switch +on the pre-solver. See section \ref{optparm} for more information on setting +parameters to the mathematical programming software. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Multiple knock-outs} \label{multknockout} + +Method \Comp{optimizeProb} can be used to study the metabolic phenotype of one +knock-out mutant. The purpose of functions \Comp{oneGeneDel()}, +\Comp{doubleGeneDel()} and \Comp{geneDeletion()} is the simulation of multiple +\emph{in silico} knock-outs (see table~\ref{tabmultko}). +\begin{table} +\centering +\caption{Functions used to simulate multiple + \emph{in silico} knock-out mutants.} +\label{tabmultko} +\begin{tabular}{ll} +\toprule +function & purpose \\ +\midrule +\Comp{oneGeneDel()} & single gene knock-outs \\ +\Comp{doubleGeneDel()} & pairwise gene knock-outs \\ +\Comp{geneDeletion()} & simultaneous deletion of $n$ genes \\ +\bottomrule +\end{tabular} +\end{table} +Function \Comp{oneGeneDel()} simulates all possible single gene knock-out +mutants in a metabolic model (default algorithm is FBA). +<<print=true>>= +opt <- oneGeneDel(Ec_core) +@ +The function \Comp{oneGeneDel} gets an argument \Comp{geneList}, a character +vector containing the gene id's to knock out. If \Comp{geneList} is missing, +all genes are taken into account. The example model contains 137 independent +genes, so 137 optimizations will be performed. + +The result stored in the variable \Comp{opt} is an object of class +\Comp{optsol\_geneDel}, extending class \Comp{optsol\_optimizeProb} +(see section~\ref{fba}). Method \Comp{checkOptSol} gives an overview about the +results and status of the optimizations. Additionally, class \Comp{optsol} +contains a method \Comp{plot}, plotting a histogram of the values of the +objective function given in the model after optimization +(section~\ref{classopt}). +<<>>= +checkOptSol(opt) +@ +Plot the histogram: +\begin{center} +<<fig=TRUE>>= +plot(opt, nint = 20) +@ +\end{center} +Argument \Comp{algorithm} can be used here to use MOMA to compute the mutant +flux distributions. Additionally, a wild-type solution can be provided. +\begin{center} +<<fig=TRUE>>= +opt <- oneGeneDel(Ec_core, algorithm = "lmoma", wtflux = getFluxDist(mtf)) +checkOptSol(opt) +plot(opt, nint = 20) +@ +\end{center} +In order to perform all possible double-knock-out mutants, or $n$-knock-out +mutants, the function \Comp{geneDeletion} can be used. Perform single gene +deletions (in principle the same as before with \Comp{oneGeneDel}). +<<>>= +opt <- geneDeletion(Ec_core) +@ +Compute all double-knock-out mutants and all triple-knock-out mutants +<<eval=FALSE>>= +opt2 <- geneDeletion(Ec_core, combinations = 2) +opt3 <- geneDeletion(Ec_core, combinations = 3) +@ +which will result in 9317 optimizations for double-knock-outs and +419\,221~Optimizations for triple-knock-outs using the metabolic model of the +core energy metabolism of \emph{E.\,coli}. This model contains 137 genes. + + +% ---------------------------------------------------------------------------- % + +\subsection{Flux variability analysis} + +The function \Comp{fluxVar} performs a flux variability analysis with a given +model \citep{Mahadevan:2003fk}. The minimum and maximum flux values for each +reaction in the model are calculated, which still support a certain percentage +of a given optimal functional state $Z_{\mathrm{opt}}$. +\begin{center} +<<fig=TRUE>>= +opt <- fluxVar(Ec_core, percentage = 80, verboseMode = 0) +plot(opt) +@ +\end{center} +% The example below is based upon the metabolic model of the human red blood cell +% by \citet{Palsson:2006fk} and \citet{Price:2004fk}. +% <<>>= +% rbc <- readTSVmod(reactList = "rbc.tsv", fpath = mp, quoteChar = "\"") +% @ +% Perform flux variability analysis. +% \begin{center} +% <<fig=TRUE>>= +% opt <- fluxVar(Ec_core, percentage = 1, verboseMode = 0) +% plot(opt) +% @ +% \end{center} + + +% ---------------------------------------------------------------------------- % + +\subsection{Robustness analysis} + +The function \Comp{robAna} performs a robustness analysis with a given model. +The flux of a control reaction will be varied stepwise between the maximum and +minimum value the flux of the control reaction can reach \citep{Palsson:2006fk}. +The example below shows a flux variability analysis based upon the metabolic +model of the core energy metabolism of \emph{E.\,coli} using the exchange flux +of oxygen as control reaction. +\begin{center} +<<fig=TRUE>>= +opt <- robAna(Ec_core, ctrlreact = "EX_o2(e)", verboseMode = 0) +plot(opt) +@ +\end{center} + + +% ---------------------------------------------------------------------------- % + +\subsection{Phenotypic phase plane analysis} + +The function \Comp{phpp} performs a phenotypic phase plane +analysis \citep{Edwards:2001fk,Edwards:2002uq} with a given model. The flux of +two control reactions will be varied stepwise between a given maximum and +minimum value. The example below shows a phenotypic phase plane analysis based +upon the metabolic model of the core energy metabolism of \emph{E.\,coli} using +the exchange fluxes of oxygen and succinate as control reactions. First, the +uptake of glucose is switched off. +\begin{center} +<<fig=TRUE>>= +Ec_core_wo_glc <- changeUptake(Ec_core, off = "glc_D[e]") +opt <- phpp(Ec_core_wo_glc, + ctrlreact = c("EX_succ(e)", "EX_o2(e)"), + redCosts = TRUE, + numP = 25, + verboseMode = 0) +plot(opt) +@ +\end{center} +Plot reduced costs of succinate import flux and oxygen import flux. + +<<fig=TRUE, label=phpp_rf, include=FALSE>>= +plot(opt, "EX_succ(e)") +@ +<<fig=TRUE,label=phpp_rs, include=FALSE>>= +plot(opt, "EX_o2(e)") +@ + +\begin{minipage}{0.45\textwidth} +\begin{center} +\includegraphics[width=\textwidth]{sybil-phpp_rf} +\end{center} +\end{minipage} +\hfill +\begin{minipage}{0.45\textwidth} +\begin{center} +\includegraphics[width=\textwidth]{sybil-phpp_rs} +\end{center} +\end{minipage} + + +% ---------------------------------------------------------------------------- % + +\subsection{Summarizing simulation results} + +Each simulation generates an object of class \Comp{optsol} containing all +the results of the optimizations. In order to get a quick overview of the +results, the function \Comp{summaryOptsol()} can be used. At first, let's +compute all single gene knock-outs of the metabolic model of the core energy +metabolism of \emph{E.\,coli}: +<<>>= +opt <- oneGeneDel(Ec_core, algorithm = "fba", fld = "all") +@ +Generate a summary: +<<print=true>>= +sum <- summaryOptsol(opt, Ec_core) +@ +The function \Comp{summaryOptsol()} returns an object of class +\Comp{optsolSummary} and needs the object of class \Comp{optsol} (results of +simulations) and the corresponding object of class \Comp{modelorg} (the entire +metabolic network). The generated object of class \Comp{summaryOptsol} contains +some information about the flux distribution, substrates, products and limiting +reactions. + +The method \Comp{printExchange()} prints a subset of the flux distribution for +the exchange reactions in the model. Each column represents the environment of +one optimization. The symbol \Comp{"-"} indicates that the corresponding +metabolite is imported (is a substrate); the symbol \Comp{"+"} indicates, that +the corresponding metabolite excreted (is a product). +<<>>= +printExchange(sum, j = c(1:50), dense = TRUE) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Parallel computing} + +The package \pkgname{} provides basic support for the R-package \pkg{parallel} +in function \Comp{multidel()}. The following example shows the computation of +all possible triple-knock-out mutants using the model of the core energy +metabolism of \emph{E.\,coli}. The set of genes included in the analysis will +be reduced to genes, which are not lethal. A gene $i$ is considered as +``lethal'', if in a single-gene-knockout the deletion of gene $i$ results in a +maximum growth ratio of zero. +<<>>= +ref <- optimizeProb(Ec_core) +opt <- oneGeneDel(Ec_core) +let <- lethal(opt, wt = mod_obj(ref)) +nletid <- c(1:length(allGenes(Ec_core)))[! let] +@ + +\noindent +At first, a wild-type maximum growth rate is computed and stored in the variable +\Comp{ref}. Then, all single-gene knock-outs are computed. The variable +\Comp{let} contains pointers to the gene id's of genes, who's deletion is +lethal. The variable \Comp{nletid} contains pointers to the gene id's of all +genes, except for the lethal ones. +<<eval=FALSE>>= +gmat <- combn(nletid, 3) +@ +The variable \Comp{gmat} now contains a matrix with three rows, each column is +one combination of three values in \Comp{nletid}; one set of genes to knock-out +in one step. +<<eval=FALSE>>= +opt <- multiDel(Ec_core, nProc = 4, todo = "geneDeletion", del1 = gmat) +@ +The function \Comp{multiDel} performs a \Comp{geneDeletion} with the model +\Comp{Ec\_core} on four CPU's (argument \Comp{nProc}) on a shared memory +machine. Argument \Comp{del1} is the matrix containing the sets of genes to +delete. This matrix will be split up in smaller sub-matrices all having about the +same number of columns and three rows. The sub-matrices are passed to +\Comp{geneDeletion} and are processed on separate cores in parallel. The +resulting variable \Comp{opt} now contains a list of four objects of class +\Comp{optsol\_genedel}. Use \Comp{mapply} to access the values stored in the +\Comp{optsol} objects. +<<eval=FALSE>>= +mapply(checkOptSol, opt) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Interacting with the optimization process} + +Method \Comp{optimizeProb} provides a basic mechanism to run commands before +and or after solving the optimization problem. In order to retrieve the reduced +costs after the optimization, use argument \Comp{poCmd}. +<<>>= +opt <- optimizeProb(Ec_core, poCmd = list("getRedCosts")) +postProc(opt) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Optimization software} + +To solve optimization problems, +GLPK\footnote{Andrew Makhorin: GNU Linear Programming Kit, version~4.42 or +higher + +\url{http://www.gnu.org/software/glpk/glpk.html}}, +\cplex\footnote{\cplex{} version 12.2 (or higher) from the IBM Academic +Ini\-tia\-tive + +\url{https://www.ibm.com/developerworks/university/academicinitiative/}}, +COIN-OR Clp\footnote{COIN-OR linear programming version 1.12.0 or higher +\url{https://projects.coin-or.org/Clp}} +or lp\_solve\footnote{lp\_solve via R-package \pkg{lpSolveAPI} version 5.5.2.0-5 +or higher + +\url{http://lpsolve.sourceforge.net/5.5/index.htm}} +can be used (package \pkg{sybilGUROBI} providing support for Gurobi +optimization\footnote{\url{http://www.gurobi.com}} is available on request). +All functions performing optimizations, get the arguments +\Comp{solver} and \Comp{method}. The first setting the desired solver and the +latter setting the desired optimization algorithm. +Possible values for the argument \Comp{solver} are: +\begin{itemize} +\item \Comp{"glpkAPI"}, which is the default, +\item \Comp{"cplexAPI"}, +\item \Comp{"clpAPI"} or +\item \Comp{"lpSolveAPI"}. +\end{itemize} +Perform FBA, using GLPK as solver and ``simplex exact'' as algorithm. +<<eval=FALSE>>= +optimizeProb(Ec_core, method = "exact") +@ +Perform FBA, using \cplex{} as solver and ``dualopt'' as algorithm. +<<eval=FALSE>>= +optimizeProb(Ec_core, solver = "cplexAPI", method = "dualopt") +@ +The R-packages \pkg{glpkAPI}, \pkg{clpAPI} and \pkg{cplexAPI} +provide access to the C-API of the corresponding optimization software. +They are also available from CRAN\footref{cranfoot}. + + +% ---------------------------------------------------------------------------- % + +\subsection{Setting parameters to the optimization software} +\label{optparm} + +All functions performing optimizations can handle the argument +\Comp{solverParm} getting a list or data frame containing parameters used by the +optimization software. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{GLPK} + +For available parameters used by GLPK, see the GLPK and the \pkg{glpkAPI} +documentation. +<<eval=FALSE>>= +opt <- oneGeneDel(Ec_core, + solverParm = list(TM_LIM = 1000, + PRESOLVE = GLP_ON)) +@ +The above command performs a single gene deletion experiment +(see section~\ref{multknockout}), sets the time limit for each optimization to +one second and does pre-solving in each optimization. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{\cplex} + +For available parameters used by \cplex{}, see the \cplex{} and the +\pkg{cplexAPI} documentation. +<<eval=FALSE>>= +opt <- optimizeProb(Ec_core, + solverParm = list(CPX_PARAM_SCRIND = CPX_ON, + CPX_PARAM_EPRHS = 1E-09), + solver = "cplexAPI") +@ +The above command performs FBA, sets the messages to screen switch to ``on'' +and sets the feasibility tolerance to $10^{-9}$. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{COIN-OR Clp} + +At the time of writing, it is not possible to set any parameters when using +COIN-OR Clp. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{lpSolveAPI} + +See the \pkg{lpSolveAPI} documentation for parameters for \Comp{lp\_solve}. +<<eval=FALSE>>= +opt <- optimizeProb(Ec_core, + solverParm = list(verbose = "full", + timeout = 10), + solver = "lpSolveAPI") +@ +The above command performs FBA, sets the verbose mode to ``full'' +and sets the timeout to ten seconds. + + + +% ---------------------------------------------------------------------------- % + +\subsection{Setting parameters in sybil} + +Parameters to \pkgname{} can be set using the function \Comp{SYBIL\_SETTINGS}. +Parameter names and their default values are shown in table~\ref{sybilparm}, +all possible values are described in the \Comp{SYBIL\_SETTINGS} documentation. +<<>>= +help(SYBIL_SETTINGS) +@ +\begin{table} +\centering +\caption{Available parameters in \pkgname{} and their default values.} +\label{sybilparm} +\begin{tabular}{ll} +\toprule +parameter name & default value \\ +\midrule +\Comp{SOLVER} & \Comp{glpkAPI} \\ +\Comp{METHOD} & \Comp{simplex} \\ +\Comp{SOLVER\_CTRL\_PARM} & \Comp{as.data.frame(NA)} \\ +\Comp{ALGORITHM} & \Comp{fba} \\ +\Comp{TOLERANCE} & \Comp{1E-6} \\ +\Comp{MAXIMUM} & \Comp{1000} \\ +\Comp{OPT\_DIRECTION} & \Comp{max} \\ +\Comp{PATH\_TO\_MODEL} & \Comp{.} \\ +\bottomrule +\end{tabular} +\end{table} +The function \Comp{SYBIL\_SETTINGS} gets at most two arguments: +<<eval=FALSE>>= +SYBIL_SETTINGS("parameter name", value) +@ +the first one giving the name of the parameter to set (as character string) and +the second one giving the desired value. If \Comp{SYBIL\_SETTINGS} is called +with only one argument +<<eval=FALSE>>= +SYBIL_SETTINGS("parameter name") +@ +the current setting of \Comp{"parameter name"} will be returned. All parameters +and their values can be achieved by calling \Comp{SYBIL\_SETTINGS} without +any argument. +<<eval=FALSE>>= +SYBIL_SETTINGS() +@ + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Solver software specific} + +The two parameters \Comp{SOLVER} and \Comp{METHOD} depend on each other, e.\,g. +the method called \Comp{simplex} is only available when \Comp{glpkAPI} is used +as solver software. Each solver has its own specific set of methods available in +order to solve optimization problems. If one changes the parameter \Comp{SOLVER} +to, let's say \Comp{cplexAPI}, the parameter \Comp{METHOD} will automatically +be adjusted to the default method used by \Comp{cplexAPI}. +Set parameter solver to \cplex{} for every optimization: +<<>>= +SYBIL_SETTINGS("SOLVER", "cplexAPI", loadPackage = FALSE) +@ +Now, \cplex{} is used as default solver e.\,g. in \Comp{optimizeProb} or +\Comp{oneGeneDel}, and parameter \Comp{METHOD} has changed to the default method +in \pkg{cplexAPI}. Setting argument \Comp{loadPackage} to \Comp{FALSE} prevents +loading the API package. Get the current setting for \Comp{Method}: +<<>>= +SYBIL_SETTINGS("METHOD") +@ +Reset the solver to \Comp{glpkAPI}: +<<>>= +SYBIL_SETTINGS("SOLVER", "glpkAPI") +@ +Now, the default method again is \Comp{simplex} +<<>>= +SYBIL_SETTINGS("METHOD") +@ +It is not possible to set a wrong method for a given solver. If the desired +method is not available, always the default method is used. +Parameters to the solver software (parameter \Comp{SOLVER\_CTRL\_PARM}) must be +set as \Comp{list} or \Comp{data.frame} as described in section~\ref{optparm}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Analysis specific} + +The parameter \Comp{ALGORITHM} controls the way gene deletion analysis will be +performed. The default setting \Comp{"fba"} will use flux-balance analysis (FBA) +as described in \citet{Edwards:2002kx} and \citet{Orth:2010vn}. Setting this +parameter to \Comp{"lmoma"}, results in a linearized version of the MOMA +algorithm described in \citet{Segre:2002fk} ("moma" will run the original +version). The linearized version of MOMA, like it is implemented in the COBRA +Toolbox \citep{Becker:2007uq,Schellenberger:2011fk}, can be used in functions +like \Comp{oneGeneDel()} via the Boolean argument \Comp{COBRAflag}. +Setting the parameter \Comp{"ALGORITHM"} to \Comp{"room"} will run a regulatory +on/off minimization as described in \citet{Shlomi:2005fk}. +See also section~\ref{komut} for details on gene deletion analysis. + + +% ---------------------------------------------------------------------------- % + +\section{Central data structures} + +\subsection{Class modelorg} \label{classmod} + +The class \Comp{modelorg} is the core datastructure to represent a metabolic +network, in particular the stoichiometric matrix $S$. +An example (E.\,coli core flux by \citep{Palsson:2006fk}) is shipped within +\pkgname and can be loaded this way: +<<>>= +data(Ec_core) +Ec_core +@ +The generic method \Comp{show} displays a short summary of the parameters of the +metabolic network. See +<<>>= +help("modelorg") +@ +for the list of available methods. All slots of an object of class +\Comp{modelorg} are accessible via setter and getter methods having the same +name as the slot. For example, slot \Comp{react\_num} contains the number of +reactions in the model (equals the number of columns in $S$). Access the +number of reactions in the \emph{E.\,coli} model. +<<>>= +react_num(Ec_core) +@ +Get all reaction is's: +<<>>= +id <- react_id(Ec_core) +@ +Change a reaction id: +<<>>= +react_id(Ec_core)[13] <- "biomass" +@ +Plot an image of the stoichiometric matrix $S$: +\begin{center} +<<fig=TRUE>>= +cg <- gray(0:8/8) +image(S(Ec_core), col.regions = c(cg, rev(cg))) +@ +\end{center} +Matrices in objects of class \Comp{modelorg} are stored in formats provided by +the \pkg{Matrix}-package\footnote{http://CRAN.R-project.org/package=Matrix}. + +Objects of class \Comp{modelorg} can easily be created. Sources are common file +formats like tab delimited files from the +BiGG database \citep{Schellenberger:2010fk}\footnote{\url{http://bigg.ucsd.edu}} +or SBML files (with package \pkg{sybilSBML}\footref{sybilhome}). +See section~\ref{inputformats} on +page \pageref{inputformats} about supported file formats and their description. +Read a reaction list generated from the BiGG database: +<<eval=FALSE>>= +mod <- readTSVmod(reactList = "reactionList.txt") +@ +Here, \Comp{"reactionList.txt"} is an from BiGG database exported reaction +list. Usually, these files do neither contain an objective function, nor upper +and lower bounds on the reaction rates. They need to be added to the returned +object of class \Comp{modelorg} using the methods \Comp{obj\_coef<-}, +\Comp{lowbnd<-} and \Comp{uppbnd<-}, or by adding the columns \Comp{obj\_coef}, +\Comp{lowbnd} and \Comp{uppbnd} to the input file. + + +% ---------------------------------------------------------------------------- % + +\subsection{Class optsol} \label{classopt} + +\begin{figure} + \centering + \includegraphics{optsol-class} + \caption{UML representation of class \Comp{optsol}.} + \label{optsol-class} +\end{figure} + +The derived classes of class \Comp{optsol} (optimization solution) are used to +store information and results from various optimization problems and their +biological relation. See +<<>>= +help("optsol") +@ +for the list of available methods to access the +data (figure~\ref{optsol-class}). A simple demonstration would be: +<<print=true>>= +os <- optimizeProb(Ec_core) +is(os) +@ +Retrieve objective value. +<<>>= +lp_obj(os) +@ +Retrieve flux distribution. +<<>>= +getFluxDist(os) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Class optObj} \label{classoo} + +\begin{figure} + \centering + \includegraphics{optObj-class} + \caption{UML representation of class \Comp{optObj}.} + \label{optObj-class} +\end{figure} + +The class \Comp{optObj} is \pkgname's internal representation of an optimization +problem (figure~\ref{optObj-class}). Objects of this class harbor four slots: +\begin{inparaenum}[i)] +\item \Comp{oobj}: a pointer to the C-structure of the problem object (depending + on the solver software), +\item \Comp{solver}: the name of the solver, +\item \Comp{method}: the name of the optimization method used by the solver and +\item \Comp{probType}: single character string, describing the problem type + (e.\,g. \Comp{lp}: linear programming, or \Comp{mip}: mixed integer + programming). +\end{inparaenum} + +The package \pkgname provides several functions to alter the problem object. +Each function takes care of the special needs of every supported solver. The +following example should illustrate the purpose of class \Comp{optObj}. +Consider a linear programming problem, here written in lp formatted file +format: +\begin{verbatim} +Maximize + obj: + x_1 + x_2 +Subject To + r_1: + 0.5 x_1 + x_2 <= 4.5 + r_2: + 2 x_1 + x_2 <= 9 +Bounds + 0 <= x_1 <= 1000 + 0 <= x_2 <= 1000 +\end{verbatim} +In order to solve this lp problem with \pkgname{}, an object of class +\Comp{optObj} has to be created. The constructor function has the same name as +the class it builds. +<<print=true>>= +lp <- optObj(solver = "glpkAPI", method = "exact") +@ +The first argument is the used solver software, in this case it is GLPK. The +second optional argument gives the method, how the solver software has to solve +the problem. Here, it is the simplex exact algorithm of GLPK. The constructor +function \Comp{optObj()} (figure~\ref{optObj-const}) returns an object of class +\Comp{optObj\_glpkAPI} in this case. This class enables \pkgname to communicate +with the GLPK software. The constructor function \Comp{optObj()} calls the +function \Comp{checkDefaultMethod()} which tries to load the specified solver +package and also checks if all other arguments (\Comp{method} and \Comp{pType}) +are valid arguments. Each solver package has its own set of methods for specific +types of optimization (e.\,g. linear programming or quadratic programming) and +is thus available maybe not for all problem types. + +\begin{figure} + \centering + \includegraphics{optObj-const} + \caption{Work flow of the constructor function \Comp{optObj()}.} + \label{optObj-const} +\end{figure} + + +Initialize the new problem object. Each solver software needs to create +specific data structures to hold the problem and solution data. +<<print=true>>= +lp <- initProb(lp) +@ +Slot \Comp{oobj} holds a pointer to the problem object of GLPK. Now, we need to +allocate space for the problem data and load the data into the problem object. +<<>>= +cm <- Matrix(c(0.5, 2, 1, 1), nrow = 2) +loadLPprob(lp, nCols = 2, nRows = 2, mat = cm, + lb = c(0, 0), ub = rep(1000, 2), obj = c(1, 1), + rlb = c(0, 0), rub = c(4.5, 9), rtype = c("U", "U"), + lpdir = "max") +@ +The first command generates the constraint matrix in sparse format (see also +documentation in package \pkg{Matrix}). The second command loads the problem +data into the problem object. +<<>>= +lp +@ +All data are now set in the problem object, so it can be solved. +<<print=true>>= +status <- solveLp(lp) +@ +Translate the status code in a text string. +<<>>= +getMeanReturn(code = status, solver = solver(lp)) +@ +Check the solution status. +<<>>= +status <- getSolStat(lp) +getMeanStatus(code = status, solver = solver(lp)) +@ +Retrieve the value of the objective function and the values of the variables +after optimization. +<<>>= +getObjVal(lp) +getFluxDist(lp) +@ +Get the reduced costs. +<<>>= +getRedCosts(lp) +@ +Delete problem object and free all memory allocated by the solver software. +<<>>= +delProb(lp) +lp +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Class sysBiolAlg} \label{classsba} + +\begin{figure} + \centering + \includegraphics{sysBiolAlg-class} + \caption{UML representation of class \Comp{sysBiolAlg}.} + \label{sysBiolAlg-class} +\end{figure} + +The class \Comp{sysBiolAlg} holds objects of class \Comp{optObj} which are +prepared for a particular kind of algorithm, e.\,g. FBA, MOMA or ROOM +(figure~\ref{sysBiolAlg-class}). Class \Comp{optObj} takes care of the +communication between \pkgname and the solver software. Class \Comp{sysBiolAlg} +instead is responsible for the algorithm used to analyze a metabolic network. +The constructor function \Comp{sysBiolalg()} (figure~\ref{sysBiolAlg-const}) +gets at least two arguments: +\begin{inparaenum}[1.] +\item an object of class \Comp{modelorg} (section~\ref{classmod}) and +\item a single character string indicating the name of the desired algorithm. +\end{inparaenum} +Further arguments are passed through argument \Comp{\dots} to the corresponding +constructor of the class extending class \Comp{sysBiolAlg}. The base class +\Comp{sysBiolAlg} is virtual, no objects can be created from that class +directly. The constructor function builds an instance of a class extending the +base class: +<<>>= +ec <- sysBiolAlg(Ec_core, algorithm = "fba") +is(ec) +@ +Now, the variable \Comp{ec} contains an object of class \Comp{sysBiolAlg\_fba}. +Slot \Comp{problem} of that object is of class \Comp{optObj} and is prepared +for FBA. The optimization can be performed with method \Comp{optimizeProb}: +<<>>= +opt <- optimizeProb(ec) +@ +The return value of \Comp{optimizeProb} is discussed in section~\ref{fba}. +Method \Comp{optimizeProb} of class \Comp{sysBiolAlg} always returns a list, +not an object of class \Comp{optsol}. +In order to run a ROOM analysis create an object of class +\Comp{sysBiolAlg\_room}: +<<>>= +ecr <- sysBiolAlg(Ec_core, algorithm = "room", wtflux = opt$fluxes) +is(ecr) +ecr +@ +Argument \Comp{wtflux} gets the optimal flux distribution computed via FBA +earlier. It is used by the constructor method of class \Comp{sysBiolAlg\_room}. + +\begin{figure} + \centering + \includegraphics{sysBiolAlg-const} + \caption{Work flow of the constructor function \Comp{sysBiolAlg()}.} + \label{sysBiolAlg-const} +\end{figure} + +\begin{figure}[ht] + \centering + \includegraphics{sysBiolAlg-init} + \caption{Work flow of the constructor methods of classes extending + class \Comp{sysBiolAlg}. The gray shaded part is done by the + constructor method or the base class.} + \label{sysBiolAlg-init} +\end{figure} + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Constructor methods} + +The base class \Comp{sysBiolAlg} contains a constructor method \Comp{initialize} +which is called by the constructor methods of the subclasses via +\Comp{callNextMethod()} (figure~\ref{sysBiolAlg-init}). Every subclass has its +own constructor method preparing all necessary data structures in order to call +the constructor of the base class. For example, for the ROOM algorithm, a +``wild type'' flux distribution is required (argument \Comp{wtflux} in the +example above). The constructor of class \Comp{sysBiolAlg\_room} generates all +data structures to build the optimization problem, e.\,g. the constraint matrix, +objective coefficients, right hand side, \dots{} It passes all these data to +the constructor of \Comp{sysBiolAlg} via a call to \Comp{callNextMethod()}. +This constructor generates the object of class \Comp{optObj} while taking care +on solver software specific details. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{New algorithms} + +In order to extend the functionality of \pkgname with new algorithms, a new +class describing that algorithm is required. The function +\Comp{promptSysBiolAlg()} generates a skeletal structure of a new class definition +and a corresponding constructor method. To implement an algorithm named ``foo'', +run +<<eval=FALSE>>= +promptSysBiolAlg(algorithm = "foo") +@ +which generates a file \Comp{sysBiolAlg\_fooClass.R} containing the new class +definition. The class \Comp{sysBiolAlg\_foo} will extend class \Comp{sysBiolAlg} +directly and will not add any slots to the class. Additionally, an unfinished +method \Comp{initialize} is included. Here it is necessary to generate the data +structures required by the new algorithm. There are comments in the skeletal +structure guiding through the process. + + +%% maybe next chapter: how to extend sybil, example fluxVar or robAna + +% ---------------------------------------------------------------------------- % + +\newpage + +\bibliographystyle{abbrvnat} +\bibliography{sybil} + +\end{document} diff --git a/inst/extdata/Ec_core_desc.tsv b/inst/extdata/Ec_core_desc.tsv new file mode 100644 index 0000000..015b052 --- /dev/null +++ b/inst/extdata/Ec_core_desc.tsv @@ -0,0 +1,2 @@ +"name" "id" "description" "compartment" "abbreviation" "Nmetabolites" "Nreactions" "Ngenes" "Nnnz" +"Ecoli_core_model" "Ecoli_core_model" "ecoli_core_model" "C_c, C_e" "[c], [e]" 72 95 137 360 diff --git a/inst/extdata/Ec_core_met.tsv b/inst/extdata/Ec_core_met.tsv new file mode 100644 index 0000000..9c708ad --- /dev/null +++ b/inst/extdata/Ec_core_met.tsv @@ -0,0 +1,55 @@ +"abbreviation" "name" "compartment" +"13dpg" "3-Phospho-D-glyceroyl-phosphate" "C_c" +"2pg" "D-Glycerate-2-phosphate" "C_c" +"3pg" "3-Phospho-D-glycerate" "C_c" +"6pgc" "6-Phospho-D-gluconate" "C_c" +"6pgl" "6-phospho-D-glucono-1-5-lactone" "C_c" +"ac" "Acetate" "C_c, C_e" +"acald" "Acetaldehyde" "C_c, C_e" +"accoa" "Acetyl-CoA" "C_c" +"acon_C" "cis-Aconitate" "C_c" +"actp" "Acetyl-phosphate" "C_c" +"adp" "ADP" "C_c" +"akg" "2-Oxoglutarate" "C_c, C_e" +"amp" "AMP" "C_c" +"atp" "ATP" "C_c" +"cit" "Citrate" "C_c" +"co2" "CO2" "C_c, C_e" +"coa" "Coenzyme-A" "C_c" +"dhap" "Dihydroxyacetone-phosphate" "C_c" +"e4p" "D-Erythrose-4-phosphate" "C_c" +"etoh" "Ethanol" "C_c, C_e" +"f6p" "D-Fructose-6-phosphate" "C_c" +"fdp" "D-Fructose-1-6-bisphosphate" "C_c" +"for" "Formate" "C_c, C_e" +"fru" "D-Fructose" "C_e" +"fum" "Fumarate" "C_c, C_e" +"g3p" "Glyceraldehyde-3-phosphate" "C_c" +"g6p" "D-Glucose-6-phosphate" "C_c" +"glc_D" "D-Glucose" "C_e" +"gln_L" "L-Glutamine" "C_c, C_e" +"glu_L" "L-Glutamate" "C_c, C_e" +"glx" "Glyoxylate" "C_c" +"h" "H" "C_c, C_e" +"h2o" "H2O" "C_c, C_e" +"icit" "Isocitrate" "C_c" +"lac_D" "D-Lactate" "C_c, C_e" +"mal_L" "L-Malate" "C_c, C_e" +"nad" "Nicotinamide-adenine-dinucleotide" "C_c" +"nadh" "Nicotinamide-adenine-dinucleotide-reduced" "C_c" +"nadp" "Nicotinamide-adenine-dinucleotide-phosphate" "C_c" +"nadph" "Nicotinamide-adenine-dinucleotide-phosphate-reduced" "C_c" +"nh4" "Ammonium" "C_c, C_e" +"o2" "O2" "C_c, C_e" +"oaa" "Oxaloacetate" "C_c" +"pep" "Phosphoenolpyruvate" "C_c" +"pi" "Phosphate" "C_c, C_e" +"pyr" "Pyruvate" "C_c, C_e" +"q8" "Ubiquinone-8" "C_c" +"q8h2" "Ubiquinol-8" "C_c" +"r5p" "alpha-D-Ribose-5-phosphate" "C_c" +"ru5p_D" "D-Ribulose-5-phosphate" "C_c" +"s7p" "Sedoheptulose-7-phosphate" "C_c" +"succ" "Succinate" "C_c, C_e" +"succoa" "Succinyl-CoA" "C_c" +"xu5p_D" "D-Xylulose-5-phosphate" "C_c" diff --git a/inst/extdata/Ec_core_react.tsv b/inst/extdata/Ec_core_react.tsv new file mode 100644 index 0000000..f16b217 --- /dev/null +++ b/inst/extdata/Ec_core_react.tsv @@ -0,0 +1,96 @@ +"abbreviation" "name" "equation" "reversible" "compartment" "lowbnd" "uppbnd" "obj_coef" "rule" "subsystem" +"ACALD" "acetaldehyde dehydrogenase (acetylating)" "[c] : acald + coa + nad <==> accoa + h + nadh" "Reversible" "C_c" -1000 1000 0 "(b0351 or b1241)" "Pyruvate Metabolism" +"ACALDt" "acetaldehyde reversible transport" "acald[e] <==> acald[c]" "Reversible" "C_c, C_e" -1000 1000 0 "s0001" "Transport, Extracellular" +"ACKr" "acetate kinase" "[c] : ac + atp <==> actp + adp" "Reversible" "C_c" -1000 1000 0 "(b3115 or b2296 or b1849)" "Pyruvate Metabolism" +"ACONTa" "aconitase (half-reaction A, Citrate hydro-lyase)" "[c] : cit <==> acon_C + h2o" "Reversible" "C_c" -1000 1000 0 "(b0118 or b1276)" "Citric Acid Cycle" +"ACONTb" "aconitase (half-reaction B, Isocitrate hydro-lyase)" "[c] : acon_C + h2o <==> icit" "Reversible" "C_c" -1000 1000 0 "(b0118 or b1276)" "Citric Acid Cycle" +"ACt2r" "acetate reversible transport via proton symport" "ac[e] + h[e] <==> ac[c] + h[c]" "Reversible" "C_c, C_e" -1000 1000 0 "" "Transport, Extracellular" +"ADK1" "adenylate kinase" "[c] : amp + atp <==> (2) adp" "Reversible" "C_c" -1000 1000 0 "b0474" "Oxidative Phosphorylation" +"AKGDH" "2-Oxoglutarate dehydrogenase" "[c] : akg + coa + nad --> co2 + nadh + succoa" "Irreversible" "C_c" 0 1000 0 "( b0116 and b0726 and b0727 )" "Citric Acid Cycle" +"AKGt2r" "2-oxoglutarate reversible transport via symport" "akg[e] + h[e] <==> akg[c] + h[c]" "Reversible" "C_c, C_e" -1000 1000 0 "b2587" "Transport, Extracellular" +"ALCD2x" "alcohol dehydrogenase (ethanol)" "[c] : etoh + nad <==> acald + h + nadh" "Reversible" "C_c" -1000 1000 0 "(b0356 or b1478 or b1241)" "Pyruvate Metabolism" +"ATPM" "ATP maintenance requirement" "[c] : atp + h2o --> adp + h + pi" "Irreversible" "C_c" 8.39 1000 0 "" "Oxidative Phosphorylation" +"ATPS4r" "ATP synthase (four protons for one ATP)" "adp[c] + (4) h[e] + pi[c] <==> atp[c] + h2o[c] + (3) h[c]" "Reversible" "C_c, C_e" -1000 1000 0 "(((b3736 and b3737 and b3738) and (b3731 and b3732 and b3733 and b3734 and b3735)) or ((b3736 and b3737 and b3738) and (b3731 and b3732 and b3733 and b3734 and b3735) and b3739))" "Oxidative Phosphorylation" +"Biomass_Ecoli_core_w_GAM" "Biomass Objective Function with GAM" "[c] : (1.496) 3pg + (3.7478) accoa + (59.81) atp + (0.361) e4p + (0.0709) f6p + (0.129) g3p + (0.205) g6p + (0.2557) gln_L + (4.9414) glu_L + (59.81) h2o + (3.547) nad + (13.0279) nadph + (1.7867) oaa + (0.5191) pep + (2.8328) pyr + (0.8977) r5p --> (59.81) adp + (4.1182) akg + (3.7478) coa + (59.81) h + (3.547) nadh + (13.0279) nadp + (59.81) pi" "Irreversible" "C_c" 0 1000 1 "" "" +"CO2t" "CO2 transporter via diffusion" "co2[e] <==> co2[c]" "Reversible" "C_c, C_e" -1000 1000 0 "s0001" "Transport, Extracellular" +"CS" "citrate synthase" "[c] : accoa + h2o + oaa --> cit + coa + h" "Irreversible" "C_c" 0 1000 0 "b0720" "Citric Acid Cycle" +"CYTBD" "cytochrome oxidase bd (ubiquinol-8: 2 protons)" "(2) h[c] + (0.5) o2[c] + q8h2[c] --> h2o[c] + (2) h[e] + q8[c]" "Irreversible" "C_c, C_e" 0 1000 0 "((b0978 and b0979) or (b0733 and b0734))" "Oxidative Phosphorylation" +"D_LACt2" "D-lactate transport via proton symport" "h[e] + lac_D[e] <==> h[c] + lac_D[c]" "Reversible" "C_c, C_e" -1000 1000 0 "( b2975 or b3603 )" "Transport, Extracellular" +"ENO" "enolase" "[c] : 2pg <==> h2o + pep" "Reversible" "C_c" -1000 1000 0 "b2779" "Glycolysis/Gluconeogenesis" +"ETOHt2r" "ethanol reversible transport via proton symport" "etoh[e] + h[e] <==> etoh[c] + h[c]" "Reversible" "C_c, C_e" -1000 1000 0 "" "Transport, Extracellular" +"EX_ac(e)" "Acetate exchange" "[e] : ac <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_acald(e)" "Acetaldehyde exchange" "[e] : acald <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_akg(e)" "2-Oxoglutarate exchange" "[e] : akg <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_co2(e)" "CO2 exchange" "[e] : co2 <==> " "Reversible" "C_e" -1000 1000 0 "" "Exchange" +"EX_etoh(e)" "Ethanol exchange" "[e] : etoh <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_for(e)" "Formate exchange" "[e] : for <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_fru(e)" "D-Fructose exchange" "[e] : fru <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_fum(e)" "Fumarate exchange" "[e] : fum <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_glc(e)" "D-Glucose exchange" "[e] : glc_D <==> " "Reversible" "C_e" -10 1000 0 "" "Exchange" +"EX_gln_L(e)" "L-Glutamine exchange" "[e] : gln_L <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_glu_L(e)" "L-Glutamate exchange" "[e] : glu_L <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_h(e)" "H+ exchange" "[e] : h <==> " "Reversible" "C_e" -1000 1000 0 "" "Exchange" +"EX_h2o(e)" "H2O exchange" "[e] : h2o <==> " "Reversible" "C_e" -1000 1000 0 "" "Exchange" +"EX_lac_D(e)" "D-Lactate exchange" "[e] : lac_D <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_mal_L(e)" "L-Malate exchange" "[e] : mal_L <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_nh4(e)" "Ammonium exchange" "[e] : nh4 <==> " "Reversible" "C_e" -1000 1000 0 "" "Exchange" +"EX_o2(e)" "O2 exchange" "[e] : o2 <==> " "Reversible" "C_e" -1000 1000 0 "" "Exchange" +"EX_pi(e)" "Phosphate exchange" "[e] : pi <==> " "Reversible" "C_e" -1000 1000 0 "" "Exchange" +"EX_pyr(e)" "Pyruvate exchange" "[e] : pyr <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"EX_succ(e)" "Succinate exchange" "[e] : succ <==> " "Reversible" "C_e" 0 1000 0 "" "Exchange" +"FBA" "fructose-bisphosphate aldolase" "[c] : fdp <==> dhap + g3p" "Reversible" "C_c" -1000 1000 0 "(b2097 or b1773 or b2925)" "Glycolysis/Gluconeogenesis" +"FBP" "fructose-bisphosphatase" "[c] : fdp + h2o --> f6p + pi" "Irreversible" "C_c" 0 1000 0 "(b3925 or b4232)" "Glycolysis/Gluconeogenesis" +"FORt2" "formate transport via proton symport (uptake only)" "for[e] + h[e] --> for[c] + h[c]" "Irreversible" "C_c, C_e" 0 1000 0 "(b0904 or b2492)" "Transport, Extracellular" +"FORti" "formate transport via diffusion" "for[c] --> for[e]" "Irreversible" "C_c, C_e" 0 1000 0 "(b0904 or b2492)" "Transport, Extracellular" +"FRD7" "fumarate reductase" "[c] : fum + q8h2 --> q8 + succ" "Irreversible" "C_c" 0 1000 0 "(b4151 and b4152 and b4153 and b4154)" "Oxidative Phosphorylation" +"FRUpts2" "Fructose transport via PEP:Pyr PTS (f6p generating)" "fru[e] + pep[c] --> f6p[c] + pyr[c]" "Irreversible" "C_c, C_e" 0 1000 0 "(b1817 and b1818 and b1819 and b2415 and b2416)" "Transport, Extracellular" +"FUM" "fumarase" "[c] : fum + h2o <==> mal_L" "Reversible" "C_c" -1000 1000 0 "( b1612 or b4122 or b1611 )" "Citric Acid Cycle" +"FUMt2_2" "Fumarate transport via proton symport (2 H)" "fum[e] + (2) h[e] --> fum[c] + (2) h[c]" "Irreversible" "C_c, C_e" 0 1000 0 "b3528" "Transport, Extracellular" +"G6PDH2r" "glucose 6-phosphate dehydrogenase" "[c] : g6p + nadp <==> 6pgl + h + nadph" "Reversible" "C_c" -1000 1000 0 "b1852" "Pentose Phosphate Pathway" +"GAPD" "glyceraldehyde-3-phosphate dehydrogenase" "[c] : g3p + nad + pi <==> 13dpg + h + nadh" "Reversible" "C_c" -1000 1000 0 "b1779" "Glycolysis/Gluconeogenesis" +"GLCpts" "D-glucose transport via PEP:Pyr PTS" "glc_D[e] + pep[c] --> g6p[c] + pyr[c]" "Irreversible" "C_c, C_e" 0 1000 0 "((b2417 and b1101 and b2415 and b2416) or (b1817 and b1818 and b1819 and b2415 and b2416) or (b2417 and b1621 and b2415 and b2416))" "Transport, Extracellular" +"GLNS" "glutamine synthetase" "[c] : atp + glu_L + nh4 --> adp + gln_L + h + pi" "Irreversible" "C_c" 0 1000 0 "(b3870 or b1297)" "Glutamate Metabolism" +"GLNabc" "L-glutamine transport via ABC system" "atp[c] + gln_L[e] + h2o[c] --> adp[c] + gln_L[c] + h[c] + pi[c]" "Irreversible" "C_c, C_e" 0 1000 0 "(b0811 and b0810 and b0809)" "Transport, Extracellular" +"GLUDy" "glutamate dehydrogenase (NADP)" "[c] : glu_L + h2o + nadp <==> akg + h + nadph + nh4" "Reversible" "C_c" -1000 1000 0 "b1761" "Glutamate Metabolism" +"GLUN" "glutaminase" "[c] : gln_L + h2o --> glu_L + nh4" "Irreversible" "C_c" 0 1000 0 "(b1812 or b0485 or b1524)" "Glutamate Metabolism" +"GLUSy" "glutamate synthase (NADPH)" "[c] : akg + gln_L + h + nadph --> (2) glu_L + nadp" "Irreversible" "C_c" 0 1000 0 "(b3212 and b3213)" "Glutamate Metabolism" +"GLUt2r" "L-glutamate transport via proton symport, reversible (periplasm)" "glu_L[e] + h[e] <==> glu_L[c] + h[c]" "Reversible" "C_c, C_e" -1000 1000 0 "b4077" "Transport, Extracellular" +"GND" "phosphogluconate dehydrogenase" "[c] : 6pgc + nadp --> co2 + nadph + ru5p_D" "Irreversible" "C_c" 0 1000 0 "b2029" "Pentose Phosphate Pathway" +"H2Ot" "H2O transport via diffusion" "h2o[e] <==> h2o[c]" "Reversible" "C_c, C_e" -1000 1000 0 "(b0875 or s0001)" "Transport, Extracellular" +"ICDHyr" "isocitrate dehydrogenase (NADP)" "[c] : icit + nadp <==> akg + co2 + nadph" "Reversible" "C_c" -1000 1000 0 "b1136" "Citric Acid Cycle" +"ICL" "Isocitrate lyase" "[c] : icit --> glx + succ" "Irreversible" "C_c" 0 1000 0 "b4015" "Anaplerotic reactions" +"LDH_D" "D lactate dehydrogenase" "[c] : lac_D + nad <==> h + nadh + pyr" "Reversible" "C_c" -1000 1000 0 "(b2133 or b1380)" "Pyruvate Metabolism" +"MALS" "malate synthase" "[c] : accoa + glx + h2o --> coa + h + mal_L" "Irreversible" "C_c" 0 1000 0 "( b4014 or b2976 )" "Anaplerotic reactions" +"MALt2_2" "Malate transport via proton symport (2 H)" "(2) h[e] + mal_L[e] --> (2) h[c] + mal_L[c]" "Irreversible" "C_c, C_e" 0 1000 0 "b3528" "Transport, Extracellular" +"MDH" "malate dehydrogenase" "[c] : mal_L + nad <==> h + nadh + oaa" "Reversible" "C_c" -1000 1000 0 "b3236" "Citric Acid Cycle" +"ME1" "malic enzyme (NAD)" "[c] : mal_L + nad --> co2 + nadh + pyr" "Irreversible" "C_c" 0 1000 0 "b1479" "Anaplerotic reactions" +"ME2" "malic enzyme (NADP)" "[c] : mal_L + nadp --> co2 + nadph + pyr" "Irreversible" "C_c" 0 1000 0 "b2463" "Anaplerotic reactions" +"NADH16" "NADH dehydrogenase (ubiquinone-8 & 3 protons)" "(4) h[c] + nadh[c] + q8[c] --> (3) h[e] + nad[c] + q8h2[c]" "Irreversible" "C_c, C_e" 0 1000 0 "(b2276 and b2277 and b2278 and b2279 and b2280 and b2281 and b2282 and b2283 and b2284 and b2285 and b2286 and b2287 and b2288)" "Oxidative Phosphorylation" +"NADTRHD" "NAD transhydrogenase" "[c] : nad + nadph --> nadh + nadp" "Irreversible" "C_c" 0 1000 0 "(b3962 or (b1602 and b1603))" "Oxidative Phosphorylation" +"NH4t" "ammonia reversible transport" "nh4[e] <==> nh4[c]" "Reversible" "C_c, C_e" -1000 1000 0 "(s0001 or b0451)" "Inorganic Ion Transport and Metabolism" +"O2t" "o2 transport via diffusion" "o2[e] <==> o2[c]" "Reversible" "C_c, C_e" -1000 1000 0 "s0001" "Transport, Extracellular" +"PDH" "pyruvate dehydrogenase" "[c] : coa + nad + pyr --> accoa + co2 + nadh" "Irreversible" "C_c" 0 1000 0 "( b0114 and b0115 and b0116 )" "Glycolysis/Gluconeogenesis" +"PFK" "phosphofructokinase" "[c] : atp + f6p --> adp + fdp + h" "Irreversible" "C_c" 0 1000 0 "( b3916 or b1723 )" "Glycolysis/Gluconeogenesis" +"PFL" "pyruvate formate lyase" "[c] : coa + pyr --> accoa + for" "Irreversible" "C_c" 0 1000 0 "(((b0902 and b0903) and b2579) or (b0902 and b0903) or (b0902 and b3114) or (b3951 and b3952))" "Pyruvate Metabolism" +"PGI" "glucose-6-phosphate isomerase" "[c] : g6p <==> f6p" "Reversible" "C_c" -1000 1000 0 "b4025" "Glycolysis/Gluconeogenesis" +"PGK" "phosphoglycerate kinase" "[c] : 3pg + atp <==> 13dpg + adp" "Reversible" "C_c" -1000 1000 0 "b2926" "Glycolysis/Gluconeogenesis" +"PGL" "6-phosphogluconolactonase" "[c] : 6pgl + h2o --> 6pgc + h" "Irreversible" "C_c" 0 1000 0 "b0767" "Pentose Phosphate Pathway" +"PGM" "phosphoglycerate mutase" "[c] : 2pg <==> 3pg" "Reversible" "C_c" -1000 1000 0 "(b3612 or b4395 or b0755)" "Glycolysis/Gluconeogenesis" +"PIt2r" "phosphate reversible transport via proton symport" "h[e] + pi[e] <==> h[c] + pi[c]" "Reversible" "C_c, C_e" -1000 1000 0 "(b2987 or b3493)" "Inorganic Ion Transport and Metabolism" +"PPC" "phosphoenolpyruvate carboxylase" "[c] : co2 + h2o + pep --> h + oaa + pi" "Irreversible" "C_c" 0 1000 0 "b3956" "Anaplerotic reactions" +"PPCK" "phosphoenolpyruvate carboxykinase" "[c] : atp + oaa --> adp + co2 + pep" "Irreversible" "C_c" 0 1000 0 "b3403" "Anaplerotic reactions" +"PPS" "phosphoenolpyruvate synthase" "[c] : atp + h2o + pyr --> amp + (2) h + pep + pi" "Irreversible" "C_c" 0 1000 0 "b1702" "Glycolysis/Gluconeogenesis" +"PTAr" "phosphotransacetylase" "[c] : accoa + pi <==> actp + coa" "Reversible" "C_c" -1000 1000 0 "(b2297 or b2458)" "Pyruvate Metabolism" +"PYK" "pyruvate kinase" "[c] : adp + h + pep --> atp + pyr" "Irreversible" "C_c" 0 1000 0 "(b1854 or b1676)" "Glycolysis/Gluconeogenesis" +"PYRt2r" "pyruvate reversible transport via proton symport" "h[e] + pyr[e] <==> h[c] + pyr[c]" "Reversible" "C_c, C_e" -1000 1000 0 "" "Transport, Extracellular" +"RPE" "ribulose 5-phosphate 3-epimerase" "[c] : ru5p_D <==> xu5p_D" "Reversible" "C_c" -1000 1000 0 "(b3386 or b4301)" "Pentose Phosphate Pathway" +"RPI" "ribose-5-phosphate isomerase" "[c] : r5p <==> ru5p_D" "Reversible" "C_c" -1000 1000 0 "( b2914 or b4090 )" "Pentose Phosphate Pathway" +"SUCCt2_2" "succinate transport via proton symport (2 H)" "(2) h[e] + succ[e] --> (2) h[c] + succ[c]" "Irreversible" "C_c, C_e" 0 1000 0 "b3528" "Transport, Extracellular" +"SUCCt3" "succinate transport out via proton antiport" "h[e] + succ[c] --> h[c] + succ[e]" "Irreversible" "C_c, C_e" 0 1000 0 "" "Transport, Extracellular" +"SUCDi" "succinate dehydrogenase (irreversible)" "[c] : q8 + succ --> fum + q8h2" "Irreversible" "C_c" 0 1000 0 "(b0721 and b0722 and b0723 and b0724)" "Oxidative Phosphorylation" +"SUCOAS" "succinyl-CoA synthetase (ADP-forming)" "[c] : atp + coa + succ <==> adp + pi + succoa" "Reversible" "C_c" -1000 1000 0 "( b0728 and b0729 )" "Citric Acid Cycle" +"TALA" "transaldolase" "[c] : g3p + s7p <==> e4p + f6p" "Reversible" "C_c" -1000 1000 0 "(b2464 or b0008)" "Pentose Phosphate Pathway" +"THD2" "NAD(P) transhydrogenase" "(2) h[e] + nadh[c] + nadp[c] --> (2) h[c] + nad[c] + nadph[c]" "Irreversible" "C_c, C_e" 0 1000 0 "( b1602 and b1603 )" "Oxidative Phosphorylation" +"TKT1" "transketolase" "[c] : r5p + xu5p_D <==> g3p + s7p" "Reversible" "C_c" -1000 1000 0 "( b2935 or b2465 )" "Pentose Phosphate Pathway" +"TKT2" "transketolase" "[c] : e4p + xu5p_D <==> f6p + g3p" "Reversible" "C_c" -1000 1000 0 "( b2935 or b2465 )" "Pentose Phosphate Pathway" +"TPI" "triose-phosphate isomerase" "[c] : dhap <==> g3p" "Reversible" "C_c" -1000 1000 0 "b3919" "Glycolysis/Gluconeogenesis" diff --git a/man/Ec_core.Rd b/man/Ec_core.Rd new file mode 100644 index 0000000..0f48f1e --- /dev/null +++ b/man/Ec_core.Rd @@ -0,0 +1,31 @@ +\name{Ec_core} +\docType{data} +\alias{Ec_core} + +\encoding{utf8} + +\title{Escherichia coli Core Metabolic Model} + +\description{ + The dataset is a network representation of the \emph{E. coli} core + metabolism. It consists of 95 internal reactions, 20 exchange + reactions and a biomass objective function. +} + +\usage{data(Ec_core)} + +\format{An object of class \code{modelorg}} + +\source{\url{http://gcrg.ucsd.edu/Downloads/EcoliCore}} + +\references{ + Bernhard Ø. Palsson (2006). + \emph{Systems Biology: Properties of Reconstructed Networks}. + Cambridge University Press. + + Orth, J. D., Fleming, R. M. T. and Palsson, B. Ø. (2010). + Reconstruction and Use of Microbial Metabolic Networks: the Core Escherichia + coli Metabolic Model as an Educational Guide \emph{in} EcoSal Chapter 10.2.1. +} + +\keyword{datasets} diff --git a/man/SYBIL_SETTINGS.Rd b/man/SYBIL_SETTINGS.Rd new file mode 100644 index 0000000..6823764 --- /dev/null +++ b/man/SYBIL_SETTINGS.Rd @@ -0,0 +1,181 @@ +\name{SYBIL_SETTINGS} +\alias{SYBIL_SETTINGS} +\alias{SOLVER} +\alias{METHOD} +\alias{TOLERANCE} +\alias{MAXIMUM} +\alias{ALGORITHM} +\alias{OPT_DIRECTION} +\alias{USE_NAMES} +\alias{PATH_TO_MODEL} +\alias{SOLVER_CTRL_PARM} + +\encoding{utf8} + +\title{ + Set and Get sybil Parameters +} + +\description{ + Manage a set of default parameter settings for sybil. +} + +\usage{ + SYBIL_SETTINGS(parm, value, ...) +} + +\arguments{ + \item{parm}{ + A character string giving the name of the parameter to set. + } + \item{value}{ + The corresponding value. + } + \item{...}{ + Further arguments passed to \code{\link{checkDefaultMethod}}. Only used if + parameters \code{"SOLVER"} or \code{"METHOD"} are set. + } +} + +\details{ + Typical usages are + \preformatted{ + SYBIL_SETTINGS(parm, value) + SYBIL_SETTINGS(parm) + SYBIL_SETTINGS() + } + Possible parameters are: + \describe{ + \item{\code{"SOLVER"}}{ + The default solver for lp problems. Possible values are depend on your + installed API package.\cr + \describe{ + \item{\pkg{glpkAPI}:}{ + \code{"glpkAPI"}, + } + \item{\pkg{cplexAPI}:}{ + \code{"cplexAPI"}, + } + \item{\pkg{clpAPI}:}{ + \code{"clpAPI"}, + } + \item{\pkg{lpSolveAPI}:}{ + \code{"lpSolveAPI"}. + } + } + Default: \code{"glpkAPI"}. + } + \item{\code{"METHOD"}}{ + The default method to solve lp problems. Possible values are + \describe{ + \item{\pkg{glpkAPI}:}{ + \code{"simplex"}, \code{"interior"}, \code{"exact"} or \code{mip}. + } + \item{\pkg{cplexAPI}:}{ + \code{"lpopt"}, \code{"primopt"} \code{"dualopt"}, \code{"baropt"}, + \code{"hybbaropt"}, \code{"hybnetopt"}, \code{"siftopt"}, + \code{mipopt} or \code{qpopt}. + } + \item{\pkg{clpAPI}:}{ + \code{"general_solve"}, \code{"inidual"} \code{"iniprimal"}, + \code{"inibarrier"}, \code{"inibarriernoc"}, \code{"idiot"}, + \code{"dual"} or \code{"primal"}. + } + \item{\pkg{lpSolveAPI}:}{ + \code{"lp_solve"}. + } + } + Default: \code{"simplex"}.\cr + If the parameter \code{"SOLVER"} is changed, the corrsponding default + \code{"METHOD"} is the first one mentioned, e.g. for \code{"cplexAPI"}, + it will be \code{"lpopt"}. This change is done automatically when changing + the solver. It is not possible, to set a not existing \code{"METHOD"} + for a particular \code{"SOLVER"}, the corresponding default value will + be used in such a case. + } + \item{\code{"TOLERANCE"}}{ + Tolerance value.\cr + Default: \code{1E-6}. + } + \item{\code{"MAXIMUM"}}{ + Absolute maximum value.\cr + Default: \code{1000}. + } + \item{\code{"ALGORITHM"}}{ + Algorithm to use in order to analyze metabolic networks. + Possible values are: + \describe{ + \item{\code{"\link[=sysBiolAlg_fba-class]{fba}"}}{ + flux-balance analysis, + } + \item{\code{"\link[=sysBiolAlg_fv-class]{fv}"}}{ + flux-variance analysis, + } + \item{\code{"\link[=sysBiolAlg_mtf-class]{mtf}"}}{ + minimize total flux, + } + \item{\code{"\link[=sysBiolAlg_moma-class]{moma}"}}{ + minimization of metabolic adjustment (MOMA), + } + \item{\code{"\link[=sysBiolAlg_lmoma-class]{lmoma}"}}{ + linear version of MOMA, + } + \item{\code{"\link[=sysBiolAlg_room-class]{room}"}}{ + regulatory on/off minimization (ROOM). + } + } + Default: \code{"fba"}. + } + \item{\code{"OPT_DIRECTION"}}{ + Direction of optimization. Can be \code{"max"} or \code{"min"}.\cr + Default: \code{"max"}. + } + \item{\code{"USE_NAMES"}}{ + A logical value indicating if reaction id's and metabolite id's (or other + names) should be used as names for variables and constraints in objects of + class \code{\linkS4class{sysBiolAlg}}.\cr + Default: \code{FALSE}. + } + \item{\code{"PATH_TO_MODEL"}}{ + Path to a directory to read or write files.\cr + Default: \code{"."}. + } + \item{\code{"SOLVER_CTRL_PARM"}}{ + A \code{data.frame} giving parameters to the optimizer software + (e.g. GLPK).\cr + Default: \code{as.data.frame(NA)}. + } + } +} + +\value{ + If successful, a set of parameters to sybil will be returned. +} + +\author{ + Gabriel Gelius-Dietrich + + Maintainer: Gabriel Gelius-Dietrich <geliudie@uni-duesseldorf.de> +} + +\seealso{ + \code{\link{checkDefaultMethod}} +} + +\examples{ + ## show all current parameters + SYBIL_SETTINGS() + + ## show current setting for "SOLVER" + SYBIL_SETTINGS("SOLVER") + + ## change current solver to glpkAPI + SYBIL_SETTINGS("SOLVER", "glpkAPI") +\dontrun{ + ## this needs cplexAPI installed + ## change current solver to cplexAPI + SYBIL_SETTINGS("SOLVER", "cplexAPI") +} +} + +\keyword{ optimize } diff --git a/man/addAlgorithm.Rd b/man/addAlgorithm.Rd new file mode 100644 index 0000000..457b89b --- /dev/null +++ b/man/addAlgorithm.Rd @@ -0,0 +1,36 @@ +\name{addAlgorithm} +\alias{addAlgorithm} + +\title{ + Add a New Algorithm Name to sybil +} +\description{ + Certain simulations can be run using different algorithms. For example, + genetic perturbations can be studied with FBA, MOMA or the like. With this + funktion you can add a new algorithm to an existing kind of simulation. +} +\usage{ + addAlgorithm(alg, purpose) +} + +\arguments{ + \item{alg}{ + A single character string containing the name of the new algorithm. + } + \item{purpose}{ + Purpose of the new algorithm. + } +} + +\value{ + Returns \code{NULL} invisibly. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{checkAlgorithm}}, \code{\link{getsybilenv}} +} + diff --git a/man/addCols-methods.Rd b/man/addCols-methods.Rd new file mode 100644 index 0000000..8e9a834 --- /dev/null +++ b/man/addCols-methods.Rd @@ -0,0 +1,66 @@ +\name{addCols-methods} + +\docType{methods} +\encoding{utf8} + +\alias{addCols} +\alias{addCols-methods} + +\alias{addCols,optObj_clpAPI,numeric-method} +\alias{addCols,optObj_cplexAPI,numeric-method} +\alias{addCols,optObj_glpkAPI,numeric-method} +\alias{addCols,optObj_lpSolveAPI,numeric-method} + +\title{Add Columns to an Optimization Problem} + +\description{ + Add columns to an optimization problem. +} + +\usage{ +\S4method{addCols}{optObj_clpAPI,numeric}(lp, ncols) + +\S4method{addCols}{optObj_cplexAPI,numeric}(lp, ncols) + +\S4method{addCols}{optObj_glpkAPI,numeric}(lp, ncols) + +\S4method{addCols}{optObj_lpSolveAPI,numeric}(lp, ncols) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", ncols = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", ncols = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", ncols = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", ncols = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{ncols}{ + Number of columns (variables) to add to the problem object. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/addColsToProb-methods.Rd b/man/addColsToProb-methods.Rd new file mode 100644 index 0000000..30ad5d6 --- /dev/null +++ b/man/addColsToProb-methods.Rd @@ -0,0 +1,86 @@ +\name{addColsToProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{addColsToProb} +\alias{addColsToProb-methods} + +\alias{addColsToProb,optObj_clpAPI-method} +\alias{addColsToProb,optObj_cplexAPI-method} +\alias{addColsToProb,optObj_glpkAPI-method} +\alias{addColsToProb,optObj_lpSolveAPI-method} + +\title{Add New Columns (Variables) to an Optimization Problem} + +\description{ + Add new columns (variables) to an optimization problem. +} + +\usage{ +\S4method{addColsToProb}{optObj_clpAPI}(lp, j, obj, lb, ub, rind, nzval) + +\S4method{addColsToProb}{optObj_cplexAPI}(lp, j, obj, lb, ub, rind, nzval) + +\S4method{addColsToProb}{optObj_glpkAPI}(lp, j, obj, lb, ub, rind, nzval) + +\S4method{addColsToProb}{optObj_lpSolveAPI}(lp, j, obj, lb, ub, rind, nzval) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the new column indices. + } + \item{obj}{ + A numeric vector containing the objective coefficients of the new variables. + } + \item{lb}{ + A numeric vector containing the lower bounds of the new variables. + } + \item{ub}{ + A numeric vector containing the upper bounds of the new variables. + } + \item{rind}{ + A list containing the row indices of the new non-zero elements. + } + \item{nzval}{ + A list containing the new non-zero elements. + } +} + +\note{ + Arguments \code{j}, \code{obj}, \code{lb}, \code{lu}, \code{rind} and + \code{nzval} must have the same length. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/addExchReact.Rd b/man/addExchReact.Rd new file mode 100644 index 0000000..6f901b8 --- /dev/null +++ b/man/addExchReact.Rd @@ -0,0 +1,79 @@ +\name{addExchReact} +\alias{addExchReact} + +\encoding{utf8} + +\title{ + Add Exchange Reactions to a Model +} + +\description{ + The function \code{addExchReact} adds exchange reactions for a set of + metabolites to a metabolic model. +} + +\usage{ + addExchReact(model, met, lb, ub) +} + +\arguments{ + \item{model}{ + An object of class \code{modelorg}. + } + \item{met}{ + A vector of character strings containing the metabolite id's to add exchange + reactions for. + } + \item{lb}{ + A vector of numeric values of the same length as \code{met} containing the + lower bounds for the exchange reactions.\cr + Default: \code{rep(0, length(met))}. + } + \item{ub}{ + A vector of numeric values of the same length as \code{met} containing the + upper bounds for the exchange reactions.\cr + Default: \code{rep(SYBIL_SETTINGS("MAXIMUM"), length(met))}. + } +} + +\details{ + If \code{lb[i] < 0}, the exchange reaction for the metabolite in \code{met[i]} + is considered to be reversible, otherwise irreversible. A reaction id is + generated for each exchange reaction by prepending the metabolite id's with + the string \code{"Ex_"}. +} + +\value{ + An object of class \code{\linkS4class{modelorg}} +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\linkS4class{modelorg}} and \code{\link{addReact}} +} + +\examples{ + # add exchange reactions (allowing input) for the metabolites + # malate and oxalacetate + data(Ec_core) + mod <- addExchReact(Ec_core, + met = c("mal_L[c]", "oaa[c]"), + lb = c(-20, -20)) + findExchReact(mod) +} + +\keyword{manip} diff --git a/man/addReact.Rd b/man/addReact.Rd new file mode 100644 index 0000000..3d61be3 --- /dev/null +++ b/man/addReact.Rd @@ -0,0 +1,137 @@ +\name{addReact} +\alias{addReact} + +\encoding{utf8} + +\title{ + Add/Change Reactions in a Model +} + +\description{ + The function \code{addReact} adds one reaction to a metabolic model, or + changes one reaction in a metabolic model. +} + +\usage{ + addReact(model, + id, + met, + Scoef, + reversible = FALSE, + lb = 0, + ub = SYBIL_SETTINGS("MAXIMUM"), + obj = 0, + subSystem = NA, + gprAssoc = NA, + reactName = NA, + metName = NA, + metComp = NA) +} + +\arguments{ + \item{model}{ + An object of class \code{modelorg}. + } + \item{id}{ + A single character string containing a reaction id (see details below). + } + \item{met}{ + A vector of character strings containing the metabolite id's used in the + reaction given in \code{Scoef}. + } + \item{Scoef}{ + A numeric vector of the same length as \code{met} of stoichiometric + coefficients for the metabolites in \code{met}. The value in \code{Scoef[i]} + is the stoichiometric coefficient of the metabolite in \code{met[i]}. + } + \item{reversible}{ + A Boolean value, indicating if the reaction is reversible or not.\cr + Default: \code{FALSE}. + } + \item{lb}{ + A single numeric value giving the lower bound of the reaction.\cr + Default: \code{0}. + } + \item{ub}{ + A single numeric value giving the upper bound of the reaction.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM")}. + } + \item{obj}{ + A single numeric value giving the objective coefficient of the reaction.\cr + Default: \code{0}. + } + \item{subSystem}{ + A vector of character strings containing the sub systems to which the + reaction belongs. All values must be available in + \code{\link{subSys}(model)}. If \code{NA}, the reaction will not be + associated to any sub system.\cr + Default: \code{NA}. + } + \item{gprAssoc}{ + A single character string giving the gpr association for the reaction. If + \code{NA}, no gpr association is created.\cr + Default: \code{NA}. + } + \item{reactName}{ + A single character string giving the name for the reaction. If \code{NA}, + the value of argument \code{id} is used.\cr + Default: \code{NA}. + } + \item{metName}{ + A vector of character strings of the same length as \code{met} containing + the the metabolites names for the metabolites given in argument \code{met}. + If set to \code{NA}, the metabolite id's are used. + Default: \code{NA}. + } + \item{metComp}{ + A vector of character strings or integers of the same length as \code{met} + containing a compartment name (as in \code{\link{mod_compart}(model)}) or an + index pointing to a value in \code{\link{mod_compart}(model)} (as in + \code{met_comp(model)}). If \code{NA}, the metabolites will not be + associated to any compartment.\cr + Default: \code{NA}. + } +} + +\details{ + The function \code{addReact} can be used to add reactions and/or metabolites + to a given metabolic model, or to change parameters of a reaction already + present in a given metabolic model. + If the reaction id in argument \code{id}is already present in the given model, + this reaction will be changed, no new column will be added to the + stoichiometric matrix. If any of the metabolite id's of argument \code{met} + are not present in the model, they will be added (new rows in the + stoichiometric matrix will be added). + + Arguments \code{subSystem}, \code{gprAssoc} and \code{reactName} are only + used, if a new reaction is added to the model (if \code{id} is not in + \code{\link{react_id}(model)}, exact matching is used). +} + +\value{ + An object of class \code{\linkS4class{modelorg}}, or + \code{\linkS4class{modelorg_irrev}}, if \code{model} is of class + \code{\linkS4class{modelorg_irrev}}. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\linkS4class{modelorg}} and \code{\link{rmReact}} +} + +\keyword{manip} + diff --git a/man/addRows-methods.Rd b/man/addRows-methods.Rd new file mode 100644 index 0000000..3e94474 --- /dev/null +++ b/man/addRows-methods.Rd @@ -0,0 +1,66 @@ +\name{addRows-methods} + +\docType{methods} +\encoding{utf8} + +\alias{addRows} +\alias{addRows-methods} + +\alias{addRows,optObj_clpAPI,numeric-method} +\alias{addRows,optObj_cplexAPI,numeric-method} +\alias{addRows,optObj_glpkAPI,numeric-method} +\alias{addRows,optObj_lpSolveAPI,numeric-method} + +\title{Add Rows to an Optimization Problem} + +\description{ + Add rows to an optimization problem. +} + +\usage{ +\S4method{addRows}{optObj_clpAPI,numeric}(lp, nrows) + +\S4method{addRows}{optObj_cplexAPI,numeric}(lp, nrows) + +\S4method{addRows}{optObj_glpkAPI,numeric}(lp, nrows) + +\S4method{addRows}{optObj_lpSolveAPI,numeric}(lp, nrows) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", nrows = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", nrows = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", nrows = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", nrows = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{nrows}{ + Number of rows (constraints) to add to the problem object. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/addRowsCols-methods.Rd b/man/addRowsCols-methods.Rd new file mode 100644 index 0000000..f1c6583 --- /dev/null +++ b/man/addRowsCols-methods.Rd @@ -0,0 +1,69 @@ +\name{addRowsCols-methods} + +\docType{methods} +\encoding{utf8} + +\alias{addRowsCols} +\alias{addRowsCols-methods} + +\alias{addRowsCols,optObj_clpAPI,numeric,numeric-method} +\alias{addRowsCols,optObj_cplexAPI,numeric,numeric-method} +\alias{addRowsCols,optObj_glpkAPI,numeric,numeric-method} +\alias{addRowsCols,optObj_lpSolveAPI,numeric,numeric-method} + +\title{Add Rows and Columns to an Optimization Problem} + +\description{ + Add rows and columns to an optimization problem. +} + +\usage{ +\S4method{addRowsCols}{optObj_clpAPI,numeric,numeric}(lp, nrows, ncols) + +\S4method{addRowsCols}{optObj_cplexAPI,numeric,numeric}(lp, nrows, ncols) + +\S4method{addRowsCols}{optObj_glpkAPI,numeric,numeric}(lp, nrows, ncols) + +\S4method{addRowsCols}{optObj_lpSolveAPI,numeric,numeric}(lp, nrows, ncols) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", nrows = "numeric", ncols = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", nrows = "numeric", ncols = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", nrows = "numeric", ncols = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", nrows = "numeric", ncols = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{nrows}{ + Number of rows (constraints) to add to the problem object. + } + \item{ncols}{ + Number of columns (variables) to add to the problem object. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/addRowsToProb-methods.Rd b/man/addRowsToProb-methods.Rd new file mode 100644 index 0000000..b035e59 --- /dev/null +++ b/man/addRowsToProb-methods.Rd @@ -0,0 +1,98 @@ +\name{addRowsToProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{addRowsToProb} +\alias{addRowsToProb-methods} + +\alias{addRowsToProb,optObj_clpAPI-method} +\alias{addRowsToProb,optObj_cplexAPI-method} +\alias{addRowsToProb,optObj_glpkAPI-method} +\alias{addRowsToProb,optObj_lpSolveAPI-method} + +\title{Add New Rows (Constraints) to an Optimization Problem} + +\description{ + Add new rows (constraints) to an optimization problem. +} + +\usage{ +\S4method{addRowsToProb}{optObj_clpAPI}(lp, i, type, lb, ub, cind, nzval, rnames = NULL) + +\S4method{addRowsToProb}{optObj_cplexAPI}(lp, i, type, lb, ub, cind, nzval, rnames = NULL) + +\S4method{addRowsToProb}{optObj_glpkAPI}(lp, i, type, lb, ub, cind, nzval, rnames = NULL) + +\S4method{addRowsToProb}{optObj_lpSolveAPI}(lp, i, type, lb, ub, cind, nzval, rnames = NULL) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. Parameter \code{rnames} is + currently unused. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{i}{ + A numeric vector containing the new row indices. + } + \item{type}{ + A character vector giving the constraint type: + \code{"F"}: free constraint (\pkg{optObj_glpkAPI} only), + \code{"L"}: \code{>=} (lower bound), + \code{"U"}: \code{<=} (upper bound) or + \code{"D"}: \code{lb <= r <= ub} (double bound) or + \code{"E"}: \code{=} (equality). + If \code{type[k]} is not \code{F}, \code{"L"}, \code{"U"}, \code{"D"} or + \code{"E"}, the value of \code{type[k]} will be set to \code{"E"}. + } + \item{lb}{ + A numeric vector containing the lower bound of the new constraints. + } + \item{ub}{ + A numeric vector containing the upper bound of the new constraints. + } + \item{cind}{ + A list containing the column indices of the new non-zero elements. + } + \item{nzval}{ + A list containing the new non-zero elements. + } + \item{rnames}{ + A character vector containing names for the new rows/constraints.\cr + Default: \code{NULL}. + } +} + +\note{ + Arguments \code{i}, \code{type}, \code{lb}, \code{cind}, \code{nzval} and + \code{rnames} (if not \code{NULL}) must have the same length. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/addSolver.Rd b/man/addSolver.Rd new file mode 100644 index 0000000..c40179f --- /dev/null +++ b/man/addSolver.Rd @@ -0,0 +1,50 @@ +\name{addSolver} +\alias{addSolver} + +\title{ + Add a New Mathematical Programming Solver to sybil +} + +\description{ + Make a new mathematical programming solver available to sybil via the + \code{\link{SYBIL_SETTINGS}} command. +} + +\usage{ + addSolver(solver, method, probType) +} + +\arguments{ + \item{solver}{ + A single character string giving the name of the desiered solver. + } + \item{method}{ + A character vector of algorithms supported by the solver given in + \code{solver}. + } + \item{probType}{ + A list of hte same length as \code{method} containing a vector of character + strings for each method which types of problems can be solved with that + method: \code{method[i]} of \code{solver} can solve problems of type + \code{probType[[i]]}. Problem types could be \code{"lp"}: linear + programming, \code{"mip"}: mixed integer programming or \code{"qp"}: + quadratic programming. + } +} + +\details{ + The parameters to the algorithms given in \code{method} are set to \code{NA}, + which means, the default parameters of the solver software will be used. If a + solver already exists, an error message will be given. +} + +\value{ + The function returns \code{NULL} invisibly. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{SYBIL_SETTINGS}} +} + diff --git a/man/applyChanges-methods.Rd b/man/applyChanges-methods.Rd new file mode 100644 index 0000000..d5b3e9b --- /dev/null +++ b/man/applyChanges-methods.Rd @@ -0,0 +1,141 @@ +\name{applyChanges-methods} + +\docType{methods} +\encoding{utf8} + +\alias{applyChanges} +\alias{applyChanges-methods} +\alias{applyChanges,sysBiolAlg-method} +\alias{applyChanges,sysBiolAlg_room-method} + +\title{Generic Function to Apply Changes to Objects of Class sysBiolAlg} + +\description{ + Use method \code{applyChanges} to apply changes in objects of class + \code{\linkS4class{sysBiolAlg}}. Changes can be coefficients of the objective + function, variable bounds or the optimization direction. +} + +\usage{ +\S4method{applyChanges}{sysBiolAlg}(object, del, obj, ld, + react = NULL, + lb = NULL, + ub = NULL, + obj_coef = NULL, + fldind = TRUE, + lpdir = NULL) + +\S4method{applyChanges}{sysBiolAlg_room}(object, del, obj, ld, + react = NULL, + lb = NULL, + ub = NULL, + obj_coef = NULL, + fldind = TRUE, + lpdir = NULL) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "sysBiolAlg")}}{ + Method used with objects extending class \code{\linkS4class{sysBiolAlg}} + } + \item{\code{signature(object = "sysBiolAlg_room")}}{ + Method used with objects of class \code{\linkS4class{sysBiolAlg_room}} + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{sysBiolAlg}}. + } + \item{del}{ + A logical value indicating whether variable bounds should be altered or not. + } + \item{obj}{ + A logical value indicating whether objective coefficients should be altered + or not. + } + \item{ld}{ + A logical value indicating whether the direction of optimization should be + altered or not. + } + \item{react}{ + A numeric vector containing indices to reactions which should be changed + (in terms of variable bounds or objective coefficients).\cr + Default: \code{NULL}. + } + \item{lb}{ + Numeric vector of the same length as \code{react}, containing the new lower + variable bounds.\cr + Default: \code{NULL}. + } + \item{ub}{ + Numeric vector of the same length as \code{react}, containing the new upper + variable bounds.\cr + Default: \code{NULL}. + } + \item{obj_coef}{ + Numeric vector of the same length as \code{react}, containing the new + objective coefficients.\cr + Default: \code{NULL}. + } + \item{fldind}{ + Boolean value. If set to \code{TRUE}, (default) indices in \code{"react"} are used + only for reactions. If set to \code{FALSE}, indices in \code{"react"} are used for + all variables during optimization, e.g. also for additional variables introduced by + the \code{\link{mtf}} algorithm. Currently unused by class + \code{\linkS4class{sysBiolAlg_room}}.\cr + Default: \code{TRUE}. + } + \item{lpdir}{ + A single character value indicating the new direction of optimization.\cr + Default: \code{NULL}. + } +} + +\value{ + Returns a list containing the original values in order to undo the changes + with \code{\link{resetChanges}}: + \item{fi}{ + A numeric vector containing variable id's to apply changes to. + } + \item{lb}{ + A numeric vector of the same length as \code{react} containing the original + variable lower bounds. + } + \item{ub}{ + A numeric vector of the same length as \code{react} containing the original + variable upper bounds. + } + \item{obj_coef}{ + A numeric vector of the same length as \code{react} containing the original + objective coefficients. + } + \item{lpdir}{ + A single character value giving the original optimization direction. + } + \item{ri}{ + A numeric vector of the same length as \code{react} containing row indices + of the stoichiometric matrix required to apply changes in variable bounds + when algorithm \code{"room"} is used. + (only used by the \code{\linkS4class{sysBiolAlg_room}} method). + } + \item{ci}{ + A numeric vector of the same length as \code{react} containing column + indices of the stoichiometric matrix required to apply changes in variable + bounds when algorithm \code{"room"} is used. + (only used by the \code{\linkS4class{sysBiolAlg_room}} method). + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{sysBiolAlg}} and \code{\link{resetChanges}} +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/backupProb-methods.Rd b/man/backupProb-methods.Rd new file mode 100644 index 0000000..25f163f --- /dev/null +++ b/man/backupProb-methods.Rd @@ -0,0 +1,71 @@ +\name{backupProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{backupProb} +\alias{backupProb-methods} + +\alias{backupProb,optObj_clpAPI-method} +\alias{backupProb,optObj_cplexAPI-method} +\alias{backupProb,optObj_glpkAPI-method} +\alias{backupProb,optObj_lpSolveAPI-method} + +\title{Copies a Problem Object to a New Problem Object} + +\description{ + Copies a problem object into a new problem object. +} + +\usage{ +\S4method{backupProb}{optObj_clpAPI}(lp) + +\S4method{backupProb}{optObj_cplexAPI}(lp) + +\S4method{backupProb}{optObj_glpkAPI}(lp) + +\S4method{backupProb}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. The new problem object + will be in the same CPLEX environment like the original one. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. Building a new problem + object will reset all parameters to their default. After backing up, set + all parameters which are not at their default values again. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + An object of the same class as given in argument \code{lp} (extending class + \code{\linkS4class{optObj}}). +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/blockedReact.Rd b/man/blockedReact.Rd new file mode 100644 index 0000000..6f9a972 --- /dev/null +++ b/man/blockedReact.Rd @@ -0,0 +1,86 @@ +\name{blockedReact} + +\alias{blockedReact} + +\title{ + Find Blocked Reactions in a Metabolic Network +} + +\description{ + A blocked Reaction in a metabolic network can not be used by the network, + given the stiochiometric matrix of the network and a set of input and output + fluxes. +} + +\usage{ + blockedReact(model, + tol = SYBIL_SETTINGS("TOLERANCE"), + exex = TRUE, + fld = FALSE, + retOptSol = FALSE, + verboseMode = 2, + ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\link{modelorg}}. + } + \item{tol}{ + Tolerance value.\cr + Default: \code{SYBIL_SETTINGS("TOLERANCE")}. + } + \item{exex}{ + Boolean, if set to \code{TRUE}, exchange reactions found by + \code{\link{findExchReact}} are excluded from the analysis.\cr + Default: \code{TRUE}. + } + \item{fld}{ + Boolean. Save the resulting flux distributions.\cr + Default: \code{FALSE} + } + \item{retOptSol}{ + Boolean. Return an object of class + \code{\linkS4class{optsol_blockedReact}} or + just a list containing the results.\cr + Default: \code{FALSE}. + } + \item{verboseMode}{ + An integer value indicating the amount of output to stdout: + 0: nothing, 1: status messages, 2: like 1 plus a progress indicator.\cr + Default: \code{2}. + } + \item{\dots}{ + Further arguments passed to \code{\linkS4class{sysBiolAlg}}. + Argument \code{solverParm} is a good candidate. + } +} + +\details{ + A reaction \eqn{i} is considered to be \sQuote{blocked}, if its calculated + reaction rate \eqn{v_i}{v[i]} is + \eqn{-\mathrm{tol} < v_i < \mathrm{tol}}{-tol < v[i] < tol}. + Reaction rates are calculated via linear optimization: maximizing and + minimizing each reaction rate. If the difference of the maximum and the + minimum is not larger than \code{tol}, that particular reaction is blocked, + given the current side conditions (exchange fluxes). +} + +\value{ + If argument \code{retOptsol} is set to \code{TRUE}, an object of class + \code{\linkS4class{optsol_blockedReact}} is returned, otherwise a logical + vector with length equal to the number of reactions of the network. If element + \code{i} equals \code{TRUE}, reaction \code{i} is blocked. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{modelorg}}, + \code{\linkS4class{optsol_blockedReact}} and + \code{\link{SYBIL_SETTINGS}}. +} + +\keyword{optimize} diff --git a/man/changeBounds.Rd b/man/changeBounds.Rd new file mode 100644 index 0000000..58d4d44 --- /dev/null +++ b/man/changeBounds.Rd @@ -0,0 +1,65 @@ +\name{changeBounds} +\alias{changeBounds} + +\encoding{utf8} + +\title{ + Change Variable Bounds in a Metabolic Network +} + +\description{ + The function changes the upper and/or lower bounds of a given metabolic + network model to new values. +} + +\usage{ + changeBounds(model, react, lb = NULL, ub = NULL) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{react}{ + An object of class \code{\linkS4class{reactId}}, character or integer. + Specifies the fluxes (variables) for which to change the upper and/or lower + bounds. + } + \item{lb}{ + Numeric vector giving the lower bounds for the fluxes mentioned in + \code{react}. If missing, lower bounds are set to zero. If \code{lb} has + a length of 1, the value of \code{lb} will be used for all reactions in + \code{react}. + } + \item{ub}{ + Numeric vector giving the upper bounds for the fluxes mentioned in + \code{react}. If missing, upper bounds are set to zero. If \code{ub} has + a length of 1, the value of \code{ub} will be used for all reactions in + \code{react}. + } +} + +\details{ + The argument \code{react} will be evaluated by the function + \code{\link{checkReactId}}. +} + +\value{ + Returns the given model (an object of the same class as the argument + \code{lpmodel}) containing the new objective function. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{\code{\link{checkReactId}}} + +\examples{ + ## change the E.coli core model to lactate input: + data(Ec_core) + Ec_new <- changeBounds(Ec_core, + c("EX_glc", "EX_lac"), + lb = c(0, -20), ub = 1000) +} + +\keyword{optimize} + diff --git a/man/changeColsBnds-methods.Rd b/man/changeColsBnds-methods.Rd new file mode 100644 index 0000000..ffae5ab --- /dev/null +++ b/man/changeColsBnds-methods.Rd @@ -0,0 +1,74 @@ +\name{changeColsBnds-methods} + +\docType{methods} +\encoding{utf8} + +\alias{changeColsBnds} +\alias{changeColsBnds-methods} + +\alias{changeColsBnds,optObj_clpAPI-method} +\alias{changeColsBnds,optObj_cplexAPI-method} +\alias{changeColsBnds,optObj_glpkAPI-method} +\alias{changeColsBnds,optObj_lpSolveAPI-method} + +\title{Change Column (Variable) Bounds in the Optimization Problem} + +\description{ + Change column (variable) bounds in the optimization problem. +} + +\usage{ +\S4method{changeColsBnds}{optObj_clpAPI}(lp, j, lb, ub) + +\S4method{changeColsBnds}{optObj_cplexAPI}(lp, j, lb, ub) + +\S4method{changeColsBnds}{optObj_glpkAPI}(lp, j, lb, ub) + +\S4method{changeColsBnds}{optObj_lpSolveAPI}(lp, j, lb, ub) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the column indices of the variables to change. + } + \item{lb}{ + A numeric vector of the same length as \code{j} containing the lower bounds + of the variables to change. + } + \item{ub}{ + A numeric vector of the same length as \code{j} containing the upper bounds + of the variables to change. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/changeColsBndsObjCoefs-methods.Rd b/man/changeColsBndsObjCoefs-methods.Rd new file mode 100644 index 0000000..2b42142 --- /dev/null +++ b/man/changeColsBndsObjCoefs-methods.Rd @@ -0,0 +1,82 @@ +\name{changeColsBndsObjCoefs-methods} + +\docType{methods} +\encoding{utf8} + +\alias{changeColsBndsObjCoefs} +\alias{changeColsBndsObjCoefs-methods} + +\alias{changeColsBndsObjCoefs,optObj_clpAPI-method} +\alias{changeColsBndsObjCoefs,optObj_cplexAPI-method} +\alias{changeColsBndsObjCoefs,optObj_glpkAPI-method} +\alias{changeColsBndsObjCoefs,optObj_lpSolveAPI-method} + +\title{ + Change Column (Variable) Bounds and Objective Coefficients in the + Optimization Problem +} + +\description{ + Change column (variable) bounds and objective coefficients in the + optimization problem. +} + +\usage{ +\S4method{changeColsBndsObjCoefs}{optObj_clpAPI}(lp, j, lb, ub, obj_coef) + +\S4method{changeColsBndsObjCoefs}{optObj_cplexAPI}(lp, j, lb, ub, obj_coef) + +\S4method{changeColsBndsObjCoefs}{optObj_glpkAPI}(lp, j, lb, ub, obj_coef) + +\S4method{changeColsBndsObjCoefs}{optObj_lpSolveAPI}(lp, j, lb, ub, obj_coef) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the column indices of the variables to change. + } + \item{lb}{ + A numeric vector of the same length as \code{j} containing the lower bounds + of the variables to change. + } + \item{ub}{ + A numeric vector of the same length as \code{j} containing the upper bounds + of the variables to change. + } + \item{obj_coef}{ + A numeric vector of the same length as \code{j} containing the objective + coefficients of the variables to change. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/changeGPR.Rd b/man/changeGPR.Rd new file mode 100644 index 0000000..cf5eb14 --- /dev/null +++ b/man/changeGPR.Rd @@ -0,0 +1,32 @@ +\name{changeGPR} +\alias{changeGPR} + +\encoding{utf8} + +\title{Check and Change the GPR Rules} + +\description{ + Checks and Changes the GPR Rules for the chosen reactions +} +\usage{ + changeGPR(model, react, gprRules = "logicalExpression", verboseMode = 1) +} + +\arguments{ + \item{model}{An object of class \code{\linkS4class{modelorg}}} + \item{react}{An object of class \code{\linkS4class{reactId}}, a + numeric vector, or a character vector containing reaction id's.} + \item{gprRules}{character: contains logical expressions.} + \item{verboseMode}{integer: verbosity level.} +} + + +\details{ + The function changes the expressions for the chosen reactions. + + The function stops if any logic expressions is not correct. + Then the changes are executed. +} + +\author{Benjamin Braasch} + diff --git a/man/changeMatrixRow-methods.Rd b/man/changeMatrixRow-methods.Rd new file mode 100644 index 0000000..d3d3be1 --- /dev/null +++ b/man/changeMatrixRow-methods.Rd @@ -0,0 +1,71 @@ +\name{changeMatrixRow-methods} + +\docType{methods} +\encoding{utf8} + +\alias{changeMatrixRow} +\alias{changeMatrixRow-methods} + +\alias{changeMatrixRow,optObj_cplexAPI-method} +\alias{changeMatrixRow,optObj_glpkAPI-method} +\alias{changeMatrixRow,optObj_lpSolveAPI-method} + +\title{Change a Row in the Constraint Matrix of the Optimization Problem} + +\description{ + Change a row in the constraint matrix of the optimization problem. +} + +\usage{ +\S4method{changeMatrixRow}{optObj_cplexAPI}(lp, i, j, val) + +\S4method{changeMatrixRow}{optObj_glpkAPI}(lp, i, j, val) + +\S4method{changeMatrixRow}{optObj_lpSolveAPI}(lp, i, j, val) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. Only the columns given + in argument \code{j} will be changed. All other columns stay the same. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. The row given in argument + \code{i} will be reset completely. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. The row given in + argument \code{i} will be reset completely. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{i}{ + A single numeric value giving the row index of the constraint matrix to + change. + } + \item{j}{ + A numeric vector containing the column indices of the new non-zero elements. + } + \item{val}{ + A numeric vector of the same length as \code{j} containing the new non-zero + elements. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/changeObjCoefs-methods.Rd b/man/changeObjCoefs-methods.Rd new file mode 100644 index 0000000..eaeff40 --- /dev/null +++ b/man/changeObjCoefs-methods.Rd @@ -0,0 +1,72 @@ +\name{changeObjCoefs-methods} + +\docType{methods} +\encoding{utf8} + +\alias{changeObjCoefs} +\alias{changeObjCoefs-methods} + +\alias{changeObjCoefs,optObj_clpAPI-method} +\alias{changeObjCoefs,optObj_cplexAPI-method} +\alias{changeObjCoefs,optObj_glpkAPI-method} +\alias{changeObjCoefs,optObj_lpSolveAPI-method} + +\title{ + Change Column (Variable) Objective Coefficients in the Optimization Problem +} + +\description{ + Change column (variable) objective coefficients in the optimization problem. +} + +\usage{ +\S4method{changeObjCoefs}{optObj_clpAPI}(lp, j, obj_coef) + +\S4method{changeObjCoefs}{optObj_cplexAPI}(lp, j, obj_coef) + +\S4method{changeObjCoefs}{optObj_glpkAPI}(lp, j, obj_coef) + +\S4method{changeObjCoefs}{optObj_lpSolveAPI}(lp, j, obj_coef) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the column indices of the variables to change. + } + \item{obj_coef}{ + A numeric vector of the same length as \code{j} containing the objective + coefficients of the variables to change. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/changeObjFunc.Rd b/man/changeObjFunc.Rd new file mode 100644 index 0000000..54e2945 --- /dev/null +++ b/man/changeObjFunc.Rd @@ -0,0 +1,57 @@ +\name{changeObjFunc} + +\alias{changeObjFunc} + +\encoding{utf8} + +\title{Sets/changes the Objective Function} + +\description{ + The function \code{changeObjFunc} changes or sets the objective + function for a specified model. +} + +\usage{ + changeObjFunc(model, react, obj_coef = rep(1, length(react))) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{react}{ + An object of class \code{\linkS4class{reactId}}, character or integer. + Specifies the fluxes (variables) for which to change the objective + coefficients. + } + \item{obj_coef}{ + A numerical vector with length equal to the number of reaction id's + given in argument \code{react} containing the objective coefficients.\cr + Default: a value of one for each reaction given in argument \code{react}. + } +} + +\details{ + The argument \code{react} will be evaluated by the function + \code{\link{checkReactId}}. The return value is used to change + the objective function. + + All reactions not given in argument \code{react} will get an objective + value of zero. +} + +\value{ + Returns the given model containing the new objective function. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{\code{\link{checkReactId}}} + +\examples{ + ## sets the objective function to the ATP maintenance reaction: + data(Ec_core) + Ec_new <- changeObjFunc(Ec_core, "ATPM") +} + +\keyword{optimize} diff --git a/man/changeRowsBnds-methods.Rd b/man/changeRowsBnds-methods.Rd new file mode 100644 index 0000000..178814b --- /dev/null +++ b/man/changeRowsBnds-methods.Rd @@ -0,0 +1,78 @@ +\name{changeRowsBnds-methods} + +\docType{methods} +\encoding{utf8} + +\alias{changeRowsBnds} +\alias{changeRowsBnds-methods} + +\alias{changeRowsBnds,optObj_clpAPI-method} +\alias{changeRowsBnds,optObj_cplexAPI-method} +\alias{changeRowsBnds,optObj_glpkAPI-method} +\alias{changeRowsBnds,optObj_lpSolveAPI-method} + +\title{Change Row Bounds in the Optimization Problem} + +\description{ + Change row bounds in the optimization problem. +} + +\usage{ +\S4method{changeRowsBnds}{optObj_clpAPI}(lp, i, lb, ub) + +\S4method{changeRowsBnds}{optObj_cplexAPI}(lp, i, lb, ub) + +\S4method{changeRowsBnds}{optObj_glpkAPI}(lp, i, lb, ub) + +\S4method{changeRowsBnds}{optObj_lpSolveAPI}(lp, i, lb, ub) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{i}{ + A numeric vector containing the row indices of the constraints to change. + } + \item{lb}{ + A numeric vector of the same length as \code{i} containing the lower bounds + of the constraints to change. + } + \item{ub}{ + A numeric vector of the same length as \code{i} containing the upper bounds + of the constraints to change. + } +} + +\note{ + Changing row bounds does not change the constraint type. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/changeUptake-methods.Rd b/man/changeUptake-methods.Rd new file mode 100644 index 0000000..24d29ea --- /dev/null +++ b/man/changeUptake-methods.Rd @@ -0,0 +1,69 @@ +\name{changeUptake-methods} + +\docType{methods} +\encoding{utf8} + +\alias{changeUptake} +\alias{changeUptake-methods} +\alias{changeUptake,modelorg-method} + +\title{Change Uptake Reactions} + +\description{ + Switch uptake reactions in metabolic networks on and off. +} + +\usage{ +\S4method{changeUptake}{modelorg}(object, off = NULL, on = NULL, + rate = SYBIL_SETTINGS("MAXIMUM") * -1) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "modelorg")}}{ + method to use with objects of class \code{\linkS4class{modelorg}}. + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{off}{ + A numeric or character vector or an object of class + \code{\linkS4class{reactId_Exch}} containing the metabolite id's of + metabolites to not use for uptake. If they have an exchange reaction with + a lower bound less than zero, this lower bound is set to \code{0}. + If \code{off} is set to \code{NULL}, all uptake reactions will be + deactivated. If \code{off} is set to \code{FALSE}, no uptake reaction will + be deactivated. If you just want to add an uptake reaction, set \code{off} + to \code{FALSE}.\cr + Default: \code{NULL}. + } + \item{on}{ + A numeric or character vector or an object of class + \code{\linkS4class{reactId_Exch}} containing the metabolite id's of + metabolites to use for uptake.\cr + Default: \code{NULL}. + } + \item{rate}{ + A numeric vector containing the uptake rates for metabolites given in + \code{on}.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM") * -1}. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\value{ + An object of class \code{\linkS4class{modelorg}}. +} + +\seealso{ + Class \code{\linkS4class{modelorg}} +} + +\keyword{methods} diff --git a/man/checkAkgorithm.Rd b/man/checkAkgorithm.Rd new file mode 100644 index 0000000..0b450c1 --- /dev/null +++ b/man/checkAkgorithm.Rd @@ -0,0 +1,36 @@ +\name{checkAlgorithm} +\alias{checkAlgorithm} + +\title{ + Check Algorithm +} + +\description{ + Test, if a given algorithm can has a certain purpose. +} + +\usage{ + checkAlgorithm(alg, purpose) +} + +\arguments{ + \item{alg}{ + A single character string containing the name of the algorithm. + } + \item{purpose}{ + Purpose of the new algorithm. + } +} + +\value{ + Returns \code{TRUE} if successful, otherwise \code{FALSE}. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{addAlgorithm}}, \code{\link{getsybilenv}} +} + diff --git a/man/checkDefaultMethod.Rd b/man/checkDefaultMethod.Rd new file mode 100644 index 0000000..9ccae53 --- /dev/null +++ b/man/checkDefaultMethod.Rd @@ -0,0 +1,76 @@ +\name{checkDefaultMethod} +\alias{checkDefaultMethod} + +\encoding{utf8} + +\title{ + Validate Solver and Method +} + +\description{ + The function \code{checkDefaultMethod} returns the default method + for a desired solver, or a default solver -- method pair. A \dQuote{solver} + is always the name of a R package offering facilities for solving + optimization problems. +} + +\usage{ + checkDefaultMethod(solver, method, probType, loadPackage = TRUE) +} + +\arguments{ + \item{solver}{ + A single character string, containing the solver name (must be identical to + the name of an R-package), see \code{\link{SYBIL_SETTINGS}}. + } + \item{method}{ + A single character string, containing the method name, see + \code{\link{SYBIL_SETTINGS}}. + } + \item{probType}{ + A single character string, containing the problem type, see + \code{\link{optObj}}. + } + \item{loadPackage}{ + A single Boolean value. If set to \code{TRUE}, load the given solver + package via \code{\link{require}}. + } +} + +\details{ + In order to run simulations (optimizations) with sybil, additional software + offering facilities for solving optimization problems is required. Supported + R packages are described in \code{\link{SYBIL_SETTINGS}}. + At first, the function checks if argument \code{solver} contains a valid + solver. If that is not the case, a corresponding library will be loaded, if + one exists (this library must have the same name as given in \code{solver}). + If this failes too, the default solver will be returned + (see \code{\link{SYBIL_SETTINGS}}). Next the same is done for the argument + \code{method}, regarding the current value of \code{solver}. + Additionally, it will be checked, wether or not the given problem type can be + solved using the given method and solver. +} + +\value{ + \item{sol}{Validated solver name.} + \item{met}{Validated method name.} + \item{parm}{Default prarmeter set for the validated method.} +} + +\note{ + Arguments \code{"glpk"}, \code{"cplex"} and \code{"clp"} not used anymore; + valid arguments must be the name of the desired solver package like + \code{"glpkAPI"}, \code{"cplexAPI"} and \code{"cplAPI"}. +} + +\author{ + Gabriel Gelius-Dietrich + + Maintainer: Gabriel Gelius-Dietrich <geliudie@uni-duesseldorf.de> +} + +\seealso{ + \code{\link{SYBIL_SETTINGS}} and \code{\link{getsybilenv}} +} + +\keyword{ optimize } diff --git a/man/checkOptSol-methods.Rd b/man/checkOptSol-methods.Rd new file mode 100644 index 0000000..2163730 --- /dev/null +++ b/man/checkOptSol-methods.Rd @@ -0,0 +1,70 @@ +\name{checkOptSol-methods} + +\docType{methods} +\encoding{utf8} + +\alias{checkOptSol} +\alias{checkOptSol-methods} +\alias{checkOptSol,optsol-method} + +\title{Summarized Information About an Object of Class Optsol} + +\description{ + The function \code{checkOptSol} evaluates the results of the solution + of optimizations; the returned objects e.g. from \code{\link{optimizeProb}}. +} + +\usage{ +\S4method{checkOptSol}{optsol}(opt, onlywarn = FALSE) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(opt = "optsol")}}{ + method to use with objects of class \code{\linkS4class{optsol}}. + } + } +} + +\arguments{ + \item{opt}{ + An object of class \code{\linkS4class{optsol}}. + } + \item{onlywarn}{ + A single Boolean value. If set to \code{TRUE}, the method will check, + if all optimizations ended successfully.\cr + Default: \code{FALSE}. + } +} + +\details{ + The function \code{checkOptSol} is used by functions performing a + linear optimization (e.g. \code{\link{optimizeProb}}). In that case, the + argument \code{onlywarn} is set to TRUE. If the optimization ends + unsuccesfull, a warning will be produced. + + It is also possible to use the function directly, with \code{onlywarn} + set to FALSE (the default). In that case, an object of class + \code{\linkS4class{checksol}} will be retuned. This object contains a summary + with the exit status of the optimization. +} + +\value{ + TRUE or FALSE if \code{onlywarn} is set to TRUE, otherwisw an object of class + \code{\linkS4class{checksol}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\linkS4class{checksol}}, + \code{\link{optimizeProb}} and \code{\link{oneGeneDel}} +} + +\examples{ + data(Ec_core) + Ec_f <- optimizeProb(Ec_core, retOptSol = TRUE) + Ec_check <- checkOptSol(Ec_f) +} + +\keyword{optimize} diff --git a/man/checkReactId.Rd b/man/checkReactId.Rd new file mode 100644 index 0000000..42efec4 --- /dev/null +++ b/man/checkReactId.Rd @@ -0,0 +1,58 @@ +\name{checkReactId} + +\alias{checkReactId} + +\encoding{utf8} + +\title{Check if a Reaction Id is Valid} + +\description{ + The function \code{checkReactId} evaluates a vector of reaction id's + if they are unique and appear in a given model. +} + +\usage{ + checkReactId(model, react) +} + +\arguments{ + \item{model}{A model. An object of class + \code{\linkS4class{modelorg}}, or a problem object of a lp solver.} + \item{react}{Character vector containing reaction id's, or a numerical + vector containing indices of reaction id's.} +} + +\details{ + If argument \code{react} is numeric, the maximun value will be + inspected, if it is larger than the number of reactions in the model. + + In case of a character vector, \code{react} is matched to the reaction + id's residing in the model. If they are not found, grep is used. + + If argument \code{react} is of class \code{\linkS4class{reactId}}, it will + be returned without checking. +} + +\value{ + An object of class \code{\linkS4class{reactId}} or \code{NULL} if argument + \code{react} contains any reactions not in \code{model}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{\code{\linkS4class{reactId}}} + +\examples{ + data(Ec_core) + + ## Example with react as character vector + ids <- c("ATPM", "ACK") + idc <- checkReactId(Ec_core, ids) + + ## Example with react as numerical vector + ids <- c(1:4) + idc <- checkReactId(Ec_core, ids) +} + +\keyword{character} + diff --git a/man/checksol-class.Rd b/man/checksol-class.Rd new file mode 100644 index 0000000..e8c8b32 --- /dev/null +++ b/man/checksol-class.Rd @@ -0,0 +1,133 @@ +\name{checksol-class} + +\docType{class} + +\alias{checksol-class} +\alias{checksol} + +\alias{exit_code<-,checksol-method} +\alias{exit_code,checksol-method} +\alias{exit_code<-} +\alias{exit_code} +\alias{exit_meaning<-,checksol-method} +\alias{exit_meaning,checksol-method} +\alias{exit_meaning<-} +\alias{exit_meaning} +\alias{exit_num<-,checksol-method} +\alias{exit_num,checksol-method} +\alias{exit_num<-} +\alias{exit_num} +\alias{num_of_prob<-,checksol-method} +\alias{num_of_prob,checksol-method} +\alias{show,checksol-method} +\alias{status_code<-,checksol-method} +\alias{status_code,checksol-method} +\alias{status_code<-} +\alias{status_code} +\alias{status_meaning<-,checksol-method} +\alias{status_meaning,checksol-method} +\alias{status_meaning<-} +\alias{status_meaning} +\alias{status_num<-,checksol-method} +\alias{status_num,checksol-method} +\alias{status_num<-} +\alias{status_num} + +\encoding{utf8} + +\title{Structure of the Class "checksol"} + +\description{ + Structure of the class \code{"checksol"}. Objects of that class are + returned by the function \code{\link{checkOptSol}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form \code{new("checksol")}. +} + +\section{Slots}{ + \describe{ + \item{\code{exit_code}:}{Object of class \code{"integer"} + containing the exit code of the lp solver. + } + \item{\code{exit_num}:}{Object of class \code{"integer"} + containing the number of appearance of a specific exit code. + } + \item{\code{exit_meaning}:}{Object of class \code{"character"} + containing the meaning of the exit code. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{status_code}:}{Object of class \code{"integer"} + containing the solution status of the lp problem. + } + \item{\code{status_num}:}{Object of class \code{"integer"} + containing the number of appearance of a specific solution status. + } + \item{\code{status_meaning}:}{Object of class \code{"character"} + containing the meaning of the solution status. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{exit_code<-}:}{\code{signature(object = "checksol")}: + sets the \code{exit_code} slot. + } + \item{\code{exit_code}:}{\code{signature(object = "checksol")}: + gets the \code{exit_code} slot. + } + \item{\code{exit_meaning<-}:}{\code{signature(object = "checksol")}: + sets the \code{exit_meaning} slot. + } + \item{\code{exit_meaning}:}{\code{signature(object = "checksol")}: + gets the \code{exit_meaning} slot. + } + \item{\code{exit_num<-}:}{\code{signature(object = "checksol")}: + sets the \code{exit_num} slot. + } + \item{\code{exit_num}:}{\code{signature(object = "checksol")}: + gets the \code{exit_num} slot. + } + \item{\code{num_of_prob<-}:}{\code{signature(object = "optsol")}: + sets the \code{num_of_prob} slot. + } + \item{\code{num_of_prob}:}{\code{signature(object = "optsol")}: + gets the \code{num_of_prob} slot. + } + \item{\code{show}:}{\code{signature(object = "checksol")}: + prints some details specific to the instance of class \code{checksol}. + } + \item{\code{status_code<-}:}{\code{signature(object = "checksol")}: + sets the \code{status_code} slot. + } + \item{\code{status_code}:}{\code{signature(object = "checksol")}: + gets the \code{status_code} slot. + } + \item{\code{status_meaning<-}:}{\code{signature(object = "checksol")}: + sets the \code{status_meaning} slot. + } + \item{\code{status_meaning}:}{\code{signature(object = "checksol")}: + gets the \code{status_meaning} slot. + } + \item{\code{status_num<-}:}{\code{signature(object = "checksol")}: + sets the \code{status_num} slot. + } + \item{\code{status_num}:}{\code{signature(object = "checksol")}: + gets the \code{status_num} slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{\code{\link{checkOptSol}}} + +\examples{ + showClass("checksol") +} + +\keyword{classes} diff --git a/man/deadEndMetabolites-methods.Rd b/man/deadEndMetabolites-methods.Rd new file mode 100644 index 0000000..483a9b1 --- /dev/null +++ b/man/deadEndMetabolites-methods.Rd @@ -0,0 +1,54 @@ +\name{deadEndMetabolites-methods} + +\docType{methods} +\encoding{utf8} + +\alias{deadEndMetabolites} +\alias{deadEndMetabolites-methods} +\alias{deadEndMetabolites,modelorg-method} + +\title{Identify Dead End Metabolites} + +\description{ + Search a metabolic network for metabolites, which are produced, but not + consumed and vice versa. +} + +\usage{ +\S4method{deadEndMetabolites}{modelorg}(object,retIds) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "modelorg")}}{ + method to use with class \code{\linkS4class{modelorg}}. + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{retIds}{ + Boolean. If set to \code{TRUE}, a list containing metabolite id's will be + returned, otherwise a list of logical vectors.\cr + Default: \code{TRUE}. + } +} + +\value{ + A list will be returned: + \item{dem}{dead end metabolites} + \item{der}{reactions containing dead end metabolites} +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{modelorg}} and \code{\link{readTSVmod}}. +} + +\keyword{methods} diff --git a/man/delProb-methods.Rd b/man/delProb-methods.Rd new file mode 100644 index 0000000..0ca6be1 --- /dev/null +++ b/man/delProb-methods.Rd @@ -0,0 +1,72 @@ +\name{delProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{delProb} +\alias{delProb-methods} + +\alias{delProb,optObj_clpAPI-method} +\alias{delProb,optObj_cplexAPI-method} +\alias{delProb,optObj_glpkAPI-method} +\alias{delProb,optObj_lpSolveAPI-method} + +\title{Free Memory Associated to the Pointer to the Problem Object} + +\description{ + Delete (free) memory associated to the pointer to the problem object. +} + +\usage{ +\S4method{delProb}{optObj_clpAPI}(lp, ...) + +\S4method{delProb}{optObj_cplexAPI}(lp, closeEnv = TRUE) + +\S4method{delProb}{optObj_glpkAPI}(lp, ...) + +\S4method{delProb}{optObj_lpSolveAPI}(lp, ...) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{closeEnv}{ + A Boolean value. If set to \code{TRUE}, the CPLEX environment associated + with the problem object will be closed also. Otherwise not.\cr + Default: \code{TRUE}. + } + \item{...}{ + Further arguments passed to the deletion function of the solver + package. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/deprecated.Rd b/man/deprecated.Rd new file mode 100644 index 0000000..7c707ae --- /dev/null +++ b/man/deprecated.Rd @@ -0,0 +1,28 @@ +\name{sybil-deprecated} +\alias{sybil-deprecated} + +\encoding{utf8} + +\title{ + Deprecated Functions and Methods in Package \code{sybil} +} + +\description{ + These functions and methods will be defunct in the next release. +} + + +\details{ + \itemize{ + \item Function \code{\link{blockedReact}} + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{Deprecated}} +} + diff --git a/man/doubleFluxDel.Rd b/man/doubleFluxDel.Rd new file mode 100644 index 0000000..419cd37 --- /dev/null +++ b/man/doubleFluxDel.Rd @@ -0,0 +1,99 @@ +\name{doubleFluxDel} +\alias{doubleFluxDel} + +\encoding{utf8} + +\title{Double Flux Deletion Experiment} + +\description{ + Double reaction (flux) deletion analysis. +} + +\usage{ + doubleFluxDel(model, react1, react2, lb = NULL, ub = NULL, + allComb = FALSE, exex = FALSE, checkOptSolObj = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{react1}{ + An object of class \code{\linkS4class{reactId}} or character or integer + containing reaction id's to constrain to zero.\cr + Default: \code{react_id(model)}. + } + \item{react2}{ + An object of class \code{\linkS4class{reactId}} or character or integer + containing reaction id's to constrain to zero.\cr + Default: \code{react_id(model)}. + } + \item{lb}{ + A numeric vector containing the lower bounds for the reaction rates of + reactions (variables) given in arguments \code{react1} and \code{react2}. + If set to \code{NULL}, all reactions will be constrained to zero.\cr + Default: \code{NULL}. + } + \item{ub}{ + A numeric vector containing the upper bounds for the reaction rates of + reactions (variables) given in arguments \code{react1} and \code{react2}. + If set to \code{NULL}, all reactions will be constrained to zero.\cr + Default: \code{NULL}. + } + \item{allComb}{ + A single Boolean value. If set to \code{TRUE}, every possible pairwise + combination of reactions given in arguments \code{react1} and \code{react2} + will be constrained to zero flux. If set to \code{FALSE}, arguments + \code{react1} and \code{react2} must have the same length. The deletions + will be computed pair-wise: first \code{react1[1]} and \code{react2[1]}, + second \code{react1[2]} and \code{react2[2]} and so on.\cr + Default: \code{FALSE}. + } + \item{exex}{ + A single Boolean value. If set to \code{TRUE}, exchange reactions will be + excluded from the analysis. They are identified by the function + \code{\link{findExchReact}}. + Default: \code{FALSE}. + } + \item{checkOptSolObj}{ + A single logical value. If set to \code{TRUE}, a warning will be generated, + if not all optimizations ended successful.\cr + Default: \code{FALSE}. + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. Important ones are + \code{algorithm} in order to set the algorithm to use or \code{solverParm} + in order to set parameter values for the optimization software. + } +} + +\details{ + The function \code{doubleFluxDel} studies the effect of double flux deletions + on the phenotype of the metabolic network. The function performs \eqn{n} + optimizations with \eqn{n} being either the number of reaction id's in + argument \code{react1} times the number of reaction id's in argument + \code{react2}, if argument \code{allComb} is set to \code{TRUE}, or the length + of one of these vectors if argument \code{allComb} is set to \code{FALSE}. + Each optimization corresponds to the simultaneous deletion of two fluxes. +} + +\value{ + An object of class \code{\linkS4class{optsol_fluxdel}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{modelorg}}, \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_fluxdel}}, + \code{\link{checkOptSol}}, \code{\link{optimizer}} and + \code{\link{SYBIL_SETTINGS}}. +} + +\examples{ + data(Ec_core) + Ec_dfd <- doubleFluxDel(Ec_core) +} + +\keyword{optimize} + diff --git a/man/doubleGeneDel.Rd b/man/doubleGeneDel.Rd new file mode 100644 index 0000000..6a093ad --- /dev/null +++ b/man/doubleGeneDel.Rd @@ -0,0 +1,125 @@ +\name{doubleGeneDel} +\alias{doubleGeneDel} + +\encoding{utf8} + +\title{Double Gene Deletion Experiment} + +\description{ + Predict the metabolic phenotype of of double-gene knock out mutants. +} + +\usage{ + doubleGeneDel(model, geneList1, geneList2, lb = NULL, ub = NULL, + allComb = FALSE, exLethal = TRUE, + tol = SYBIL_SETTINGS("TOLERANCE"), + checkOptSolObj = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{geneList1}{ + A character vector containing the set of genes to be deleted.\cr + Default: \code{allGenes(model)}. + } + \item{geneList2}{ + A character vector containing the set of genes to be deleted.\cr + Default: \code{allGenes(model)}. + } + \item{lb}{ + A numeric vector containing the lower bounds for the reaction rates of + reactions (variables) affected by the genes given in arguments + \code{geneList1} and \code{geneList2}. If set to \code{NULL}, all reactions + affected will be constrained to zero.\cr + Default: \code{NULL}. + } + \item{ub}{ + A numeric vector containing the upper bounds for the reaction rates of + reactions (variables) affected by the genes given in arguments + \code{geneList1} and \code{geneList2}. If set to \code{NULL}, all reactions + affected will be constrained to zero.\cr + Default: \code{NULL}. + } + \item{allComb}{ + A single Boolean value. If set to \code{TRUE}, every possible pairwise + combination of genes given in arguments \code{geneList1} and + \code{geneList2} will be knocked-out. If set to \code{FALSE}, arguments + \code{geneList1} and \code{geneList2} must have the same length. The + knock-outs will be computed pair-wise: first \code{geneList1[1]} and + \code{geneList2[1]}, second \code{geneList1[2]} and \code{geneList2[2]} + and so on.\cr + Default: \code{FALSE}. + } + \item{exLethal}{ + A single Boolean value. If set to \code{TRUE}, lethal genes are removed from + the analysis. A unique set of genes in \code{geneList1} and \code{geneList2} + will be scanned for lethal genes. A particular gene \eqn{i} is considered as + lethal, if the deletion of this gene results in a zero flux rate in the + objective function given in \code{model}. + Default: \code{TRUE}. + } + \item{tol}{ + A single numeric value, containing an absolute threshold value for a gene + being lethal or not.\cr + Default: \code{SYBIL_SETTINGS("TOLERANCE")}. + } + \item{checkOptSolObj}{ + A single logical value. If set to \code{TRUE}, a warning will be generated, + if not all optimizations ended successful.\cr + Default: \code{FALSE}. + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. Important ones are + \code{algorithm} in order to set the algorithm to use or \code{solverParm} + in order to set parameter values for the optimization software. + } +} + +\details{ + The function \code{doubleGeneDel} studies the effect of genetic perturbations + by double gene deletions on the phenotype of the metabolic network. The + function performs \eqn{n} optimizations with \eqn{n} being either the length + of the character vector in argument \code{geneList1} times the length of the + character vector in argument \code{geneList2}, if argument \code{allComb} is + set to \code{TRUE}, or the length of one of these vectors if argument + \code{allComb} is set to \code{FALSE}. For each gene deletion \eqn{i,j} + the set of fluxes effected by the simultaneous deletion of genes \eqn{i} and + \eqn{j} is constrained to zero flux. If the deletion of a certain pair of + genes has an effect, is tested with the function \code{\link{geneDel}}. Each + optimization corresponds to the simultaneous deletion of two genes. +} + +\value{ + An object of class \code{\linkS4class{optsol_genedel}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{modelorg}}, \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_genedel}}, + \code{\link{checkOptSol}}, \code{\link{optimizer}} and + \code{\link{SYBIL_SETTINGS}}. +} + +\examples{ +\dontrun{ + ## compute all possible pairwise gene deletions + # load example data set + data(Ec_core) + + # compute all possible pairwise gene deletions via + # FBA (default) + Ec_dgd <- doubleGeneDel(Ec_core, allComb = TRUE) + + # or MOMA (linearized version) + Ec_dgd <- doubleGeneDel(Ec_core, + allComb = TRUE, + algorithm = "lmoma") +} +} + +\keyword{optimize} + diff --git a/man/doubleReact.Rd b/man/doubleReact.Rd new file mode 100644 index 0000000..8494fee --- /dev/null +++ b/man/doubleReact.Rd @@ -0,0 +1,74 @@ +\name{doubleReact} +\alias{doubleReact} + +\encoding{utf8} + +\title{Identifies Identical Reactions} + +\description{ + The function \code{doubleReact} identifies identical reactions + (isoenzymes) in a model. +} + +\usage{ + doubleReact(model, checkRev = TRUE, linInd = FALSE) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{checkRev}{ + A single logical value. If set to \code{TRUE}, two reactions are identical, + if, additionally to the stoichiometric coefficients, the direction of the + reactions is the same (the corresponding value of slot + \code{\link{react_rev}} of the model).\cr + Default: \code{TRUE}. + } + \item{linInd}{ + A single logical value. If set to \code{TRUE}, two reactions are identical, + if the vectors of stoichiometric coefficients are linear dependent. + For example, two reactions with coefficients \eqn{(1, 1, -1)} and + \eqn{(2, 2, -2)} are linear dependent. If the coefficients have different + signs, for example \eqn{(-1, 1)} and \eqn{(1, -1)} (the first reaction + being forward direction and the second one being backward direction), they + are not identical. If \code{linInd} is set to \code{FALSE}, the + stoichiometric must be identical, for two reactions considered to be + identical. + Default: \code{FALSE}. + } +} + +\details{ + In the first step, the stoichiometric matrix S is divided into + groups of reactions containing the same number of metabolites. After + that, the row indices of the non-zero elements of these matrices are + compared. If identical pairs are found, we check the corresponding + values in S. If they are also identical, the reversibility of the reactions + are examined. If they are the same, the two reactions are called identical. +} + +\value{ + If no identical reactions were found, the return value is + FALSE. Otherwise a list is returned, ordered by the number of + metabolites used in each reaction. Each element is a numerical vector + containing the indices (column number fo the stoichiometrix matrix) of + identical reactions. +} + + +\author{Gabriel Gelius-Dietrich} + +\note{ + At the moment, the directions of a pair of reactions is not + compared. Meaning, that if concerning to the values in S the reaction + is in forward direction, but not when including the flux values, + \code{doubleReact} will not find it. +} + +\examples{ + data(Ec_core) + Ec_dr <- doubleReact(Ec_core) +} + +\keyword{manip} diff --git a/man/editEnvir.Rd b/man/editEnvir.Rd new file mode 100644 index 0000000..d5acbbb --- /dev/null +++ b/man/editEnvir.Rd @@ -0,0 +1,44 @@ +\name{editEnvir} +\alias{editEnvir} + +\title{ + Environment Editor for Metabolic Networks +} +\description{ + Environment editor for metabolic networks. The function \code{editEnvir} + opens the exchange reactions of a metabolic network in R's data editor. + Changes in upper and lower bounds will be set in the given model. +} +\usage{ + editEnvir(model, newKey = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{newKey}{ + If set to \code{TRUE}, a new model key will be generated. + } + \item{\dots}{ + Further arguments passed to \code{\link{edit}}. + } +} + +\value{ + An object of class \code{\linkS4class{modelorg}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{\code{\link{checkReactId}}} + +\examples{ + \dontrun{ + ## change environment of E.coli core model: + data(Ec_core) + mod <- editEnvir(Ec_core) + } +} + + diff --git a/man/findExchReact.Rd b/man/findExchReact.Rd new file mode 100644 index 0000000..2e320ce --- /dev/null +++ b/man/findExchReact.Rd @@ -0,0 +1,73 @@ +\name{findExchReact} + +\alias{findExchReact} + +\encoding{utf8} + +\title{ + Find Exchange Reactions +} + +\description{ + This function identifies reactions in a metabolic network which transport + metabolites accross the network boundary. Only the stroichiometric matrix + is taken into account, so the identified reactions are basically those, + having only one non-zero entry in their column of the stroichiometric matrix. + In order to work, the network must be \dQuote{open}, it must not contain + boundary metabolites. +} + +\usage{ + findExchReact(model) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}, + \code{\link[Matrix]{Matrix}} or \code{\link{matrix}}. + } +} + +\value{ + If \code{model} is of class \code{\linkS4class{modelorg}} an object of class + \code{\linkS4class{reactId_Exch}} is returned. + Otherwise, if \code{model} is of class \code{\link{matrix}} or + of class \code{\link[Matrix]{Matrix}}, a logical vector is returned. + If element \code{i} equals \code{TRUE}, column \code{i} of \code{model} is an + exchange reaction. The function returns \code{\link{NULL}} and gives a + warning, if no exchange reaction can be found. +} + +\details{ + A exchange reaction \eqn{j} for a particular metabolite \eqn{i} has exactly + one non-zero entry in the stoichiometric matrix + \eqn{S_{ij} \in \{-1, 1\}}{S_ij \in {-1, 1}}. If \eqn{S_{ij} = -1}{S_ij = -1}, + reaction \eqn{j} is considered to be an uptake (source) reaction. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\examples{ + data(Ec_core) + ex <- findExchReact(Ec_core) + + # run FBA + opt <- optimizeProb(Ec_core) + + # get flux distribution of exchange reactions + getFluxDist(opt, ex) +} + +\author{Gabriel Gelius-Dietrich} + diff --git a/man/fluxDistribution-class.Rd b/man/fluxDistribution-class.Rd new file mode 100644 index 0000000..8654dd9 --- /dev/null +++ b/man/fluxDistribution-class.Rd @@ -0,0 +1,91 @@ +\name{fluxDistribution-class} + +\Rdversion{1.1} +\docType{class} + +\alias{fluxDistribution-class} +\alias{fluxDistribution} + +\alias{[,fluxDistribution,ANY,ANY,ANY-method} +\alias{fluxes,fluxDistribution-method} +\alias{fluxes<-,fluxDistribution-method} +\alias{num_of_fluxes,fluxDistribution-method} +\alias{plot,fluxDistribution,missing-method} +\alias{nnzero,fluxDistribution-method} +\alias{nvar,fluxDistribution-method} +\alias{nvar} + +\alias{num_of_fluxes} + +\title{Class \code{"fluxDistribution"}} + +\description{ + Structure of the class \code{"fluxDistribution"}. Objects of that class are + used by class \code{"\linkS4class{optsol}"} in order to store flux + distributions. Flux distributions are stored column by column; each flux + corresponds to one row and the optimizations correspond to the columns. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{test <- fluxDistribution(fluxes, nrow = 1, ncol = 1}. + + If argument \code{fluxes} is of class \code{Matrix} or \code{matrix}, + \code{num_of_fluxes} is set to \code{ncol(fluxes) * nrow(fluxes)}. + If argument \code{fluxes} is a vector, a matrix will be generated according + to \code{nrow} and \code{ncol}. +} + +\section{Slots}{ + \describe{ + \item{\code{fluxes}:}{ + Object of class \code{"Matrix"} containing fluxdistributions column by + column. + } + \item{\code{num_of_fluxes}:}{ + Object of class \code{"integer"} containing the number of elements in + \code{fluxes}. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{[}}{ + \code{signature(x = "fluxDistribution")}: subsetting operator for the + matrix of flux distributions. + } + \item{\code{fluxes}}{ + \code{signature(object = "fluxDistribution")}: gets the \code{fluxes} + slot. + } + \item{\code{fluxes<-}}{ + \code{signature(object = "fluxDistribution")}: sets the \code{fluxes} + slot. + } + \item{\code{num_of_fluxes}}{ + \code{signature(object = "fluxDistribution")}: gets the + \code{num_of_fluxes} slot. + } + \item{\code{nnzero}}{ + \code{signature(object = "fluxDistribution")}: gets the number of + non-zero elements in slot \code{fluxes}. + } + \item{\code{nvar}}{ + \code{signature(object = "fluxDistribution")}: gets the number of + fluxes in the fluxdistribution in slot \code{fluxes} (the number of rows + of slot \code{fluxes}). + } + \item{\code{plot}}{ + \code{signature(x = "fluxDistribution", y = "missing")}: heatmap like + plotting method for fluxdistributions. Not finished yet. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\examples{ + showClass("fluxDistribution") +} +\keyword{classes} diff --git a/man/fluxVar.Rd b/man/fluxVar.Rd new file mode 100644 index 0000000..cad64c6 --- /dev/null +++ b/man/fluxVar.Rd @@ -0,0 +1,79 @@ +\name{fluxVar} +\alias{fluxVar} + +\encoding{utf8} + +\title{ + Flux Variability Analysis +} +\description{ + Performs flux variability analysis for a given model. +} +\usage{ + fluxVar(model, react = c(1:react_num(model)), exex = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{react}{ + An object of class \code{\linkS4class{reactId}}, character or integer. + Specifies the fluxes (variables) to analyse.\cr + Default: all reactions present in \code{model}. + } + \item{exex}{ + Boolean. Exclude exchange reactions from analysis. If set to \code{TRUE}, + argument \code{react} will be ignored. All reactions present in \code{model} + will be used, except for the exchange reactions.\cr + Default: \code{FALSE} + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. Argument + \code{algorithm} is set to \code{"\link[=sysBiolAlg_fv-class]{fv}"}, further + possible arguments are \code{fld}, arguments for pre and post processing + commands, \code{verboseMode} and further arguments passed to the constructor + for objects of class \code{\linkS4class{sysBiolAlg_fv}}, see there for + details. + } +} + +\details{ + The algorithm is described in + \code{\linkS4class{sysBiolAlg_fv}}. +} + +\value{ + An object of class \code{\linkS4class{optsol_fluxVar}}. The first \eqn{1} to + \eqn{n} (with \eqn{n} being the number of elements in argument \code{react}) + solutions are from the minimizations, and the last \eqn{n+1} to \eqn{2n} + solutions are from the maximizations. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. + + Bernhard Ø. Palsson (2006). + \emph{Systems Biology: Properties of Reconstructed Networks}. + Cambridge University Press. +} + +\author{Gabriel Gelius-Dietrich} + +\examples{ + data(Ec_core) + fv <- fluxVar(Ec_core) + plot(fv) +} + +\keyword{optimize} + diff --git a/man/geneDel.Rd b/man/geneDel.Rd new file mode 100644 index 0000000..3a8ddb0 --- /dev/null +++ b/man/geneDel.Rd @@ -0,0 +1,58 @@ +\name{geneDel} +\alias{geneDel} + +\encoding{utf8} + +\title{ + Get Gene-Reaction Association +} + +\description{ + The function \code{geneDel} returns the fluxes which are effected by a + particular combination of genes. +} + +\usage{ + geneDel(model, genes, checkId = FALSE) +} + +\arguments{ + \item{model}{ + An object of class \code{modelorg}. + } + \item{genes}{ + A vector of character strings of gene id's used in \code{model}, or an + integer vector with indices to gene id's in \code{\link{allGenes}(model)}. + } + \item{checkId}{ + Boolean. If set to \code{TRUE}, argument \code{genes} will be checked wether + it fits to \code{model} (e.g. are all genes existing). If set to + \code{FALSE}, \code{genes} must contain indices of gene id's in + \code{model}, e.g. in calls from \code{\link{optimizer}}. + } +} + +\details{ + The function \code{geneDel} checks for a set of gene id's in \code{gene} + on which fluxes a deletion of this set of genes has an effect. +} + +\value{ + An numeric vector of pointers to reaction id's in \code{model} or \code{NULL}, + if no fluxes are effected by the gene deletion. +} + +\references{ + Edwards, J. S., Ibarra, R. U. and Palsson, B. Ø. (2001) In silico predictions + of \emph{Escherichia coli} metabolic capabilities are consistent with + experimental data. \emph{Nat Biotechnol} \bold{19}, 125--130. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{optimizer}} +} + diff --git a/man/geneDeletion.Rd b/man/geneDeletion.Rd new file mode 100644 index 0000000..4e50477 --- /dev/null +++ b/man/geneDeletion.Rd @@ -0,0 +1,128 @@ +\name{geneDeletion} +\alias{geneDeletion} + +\encoding{utf8} + +\title{ + Gene Deletion Experiments +} + +\description{ + The function \code{geneDeletion} studies the effect of \eqn{n} in silico gene + deletions on the phenotype of a metabolic network. The value of \eqn{n} is the + number of genes knocked-out simultaneously. +} + +\usage{ + geneDeletion(model, genes, combinations = 1, + lb = NULL, ub = NULL, checkOptSolObj = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{genes}{ + Character or Integer: the genes to delete (see Details below). + } + \item{combinations}{ + A single integer value. If \code{combinations > 1} and \code{genes} is not a + matrix, \code{combinations} is the number of elements from \code{genes} + taken at a time while building all combinations of the elements in + \code{genes} (see Details below).\cr + Default: \code{1}. + } + \item{lb}{ + A numeric vector containing the lower bounds for the reaction rates of + reactions (variables) affected by the genes given in argument + \code{genes}. If set to \code{NULL}, all reactions affected will be + constrained to zero.\cr + Default: \code{NULL}. + } + \item{ub}{ + A numeric vector containing the upper bounds for the reaction rates of + reactions (variables) affected by the genes given in argument + \code{genes}. If set to \code{NULL}, all reactions affected will be + constrained to zero.\cr + Default: \code{NULL}. + } + \item{checkOptSolObj}{ + A single logical value. If set to \code{TRUE}, a warning will be generated, + if not all optimizations ended successful.\cr + Default: \code{FALSE}. + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. Important ones are + \code{algorithm} in order to set the algorithm to use or \code{solverParm} + in order to set parameter values for the optimization software. + } +} + +\details{ + If argument \code{genes} is a matrix of character values (gene id's) or + integers (pointers to gene id's), each column is treated as one deletion + experiment. If the matrix is made up of integers, a zero entry means no gene. + + If argument \code{genes} is a character vector or integer, the argument + \code{combinations} gives the number of gene id's taken each time in order + to build all possible combinations of \code{genes}. A matrix is constructed + using \code{\link{combn}}. The value of argument \code{combinations} gives the + number of genes, which are knocked-out simultaneously. The default value + \eqn{1} performs a single gene deletion experiment, like the function + \code{\link{oneGeneDel}} does. A value of \eqn{2} performs a double gene + deletion as described in \code{\link{doubleGeneDel}}. A value of \eqn{n} + performs an \eqn{n} gene deletion experiment. Keep in mind, that the number + of optimizations will get very high for increasing values of + \code{combinations}. + + If argument \code{genes} is empty, the number of unique genes present in + \code{model} is used. + + The required length of arguments \code{lb} and \code{ub} (if not \code{NULL}) + depends on the values given in arguments \code{genes} and \code{combinations}. + If \code{genes} is a matrix, \code{lb} and \code{ub} must be of length equal + to the number of columns in \code{genes}. If genes is a vector, \code{lb} and + \code{ub} must be of length equal to \code{length(genes) * combinations}. +} + +\value{ + An object of class \code{\linkS4class{optsol_genedel}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\linkS4class{modelorg}}, \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_genedel}}, + \code{\link{checkOptSol}}, \code{\link{oneGeneDel}}, + \code{\link{optimizer}}, \code{\link{optimizeProb}}, + \code{\link{combn}} and \code{\link{SYBIL_SETTINGS}}. +} + +\examples{ + ## load the dataset + data(Ec_core) + + ## perform a single gene deletion analysis + ## (delete every gene one by one) via FBA + gd <- geneDeletion(Ec_core) + + ## or via MOMA (linearized version) + gd <- geneDeletion(Ec_core, algorithm = "lmoma") + + ## triple gene deletion analysis using the first ten genes + gd <- geneDeletion(Ec_core, genes = 10, combinations = 3) + +\dontrun{ + ## perform a double gene deletion analysis + ##(delete all possible pairwise combinations of all genes) + gd <- geneDeletion(Ec_core, combinations = 2) + + ## perform a triple gene deletion analysis + ## (very high number of optimizations) + gd <- geneDeletion(Ec_core, combinations = 3) +} +} + +\keyword{optimize} + diff --git a/man/getColPrim-methods.Rd b/man/getColPrim-methods.Rd new file mode 100644 index 0000000..92b4aa7 --- /dev/null +++ b/man/getColPrim-methods.Rd @@ -0,0 +1,70 @@ +\name{getColPrim-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getColPrim} +\alias{getColPrim-methods} + +\alias{getColPrim,optObj_clpAPI,numeric-method} +\alias{getColPrim,optObj_cplexAPI,numeric-method} +\alias{getColPrim,optObj_glpkAPI,numeric-method} +\alias{getColPrim,optObj_lpSolveAPI,numeric-method} + +\title{Get Primal Value of Variables After Optimization} + +\description{ + Get primal value of variables after optimization. +} + +\usage{ +\S4method{getColPrim}{optObj_clpAPI,numeric}(lp, j) + +\S4method{getColPrim}{optObj_cplexAPI,numeric}(lp, j) + +\S4method{getColPrim}{optObj_glpkAPI,numeric}(lp, j) + +\S4method{getColPrim}{optObj_lpSolveAPI,numeric}(lp, j) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the column (variable) indices. + } +} + +\value{ + A numeric vector containing the desired primal values. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getColsLowBnds-methods.Rd b/man/getColsLowBnds-methods.Rd new file mode 100644 index 0000000..aeb376c --- /dev/null +++ b/man/getColsLowBnds-methods.Rd @@ -0,0 +1,70 @@ +\name{getColsLowBnds-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getColsLowBnds} +\alias{getColsLowBnds-methods} + +\alias{getColsLowBnds,optObj_clpAPI,numeric-method} +\alias{getColsLowBnds,optObj_cplexAPI,numeric-method} +\alias{getColsLowBnds,optObj_glpkAPI,numeric-method} +\alias{getColsLowBnds,optObj_lpSolveAPI,numeric-method} + +\title{Get Lower Bounds of the Columns (Variables) of the Optimization Problem} + +\description{ + Get lower bounds of the columns (variables) of the optimization Problem. +} + +\usage{ +\S4method{getColsLowBnds}{optObj_clpAPI,numeric}(lp, j) + +\S4method{getColsLowBnds}{optObj_cplexAPI,numeric}(lp, j) + +\S4method{getColsLowBnds}{optObj_glpkAPI,numeric}(lp, j) + +\S4method{getColsLowBnds}{optObj_lpSolveAPI,numeric}(lp, j) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the column (variable) indices. + } +} + +\value{ + A numeric vector containing the desired column bounds. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getColsNames-methods.Rd b/man/getColsNames-methods.Rd new file mode 100644 index 0000000..0fa699d --- /dev/null +++ b/man/getColsNames-methods.Rd @@ -0,0 +1,69 @@ +\name{getColsNames-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getColsNames} +\alias{getColsNames-methods} + +\alias{getColsNames,optObj_cplexAPI,numeric-method} +\alias{getColsNames,optObj_glpkAPI,numeric-method} +\alias{getColsNames,optObj_lpSolveAPI,numeric-method} + +\title{Retrieve Variable Names} + +\description{ + Get names of variables (columns) used in a optimization problem. +} + +\usage{ +\S4method{getColsNames}{optObj_cplexAPI,numeric}(lp, j) + +\S4method{getColsNames}{optObj_glpkAPI,numeric}(lp, j) + +\S4method{getColsNames}{optObj_lpSolveAPI,numeric}(lp, j) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_cplexAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector of column indices. + } +} + +\value{ + A character vector of column names, if names are existing. +} + +\note{ + For the \code{\linkS4class{optObj_glpkAPI}} method: the result vector may + be shorter than \code{j}, if some names are missing. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getColsUppBnds-methods.Rd b/man/getColsUppBnds-methods.Rd new file mode 100644 index 0000000..26b8e25 --- /dev/null +++ b/man/getColsUppBnds-methods.Rd @@ -0,0 +1,70 @@ +\name{getColsUppBnds-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getColsUppBnds} +\alias{getColsUppBnds-methods} + +\alias{getColsUppBnds,optObj_clpAPI,numeric-method} +\alias{getColsUppBnds,optObj_cplexAPI,numeric-method} +\alias{getColsUppBnds,optObj_glpkAPI,numeric-method} +\alias{getColsUppBnds,optObj_lpSolveAPI,numeric-method} + +\title{Get Upper Bounds of the Columns (Variables) of the Optimization Problem} + +\description{ + Get upper bounds of the columns (variables) of the optimization Problem. +} + +\usage{ +\S4method{getColsUppBnds}{optObj_clpAPI,numeric}(lp, j) + +\S4method{getColsUppBnds}{optObj_cplexAPI,numeric}(lp, j) + +\S4method{getColsUppBnds}{optObj_glpkAPI,numeric}(lp, j) + +\S4method{getColsUppBnds}{optObj_lpSolveAPI,numeric}(lp, j) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the column (variable) indices. + } +} + +\value{ + A numeric vector containing the desired column bounds. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getFluxDist-methods.Rd b/man/getFluxDist-methods.Rd new file mode 100644 index 0000000..87e9283 --- /dev/null +++ b/man/getFluxDist-methods.Rd @@ -0,0 +1,95 @@ +\name{getFluxDist-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getFluxDist} +\alias{getFluxDist-methods} + +\alias{getFluxDist,optObj_clpAPI-method} +\alias{getFluxDist,optObj_cplexAPI-method} +\alias{getFluxDist,optObj_glpkAPI-method} +\alias{getFluxDist,optObj_lpSolveAPI-method} +\alias{getFluxDist,optsol-method} + +\title{Retrieve Flux Distribution} + +\description{ + Get all primal values of variables after optimization (the resulting flux + distribution). +} + +\usage{ +\S4method{getFluxDist}{optObj_clpAPI}(lp) + +\S4method{getFluxDist}{optObj_cplexAPI}(lp) + +\S4method{getFluxDist}{optObj_glpkAPI}(lp) + +\S4method{getFluxDist}{optObj_lpSolveAPI}(lp) + +\S4method{getFluxDist}{optsol}(lp, react = NULL, opt = NULL, drop = TRUE) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + \item{\code{signature(lp = "optsol")}}{ + method to use with objects of class \code{\linkS4class{optsol}}. + Returns a subset of the flux distribution stored in slot \code{fluxdist} + as object of class \code{\link[Matrix]{Matrix}}. + If arguments \code{react} and \code{opt} are both set to \code{NULL} + (default), the flux distribution corresponding to the variable indices in + slot \code{fldind} will be returned. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}} or class + \code{\linkS4class{optsol}}. + } + \item{react}{ + Numeric vector or object of class \code{\linkS4class{reactId}} indicating + the reactions (rows of the flux distribution) to return.\cr + Default: \code{NULL}. + } + \item{opt}{ + Numeric vector indicating the optimizations (columns of the flux + distribution) to return.\cr + Default: \code{NULL}. + } + \item{drop}{ + Used for array subsetting like in \code{\link{[}}.\cr + Default: \code{TRUE}. + } +} + +\value{ + A numeric matrix or vector containing all primal values + (the flux distribution). +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getNumCols-methods.Rd b/man/getNumCols-methods.Rd new file mode 100644 index 0000000..bc8597c --- /dev/null +++ b/man/getNumCols-methods.Rd @@ -0,0 +1,67 @@ +\name{getNumCols-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getNumCols} +\alias{getNumCols-methods} + +\alias{getNumCols,optObj_clpAPI-method} +\alias{getNumCols,optObj_cplexAPI-method} +\alias{getNumCols,optObj_glpkAPI-method} +\alias{getNumCols,optObj_lpSolveAPI-method} + +\title{Get Number of Columns (Variables) of the Optimization Problem} + +\description{ + Get number of columns (variables) of the optimization problem. +} + +\usage{ +\S4method{getNumCols}{optObj_clpAPI}(lp) + +\S4method{getNumCols}{optObj_cplexAPI}(lp) + +\S4method{getNumCols}{optObj_glpkAPI}(lp) + +\S4method{getNumCols}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + A single numeric value. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getNumNnz-methods.Rd b/man/getNumNnz-methods.Rd new file mode 100644 index 0000000..fd39afd --- /dev/null +++ b/man/getNumNnz-methods.Rd @@ -0,0 +1,62 @@ +\name{getNumNnz-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getNumNnz} +\alias{getNumNnz-methods} + +\alias{getNumNnz,optObj_clpAPI-method} +\alias{getNumNnz,optObj_cplexAPI-method} +\alias{getNumNnz,optObj_glpkAPI-method} + +\title{Retrieve the Number of Non-Zero Elements of the Constraint Matrix} + +\description{ + Retrieve the number of non-zero elements in the constraint matrix of the + optimization problem. +} + +\usage{ +\S4method{getNumNnz}{optObj_clpAPI}(lp) + +\S4method{getNumNnz}{optObj_cplexAPI}(lp) + +\S4method{getNumNnz}{optObj_glpkAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + A single numeric value. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getNumRows-methods.Rd b/man/getNumRows-methods.Rd new file mode 100644 index 0000000..3e6e375 --- /dev/null +++ b/man/getNumRows-methods.Rd @@ -0,0 +1,67 @@ +\name{getNumRows-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getNumRows} +\alias{getNumRows-methods} + +\alias{getNumRows,optObj_clpAPI-method} +\alias{getNumRows,optObj_cplexAPI-method} +\alias{getNumRows,optObj_glpkAPI-method} +\alias{getNumRows,optObj_lpSolveAPI-method} + +\title{Get Number of Rows (Constraints) of the Optimization Problem} + +\description{ + Get number of rows (constraints) of the optimization problem. +} + +\usage{ +\S4method{getNumRows}{optObj_clpAPI}(lp) + +\S4method{getNumRows}{optObj_cplexAPI}(lp) + +\S4method{getNumRows}{optObj_glpkAPI}(lp) + +\S4method{getNumRows}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + A single numeric value. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getObjCoefs-methods.Rd b/man/getObjCoefs-methods.Rd new file mode 100644 index 0000000..ff2c85a --- /dev/null +++ b/man/getObjCoefs-methods.Rd @@ -0,0 +1,70 @@ +\name{getObjCoefs-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getObjCoefs} +\alias{getObjCoefs-methods} + +\alias{getObjCoefs,optObj_clpAPI,numeric-method} +\alias{getObjCoefs,optObj_cplexAPI,numeric-method} +\alias{getObjCoefs,optObj_glpkAPI,numeric-method} +\alias{getObjCoefs,optObj_lpSolveAPI,numeric-method} + +\title{Get Objective Coefficients of the Optimization Problem} + +\description{ + Get objective coefficients of the optimization problem. +} + +\usage{ +\S4method{getObjCoefs}{optObj_clpAPI,numeric}(lp, j) + +\S4method{getObjCoefs}{optObj_cplexAPI,numeric}(lp, j) + +\S4method{getObjCoefs}{optObj_glpkAPI,numeric}(lp, j) + +\S4method{getObjCoefs}{optObj_lpSolveAPI,numeric}(lp, j) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", j = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector containing the column (variable) indices. + } +} + +\value{ + A numeric vector containing the desired objective coefficients. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getObjDir-methods.Rd b/man/getObjDir-methods.Rd new file mode 100644 index 0000000..2411dee --- /dev/null +++ b/man/getObjDir-methods.Rd @@ -0,0 +1,68 @@ +\name{getObjDir-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getObjDir} +\alias{getObjDir-methods} + +\alias{getObjDir,optObj_clpAPI-method} +\alias{getObjDir,optObj_cplexAPI-method} +\alias{getObjDir,optObj_glpkAPI-method} +\alias{getObjDir,optObj_lpSolveAPI-method} + +\title{Get Direction of Optimization.} + +\description{ + Get direction of optimization. +} + +\usage{ +\S4method{getObjDir}{optObj_clpAPI}(lp) + +\S4method{getObjDir}{optObj_cplexAPI}(lp) + +\S4method{getObjDir}{optObj_glpkAPI}(lp) + +\S4method{getObjDir}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + Returns a single character string indicating the direction of optimization: + \code{"max"}: maximization, or \code{"min"}: minimization. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getObjVal-methods.Rd b/man/getObjVal-methods.Rd new file mode 100644 index 0000000..e5d7d67 --- /dev/null +++ b/man/getObjVal-methods.Rd @@ -0,0 +1,69 @@ +\name{getObjVal-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getObjVal} +\alias{getObjVal-methods} + +\alias{getObjVal,optObj_clpAPI-method} +\alias{getObjVal,optObj_cplexAPI-method} +\alias{getObjVal,optObj_glpkAPI-method} +\alias{getObjVal,optObj_lpSolveAPI-method} + +\title{Get Value of the Objective Function After Optimization} + +\description{ + Get value of the objective function after optimization. +} + +\usage{ +\S4method{getObjVal}{optObj_clpAPI}(lp) + +\S4method{getObjVal}{optObj_cplexAPI}(lp) + +\S4method{getObjVal}{optObj_glpkAPI}(lp) + +\S4method{getObjVal}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. For problems of type + \code{"mip"}: if no solution exists, the \pkg{cplexAPI} function + \code{getBestObjValCPLEX} will be used. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + Returns a single numeric value. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getRedCosts-methods.Rd b/man/getRedCosts-methods.Rd new file mode 100644 index 0000000..b8fa314 --- /dev/null +++ b/man/getRedCosts-methods.Rd @@ -0,0 +1,67 @@ +\name{getRedCosts-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getRedCosts} +\alias{getRedCosts-methods} + +\alias{getRedCosts,optObj_clpAPI-method} +\alias{getRedCosts,optObj_cplexAPI-method} +\alias{getRedCosts,optObj_glpkAPI-method} +\alias{getRedCosts,optObj_lpSolveAPI-method} + +\title{Get Reduced Costs of all Variables After Optimization} + +\description{ + Get reduced costs of all variables after optimization. +} + +\usage{ +\S4method{getRedCosts}{optObj_clpAPI}(lp) + +\S4method{getRedCosts}{optObj_cplexAPI}(lp) + +\S4method{getRedCosts}{optObj_glpkAPI}(lp) + +\S4method{getRedCosts}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\value{ + A numeric vector containing the reduced costs of all variables. +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getRowsLowBnds-methods.Rd b/man/getRowsLowBnds-methods.Rd new file mode 100644 index 0000000..33ddaa1 --- /dev/null +++ b/man/getRowsLowBnds-methods.Rd @@ -0,0 +1,71 @@ +\name{getRowsLowBnds-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getRowsLowBnds} +\alias{getRowsLowBnds-methods} + +\alias{getRowsLowBnds,optObj_clpAPI,numeric-method} +\alias{getRowsLowBnds,optObj_cplexAPI,numeric-method} +\alias{getRowsLowBnds,optObj_glpkAPI,numeric-method} +\alias{getRowsLowBnds,optObj_lpSolveAPI,numeric-method} + +\title{Get Lower Bounds of the Rows (Constraints) of the Optimization Problem} + +\description{ + Get lower bounds of the rows (constraints) of the optimization Problem. +} + +\usage{ +\S4method{getRowsLowBnds}{optObj_clpAPI,numeric}(lp, i) + +\S4method{getRowsLowBnds}{optObj_cplexAPI,numeric}(lp, i) + +\S4method{getRowsLowBnds}{optObj_glpkAPI,numeric}(lp, i) + +\S4method{getRowsLowBnds}{optObj_lpSolveAPI,numeric}(lp, i) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. This method returns + always \code{FALSE}. + } + \item{\code{signature(lp = "optObj_glpkAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{i}{ + A numeric vector containing the row indices. + } +} + +\value{ + A numeric vector containing the desired row bounds. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getRowsNames-methods.Rd b/man/getRowsNames-methods.Rd new file mode 100644 index 0000000..ec1a2f6 --- /dev/null +++ b/man/getRowsNames-methods.Rd @@ -0,0 +1,69 @@ +\name{getRowsNames-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getRowsNames} +\alias{getRowsNames-methods} + +\alias{getRowsNames,optObj_cplexAPI,numeric-method} +\alias{getRowsNames,optObj_glpkAPI,numeric-method} +\alias{getRowsNames,optObj_lpSolveAPI,numeric-method} + +\title{Retrieve Constraint Names} + +\description{ + Get names of constraints (rows) used in a optimization problem. +} + +\usage{ +\S4method{getRowsNames}{optObj_cplexAPI,numeric}(lp, i) + +\S4method{getRowsNames}{optObj_glpkAPI,numeric}(lp, i) + +\S4method{getRowsNames}{optObj_lpSolveAPI,numeric}(lp, i) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_cplexAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{i}{ + A numeric vector of row indices. + } +} + +\value{ + A character vector of row names, if names are existing. +} + +\note{ + For the \code{\linkS4class{optObj_glpkAPI}} method: the result vector may + be shorter than \code{i}, if some names are missing. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getRowsUppBnds-methods.Rd b/man/getRowsUppBnds-methods.Rd new file mode 100644 index 0000000..6a9a36d --- /dev/null +++ b/man/getRowsUppBnds-methods.Rd @@ -0,0 +1,71 @@ +\name{getRowsUppBnds-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getRowsUppBnds} +\alias{getRowsUppBnds-methods} + +\alias{getRowsUppBnds,optObj_clpAPI,numeric-method} +\alias{getRowsUppBnds,optObj_cplexAPI,numeric-method} +\alias{getRowsUppBnds,optObj_glpkAPI,numeric-method} +\alias{getRowsUppBnds,optObj_lpSolveAPI,numeric-method} + +\title{Get Upper Bounds of the Rows (Constraints) of the Optimization Problem} + +\description{ + Get upper bounds of the rows (constraints) of the optimization Problem. +} + +\usage{ +\S4method{getRowsUppBnds}{optObj_clpAPI,numeric}(lp, i) + +\S4method{getRowsUppBnds}{optObj_cplexAPI,numeric}(lp, i) + +\S4method{getRowsUppBnds}{optObj_glpkAPI,numeric}(lp, i) + +\S4method{getRowsUppBnds}{optObj_lpSolveAPI,numeric}(lp, i) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. This method returns + always \code{FALSE}. + } + \item{\code{signature(lp = "optObj_glpkAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", i = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{i}{ + A numeric vector containing the row indices. + } +} + +\value{ + A numeric vector containing the desired row bounds. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getSolStat-methods.Rd b/man/getSolStat-methods.Rd new file mode 100644 index 0000000..6922a8a --- /dev/null +++ b/man/getSolStat-methods.Rd @@ -0,0 +1,70 @@ +\name{getSolStat-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getSolStat} +\alias{getSolStat-methods} + +\alias{getSolStat,optObj_clpAPI-method} +\alias{getSolStat,optObj_cplexAPI-method} +\alias{getSolStat,optObj_glpkAPI-method} +\alias{getSolStat,optObj_lpSolveAPI-method} + +\title{Get Solution Status After Optimization} + +\description{ + Get solution status after optimization. +} + +\usage{ +\S4method{getSolStat}{optObj_clpAPI}(lp) + +\S4method{getSolStat}{optObj_cplexAPI}(lp) + +\S4method{getSolStat}{optObj_glpkAPI}(lp) + +\S4method{getSolStat}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. This method returns + \code{NA}. Package \pkg{lpSolveAPI} does not provide a solution status. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + Returns a single numeric value indicating the solution status after + optimization. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Function \code{\link{getMeanStatus}} and superclass + \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getSolverParm-methods.Rd b/man/getSolverParm-methods.Rd new file mode 100644 index 0000000..bff9414 --- /dev/null +++ b/man/getSolverParm-methods.Rd @@ -0,0 +1,71 @@ +\name{getSolverParm-methods} + +\docType{methods} +\encoding{utf8} + +\alias{getSolverParm} +\alias{getSolverParm-methods} + +\alias{getSolverParm,optObj_clpAPI-method} +\alias{getSolverParm,optObj_cplexAPI-method} +\alias{getSolverParm,optObj_glpkAPI-method} +\alias{getSolverParm,optObj_lpSolveAPI-method} + +\title{Retrieve Current Parameter Settings Used By The Optimization Software} + +\description{ + Retrieve current parameter settings used by the optimization software. +} + +\usage{ +\S4method{getSolverParm}{optObj_clpAPI}(lp) + +\S4method{getSolverParm}{optObj_cplexAPI}(lp) + +\S4method{getSolverParm}{optObj_glpkAPI}(lp) + +\S4method{getSolverParm}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. This method is currently + unused. It is not possible to provide parameters for package \pkg{clpAPI}. + Always \code{FALSE} will be returned. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. This method writes + the current parameter settings to the file \code{"cplex_parameters.prm"}. + The method returns zero if successfull, otherwise non-zero. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\value{ + Returns a list containing the current parameter settings or zero/non-zero. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/getsybilenv.Rd b/man/getsybilenv.Rd new file mode 100644 index 0000000..1f86355 --- /dev/null +++ b/man/getsybilenv.Rd @@ -0,0 +1,57 @@ +\name{getsybilenv} +\alias{getsybilenv} + +\title{ + Print sybil Environment +} + +\description{ + Prints current settings in the sybil environment. +} + +\usage{ + getsybilenv(part) +} + +\arguments{ + \item{part}{ + A character vector containing names of elements in the sybil environment. + Possible values are: + \describe{ + \item{\code{"solvers"}}{ + supported R packages for solving optimization problems. + } + \item{\code{"methods"}}{ + methods to solve optimization problems included in the R packages. + } + \item{\code{"ptype"}}{ + methods required for a particular problem type. + } + \item{\code{"purpose"}}{ + algorithms used in systems biology to use with a particular purpose. + } + } + } +} + +\details{ + Typical usages are + \preformatted{ + getsybilenv(part) + getsybilenv() + } + If argument \code{part} is not given, all elements described above will be + printed. +} + +\value{ + Returns \code{NULL} invisibly. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{addSolver}}, \code{\link{checkDefaultMethod}} + and \code{\link{SYBIL_SETTINGS}}. +} + diff --git a/man/initProb-methods.Rd b/man/initProb-methods.Rd new file mode 100644 index 0000000..a8e39e0 --- /dev/null +++ b/man/initProb-methods.Rd @@ -0,0 +1,90 @@ +\name{initProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{initProb} +\alias{initProb-methods} + +\alias{initProb,optObj_clpAPI-method} +\alias{initProb,optObj_cplexAPI-method} +\alias{initProb,optObj_glpkAPI-method} +\alias{initProb,optObj_lpSolveAPI-method} + +\title{Initialize Problem Object} + +\description{ + Initialize Problem Object. +} + +\usage{ +\S4method{initProb}{optObj_clpAPI}(lp, to = NULL, ...) + +\S4method{initProb}{optObj_cplexAPI}(lp, to = FALSE, ...) + +\S4method{initProb}{optObj_glpkAPI}(lp, to = FALSE, ...) + +\S4method{initProb}{optObj_lpSolveAPI}(lp, to = NULL, nrows, ncols) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}, argument \code{to} can + be a single numeric value: \code{0} -- \dQuote{none}, + \code{1} -- \dQuote{just final}, \code{2} -- \dQuote{just factorizations}, + \code{3} -- \dQuote{as 2 plus a bit more}, code{4} -- \dQuote{verbose}. + See COIN-OR Clp documentation for more details. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}, argument \code{to} can + be \code{TRUE} or \code{FALSE}. Setting CPLEX parameter + \code{CPX_PARAM_SCRIND} to \code{CPX_ON} or \code{CPX_OFF} has the same + effect. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}, argument \code{to} can + be \code{TRUE} or \code{FALSE}, setting GLPK function + \code{termOutGLPK} to \code{GLP_ON} or \code{GLP_OFF}. The amount of + output is controlled by the GLPK parameter \code{MSG_LEV}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}, argument \code{to} can + be a single character value, see \pkg{lpSolveAPI} documentation for more + details (\code{lp.control.options}, section \code{verbose}). + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{to}{ + A single boolean, numeric or character value, controling the amount of + terminal output of the solver software.\cr + Default: \code{FALSE} or \code{NULL}. + } + \item{nrows}{ + Number of rows (constraints) of the new problem object. + } + \item{ncols}{ + Number of columns (variables) of the new problem object. + } + \item{...}{ + Further arguments passed to the initialization function of the solver + package. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/loadLPprob-methods.Rd b/man/loadLPprob-methods.Rd new file mode 100644 index 0000000..54f93a5 --- /dev/null +++ b/man/loadLPprob-methods.Rd @@ -0,0 +1,219 @@ +\name{loadLPprob-methods} + +\docType{methods} +\encoding{utf8} + +\alias{loadLPprob} +\alias{loadLPprob-methods} +\alias{loadLPprob,optObj_clpAPI-method} +\alias{loadLPprob,optObj_cplexAPI-method} +\alias{loadLPprob,optObj_glpkAPI-method} +\alias{loadLPprob,optObj_lpSolveAPI-method} + +\title{Load Data to Optimization Problem} + +\description{ + Load data to the problem object (extending class + \code{\linkS4class{optObj}}). Use this method to generate problem + objects. +} + +\usage{ +\S4method{loadLPprob}{optObj_clpAPI}(lp, + nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL, + defLowerBnd = SYBIL_SETTINGS("MAXIMUM") * -1, + defUpperBnd = SYBIL_SETTINGS("MAXIMUM") +) + +\S4method{loadLPprob}{optObj_cplexAPI}(lp, + nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL) + +\S4method{loadLPprob}{optObj_glpkAPI}(lp, + nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL) + +\S4method{loadLPprob}{optObj_lpSolveAPI}(lp, + nCols, nRows, mat, ub, lb, obj, rlb, rtype, + lpdir = "max", rub = NULL, ctype = NULL, + cnames = NULL, rnames = NULL, pname = NULL) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object of class + \code{\linkS4class{optObj_clpAPI}}, + \code{\linkS4class{optObj_cplexAPI}}, + \code{\linkS4class{optObj_glpkAPI}} or + \code{\linkS4class{optObj_lpSolveAPI}}. + } + \item{nCols}{ + Number of columns (variables) of the constraint matrix. + } + \item{nRows}{ + Number of rows (constraints) of the constraint matrix. + } + \item{mat}{ + An object of class \code{\link{Matrix}}. The constraint matrix of the + problem object. The number of columns in \code{mat} must be \code{nCols} + and the number of rows in \code{mat} must be \code{nRows}. + } + \item{ub}{ + A numeric vector of length \code{nCols} giving the upper bounds of the + variables of the problem object. + } + \item{lb}{ + A numeric vector of length \code{nCols} giving the lower bounds of the + variables of the problem object. + } + \item{obj}{ + A numeric vector of length \code{nCols} giving the objective coefficients + of the variables of the problem object. + } + \item{rlb}{ + A numeric vector of length \code{nRows} giving the right hand side of the + problem object. If argument \code{rub} is not \code{NULL}, \code{rlb} + contains the lower bounds of the constraints of the problem object. + See Details. + } + \item{rtype}{ + A character vector of length \code{nRows} giving the constraint type: + \tabular{lll}{ + \code{"F"}: \tab free constraint (GLPK only) \tab \eqn{-\infty < x < \infty}{-INF < x < INF} \cr + \code{"L"}: \tab constraint with lower bound \tab \eqn{\mathrm{lb} \leq x < \infty}{lb <= x < INF} \cr + \code{"U"}: \tab constraint with upper bound \tab \eqn{-\infty < x \leq \mathrm{ub}}{-INF < x <= ub} \cr + \code{"D"}: \tab double-bounded (ranged) constraint \tab \eqn{\mathrm{lb} \leq x \leq \mathrm{ub}}{lb <= x <= ub} \cr + \code{"E"}: \tab fixed (equality) constraint \tab \eqn{\mathrm{lb} = x = \mathrm{ub}}{lb = x = ub} \cr + } + If \code{rtype[i]} is not one of \code{"F"}, \code{"L"}, \code{"U"}, + \code{"D"} or \code{"E"}, the value of \code{rtype[i]} will be set to + \code{"E"}. See Details. + } + \item{lpdir}{ + Single character string containing the direction of optimization. + Can be set to \code{"min"} or \code{"max"}.\cr + Default: \code{"max"}. + } + \item{rub}{ + A numeric vector of length \code{nRows} giving the right hand side of the + problem object. If not \code{NULL}, it contains the upper bounds of the + constraints of the problem object. See Details.\cr + Default: \code{NULL}. + } + \item{ctype}{ + A character vector of length \code{nCols} giving the variable type. If set + to \code{NULL}, no specific variable type is set, which usually means, all + variables are treated as continuous variables.\cr + Default: \code{NULL}. + \tabular{lll}{ + \code{"C"}: \tab continuous variable \cr + \code{"B"}: \tab binary variable \cr + \code{"I"}: \tab integer variable \cr + \code{"S"}: \tab semi-continuous variable \cr + \code{"N"}: \tab semi-integer variable \cr + } + Values \code{"S"} and \code{"N"} are not available for every solver + software. Check documentation of the solver software if semi-continuous and + semi-integer variables are supported. + If \code{ctype[j]} is not \code{"C"}, \code{"B"}, \code{"I"}, \code{"S"}, + or \code{"N"}, the value of \code{ctype[j]} will be set to \code{"C"}. + } + \item{cnames}{ + A character vector of length \code{nCols} containing symbolic names for + the variable of the problem object.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector of length \code{nRows} containing symbolic names for + the constraints of the problem object.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{defLowerBnd}{ + For the \code{\linkS4class{optObj_clpAPI}} method only: a single numeric + value containing a default value for an lower bound to a constraint in an + optimization problem.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM") * -1}. + } + \item{defUpperBnd}{ + For the \code{\linkS4class{optObj_clpAPI}} method only: a single numeric + value containing a default value for an upper bound to a constraint in an + optimization problem.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM")}. + } +} + +\details{ + Method \code{loadLPprob} can be used any time after a problem object is + initialized by \code{\link{initProb}}. + + In order so set constraints, usually only parameter \code{rlb} is required + and parameter \code{rub} can be left at \code{NULL} (which is the default). + If \code{rub} is not \code{NULL}, \code{rlb} and \code{rub} must have the same + length. Parameter \code{rub} is required, if a particular constraint is a + ranged or double bounded constraint. The general idea is, for any constraint + \code{i}, the value in \code{rlb[i]} gives the lower bound and the value in + \code{rub[i]} gives the upper bound. If the constraints of the optimization + problem do only have one bound (type \code{"L"}, \code{"U"} and \code{"E"}), + all bounds can be set via \code{rlb} and \code{rub} is not required. If any + constraint is of type \code{"D"} (a double-bounded or ranged constraint) + additionally \code{rub} is required. It is of course also possible to use + \code{rlb} strictly for all lower bounds and \code{rub} for all upper bounds. + Again, if both \code{rlb} and \code{rub} are given (not \code{NULL}), they + must have the same length. For equality constraints (type \code{"E"}), allways + the value in \code{rlb} is used. + + For the \code{\linkS4class{optObj_cplexAPI}} method: CPLEX uses so called + ranged constraints for double bounded constraints. The values in \code{rlb} + and \code{rub} will be transformed into range values for ranged constraints. + The range for a ranged constraint \eqn{i} is given as + \code{abs(rub[i] - rlb[i])}, so that the valid interval is denoted as + \code{[rlb[i], rlb[i] + range]}. + + For the \code{\linkS4class{optObj_glpkAPI}} method: if \code{cnames} or + \code{rnames} is not \code{NULL}, an index will be created. + + For the \code{\linkS4class{optObj_clpAPI}} method: if \code{cnames} is + not \code{NULL}, \code{rnames} must be also not \code{NULL} and vice versa. + + For the \code{\linkS4class{optObj_lpSolveAPI}} method: if \code{cnames} is + not \code{NULL}, \code{rnames} must be also not \code{NULL} and vice versa. + Round brackets (\code{"("} and \code{")"}) will be replaced by underscores + \code{"_"}. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/loadQobj-methods.Rd b/man/loadQobj-methods.Rd new file mode 100644 index 0000000..8e0b9e4 --- /dev/null +++ b/man/loadQobj-methods.Rd @@ -0,0 +1,56 @@ +\name{loadQobj-methods} + +\docType{methods} +\encoding{utf8} + +\alias{loadQobj} +\alias{loadQobj-methods} + +\alias{loadQobj,optObj_cplexAPI,Matrix-method} +\alias{loadQobj,optObj_cplexAPI,numeric-method} + +\title{Load Quadratic Part of the Objective Function to the Optimization Problem} + +\description{ + load quadratic part of the objective function to the optimization problem. +} + +\usage{ +\S4method{loadQobj}{optObj_cplexAPI,Matrix}(lp, mat) +\S4method{loadQobj}{optObj_cplexAPI,numeric}(lp, mat) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_cplexAPI", mat = "Matrix")}}{ + method to use with package \pkg{optObj_cplexAPI} and if \code{mat} is + of class \code{\linkS4class{Matrix}}. + } + \item{\code{signature(lp = "optObj_cplexAPI", mat = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI} and if \code{mat} is + a \code{numeric} vector. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{mat}{ + An object of class \code{\link{Matrix}} or a \code{numeric} vector + containing the quadratic objective Matrix \eqn{Q}. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/makeOptsolMO.Rd b/man/makeOptsolMO.Rd new file mode 100644 index 0000000..b36a0c9 --- /dev/null +++ b/man/makeOptsolMO.Rd @@ -0,0 +1,35 @@ +\name{makeOptsolMO} +\alias{makeOptsolMO} + +\title{ + Constructor Function for Objects of Class \code{optsol_optimizeProb}. +} + +\description{ + This function is a constructor function generating objects of + class \code{\linkS4class{optsol_optimizeProb}}. +} + +\usage{ + makeOptsolMO(mod, sol) +} + +\arguments{ + \item{mod}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{sol}{ + A list returned by function \code{\link{optimizer}}. + } +} + +\value{ + An object of class \code{\linkS4class{optsol_optimizeProb}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + Class \code{\linkS4class{optsol_optimizeProb}}, + class \code{\linkS4class{modelorg}} and function \code{\link{optimizer}}. +} diff --git a/man/mod2irrev.Rd b/man/mod2irrev.Rd new file mode 100644 index 0000000..ec40662 --- /dev/null +++ b/man/mod2irrev.Rd @@ -0,0 +1,64 @@ +\name{mod2irrev} +\alias{mod2irrev} + +\encoding{utf8} + +\title{Produces a Model in Irreversible Format} + +\description{ + The function \code{mod2irrev} produces a model with all reactions + moving in positive direction. +} + +\usage{ + mod2irrev(model, exex = FALSE) +} + +\arguments{ + \item{model}{An object of class \code{\linkS4class{modelorg}}.} + \item{exex}{Boolean. Exclude exchange fluxes (default: FALSE).} +} + +\details{ + The returned model consists only of reactions moving in positive + direction. Reactions with a negative direction in the original model + are transferred to positive direction; the corresponding reaction id + gets extended by \dQuote{\code{_r}}. + + Reversible reactions are split into two reactions. The corresponding + reaction ids gets extended by \dQuote{\code{_f}}, or \dQuote{\code{_b}} + indicating the original direction. + + If \code{exex = TRUE}, the exchange reactions were obtained by + \code{findExchReact}. +} + +\value{ + An object of class \code{\link{modelorg_irrev}}. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\author{Gabriel Gelius-Dietrich, Markus Herrgard} + +\seealso{\code{\linkS4class{modelorg_irrev}}} + +\examples{ + data(Ec_core) + Ec_ir <- mod2irrev(Ec_core) +} + +\keyword{manip} + + diff --git a/man/modelorg-class.Rd b/man/modelorg-class.Rd new file mode 100644 index 0000000..0a8474f --- /dev/null +++ b/man/modelorg-class.Rd @@ -0,0 +1,457 @@ +\name{modelorg-class} + +\docType{class} + +\alias{modelorg-class} +\alias{modelorg} +\alias{allGenes<-,modelorg-method} +\alias{allGenes,modelorg-method} +\alias{allGenes<-} +\alias{allGenes} +\alias{dim,modelorg-method} +\alias{genes<-,modelorg-method} +\alias{genes,modelorg-method} +\alias{genes<-} +\alias{genes} +\alias{gpr<-,modelorg-method} +\alias{gpr,modelorg-method} +\alias{gpr<-} +\alias{gpr} +\alias{gprRules<-,modelorg-method} +\alias{gprRules,modelorg-method} +\alias{gprRules<-} +\alias{gprRules} +\alias{lowbnd<-,modelorg-method} +\alias{lowbnd,modelorg-method} +\alias{lowbnd<-} +\alias{lowbnd} +\alias{met_comp<-,modelorg-method} +\alias{met_comp,modelorg-method} +\alias{met_comp<-} +\alias{met_comp} +\alias{met_de<-,modelorg-method} +\alias{met_de,modelorg-method} +\alias{met_de<-} +\alias{met_de} +\alias{met_id<-,modelorg-method} +\alias{met_id,modelorg-method} +\alias{met_id<-} +\alias{met_id} +\alias{met_name<-,modelorg-method} +\alias{met_name,modelorg-method} +\alias{met_name<-} +\alias{met_name} +\alias{met_num<-,modelorg-method} +\alias{met_num,modelorg-method} +\alias{met_num<-} +\alias{met_num} +\alias{met_single<-,modelorg-method} +\alias{met_single,modelorg-method} +\alias{met_single<-} +\alias{met_single} +\alias{mod_compart<-,modelorg-method} +\alias{mod_compart,modelorg-method} +\alias{mod_compart<-} +\alias{mod_compart} +\alias{mod_desc<-,modelorg-method} +\alias{mod_desc,modelorg-method} +\alias{mod_desc<-} +\alias{mod_desc} +\alias{mod_id<-,modelorg-method} +\alias{mod_id,modelorg-method} +\alias{mod_id<-} +\alias{mod_id} +\alias{mod_key<-,modelorg-method} +\alias{mod_key,modelorg-method} +\alias{mod_key<-} +\alias{mod_key} +\alias{mod_name<-,modelorg-method} +\alias{mod_name,modelorg-method} +\alias{mod_name<-} +\alias{mod_name} +\alias{obj_coef<-,modelorg-method} +\alias{obj_coef,modelorg-method} +\alias{obj_coef<-} +\alias{obj_coef} +\alias{printObjFunc,modelorg-method} +\alias{printObjFunc} +\alias{react_de<-,modelorg-method} +\alias{react_de,modelorg-method} +\alias{react_de<-} +\alias{react_de} +\alias{react_id<-,modelorg-method} +\alias{react_id,modelorg-method} +\alias{react_id<-} +\alias{react_id} +\alias{react_name<-,modelorg-method} +\alias{react_name,modelorg-method} +\alias{react_name<-} +\alias{react_name} +\alias{react_num<-,modelorg-method} +\alias{react_num,modelorg-method} +\alias{react_num<-} +\alias{react_num} +\alias{react_rev<-,modelorg-method} +\alias{react_rev,modelorg-method} +\alias{react_rev<-} +\alias{react_rev} +\alias{react_single<-,modelorg-method} +\alias{react_single,modelorg-method} +\alias{react_single<-} +\alias{react_single} +\alias{rxnGeneMat<-,modelorg-method} +\alias{rxnGeneMat,modelorg-method} +\alias{rxnGeneMat<-} +\alias{rxnGeneMat} +\alias{show,modelorg-method} +\alias{S<-,modelorg-method} +\alias{S,modelorg-method} +\alias{S<-} +\alias{S} +\alias{Snnz,modelorg-method} +\alias{Snnz} +\alias{subSys<-,modelorg-method} +\alias{subSys,modelorg-method} +\alias{subSys<-} +\alias{subSys} +\alias{uppbnd<-,modelorg-method} +\alias{uppbnd,modelorg-method} +\alias{uppbnd<-} +\alias{uppbnd} + +\encoding{utf8} + +\title{Structure of Class "modelorg"} + +\description{ + Structure of the class \code{"modelorg"}. Objects of that class are + returned by functions like \code{\link{readTSVmod}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the function \code{modelorg}: + + \code{test <- modelorg(id = "foo", name = "bar", + subSys = NULL, compartment = NULL)}. + \describe{ + \item{\code{id}:}{ + a single character string giving the model id. + } + \item{\code{name}:}{ + a single character string giving the model name. + } + \item{\code{subSys}:}{ + an optional single character string giving the metabolic subsystems + of the model. Default: \code{NULL} + } + \item{\code{compartment}:}{ + an optional single character string giving the compartments of the + model. Default: \code{NULL} + } + } + This constructor also generates the model key used in slot \code{mod_key}. +} + +\section{Slots}{ + \describe{ + \item{\code{mod_desc}:}{ + Object of class \code{"character"} containing a description of the model. + } + \item{\code{mod_name}:}{ + Object of class \code{"character"} indicating the model name. + } + \item{\code{mod_id}:}{ + Object of class \code{"character"} indicating the model id. + } + \item{\code{mod_key}:}{ + Object of class \code{"character"} containing a single character string + functioning as a unique key to a model object. + } + \item{\code{mod_compart}:}{ + Object of class \code{"character"} containing the model compartments. + } + \item{\code{met_num}:}{ + Object of class \code{"integer"} indicating the number of metabolites. + } + \item{\code{met_id}:}{ + Object of class \code{"character"} containing the metabolite id's. + } + \item{\code{met_name}:}{ + Object of class \code{"character"} containing the metabolite names. + } + \item{\code{met_comp}:}{ + Object of class \code{"integer"} containing the metabolites compartment. + } + \item{\code{met_single}:}{ + Object of class \code{"logical"} with length \code{met_num}. Element + \code{i} is \code{TRUE}, if metabolite \code{i} appears only once in S. + } + \item{\code{met_de}:}{ + Object of class \code{"logical"} with length \code{met_num}. Element + \code{i} is \code{TRUE}, if metabolite \code{i} is a dead end metabolite. + } + \item{\code{react_num}:}{ + Object of class \code{"integer"} indicating the number of reactions. + } + \item{\code{react_rev}:}{ + Object of class \code{"logical"} indicating whether a reaction is + reversible or not. + } + \item{\code{react_id}:}{ + Object of class \code{"character"} containing the reaction id's. + } + \item{\code{react_name}:}{ + Object of class \code{"character"} containing the reaction names. + } + \item{\code{react_single}:}{ + Object of class \code{"logical"} with length \code{react_num}. Element + \code{i} is \code{TRUE}, if reaction \code{i} uses metabolites appearing + only once in S. + } + \item{\code{react_de}:}{ + Object of class \code{"logical"} with length \code{react_num}. Element + \code{i} is \code{TRUE}, if reaction \code{i} uses dead end metabolites. + } + \item{\code{S}:}{ + Object of class \code{"matrix"} containing the stoichiometric matrix. + } + \item{\code{lowbnd}:}{ + Object of class \code{"numeric"} containing the reactions lower bounds. + } + \item{\code{uppbnd}:}{ + Object of class \code{"numeric"} containing the reactions upper bounds. + } + \item{\code{obj_coef}:}{ + Object of class \code{"numeric"} containing the objective coefficients. + } + \item{\code{gprRules}:}{ + Object of class \code{"character"} containing the gene-reaction + association rules in computable form. + } + \item{\code{genes}:}{ + Object of class \code{"list"} containing the genes corresponding to each + reaction. Every list element is a vector of the type \code{character}. + } + \item{\code{gpr}:}{ + Object of class \code{"character"} containing the gene-reaction + association rules for each reaction. + } + \item{\code{allGenes}:}{ + Object of class \code{"character"} containing a unique list of all genes. + } + \item{\code{rxnGeneMat}:}{ + Object of class \code{"matrix"} containing a reaction to gene mapping. + } + \item{\code{subSys}:}{ + Object of class \code{"matrix"} giving one or more subsystem name for each + reaction. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{allGenes<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{allGenes} slot. + } + \item{\code{allGenes}:}{ + \code{signature(object = "modelorg")}: gets the \code{allGenes} slot. + } + \item{\code{dim}:}{ + \code{signature(object = "modelorg")}: gets the \code{dimension} attribute + of slot \code{S}. + } + \item{\code{genes<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{genes} slot. + } + \item{\code{genes}:}{ + \code{signature(object = "modelorg")}: gets the \code{genes} slot. + } + \item{\code{gpr<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{gpr} slot. + } + \item{\code{gpr}:}{ + \code{signature(object = "modelorg")}: gets the \code{gpr} slot. + } + \item{\code{gprRules<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{gprRules} slot. + } + \item{\code{gprRules}:}{ + \code{signature(object = "modelorg")}: gets the \code{gprRules} slot. + } + \item{\code{lowbnd<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{lowbnd} slot. + } + \item{\code{lowbnd}:}{ + \code{signature(object = "modelorg")}: gets the \code{lowbnd} slot. + } + \item{\code{met_comp<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{met_comp} slot. + } + \item{\code{met_comp}:}{ + \code{signature(object = "modelorg")}: gets the \code{met_comp} slot. + } + \item{\code{met_de<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{met_de} slot. + } + \item{\code{met_de}:}{ + \code{signature(object = "modelorg")}: gets the \code{met_de} slot. + } + \item{\code{met_id<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{met_id} slot. + } + \item{\code{met_id}:}{ + \code{signature(object = "modelorg")}: gets the \code{met_id} slot. + } + \item{\code{met_name<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{met_name} slot. + } + \item{\code{met_name}:}{ + \code{signature(object = "modelorg")}: gets the \code{met_name} slot. + } + \item{\code{met_num<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{met_num} slot. + } + \item{\code{met_num}:}{ + \code{signature(object = "modelorg")}: gets the \code{met_num} slot. + } + \item{\code{met_single<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{met_single} slot. + } + \item{\code{met_single}:}{ + \code{signature(object = "modelorg")}: gets the \code{met_single} slot. + } + \item{\code{mod_compart<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{mod_compart} slot. + } + \item{\code{mod_compart}:}{ + \code{signature(object = "modelorg")}: gets the \code{mod_compart} slot. + } + \item{\code{mod_desc<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{mod_desc} slot. + } + \item{\code{mod_desc}:}{ + \code{signature(object = "modelorg")}: gets the \code{mod_desc} slot. + } + \item{\code{mod_id<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{mod_id} slot. + } + \item{\code{mod_id}:}{ + \code{signature(object = "modelorg")}: gets the \code{mod_id} slot. + } + \item{\code{mod_key<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{mod_key} slot. + } + \item{\code{mod_key}:}{ + \code{signature(object = "modelorg")}: gets the \code{mod_key} slot. + } + \item{\code{mod_name<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{mod_name} slot. + } + \item{\code{mod_name}:}{ + \code{signature(object = "modelorg")}: gets the \code{mod_name} slot. + } + \item{\code{obj_coef<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{obj_coef} slot. + } + \item{\code{obj_coef}:}{ + \code{signature(object = "modelorg")}: gets the \code{obj_coef} slot. + } + \item{\code{printObjFunc}:}{ + \code{signature(object = "modelorg")}: prints the objective function in + a human readable way. + } + \item{\code{react_de<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{react_de} slot. + } + \item{\code{react_de}:}{ + \code{signature(object = "modelorg")}: gets the \code{react_de} slot. + } + \item{\code{react_id<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{react_id} slot. + } + \item{\code{react_id}:}{ + \code{signature(object = "modelorg")}: gets the \code{react_id} slot. + } + \item{\code{react_name<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{react_name} slot. + } + \item{\code{react_name}:}{ + \code{signature(object = "modelorg")}: gets the \code{react_name} slot. + } + \item{\code{react_num<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{react_num} slot. + } + \item{\code{react_num}:}{ + \code{signature(object = "modelorg")}: gets the \code{react_num} slot. + } + \item{\code{react_rev<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{react_rev} slot. + } + \item{\code{react_rev}:}{ + \code{signature(object = "modelorg")}: gets the \code{react_rev} slot. + } + \item{\code{react_single<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{react_single} slot. + } + \item{\code{react_single}:}{ + \code{signature(object = "modelorg")}: gets the \code{react_single} slot. + } + \item{\code{rxnGeneMat<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{rxnGeneMat} slot. + } + \item{\code{rxnGeneMat}:}{ + \code{signature(object = "modelorg")}: gets the \code{rxnGeneMat} slot. + } + \item{\code{show}:}{ + \code{signature(object = "modelorg")}: prints some details specific to the + instance of class \code{modelorg}. + } + \item{\code{Snnz}:}{ + \code{signature(object = "modelorg")}: prints the number of non-zero + elements in \code{S}. + } + \item{\code{S<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{S} slot as matrix, + see Details below. + } + \item{\code{S}:}{ + \code{signature(object = "modelorg")}: gets the \code{S} slot as matrix. + } + \item{\code{subSys<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{subSys} slot. + } + \item{\code{subSys}:}{ + \code{signature(object = "modelorg")}: gets the \code{subSys} slot. + } + \item{\code{uppbnd<-}:}{ + \code{signature(object = "modelorg")}: sets the \code{uppnds} slot. + } + \item{\code{uppbnd}:}{ + \code{signature(object = "modelorg")}: gets the \code{uppbnd} slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\linkS4class{modelorg_irrev}} for models in irreversible format. +} + +\examples{ + showClass("modelorg") + + ## print human readable version of the objective function + data(Ec_core) + printObjFunc(Ec_core) + + ## change objective function and print + Ec_objf <- changeObjFunc(Ec_core, c("EX_etoh(e)", "ETOHt2r"), c(1, 2)) + printObjFunc(Ec_objf) +} + +\keyword{classes} + + + diff --git a/man/modelorg2ExPA.Rd b/man/modelorg2ExPA.Rd new file mode 100644 index 0000000..4d88990 --- /dev/null +++ b/man/modelorg2ExPA.Rd @@ -0,0 +1,76 @@ +\name{modelorg2ExPA} +\alias{modelorg2ExPA} + +\encoding{utf8} + +\title{ + Write an Instance of Class modelorg to File in ExPA Format +} + +\description{ + The function \code{modelorg2ExPA} writes the content of an instance of class + \code{\link{modelorg}} to text files in a format which can be read by the + program ExPA to compute extreme pathways. +} + +\usage{ + modelorg2ExPA(model, fname = NULL, exIntReact = NULL, + filepath = ".", suffix = "expa", + tol = SYBIL_SETTINGS("TOLERANCE")) +} + +\arguments{ + \item{model}{ + An object of class \code{\link{modelorg}}. + } + \item{fname}{ + An single character string giving the filename to write to.\cr + Default: \code{<model_id>.expa}. + } + \item{exIntReact}{ + An object of class \code{\linkS4class{reactId}}, character or integer, + giving id's of internal reactions to exclude in the ExPA file.\cr + Default: \code{NULL}. + } + \item{filepath}{ + A single character string giving the path to a certain directory in which + the output files will be stored.\cr + Default: \code{"."}. + } + \item{suffix}{ + A single character string giving the file name extension.\cr + Default: \code{"expa"}. + } + \item{tol}{ + A single numeric value giving the limit of tolerance. An element + \eqn{S_{ij}}{S[i,j]} of the stoichiometric matrix is treated as non-zero, + if \eqn{|S_{ij}| > \textrm{tol}}{S[i,j] > tol} is true.\cr + Default: \code{"expa"}. + } +} + +\details{ + The function \code{modelorg2ExPA} produces input files for the program ExPA. + With ExPA, it is possible to calculate extreme pathways in metabolic networks. + + The function produces a warning, if a reaction contains non-integer + stoichiometric values, because they are not compatible with the ExPA program. +} + +\value{ + Returns \code{TRUE} invisibly on success. +} + +\references{ + Bell, S. L. and Palsson, B. Ø. (2005) Expa: a program for calculating extreme + pathways in biochemical reaction networks. \emph{Bioinformatics} \bold{21}, + 1739--1740. + + The ExPA homepage \url{http://gcrg.ucsd.edu/Downloads/ExtremePathwayAnalysis}. +} + +\author{ + Gabriel Gelius-Dietrich, C. Jonathan Fritzemeier +} + +\keyword{ IO } diff --git a/man/modelorg2tsv.Rd b/man/modelorg2tsv.Rd new file mode 100644 index 0000000..52c745c --- /dev/null +++ b/man/modelorg2tsv.Rd @@ -0,0 +1,161 @@ +\name{modelorg2tsv} +\alias{modelorg2tsv} + +\encoding{utf8} + +\title{ + Write an Instance of Class modelorg to File +} + +\description{ + The function \code{modelorg2tsv} writes the content of an instance of class + \code{\link{modelorg}} to text files in a character-separated value format + adopted from the BiGG database output. +} + +\usage{ + modelorg2tsv(model, prefix, suffix, extMetFlag = "b", + fielddelim = "\t", entrydelim = ", ", + makeClosedNetwork = FALSE, + onlyReactionList = FALSE, + minimalSet = FALSE, + fpath = SYBIL_SETTINGS("PATH_TO_MODEL"), ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\link{modelorg}}. + } + \item{prefix}{ + A single character string giving the prefix for three possible output files + (see Details below). + } + \item{suffix}{ + A single character string giving the file name extension. If missing, the + value of \code{suffix} depends on the argument \code{fielddelim}, see + Details below.\cr + Default: \code{"tsv"}. + } + \item{extMetFlag}{ + A single character string giving the identificator for metabolites which + are outside the system boundary. Only necessary, if the model is a closed + one.\cr + Default: \code{"b"}. + } + \item{fielddelim}{ + A single character string giving the value separator.\cr + Default: \code{"\t"}. + } + \item{entrydelim}{ + A single character string giving the a separator for values containing + more than one entry.\cr + Default: \code{", "}. + } + \item{makeClosedNetwork}{ + Boolean. If set to \code{TRUE}, external metabolites (which are outside the + system boundary) will be added to the model. These metabolites participate + in reactions, transporting metabolites across the system boundary. + The metabolite id will be the same as for the metabolite inside the system, + but the compartment type is set to the value of argument + \code{extMetFlag}. + + For example, most models contain a transport reaction for glucose: + + \code{glc[c] <==> } + + If \code{makeClosedNetwork} is set to \code{TRUE}, this reaction will be + written as + + \code{glc[c] <==> glc[b]} + + with the letter \code{b} being the default value for \code{extMetFlag}.\cr + Default: \code{FALSE}. + } + \item{onlyReactionList}{ + Boolean. If set to \code{TRUE}, only one file containing all reaction + equations will be produced (output file has one column).\cr + Default: \code{FALSE}. + } + \item{minimalSet}{ + Boolean. If set to \code{TRUE}, only one file containing the fields + \code{"abbreviation"}, \code{"equation"}, \code{"lowbnd"}, \code{"uppbnd"} + and \code{"obj_coef"} will be produced (output file has five columns).\cr + Default: \code{FALSE}. + } + \item{fpath}{ + A single character string giving the path to a certain directory in which + the output files will be stored.\cr + Default: \code{SYBIL_SETTINGS("PATH_TO_MODEL")}. + } + \item{\dots}{ + Further arguments passed to \code{\link{write.table}}, e.g. the Boolean + argument \code{quote} can be used here. + } +} + +\details{ + The function \code{modelorg2tsv} produces three output files: a reactions + list, a metabolites list and a model description file. + + The reactions list has the following columns: + \tabular{ll}{ + \code{"abbreviation"} \tab \code{react_id(model)} \cr + \code{"name"} \tab \code{react_name(model)} \cr + \code{"equation"} \tab the reaction equations \cr + \code{"reversible"} \tab \code{react_rev(model)} \cr + \code{"compartment"} \tab reaction compartment(s) \cr + \code{"lowbnd"} \tab \code{lowbnd(model)} \cr + \code{"uppbnd"} \tab \code{uppbnd(model)} \cr + \code{"obj_coef"} \tab \code{obj_coef(model)} \cr + \code{"rule"} \tab \code{gpr(model)} \cr + \code{"subsystem"} \tab \code{subSys(model)} \cr + } + + The metabolites list has the following columns: + \tabular{ll}{ + \code{"abbreviation"} \tab \code{met_id(model)} \cr + \code{"name"} \tab \code{met_name(model)} \cr + \code{"compartment"} \tab \code{met_comp(model)} \cr + } + + The model description file has the following columns: + \tabular{ll}{ + \code{"name"} \tab \code{mod_name(model)} \cr + \code{"id"} \tab \code{mod_id(model)} \cr + \code{"description"} \tab \code{mod_desc(model)} \cr + \code{"compartment"} \tab \code{mod_compart(model)} \cr + \code{"abbreviation"} \tab unique compartment abbreviations \cr + \code{"Nmetabolites"} \tab number of metabolites \cr + \code{"Nreactions"} \tab number of reactions \cr + \code{"Ngenes"} \tab number of independend genes \cr + \code{"Nnnz"} \tab number of non-zero elements in + the stoichiometric matrix \cr + } + + If \code{onlyReactionList} is set to \code{TRUE}, only the reactions list + containing the column \code{"equation"} is produced. + + Please read the package vignette for detailed information about file formats + and examples. + + All fields in the output files are in double quotes. In order to read them in + with \code{\link{readTSVmod}}, set argument \code{quoteChar} to \code{"\""}. +} + +\value{ + Returns \code{TRUE} on success. +} + +\references{ + The BiGG database \url{http://bigg.ucsd.edu/}. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{read.table}}, \code{\link{modelorg2tsv}}, \code{\link{modelorg}}. +} + +\keyword{ IO } diff --git a/man/modelorg_irrev-class.Rd b/man/modelorg_irrev-class.Rd new file mode 100644 index 0000000..b4c76bd --- /dev/null +++ b/man/modelorg_irrev-class.Rd @@ -0,0 +1,109 @@ +\name{modelorg_irrev-class} + +\docType{class} + +\alias{modelorg_irrev-class} +\alias{modelorg_irrev} +\alias{matchrev<-,modelorg_irrev-method} +\alias{matchrev,modelorg_irrev-method} +\alias{matchrev<-} +\alias{matchrev} +\alias{irrev<-,modelorg_irrev-method} +\alias{irrev,modelorg_irrev-method} +\alias{irrev<-} +\alias{irrev} +\alias{rev2irrev<-,modelorg_irrev-method} +\alias{rev2irrev,modelorg_irrev-method} +\alias{rev2irrev<-} +\alias{rev2irrev} +\alias{irrev2rev<-,modelorg_irrev-method} +\alias{irrev2rev,modelorg_irrev-method} +\alias{irrev2rev<-} +\alias{irrev2rev} + +\encoding{utf8} + +\title{Class for Metabolic Networks in Irreversible Format.} + +\description{ + Structure of the class \code{"modelorg_irrev"}. Objects of that class are + returned by the function \code{\link{mod2irrev}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the function \code{modelorg_irrev}: + + \code{test <- modelorg_irrev(id = "foo", name = "bar")}. +} + +\section{Slots}{ + \describe{ + \item{\code{irrev}:}{ + Object of class \code{"logical"} indicating if the model is in + irreversible format. + } + \item{\code{matchrev}:}{ + Object of class \code{"integer"} matching of forward and backward + reactions of a reversible reaction. + } + \item{\code{rev2irrev}:}{ + Object of class \code{"matrix"} containing the reaction id's of the + corresponding reactions in irreversible format. + } + \item{\code{irrev2rev}:}{ + Object of class \code{"integer"} containing the reaction id's of the + corresponding reaction in reversible format. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{modelorg}"}, directly. +} + +\section{Methods}{ + \describe{ + \item{\code{irrev<-}:}{ + \code{signature(object = "modelorg_irrev")}: sets the \code{irrev} slot. + } + \item{\code{irrev}:}{ + \code{signature(object = "modelorg_irrev")}: gets the \code{irrev} slot. + } + \item{\code{matchrev<-}:}{ + \code{signature(object = "modelorg_irrev")}: sets the \code{matchrev} + slot. + } + \item{\code{matchrev}:}{ + \code{signature(object = "modelorg_irrev")}: gets the \code{matchrev} + slot. + } + \item{\code{rev2irrev<-}:}{ + \code{signature(object = "modelorg_irrev")}: sets the \code{rev2irrev} + slot. + } + \item{\code{rev2irrev}:}{ + \code{signature(object = "modelorg_irrev")}: gets the \code{rev2irrev} + slot. + } + \item{\code{irrev2rev<-}:}{ + \code{signature(object = "modelorg_irrev")}: sets the \code{irrev2rev} + slot. + } + \item{\code{irrev2rev}:}{ + \code{signature(object = "modelorg_irrev")}: gets the \code{irrev2rev} + slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\linkS4class{modelorg}} +} + +\examples{ + showClass("modelorg_irrev") +} + +\keyword{classes} diff --git a/man/multiDel.Rd b/man/multiDel.Rd new file mode 100644 index 0000000..a60d034 --- /dev/null +++ b/man/multiDel.Rd @@ -0,0 +1,82 @@ +\name{multiDel} +\alias{multiDel} + +\title{ + Parallel Support for sybil +} + +\description{ + Parallel computation support for the functions \code{\link{oneGeneDel}}, + \code{\link{doubleGeneDel}}, \code{\link{oneFluxDel}}, + \code{\link{doubleFluxDel}} and \code{\link{fluxVar}}. +} + +\usage{ + multiDel(model, nProc = 2, todo = "oneGeneDel", del1 = NA, del2 = NA, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\link{modelorg}}. + } + \item{nProc}{ + Number of cores (processes) to use. + } + \item{todo}{ + A single character value giving the function name, which should be + parallelised. Can be one of \code{"oneGeneDel"}, + \code{"doubleGeneDel"}, \code{"oneFluxDel"}, + \code{"doubleFluxDel"} or \code{"fluxVar"}. + } + \item{del1}{ + Vector of genes/reactions to consider. + } + \item{del2}{ + Vector of genes/reactions to consider (for use with + \code{\link{doubleGeneDel}} or \code{\link{doubleFluxDel}}). + } + \item{\dots}{ + Further arguments passed to \code{\link{oneGeneDel}}, + \code{\link{doubleGeneDel}}, \code{\link{oneFluxDel}}, + \code{\link{doubleFluxDel}} or \code{\link{fluxVar}}. + } +} + +\details{ + The function loads the package \pkg{parallel} if available. Argument + \code{nProc} should be the number of cores to use. This number is veryfied + via a call to \code{detectCores} (of \pkg{parallel}) and is set to the return + value of \code{detectCores}, if \code{nProc > detectCores()} evaluates to + \code{TRUE}. Arguments \code{del1} and \code{del2} are split into lists, + each list element containing \code{nProc/del1} elements. These are passed to + \code{\link{mclapply}}. +} + +\value{ + A list of length \code{nProc} (or less, depending of the numbers of available + cores), each element containing the return value of the function called (on + object of a class extending \code{\linkS4class{optsol}}). +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{mclapply}}, \code{\linkS4class{optsol}}, \code{\link{oneGeneDel}}, + \code{\link{doubleGeneDel}}, \code{\link{oneFluxDel}}, + \code{\link{doubleFluxDel}} and \code{\link{fluxVar}}. +} + +\examples{ +\dontrun{ +## The examples here require the packages glpkAPI and parallel to be +## installed. + +## perform single gene deletion analysis using the E. coli core +## metabolic model +data(Ec_core) +ad <- multiDel(Ec_core) +mapply(checkOptSol, ad) +} +} diff --git a/man/netFlux-class.Rd b/man/netFlux-class.Rd new file mode 100644 index 0000000..699896e --- /dev/null +++ b/man/netFlux-class.Rd @@ -0,0 +1,91 @@ +\name{netFlux-class} + +\Rdversion{1.1} +\encoding{utf8} +\docType{class} + +\alias{netFlux} +\alias{netFlux-class} +\alias{getNetFlux} +\alias{length,netFlux-method} +\alias{rate,netFlux-method} +\alias{rate} +\alias{react_id,netFlux-method} +\alias{react_id<-,netFlux-method} + +\title{Class \code{"netFlux"}} + +\description{ + Class \code{"netFlux"} groups exchange reaction rates according to their sign + in uptake, excretion and unused reactions. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form \code{getNetFlux(rates, tol)}, + with argument \code{rates} being a named numeric vector containing reaction + rates of exchange fluxes and corresponding reaction id's. Argument + \code{rates} can be obtained by a call to \code{\link{optimizeProb}}. The + second argument \code{tol} is a tolerance value (default: + \code{SYBIL_SETTINGS("TOLERANCE")}). Reaction rates less than \code{tol * -1} + are uptake reactions, reaction rates greater than \code{tol} are excretion + reactions and all others (\code{abs(rates) < tol}) are unused reactions. +} + +\section{Slots}{ + \describe{ + \item{\code{uptake}:}{ + Object of class \code{"logical"} indicating uptake reactions. + } + \item{\code{product}:}{ + Object of class \code{"logical"} indicating excretion reactions. + } + \item{\code{unused}:}{ + Object of class \code{"logical"} indicating unused reactions. + } + \item{\code{react_id}:}{ + Object of class \code{"character"} containing the reaction id's of the + exchange reactions. + } + \item{\code{rate}:}{ + Object of class \code{"numeric"} containing the reaction rates of the + exchange reactions. + } + } +} + +\section{Methods}{ + \describe{ + \item{length}{\code{signature(x = "netFlux")}: + number of exchange reactions. + } + \item{rate}{\code{signature(object = "netFlux")}: + gets the \code{rate} slot. + } + \item{react_id}{\code{signature(object = "netFlux")}: + gets the \code{react_id} slot. + } + \item{react_id<-}{\code{signature(object = "netFlux")}: + sets the \code{react_id} slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{optimizeProb}}, \code{\link{getFluxDist}} +} + +\examples{ + data(Ec_core) + # retrieve all exchange reactions + ex <- findExchReact(Ec_core) + # perform flux balance analysis + opt <- optimizeProb(Ec_core, algorithm = "fba") + # get flux distribution of all exchange reactions + fd <- getFluxDist(opt, ex) + # group exchange reactions + getNetFlux(fd) +} + +\keyword{classes} diff --git a/man/oneFluxDel.Rd b/man/oneFluxDel.Rd new file mode 100644 index 0000000..eafe5b7 --- /dev/null +++ b/man/oneFluxDel.Rd @@ -0,0 +1,81 @@ +\name{oneFluxDel} +\alias{oneFluxDel} + +\encoding{utf8} + +\title{Single Flux Deletion Experiment} + +\description{ + Single reaction (flux) deletion analysis. +} + +\usage{ + oneFluxDel(model, react = c(1:react_num(model)), + lb = rep(0, length(react)), + ub = rep(0, length(react)), + checkOptSolObj = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{react}{ + An object of class \code{\linkS4class{reactId}} or character or integer + containing reaction id's to constrain to zero one by one.\cr + Default: all reactions present in argument \code{model}. + } + \item{lb}{ + A numeric vector of the same length as \code{react} containing the lower + bounds for the reaction rates of reactions (variables) given in argument + \code{react}.\cr + Default: \code{0} for all reactions in \code{react}, zero flux through all + reactions. + } + \item{ub}{ + A numeric vector of the same length as \code{react} containing the lower + bounds for the reaction rates of reactions (variables) given in argument + \code{react}.\cr + Default: \code{0} for all reactions in \code{react}, zero flux through all + reactions. + } + \item{checkOptSolObj}{ + A single logical value. If set to \code{TRUE}, a warning will be generated, + if not all optimizations ended successful.\cr + Default: \code{FALSE}. + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. Important ones are + \code{algorithm} in order to set the algorithm to use or \code{solverParm} + in order to set parameter values for the optimization software. + } +} + +\details{ + The function \code{oneFluxDel} studies the effect of constraining single + fluxes to zero flux rates on the phenotype of the metabolic network. The + function performs \eqn{n} optimizations with \eqn{n} being the number of + reaction id's given in argument \code{react}. Each optimization corresponds + to the removal of one reaction. +} + +\value{ + An object of class \code{\linkS4class{optsol_fluxdel}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{modelorg}}, \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_fluxdel}}, + \code{\link{checkOptSol}}, \code{\link{optimizer}} and + \code{\link{SYBIL_SETTINGS}}. +} + +\examples{ + data(Ec_core) + Ec_ofd <- oneFluxDel(Ec_core) +} + +\keyword{optimize} + diff --git a/man/oneGeneDel.Rd b/man/oneGeneDel.Rd new file mode 100644 index 0000000..eb13f5d --- /dev/null +++ b/man/oneGeneDel.Rd @@ -0,0 +1,90 @@ +\name{oneGeneDel} +\alias{oneGeneDel} + +\encoding{utf8} + +\title{Single Gene Deletion Experiment} + +\description{ + Predict the metabolic phenotype of single-gene knock out mutants. +} + +\usage{ + oneGeneDel(model, geneList, + lb = rep(0, length(geneList)), + ub = rep(0, length(geneList)), + checkOptSolObj = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{geneList}{ + A character vector containing the set of genes to be deleted one by one.\cr + Default: \code{allGenes(model)}. + } + \item{lb}{ + A numeric vector of the same length as \code{geneList} containing the lower + bounds for the reaction rates of reactions (variables) affected by the genes + given in argument \code{geneList}.\cr + Default: \code{0} for all genes in \code{geneList}, simulating knock-out + mutants. + } + \item{ub}{ + A numeric vector of the same length as \code{geneList} containing the upper + bounds for the reaction rates of reactions (variables) affected by the genes + given in argument \code{geneList}.\cr + Default: \code{0} for all genes in \code{geneList}, simulating knock-out + mutants. + } + \item{checkOptSolObj}{ + A single logical value. If set to \code{TRUE}, a warning will be generated, + if not all optimizations ended successful.\cr + Default: \code{FALSE}. + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. Important ones are + \code{algorithm} in order to set the algorithm to use or \code{solverParm} + in order to set parameter values for the optimization software. + } +} + +\details{ + The function \code{oneGeneDel} studies the effect of genetic perturbations + by single gene deletions on the phenotype of the metabolic network. The + function performs \eqn{n} optimizations with \eqn{n} being the length of the + character vector in argument \code{geneList}. For each gene deletion \eqn{j} + the set of fluxes effected by the deletion of gene given in \code{geneList[j]} + is constrained to zero flux. If the deletion of a certain gene has an effect, + is tested with the function \code{\link{geneDel}}. Each optimization + corresponds to the deletion of one gene. +} + +\value{ + An object of class \code{\linkS4class{optsol_genedel}}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{modelorg}}, \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_genedel}}, + \code{\link{checkOptSol}}, \code{\link{optimizer}} and + \code{\link{SYBIL_SETTINGS}}. +} + +\examples{ + # load example data set + data(Ec_core) + + # compute phenotypes of genetic perturbations via + # FBA (default) + Ec_ogd <- oneGeneDel(Ec_core) + + # or MOMA (linearized version) + Ec_ogd <- oneGeneDel(Ec_core, algorithm = "lmoma") +} + +\keyword{optimize} + diff --git a/man/onlyChangeGPR.Rd b/man/onlyChangeGPR.Rd new file mode 100644 index 0000000..643ab9e --- /dev/null +++ b/man/onlyChangeGPR.Rd @@ -0,0 +1,32 @@ +\name{onlyChangeGPR} +\alias{onlyChangeGPR} + +\encoding{utf8} + +\title{Change the GPR Rules} + +\description{ + Changes the GPR Rules for the chosen reactions +} +\usage{ + onlyChangeGPR(model, gprRules, reactNr, verboseMode = 0) +} + +\arguments{ + \item{model}{An object of class \code{\linkS4class{modelorg}}} + \item{gprRules}{character: contains logical expressions.} + \item{reactNr}{An object of class \code{\linkS4class{reactId}}, a + numeric vector, or a character vector containing reaction id's.} + \item{verboseMode}{integer: verbosity level.} +} + + +\details{ + The function changes the expressions for the chosen reactions. + + Use onlyCheckGPR first to check the expressions. +} + +\author{Benjamin Braasch} + +\keyword{change} diff --git a/man/onlyCheckGPR.Rd b/man/onlyCheckGPR.Rd new file mode 100644 index 0000000..46a05cb --- /dev/null +++ b/man/onlyCheckGPR.Rd @@ -0,0 +1,30 @@ +\name{onlyCheckGPR} +\alias{onlyCheckGPR} + +\encoding{utf8} + +\title{Check the GPR Rules} + +\description{ + Checks the GPR Rules for the chosen reactions +} +\usage{ + onlyCheckGPR(model, gprRules, reactNr, verboseMode = 1) +} + +\arguments{ + \item{model}{An object of class \code{\linkS4class{modelorg}}} + \item{gprRules}{character: contains logical expressions.} + \item{reactNr}{An object of class \code{\linkS4class{reactId}}, a + numeric vector, or a character vector containing reaction id's.} + \item{verboseMode}{integer: verbosity level.} +} + + +\details{ + The function checks the expressions for the chosen reactions. +} + +\author{Benjamin Braasch} + +\keyword{check} diff --git a/man/optObj-class.Rd b/man/optObj-class.Rd new file mode 100644 index 0000000..6207d6a --- /dev/null +++ b/man/optObj-class.Rd @@ -0,0 +1,292 @@ +\name{optObj-class} + +\Rdversion{1.1} +\encoding{utf8} +\docType{class} + +\alias{optObj-class} + +\alias{lpExtPtr-class} +\alias{pointerToProb-class} +\alias{pointerToProb} + +\alias{clpPtr-class} +\alias{cplexPtr-class} +\alias{glpkPtr-class} +\alias{cplexPointer-class} + +\alias{dim,optObj-method} +\alias{method,optObj-method} +\alias{solver,optObj-method} +\alias{probType,optObj-method} +\alias{probType} + +\alias{checkSolStat} +\alias{getMeanReturn} +\alias{getMeanStatus} +\alias{wrong_type_msg} +\alias{wrong_solver_msg} + + +\title{Class \code{"optObj"}} + +\description{ + Structure of the class \code{"optObj"}. Objects extending \code{optObj} + returned by the constructor function \code{optObj}. These objects are used + as part of class \code{\linkS4class{sysBiolAlg}}. +} + +\section{Objects from the Class}{ + A virtual Class: No objects may be created from it. +} + +\section{Slots}{ + \describe{ + \item{\code{oobj}:}{ + Object of class \code{"pointerToProb"} containing a pointer to a problem + object (see section Note). + } + \item{\code{solver}:}{ + Object of class \code{"character"} containing the name of the solver + software (see \code{\link{SYBIL_SETTINGS}} for suitable values). + } + \item{\code{method}:}{ + Object of class \code{"character"} containing the method (algorithm) used + by the solver software (see \code{\link{SYBIL_SETTINGS}} for suitable + values). + } + \item{\code{probType}:}{ + Object of class \code{"character"} giving the problem type (see + \code{\link{optObj}} argument \code{pType} for suitable values). + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{dim}}{\code{signature(x = "optObj")}: + returns a vector \code{d} of length two with d[1] and d[2] containing the + number of rows and columns of the constraint matrix. + } + \item{\code{method}}{\code{signature(object = "optObj")}: + gets the \code{method} slot. + } + \item{\code{probType}}{\code{signature(object = "optObj")}: + gets the \code{probType} slot. + } + \item{\code{solver}}{\code{signature(object = "optObj")}: + gets the \code{solver} slot. + } + } +} + +\section{Further usefull Functions}{ + \describe{ + \item{\code{checkSolStat}:}{ + \code{checkSolStat(stat, solver = SYBIL_SETTINGS("SOLVER"))} + \cr + Returns the indices of problems with a non-optimal solution status, or + \code{NA} if it is not possible to retrieve a solution status. + \describe{ + \item{\code{stat}}{ + Vector of integer values containing the solution status. + } + \item{\code{solver}}{ + Single character string specifying the used solver + (see \code{\link{SYBIL_SETTINGS}}). + } + } + } + \item{\code{getMeanReturn}:}{ + \code{getMeanReturn(code, solver = SYBIL_SETTINGS("SOLVER"))} + \cr + Translates the return value (\code{code}) of a solver in a human + readable string. Returns \code{NA} if hte translation is not possible. + } + \item{\code{getMeanStatus}:}{ + \code{getMeanStatus(code, solver = SYBIL_SETTINGS("SOLVER"), env = NULL)} + \cr + Translates the soluton status value (\code{code}) of a solver in a + human readable string. Returns \code{NA} if hte translation is not + possible. Argument \code{env} is for use with IBM ILOG CPLEX holding an + object of class \code{cplexPtr} pointing to a IBM ILOG CPLEX environment. + } + \item{\code{wrong_type_msg}:}{ + \code{wrong_type_msg(lp)} + \cr + prints a warning message, if slot \code{oobj} from \code{lp} (an instance + of class \code{optObj}) does not contain a pointer to a valid solver. See + also \code{\link{SYBIL_SETTINGS}} for possible solvers. + } + \item{\code{wrong_solver_msg}:}{ + \code{wrong_solver_msg(lp, method, printOut = TRUE)} + \cr + if \code{printOut == TRUE}, it will print a warning message, + if \code{method} is not available for \code{solver} in \code{lp}. + } + } +} + +\section{Additional methods used by classes extending class \code{optObj}}{ + \describe{ + \item{\code{\link{addCols}}:}{ + add columns to the problem object. + } + \item{\code{\link{addRows}}:}{ + add rows to the problem object. + } + \item{\code{\link{addRowsCols}}:}{ + add rows and columns to the problem object. + } + \item{\code{\link{addColsToProb}}:}{ + add new columns (variables) to the problem object. + } + \item{\code{\link{addRowsToProb}}:}{ + add new rows (constraints) to the problem object. + } + \item{\code{\link{backupProb}}:}{ + copies a problem object into a new problem object. + } + \item{\code{\link{changeColsBnds}}:}{ + change column (variable) bounds in the problem object. + } + \item{\code{\link{changeColsBndsObjCoefs}}:}{ + change column (variable) bounds and objective coefficients in the + problem object. + } + \item{\code{\link{changeMatrixRow}}:}{ + change a row in the constraint matrix of the problem object. + } + \item{\code{\link{changeObjCoefs}}:}{ + change objective coefficients in the problem object. + } + \item{\code{\link{changeRowsBnds}}:}{ + change row bounds in the problem object. + } + \item{\code{\link{delProb}}:}{ + delete (free) memory associated to the pointer to the problem object. + } + \item{\code{\link{getColPrim}}:}{ + get primal value of variables after optimization. + } + \item{\code{\link{getColsLowBnds}}:}{ + get lower bounds of variables. + } + \item{\code{\link{getColsUppBnds}}:}{ + get upper bounds of variables. + } + \item{\code{\link{getFluxDist}}:}{ + get all primal values of variables after optimization (resulting flux + distribution). + } + \item{\code{\link{getNumCols}}:}{ + get number of columns in the problem object. + } + \item{\code{\link{getNumNnz}}:}{ + get number of non zero elements in the constraint matrix of the problem + object. + } + \item{\code{\link{getNumRows}}:}{ + get number of rows in the problem object. + } + \item{\code{\link{getObjCoefs}}:}{ + get objective coefficients in the problem object. + } + \item{\code{\link{getObjDir}}:}{ + get direction of optimization. + } + \item{\code{\link{getObjVal}}:}{ + get value of the objective function after optimization. + } + \item{\code{\link{getRedCosts}}:}{ + get reduced costs of all variables after optimization. + } + \item{\code{\link{getRowsLowBnds}}:}{ + get lower row bounds of the problem object. + } + \item{\code{\link{getRowsUppBnds}}:}{ + get lower bounds of the rows (constraints) of the problem object. + } + \item{\code{\link{getSolStat}}:}{ + get solution status after optimization. + } + \item{\code{\link{getSolverParm}}:}{ + get current parameter settings of the used solver. + } + \item{\code{\link{initProb}}:}{ + initialize problem object. + } + \item{\code{\link{loadLPprob}}:}{ + load data to the problem object. Use this method to generate problem + objects. + } + \item{\code{\link{loadQobj}}:}{ + load quadratic part of the objective function to the problem object. + } + \item{\code{\link{readProb}}:}{ + read problem object from file (e.g. lp formated). + } + \item{\code{\link{scaleProb}}:}{ + scaling of the constraint matrix. + } + \item{\code{\link{sensitivityAnalysis}}:}{ + perform sensitivity analysis. + } + \item{\code{\link{setObjDir}}:}{ + set direction of optimization. + } + \item{\code{\link{setRhsZero}}:}{ + set right hand side of the problem object to zero: + \eqn{\mbox{\boldmath$Sv$\unboldmath} = 0}{Sv = 0}. + } + \item{\code{\link{setSolverParm}}:}{ + set parameters for the used solver. + } + \item{\code{\link{solveLp}}:}{ + run optimization with the solver mentioned in slot \code{\link{solver}} and with + the method given by slot \code{\link{method}}. + } + \item{\code{\link{writeProb}}:}{ + write problem object to file (e.g. in lp format). + } + } +} + +\details{ + The intention of class \code{optObj} is, to provide a flexible + user interface to several optimization software products. The + methods here working on the slot \code{oobj} are interface functions + to low level functions invoking corresponding C functions. + Basically, the user has not to care about the nature of the solver, + or solver-specific functions. That is done by the class. +} + +\note{ + The class \code{pointerToProb} contains an external pointer to a problem + object (usually a C/C++ pointer). This is for \pkg{glpkAPI} an object of class + \code{\link[glpkAPI]{glpkPtr}}, for \pkg{clpAPI} an object of class + \code{\linkS4class{externalptr}}, for \pkg{lpSolveAPI} an object + of class \code{lpExtPtr} and for \pkg{cplexAPI} an object of class + \code{cplexPointer}. + + The class \code{cplexPointer} has two slots \code{env} and \code{lp}, each of + class \code{cplexPtr}. %\code{\link[cplexAPI]{cplexPtr}}. + To access for example the environment + pointer from an object of class \code{optObj}, one can write + \code{lp@oobj@env}. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + The constructor function \code{\link{sysBiolAlg}} for objects extending + class \code{\linkS4class{sysBiolAlg}}; + The constructor function \code{\link{optObj}}; \code{\link{SYBIL_SETTINGS}} + and \code{\link{checkDefaultMethod}}. +} + +\examples{ + showClass("optObj") +} + +\keyword{classes} diff --git a/man/optObj.Rd b/man/optObj.Rd new file mode 100644 index 0000000..664d846 --- /dev/null +++ b/man/optObj.Rd @@ -0,0 +1,71 @@ +\name{optObj} +\alias{optObj} + +\title{ + General Constructor Function For Objects of Class \code{optObj} +} +\description{ + This function serves as a user constructor function for objects of class + \code{\linkS4class{optObj}}. +} +\usage{ + optObj(solver = SYBIL_SETTINGS("SOLVER"), + method = SYBIL_SETTINGS("METHOD"), + pType = "lp", prefix = "optObj", sep = "_") +} + +\arguments{ + \item{solver}{ + A single character string giving the name of the solver package to use. + See \code{\link{SYBIL_SETTINGS}} for possible values.\cr + Default: \code{SYBIL_SETTINGS("SOLVER")}. + } + \item{method}{ + A single character string containing the name of the method used by + \code{solver}. See \code{\link{SYBIL_SETTINGS}} for possible values. + If missing or not available, the default method for \code{solver} is used + (see also \code{\link{checkDefaultMethod}}).\cr + Default: \code{SYBIL_SETTINGS("METHOD")}. + } + \item{pType}{ + A single character string containing the type of optimization problem. Can + be \code{"lp"}: linear programming, \code{"mip"}: mixed integer programming + or \code{"qp"}: quadratic programming.\cr + Default: \code{"lp"}. + } + \item{prefix}{ + A single character string containing a prefix for the new class name.\cr + Default: \code{"optObj"}. + } + \item{sep}{ + A single character string containing a separator for \code{prefix} and + \code{solver}.\cr + Default: \code{"_"}. + } +} + +\details{ + If argument \code{solver} is set to \code{"foo"} and \code{prefix} is set + to \code{"optObj"} (default), \code{optObj} will try to build an instance of + class \code{optObj_foo}. If \code{solver} does not contain a valid name of a + solver package (this is checked by \code{\link{checkDefaultMethod}}), the + default solver package will be used (see \code{\link{SYBIL_SETTINGS}}). + For the name of the class, the arguments \code{prefix} and \code{solver} are + stick together separated by \code{sep} (default: a single underscore + \code{"_"}): \code{prefix_solver}. +} + +\value{ + An instance of a subclass of class \code{\linkS4class{optObj}}. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{optObj}}, \code{\link{SYBIL_SETTINGS}} + and \code{\link{checkDefaultMethod}}. +} + +\keyword{classes} diff --git a/man/optObj_clpAPI-class.Rd b/man/optObj_clpAPI-class.Rd new file mode 100644 index 0000000..2f8e08c --- /dev/null +++ b/man/optObj_clpAPI-class.Rd @@ -0,0 +1,60 @@ +\name{optObj_clpAPI-class} + +\Rdversion{1.1} +\encoding{utf8} +\docType{class} + +\alias{optObj_clpAPI-class} + +\title{Class \code{"optObj_clpAPI"}} + +\description{ + Structure of the class \code{"optObj_clpAPI"}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the constructor function \code{optObj}: + + \code{test <- optObj(solver = "clpAPI")}. +} + +\section{Slots}{ + \describe{ + \item{\code{oobj}:}{ + Object of class \code{"pointerToProb"} containing a pointer to a + \pkg{clpAPI} problem object. + } + \item{\code{solver}:}{ + Object of class \code{"character"} containing the name of the solver + software (see \code{\link{SYBIL_SETTINGS}} for suitable values). + } + \item{\code{method}:}{ + Object of class \code{"character"} containing the method (algorithm) used + by the solver software (see \code{\link{SYBIL_SETTINGS}} for suitable + values). + } + \item{\code{probType}:}{ + Object of class \code{"character"} giving the problem type (see + \code{\link{optObj}} for suitable values). + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optObj}"}, directly. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}} +} + +\examples{ + showClass("optObj_clpAPI") +} + +\keyword{classes} + + diff --git a/man/optObj_cplexAPI-class.Rd b/man/optObj_cplexAPI-class.Rd new file mode 100644 index 0000000..a0da30e --- /dev/null +++ b/man/optObj_cplexAPI-class.Rd @@ -0,0 +1,60 @@ +\name{optObj_cplexAPI-class} + +\Rdversion{1.1} +\encoding{utf8} +\docType{class} + +\alias{optObj_cplexAPI-class} + +\title{Class \code{"optObj_cplexAPI"}} + +\description{ + Structure of the class \code{"optObj_cplexAPI"}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the constructor function \code{optObj}: + + \code{test <- optObj(solver = "cplexAPI")}. +} + +\section{Slots}{ + \describe{ + \item{\code{oobj}:}{ + Object of class \code{"pointerToProb"} containing a pointer to a + \pkg{cplexAPI} problem object. + } + \item{\code{solver}:}{ + Object of class \code{"character"} containing the name of the solver + software (see \code{\link{SYBIL_SETTINGS}} for suitable values). + } + \item{\code{method}:}{ + Object of class \code{"character"} containing the method (algorithm) used + by the solver software (see \code{\link{SYBIL_SETTINGS}} for suitable + values). + } + \item{\code{probType}:}{ + Object of class \code{"character"} giving the problem type (see + \code{\link{optObj}} for suitable values). + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optObj}"}, directly. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}} +} + +\examples{ + showClass("optObj_cplexAPI") +} + +\keyword{classes} + + diff --git a/man/optObj_glpkAPI-class.Rd b/man/optObj_glpkAPI-class.Rd new file mode 100644 index 0000000..4b1fcf8 --- /dev/null +++ b/man/optObj_glpkAPI-class.Rd @@ -0,0 +1,60 @@ +\name{optObj_glpkAPI-class} + +\Rdversion{1.1} +\encoding{utf8} +\docType{class} + +\alias{optObj_glpkAPI-class} + +\title{Class \code{"optObj_glpkAPI"}} + +\description{ + Structure of the class \code{"optObj_glpkAPI"}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the constructor function \code{optObj}: + + \code{test <- optObj(solver = "glpkAPI")}. +} + +\section{Slots}{ + \describe{ + \item{\code{oobj}:}{ + Object of class \code{"pointerToProb"} containing a pointer to a + \pkg{glpkAPI} problem object. + } + \item{\code{solver}:}{ + Object of class \code{"character"} containing the name of the solver + software (see \code{\link{SYBIL_SETTINGS}} for suitable values). + } + \item{\code{method}:}{ + Object of class \code{"character"} containing the method (algorithm) used + by the solver software (see \code{\link{SYBIL_SETTINGS}} for suitable + values). + } + \item{\code{probType}:}{ + Object of class \code{"character"} giving the problem type (see + \code{\link{optObj}} for suitable values). + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optObj}"}, directly. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}} +} + +\examples{ + showClass("optObj_glpkAPI") +} + +\keyword{classes} + + diff --git a/man/optObj_lpSolveAPI-class.Rd b/man/optObj_lpSolveAPI-class.Rd new file mode 100644 index 0000000..4d7d827 --- /dev/null +++ b/man/optObj_lpSolveAPI-class.Rd @@ -0,0 +1,75 @@ +\name{optObj_lpSolveAPI-class} + +\Rdversion{1.1} +\encoding{utf8} +\docType{class} + +\alias{return_codeLPSOLVE} +\alias{loadMatrixPerColumnLPSOLVE} + +\alias{optObj_lpSolveAPI-class} + +\title{Class \code{"optObj_lpSolveAPI"}} + +\description{ + Structure of the class \code{"optObj_lpSolveAPI"}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the constructor function \code{optObj}: + + \code{test <- optObj(solver = "lpSolveAPI")}. +} + +\section{Slots}{ + \describe{ + \item{\code{oobj}:}{ + Object of class \code{"pointerToProb"} containing a pointer to a + \pkg{lpSolveAPI} problem object. + } + \item{\code{solver}:}{ + Object of class \code{"character"} containing the name of the solver + software (see \code{\link{SYBIL_SETTINGS}} for suitable values). + } + \item{\code{method}:}{ + Object of class \code{"character"} containing the method (algorithm) used + by the solver software (see \code{\link{SYBIL_SETTINGS}} for suitable + values). + } + \item{\code{probType}:}{ + Object of class \code{"character"} giving the problem type (see + \code{\link{optObj}} for suitable values). + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optObj}"}, directly. +} + +\section{Further usefull Functions}{ + \describe{ + \item{\code{return_codeLPSOLVE}:}{(\code{code}) + prints a human readable translation of return codes of lpSolveAPI. + } + \item{\code{loadMatrixPerColumnLPSOLVE}:}{(\code{lpmod, constMat}) + load a constraint matrix (an object of class \code{\link{Matrix}}) to a + \pkg{lpSolveAPI} problem object column by column. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}} +} + +\examples{ + showClass("optObj_lpSolveAPI") +} + +\keyword{classes} + + diff --git a/man/optimizeProb-methods.Rd b/man/optimizeProb-methods.Rd new file mode 100644 index 0000000..7561b76 --- /dev/null +++ b/man/optimizeProb-methods.Rd @@ -0,0 +1,343 @@ +\name{optimizeProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{optimizeProb} +\alias{optimizeProb-methods} +\alias{optimizeProb,modelorg-method} +\alias{optimizeProb,sysBiolAlg-method} + +\title{Optimize Problem Object} + +\description{ + The generic \code{optimizeProb} performs the optimization of a mathematical + programming object. +} + +\usage{ +\S4method{optimizeProb}{modelorg}(object, + algorithm = SYBIL_SETTINGS("ALGORITHM"), + gene = NULL, + react = NULL, + lb = NULL, + ub = NULL, + retOptSol = TRUE, + obj_coef = NULL, + lpdir = NULL, + mtfobj = NULL, + fldind = TRUE, + prCmd = NA, + poCmd = NA, + prCil = NA, + poCil = NA, + ...) + +\S4method{optimizeProb}{sysBiolAlg}(object, + react = NULL, + lb = NULL, + ub = NULL, + obj_coef = NULL, + lpdir = NULL, + fldind = TRUE, + resetChanges = TRUE, + prCmd = NA, + poCmd = NA, + prCil = NA, + poCil = NA) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "modelorg")}}{ + Translates the object of class \code{\linkS4class{modelorg}} into an + object of class \code{\linkS4class{sysBiolAlg}} and calls + \code{optimizeProb} again. + } + \item{\code{signature(object = "sysBiolAlg")}}{ + Run optimization with the given problem object. + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{modelorg}} or + \code{\linkS4class{sysBiolAlg}}. + } + \item{algorithm}{ + A single character string giving the name of the algorithm to use. See + parameter \code{"ALGORITHM"} in \code{\link{SYBIL_SETTINGS}} for possible + values.\cr + Default: \code{SYBIL_SETTINGS("ALGORITHM")}. + } + \item{gene}{ + A character or integer vector containing gene id's or indices of gene id's + in \code{\link{allGenes}(model)}. If arguments \code{lb} and/or \code{ub} + are additionally used (not \code{NULL}), upper and lower bounds will be + applied to all fluxes on which the deletion of the genes given in + \code{gene} have an effect. In this case, the first value in \code{lb} and + \code{ub} is used. + Default: \code{NULL}. + } + \item{react}{ + An object of class \code{\linkS4class{reactId}}, character or integer. + Specifies the fluxes (variables) for which to change the upper and lower + bound (see also arguments \code{lb} and \code{ub}) or objective coefficients + (see also argument \code{obj_coef}). For class + \code{\linkS4class{sysBiolAlg}}, it must be numeric. For class + \code{\linkS4class{modelorg}}, setting \code{react} as no effect, if + \code{gene} is also not \code{NULL}.\cr + Default: \code{NULL}. + } + \item{lb}{ + Numeric vector, must have the same length as \code{react}. Contains the new + values for the lower bounds of fluxes (variables) mentioned in \code{react}. + If set to \code{NULL}, lower bounds for variables in \code{react} will be + left unchanged. For class \code{\linkS4class{modelorg}}: if \code{lb} is of length + one, \code{lb} is used for all elements in \code{react}.\cr + Default: \code{NULL}. + } + \item{ub}{ + Same functionality as \code{lb}, but for upper bounds.\cr + Default: \code{NULL}. + } + \item{obj_coef}{ + Numeric vector, must have the same length as \code{react}. Contains the new + values for the objective coefficients of fluxes (variables) mentioned in + \code{react}. All other objective coefficients stay untouched. If set to + \code{NULL}, objective coefficients for variables in \code{react} will be + left unchanged. For class \code{\linkS4class{modelorg}}: if \code{obj_coef} is of + length one, \code{obj_coef} is used for all elements in \code{react}.\cr + Default: \code{NULL}. + } + \item{lpdir}{ + Character value, direction of optimization. Can be set to \code{"min"} for + minimization or \code{"max"} for maximization.\cr + Default: \code{SYBIL_SETTINGS("OPT_DIRECTION")}. + } + \item{mtfobj}{ + Only used, if argument \code{algorithm} is set to \code{"mtf"}. + A single numeric value giving a previously calculated optimized value of the + objective function given in the model. + The objective function of the model will be fixed to this value during + optimization. If set to \code{NULL}, it will be computed by means of the + \code{"\link[=sysBiolAlg_fba-class]{fba}"} algorithm. If additionally + arguments \code{solver} and \code{method} are set, they will be used here + too.\cr + Default: \code{NULL}. + } + \item{fldind}{ + Boolean value. If set to \code{TRUE}, (default) indices in \code{"react"} are used + only for reactions. If set to \code{FALSE}, indices in \code{"react"} are used for + all variables during optimization, e.g. also for additional variables introduced by + the \code{\link{mtf}} algorithm. Currently unused by class + \code{\linkS4class{sysBiolAlg_room}}.\cr + Default: \code{TRUE}. + } + \item{resetChanges}{ + Boolean value. If set to \code{TRUE}, (default) modifications of the + problem object will be reset to their original values (e.g. changing + upper and lower bounds for certain reactions). If set to \code{FALSE}, + modifications will stay in the model.\cr + Default: \code{TRUE}. + } + \item{prCmd}{ + A list of preprocessing commands. See Details below.\cr + Default: \code{NA}. + } + \item{poCmd}{ + A list of postprocessing commands. See Details below.\cr + Default: \code{NA}. + } + \item{prCil}{ + Can be used if \code{optimizeProb} is called several times (like in + \code{\link{optimizer}}). The argument \code{prCil} gets the value of the + loop variable and passes it to the preprocessing function. There, one + can access it via the keyword \dQuote{LOOP_VAR}. See also + \code{\link{optimizer}}.\cr + Default: \code{NA}. + } + \item{poCil}{ + Same as \code{prCil}, but for postprocessing.\cr + Default: \code{NA}. + } + \item{retOptSol}{ + Boolean. Return an object of class + \code{\linkS4class{optsol_optimizeProb}} or + just a list containing the results.\cr + Default: \code{TRUE}. + } + \item{\dots}{ + Only for the \code{modelorg-method}: further arguments passed to + \code{\link{sysBiolAlg}}. See Details below. + } +} + +\details{ + The arguments \code{prCmd} and \code{poCmd} can be used to execute \R commands + working on the problem object. All commands in \code{prCmd} are executed + immediately before solving the problem; all commands in \code{poCmd} are + executed after the problem has been solved. In all other aspects, the + arguments work the same. The value of \code{prCmd} or \code{poCmd} are + lists of character vectors (each list element is one command). Each command + is a character vector and should be built as follows: + \itemize{ + \item The first element is the name of the function to call. + \item All other elements are arguments to the function named in the + first element. + \item If any argument is character, enclose it in single + quotes \code{' '}. + \item Use the keyword \kbd{LP_PROB} in order to refer to the variable name + of the problem object (object of class + \code{\linkS4class{optObj}}). + \item If the length of the character vector is one, it is treated as a + function call with the problem object + (object of class \code{\linkS4class{optObj}}) as single + argument. + } + The result will be an object of class \code{\link{ppProc}}. + A few examples for arguments \code{prCmd} or \code{poCmd} (all arguments must + be lists, see examples section below): + \preformatted{ + sensitivityAnalysis + } + will be translated to the command + \preformatted{ + sensitivityAnalysis(LP_PROB) + } + with \code{LP_PROB} being the placeholder for the variable name of the + problem object. The vector + \preformatted{ + c("writeProb", "LP_PROB", "'Ec_core.lp'", "'lp'") + } + will be translated to the command + \preformatted{ + writeProb(LP_PROB, 'Ec_core.lp', 'lp') + } + The first element will be the function name and the others the arguments to + that function. The list of commands + \preformatted{ + list("sensitivityAnalysis", + c("getDjCPLEX", "LP_PROB@oobj@env", + "LP_PROB@oobj@lp", "0", "react_num(Ec_core)-1" + ) + ) + } + will be translated to the commands + \preformatted{ + sensitivityAnalysis(LP_PROB) + getDjCPLEX(LP_PROB@oobj@env, LP_PROB@oobj@lp, + 0, react_num(Ec_core)-1) + } + For more information on the usage of \code{prCmd} and \code{poCmd}, see the + examples section below. + + The method \code{optimizeProb} for class \code{\linkS4class{modelorg}} + generates a subclass of class \code{\linkS4class{sysBiolAlg}} + and calls \code{optimizeProb} for that object again. Argument \code{MoreArgs} + is used to transport arguments to the second \code{optimizeProb} call. + Argument \code{\dots} instead is used to transport arguments to the constructor + function \code{\link{sysBiolAlg}}, for example \code{algorithm}, + \code{solver}, \code{method} and \code{solverParm}. + See \code{\link{SYBIL_SETTINGS}} for possible values. + + Arguments \code{gene}, \code{react}, \code{lb}, \code{ub} and \code{react} + cause changes in the problem object (object of class + \code{\linkS4class{optObj}}, slot \code{problem} of class + \code{\linkS4class{sysBiolAlg}}). These changes will be reset + immediately after optimization if argument \code{resetChanges} is set to + \code{TRUE}, otherwise changes will persist. +} + +\value{ + Calls to \code{optimizeProb} returns either an object of class + \code{\linkS4class{optsol_optimizeProb}} of length one + if argument \code{retOptSol} is set to \code{TRUE} and \code{object} is of + class \code{\linkS4class{modelorg}}, or a list containing the results of the + optimization: + \item{ok}{ + Return value of the optimizer (e.g. \dQuote{solution process was + successful} or \dQuote{time limit exceeded}). + } + \item{obj}{ + Value of the objective function after optimization. + } + \item{stat}{ + Status value of the optimization (e.g. \dQuote{solution is optimal} or + \dQuote{no feasible solution exists}). + } + \item{fluxes}{ + The resulting flux distribution. + } + \item{fldind}{ + Pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the solution object + represents reaction \code{i} in the original network. + } + \item{preP}{ + An object of class \code{\link{ppProc}} if a preprocessing command + was given. + } + \item{postP}{ + An object of class \code{\link{ppProc}} if a postprocessing command + was given. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{modelorg}}, \code{\link{applyChanges}} and \code{\linkS4class{sysBiolAlg}}. +} + +\examples{ +\dontrun{ +## 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 = SYBIL_SETTINGS("SOLVER")). + +## load the example data set +data(Ec_core) + +## run optimizeProb(), Ec_sf will be an object of +## class optsol_optimizeProb +Ec_sf <- optimizeProb(Ec_core) + +## run optimizeProb(), Ec_sf will be a list +Ec_sf <- optimizeProb(Ec_core, retOptSol = FALSE) + +## do FBA, change the upper and lower bounds for the reactions +## "ATPM" and "PFK". +optimizeProb(Ec_core, react = c("ATPM", "PFK"), + lb = c(3, -3), ub = c(5, 6)) + +## do FBA, perform sensitivity analysis after optimization +optimizeProb(Ec_core, poCmd = list("sensitivityAnalysis")) + +## do FBA, write the problem object to file in lp-format +optimizeProb(Ec_core, + poCmd = list(c("writeProb", "LP_PROB", + "'Ec_core.lp'", "'lp'"))) + +## do FBA, use "cplexAPI" as lp solver. Get all lower bounds before +## solving the problem. After solving, perform a sensitivity +## analysis and retrieve the reduced costs +opt <- optimizeProb(Ec_core, solver = "cplexAPI", + prCmd = list(c("getColsLowBnds", "LP_PROB", "1:77")), + poCmd = list("sensitivityAnalysis", + c("getDjCPLEX", + "LP_PROB@oobj@env", + "LP_PROB@oobj@lp", + "0", "react_num(Ec_core)-1"))) +## get lower bounds +preProc(opt) +## get results of sensitivity analysis +postProc(opt) +} +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/optimizer.Rd b/man/optimizer.Rd new file mode 100644 index 0000000..5c8cac3 --- /dev/null +++ b/man/optimizer.Rd @@ -0,0 +1,253 @@ +\name{optimizer} +\alias{optimizer} + +\encoding{utf8} + +\title{Performs Series of Optimizations} + +\description{ + The function \code{optimizer} is a wrapper to the + \code{\linkS4class{sysBiolAlg}}-method \code{\link{optimizeProb}}. + While \code{optimizeProb} runs one optimization, \code{optimizer} is designed + to run a series of optimization by re-optimizing a given problem object + (successive calls to \code{\link{optimizeProb}}. +} + +\usage{ +optimizer(model, react, lb, ub, obj_coef, lpdir, + algorithm = SYBIL_SETTINGS("ALGORITHM"), + mtfobj = NULL, + setToZero = FALSE, + rebuildModel = FALSE, + fld = "none", + prCmd = NA, poCmd = NA, + prDIR = NULL, poDIR = NULL, + verboseMode = 2, + ...) +} + +\arguments{ + \item{model}{ + An object of class \code{modelorg}. + } + \item{react}{ + A list of numeric vectors. Each value must point to a reaction id present + in \code{model}. The length of the list in \code{react} determines the + number of optimizations to run. Each list element can be used in conjunction + with arguments \code{lb} and \code{ub} or \code{obj_coef} and \code{lpdir}. + The parameters given in this arguments will be set temporarily for each + optimization. + } + \item{lb}{ + A numeric vector or list of the same length as \code{react} or a matrix with + the number of rows equal to the length of \code{react} containing the lower + bounds for the reaction rates of reactions (variables) given in argument + \code{react}. If set to \code{NULL}, no lower bounds will be changed. + If \code{lb} is a vector, \code{lb[k]} is used as lower bound for all + reactions given in \code{react[k]}. If \code{lb} is a list, \code{lb[k]} + must have the same length as \code{react[k]}. If \code{lb} is a matrix, each + row serves as lower bound for the reactions given in each element of + \code{react} (all elements in \code{react} must have the same length).\cr + Default: \code{NULL}. + } + \item{ub}{ + A numeric vector or list of the same length as \code{react} or a matrix with + the number of rows equal to the length of \code{react} containing the upper + bounds for the reaction rates of reactions (variables) given in argument + \code{react}. If set to \code{NULL}, no upper bounds will be changed. + If \code{ub} is a vector, \code{ub[k]} is used as upper bound for all + reactions given in \code{react[k]}. If \code{ub} is a list, \code{ub[k]} + must have the same length as \code{react[k]}. If \code{ub} is a matrix, each + row serves as upper bound for the reactions given in each element of + \code{react} (all elements in \code{react} must have the same length).\cr + Default: \code{NULL}. + } + \item{obj_coef}{ + A numeric vector or list of the same length as \code{react} or a matrix with + the number of rows equal to the length of \code{react} containing the + objective coefficients for the reactions (variables) given in argument + \code{react}. If set to \code{NULL}, no objective coefficients will be + changed. If \code{obj_coef} is a vector, \code{obj_coef[k]} is used as + objective coefficients for all reactions given in \code{react[k]}. + If \code{obj_coef} is a list, \code{obj_coef[k]} must have the same length + as \code{react[k]}. If \code{obj_coef} is a matrix, each row serves as + objective coefficient for the reactions given in each element of + \code{react} (all elements in \code{react} must have the same length).\cr + Default: \code{NULL}. + } + \item{lpdir}{ + A character vector of the same length as \code{react} containing the + direction of optimization for each optimization. Possible values are + \code{"min"} for minimization, or \code{"max"} for maximization. If set to + \code{NULL}, optimization direction will not change.\cr + Default: \code{NULL}. + } + \item{algorithm}{ + A single character value giving the algorithm to compute genetic + perturbations. Can be + \code{"\link[=sysBiolAlg_fba-class]{fba}"}: flux-balance analysis, + \code{"\link[=sysBiolAlg_mtf-class]{mtf}"}: minimization of absolute total + flux (see Details below), + \code{"\link[=sysBiolAlg_moma-class]{moma}"}: minimization of + metabolic adjustment (MOMA), + \code{"\link[=sysBiolAlg_lmoma-class]{lmoma}"}: linear version of MOMA, + \code{"\link[=sysBiolAlg_room-class]{room}"}: regulatory on/off + minimization (ROOM) or + \code{"\link[=sysBiolAlg_fv-class]{fv}"}: flux variability analysis.\cr + Default: \code{SYBIL_SETTINGS("ALGORITHM")}. + } + \item{mtfobj}{ + Only used, if argument \code{algorithm} is set to \code{"mtf"}. + A numeric vector of the same length as \code{react} containing previously + calculated optimized values of the objective function given in the model. + The objective function of the model will be fixed to this values in each + optimization. If set to \code{NULL}, they will be computed by means of the + \code{"\link[=sysBiolAlg_fba-class]{fba}"} algorithm. If additionally + arguments \code{solver} and \code{method} are set, they will be used here + too.\cr + Default: \code{NULL}. + } + \item{setToZero}{ + Logical: If the mathematical programming software returns a solution status + which is not optimal, set the corresponding objective value to zero.\cr + Default: \code{FALSE}. + } + \item{rebuildModel}{ + Logical. If set to \code{TRUE}, the problem object will be rebuilt prior + each round of optimization. + Default: \code{FALSE}. + } + \item{fld}{ + Type of flux distribution to return. If set to \code{"none"}, no flux + distribution will be returned. If set to \code{"fluxes"}, only the real + flux distribution is returned, meaning all variable values after + optimization representing a flux (reaction) in the model. If set to + \code{"all"}, all variable values are returned. If \code{algorithm} is set + to \code{"mtf"} and \code{fld} equals \code{"none"}, argument \code{fld} + will be changed to \code{"fluxes"}.\cr + Default: \code{"none"}. + } + \item{prCmd}{ + A list of preprocessing commands passed to \code{\link{optimizeProb}}. + See there for details.\cr + Default: \code{NA}. + } + \item{poCmd}{ + A list of postprocessing commands passed to \code{\link{optimizeProb}}. + See there for details.\cr + Default: \code{NA}. + } + \item{prDIR}{ + A numeric or character vector, indicating in which round of optimization + the preprocessing command(s) will be executed. \code{prDIR = c(2, 5, 10)} + executes the commands in prCmd before the second, 5th and 10th optimization. + + If \code{prDIR} is a character vector, for example + \code{prDIR = c("10")}, the preprocessing commands given in \code{prCmd} + will pe executed every 10th round of optimization. + + If \code{prDIR} is character and has length \code{2}, the first element is + an offset to the following elements. \code{prDIR = c("-2", "10")} will do + the preprocessing on every 10th round of optimization, beginning in round + number \code{10 - 2 = 8}.\cr + Default: \code{NULL}. + } + \item{poDIR}{ + The same as \code{prDIR}, but for postprocessing. + Default: \code{NULL}. + } + \item{verboseMode}{ + Single integer value, giving the amount of output to the console. Use + \code{\link{sink}} to redirect output to a file. If \code{verboseMode == 1} + status messages will be printed, if \code{verboseMode == 2} additionally + a progress bar will be produced. If \code{verboseMode > 2}, intermediate + results will be printed. Use \code{\link{suppressMessages}} to disable any + output to the console.\cr + Default: \code{2}. + } + \item{\dots}{ + Further arguments passed to \code{\link{sysBiolAlg}}. + } +} + +\value{ + A list containing the results of the optimization: + \item{solver}{ + A single character string indicating the used mathematical programming + software. + } + \item{method}{ + A single character string indicating the used optimization method by the + mathematical programming software. + } + \item{algorithm}{ + A single character string indicating the used algorithm. + } + \item{lp_num_cols}{ + Number of columns (variables) in the problem object. + } + \item{lp_num_rows}{ + Number of rows (constraints) in the problem object. + } + \item{obj}{ + A numeric vector containing the values of the objective function after + optimization. + } + \item{ok}{ + A numeric vector containing the return values of the optimizer + (e.g. \dQuote{solution process was successful} or + \dQuote{time limit exceeded}). + } + \item{stat}{ + A numeric vector containing the status value of the optimization (e.g. + \dQuote{solution is optimal} or \dQuote{no feasible solution exists}). + } + \item{lp_dir}{ + A factor variable indicating the direction of optimization for each + optimization. + } + \item{fldind}{ + Pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the solution object + represents reaction \code{i} in the original network. + } + \item{fluxdist}{ + The resulting flux distribution. + } + \item{prAna}{ + An object of class \code{\link{ppProc}} if a preprocessing command + was given. + } + \item{poAna}{ + An object of class \code{\link{ppProc}} if a postprocessing command + was given. + } + \item{alg_par}{ + A named list of algorithm specific parameters. + } +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + Class \code{\linkS4class{sysBiolAlg}}, and constructor function + \code{\link{sysBiolAlg}}, \code{\link{optimizeProb}} + and \code{\link{SYBIL_SETTINGS}}. +} + + +\keyword{optimize} + diff --git a/man/optsol-class.Rd b/man/optsol-class.Rd new file mode 100644 index 0000000..7b93e53 --- /dev/null +++ b/man/optsol-class.Rd @@ -0,0 +1,338 @@ +\name{optsol-class} + +\docType{class} + +\alias{optsol-class} +\alias{optsol} + +\alias{checkStat,optsol-method} +\alias{checkStat} + +\alias{algorithm,optsol-method} +\alias{algorithm} +\alias{algorithm<-,optsol-method} +\alias{algorithm<-} +\alias{alg_par,optsol-method} +\alias{alg_par<-,optsol-method} +\alias{fldind,optsol-method} +\alias{fldind} +\alias{fldind<-,optsol-method} +\alias{fldind<-} +\alias{fluxdist,optsol-method} +\alias{fluxdist} +\alias{fluxdist<-,optsol-method} +\alias{fluxdist<-} +\alias{fluxes,optsol-method} +\alias{fluxes} +\alias{fluxes<-,optsol-method} +\alias{fluxes<-} +\alias{lp_dir,optsol-method} +\alias{lp_dir} +\alias{lp_dir<-,optsol,character-method} +\alias{lp_dir<-,optsol,factor-method} +\alias{lp_dir<-,optsol,numeric-method} +\alias{lp_dir<-} +\alias{lp_num_cols,optsol-method} +\alias{lp_num_cols} +\alias{lp_num_cols<-,optsol-method} +\alias{lp_num_cols<-} +\alias{lp_num_rows,optsol-method} +\alias{lp_num_rows} +\alias{lp_num_rows<-,optsol-method} +\alias{lp_num_rows<-} +\alias{lp_obj,optsol-method} +\alias{lp_obj} +\alias{lp_obj<-,optsol-method} +\alias{lp_obj<-} +\alias{lp_ok,optsol-method} +\alias{lp_ok} +\alias{lp_ok<-,optsol-method} +\alias{lp_ok<-} +\alias{lp_stat,optsol-method} +\alias{lp_stat} +\alias{lp_stat<-,optsol-method} +\alias{lp_stat<-} +\alias{method,optsol-method} +\alias{method} +\alias{method<-,optsol-method} +\alias{method<-} +\alias{mod_id,optsol-method} +\alias{mod_id<-,optsol-method} +\alias{mod_key<-,optsol-method} +\alias{mod_key,optsol-method} +\alias{mod_obj,optsol-method} +\alias{mod_obj} +\alias{nfluxes,optsol-method} +\alias{nfluxes} +\alias{num_of_prob,optsol-method} +\alias{num_of_prob} +\alias{num_of_prob<-,optsol-method} +\alias{num_of_prob<-} +\alias{obj_coef,optsol-method} +\alias{obj_coef<-,optsol-method} +\alias{obj_func,optsol-method} +\alias{obj_func} +\alias{obj_func<-,optsol-method} +\alias{obj_func<-} +\alias{react_id,optsol-method} +\alias{react_id<-,optsol-method} +\alias{show,optsol-method} +\alias{solver,optsol-method} +\alias{solver} +\alias{solver<-,optsol-method} +\alias{solver<-} +\alias{length,optsol-method} +\alias{plot,optsol,missing-method} + +\encoding{utf8} + +\title{Class optsol} + +\description{ + The class \code{optsol} provides data structures to store and access the + results of optimizations. This class is extended by other classes and will + not be used as is. The representation of class \code{optsol} is used as + superclass. +} + +\section{Objects from the Class}{ + A virtual Class: No objects may be created from it. +} + +\section{Slots}{ + \describe{ + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. If no flux distribution is available, slot \code{lp_obj} + contains the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{algorithm<-}:}{\code{signature(object = "optsol")}: + sets the \code{algorithm} slot. + } + \item{\code{algorithm}:}{\code{signature(object = "optsol")}: + gets the \code{algorithm} slot. + } + \item{alg_par}{\code{signature(object = "optsol")}: + gets the \code{alg_par} slot. + } + \item{alg_par<-}{\code{signature(object = "optsol")}: + sets the \code{alg_par} slot. + } + \item{\code{checkStat}:}{\code{signature(opt = "optsol")}: + returns the indices of problems with a non optimal solution status. + } + \item{\code{fldind<-}:}{\code{signature(object = "optsol")}: + sets the \code{fldind} slot. + } + \item{\code{fldind}:}{\code{signature(object = "optsol")}: + gets the \code{fldind} slot. + } + \item{\code{fluxdist<-}:}{\code{signature(object = "optsol")}: + sets the \code{fluxdist} slot. + } + \item{\code{fluxdist}:}{\code{signature(object = "optsol")}: + gets the \code{fluxdist} slot. + } + \item{\code{fluxes<-}:}{\code{signature(object = "optsol")}: + sets the \code{fluxes} slot of slot \code{fluxdist}. + } + \item{\code{fluxes}:}{\code{signature(object = "optsol")}: + gets the \code{fluxes} slot of slot \code{fluxdist}. + } + \item{\code{plot}:}{ + \code{signature(x = "optsol")}: plots a \code{\link{histogram}} of the + values of the objective function given in the model in optimal state. + Additional arguments can be passed to \code{\link{histogram}} via the + \code{\dots} argument. + } + \item{\code{length}:}{\code{signature(x = "optsol")}: + returns the number of optimizations. + } + \item{\code{lp_dir<-}:}{\code{signature(object = "optsol", value = "character")}: + sets the \code{lp_dir} slot. Argument \code{value} can be \code{"min"} + (minimization) or \code{"max"} (maximization). + } + \item{\code{lp_dir<-}:}{\code{signature(object = "optsol", value = "factor")}: + sets the \code{lp_dir} slot. + } + \item{\code{lp_dir<-}:}{\code{signature(object = "optsol", value = "numeric")}: + sets the \code{lp_dir} slot. Argument \code{value} can be \code{1} + (minimization) or \code{-1} (maximization). + } + \item{\code{lp_dir}:}{\code{signature(object = "optsol")}: + gets the \code{lp_dir} slot. + } + \item{\code{lp_num_cols<-}:}{\code{signature(object = "optsol")}: + sets the \code{lp_num_cols} slot. + } + \item{\code{lp_num_cols}:}{\code{signature(object = "optsol")}: + gets the \code{lp_num_cols} slot. + } + \item{\code{lp_num_rows<-}:}{\code{signature(object = "optsol")}: + sets the \code{lp_num_rows} slot. + } + \item{\code{lp_num_rows}:}{\code{signature(object = "optsol")}: + gets the \code{lp_num_rows} slot. + } + \item{\code{lp_obj<-}:}{\code{signature(object = "optsol")}: + sets the \code{lp_obj} slot. + } + \item{\code{lp_obj}:}{\code{signature(object = "optsol")}: + gets the \code{lp_obj} slot. + } + \item{\code{lp_ok<-}:}{\code{signature(object = "optsol")}: + sets the \code{lp_ok} slot. + } + \item{\code{lp_ok}:}{\code{signature(object = "optsol")}: + gets the \code{lp_ok} slot. + } + \item{\code{lp_stat<-}:}{\code{signature(object = "optsol")}: + sets the \code{lp_stat} slot. + } + \item{\code{lp_stat}:}{\code{signature(object = "optsol")}: + gets the \code{lp_stat} slot. + } + \item{\code{method<-}:}{\code{signature(object = "optsol")}: + sets the \code{method} slot. + } + \item{\code{method}:}{\code{signature(object = "optsol")}: + gets the \code{method} slot. + } + \item{\code{mod_id<-}:}{\code{signature(object = "optsol")}: + sets the \code{mod_id} slot. + } + \item{\code{mod_id}:}{\code{signature(object = "optsol")}: + gets the \code{mod_id} slot. + } + \item{\code{mod_key<-}:}{\code{signature(object = "optsol")}: + sets the \code{mod_key} slot. + } + \item{\code{mod_key}:}{\code{signature(object = "optsol")}: + gets the \code{mod_key} slot. + } + \item{\code{mod_obj}:}{\code{signature(object = "optsol_fluxdel")}: + returns always the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). If slot \code{obj_coef} is + \code{NA}, the content of slot \code{lp_obj} is returned. + In contrast, method \code{lp_obj} always returns the value of the + objective function of the used algorithm after optimization. + } + \item{\code{nfluxes}:}{\code{signature(object = "optsol")}: + gets the number of elements in the flux distribution matrix. + } + \item{\code{num_of_prob<-}:}{\code{signature(object = "optsol")}: + sets the \code{num_of_prob} slot. + } + \item{\code{num_of_prob}:}{\code{signature(object = "optsol")}: + gets the \code{num_of_prob} slot. + } + \item{\code{obj_coef<-}:}{\code{signature(object = "optsol")}: + sets the \code{obj_coef} slot. + } + \item{\code{obj_coef}:}{\code{signature(object = "optsol")}: + gets the \code{obj_coef} slot. + } + \item{\code{obj_func<-}:}{\code{signature(object = "optsol")}: + sets the \code{obj_func} slot. + } + \item{\code{obj_func}:}{\code{signature(object = "optsol")}: + gets the \code{obj_func} slot. + } + \item{\code{react_id<-}:}{\code{signature(object = "optsol")}: + sets the \code{react_id} slot. + } + \item{\code{react_id}:}{\code{signature(object = "optsol")}: + gets the \code{react_id} slot. + } + \item{\code{show}:}{\code{signature(object = "optsol")}: + prints a summary of the content of instance of class \code{optsol}. + } + \item{\code{solver<-}:}{\code{signature(object = "optsol")}: + sets the \code{solver} slot. + } + \item{\code{solver}:}{\code{signature(object = "optsol")}: + gets the \code{solver} slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{checkOptSol}}, + \code{\linkS4class{optsol_optimizeProb}} + \code{\linkS4class{optsol_fluxdel}}, + \code{\linkS4class{optsol_genedel}}, + \code{\linkS4class{optsol_robAna}} and + \code{\linkS4class{optsol_fluxVar}} +} + +\examples{ + showClass("optsol") +} + +\keyword{classes} diff --git a/man/optsol_blockedReact-class.Rd b/man/optsol_blockedReact-class.Rd new file mode 100644 index 0000000..c7823a6 --- /dev/null +++ b/man/optsol_blockedReact-class.Rd @@ -0,0 +1,147 @@ +\name{optsol_blockedReact-class} + +\Rdversion{1.1} +\docType{class} + +\alias{optsol_blockedReact-class} + +\alias{blocked,optsol_blockedReact-method} +\alias{blocked<-,optsol_blockedReact-method} +\alias{blocked} +\alias{blocked<-} +\alias{react,optsol_blockedReact-method} +\alias{react<-,optsol_blockedReact-method} +\alias{react} +\alias{react<-} +\alias{maxSol,optsol_blockedReact-method} +\alias{minSol,optsol_blockedReact-method} +\alias{maxSol} +\alias{minSol} + +\title{Class \code{"optsol_blockedReact"}} + +\description{ + Structure of the class \code{"optsol_blockedReact"}. Objects of that class are + returned by the function \code{\link{blockedReact}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("optsol_blockedReact", ...)}. +} + +\section{Slots}{ + \describe{ + \item{\code{blocked}:}{Object of class \code{"logical"} + indicating if a reaction is blocked, or not. + } + \item{\code{react}:}{Object of class \code{"reactId"} + containing the reaction id's of checked reactions. + } + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. If no flux distribution is available, slot \code{lp_obj} + contains the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optsol}"}, directly. +} + +\section{Methods}{ + \describe{ + \item{\code{blocked}:}{ + \code{signature(object = "optsol_blockedReact")}: gets the \code{blocked} slot. + } + \item{\code{blocked<-}:}{ + \code{signature(object = "optsol_blockedReact")} sets the \code{blocked} slot. + } + \item{\code{react}:}{ + \code{signature(object = "optsol_blockedReact")}: gets the \code{react} slot. + } + \item{\code{react<-}:}{ + \code{signature(object = "optsol_blockedReact")} sets the \code{react} slot. + } + \item{\code{maxSol}:}{ + \code{signature(object = "optsol_blockedReact")}(\code{slot}): returns the + values in the slot given in \code{slot} for optimizations in \dQuote{max} + direction. + } + \item{\code{minSol}:}{ + \code{signature(object = "optsol_blockedReact")}(\code{slot}): returns the + values in the slot given in \code{slot} for optimizations in \dQuote{min} + direction. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{checkOptSol}} and \code{\linkS4class{optsol}} +} + +\examples{ + showClass("optsol_blockedReact") +} + +\keyword{classes} diff --git a/man/optsol_fluxVar-class.Rd b/man/optsol_fluxVar-class.Rd new file mode 100644 index 0000000..425ec63 --- /dev/null +++ b/man/optsol_fluxVar-class.Rd @@ -0,0 +1,222 @@ +\name{optsol_fluxVar-class} + +\Rdversion{1.1} +\docType{class} + +\alias{optsol_fluxVar-class} + +\alias{react,optsol_fluxVar-method} +\alias{react<-,optsol_fluxVar-method} +\alias{maxSol,optsol_fluxVar-method} +\alias{minSol,optsol_fluxVar-method} +\alias{plot,optsol_fluxVar,missing-method} +\alias{plotRangeVar,optsol_fluxVar-method} +\alias{plotRangeVar} +\alias{blReact,optsol_fluxVar-method} +\alias{blReact} + + +\title{Class \code{"optsol_fluxVar"}} + +\description{ + Structure of the class \code{"optsol_fluxVar"}. Objects of that class are + returned by the function \code{\link{fluxVar}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("optsol_fluxVar", ...)}. +} + +\section{Slots}{ + \describe{ + \item{\code{react}:}{Object of class \code{"reactId"} + containing reaction id's for which ranges were calculated. + } + \item{\code{preProc}:}{Object of class \code{"ppProc"} + containing the results of pre-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{postProc}:}{Object of class \code{"ppProc"} + containing the results of post-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optsol_optimizeProb}"}, directly. + Class \code{"\linkS4class{optsol}"}, by class "optsol_optimizeProb", distance 2. +} + +\section{Methods}{ + \describe{ + \item{\code{react}:}{\code{signature(object = "optsol_fluxVar")}: + gets the \code{react} slot. + } + \item{\code{react<-}:}{\code{signature(object = "optsol_fluxVar")}: + sets the \code{react} slot. + } + \item{\code{maxSol}:}{ + \code{signature(object = "optsol_fluxVar")}(\code{slot}): returns the + values in the slot given in \code{slot} for optimizations in \dQuote{max} + direction. + } + \item{\code{minSol}:}{ + \code{signature(object = "optsol_fluxVar")}(\code{slot}): returns the + values in the slot given in \code{slot} for optimizations in \dQuote{min} + direction. + } + \item{\code{plot}}{ + \code{signature(x = "optsol_fluxVar", y = "missing")} + (\code{ylim, xlab = "", ylab = "Value", pch = 20, col = "black", + collower, colupper, pchupper, pchlower, + dottedline = FALSE, baseline = 0, ...}):\cr + plots the range of values each flux can have still giving an optimal + objective function value. + \describe{ + \item{\code{ylim}}{ + scaling of y-axis, if missing, the maximum and minimum value of + all optimizations is used (rounded to the next smaller/larger + integer value). + } + \item{\code{xlab}}{ + label of x-axis, see also \code{\link{par}}. + } + \item{\code{ylab}}{ + label of y-axis, see also \code{\link{par}}. + } + \item{\code{pch}}{ + how to plot the points, see also \code{\link{par}}. + } + \item{\code{col}}{ + color of the plot, see also \code{\link{par}}. + } + \item{\code{collower}}{ + color of the minimum range value. Default \code{col}. + } + \item{\code{colupper}}{ + color of the maximum range value. Default \code{col}. + } + \item{\code{pchupper}}{ + how to plot the point for the maximum range value. Default \code{pch}. + } + \item{\code{pchlower}}{ + how to plot the point for the minimum range value. Default \code{pch}. + } + \item{\code{dottedline}}{ + if set to \code{FALSE}, from each minimum range value a dotted line to + the corresponding x-axis label will be plotted. Default \code{FALSE}. + } + \item{\code{baseline}}{ + plot a horizontal dashed line at the value of \code{baseline}. Default + \code{0}. If set to \code{NA}, no baseline will be plotted. + } + \item{\code{connect}}{ + if set to \code{TRUE}, a solid connecting line will be drawn + between the minimum and maximum value of one reaction. + Default \code{TRUE}. + } + \item{\code{colconnect}}{ + color of the connecting line. Default \code{"black"}. + } + \item{\code{\dots}}{ + further arguments to the \code{\link{plot}} function. + } + } + } + \item{\code{plotRangeVar}}{\code{signature(object = "optsol_fluxVar")} + (\code{...}): plot a histogram of the span of the minimum and maximum + range values for each flux. + \describe{ + \item{\code{...}}{ + further arguments to the \code{\link{hist}} function. + } + } + } + \item{\code{blReact}}{\code{signature(object = "optsol_fluxVar")} + (\code{tol = SYBIL_SETTINGS("TOLERANCE")}): returns a logical vector of + length equal to the number of reactions analyzed during flux variance + analysis (number of optimizations divided by two). + If \code{blReact(object)[j]} equals \code{TRUE}, reaction \code{j} is + considered to be blocked (zero flux rate) given the used conditions. + A reaction \eqn{j} is considered to be \sQuote{blocked}, if its calculated + range of reaction rates does not exceed \code{0 +/- tol}. + \describe{ + \item{\code{tol}}{ + limit of tolerance. + } + } + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{checkOptSol}} and \code{\linkS4class{optsol}} +} + +\examples{ + showClass("optsol_fluxVar") +} + +\keyword{classes} diff --git a/man/optsol_fluxdel-class.Rd b/man/optsol_fluxdel-class.Rd new file mode 100644 index 0000000..e7edb43 --- /dev/null +++ b/man/optsol_fluxdel-class.Rd @@ -0,0 +1,209 @@ +\name{optsol_fluxdel-class} + +\docType{class} + +\alias{optsol_fluxdel-class} + +\alias{chlb,optsol_fluxdel-method} +\alias{chlb<-,optsol_fluxdel-method} +\alias{chlb} +\alias{chlb<-} +\alias{chub,optsol_fluxdel-method} +\alias{chub<-,optsol_fluxdel-method} +\alias{chub} +\alias{chub<-} +\alias{dels,optsol_fluxdel-method} +\alias{dels<-,optsol_fluxdel-method} +\alias{dels} +\alias{dels<-} +% \alias{ind2id,optsol_fluxdel-method} +% \alias{ind2id} +\alias{deleted,optsol_fluxdel-method} +\alias{deleted} +\alias{lethal,optsol_fluxdel-method} +\alias{lethal} +\alias{[,optsol_fluxdel,ANY,ANY,ANY-method} + +\encoding{utf8} + +\title{Class \code{"optsol_fluxdel"}} + +\description{ + Structure of the class \code{"optsol_fluxdel"}. Objects of that class are + returned by the function \code{\link{oneFluxDel}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("optsol_fluxdel", ...)}. +} + +\section{Slots}{ + \describe{ + \item{\code{chlb}:}{Object of class \code{"numeric"} + containing the new (changed) values for the columns lower bounds. + } + \item{\code{chub}:}{Object of class \code{"numeric"} + containing the new (changed) values for the columns upper bounds. + } + \item{\code{dels}:}{ + Object of class \code{"matrix"} containing the reaction id's of + constrained reactions. Each row of the matrix represents one set of + simultaneously constrained reactions. + } + \item{\code{preProc}:}{Object of class \code{"ppProc"} + containing the results of pre-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{postProc}:}{Object of class \code{"ppProc"} + containing the results of post-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. If no flux distribution is available, slot \code{lp_obj} + contains the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optsol_optimizeProb}"}, directly. + Class \code{"\linkS4class{optsol}"}, + by class "optsol_optimizeProb", distance 2. +} + +\section{Methods}{ + \describe{ + \item{\code{react_id}:}{ + \code{signature(object = "optsol_fluxdel")}: gets the \code{react_id} slot. + } + \item{\code{react_id<-}:}{ + \code{signature(object = "optsol_fluxdel")} sets the \code{react_id} slot. + } + \item{\code{allGenes}:}{ + \code{signature(object = "optsol_fluxdel")}: gets the \code{allGenes} slot. + } + \item{\code{allGenes<-}:}{ + \code{signature(object = "optsol_fluxdel")} sets the \code{allGenes} slot. + } + \item{\code{chlb}:}{ + \code{signature(object = "optsol_fluxdel")}: gets the \code{chlb} slot. + } + \item{\code{chlb<-}:}{ + \code{signature(object = "optsol_fluxdel")} sets the \code{chlb} slot. + } + \item{\code{chub}:}{ + \code{signature(object = "optsol_fluxdel")}: gets the \code{chub} slot. + } + \item{\code{chub<-}:}{ + \code{signature(object = "optsol_fluxdel")}: sets the \code{chub} slot. + } + \item{\code{dels}:}{ + \code{signature(object = "optsol_fluxdel")}: gets the \code{dels} slot. + } + \item{\code{dels<-}:}{ + \code{signature(object = "optsol_fluxdel")} sets the \code{dels} slot. + } + \item{\code{algorithm}:}{ + \code{signature(object = "optsol_fluxdel")}: gets the \code{algorithm} slot. + } + \item{\code{algorithm<-}:}{ + \code{signature(object = "optsol_fluxdel")} sets the \code{algorithm} slot. + } +% \item{\code{ind2id}:}{ +% \code{signature(object = "optsol_fluxdel")}(\code{slotN}): translates the +% indices in \code{slotN} into corresponding gene or reaction id's. Possible +% values for \code{slotN} are: \code{"dels"}. +% } + \item{\code{lethal}:}{ + \code{signature(object = "optsol_fluxdel")}(\code{wt, tol}): returns + a logical vector of length \code{num_of_prob(object)}. Argument \code{wt} + is an optimal (wild type) growth rate, e.g. computed via FBA. If the + absolute growth ratio (\code{mod_obj(object)/wt}) of knock-out \code{i} + is less than \code{tol}, the deletion is considered as lethal. + If \code{lethal(object)[i]} is \code{TRUE}, deletion [i] is lethal. + } + \item{\code{deleted}:}{ + \code{signature(object = "optsol_fluxdel")}(\code{i}): gets the \code{i}th + element of the \code{dels} slot. + } + \item{\code{[}:}{ + \code{signature(x = "optsol_fluxdel")}: access like a vector. + \code{x[i]} returns a new object of class \code{optsol_fluxdel} containing + the \code{i}th deletion experiment. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{checkOptSol}}, + \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_genedel}} and + \code{\linkS4class{optsol_optimizeProb}} +} + +\examples{ + showClass("optsol_fluxdel") +} + +\keyword{classes} diff --git a/man/optsol_genedel-class.Rd b/man/optsol_genedel-class.Rd new file mode 100644 index 0000000..0ba5415 --- /dev/null +++ b/man/optsol_genedel-class.Rd @@ -0,0 +1,184 @@ +\name{optsol_genedel-class} + +\docType{class} + +\alias{optsol_genedel-class} + +\alias{fluxdels,optsol_genedel-method} +\alias{fluxdels} +\alias{fluxdels<-,optsol_genedel-method} +\alias{fluxdels<-} +\alias{hasEffect,optsol_genedel-method} +\alias{hasEffect} +\alias{hasEffect<-,optsol_genedel-method} +\alias{hasEffect<-} +%\alias{ind2id,optsol_genedel-method} +\alias{deleted,optsol_genedel-method} +%\alias{cpsol,optsol_genedel-method} +%\alias{cpsol} + +\encoding{utf8} + +\title{Class \code{"optsol_genedel"}} + +\description{ + Structure of the class \code{"optsol_genedel"}. Objects of that class are + returned by the function \code{geneDel}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("optsol_genedel", ...)}. +} + +\section{Slots}{ + \describe{ + \item{\code{fluxdels}:}{ + Object of class \code{"list"} containing the reaction id's of constrained + reactions (fluxes). + \code{fluxdels(optsol_genedel)[[i]][j] = l}: The deletion of gene \code{i} + requires the deletion of a set of fluxes \code{1..k} (j \eqn{\le} k), + \code{j} being the j'th reaction of that set. + } + \item{\code{hasEffect}:}{ + Object of class \code{"logical"} indicating whether deletion of + gene \code{i} has an effect or not. + } + \item{\code{chlb}:}{Object of class \code{"numeric"} + containing the new (changed) values for the columns lower bounds. + } + \item{\code{chub}:}{Object of class \code{"numeric"} + containing the new (changed) values for the columns upper bounds. + } + \item{\code{dels}:}{ + Object of class \code{"matrix"} containing the gene id of constrained + genes. Each row of the matrix represents one set of simultaneously + constrained genes. + } + \item{\code{preProc}:}{Object of class \code{"ppProc"} + containing the results of pre-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{postProc}:}{Object of class \code{"ppProc"} + containing the results of post-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. If no flux distribution is available, slot \code{lp_obj} + contains the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optsol_fluxdel}"}, directly. + Class \code{"\linkS4class{optsol_optimizeProb}"}, + by class "optsol_fluxdel", distance 2. + Class \code{"\linkS4class{optsol}"}, by class "optsol_fluxdel", distance 3. +} + +\section{Methods}{ + \describe{ + \item{\code{fluxdels}:}{ + \code{signature(object = "optsol_genedel")}: gets the \code{fluxdels} slot. + } + \item{\code{fluxdels<-}:}{ + \code{signature(object = "optsol_genedel")} sets the \code{fluxdels} slot. + } + \item{\code{hasEffect}:}{ + \code{signature(object = "optsol_genedel")}: gets the \code{hasEffect} slot. + } + \item{\code{hasEffect<-}:}{ + \code{signature(object = "optsol_genedel")}: sets the \code{hasEffect} slot. + } +% \item{\code{ind2id}:}{ +% \code{signature(object = "optsol_genedel")}(\code{slotN}): translates the +% indices in \code{slotN} into corresponding gene or reaction id's. Possible +% values for \code{slotN} are: \code{"dels"} or \code{"fluxdels"}. +% } + \item{\code{deleted}:}{ + \code{signature(object = "optsol_genedel")}(\code{i}): gets the \code{i}th + element of the \code{dels} slot. + } +% \item{\code{cpsol}:}{ +% \code{signature(object = "optsol_genedel")}(\code{i, z, fld)}: copies solution number \code{i} +% to solution number \code{z} of solution \code{object}. If \code{fld} +% is set to \code{TRUE}, also the flux distribution will be copied +% (default: FALSE). +% } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{checkOptSol}}, + \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_fluxdel}} and + \code{\linkS4class{optsol_optimizeProb}} +} + +\examples{ + showClass("optsol_genedel") +} + +\keyword{classes} + diff --git a/man/optsol_optimizeProb-class.Rd b/man/optsol_optimizeProb-class.Rd new file mode 100644 index 0000000..9eae26f --- /dev/null +++ b/man/optsol_optimizeProb-class.Rd @@ -0,0 +1,141 @@ +\name{optsol_optimizeProb-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{optsol_optimizeProb-class} +\alias{postProc,optsol_optimizeProb-method} +\alias{postProc<-,optsol_optimizeProb-method} +\alias{preProc,optsol_optimizeProb-method} +\alias{preProc<-,optsol_optimizeProb-method} +\alias{preProc} +\alias{preProc<-} +\alias{postProc} +\alias{postProc<-} + +\title{Class \code{"optsol_optimizeProb"}} + +\description{ + Structure of the class \code{"optsol_optimizeProb"}. Objects of that class are + returned by the function \code{\link{optimizeProb}} with the argument + \code{retOptSol} set to \code{TRUE}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("optsol_optimizeProb", ...)}, or via the constructor function + \code{\link{makeOptsolMO}}. +} + +\section{Slots}{ + \describe{ + \item{\code{preProc}:}{Object of class \code{"ppProc"} + containing the results of pre-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{postProc}:}{Object of class \code{"ppProc"} + containing the results of post-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. If no flux distribution is available, slot \code{lp_obj} + contains the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} +\section{Extends}{ + Class \code{"\linkS4class{optsol}"}, directly. +} + +\section{Methods}{ + \describe{ + \item{\code{preProc}:}{\code{signature(object = "optsol_optimizeProb")}: + gets the \code{preProc} slot. + } + \item{\code{preProc<-}:}{\code{signature(object = "optsol_optimizeProb")}: + sets the \code{preProc} slot. + } + \item{\code{postProc}:}{\code{signature(object = "optsol_optimizeProb")}: + gets the \code{postProc} slot. + } + \item{\code{postProc<-}:}{\code{signature(object = "optsol_optimizeProb")}: + sets the \code{postProc} slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{checkOptSol}}, + \code{\linkS4class{optsol}}, + \code{\linkS4class{optsol_genedel}} and + \code{\linkS4class{optsol_fluxdel}} +} + + +\examples{ + showClass("optsol_optimizeProb") +} + +\keyword{classes} diff --git a/man/optsol_phpp-class.Rd b/man/optsol_phpp-class.Rd new file mode 100644 index 0000000..42fee8c --- /dev/null +++ b/man/optsol_phpp-class.Rd @@ -0,0 +1,218 @@ +\name{optsol_phpp-class} + +\Rdversion{1.1} +\docType{class} + +\alias{optsol_phpp-class} + +\alias{ctrlfl,optsol_phpp-method} +\alias{ctrlfl<-,optsol_phpp-method} +\alias{getRedCosts,optsol_phpp-method} +\alias{plot,optsol_phpp,character-method} +\alias{plot,optsol_phpp,missing-method} + +\title{Class \code{"optsol_phpp"}} + +\description{ + Structure of the class \code{"optsol_robAna"}. Objects of that class are + returned by the function \code{\link{phpp}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("optsol_phpp", ...)}. +} + +\section{Slots}{ + \describe{ + \item{\code{ctrlflm}:}{Object of class \code{"matrix"} + containing the control flux values. + } + \item{\code{redCosts}:}{Object of class \code{"matrix"} + containing the reduced costs of the two control flux values. + } + \item{\code{ctrlr}:}{Object of class \code{"reactId"} + containing the reaction id of the control reaction. + } + \item{\code{ctrlfl}:}{Object of class \code{"numeric"} + unused, see \code{ctrlflm}. + } + \item{\code{preProc}:}{Object of class \code{"ppProc"} + containing the results of pre-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{postProc}:}{Object of class \code{"ppProc"} + containing the results of post-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. If no flux distribution is available, slot \code{lp_obj} + contains the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optsol_robAna}"}, directly. + Class \code{"\linkS4class{optsol_optimizeProb}"}, by class "optsol_robAna", distance 2. + Class \code{"\linkS4class{optsol}"}, by class "optsol_robAna", distance 3. +} + +\section{Methods}{ + \describe{ + \item{ctrlfl}{\code{signature(object = "optsol_phpp")}: + gets the \code{ctrlflm} slot. + } + \item{ctrlfl<-}{\code{signature(object = "optsol_phpp")}: + sets the \code{ctrlflm} slot. + } + \item{getRedCosts}{\code{signature(lp = "optsol_phpp")}: + gets the \code{ctrlflm} slot. + } + \item{plot}{\code{signature(x = "optsol_phpp", y = "character")}: + (\code{main = paste("Reduced Costs:", y), + xlab = react_id(ctrlr(x)[1]), + ylab = react_id(ctrlr(x)[2]), + shrink = c(0.95, 0.95), + col.regions = colorRampPalette(c("#FFFFFF", "#F0F0F0", + "#D9D9D9", "#BDBDBD", "#969696", "#737373", + "#525252", "#252525", "#000000"))(100), + ...}):\cr + plots the reduced costs of the control fluxes as \code{\link{levelplot}}. + \describe{ + \item{\code{y}}{ + reaction id of one control reaction. + } + \item{\code{main}}{ + plot title, see also \code{\link{levelplot}}. + } + \item{\code{xlab}}{ + label of x-axis, see also \code{\link{levelplot}}. + } + \item{\code{ylab}}{ + label of y-axis, see also \code{\link{levelplot}}. + } + \item{\code{shrink}}{ + scale of rectangles to plot, see \code{\link{levelplot}}. + } + \item{\code{col.regions}}{ + a vector of colors (default greyscale) see \code{\link{levelplot}}. + } + \item{\code{...}}{ + further graphical parameters to the \code{\link{levelplot}} function. + } + } + } + \item{plot}{\code{signature(x = "optsol_phpp", y = "missing")}: + (\code{xlab = list(label = react_id(ctrlr(x)[1]), rot = 30, cex = 0.8), + ylab = list(label = react_id(ctrlr(x)[2]), rot = -40, cex = 0.8), + zlab = list(label = obj_func(x), rot = 90, cex = 0.8), + scales = list(arrows = FALSE, cex = 0.6, font = 3, tck = 1, col = "black"), + par.settings = list(axis.line = list(col = "transparent")), + shade = TRUE, + shade.colors = function(irr, ref, height, w = 0.75) { + grey(w * irr + (1 - w) * (1-(1-ref)^0.75)) + }, + ...}):\cr + plots the optimal values of the objective function vs. the control flux + values in a \code{\link{wireframe}} plot. + \describe{ + \item{\code{xlab}}{ + label of x-axis, see also \code{\link{wireframe}}. + } + \item{\code{ylab}}{ + label of y-axis, see also \code{\link{wireframe}}. + } + \item{\code{zlab}}{ + label of z-axis, see also \code{\link{wireframe}}. + } + \item{\code{scales}}{ + parameters describing scales, see \code{\link{wireframe}}. + } + \item{\code{par.settings}}{ + additional parameters, see \code{\link{wireframe}}. + } + \item{\code{shade}}{ + enable/disable shading, see \code{\link{wireframe}}. + } + \item{\code{shade.colors}}{ + a function for the shading color (default greyscale), + see \code{\link{wireframe}}. + } + \item{\code{...}}{ + further graphical parameters to the \code{\link{wireframe}} function. + } + } + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{phpp}}, \code{\link{checkOptSol}} and \code{\linkS4class{optsol}} +} + +\examples{ + showClass("optsol_phpp") +} + +\keyword{classes} diff --git a/man/optsol_robAna-class.Rd b/man/optsol_robAna-class.Rd new file mode 100644 index 0000000..0c3e22e --- /dev/null +++ b/man/optsol_robAna-class.Rd @@ -0,0 +1,179 @@ +\name{optsol_robAna-class} + +\Rdversion{1.1} +\docType{class} + +\alias{optsol_robAna-class} + +\alias{ctrlfl,optsol_robAna-method} +\alias{ctrlfl<-,optsol_robAna-method} +\alias{ctrlfl} +\alias{ctrlfl<-} +\alias{ctrlr,optsol_robAna-method} +\alias{ctrlr<-,optsol_robAna-method} +\alias{ctrlr} +\alias{ctrlr<-} +\alias{plot,optsol_robAna,missing-method} + +\title{Class \code{"optsol_robAna"}} + +\description{ + Structure of the class \code{"optsol_robAna"}. Objects of that class are + returned by the function \code{\link{robAna}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("optsol_robAna", ...)}. +} + +\section{Slots}{ + \describe{ + \item{\code{ctrlr}:}{Object of class \code{"reactId"} + containing the reaction id of the control reaction. + } + \item{\code{ctrlfl}:}{Object of class \code{"numeric"} + containing the control flux values. + } + \item{\code{preProc}:}{Object of class \code{"ppProc"} + containing the results of pre-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{postProc}:}{Object of class \code{"ppProc"} + containing the results of post-processing. + See also \code{\link{optimizeProb}}. + } + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the used model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{solver}:}{Object of class \code{"character"} + indicating the used solver. + } + \item{\code{method}:}{Object of class \code{"character"} + indicating the used method. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm used for optimizations. + } + \item{\code{num_of_prob}:}{Object of class \code{"integer"} + indicating the number of optimization problems. + } + \item{\code{lp_num_cols}:}{Object of class \code{"integer"} + indicating the number of columns. + } + \item{\code{lp_num_rows}:}{Object of class \code{"integer"} + indicating the number of rows. + } + \item{\code{lp_obj}:}{Object of class \code{"numeric"} + containing the optimal values of the objective function after + optimization. If no flux distribution is available, slot \code{lp_obj} + contains the cross-product of the objective coefficients in slot + \code{obj_coef} and the part of the flux distribution in slot + \code{fluxdist} containing the values representing fluxes in the entire + metabolic network (slot \code{fldind}). + } + \item{\code{lp_ok}:}{Object of class \code{"integer"} + containing the exit code of the optimization. + } + \item{\code{lp_stat}:}{Object of class \code{"integer"} + containing the solution status of the optimization. + } + \item{\code{lp_dir}:}{Object of class \code{"character"} + indicating the direction of optimization. + } + \item{\code{obj_coef}:}{Object of class \code{"numeric"} + containing the objective coefficients of the used model (slot + \code{obj_coef} of an object of class \code{\linkS4class{modelorg}}). + These are not necessarily the objective coefficients of the used + algorithm. + } + \item{\code{obj_func}:}{Object of class \code{"character"} + containing the objective function of the used model. Usually, it contains + the return value of \code{\link{printObjFunc}}. + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{fluxdist}:}{Object of class \code{"fluxDistribution"} + containing the solutions flux distributions. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{optsol_optimizeProb}"}, directly. + Class \code{"\linkS4class{optsol}"}, by class "optsol_optimizeProb", distance 2. +} + +\section{Methods}{ + \describe{ + \item{\code{ctrlfl}:}{\code{signature(object = "optsol_robAna")}: + gets the \code{ctrlfl} slot. + } + \item{\code{ctrlfl<-}:}{\code{signature(object = "optsol_robAna")}: + sets the \code{ctrlfl} slot. + } + \item{\code{ctrlr}:}{\code{signature(object = "optsol_robAna")}: + gets the \code{ctrlr} slot. + } + \item{\code{ctrlr<-}:}{\code{signature(object = "optsol_robAna")}: + sets the \code{ctrlr} slot. + } + \item{\code{plot}}{\code{signature(x = "optsol_robAna", y = "missing")} + (\code{xlab = paste("Control Flux:", react_id(ctrlr(x))), + ylab = paste("Objective Function:", obj_func(x)), + type = "b", pch = 20, fillColorBg = "grey", fillBg = TRUE, + absCtrl = TRUE, ...}):\cr + plots the optimal values of the objective function vs. the control flux + values. + \describe{ + \item{\code{xlab}}{ + label of x-axis, see also \code{\link{par}}. + } + \item{\code{ylab}}{ + label of y-axis, see also \code{\link{par}}. + } + \item{\code{type}}{ + plot type, see also \code{\link{par}}. + } + \item{\code{pch}}{ + how to plot the points, see also \code{\link{par}}. + } + \item{\code{fillColorBg}}{ + color of the area below the curve. + } + \item{\code{fillBg}}{ + logical: color the area below the curve. + } + \item{\code{absCtrl}}{ + if set to \code{TRUE}, the control flux values (x axis) are plotted + as absolute values. + } + \item{\code{...}}{ + further graphical parameters to the \code{\link{points}} function. + } + } + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{robAna}}, \code{\link{checkOptSol}} and + \code{\linkS4class{optsol}} +} + +\examples{ + showClass("optsol_robAna") +} + +\keyword{classes} diff --git a/man/phpp.Rd b/man/phpp.Rd new file mode 100644 index 0000000..de547f4 --- /dev/null +++ b/man/phpp.Rd @@ -0,0 +1,107 @@ +\name{phpp} +\alias{phpp} + +\encoding{utf8} + +\title{ + Phenotypic Phase Plane Analysis +} + +\description{ + Performs phenotypic phase plane analysis for a given metabolic model. +} + +\usage{ +phpp(model, ctrlreact, rng = c(0, 0, 20, 20), + numP = 50, setToZero = TRUE, redCosts = FALSE, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{ctrlreact}{ + An object of class \code{\linkS4class{reactId}}, character or integer. + Specifies two control reactions. + } + \item{rng}{ + A numeric vector of length four, giving the lower and upper bounds of the + control reactions. The first two values contain the lower bounds, the last + two values the upper bounds.\cr + Default: \code{c(0, 0, 20, 20)} + } + \item{numP}{ + The number of points to analyse.\cr + Default: \code{50} + } + \item{setToZero}{ + Logical: If the mathematical programming software returns a solution status + which is not optimal, set the corresponding objective value to zero (see + also \code{\link{optimizer}}).\cr + Default: \code{TRUE}. + } + \item{redCosts}{ + Logical: store reduced costs of the control variables.\cr + Default: \code{FALSE}. + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. + } +} + +\details{ + The two control reactions given in argument \code{ctrlreact} are treated as + uptake reactions: reactions that transport metabolites into the metabolic + network. That means, the optimizations are performed using + \code{abs(rng) * -1}. +} + +\value{ + An object of class \code{\linkS4class{optsol_phpp}}. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. + + Edwards, J. S., Ibarra, R. U. and Palsson, B. Ø. (2001) In silico predictions + of \emph{Escherichia coli} metabolic capabilities are consistent with + experimental data. + \emph{Nat Biotechnol} \bold{19}, 125--130. + + Edwards, J. S., Ramakrishna, R. and Palsson, B. Ø. (2002) Characterizing the + metabolic phenotype: a phenotype phase plane analysis. + \emph{Biotechnol Bioeng} \bold{77}, 27--36. + + Bernhard Ø. Palsson (2006). + \emph{Systems Biology: Properties of Reconstructed Networks}. + Cambridge University Press. +} + +\author{Gabriel Gelius-Dietrich} + +\examples{ + data(Ec_core) + + # switch off glucose input + Ec_core_wo_glc <- changeUptake(Ec_core, off = "glc_D[e]") + opt <- phpp(Ec_core_wo_glc, ctrlreact = c("EX_succ(e)", "EX_o2(e)")) + + # plot phenotypic phase plane + plot(opt) + + # plot reduced costs of the two control reactions + plot(opt, "EX_succ(e)") + plot(opt, "EX_o2(e)") +} + +\keyword{optimize} + diff --git a/man/ppProc-class.Rd b/man/ppProc-class.Rd new file mode 100644 index 0000000..6f0ee9a --- /dev/null +++ b/man/ppProc-class.Rd @@ -0,0 +1,92 @@ +\name{ppProc-class} + +\Rdversion{1.1} +\docType{class} + +\alias{ppProc-class} +\alias{ppProc} + +\alias{cmd,ppProc-method} +\alias{cmd<-,ppProc-method} +\alias{cmd} +\alias{cmd<-} +\alias{ind,ppProc-method} +\alias{ind<-,ppProc-method} +\alias{ind} +\alias{ind<-} +\alias{pa,ppProc-method} +\alias{pa<-,ppProc-method} +\alias{pa} +\alias{pa<-} + +\title{Class \code{"ppProc"}} + +\description{ + Structure of the class \code{"ppProc"}. Objects of that class are + returned as part of class \code{\linkS4class{optsol}} when performing + pre- or post-processing of an optimization, e.g. in + \code{\link{optimizeProb}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the function \code{ppProc}: + + \code{test <- ppProc(cmd)}. + \describe{ + \item{\code{cmd}:}{Object of class \code{"list"}. + } + } +} + +\section{Slots}{ + \describe{ + \item{\code{cmd}:}{Object of class \code{"list"} + a character vector or a list of character strings containing pre- or + postprocessing commands. + } + \item{\code{pa}:}{Object of class \code{"list"} + return values of the pre- or postprocessing commands. They can be + numeric, integer, character, list or of class + \code{\linkS4class{sybilError}}. + } + \item{\code{ind}:}{Object of class \code{"integer"} + giving the indices of the optimizations when pre- or postprocessing was + performed. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{cmd}:}{\code{signature(object = "ppProc")}: + gets the \code{cmd} slot. + } + \item{\code{cmd<-}:}{\code{signature(object = "ppProc")}: + sets the \code{cmd} slot. + } + \item{\code{pa}:}{\code{signature(object = "ppProc")}: + gets the \code{pa} slot. + } + \item{\code{pa<-}:}{\code{signature(object = "ppProc")}: + sets the \code{pa} slot. + } + \item{\code{ind}:}{\code{signature(object = "ppProc")}: + gets the \code{ind} slot. + } + \item{\code{ind<-}:}{\code{signature(object = "ppProc")}: + sets the \code{ind} slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{optimizeProb}} and \code{\link{optimizer}} +} + +\examples{ + showClass("ppProc") +} + +\keyword{classes} diff --git a/man/printMetabolite-methods.Rd b/man/printMetabolite-methods.Rd new file mode 100644 index 0000000..b4070de --- /dev/null +++ b/man/printMetabolite-methods.Rd @@ -0,0 +1,77 @@ +\name{printMetabolite-methods} + +\docType{methods} +\encoding{utf8} + +\alias{printMetabolite} +\alias{printMetabolite-methods} +\alias{printMetabolite,modelorg-method} + +\title{Print Rows of the Stoichiometric Matrix} + +\description{ + Print the rows of the stoichiometric matrix or an FBA model in CPLEX LP + file format. +} + +\usage{ +\S4method{printMetabolite}{modelorg}(object, met, FBAlp = FALSE, printOut = TRUE, ...) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "modelorg")}}{ + method to use with objects of class \code{\linkS4class{modelorg}}. + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{met}{ + A numeric or character vector containing the metabolite id's of metabolites + to print out. If missing, all metabolites given in the model are used. + } + \item{FBAlp}{ + A single logical value. If set to \code{TRUE}, the output will be in + CPLEX LP file format, including the objective function given in the model + and reaction bounds. Additionally, if set to \code{TRUE}, argument + \code{met} will be ignored; all metabolites present in the model are used. + See also Details.\cr + Default: \code{FALSE}. + } + \item{printOut}{ + A single Boolean value. If set to \code{TRUE}, the desired reactions will + be printed via the \code{\link{cat}} function.\cr + Default: \code{TRUE}. + } + \item{...}{ + Further arguments passed to \code{\link{cat}}, e.g. argument \code{file}. + } +} + +\details{ + Metabolite id's beginning with a digit or period will be prefixed by the + letter \code{"r"}, reaction id's beginning with a digit or period will be + prefixed by the letter \code{"x"} and square brackets in reaction or + metabolite id's will be replaced by round brackets. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\value{ + The \code{\linkS4class{modelorg}} method returns a character vector of length + equal to the number of metabolites given in argument \code{met}, invisibly. + Each string represents the reaction participation of one particular + metabolite. +} + +\seealso{ + Class \code{\linkS4class{modelorg}} +} + +\keyword{methods} diff --git a/man/printReaction-methods.Rd b/man/printReaction-methods.Rd new file mode 100644 index 0000000..b9be30f --- /dev/null +++ b/man/printReaction-methods.Rd @@ -0,0 +1,96 @@ +\name{printReaction-methods} + +\docType{methods} +\encoding{utf8} + +\alias{printReaction} +\alias{printReaction-methods} +\alias{printReaction,modelorg,ANY-method} +\alias{printReaction,summaryOptsol,modelorg-method} + +\title{Print Columns of the Stoichiometric Matrix} + +\description{ + Print the columns of the stoichiometric matrix. +} + +\usage{ +\S4method{printReaction}{modelorg,ANY}(object, react, printOut = TRUE, ...) +\S4method{printReaction}{summaryOptsol,modelorg}(object, mod, j, ...) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "modelorg")}}{ + method to use with objects of class \code{\linkS4class{modelorg}}. + } + \item{\code{signature(object = "summaryOptsol", mod = "modelorg")}}{ + method to use with objects of class \code{\linkS4class{summaryOptsol}}. + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{modelorg}} or of class + \code{\linkS4class{summaryOptsol}}. + } + \item{mod}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{react}{ + A numeric of character vector or an object of class + \code{\linkS4class{reactId}} containing the reaction id's of reactions + to print out. + } + \item{j}{ + A numeric of character vector indicating the simulations to consider, + see Details. + + } + \item{printOut}{ + A single Boolean value. If set to \code{TRUE}, the desired reactions will + be printed via the \code{\link{cat}} function.\cr + Default: \code{TRUE}. + } + \item{...}{ + Further arguments passed to \code{\link{cat}}, e.g. argument \code{file}. + } +} + +\details{ + The output of the \code{\linkS4class{modelorg}} method is compatible to the + file format produced by \code{\link{modelorg2tsv}}. Two columns are used: + \code{"abbreviation"} containing the reaction id's and \code{"equation"} + containing the reaction equation. + + The \code{\linkS4class{summaryOptsol}} method prints the limiting reactions + generated in simulations and stored in objects of class + \code{\linkS4class{summaryOptsol}}. Slot \code{react_id} of class + \code{\linkS4class{summaryOptsol}} contains a list of reaction id's: list + element \code{j} gives the reaction id's limiting simulation number \code{j}. + +} + +\author{ + Gabriel Gelius-Dietrich +} + +\value{ + The \code{\linkS4class{modelorg}} method returns invisibly a character vector + of length equal to the number of reactions given in argument \code{react}. + Each string consists of two tab-delimited values: first, the reaction id, + second, the reaction equation. + + The \code{\linkS4class{summaryOptsol}} returns invisibly a list of length + equal to the number of elements in argument \code{j}. Each list element is + of the same type as the return value of the \code{\linkS4class{modelorg}} + method. +} + +\seealso{ + Class \code{\linkS4class{modelorg}} and + class \code{\linkS4class{summaryOptsol}}. +} + +\keyword{methods} diff --git a/man/promptSysBiolAlg.Rd b/man/promptSysBiolAlg.Rd new file mode 100644 index 0000000..715b30c --- /dev/null +++ b/man/promptSysBiolAlg.Rd @@ -0,0 +1,74 @@ +\name{promptSysBiolAlg} +\alias{promptSysBiolAlg} + +\title{ + Generate A Skeletal Structure of Subclasses of sysBiolAlg +} + +\description{ + Generates a skeletal structure of new subclasses of class + \code{\linkS4class{sysBiolAlg}}, in particular for the + constructor method \code{\link{initialize}}. +} + +\usage{ + promptSysBiolAlg(algorithm, prefix = "sysBiolAlg", sep = "_", + suffix = "R", fpath = ".", ...) +} + +\arguments{ + \item{algorithm}{ + A single character string containing the name of the new algorithm. + } + \item{prefix}{ + A single character string containing a prefix for the new algorithm, see + Details below.\cr + Default: \code{"sysBiolAlg"}. + } + \item{sep}{ + A single character string containing a separator for \code{prefix} and + \code{algorithm}.\cr + Default: \code{"_"}. + } + \item{suffix}{ + A single character string containing a file name suffix.\cr + Default: \code{"R"}. + } + \item{fpath}{ + A single character string containing a file path.\cr + Default: \code{\dots}. + } + \item{\dots}{ + Further arguments passed to \code{\link{file}}. + } +} + +\details{ + The arguments \code{prefix} \code{algorithm} are stick together separated by + \code{sep} (default: a single underscore \code{"_"}) to get the new class + name: \code{prefix_algorithm}. The filename will be: + \code{prefix_algorithmClass.R}. + + The class definition in the new file will extend class + \code{\linkS4class{sysBiolAlg}} directly and will not add any + slots. Additionally a skeletal structure for method \code{\link{initialize}} + will be generated. In this method, the user should create all arguments to + the \code{initialize} method described in the base class + \code{\linkS4class{sysBiolAlg}} and put them all to + \code{\link{callNextMethod}}. Or, alternatively, generate an instance of + class \code{\linkS4class{optObj}} \dQuote{by hand}. +} + +\value{ + Returns \code{NULL} invisible. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\linkS4class{sysBiolAlg}} +} + +\keyword{ IO } diff --git a/man/reactId-class.Rd b/man/reactId-class.Rd new file mode 100644 index 0000000..459e97e --- /dev/null +++ b/man/reactId-class.Rd @@ -0,0 +1,119 @@ +\name{reactId-class} + +\docType{class} +\encoding{utf8} + +\alias{reactId-class} +\alias{reactId} +\alias{react_pos<-,reactId-method} +\alias{react_pos,reactId-method} +\alias{react_pos<-} +\alias{react_pos} +\alias{react_id<-,reactId-method} +\alias{react_id,reactId-method} +\alias{mod_id,reactId-method} +\alias{mod_id<-,reactId-method} +\alias{mod_key,reactId-method} +\alias{mod_key<-,reactId-method} +\alias{length,reactId-method} +\alias{[,reactId,ANY,ANY,ANY-method} + +\title{Structure of Class "reactId"} + +\description{ + Structure of the class \code{"reactId"}. Objects of that class are + returned by the function \code{\link{checkReactId}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("reactId", mod_id, pnt, id = NULL, mod_key = "")}. + \describe{ + \item{\code{mod_id}:}{ + Object of class \code{"character"} containing the model id. + } + \item{\code{pnt}:}{ + Object of class \code{"numeric"} containing the column indices in a + stoichiometric matrix of the reactions given in \code{react}. + } + \item{\code{id}:}{ + Object of class \code{"character"} containing the reaction id's + corresponding to argument \code{pos}. If set to \code{NULL} (default), + no reaction id's are used. + } + \item{\code{mod_key}:}{ + Object of class \code{"character"} containing the model key. + } + } +} + +\section{Slots}{ + \describe{ + \item{\code{mod_id}:}{ + Object of class \code{"character"} containing the model id. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{react_pos}:}{ + Object of class \code{"integer"} containing the column indices of reaction + id's in the stoichiometric matrix of the metabolic model with id + \code{mod_id}. + } + \item{\code{react_id}:}{ + Object of class \code{"character"} containing the reaction id's + corresponding to the indices given in slot \code{react_pos}. + } + \item{\code{react_num}:}{ + Object of class \code{"integer"} containing the number of reaction id's. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{mod_id<-}:}{ + \code{signature(object = "reactId")}: sets the \code{mod_id} slot. + } + \item{\code{mod_id}:}{ + \code{signature(object = "reactId")}: gets the \code{mod_id} slot. + } + \item{\code{mod_key<-}:}{ + \code{signature(object = "reactId")}: sets the \code{mod_key} slot. + } + \item{\code{mod_key}:}{ + \code{signature(object = "reactId")}: gets the \code{mod_key} slot. + } + \item{\code{react_pos<-}:}{ + \code{signature(object = "reactId")}: sets the \code{react_pos} slot. + } + \item{\code{react_pos}:}{ + \code{signature(object = "reactId")}: gets the \code{react_pos} slot. + } + \item{\code{react_id<-}:}{ + \code{signature(object = "reactId")}: sets the \code{react_id} slot. + } + \item{\code{react_id}:}{ + \code{signature(object = "reactId")}: gets the \code{react_id} slot. + } + \item{\code{length}}{ + \code{signature(object = "reactId")}: returns the number of reaction id's. + } + \item{\code{[}:}{ + \code{signature(x = "reactId")}: access like a vector. + \code{x[i]} returns a new object of class \code{reactId} containing + the \code{i}th reaction id. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{\code{\link{checkReactId}}} + +\examples{ + showClass("reactId") +} + +\keyword{classes} + diff --git a/man/reactId_Exch-class.Rd b/man/reactId_Exch-class.Rd new file mode 100644 index 0000000..0bc1b28 --- /dev/null +++ b/man/reactId_Exch-class.Rd @@ -0,0 +1,196 @@ +\name{reactId_Exch-class} + +\Rdversion{1.1} + +\docType{class} +\encoding{utf8} + +\alias{reactId_Exch-class} +\alias{reactId_Exch} +\alias{met_id,reactId_Exch-method} +\alias{met_id<-,reactId_Exch-method} +\alias{met_pos} +\alias{met_pos,reactId_Exch-method} +\alias{met_pos<-} +\alias{met_pos<-,reactId_Exch-method} +\alias{uptake} +\alias{uptake,reactId_Exch-method} +\alias{uptake<-} +\alias{uptake<-,reactId_Exch-method} +\alias{uptMet} +\alias{uptMet,reactId_Exch-method} +\alias{uptReact} +\alias{uptReact,reactId_Exch-method} +\alias{lowbnd,reactId_Exch-method} +\alias{lowbnd<-,reactId_Exch-method} +\alias{uppbnd,reactId_Exch-method} +\alias{uppbnd<-,reactId_Exch-method} +\alias{[,reactId_Exch,ANY,ANY,ANY-method} + +\title{Class \code{"reactId_Exch"}} + +\description{ + Structure of the class \code{"reactId_Exch"}. Objects of that class are + returned by the function \code{\link{findExchReact}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + \code{new("reactId_Exch", mod_id, mod_key, rpnt, rid, upt, mpnt, mid, lb, ub)}. + \describe{ + \item{\code{mod_id}:}{ + Object of class \code{"character"} containing the model id. + } + \item{\code{mod_key}:}{ + Object of class \code{"character"} containing the model key. + } + \item{\code{rpnt}:}{ + Object of class \code{"numeric"} containing the column indices in a + stoichiometric matrix of the reactions given in \code{rid}. + } + \item{\code{rid}:}{ + Object of class \code{"character"} containing the reaction id's + corresponding to argument \code{rpnt}. + } + \item{\code{upt}:}{ + Object of class \code{"logical"}: \code{upt[j]} equals \code{TRUE} if + reaction \eqn{j} in \code{rid} is an uptake reaction (an exchange reaction + with a lower bound less than zero). + } + \item{\code{mpnt}:}{ + Object of class \code{"numeric"} containing the row indices in a + stoichiometric matrix of the metabolites given in \code{mid}. The reaction + given in \code{rid[j]} transports metabolite \code{mid[j]} across the + system boundary of the model. + } + \item{\code{mid}:}{ + Object of class \code{"character"} containing the metabolite id's + corresponding to argument \code{mpnt}. + } + \item{\code{lb}:}{ + Object of class \code{"numeric"} containing the lower bounds of the + reactions given in \code{rpnt}. + } + \item{\code{ub}:}{ + Object of class \code{"numeric"} containing the upper bounds of the + reactions given in \code{rpnt}. + } + } +} + +\section{Slots}{ + \describe{ + \item{\code{uptake}:}{ + Object of class \code{"logical"} indicating if a certain reaction is an + uptake reaction or not. + } + \item{\code{met_pos}:}{ + Object of class \code{"integer"} containing the row indices of metabolite + id's in the stoichiometric matrix of the metabolic model with id + \code{mod_id}. + } + \item{\code{met_id}:}{ + Object of class \code{"character"} containing the metabolite id's + corresponding to the indices given in slot \code{met_pos}. + } + \item{\code{lowbnd}:}{ + Object of class \code{"numeric"} containing the lower bounds of the + reactions given in slot \code{react_pos}. + } + \item{\code{uppbnd}:}{ + Object of class \code{"numeric"} containing the upper bounds of the + reactions given in slot \code{react_pos}. + } + \item{\code{mod_id}:}{ + Object of class \code{"character"} containing the model id. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{react_pos}:}{ + Object of class \code{"integer"} containing the column indices of reaction + id's in the stoichiometric matrix of the metabolic model with id + \code{mod_id}. + } + \item{\code{react_id}:}{ + Object of class \code{"character"} containing the reaction id's + corresponding to the indices given in slot \code{react_pos}. + } + \item{\code{react_num}:}{ + Object of class \code{"integer"} containing the number of reaction id's. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{reactId}"}, directly. +} + +\section{Methods}{ + \describe{ + \item{met_pos}{\code{signature(object = "reactId_Exch")}: + gets the \code{met_pos} slot. + } + \item{met_pos<-}{\code{signature(object = "reactId_Exch")}: + sets the \code{met_pos} slot. + } + \item{met_id}{\code{signature(object = "reactId_Exch")}: + gets the \code{met_id} slot. + } + \item{met_id<-}{\code{signature(object = "reactId_Exch")}: + sets the \code{met_id} slot. + } + \item{met_pos}{\code{signature(object = "reactId_Exch")}: + gets the \code{met_pos} slot. + } + \item{met_pos<-}{\code{signature(object = "reactId_Exch")}: + sets the \code{met_pos} slot. + } + \item{lowbnd}{\code{signature(object = "reactId_Exch")}: + gets the \code{lowbnd} slot. + } + \item{lowbnd<-}{\code{signature(object = "reactId_Exch")}: + sets the \code{lowbnd} slot. + } + \item{uppbnd}{\code{signature(object = "reactId_Exch")}: + gets the \code{uppbnd} slot. + } + \item{uppbnd<-}{\code{signature(object = "reactId_Exch")}: + sets the \code{uppbnd} slot. + } + \item{uptake}{\code{signature(object = "reactId_Exch")}: + gets the \code{uptake} slot. + } + \item{uptake<-}{\code{signature(object = "reactId_Exch")}: + sets the \code{uptake} slot. + } + \item{uptReact}{\code{signature(object = "reactId_Exch")}: + gets the id's of uptake reactions. + } + \item{uptMet}{\code{signature(object = "reactId_Exch")}: + gets the metabolite id's of metabolites used by uptake reactions. + } + \item{\code{[}:}{ + \code{signature(x = "reactId_Exch")}: access like a vector. + \code{x[i]} returns a new object of class \code{reactId_Exch} containing + the \code{i}th exchange reaction id. + } + \item{\code{show}:}{ + \code{signature(x = "reactId_Exch")}: prints a table of all exchange + reactions. If an upper or lower bound is equal or greater than + \code{abs(SYBIL_SETINGS("MAXIMUM"))}, it will be shown as \code{Inf} or + \code{-Inf}. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{\code{\link{checkReactId}}} + +\examples{ + showClass("reactId") +} + +\keyword{classes} + diff --git a/man/readProb-methods.Rd b/man/readProb-methods.Rd new file mode 100644 index 0000000..ec3d4a6 --- /dev/null +++ b/man/readProb-methods.Rd @@ -0,0 +1,82 @@ +\name{readProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{readProb} +\alias{readProb-methods} + +\alias{readProb,optObj_clpAPI,character-method} +\alias{readProb,optObj_cplexAPI,character-method} +\alias{readProb,optObj_glpkAPI,character-method} +\alias{readProb,optObj_lpSolveAPI,character-method} + +\title{Read Problem Object From File} + +\description{ + Read problem object from file. +} + +\usage{ +\S4method{readProb}{optObj_clpAPI,character}(lp, fname, ff = "mps", ...) + +\S4method{readProb}{optObj_cplexAPI,character}(lp, fname, ff = "lp") + +\S4method{readProb}{optObj_glpkAPI,character}(lp, fname, ff = "lp", ...) + +\S4method{readProb}{optObj_lpSolveAPI,character}(lp, fname, ff = "lp", ...) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", fname = "character")}}{ + method to use with package \pkg{optObj_clpAPI}. Argument \code{ff} is + not used here. + } + \item{\code{signature(lp = "optObj_cplexAPI", fname = "character")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", fname = "character")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", fname = "character")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{fname}{ + A single character string giving the file name to read from. + } + \item{ff}{ + A single character string giving the file format to use, see Details.\cr + Default: \code{"lp"}. + } + \item{...}{ + Further arguments passed to the corresponding API routine. + } +} + +\details{ + Argument \code{"ff"} in conjunction with \pkg{clpAPI} can be \code{mps} for + MPS file format or \code{"clp"} for COIN-OR Clp file mormat. Valid values for + \pkg{cplexAPI} and \code{lpSolveAPI} are available in their documentations. + For \pkg{glpkAPI}, argument \code{"ff"} can be \code{"lp"} for LP file format, + \code{"mps"} for MPS file format or \code{"glpk"} for GLPK file format. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/readTSVmod.Rd b/man/readTSVmod.Rd new file mode 100644 index 0000000..a38df6b --- /dev/null +++ b/man/readTSVmod.Rd @@ -0,0 +1,393 @@ +\name{readTSVmod} +\alias{readTSVmod} + +\encoding{utf8} + +\title{ + Read a Metabolic Network in a TSV (CSV) Format +} +\description{ + The function \code{readTSVmod} reads metabolic networks in text files, + following a character-separated value format. Each line should contain one + entry; the default value separator is a tab. Output files from the + BiGG database are compatible. +} +\usage{ + readTSVmod(prefix, suffix, + reactList, metList = NA, modDesc = NA, + fielddelim = "\t", entrydelim = ", ", extMetFlag = "b", + excludeComments = TRUE, + oneSubSystem = TRUE, + mergeMet = TRUE, + balanceReact = TRUE, + remUnusedMetReact = TRUE, + singletonMet = FALSE, + deadEndMet = FALSE, + remMet = FALSE, + constrMet = FALSE, + tol = SYBIL_SETTINGS("TOLERANCE"), + fpath = SYBIL_SETTINGS("PATH_TO_MODEL"), + def_bnd = SYBIL_SETTINGS("MAXIMUM"), + arrowlength = NULL, + quoteChar = "", + commentChar, ...) +} + +\arguments{ + \item{prefix}{ + A single character string giving the prefix for three possible input files + (see Details below). + } + \item{suffix}{ + A single character string giving the file name extension. If missing, the + value of \code{suffix} depends on the argument \code{fielddelim}, see + Details below.\cr + Default: \code{"tsv"}. + } + \item{reactList}{ + A single character vector giving a file name containing a reaction list. + Only necessary, if argument \code{suffix} is empty. + } + \item{metList}{ + A single character vector giving a file name containing a metabolite + list.\cr + Default: \code{NA}. + } + \item{modDesc}{ + A single character vector giving a file name containing a model + description.\cr + Default: \code{NA}. + } + \item{fielddelim}{ + A single character string giving the value separator.\cr + Default: \code{"\t"}. + } + \item{entrydelim}{ + A single character string giving the a separator for values containing + more than one entry.\cr + Default: \code{", "}. + } + \item{extMetFlag}{ + A single character string giving the identificator for metabolites which + are outside the system boundary. Only necessary, if the model is a closed + one.\cr + Default: \code{"b"}. + } + \item{excludeComments}{ + A Boolean value. Sometimes, the reaction abbreviations and/or the metabolite + abbreviations contain comments in square brackets. If set to \code{TRUE}, + these comments will be removed. If set to \code{FALSE}, whitespaces included + in comments in metabolite abbreviations will be removed. Comments in + reaction abbreviations stay unchanged. A reaction id with comment is, for + example, the string: \code{pfk [comment]}, with \code{[comment]} being the + comment. There must be at least one whitespace between id and comment, + otherwise it will be considered as compartment flag.\cr + Default: \code{TRUE}. + } + \item{oneSubSystem}{ + A Boolean value. Ignore parameter \code{entrydelim} for the field + \sQuote{subsystem}, if every reaction belongs to exactly one sub system.\cr + Default: \code{TRUE}. + } + \item{mergeMet}{ + Boolean: if set to \code{TRUE}, metabolites used more than once as reactand + or product in a particular reaction are added up, see details below. If set + to \code{FALSE}, the last value is used without warning.\cr + Default: \code{TRUE}. + } + \item{balanceReact}{ + Boolean: if set to \code{TRUE}, metabolites used as reactand and product in + a particular reaction at the same time are balanced, see details below. If + set to \code{FALSE} the last value is used without warning (reactands before + products).\cr + Default: \code{TRUE}. + } + \item{remUnusedMetReact}{ + Boolean: if set to TRUE, metabolites and reactions which are not used in the + stoichiometric matrix will be removed. A metabolite or a reaction is + considered as unused, if the corresponding element of \code{rowSums} + (metabolites) or \code{colSums} (reactions) of the binary version of the + stoichiometric matrix is zero, see details below. If set to \code{FALSE}, + only a warning is given.\cr + Default: \code{FALSE}. + } + \item{singletonMet}{ + Boolean: if set to TRUE, metabolites appearing only once in the + stoichiometric matrix are identified. Metabolites appear only + once, if \code{\link{rowSums}} of the binary stoichiometric matrix is one in + the corresponding row, see details below.\cr + Default: \code{FALSE}. + } + \item{deadEndMet}{ + Boolean: if set to TRUE, metabolites which are produced but not consumed, or + vice versa are identified, see details below. If both arguments + \code{singletonMet} and \code{deadEndMet} are set to \code{TRUE}, the + function will first look for singleton metabolites, and exclude them (and + the corresponding reactions) from the search list. Afterwards, dead end + metabolites are searched only in the smaller model.\cr + Default: \code{FALSE}. + } + \item{remMet}{ + Boolean: if set to TRUE, metabolites identified as singleton or dead end + metabolites will be removed from the model. Additionally, reactions + containing such metabolites will be removed also.\cr + Default: \code{FALSE}. + } + \item{constrMet}{ + Boolean: if set to TRUE, reactions containing metabolites identified as + singleton or dead end metabolites will be constrained to zero.\cr + Default: \code{FALSE}. + } + \item{tol}{ + A single numeric value, giving the smallest positive floating point number + unequal to zero, see details below.\cr + Default: \code{SYBIL_SETTINGS("TOLERANCE")}. + } + \item{fpath}{ + A single character string giving the path to a certain directory containing + the model files.\cr + Default: \code{SYBIL_SETTINGS("PATH_TO_MODEL")}. + } + \item{def_bnd}{ + A single numeric value. Absolute value for uppper and lower bounds for + reaction bounds.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM")}. + } + \item{arrowlength}{ + A single numeric or character value or \code{NULL}. This argument controls + the number of \code{"-"} and \code{"="} used in reaction arrows in the + equation strings. If set to \code{NULL}, one or more symbols are used. + The regular expression used is \code{"<?[=-]+>"}. + If numeric, all reaction arrows must consist of exactly \code{arrowlength} + signs. The regular expression used is \code{"<?[=-]{arrowlength}>"}. + If character, \code{arrowlength} must be a regular expression and will be + used as \code{"<?[=-]arrowlength>"}. For example, if \code{arrowlength} is + \code{"{1,2}"} the regular expression is \code{"<?[=-]{1,2}>"}, meaning the + reaction arrow can consist of one or two signs. In any case, the completed + regular expression will always used with argument \code{perl = TRUE}.\cr + Default: \code{NULL}. + } + \item{quoteChar}{ + Set of quoting characters used for the argument \code{quote} in + \code{\link{read.table}}, see there for details.\cr + Default: \code{""} (disable quoting). + } + \item{commentChar}{ + A single character used for the argument \code{comment.char} in + \code{\link{read.table}}, see there for details. If a comment char is + needed, e.g. \dQuote{\code{@}} (at) seems to be a good one.\cr + Default: \code{""}. + } + \item{\dots}{ + Further arguments passed to \code{\link{read.table}}, e.g. argument + \code{quote}, \code{comment.char} or argument \code{fill}, if some lines do + not have enough elements. If all fields are in double quotes, for example, + set \code{quote} to \code{"\""}. + } +} + +\details{ + A metabolic model consists of three input files: + \enumerate{ + \item \code{<prefix>_react.<suffix>} containing all reactions. + \item \code{<prefix>_met.<suffix>} containing all metabolites. + \item \code{<prefix>_desc.<suffix>} containing a model description. + } + All of these files must be character separated value files (for a detailed + format description and examples, see package vignette). The argument + \code{prefix} is the part of the filenames, all three have in common (e.g. if + they where produced by \code{\link{modelorg2tsv}}). + Alternatively, the arguments \code{reactList}, \code{metList} and + \code{modDesc} can be used. A file containing all reactions must be there, + everything else is optional. + + If \code{suffix} is missing, it is set according to the value of + \code{fielddelim}: + \tabular{ll}{ + \code{"\t"} \tab \code{"tsv"} \cr + \code{";"} \tab \code{"csv"} \cr + \code{","} \tab \code{"csv"} \cr + \code{"|"} \tab \code{"dsv"} \cr + anything else \tab \code{"dsv"} \cr + } + + The argument \code{...} is passed to \code{\link{read.table}}. + + In some cases, it could be necessary, to turn off quoting + \code{quoteChar = ""} (default), if e.g. metabolite names contain quoting + characters \code{"'"} like in \code{3',5'-bisphosphate nucleotidase}. If all + fields are in quotes (e.g. files generated by \code{\link{modelorg2tsv}}), use + \code{quoteChar = "\""} for example. + + The input files are read using the function \code{\link{read.table}}. The + argument \code{header} is set to \code{TRUE} and the argument \code{sep} is + set to the value of \code{fielddelim}. Everything else can be passed via + the \code{...} argument. + + The header for the reactions list may have the following columns: + \tabular{ll}{ + \code{"abbreviation"} \tab a unique reaction id \cr + \code{"name"} \tab a reaction name \cr + \code{"equation"} \tab the reaction equation \cr + \code{"reversible"} \tab TRUE, if the reaction is reversible \cr + \code{"compartment"} \tab reaction compartment(s) (currently unused) \cr + \code{"lowbnd"} \tab lower bound \cr + \code{"uppbnd"} \tab upper bound \cr + \code{"obj_coef"} \tab objective coefficient \cr + \code{"rule"} \tab gene to reaction association \cr + \code{"subsystem"} \tab subsystem of the reaction \cr + } + Every entry except for \code{"equation"} is optional. If there are missing + values in field \code{"lowbnd"}, they will be set to \code{-1 * def_bnd}; + if there are missing values in field \code{"uppbnd"}, they will be set to + \code{def_bnd}; if there are missing values in field \code{"obj_coef"}, they + will be set to \code{0}. + + The header for the metabolites list may have the following columns: + \tabular{ll}{ + \code{"abbreviation"} \tab a unique metabolite id \cr + \code{"name"} \tab a metabolite name \cr + \code{"compartment"} \tab metabolite compartment (currently unused) \cr + } + If a metabolite list is provided, it is supposed to contain at least the + entries \code{"abbreviation"} and \code{"name"}. + + The header for the model description file may have the following columns: + \tabular{ll}{ + \code{"name"} \tab a name for the model \cr + \code{"id"} \tab a shorter model id \cr + \code{"description"} \tab a model description \cr + \code{"compartment"} \tab the compartments \cr + \code{"abbreviation"} \tab unique compartment abbreviations \cr + \code{"Nmetabolites"} \tab number of metabolites \cr + \code{"Nreactions"} \tab number of reactions \cr + \code{"Ngenes"} \tab number of independend genes \cr + \code{"Nnnz"} \tab number of non-zero elements in + the stoichiometric matrix \cr + } + If a file contains a certain column name, there must be no empty entries. + + If a model description file is provided, it is supposed to contain at least + the entries \code{"name"} and \code{"id"}. Otherwise, the filename of the + reactions list will be used (the filename extension and the string + \code{_react} at the end of the filename will be removed). + + The compartments in which a reaction takes place is determined by the + compartment flags of the participating metabolites. + + All fields in the output files of \code{\link{modelorg2tsv}} are in double + quotes. In order to read them, set argument \code{quoteChar} to \code{"\""}. + + Please read the package vignette for detailed information about input formats + and examples. + + If a metabolite is used more than once as product or + reactand of a particular reaction, it is merged: + \code{a + (2) a} is converted to \code{(3) a} + and a warning will be given. + + If a metabolite is used first as reactand and then as + product of a particular reaction, the reaction is + balanced: + \code{(2) b + a -> b + c} + is converted to + \code{ b + a -> c} + + A binary version of the stoichiometric matrix \eqn{S} is constructed + via \eqn{\left|S\right| > tol}{abs(S) > tol}. + + A binary version of the stoichiometric matrix \eqn{S} is scanned for reactions + and metabolites which are not used in S. If there are some, a warning will be + given and the corresponding reactions and metabolites will be removed from + the model if \code{remUnusedMetReact} is set to \code{TRUE}. + + The binary version of the stoichiometric matrix \eqn{S} is scanned for + metabolites, which are used only once in S. If there are some, at least a + warning will be given. If either \code{constrMet} or \code{remMet} is set to + \code{TRUE}, the binary version of \eqn{S} is scanned for paths of singleton + metabolites. If \code{constrMet} is set to \code{TRUE}, reactions containing + those metabolites will be constrained to zero; if \code{remMet} is set to + \code{TRUE}, the metabolites and the reactions containing those metabolites + will be removed from the network. + + In order to find path of singleton metabolites a binary version of the + stoichiometric matrix \eqn{S} is used. Sums of rows gives the vector of + metabolite usage, each element is the number of reactions a metabolite + participates. A single metabolite (singleton) is a metabolite with a row sum + of zero. All columns in \eqn{S} (reactions) containing singleton metabolites + will be set to zero. And again, singleton metabolites will be searched until + none are found. + + The algorithm to find dead end metabolites works in a quite similar way, but + not in the binary version of the stroichiometric matrix. Here, metabolite + \code{i} is considered as dead end, if it is for example produced by reaction + \code{j} but not used by any other reaction \code{k}. +} + +\value{ + An instance of class \code{\link{modelorg}}. +} + +\references{ + The BiGG database \url{http://bigg.ucsd.edu/}. + + Schellenberger, J., Park, J. O., Conrad, T. C., and Palsson, B. Ø., (2010) + BiGG: a Biochemical Genetic and Genomic knowledgebase of large scale metabolic + reconstructions. \emph{BMC Bioinformatics} \bold{11}, 213. + + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\link{read.table}}, \code{\link{modelorg2tsv}}, \code{\link{modelorg}} +} + +\examples{ + ## read example dataset + mp <- system.file(package = "sybil", "extdata") + mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"") + + ## redirect warnings to a log file + sink(file = "warn.log") + mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"") + warnings() + sink() + unlink("warn.log") + + ## print no warnings + suppressWarnings( + mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"")) + + ## print no messages + suppressMessages( + mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"")) + +\dontrun{ + ## set number of warnings to keep + options(nwarnings = 1000) + + ## redirect every output to a file + zz <- file("log.Rout", open = "wt") + sink(zz) + sink(zz, type = "message") + mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"") + warnings() + sink(type = "message") + sink() + close(zz) +} +} +\keyword{ IO } diff --git a/man/resetChanges-methods.Rd b/man/resetChanges-methods.Rd new file mode 100644 index 0000000..fdf7385 --- /dev/null +++ b/man/resetChanges-methods.Rd @@ -0,0 +1,58 @@ +\name{resetChanges-methods} + +\docType{methods} +\encoding{utf8} + +\alias{resetChanges} +\alias{resetChanges-methods} +\alias{resetChanges,sysBiolAlg-method} +\alias{resetChanges,sysBiolAlg_room-method} + +\title{Generic Function to Reset Temporary Changes in Objects of Class sysBiolAlg} + +\description{ + Use method \code{resetChanges} to undo changes in objects of class + \code{\linkS4class{sysBiolAlg}} made by \code{\link{applyChanges}}. +} + +\usage{ +\S4method{resetChanges}{sysBiolAlg}(object, old_val) + +\S4method{resetChanges}{sysBiolAlg_room}(object, old_val) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "sysBiolAlg")}}{ + Method used with objects extending class \code{\linkS4class{sysBiolAlg}} + } + \item{\code{signature(object = "sysBiolAlg_room")}}{ + Method used with objects of class \code{\linkS4class{sysBiolAlg_room}} + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{sysBiolAlg}}. + } + \item{old_val}{ + A list containing the original values of the model. This list is returned + by \code{\link{applyChanges}}. + } +} + +\value{ + Invisibly \code{TRUE} will be returned. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{sysBiolAlg}} and \code{\link{applyChanges}} +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/rmReact.Rd b/man/rmReact.Rd new file mode 100644 index 0000000..2256479 --- /dev/null +++ b/man/rmReact.Rd @@ -0,0 +1,58 @@ +\name{rmReact} +\alias{rmReact} + +\encoding{utf8} + +\title{Remove Reactions From a Model} + +\description{ + The function \code{rmReact} removes reactions from a model. +} + +\usage{ + rmReact(model, react, rm_met = TRUE) +} + +\arguments{ + \item{model}{An object of class \code{\linkS4class{modelorg}}} + \item{react}{An object of class \code{\linkS4class{reactId}}, a + numeric vector, or a character vector containing reaction id's.} + \item{rm_met}{Logical: also remove unused metabolites (default: TRUE).} +} + +\details{ + The argument \code{react} is evaluated by the function + \code{\link{checkReactId}}. +} + +\value{ + An object of class \code{\linkS4class{modelorg}}. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\linkS4class{modelorg}}, + \code{\linkS4class{reactId}} and \code{\link{checkReactId}} +} + +\examples{ + data(Ec_core) + Ec_r <- rmReact(Ec_core, c("ATPM", "Biomass")) +} + +\keyword{manip} + diff --git a/man/robAna.Rd b/man/robAna.Rd new file mode 100644 index 0000000..cf5b1c4 --- /dev/null +++ b/man/robAna.Rd @@ -0,0 +1,114 @@ +\name{robAna} +\alias{robAna} + +\encoding{utf8} + +\title{ + Robustness Analysis +} + +\description{ + Performs robustness analysis for a given metabolic model. +} + +\usage{ + robAna(model, ctrlreact, rng = NULL, + numP = 20, verboseMode = 1, ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{ctrlreact}{ + An object of class \code{\linkS4class{reactId}}, character or integer. + Specifies the control reaction -- the parameter to vary. + } + \item{rng}{ + A numeric vector of length two, giving the lower and upper bound of the + control reaction. If set to \code{NULL} (the default), the range will be + computed by flux variability analysis for the reaction given in + \code{ctrlreact}.\cr + Default: \code{NULL} + } + \item{numP}{ + The number of points to analyse.\cr + Default: \code{20} + } + \item{verboseMode}{ + An integer value indicating the amount of output to stdout, see + \code{\link{optimizer}} for details.\cr + Default: \code{1}. + } + \item{\dots}{ + Further arguments passed to \code{\link{optimizer}}. + } +} + +\details{ + The function \code{robAna} performs a robustness analysis with a given + model. The flux of \code{ctrlreact} will be varied in \code{numP} steps + between the maximum and minimum value the flux of \code{ctrlreact} can reach. + For each of the \code{numP} datapoints the followong lp problem is solved + \deqn{% + \begin{array}{rll}% + \max & \mbox{\boldmath$c$\unboldmath}^{\mathrm{T}} + \mbox{\boldmath$v$\unboldmath} \\[1ex] + \mathrm{s.\,t.} & \mbox{\boldmath$Sv$\unboldmath} = 0 \\[1ex] + & v_j = c_k \\[1ex] + & \alpha_i \leq v_i \leq \beta_i + & \quad \forall i \in \{1, \ldots, n\}, i \neq j\\[1ex] + \end{array}% + }{ + max c^T v + s.t. Sv = 0 + v_j = c_k + a_i <= v_i <= b_i for i = 1, ..., n, i != j + } + with \eqn{\bold{S}}{S} being the stoichiometric matrix, \eqn{\alpha_i}{a_i} + and \eqn{\beta_i}{b_i} being the lower and upper bounds for flux (variable) + \eqn{i}. The total number of variables of the optimization problem is denoted + by \eqn{n}. The parameter \eqn{c_k} is varied \code{numP} times in the range + of \eqn{v_{j,\mathrm{min}}}{v_i,min} to \eqn{v_{j,\mathrm{max}}}{v_i,max}. + The result of the optimization is returned as object of class + \code{\linkS4class{optsol_robAna}} containing the objective + value for each datapoint. + + The extreme points of the range for \code{ctrlreact} are calculated via flux + balance analysis (see also + \code{\linkS4class{sysBiolAlg_fba}}) with the objective + function being minimization and maximization of the flux through + \code{ctrlreact}. +} + +\value{ + An object of class \code{\linkS4class{optsol_robAna}}. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. + + Bernhard Ø. Palsson (2006). + \emph{Systems Biology: Properties of Reconstructed Networks}. + Cambridge University Press. +} + +\author{Gabriel Gelius-Dietrich} + +\examples{ + data(Ec_core) + rb <- robAna(Ec_core, ctrlreact = "EX_o2(e)") + plot(rb) +} + +\keyword{optimize} + diff --git a/man/scaleProb-methods.Rd b/man/scaleProb-methods.Rd new file mode 100644 index 0000000..dea1caa --- /dev/null +++ b/man/scaleProb-methods.Rd @@ -0,0 +1,66 @@ +\name{scaleProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{scaleProb} +\alias{scaleProb-methods} + +\alias{scaleProb,optObj_clpAPI-method} +\alias{scaleProb,optObj_cplexAPI-method} +\alias{scaleProb,optObj_glpkAPI-method} +\alias{scaleProb,optObj_lpSolveAPI-method} + +\title{Scaling of the Constraint Matrix of an Optimization Problem} + +\description{ + Scaling of the constraint matrix of an optimization problem. +} + +\usage{ +\S4method{scaleProb}{optObj_clpAPI}(lp, opt) + +\S4method{scaleProb}{optObj_cplexAPI}(lp, opt) + +\S4method{scaleProb}{optObj_glpkAPI}(lp, opt) + +\S4method{scaleProb}{optObj_lpSolveAPI}(lp, opt) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{opt}{ + Scaling option depending on the used solver software. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/sensitivityAnalysis-methods.Rd b/man/sensitivityAnalysis-methods.Rd new file mode 100644 index 0000000..4f7fa4d --- /dev/null +++ b/man/sensitivityAnalysis-methods.Rd @@ -0,0 +1,60 @@ +\name{sensitivityAnalysis-methods} + +\docType{methods} +\encoding{utf8} + +\alias{sensitivityAnalysis} +\alias{sensitivityAnalysis-methods} + +\alias{sensitivityAnalysis,optObj_cplexAPI-method} +\alias{sensitivityAnalysis,optObj_glpkAPI-method} + +\title{Sensitivity Analysis} + +\description{ + Perform sensitivity analysis. +} + +\usage{ +\S4method{sensitivityAnalysis}{optObj_cplexAPI}(lp, ...) + +\S4method{sensitivityAnalysis}{optObj_glpkAPI}(lp, ...) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{...}{ + Further arguments passed to the initialization function of the solver + package. + } +} + +\value{ + The \pkg{glpkAPI} method generates a file \code{"sar.txt"} and the + \pkg{cplexAPI} method returns a list. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/setColsNames-methods.Rd b/man/setColsNames-methods.Rd new file mode 100644 index 0000000..1619b54 --- /dev/null +++ b/man/setColsNames-methods.Rd @@ -0,0 +1,74 @@ +\name{setColsNames-methods} + +\docType{methods} +\encoding{utf8} + +\alias{setColsNames} +\alias{setColsNames-methods} + +\alias{setColsNames,optObj_clpAPI,numeric,character-method} +\alias{setColsNames,optObj_cplexAPI,numeric,character-method} +\alias{setColsNames,optObj_glpkAPI,numeric,character-method} +\alias{setColsNames,optObj_lpSolveAPI,numeric,character-method} + +\title{Set/Change Variable Names} + +\description{ + Set or change names of variables (columns) used in a optimization problem. +} + +\usage{ +\S4method{setColsNames}{optObj_clpAPI,numeric,character}(lp, j, names) + +\S4method{setColsNames}{optObj_cplexAPI,numeric,character}(lp, j, names) + +\S4method{setColsNames}{optObj_glpkAPI,numeric,character}(lp, j, names) + +\S4method{setColsNames}{optObj_lpSolveAPI,numeric,character}(lp, j, names) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", j = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", j = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", j = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", j = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{j}{ + A numeric vector of column indices. + } + \item{names}{ + A character vector of the same length as \code{j} containing the + column names. + } +} + +\value{ + \code{NULL} is invisibly returned. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/setObjDir-methods.Rd b/man/setObjDir-methods.Rd new file mode 100644 index 0000000..321e2dd --- /dev/null +++ b/man/setObjDir-methods.Rd @@ -0,0 +1,115 @@ +\name{setObjDir-methods} + +\docType{methods} +\encoding{utf8} + +\alias{setObjDir} +\alias{setObjDir-methods} + +\alias{setObjDir,optObj_clpAPI,character-method} +\alias{setObjDir,optObj_clpAPI,numeric-method} +\alias{setObjDir,optObj_cplexAPI,character-method} +\alias{setObjDir,optObj_cplexAPI,integer-method} +\alias{setObjDir,optObj_cplexAPI,numeric-method} +\alias{setObjDir,optObj_glpkAPI,character-method} +\alias{setObjDir,optObj_glpkAPI,integer-method} +\alias{setObjDir,optObj_glpkAPI,numeric-method} +\alias{setObjDir,optObj_lpSolveAPI,character-method} +\alias{setObjDir,optObj_lpSolveAPI,numeric-method} + +\title{Set Direction of Optimization} + +\description{ + Set direction of optimization. +} + +\usage{ +\S4method{setObjDir}{optObj_clpAPI,character}(lp, lpdir) + +\S4method{setObjDir}{optObj_clpAPI,numeric}(lp, lpdir) + +\S4method{setObjDir}{optObj_cplexAPI,character}(lp, lpdir) + +\S4method{setObjDir}{optObj_cplexAPI,integer}(lp, lpdir) + +\S4method{setObjDir}{optObj_cplexAPI,numeric}(lp, lpdir) + +\S4method{setObjDir}{optObj_glpkAPI,character}(lp, lpdir) + +\S4method{setObjDir}{optObj_glpkAPI,integer}(lp, lpdir) + +\S4method{setObjDir}{optObj_glpkAPI,numeric}(lp, lpdir) + +\S4method{setObjDir}{optObj_lpSolveAPI,character}(lp, lpdir) + +\S4method{setObjDir}{optObj_lpSolveAPI,numeric}(lp, lpdir) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", lpdir = "character")}}{ + method to use with package \pkg{optObj_clpAPI}. Set \code{lpdir} to + \code{"max"} for maximization or \code{"min"} for minimization. + } + \item{\code{signature(lp = "optObj_clpAPI", lpdir = "numeric")}}{ + method to use with package \pkg{optObj_clpAPI}. Set \code{lpdir} to + \code{-1} for maximization or \code{1} for minimization. + } + \item{\code{signature(lp = "optObj_cplexAPI", lpdir = "character")}}{ + method to use with package \pkg{optObj_cplexAPI}. Set \code{lpdir} to + \code{"max"} for maximization or \code{"min"} for minimization. + } + \item{\code{signature(lp = "optObj_cplexAPI", lpdir = "integer")}}{ + method to use with package \pkg{optObj_cplexAPI}. Set \code{lpdir} to + \code{CPX_MAX} for maximization or \code{CPX_MIN} for minimization. + } + \item{\code{signature(lp = "optObj_cplexAPI", lpdir = "numeric")}}{ + method to use with package \pkg{optObj_cplexAPI}. Set \code{lpdir} to + \code{-1} for maximization or \code{1} for minimization. + } + \item{\code{signature(lp = "optObj_glpkAPI", lpdir = "character")}}{ + method to use with package \pkg{optObj_glpkAPI}. Set \code{lpdir} to + \code{"max"} for maximization or \code{"min"} for minimization. + } + \item{\code{signature(lp = "optObj_glpkAPI", lpdir = "integer")}}{ + method to use with package \pkg{optObj_glpkAPI}. Set \code{lpdir} to + \code{GLP_MAX} for maximization or \code{GLP_MIN} for minimization. + } + \item{\code{signature(lp = "optObj_glpkAPI", lpdir = "numeric")}}{ + method to use with package \pkg{optObj_glpkAPI}. Set \code{lpdir} to + \code{-1} for maximization or \code{1} for minimization. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", lpdir = "character")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. Set \code{lpdir} to + \code{"max"} for maximization or \code{"min"} for minimization. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", lpdir = "numeric")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. Set \code{lpdir} to + \code{-1} for maximization or \code{1} for minimization. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{lpdir}{ + A single character string, numeric or integer value. Can be set to + \code{"max"} or \code{-1} for maximization, or \code{"min"} or \code{1} for + minimization. For packages \pkg{cplexAPI} and \code{glpkAPI} it is also + possible to use the corresponding constant given by the package. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/setRhsZero-methods.Rd b/man/setRhsZero-methods.Rd new file mode 100644 index 0000000..17ed8c1 --- /dev/null +++ b/man/setRhsZero-methods.Rd @@ -0,0 +1,64 @@ +\name{setRhsZero-methods} + +\docType{methods} +\encoding{utf8} + +\alias{setRhsZero} +\alias{setRhsZero-methods} + +\alias{setRhsZero,optObj_clpAPI-method} +\alias{setRhsZero,optObj_cplexAPI-method} +\alias{setRhsZero,optObj_glpkAPI-method} +\alias{setRhsZero,optObj_lpSolveAPI-method} + +\title{Set Right Hand Side of the Optimization Problem To Zero} + +\description{ + Set right hand side of the optimization problem to zero: + \eqn{\mbox{\boldmath$Sv$\unboldmath} = 0}{Sv = 0}. +} + +\usage{ +\S4method{setRhsZero}{optObj_clpAPI}(lp) + +\S4method{setRhsZero}{optObj_cplexAPI}(lp) + +\S4method{setRhsZero}{optObj_glpkAPI}(lp) + +\S4method{setRhsZero}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/setRowsNames-methods.Rd b/man/setRowsNames-methods.Rd new file mode 100644 index 0000000..15f935f --- /dev/null +++ b/man/setRowsNames-methods.Rd @@ -0,0 +1,74 @@ +\name{setRowsNames-methods} + +\docType{methods} +\encoding{utf8} + +\alias{setRowsNames} +\alias{setRowsNames-methods} + +\alias{setRowsNames,optObj_clpAPI,numeric,character-method} +\alias{setRowsNames,optObj_cplexAPI,numeric,character-method} +\alias{setRowsNames,optObj_glpkAPI,numeric,character-method} +\alias{setRowsNames,optObj_lpSolveAPI,numeric,character-method} + +\title{Set/Change Constraint Names} + +\description{ + Set or change names of constraints (rows) used in a optimization problem. +} + +\usage{ +\S4method{setRowsNames}{optObj_clpAPI,numeric,character}(lp, i, names) + +\S4method{setRowsNames}{optObj_cplexAPI,numeric,character}(lp, i, names) + +\S4method{setRowsNames}{optObj_glpkAPI,numeric,character}(lp, i, names) + +\S4method{setRowsNames}{optObj_lpSolveAPI,numeric,character}(lp, i, names) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", i = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI", i = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", i = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", i = "numeric", names = "character")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{i}{ + A numeric vector of row indices. + } + \item{names}{ + A character vector of the same length as \code{i} containing the + row names. + } +} + +\value{ + \code{NULL} is invisibly returned. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/setSolverParm-methods.Rd b/man/setSolverParm-methods.Rd new file mode 100644 index 0000000..c038d4e --- /dev/null +++ b/man/setSolverParm-methods.Rd @@ -0,0 +1,76 @@ +\name{setSolverParm-methods} + +\docType{methods} +\encoding{utf8} + +\alias{setSolverParm} +\alias{setSolverParm-methods} + +\alias{setSolverParm,optObj_clpAPI-method} +\alias{setSolverParm,optObj_cplexAPI-method} +\alias{setSolverParm,optObj_glpkAPI-method} +\alias{setSolverParm,optObj_lpSolveAPI-method} + +\title{Set Parameters Used By The Optimization Software} + +\description{ + Set parameters used by the optimization software. Parameters are set on a + key-value basis. Sets of parameters can be set via a named list or a named + data frame. The names of the parameters itself and possible values differ from + solver to solver. Please consult the documentation of your solver software + to get information about available parameters. +} + +\usage{ +\S4method{setSolverParm}{optObj_clpAPI}(lp, solverParm) + +\S4method{setSolverParm}{optObj_cplexAPI}(lp, solverParm) + +\S4method{setSolverParm}{optObj_glpkAPI}(lp, solverParm) + +\S4method{setSolverParm}{optObj_lpSolveAPI}(lp, solverParm) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. This method is currently + unused. It is not possible to provide parameters for package \pkg{clpAPI}. + Always \code{FALSE} will be returned. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. In order to set + integer parameters (parameters of type \code{CPXINT}), the value must be + of type integer. For example, like \code{as.integer(42)} or \code{23L}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{solverParm}{ + A named list or data frame containing sets of parameters. They must not + contain \code{NA} values and every list or data frame element must have + length one. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/shrinkMatrix-methods.Rd b/man/shrinkMatrix-methods.Rd new file mode 100644 index 0000000..1e0f40f --- /dev/null +++ b/man/shrinkMatrix-methods.Rd @@ -0,0 +1,83 @@ +\name{shrinkMatrix-methods} + +\docType{methods} +\encoding{utf8} + +\alias{shrinkMatrix} +\alias{shrinkMatrix-methods} +\alias{shrinkMatrix,modelorg-method} + +\title{Get a Subset of Matrix Like Objects} + +\description{ + Generate subsets of matrix-like objects. +} + +\usage{ +\S4method{shrinkMatrix}{modelorg}(X, i = NULL, j = NULL, + tol = SYBIL_SETTINGS("TOLERANCE")) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(X = "modelorg")}}{ + method to use with objects of class \code{\linkS4class{modelorg}} for + subsets of the stoichiometric matrix. Either argument \code{i} or + argument \code{j} can be used, not both at the same time. If they are of + type character, they must contain metabolite or reaction id's existing + in the \code{\linkS4class{modelorg}} object. Use \code{i} to get the + reactions in which the metabolites given in \code{i} participate (the + metabolites given in \code{i} will be located in the first rows of the + result). Use \code{j} to get all reactions given in \code{j}. The method + will remove all non-zero rows and columns from the result. + } + } +} + +\arguments{ + \item{X}{ + An object treated to be matrix-like. + } + \item{i}{ + A numeric or character vector containing row indices of the matrix + given in argument \code{X}. For the \code{\linkS4class{modelorg}} method, + this can be an object of class \code{\linkS4class{reactId_Exch}}.\cr + Default: \code{NULL}. + } + \item{j}{ + A numeric or character vector containing column indices of the + matrix given in argument \code{X}. For the \code{\linkS4class{modelorg}} + method, this can be an object of class \code{\linkS4class{reactId}}.\cr + Default: \code{NULL}. + } + \item{tol}{ + A tolerance value. An element \eqn{X_{ij}}{X[i, j]} of the matrix given in + argument \code{X} is considered to be zero, if + \eqn{|X_{ij}| > \mathit{tol}}{abs([X[i, j]]) > tol} is true.\cr + Default: \code{SYBIL_SETTINGS("TOLERANCE")}. + } +} + +\value{ + The \code{\linkS4class{modelorg}} method will return an object of class + \code{\linkS4class{Matrix}}, with columns named by their reaction id's and + rows named by their metabolite id's. +} + +\examples{ + # get the part of the stoichiometric containing + # the exchange reactions + data(Ec_core) + ex <- findExchReact(Ec_core) + shrinkMatrix(Ec_core, j = ex) +} + +\author{ + Claus Jonathan Fritzemeier, Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{modelorg}}. +} + +\keyword{methods} diff --git a/man/singletonMetabolites-methods.Rd b/man/singletonMetabolites-methods.Rd new file mode 100644 index 0000000..b69519d --- /dev/null +++ b/man/singletonMetabolites-methods.Rd @@ -0,0 +1,59 @@ +\name{singletonMetabolites-methods} + +\docType{methods} +\encoding{utf8} + +\alias{singletonMetabolites} +\alias{singletonMetabolites-methods} +\alias{singletonMetabolites,modelorg-method} + +\title{Identify Singleton Metabolites} + +\description{ + Search a metabolic network for metabolites, which appear only once in the + stoichiometric matrix. +} + +\usage{ +\S4method{singletonMetabolites}{modelorg}(object,tol,retIds) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(object = "modelorg")}}{ + method to use with class \code{\linkS4class{modelorg}}. + } + } +} + +\arguments{ + \item{object}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{tol}{ + A numeric tolerance value: an entry of the stoichiometric matrix \eqn{s_ij} + is considered to be non-zero if \eqn{abs(s_ij) > tol} is \code{TRUE}.\cr + Default: \code{SYBIL_SETTINGS("TOLERANCE")}. + } + \item{retIds}{ + Boolean. If set to \code{TRUE}, a list containing metabolite id's will be + returned, otherwise a list of logical vectors.\cr + Default: \code{TRUE}. + } +} + +\value{ + A list will be returned: + \item{smet}{singleton metabolites} + \item{sreact}{reactions containing singleton metabolites} +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{modelorg}} and \code{\link{readTSVmod}}. +} + +\keyword{methods} diff --git a/man/solveLp-methods.Rd b/man/solveLp-methods.Rd new file mode 100644 index 0000000..8b6a88e --- /dev/null +++ b/man/solveLp-methods.Rd @@ -0,0 +1,63 @@ +\name{solveLp-methods} + +\docType{methods} +\encoding{utf8} + +\alias{solveLp} +\alias{solveLp-methods} + +\alias{solveLp,optObj_clpAPI-method} +\alias{solveLp,optObj_cplexAPI-method} +\alias{solveLp,optObj_glpkAPI-method} +\alias{solveLp,optObj_lpSolveAPI-method} + +\title{Optimize Problem Object} + +\description{ + Optimize problem object. +} + +\usage{ +\S4method{solveLp}{optObj_clpAPI}(lp) + +\S4method{solveLp}{optObj_cplexAPI}(lp) + +\S4method{solveLp}{optObj_glpkAPI}(lp) + +\S4method{solveLp}{optObj_lpSolveAPI}(lp) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI")}}{ + method to use with package \pkg{optObj_clpAPI}. + } + \item{\code{signature(lp = "optObj_cplexAPI")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/summaryOptsol-class.Rd b/man/summaryOptsol-class.Rd new file mode 100644 index 0000000..adffc56 --- /dev/null +++ b/man/summaryOptsol-class.Rd @@ -0,0 +1,168 @@ +\name{summaryOptsol-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{summaryOptsol-class} + +\alias{ex_met,summaryOptsol-method} +\alias{ex_val,summaryOptsol-method} +\alias{image,summaryOptsol-method} +\alias{mod_id,summaryOptsol-method} +\alias{mod_id<-,summaryOptsol-method} +\alias{mod_key,summaryOptsol-method} +\alias{mod_key<-,summaryOptsol-method} +\alias{mod_obj,summaryOptsol-method} +\alias{mod_obj<-,summaryOptsol-method} +\alias{nnzero,summaryOptsol-method} +\alias{nzeros,summaryOptsol-method} +\alias{plot,summaryOptsol,missing-method} +\alias{printExchange,summaryOptsol-method} +\alias{ex_met} +\alias{ex_val} +\alias{mod_obj<-} +\alias{nzeros} +\alias{printExchange} + +\title{Class \code{"summaryOptsol"}} + +\description{ + Class \code{summaryOptsol} stores a summary of instances of class + \code{\linkS4class{optsol}}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form \code{summaryOptsol(opt, mod)}. +} + +\section{Slots}{ + \describe{ + \item{\code{mod_id}:}{Object of class \code{"character"} + containing the model id of the analyzed model. + } + \item{\code{mod_key}:}{Object of class \code{"character"} + containing the model key of the used model. + } + \item{\code{nzeros}:}{Object of class \code{"integer"} + giving the number of zeros in the flux distribution. + } + \item{\code{nnonzero}:}{Object of class \code{"integer"} + giving the number of non-zeros in the flux distribution. + } + \item{\code{mod_obj}:}{Object of class \code{"numeric"} + containing the objective coefficients of the model. + } + \item{\code{ex_met}:}{Object of class \code{"character"} + containing the id's of exchange metabolites. These are metabolites which + are transported across the system boundary. + } + \item{\code{ex_val}:}{Object of class \code{"Matrix"} + with each column being the flux distribution of the exchange metabolites + of one optimization. + } + \item{\code{react_id}:}{Object of class \code{"list"} + with each list element containing a set of reaction id's limiting one + optimization. A reactions is considered as \dQuote{limiting}, if it + has a non-zero flux value and if its flux value hits an upper or lower + bound. + } + \item{\code{chksol}:}{Object of class \code{"checksol"} + describing return values of the mathematical programming software and + solution status. + } + } +} + +\section{Methods}{ + \describe{ + \item{ex_met}{\code{signature(object = "summaryOptsol")}: + gets the \code{ex_met} slot. + } + \item{ex_val}{\code{signature(object = "summaryOptsol")}: + gets the \code{ex_val} slot. + } + \item{\code{plot}:}{\code{signature(x = "summaryOptsol")}: + plots a \code{\link{histogram}} of the values of the objective function + in optimal state. Additional arguments can be passed to + \code{\link{histogram}} via the \code{\dots} argument. + } + \item{image}{\code{signature(x = "summaryOptsol")}: + plots a grey-scale representation of the exchange fluxes of the flux + distribution. Black: metabolite is produced, grey: metabolite is imported. + Further arguments are: + \describe{ + \item{\code{printOut}}{ + A single logical value. If set to \code{FALSE}, a + \code{\link[lattice]{trellis.object}} is returned invisibly. + Otherwise, a plot is drawn additionally.\cr + Default: \code{TRUE}. + } + \item{\code{...}}{ + Further arguments to \code{\link[Matrix]{image-methods}}. + } + } + } + \item{mod_id}{\code{signature(object = "summaryOptsol")}: + gets the \code{mod_id} slot. + } + \item{mod_id<-}{\code{signature(object = "summaryOptsol")}: + sets the \code{mod_id} slot. + } + \item{mod_key}{\code{signature(object = "summaryOptsol")}: + gets the \code{mod_key} slot. + } + \item{mod_key<-}{\code{signature(object = "summaryOptsol")}: + sets the \code{mod_key} slot. + } + \item{mod_obj}{\code{signature(object = "summaryOptsol")}: + gets the \code{mod_obj} slot. + } + \item{mod_obj<-}{\code{signature(object = "summaryOptsol")}: + sets the \code{mod_obj} slot. + } + \item{nnzero}{\code{signature(object = "summaryOptsol")}: + gets the \code{nnonzero} slot. + } + \item{nzeros}{\code{signature(object = "summaryOptsol")}: + gets the \code{nzeros} slot. + } + \item{printExchange}{\code{signature(object = "summaryOptsol")}: + prints a matrix indicating wether a particular metabolite is taken up or + produced by the metabolic network given certain conditions. Each line + corresponds to one metabolite and each column to one optimization. + A \code{"-"} indicates uptake and \code{"+"} indicates excretion. A + whitespace character \code{" "} is used, if the metabolite is unused. + Further arguments are: + \describe{ + \item{\code{i}}{ + A numeric vector indicating the metabolites (rows) to print: + \code{i[x]} points to matabolite \code{ec_met(object)[x]}. + } + \item{\code{j}}{ + A numeric vector indicating the optimizations (columns) to print. + } + \item{\code{dense}}{ + A single Boolean value. If set to \code{TRUE}, each column has a + column with of one letter. + } + } + } + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Constructor function \code{\link{summaryOptsol}}, + class \code{\linkS4class{optsol}} and class \code{\linkS4class{modelorg}}. +} + +\examples{ + showClass("summaryOptsol") +} + +\keyword{classes} diff --git a/man/summaryOptsol.Rd b/man/summaryOptsol.Rd new file mode 100644 index 0000000..d0927d6 --- /dev/null +++ b/man/summaryOptsol.Rd @@ -0,0 +1,68 @@ +\name{summaryOptsol} +\alias{summaryOptsol} + +\title{ + Summarize Objects of Class Optsol +} + +\description{ + Generates a quick overview of results of simulations stored in objects + of class \code{\linkS4class{optsol}}. +} + +\usage{ + summaryOptsol(opt, mod, perc = 1, tol = SYBIL_SETTINGS("TOLERANCE")) +} + +\arguments{ + \item{opt}{ + An object of class \code{\linkS4class{optsol}}. + } + \item{mod}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{perc}{ + A single numeric value in between zero and one indicating how close a flux + value has to reach a flux boundary in order to be called \dQuote{limiting}, + see Details below.\cr + Default: \code{1}. + } + \item{tol}{ + A tolerance value, see Details below.\cr + Default: \code{SYBIL_SETTINGS("TOLERANCE")}. + } +} + +\details{ + The function \code{summaryOptsol} generates a summary of the simulations + resulting in the object given in argument \code{opt}. Both model id's, of + the \code{\linkS4class{optsol}} object and of the + \code{\linkS4class{modelorg}} object must be identical. The resulting object + of class \code{\linkS4class{summaryOptsol}} contains information about the + number of zeros and non-zeros in the flux distribution, the substrates and + products and about the limiting reactions. + + A reaction \eqn{i} is called \dQuote{limiting}, if its flux value \eqn{v_i} + is non-zero: \eqn{|v_i| > \mathit{tol}}{abs(v_i) > tol} and if its flux value + hits the flux boundaries: + \eqn{v_i \leq v_{i,\textrm{min}} \cdot \mathit{perc} \lor + v_i \geq v_{i,\textrm{max}} \cdot \mathit{perc}}{v_i <= v_i,min * perc + || v_i >= v_i,max * perc}. +} + +\value{ + An object of class \code{\linkS4class{summaryOptsol}} if a flux distribution + exists in argument \code{opt}, otherwise a \code{\link{summary}} of the + objective values (\code{\link{mod_obj}}) is returned. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{optsol}}, class \code{\linkS4class{modelorg}} and + class \code{\linkS4class{summaryOptsol}}. +} + +\keyword{classes} diff --git a/man/sybil-internal.Rd b/man/sybil-internal.Rd new file mode 100644 index 0000000..d2437bc --- /dev/null +++ b/man/sybil-internal.Rd @@ -0,0 +1,23 @@ +\name{sybil-internal} + +% waiting for documentation to be written +\alias{modelorg2text} +\alias{readTEXTmod} +%\alias{readModel} + +% ??? +\alias{object} + + +\title{Internal sybil Functions} + +\description{ + Internal sybil functions +} + +\details{ + These are not to be called by the user (or in some cases are just + waiting for proper documentation to be written :). +} + +\keyword{ internal } diff --git a/man/sybil-package.Rd b/man/sybil-package.Rd new file mode 100644 index 0000000..5ccce14 --- /dev/null +++ b/man/sybil-package.Rd @@ -0,0 +1,88 @@ +\name{sybil-package} + +\alias{sybil-package} +\alias{sybil} + +\encoding{utf8} + +\docType{package} + +\title{ + sybil -- Efficient Constrained Based Modelling in R +} + +\description{ + The package \pkg{sybil} is a collection of functions designed for + in silico analysis---in particular constrained based analysis---of metabolic + networks. +} + +\details{ + + The package sybil is designed to read metabolic networks from csv files. + This is done by the function \code{\link{readTSVmod}}. The function returns + an object of the class \code{\linkS4class{modelorg}}. + + Read csv files (example files included): + \preformatted{ +mpath <- system.file(package = "sybil", "extdata") +model <- readTSVmod(prefix = "Ec_core", + fpath = mpath, quote = "\"") + } + Perform flux balance analysis (FBA):\cr + \code{ec_f <- optimizeProb(model)} + + Perform single gene deletion analysis:\cr + \code{ec_g <- oneGeneDel(model)} + + Plot the values of the objective function after optimization in a + histogram:\cr + \code{plot(ec_g)} + + Perform flux variability analysis:\cr + \code{ec_v <- fluxVar(model)} + + Plot the result:\cr + \code{plot(ec_v)} +} + +\author{ + Gabriel Gelius-Dietrich + + Maintainer: geliudie@uni-duesseldorf.de +} + +\references{ + The BiGG database \url{http://bigg.ucsd.edu/}. + + Schellenberger, J., Park, J. O., Conrad, T. C., and Palsson, B. Ø., (2010) + BiGG: a Biochemical Genetic and Genomic knowledgebase of large scale metabolic + reconstructions. \emph{BMC Bioinformatics} \bold{11}, 213. + + The openCOBRA project \url{http://opencobra.sourceforge.net/}. + + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. +} + +\seealso{ + Package \pkg{sybilSBML} and there the function \code{readSBMLmod} to read + metabolic models written in SBML language. +} + +\examples{ + data(Ec_core) + Ec_ofd <- oneGeneDel(Ec_core) + plot(Ec_ofd) +} + +\keyword{package} + diff --git a/man/sybilError-class.Rd b/man/sybilError-class.Rd new file mode 100644 index 0000000..9f4746f --- /dev/null +++ b/man/sybilError-class.Rd @@ -0,0 +1,74 @@ +\name{sybilError-class} + +\Rdversion{1.1} +\docType{class} + +\alias{sybilError-class} +\alias{sybilError} + +\alias{emsg,sybilError-method} +\alias{emsg<-,sybilError-method} +\alias{emsg} +\alias{emsg<-} +\alias{enum,sybilError-method} +\alias{enum<-,sybilError-method} +\alias{enum} +\alias{enum<-} + +\title{Class \code{"sybilError"}} + +\description{ + Structure of the class \code{"sybilError"}. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the function \code{sybilError}: + + \code{test <- sybilError(errmsg = "", number = NA)}. + \describe{ + \item{\code{errmsg}:}{Object of class \code{"character"} containing an + error message. + } + \item{\code{number}:}{Object of class \code{"integer"} containing an error + number. + } + } +} + +\section{Slots}{ + \describe{ + \item{\code{emsg}:}{Object of class \code{"character"} error message. + } + \item{\code{enum}:}{Object of class \code{"integer"} error number. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{emsg}:}{\code{signature(object = "sybilError")}: + gets the \code{emsg} slot. + } + \item{\code{emsg<-}:}{\code{signature(object = "sybilError")}: + sets the \code{emsg} slot. + } + \item{\code{enum}:}{\code{signature(object = "sybilError")}: + gets the \code{enum} slot. + } + \item{\code{enum<-}:}{\code{signature(object = "sybilError")}: + sets the \code{enum} slot. + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\seealso{ + \code{\link{optimizeProb}} +} + +\examples{ + showClass("sybilError") +} + +\keyword{classes} diff --git a/man/sybilLog-class.Rd b/man/sybilLog-class.Rd new file mode 100644 index 0000000..cf0e940 --- /dev/null +++ b/man/sybilLog-class.Rd @@ -0,0 +1,282 @@ +\name{sybilLog-class} + +\Rdversion{1.1} +\docType{class} + +\alias{sybilLog-class} +\alias{sybilLog} + +\alias{file-class} + +\alias{didFoot,sybilLog-method} +\alias{didFoot<-,sybilLog-method} +\alias{didFoot} +\alias{didFoot<-} +\alias{fenc,sybilLog-method} +\alias{fenc<-,sybilLog-method} +\alias{fenc} +\alias{fenc<-} +\alias{fh,sybilLog-method} +\alias{fh<-,sybilLog-method} +\alias{fh} +\alias{fh<-} +\alias{fname,sybilLog-method} +\alias{fname<-,sybilLog-method} +\alias{fname} +\alias{fname<-} +\alias{fpath,sybilLog-method} +\alias{fpath<-,sybilLog-method} +\alias{fpath} +\alias{fpath<-} +\alias{logCall,sybilLog-method} +\alias{logCall} +\alias{logClose<-,sybilLog-method} +\alias{logClose<-} +\alias{logComment,sybilLog-method} +\alias{logComment} +\alias{logError,sybilLog-method} +\alias{logError,sybilLog,ANY,ANY-method} +\alias{logError,sybilLog,ANY,numeric-method} +\alias{logError} +\alias{logFH,sybilLog-method} +\alias{logFH} +\alias{logFoot<-,sybilLog-method} +\alias{logFoot<-} +\alias{logHead,sybilLog-method} +\alias{logHead} +\alias{loglevel,sybilLog-method} +\alias{loglevel<-,sybilLog-method} +\alias{loglevel} +\alias{loglevel<-} +\alias{logMessage,sybilLog-method} +\alias{logMessage} +\alias{logOptimization,sybilLog-method} +\alias{logOptimization} +\alias{logOptimizationTH,sybilLog-method} +\alias{logOptimizationTH} +\alias{logStep<-,sybilLog-method} +\alias{logStep<-} +\alias{logWarning,sybilLog-method} +\alias{logWarning} +\alias{lstname,sybilLog-method} +\alias{lstname} +\alias{verblevel,sybilLog-method} +\alias{verblevel<-,sybilLog-method} +\alias{verblevel} +\alias{verblevel<-} + +\alias{logFileFH} + + +\title{Class \code{"sybilLog"}} + +\description{ + Handles log files, messages warnings and errors. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the function \code{sybilLog}: + + \code{logObj <- sybilLog(filename)}. +} + +\section{Slots}{ + \describe{ + \item{\code{fh}:}{Object of class \code{\link{file}} which is a connection + to a file to print to. + } + \item{\code{fname}:}{Object of class \code{"character"} + being the name of the file to print to. If set to \code{NA}, no logfile + is used. Default: \code{NA}. + } + \item{\code{fpath}:}{Object of class \code{"character"} + giving the path to the file mentioned in \code{fname}. + Default: \code{"."}. + } + \item{\code{fenc}:}{Object of class \code{"character"} + encoding of the log file. Default: \code{""}. + } + \item{\code{loglevel}:}{Object of class \code{"integer"} + controlling the amount of details to log: If set to \code{0}, + nothing will be written to the logfile. If set to \code{> 0}, all + warnings are logged; if set do \code{> 1}, also messages are logged. + If \code{loglevel} is \code{> 2}, the used function call will be printed. + Default: \code{0}. + } + \item{\code{verblevel}:}{Object of class \code{"integer"} + controlling the amount of details to log: If set to \code{0}, + nothing will be written to the standard output connection. + If set to \code{> 0}, all warnings are logged; if set do \code{> 1}, also + messages are logged. Default: \code{0}. + } + \item{\code{lastStep}:}{Object of class \code{"list"} + which is a stack, containing character strings describing performed steps. + See also \code{\link{sybilStack}}. + } + \item{\code{lstname}:}{Object of class \code{"list"} + giving the name of the stack in \code{lastStep}. + } + \item{\code{didFoot}:}{Object of class \code{"logical"} + which is \code{FALSE}, if the footer of the log file is not yet printed, + otherwise \code{TRUE}. This is useful if the function which is logged, + stops unexpected. + } + } +} + +\section{Methods}{ + \describe{ + \item{\code{didFoot}}{\code{signature(object = "sybilLog")}: + gets the \code{didFoot} slot. + } + \item{\code{didFoot<-}}{\code{signature(object = "sybilLog")}: + sets the \code{didFoot} slot. + } + \item{\code{fenc}}{\code{signature(object = "sybilLog")}: + gets the \code{fenc} slot. + } + \item{\code{fenc<-}}{\code{signature(object = "sybilLog")}: + sets the \code{fenc} slot. + } + \item{\code{fh}}{\code{signature(object = "sybilLog")}: + gets the \code{fh} slot. + } + \item{\code{fh<-}}{\code{signature(object = "sybilLog")}: + sets the \code{fh} slot. + } + \item{\code{fname}}{\code{signature(object = "sybilLog")}: + gets the \code{fname} slot. + } + \item{\code{fname<-}}{\code{signature(object = "sybilLog")}: + sets the \code{fname} slot. + } + \item{\code{fpath}}{\code{signature(object = "sybilLog")}: + gets the \code{fpath} slot. + } + \item{\code{fpath<-}}{\code{signature(object = "sybilLog")}: + sets the \code{fpath} slot. + } + \item{\code{loglevel}}{\code{signature(object = "sybilLog")}: + gets the \code{loglevel} slot. + } + \item{\code{loglevel<-}}{\code{signature(object = "sybilLog")}: + sets the \code{loglevel} slot. + } + \item{\code{lstname}}{\code{signature(object = "sybilLog")}: + gets the \code{lstname} slot. + } + \item{\code{verblevel}}{\code{signature(object = "sybilLog")}: + gets the \code{verblevel} slot. + } + \item{\code{verblevel<-}}{\code{signature(object = "sybilLog")}: + sets the \code{verblevel} slot. + } + + \item{\code{logCall}}{\code{signature(object = "sybilLog")} (\code{nog}): + writes all arguments and values of the function call to be + logged to the log file. Nothing is printed to the standard + output; \code{verblevel} has no meaning here; \code{verblevel} + must be \code{> 2}. + \tabular{rr}{ + \code{nog} \tab number of generations to go back \cr + } + } + \item{\code{logClose<-}}{\code{signature(object = "sybilLog")}: + close the connection in slot \code{fh} and set it to \code{NA}. + If slot \code{didFoot} is not \code{TRUE}, it prints a log + comment to the connection in \code{fh} mentioning, that the + logging ended unexpected. + } + \item{\code{logComment}}{\code{signature(object = "sybilLog")} + (\code{cmt, commentChar}): + add a comment to the log file if \code{loglevel} is \code{> 2} and to + \code{stdout} if \code{verblevel} is \code{> 2}. + \tabular{rr}{ + \code{cmt} \tab the comment text \cr + \code{cmtChar} \tab a string to prefix \code{cmt}, + default: \code{# } \cr + } + } + \item{\code{logError}}{\code{signature(object = "sybilLog")} + (\code{msg, num}): + add an error message to the log file. Returns an object of + class \code{\linkS4class{sybilError}}. + \tabular{rr}{ + \code{msg} \tab the error message \cr + \code{num} \tab an error number \cr + } + } + \item{\code{logFH}}{\code{signature(object = "sybilLog")}: + Returns \code{TRUE}, if slot \code{fh} is of class \code{file}, otherwise + \code{FALSE}. + } + \item{\code{logFoot<-}}{\code{signature(object = "sybilLog")}: + Print a head for your log file. + } + \item{\code{logHead}}{\code{signature(object = "sybilLog")}: + Print a foot for your log file. + } + \item{\code{logMessage}}{\code{signature(object = "sybilLog")}: + add a message to the log file if \code{loglevel} is \code{> 1}. + \tabular{rr}{ + \code{...} \tab strings pasted to the log file \cr + } + } + \item{\code{logOptimization}}{\code{signature(object = "sybilLog")}: + (\code{ok, stat, obj, del, i}): + add a row containing results of an optimization to the log file if + \code{loglevel} is \code{> 2} and to \code{stdout} if \code{verblevel} is + \code{> 2}. + \tabular{rr}{ + \code{opt no.} \tab (integer) a consecutive number \cr + \code{ret} \tab (integer) return value of the used solver \cr + \code{stat} \tab (integer) solution status after optimization \cr + \code{obj value} \tab (numeric) value of the objective function after + optimization \cr + \code{dir} \tab if not given, it is a global value of the + algorithm (here empty), otherwise the current + setting of the direction of optimization \cr + \code{obj c} \tab if not given, it is a globel value of the model + (here empty), otherwise the current setting of the + objective coefficients of the variables given in + column \sQuote{flux no.} \cr + \code{flux no.} \tab fluxes (variables) which are considered in the + current optimization \cr + } + } + \item{\code{logOptimizationTH}}{\code{signature(object = "sybilLog")}: + add a row containing a table header for results of an optimization to the + log file if \code{loglevel} is \code{> 2} and to \code{stdout} if + \code{verblevel} is \code{> 2}. This should be used prior + \code{logOptimization}. + } + \item{\code{logStep<-}}{\code{signature(object = "sybilLog")}: + (\code{value}): + add a status message to the log file if \code{loglevel} is \code{> 1}, + like \dQuote{performing step x}. + \tabular{rr}{ + \code{value} \tab strings giving the status \cr + } + If \code{is.na(value)} evaluates to \code{TRUE}, the current process is + assumed to have finished as expected. If \code{verblevel} is \code{> 1}, + \dQuote{\code{OK}} will be printed on the command line end if + \code{loglevel} is \code{> 1}, \dQuote{\code{# done step x}} will be + printed to the log file. + } + \item{\code{logWarning}}{\code{signature(object = "sybilLog")}: + (\code{...}): + add a warning to the log file if \code{loglevel} is \code{> 0}. + \tabular{rr}{ + \code{...} \tab strings pastes to the log file \cr + } + } + } +} + +\author{Gabriel Gelius-Dietrich} + +\examples{ + showClass("sybilLog") +} + +\keyword{classes} diff --git a/man/sybilStack.Rd b/man/sybilStack.Rd new file mode 100644 index 0000000..cfdc31e --- /dev/null +++ b/man/sybilStack.Rd @@ -0,0 +1,105 @@ +\name{sybilStack} + +\alias{sybilStack} +\alias{stinit} +\alias{stclear} +\alias{stpush} +\alias{stpop} +\alias{stunshift} +\alias{stshift} +\alias{stseek} +\alias{stfirst} +\alias{stlist} +\alias{stlength} +\alias{stexists} + +\title{ + A Data Type Providing Stack (LIFO) And Queue (FIFO) Functionality +} + +\description{ + These functions implement simple stack or queue functionality. +} + +\usage{ + stinit(stname) + stclear(stname) + stpush(stname, value) + stpop(stname) + stunshift(stname, value) + stshift(stname) + stseek(stname) + stfirst(stname) + stlist(stname) + stlength(stname) + stexists(stname) +} + +\arguments{ + \item{stname}{ + A single character string, giving the name of the stack or queue. + } + \item{value}{ + Value to add to the stack or queue. + } +} + +\details{ + The funtion \code{stinit} creates an empty stack named \code{stname}. + + The funtion \code{stclear} removes the stack named \code{stname}. + + The funtion \code{stpush} appends element \code{value} at the end of the + stack named \code{stname}. + + The funtion \code{stpop} removes the last element of the stack named + \code{stname} and returns it invisible. + + The funtion \code{stunshift} appends element \code{value} at the beginning of + the stack \code{stname}. + + The funtion \code{stshift} removes the first element of the stack named + \code{stname} and returns it invisible. + + The funtion \code{stseek} returns the last element of the stack named + \code{stname} but does not remove it. + + The funtion \code{stfirst} returns the first element of the stack named + \code{stname} but does not remove it. + + The funtion \code{stlist} returns the stack named \code{stname} as list. + + The funtion \code{stlength} returns the number of elements stored in the stack + named \code{stname}. + + The funtion \code{stexists} returns \code{TRUE} if a stack named + \code{stname} exists, otherwise \code{FALSE}. +} + +\value{ + The functions \code{stpop} and \code{stshift} return the last/first element + of the stack invisibly. The functions \code{stseek} and \code{stfirst} just + return the last/first element. +} + +\author{ + Gabriel Gelius-Dietrich + + Maintainer: Gabriel Gelius-Dietrich <geliudie@uni-duesseldorf.de> +} + +\examples{ + ## initialize empty stack named test + stinit("test") + + ## add a few elemets + stpush("test", 9) + stpush("test", 3) + stpush("test", 7) + + ## get last element + stpop("test") + + ## remove stack + stclear("test") +} diff --git a/man/sysBiolAlg-class.Rd b/man/sysBiolAlg-class.Rd new file mode 100644 index 0000000..941efbf --- /dev/null +++ b/man/sysBiolAlg-class.Rd @@ -0,0 +1,266 @@ +\name{sysBiolAlg-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{sysBiolAlg-class} +\alias{algorithm,sysBiolAlg-method} +\alias{algorithm<-,sysBiolAlg-method} +\alias{fldind,sysBiolAlg-method} +\alias{fldind<-,sysBiolAlg-method} +\alias{nc,sysBiolAlg-method} +\alias{nc} +\alias{nc<-,sysBiolAlg-method} +\alias{nc<-} +\alias{nr,sysBiolAlg-method} +\alias{nr} +\alias{nr<-,sysBiolAlg-method} +\alias{nr<-} +\alias{alg_par,sysBiolAlg-method} +\alias{alg_par} +\alias{alg_par<-,sysBiolAlg-method} +\alias{alg_par<-} +\alias{problem,sysBiolAlg-method} +\alias{problem} + +\title{Class \code{"sysBiolAlg"}} + +\description{ + The class \code{sysBiolAlg} holds an object of class + \code{\linkS4class{optObj}} which is generated concerning a particular + algorithm, e.g. FBA or ROOM. This class is extended by other classes and will + not be used as is. The representation of class \code{sysBiolAlg} is used as + superclass. +} + +\section{Objects from the Class}{ + A virtual Class: No objects may be created from it. +} + +\section{Slots}{ + \describe{ + \item{\code{problem}:}{Object of class \code{"optObj"} + containing the problem object. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm. + } + \item{\code{nr}:}{Object of class \code{"integer"} + containing the number of rows of the problem object. + } + \item{\code{nc}:}{Object of class \code{"integer"} + containing the number of columns of the problem object + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list of algorithm specific parameters. + } + } +} + +\section{Methods}{ + \describe{ + \item{algorithm}{\code{signature(object = "sysBiolAlg")}: + gets the \code{algorithm} slot. + } + \item{algorithm<-}{\code{signature(object = "sysBiolAlg")}: + sets the \code{algorithm} slot. + } + \item{alg_par}{\code{signature(object = "sysBiolAlg")}: + gets the \code{alg_par} slot. + } + \item{alg_par<-}{\code{signature(object = "sysBiolAlg")}: + sets the \code{alg_par} slot. + } + \item{fldind}{\code{signature(object = "sysBiolAlg")}: + gets the \code{fldind} slot. + } + \item{fldind<-}{\code{signature(object = "sysBiolAlg")}: + sets the \code{fldind} slot. + } + \item{nc}{\code{signature(object = "sysBiolAlg")}: + gets the \code{nc} slot. + } + \item{nc<-}{\code{signature(object = "sysBiolAlg")}: + sets the \code{nc} slot. + } + \item{nr}{\code{signature(object = "sysBiolAlg")}: + gets the \code{nr} slot. + } + \item{nr<-}{\code{signature(object = "sysBiolAlg")}: + sets the \code{nr} slot. + } + \item{optimizeProb}{\code{signature(object = "sysBiolAlg")}: + runs optimization on the given problem object + (see \code{\link{optimizeProb}} for details). + } + \item{problem}{\code{signature(object = "sysBiolAlg")}: + gets the \code{problem} slot. + } + \item{initialize}{\code{signature(object = "sysBiolAlg")}: + default constructor method for objects inheriting from class + \code{sysBiolAlg}. It gets all data structures necessary to built a + problem object (object of class \code{\linkS4class{optObj}}) + representing a particular algorithm. This method can be used in + constructor methods for subclasses of \code{sysBiolAlg} via + \code{\link{callNextMethod}}. In this case, the constructor has to + generate all the data structures, pass them to + \code{\link{callNextMethod}} and let the constructor of the superclass do + all the work in generating the problem object and interacting with the + solver software. See also the Details section. + } + } +} + +\details{ + The \code{initialize} method has the following arguments: + \describe{ + \item{solver}{ + Single character string giving the solver package to use. See + \code{\link{SYBIL_SETTINGS}} for possible values.\cr + Default: \code{SYBIL_SETTINGS("SOLVER")}. + } + \item{method}{ + Single character string giving the method the desired solver has to use. + \code{\link{SYBIL_SETTINGS}} for possible values.\cr + Default: \code{SYBIL_SETTINGS("METHOD")}. + } + \item{solverParm}{ + A named data frame or list containing parameters for the specified + solver. Parameters can be set as data frame or list: + \code{solverParm = list(parm1 = val1, parm2 = val2)} with \code{parm1} and + \code{parm2} being the names of two different parameters and \code{val1} + and \code{val2} the corresponding values. For possible parameters and + values see the documentation of the used solver package + (e.g. \pkg{glpkAPI}).\cr + Default: \code{SYBIL_SETTINGS("SOLVER_CTRL_PARM")}. + } + \item{termOut}{ + A single boolean, numeric or character value, controling the amount of + terminal output of the solver software. See also \code{\link{initProb}} + (argument \code{to}) for more details.\cr + Default: \code{NULL}. + } + \item{sbalg}{ + Single character string containing the name of the algorithm to use. + } + \item{pType}{ + Single character string containing the type of the problem object. Can be + \code{"lp"}: linear program, \code{mip}: mixed integer program or + \code{"qp"}: quadratic program.\cr + Default: \code{"lp"}. + } + \item{scaling}{ + Scaling options used to scale the constraint matrix. If set to + \code{NULL}, no scaling will be performed + (see \code{\link{scaleProb}}).\cr + Default: \code{NULL}. + } + \item{fi}{ + Pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{nCols}{ + Number of columns (variables) of the problem object. + } + \item{nRows}{ + Number of rows (constraints) of the problem object. + } + \item{mat}{ + An object of class \code{\link{Matrix}}. The constraint matrix of the + problem object. The number of columns in \code{mat} must be \code{nCols} + and the number of rows in \code{mat} must be \code{nRows}. + } + \item{ub}{ + A numeric vector of length \code{nCols} giving the upper bounds of the + variables of the problem object. + } + \item{lb}{ + A numeric vector of length \code{nCols} giving the lower bounds of the + variables of the problem object. + } + \item{obj}{ + A numeric vector of length \code{nCols} giving the objective coefficients + of the variables of the problem object. + } + \item{rlb}{ + A numeric vector of length \code{nRows} giving the right hand side of the + problem object. If argument \code{rub} is not \code{NULL}, \code{rlb} + contains the lower bounds of the constraints of the problem object. + } + \item{rtype}{ + A character vector of length \code{nRows} giving the constraint type. + See \code{\link{loadLPprob}} for details. + } + \item{lpdir}{ + Single character string containing the direction of optimization. + Can be set to \code{"min"} or \code{"max"}.\cr + Default: \code{"max"}. + } + \item{rub}{ + A numeric vector of length \code{nRows} giving the right hand side of the + problem object. If not \code{NULL}, it contains the upper bounds of the + constraints of the problem object.\cr + Default: \code{NULL}. + } + \item{ctype}{ + A character vector of length \code{nCols} giving the variable type. If set + to \code{NULL}, no specific variable type is set, which usually means, all + variables are treated as continuous variables. + See \code{\link{loadLPprob}} for details.\cr + Default: \code{NULL}. + } + \item{cnames}{ + A character vector of length \code{nCols} giving the variable names. + If set to \code{NULL}, no specific variable names are set.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector of length \code{nRows} giving the constraint names. + If set to \code{NULL}, no specific constraint names are set.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{retAlgPar}{ + A single boolean flag, if algorithm specific parameters should be saved + in the object extending class \code{sysBiolAlg}.\cr + Default: \code{TRUE}. + } + \item{algPar}{ + A named list containing algorithm specific parameters.\cr + Default: \code{NULL}. + } + } +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + The general constructor function \code{\link{sysBiolAlg}}, + and classes + \code{\linkS4class{sysBiolAlg_fba}}, + \code{\linkS4class{sysBiolAlg_fv}}, + \code{\linkS4class{sysBiolAlg_mtf}}, + \code{\linkS4class{sysBiolAlg_lmoma}}, + \code{\linkS4class{sysBiolAlg_moma}} and + \code{\linkS4class{sysBiolAlg_room}}. +} + +\examples{ + showClass("sysBiolAlg") +} + +\keyword{classes} +\keyword{optimize} diff --git a/man/sysBiolAlg.Rd b/man/sysBiolAlg.Rd new file mode 100644 index 0000000..2392cb9 --- /dev/null +++ b/man/sysBiolAlg.Rd @@ -0,0 +1,86 @@ +\name{sysBiolAlg} +\alias{sysBiolAlg} + +\title{ + General Constructor Function For Objects of Class \code{sysBiolAlg} +} + +\description{ + This function serves as a user constructor function for objects of class + \code{\linkS4class{sysBiolAlg}}. +} + +\usage{ + sysBiolAlg(model, + algorithm = SYBIL_SETTINGS("ALGORITHM"), + prefix = "sysBiolAlg", sep = "_", + ...) +} + +\arguments{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{algorithm}{ + A single character string giving the name of the algorithm to use. See + parameter \code{"ALGORITHM"} in \code{\link{SYBIL_SETTINGS}} for possible + values.\cr + Default: \code{SYBIL_SETTINGS("ALGORITHM")}. + } + \item{prefix}{ + A single character string containing a prefix for the new class name.\cr + Default: \code{"sysBiolAlg"}. + } + \item{sep}{ + A single character string containing a separator for \code{prefix} and + \code{algorithm}.\cr + Default: \code{"_"}. + } + \item{\dots}{ + Further arguments passed to the initialize method depending on the + desired algorithm (see Details below). + } +} + +\details{ + If argument \code{algorithm} is set to \code{"foo"} and \code{prefix} is set + to \code{"sysBiolAlg"} (default), \code{sysBiolAlg} will try to build an + instance of class \code{sysBiolAlg_foo}. If no such class definition exists, + an error will be returned. For the name of the class, the values of arguments + \code{prefix} and \code{algorithm} are stick together separated by the value + of argument \code{sep}: \code{prefix_algorithm}. + + Additional arguments required by the initialize method are for example + \code{solver}, \code{method} and \code{solverParm}. +} + +\value{ + An instance of a subclass of + class \code{\linkS4class{sysBiolAlg}}. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Class \code{\linkS4class{sysBiolAlg}} +} + +\examples{ +\dontrun{ +## 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 = SYBIL_SETTINGS("SOLVER")). + +data(Ec_core) + +## algorithm: fba (flux balance analysis) +fb <- sysBiolAlg(Ec_core, algorithm = "fba") + +## algorithm: lmoma (linearized version of MOMA) +fb <- sysBiolAlg(Ec_core, algorithm = "lmoma") +} +} + +\keyword{classes} diff --git a/man/sysBiolAlg_fba-class.Rd b/man/sysBiolAlg_fba-class.Rd new file mode 100644 index 0000000..ebd1563 --- /dev/null +++ b/man/sysBiolAlg_fba-class.Rd @@ -0,0 +1,162 @@ +\name{sysBiolAlg_fba-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{sysBiolAlg_fba-class} +\alias{sysBiolAlg_fba} +\alias{fba} + +\title{Class \code{"sysBiolAlg_fba"}} + +\description{ + The class \code{sysBiolAlg_fba} holds an object of class + \code{\linkS4class{optObj}} which is generated to meet the + requirements of the FBA algorithm. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + + \code{sysBiolAlg(model, algorithm = "fba", ...)}. + + Arguments to \code{...} which are passed to method \code{initialize} of class + \code{sysBiolAlg_fba} are described in the Details section. +} + +\section{Slots}{ + \describe{ + \item{\code{problem}:}{Object of class \code{"optObj"} + containing the problem object. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm. + } + \item{\code{nr}:}{Object of class \code{"integer"} + containing the number of rows of the problem object. + } + \item{\code{nc}:}{Object of class \code{"integer"} + containing the number of columns of the problem object + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{sysBiolAlg}"}, directly. +} + +\section{Methods}{ + No methods defined with class "sysBiolAlg_fba" in the signature. +} + +\details{ + The \code{initialize} method has the following arguments: + \describe{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{lpdir}{ + Single character string containing the direction of optimization. + Can be set to \code{"min"} or \code{"max"}.\cr + Default: \code{"max"}. + } + \item{useNames}{ + A single boolean value. If set to \code{TRUE}, variables and constraints + will be named according to \code{cnames} and \code{rnames}. If set to + \code{NULL}, no specific variable or constraint names are set.\cr + Default: \code{SYBIL_SETTINGS("USE_NAMES")}. + } + \item{cnames}{ + A character vector giving the variable names. If set to \code{NULL}, + the reaction id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector giving the constraint names. If set to \code{NULL}, + the metabolite id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{scaling}{ + Scaling options used to scale the constraint matrix. If set to + \code{NULL}, no scaling will be performed + (see \code{\link{scaleProb}}).\cr + Default: \code{NULL}. + } + \item{writeProbToFileName}{ + A single character string containing a file name to which the problem + object will be written in LP file format.\cr + Default: \code{NULL}. + } + \item{...}{ + Further arguments passed to the initialize method of + \code{\linkS4class{sysBiolAlg}}. They are \code{solver}, + \code{method} and \code{solverParm}. + } + } + + The problem object is built to be capable to perform flux balance analysis + (FBA) with a given model, which is basically the solution of a linear + programming problem + \deqn{% + \begin{array}{rll}% + \max & \mbox{\boldmath$c$\unboldmath}^{\mathrm{T}} + \mbox{\boldmath$v$\unboldmath} \\[1ex] + \mathrm{s.\,t.} & \mbox{\boldmath$Sv$\unboldmath} = 0 \\[1ex] + & \alpha_i \leq v_i \leq \beta_i + & \quad \forall i \in \{1, \ldots, n\} \\[1ex] + \end{array}% + }{ + max c^T v + s.t. Sv = 0 + a_i <= v_i <= b_i for i = 1, ..., n + } + with \eqn{\bold{S}}{S} being the stoichiometric matrix, \eqn{\alpha_i}{a_i} + and \eqn{\beta_i}{b_i} being the lower and upper bounds for flux (variable) + \eqn{i} respectively. The total number of variables of the optimization + problem is denoted by \eqn{n}. The solution of the optimization is a flux + distribution maximizing the objective function + \eqn{ + \mbox{\boldmath$c$\unboldmath}^{\mathrm{T}} + \mbox{\boldmath$v$\unboldmath} + }{c^T v} under the a given environment and the assumption of steady state. + The optimization can be executed by using \code{\link{optimizeProb}}. +} + +\references{ + Edwards, J. S., Covert, M and Palsson, B. Ø. (2002) Metabolic modelling of + microbes: the flux-balance approach. \emph{Environ Microbiol} \bold{4}, + 133--140. + + Edwards, J. S., Ibarra, R. U. and Palsson, B. Ø. (2001) In silico predictions + of \emph{Escherichia coli} metabolic capabilities are consistent with + experimental data. \emph{Nat Biotechnol} \bold{19}, 125--130. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Constructor function \code{\link{sysBiolAlg}} and + superclass \code{\linkS4class{sysBiolAlg}}. +} + +\examples{ + showClass("sysBiolAlg_fba") +} + +\keyword{classes} diff --git a/man/sysBiolAlg_fv-class.Rd b/man/sysBiolAlg_fv-class.Rd new file mode 100644 index 0000000..a53ac2a --- /dev/null +++ b/man/sysBiolAlg_fv-class.Rd @@ -0,0 +1,190 @@ +\name{sysBiolAlg_fv-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{sysBiolAlg_fv-class} +\alias{sysBiolAlg_fv} +\alias{fv} + +\title{Class \code{"sysBiolAlg_fv"}} + +\description{ + The class \code{sysBiolAlg_fv} holds an object of class + \code{\linkS4class{optObj}} which is generated to meet the + requirements of the flux variance algorithm. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + + \code{sysBiolAlg(model, algorithm = "fv", ...)}. + + Arguments to \code{...} which are passed to method \code{initialize} of class + \code{sysBiolAlg_fv} are described in the Details section. +} + +\section{Slots}{ + \describe{ + \item{\code{problem}:}{Object of class \code{"optObj"} + containing the problem object. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm. + } + \item{\code{nr}:}{Object of class \code{"integer"} + containing the number of rows of the problem object. + } + \item{\code{nc}:}{Object of class \code{"integer"} + containing the number of columns of the problem object + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{sysBiolAlg}"}, directly. +} + +\section{Methods}{ + No methods defined with class "sysBiolAlg_fv" in the signature. +} + +\details{ + The \code{initialize} method has the following arguments: + \describe{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{percentage}{ + Consider solutions with \code{x} percent of the optimal solution.\cr + Default: \code{100}. + } + \item{Zopt}{ + A single numeric value giving the optimal value to be fixed during all + other optimizations (see argument \code{fixObjVal}). If \code{Zopt} is set + to \code{NULL} and \code{model} has an objective function, a default value + is computed based on FBA. If given, arguments \code{solver}, \code{method} + and \code{solverParm} are used during FBA.\cr + Default: \code{NULL}. + } + \item{fixObjVal}{ + A single Boolean value. If set to \code{TRUE} and if the model contains + an objective function, an optimal value of this objective function will be + fixed during all other optimizations. The optimal value can be controlled + by argument \code{Zopt}.\cr + Default: \code{TRUE}. + } + \item{tol}{ + Single numeric value giving the tolerance value.\cr + Default: \code{SYBIL_SETTINGS("TOLERANCE")}. + } + \item{lpdir}{ + Single character string containing the direction of optimization. + Can be set to \code{"min"} or \code{"max"}.\cr + Default: \code{SYBIL_SETTINGS("OPT_DIRECTION")}. + } + \item{useNames}{ + A single boolean value. If set to \code{TRUE}, variables and constraints + will be named according to \code{cnames} and \code{rnames}. If set to + \code{NULL}, no specific variable or constraint names are set.\cr + Default: \code{SYBIL_SETTINGS("USE_NAMES")}. + } + \item{cnames}{ + A character vector giving the variable names. If set to \code{NULL}, + the reaction id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector giving the constraint names. If set to \code{NULL}, + the metabolite id's of \code{model} are used. If an objective value has + to be fixed (see argument \code{fixObjVal}), the corresponding constrained + is named \code{"Z"}.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{scaling}{ + Scaling options used to scale the constraint matrix. If set to + \code{NULL}, no scaling will be performed + (see \code{\link{scaleProb}}).\cr + Default: \code{NULL}. + } + \item{writeProbToFileName}{ + A single character string containing a file name to which the problem + object will be written in LP file format.\cr + Default: \code{NULL}. + } + \item{...}{ + Further arguments passed to the initialize method of + \code{\linkS4class{sysBiolAlg}}. They are \code{solver}, + \code{method} and \code{solverParm}. + } + } + + The problem object is built to be capable to perform the flux variance + algorithm with a given model, which is basically the solution of a linear + program + \deqn{% + \begin{array}{rll}% + \max \textrm{ or } \min & v_i \\[1ex] + \mathrm{s.\,t.} & Z = Z_{\mathrm{opt}} \\[1ex] + & \mbox{\boldmath$Sv$\unboldmath} = 0 \\[1ex] + & \alpha_i \leq v_i \leq \beta_i + & \quad \forall i \in \{1, \ldots, n\} \\[1ex] + \end{array}% + }{ + max or min v[i] + s.t. Z = Z[opt] + Sv = 0 + a_i <= v_i <= b_i for i = 1, ..., n + } + with \eqn{\bold{S}}{S} being the stoichiometric matrix, \eqn{\alpha_i}{a_i} + and \eqn{\beta_i}{b_i} being the lower and upper bounds for flux (variable) + \eqn{i}. The total number of variables of the optimization problem is denoted + by \eqn{n}. + The optimization can be executed by using \code{\link{optimizeProb}}. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. + + Bernhard Ø. Palsson (2006). + \emph{Systems Biology: Properties of Reconstructed Networks}. + Cambridge University Press. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Constructor function \code{\link{sysBiolAlg}} and + superclass \code{\linkS4class{sysBiolAlg}}. +} + +\examples{ + showClass("sysBiolAlg_fv") +} + +\keyword{classes} diff --git a/man/sysBiolAlg_lmoma-class.Rd b/man/sysBiolAlg_lmoma-class.Rd new file mode 100644 index 0000000..7762e20 --- /dev/null +++ b/man/sysBiolAlg_lmoma-class.Rd @@ -0,0 +1,258 @@ +\name{sysBiolAlg_lmoma-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{sysBiolAlg_lmoma-class} +\alias{sysBiolAlg_lmoma} +\alias{lmoma} + +\title{Class \code{"sysBiolAlg_lmoma"}} + +\description{ + The class \code{sysBiolAlg_lmoma} holds an object of class + \code{\linkS4class{optObj}} which is generated to meet the + requirements of a lineraized versoin of the MOMA algorithm. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + + \code{sysBiolAlg(model, algorithm = "lmoma", ...)}. + + Arguments to \code{...} which are passed to method \code{initialize} of class + \code{sysBiolAlg_lmoma} are described in the Details section. +} + +\section{Slots}{ + \describe{ + \item{\code{problem}:}{Object of class \code{"optObj"} + containing the problem object. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm. + } + \item{\code{nr}:}{Object of class \code{"integer"} + containing the number of rows of the problem object. + } + \item{\code{nc}:}{Object of class \code{"integer"} + containing the number of columns of the problem object + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{sysBiolAlg}"}, directly. +} + +\section{Methods}{ + No methods defined with class "sysBiolAlg_lmoma" in the signature. +} + +\details{ + The \code{initialize} method has the following arguments: + \describe{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{wtflux}{ + A numeric vector holding an optimal wild type flux distribution for the + given model. If missing, a default value is computed based on FBA. + If given, arguments \code{solver} and \code{method} are used, but + \code{solverParm} is not. + } + \item{COBRAflag}{ + Boolean, prepare problem object in order to perform minimization of + metabolic adjustment as in COBRA Toolbox.\cr + Default: \code{FALSE}. + } + \item{wtobj}{ + Only used if argument \code{COBRAflag} is set to \code{TRUE}: + A single numeric value giving the optimized value of the objective + function of the wild type problem. If missing, a default + value is computed based on FBA. If given, arguments \code{solver} and + \code{method} are used, but \code{solverParm} is not. + } + \item{wtobjLB}{ + Only used if argument \code{COBRAflag} is set to \code{TRUE}: + Boolean. If set to \code{TRUE}, the value of argument \code{wtobj} is + treated as lower bound. If set to \code{FALSE}, \code{wtobj} serves as + an upper bound.\cr + Default: \code{TRUE}. + } + \item{obj_coefD}{ + A numeric vector of length two times the number of reactions in the model + containing the non-zero part of the objective function. If set to + \code{NULL}, the vector is filled with ones.\cr + Default: \code{NULL}. + } + \item{absMAX}{ + A single numerical value used as a maximum value for upper variable + and contraint bounds.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM")}. + } + \item{useNames}{ + A single boolean value. If set to \code{TRUE}, variables and constraints + will be named according to \code{cnames} and \code{rnames}. If set to + \code{NULL}, no specific variable or constraint names are set.\cr + Default: \code{SYBIL_SETTINGS("USE_NAMES")}. + } + \item{cnames}{ + A character vector giving the variable names. If set to \code{NULL}, + the reaction id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector giving the constraint names. If set to \code{NULL}, + the metabolite id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{scaling}{ + Scaling options used to scale the constraint matrix. If set to + \code{NULL}, no scaling will be performed + (see \code{\link{scaleProb}}).\cr + Default: \code{NULL}. + } + \item{writeProbToFileName}{ + A single character string containing a file name to which the problem + object will be written in LP file format.\cr + Default: \code{NULL}. + } + \item{...}{ + Further arguments passed to the initialize method of + \code{\linkS4class{sysBiolAlg}}. They are \code{solver}, + \code{method} and \code{solverParm}. + } + } + + The problem object is built to be capable to perform a linearized version of + the MOMA algorithm with a given model, which is basically the solution of a + linear programming problem + \deqn{% + \begin{array}{rll}% + \min & \begin{minipage}[b]{5em} + \[ + \sum_{i,j=1}^n + \bigl|v_{j,\mathrm{del}} - v_{i,\mathrm{wt}}\bigr| + \] + \end{minipage} \\[2em] + \mathrm{s.\,t.} & \mbox{\boldmath$Sv$\unboldmath}_{\mathrm{del}} = 0 + \\[1ex] + & v_i = v_{i,\mathrm{wt}} + & \quad \forall i \in \{1, \ldots, n\} \\[1ex] + & \alpha_j \leq v_{j,\mathrm{del}} \leq \beta_j + & \quad \forall j \in \{1, \ldots, n\} \\[1ex] + \end{array}% + }{ + min sum |v_j,del - v_i,wt| for i,j = 1, ..., n + s.t. Sv_del = 0 + v_i = vi_i,wt for i = 1, ..., n + a_j <= v_j,del <= b_j for j = 1, ..., n + } + Here, + \eqn{ + \mbox{\boldmath$v$\unboldmath}_{\mathrm{wt}} + }{v_wt} + is the optimal wild type flux distribution. This can be set via the argument + \code{wtflux}. If \code{wtflux} is \code{NULL} (the default), the + wild type flux distribution will be calculated by a standard FBA. + + If argument \code{COBRAflag} is set to \code{TRUE}, the linear programm is + formulated differently. Wild type and knock-out strain will be computed + simultaneously. + \deqn{% + \begin{array}{rll}% + \min & \begin{minipage}[b]{5em} + \[ + \sum_{i,j=1}^n + \bigl|v_{j,\mathrm{del}} - v_{i,\mathrm{wt}}\bigr| + \] + \end{minipage} \\[2em] + \mathrm{s.\,t.} & \mbox{\boldmath$Sv$\unboldmath}_{\mathrm{wt}} = 0 + \\[1ex] + & \alpha_i \leq v_{i,\mathrm{wt}} \leq \beta_i + & \quad \forall i \in \{1, \ldots, n\} \\[1ex] + + & \mbox{\boldmath$Sv$\unboldmath}_{\mathrm{del}} = 0 + \\[1ex] + & \alpha_j \leq v_{j,\mathrm{del}} \leq \beta_j + & \quad \forall j \in \{1, \ldots, n\} \\[1ex] + & \mbox{$\mu$}_{\mathrm{wt}} = + \mbox{\boldmath$c$\unboldmath}^{\mathrm{T}} + \mbox{\boldmath$v$\unboldmath}_{\mathrm{wt}} \\[1ex] + \end{array}% + }{ + min sum |v_j,del - v_i,wt| for i,j = 1, ..., n + s.t. Sv_wt = 0 + v_i = vi_i,wt for i = 1, ..., n + Sv_del = 0 + a_j <= v_j,del <= b_j for j = 1, ..., n + mu_wt = c^T v_wt + } + with \eqn{\bold{S}}{S} being the stoichiometric matrix, \eqn{\alpha_i}{a_i} + and \eqn{\beta_i}{b_i} being the lower and upper bounds for flux (variable) + \eqn{i} (\eqn{j} for the deletion strain). + The total number of variables of the optimization problem is denoted + by \eqn{n}. + Here, + \eqn{ + \mu_{\mathrm{wt}} + }{mu_wt} + is the optimal wild type growth rate. This can be set via the argument + \code{wtobj}. If \code{wtobj} is \code{NULL} (the default), the + wild type growth rate will be calculated by a standard FBA. + The optimization can be executed by using \code{\link{optimizeProb}}. +} + +\references{ + Becker, S. A., Feist, A. M., Mo, M. L., Hannum, G., Palsson, B. Ø. and + Herrgard, M. J. (2007) Quantitative prediction of cellular metabolism with + constraint-based models: the COBRA Toolbox. \emph{Nat Protoc} \bold{2}, + 727--738. + + Edwards, J. S., Covert, M and Palsson, B. Ø. (2002) Metabolic modelling of + microbes: the flux-balance approach. \emph{Environ Microbiol} \bold{4}, + 133--140. + + Edwards, J. S., Ibarra, R. U. and Palsson, B. Ø. (2001) In silico predictions + of \emph{Escherichia coli} metabolic capabilities are consistent with + experimental data. \emph{Nat Biotechnol} \bold{19}, 125--130. + + Schellenberger, J., Que, R., Fleming, R. M. T., Thiele, I., Orth, J. D., + Feist, A. M., Zielinski, D. C., Bordbar, A., Lewis, N. E., Rahmanian, S., + Kang, J., Hyduke, D. R. and Palsson, B. Ø. (2011) Quantitative prediction of + cellular metabolism with constraint-based models: the COBRA Toolbox v2.0. + \emph{Nat Protoc} \bold{6}, 1290--1307. + + Segrè, D., Vitkup, D. and Church, G. M. (2002) Analysis or optimality in + natural and pertubed metabolic networks. \emph{PNAS} \bold{99}, 15112--15117. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Constructor function \code{\link{sysBiolAlg}} and + superclass \code{\linkS4class{sysBiolAlg}}. +} + +\examples{ + showClass("sysBiolAlg_lmoma") +} + +\keyword{classes} diff --git a/man/sysBiolAlg_moma-class.Rd b/man/sysBiolAlg_moma-class.Rd new file mode 100644 index 0000000..b05f164 --- /dev/null +++ b/man/sysBiolAlg_moma-class.Rd @@ -0,0 +1,183 @@ +\name{sysBiolAlg_moma-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{sysBiolAlg_moma-class} +\alias{sysBiolAlg_moma} +\alias{moma} + +\title{Class \code{"sysBiolAlg_moma"}} + +\description{ + The class \code{sysBiolAlg_moma} holds an object of class + \code{\linkS4class{optObj}} which is generated to meet the + requirements of the MOMA algorithm. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + + \code{sysBiolAlg(model, algorithm = "moma", ...)}. + + Arguments to \code{...} which are passed to method \code{initialize} of class + \code{sysBiolAlg_moma} are described in the Details section. +} + +\section{Slots}{ + \describe{ + \item{\code{problem}:}{Object of class \code{"optObj"} + containing the problem object. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm. + } + \item{\code{nr}:}{Object of class \code{"integer"} + containing the number of rows of the problem object. + } + \item{\code{nc}:}{Object of class \code{"integer"} + containing the number of columns of the problem object + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{sysBiolAlg}"}, directly. +} + +\section{Methods}{ + No methods defined with class "sysBiolAlg_moma" in the signature. +} + +\details{ + The \code{initialize} method has the following arguments: + \describe{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{wtflux}{ + A numeric vector holding an optimal wild type flux distribution for the + given model. If set to \code{NULL}, a default value is computed based on + flux-balance analysis. If given, arguments \code{solver} and \code{method} + are used, but \code{solverParm} is not. + Default: \code{NULL}. + } + \item{Qmat}{ + A numeric vector or matrix (of class \code{\linkS4class{Matrix}}) holding + the quadratic part of the objective function. If set to \code{NULL}, a + quadratic unity matrix with number of columns and rows equal to the number + of reactions given in the model is used. + Default: \code{NULL}. + } + \item{scaleDist}{ + A numeric vector containing scaling factors for each reaction in the + objective function. If \code{scaleDist[j]} is set to \code{0}, reaction + \code{j} will be ignored. The quadratic and the linear part of the + objective function are multiplied by this factor. If set to \code{NULL}, + the reactions are not scaled. + Default: \code{NULL}. + } + \item{useNames}{ + A single boolean value. If set to \code{TRUE}, variables and constraints + will be named according to \code{cnames} and \code{rnames}. If set to + \code{NULL}, no specific variable or constraint names are set.\cr + Default: \code{SYBIL_SETTINGS("USE_NAMES")}. + } + \item{cnames}{ + A character vector giving the variable names. If set to \code{NULL}, + the reaction id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector giving the constraint names. If set to \code{NULL}, + the metabolite id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{scaling}{ + Scaling options used to scale the constraint matrix. If set to + \code{NULL}, no scaling will be performed + (see \code{\link{scaleProb}}).\cr + Default: \code{NULL}. + } + \item{writeProbToFileName}{ + A single character string containing a file name to which the problem + object will be written in LP file format.\cr + Default: \code{NULL}. + } + \item{...}{ + Further arguments passed to the initialize method of + \code{\linkS4class{sysBiolAlg}}. They are \code{solver}, + \code{method} and \code{solverParm}. + } + } + + The problem object is built to be capable to perform the MOMA algorithm with + a given model, which is basically the solution of a quadratic programming + problem + \deqn{% + \begin{array}{rll}% + \min & \begin{minipage}[b]{5em} + \[ + \sum_{j=1}^n + %\bigl(v_{j,\mathrm{del}} - v_{j,\mathrm{wt}}\bigr)^2 + \left(\left(v_{j,\mathrm{del}} - v_{j,\mathrm{wt}}\right) \cdot sd_j \right)^2 + \] + \end{minipage} \\[2em] + \mathrm{s.\,t.} & \mbox{\boldmath$Sv$\unboldmath} = 0 \\[1ex] + & \alpha_j \leq v_j \leq \beta_j + & \quad \forall j \in \{1, \ldots, n\} \\[1ex] + \end{array}% + }{ + min sum ( (v_j,del - v_j,wt) * sd[j] )^2 for j = 1, ..., n + s.t. Sv = 0 + a_j <= v_j <= b_j for j = 1, ..., n + } + with \eqn{\bold{S}}{S} being the stoichiometric matrix, \eqn{\alpha_j}{a_j} + and \eqn{\beta_j}{b_j} being the lower and upper bounds for flux (variable) + \eqn{j} and \eqn{sd_j}{sd[j]} being the scaling factor for reaction \eqn{j} + (default: \eqn{sd_j = 1,\ \forall j}{sd[j] = 1, for j = 1, ..., n}). + The total number of variables of the optimization problem is denoted by + \eqn{n}. Here, + \eqn{ + \mbox{\boldmath$v$\unboldmath}_{\mathrm{wt}} + }{v_wt} + is the optimal wild type flux distribution. This can be set via the argument + \code{wtflux}. If \code{wtflux} is \code{NULL} (the default), the + wild type flux distribution will be calculated by a standard FBA. + The optimization can be executed by using \code{\link{optimizeProb}}. +} + + +\references{ + Segrè, D., Vitkup, D. and Church, G. M. (2002) Analysis or optimality in + natural and pertubed metabolic networks. \emph{PNAS} \bold{99}, 15112--15117. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Constructor function \code{\link{sysBiolAlg}} and + superclass \code{\linkS4class{sysBiolAlg}}. +} + +\examples{ + showClass("sysBiolAlg_moma") +} + +\keyword{classes} diff --git a/man/sysBiolAlg_mtf-class.Rd b/man/sysBiolAlg_mtf-class.Rd new file mode 100644 index 0000000..285d646 --- /dev/null +++ b/man/sysBiolAlg_mtf-class.Rd @@ -0,0 +1,217 @@ +\name{sysBiolAlg_mtf-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{changeMaxObj,sysBiolAlg_mtf-method} +\alias{changeMaxObj} + +\alias{sysBiolAlg_mtf-class} +\alias{sysBiolAlg_mtf} +\alias{mtf} + +\title{Class \code{"sysBiolAlg_mtf"}} + +\description{ + The class \code{sysBiolAlg_mtf} holds an object of class + \code{\linkS4class{optObj}} which is generated to meet the + requirements of the minimize total flux algorithm: minimize the absolute sum + of all fluxes given a previously calculated objective value. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + + \code{sysBiolAlg(model, algorithm = "mtf", ...)}. + + Arguments to \code{...} which are passed to method \code{initialize} of class + \code{sysBiolAlg_mtf} are described in the Details section. +} + +\section{Slots}{ + \describe{ + \item{\code{maxobj}:}{Object of class \code{"numeric"} + containing optimized objective values. + } + \item{\code{problem}:}{Object of class \code{"optObj"} + containing the problem object. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm. + } + \item{\code{nr}:}{Object of class \code{"integer"} + containing the number of rows of the problem object. + } + \item{\code{nc}:}{Object of class \code{"integer"} + containing the number of columns of the problem object + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{sysBiolAlg}"}, directly. +} + +\section{Methods}{ + \describe{ + \item{changeMaxObj}{\code{signature(object = "sysBiolAlg_mtf")}: + change current objective value to the \eqn{j}th value given in slot + \code{maxobj}. Argument \code{j} must be in \code{[1:length(maxobj)]}. + } + } +} + +\details{ + The \code{initialize} method has the following arguments: + \describe{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{wtobj}{ + A single numeric value giving the optimal value. If missing, a default + value is computed based on FBA. If given, arguments \code{solver} and + \code{method} are used, but \code{solverParm} is not.\cr + Default: \code{NULL}. + } + \item{react}{ + Arguments \code{react}, \code{lb} and \code{ub} are used, if argument + \code{wtobj} is \code{NULL}, meaning: no previous objective value is + given. Objective values will be calculated via \code{\link{fba}} using + the parameters given in \code{react}, \code{lb} and \code{ub}.\cr + Default: \code{NULL}. + } + \item{lb}{ + See argument \code{react}.\cr + Default: \code{NULL}. + } + \item{ub}{ + See argument \code{react}.\cr + Default: \code{NULL}. + } + \item{costcoeffw}{ + A numeric vector containing cost coefficients for all variables (forward + direction). If set to \code{NULL}, all cost coefficients are set to + \code{1}, so that all variables have the same impact on the objective + function.\cr + Default: \code{NULL}. + } + \item{costcoefbw}{ + A numeric vector containing cost coefficients for all variables (backward + direction). If set to \code{NULL}, all cost coefficients are set to the + values given in \code{costcoeffw}.\cr + Default: \code{NULL}. + } + \item{absMAX}{ + A single numerical value used as a maximum value for upper variable + and contraint bounds.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM")}. + } + \item{useNames}{ + A single boolean value. If set to \code{TRUE}, variables and constraints + will be named according to \code{cnames} and \code{rnames}. If set to + \code{NULL}, no specific variable or constraint names are set.\cr + Default: \code{SYBIL_SETTINGS("USE_NAMES")}. + } + \item{cnames}{ + A character vector giving the variable names. If set to \code{NULL}, + the reaction id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector giving the constraint names. If set to \code{NULL}, + the metabolite id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{scaling}{ + Scaling options used to scale the constraint matrix. If set to + \code{NULL}, no scaling will be performed + (see \code{\link{scaleProb}}).\cr + Default: \code{NULL}. + } + \item{writeProbToFileName}{ + A single character string containing a file name to which the problem + object will be written in LP file format.\cr + Default: \code{NULL}. + } + \item{...}{ + Further arguments passed to the initialize method of + \code{\linkS4class{sysBiolAlg}}. They are \code{solver}, + \code{method} and \code{solverParm}. + } + } + + The problem object is built to be capable to perform minimize total flux + with a given model, which is basically the solution of a linear programming + problem + \deqn{% + \begin{array}{rll}% + \min & \begin{minipage}[b]{2.5em} + \[ + \sum_{i=1}^n cost_i |v_i| + \] + \end{minipage} \\[2em] + \mathrm{s.\,t.} & \mbox{\boldmath$Sv$\unboldmath} = 0 \\[1ex] + & \alpha_i \leq v_i \leq \beta_i + & \quad \forall i \in \{1, \ldots, n\} \\[1ex] + & \mbox{\boldmath$c$\unboldmath}_{\mathrm{wt}} \geq + \mbox{\boldmath$c$\unboldmath}^{\mathrm{T}} + \mbox{\boldmath$v$\unboldmath}_{\mathrm{wt}} \\[1ex] + \end{array}% + }{ + min sum cost_i abs(v_i) for i = 1, ..., n + s.t. Sv = 0 + a_i <= v_i <= b_i for i = 1, ..., n + c_wt >= c^T v_wt + } + with + \eqn{ + \mbox{\boldmath$c$\unboldmath}^{\mathrm{T}} + \mbox{\boldmath$v$\unboldmath}_{\mathrm{wt}} + }{c^T v_wt} + being the previously computed optimized value of the objective function + (argument \code{wtobj}). + The variable \eqn{\bold{S}}{S} denotes the stoichiometric matrix, + \eqn{\alpha_i}{a_i} and \eqn{\beta_i}{b_i} being the lower and upper bounds + for flux (variable) \eqn{i}. The total number of variables of the + optimization problem is denoted by \eqn{n}. + The optimization can be executed by using \code{\link{optimizeProb}}. +} + +\references{ + Edwards, J. S., Covert, M and Palsson, B. Ø. (2002) Metabolic modelling of + microbes: the flux-balance approach. \emph{Environ Microbiol} \bold{4}, + 133--140. + + Edwards, J. S., Ibarra, R. U. and Palsson, B. Ø. (2001) In silico predictions + of \emph{Escherichia coli} metabolic capabilities are consistent with + experimental data. \emph{Nat Biotechnol} \bold{19}, 125--130. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Constructor function \code{\link{sysBiolAlg}} and + superclass \code{\linkS4class{sysBiolAlg}}. +} + +\examples{ + showClass("sysBiolAlg_mtf") +} + +\keyword{classes} diff --git a/man/sysBiolAlg_room-class.Rd b/man/sysBiolAlg_room-class.Rd new file mode 100644 index 0000000..fd13375 --- /dev/null +++ b/man/sysBiolAlg_room-class.Rd @@ -0,0 +1,221 @@ +\name{sysBiolAlg_room-class} + +\Rdversion{1.1} +\encoding{utf8} + +\docType{class} + +\alias{sysBiolAlg_room-class} +\alias{sysBiolAlg_room} +\alias{room} + +\title{Class \code{"sysBiolAlg_room"}} + +\description{ + The class \code{sysBiolAlg_room} holds an object of class + \code{\linkS4class{optObj}} which is generated to meet the + requirements of the ROOM algorithm. +} + +\section{Objects from the Class}{ + Objects can be created by calls of the form + + \code{sysBiolAlg(model, algorithm = "room", ...)}. + + Arguments to \code{...} which are passed to method \code{initialize} of class + \code{sysBiolAlg_room} are described in the Details section. +} + +\section{Slots}{ + \describe{ + \item{\code{wu}:}{Object of class \code{"numeric"} + containing the upper threshold for a significant flux change, + see Details below. + } + \item{\code{wl}:}{Object of class \code{"numeric"} + containing the lower threshold for a significant flux change, + see Details below. + } + \item{\code{fnc}:}{Object of class \code{"integer"} + containing the number of reactions in the entire metabolic network + (argument \code{model} to the constructor function + \code{\link{sysBiolAlg}}). + } + \item{\code{fnr}:}{Object of class \code{"integer"} + containing the number of metabolites in the entire metabolic network + (argument \code{model} to the constructor function + \code{\link{sysBiolAlg}}). + } + \item{\code{problem}:}{Object of class \code{"optObj"} + containing the problem object. + } + \item{\code{algorithm}:}{Object of class \code{"character"} + containing the name of the algorithm. + } + \item{\code{nr}:}{Object of class \code{"integer"} + containing the number of rows of the problem object. + } + \item{\code{nc}:}{Object of class \code{"integer"} + containing the number of columns of the problem object + } + \item{\code{fldind}:}{Object of class \code{"integer"} + pointers to columns (variables) representing a flux (reaction) in the + original network. The variable \code{fldind[i]} in the problem object + represents reaction \code{i} in the original network. + } + \item{\code{alg_par}:}{Object of class \code{"list"} + containing a named list containing algorithm specific parameters. + } + } +} + +\section{Extends}{ + Class \code{"\linkS4class{sysBiolAlg}"}, directly. +} + +\section{Methods}{ + \describe{ + \item{optimizeProb}{\code{signature(object = "sysBiolAlg_room")}: + runs optimization on the given problem object + (see \code{\link{optimizeProb}} for details). + } + } +} + +\details{ + The \code{initialize} method has the following arguments: + \describe{ + \item{model}{ + An object of class \code{\linkS4class{modelorg}}. + } + \item{wtflux}{ + A numeric vector holding an optimal wild type flux distribution for the + given model. If missing, a default value is computed based on FBA. + If given, arguments \code{solver} and \code{method} are used to calculate + the dafault, but \code{solverParm} is not. + } + \item{delta}{ + A single numeric value giving the relative range of tolerance, see + Details below.\cr + Default: \code{0.03}. + } + \item{epsilon}{ + A single numeric value giving the absolute range of tolerance, see + Details below.\cr + Default: \code{0.001}. + } + \item{LPvariant}{ + Boolean. If \code{TRUE}, the problem object is formulated as linear + program. See Details below.\cr + Default: \code{FALSE}. + } + \item{LPvariant}{ + Boolean. If \code{TRUE}, the problem object is formulated as linear + program. See Details below.\cr + Default: \code{FALSE}. + } + \item{absMAX}{ + A single numerical value used as a maximum value for upper variable + and contraint bounds.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM")}. + } + \item{cnames}{ + A character vector giving the variable names. If set to \code{NULL}, + the reaction id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{rnames}{ + A character vector giving the constraint names. If set to \code{NULL}, + the metabolite id's of \code{model} are used.\cr + Default: \code{NULL}. + } + \item{pname}{ + A single character string containing a name for the problem object.\cr + Default: \code{NULL}. + } + \item{scaling}{ + Scaling options used to scale the constraint matrix. If set to + \code{NULL}, no scaling will be performed + (see \code{\link{scaleProb}}).\cr + Default: \code{NULL}. + } + \item{writeProbToFileName}{ + A single character string containing a file name to which the problem + object will be written in LP file format.\cr + Default: \code{NULL}. + } + \item{...}{ + Further arguments passed to the initialize method of + \code{\linkS4class{sysBiolAlg}}. They are \code{solver}, + \code{method} and \code{solverParm}. + } + } + + The problem object is built to be capable to perform the ROOM algorithm with + a given model, which is basically the solution of a mixed integer programming + problem + \deqn{% + \begin{array}{rll}% + \min & \begin{minipage}[b]{5em} + \[ + \sum_{i=1}^n y_i + \] + \end{minipage} \\[2em] + \mathrm{s.\,t.} & \mbox{\boldmath$Sv$\unboldmath} = 0 \\[1ex] + & \alpha_i \leq v_i \leq \beta_i + & \quad \forall i \in \{1, \ldots, n\} \\[1ex] + & v_i - y(\beta_i - w_i^u) \leq w_i^u \\[1ex] + & v_i - y(\alpha_i - w_i^l) \geq w_i^l \\[1ex] + & y_i \in \{0, 1\} \\[1ex] + & w_i^u = w_i + \delta |w_i| + \epsilon \\[1ex] + & w_i^l = w_i - \delta |w_i| - \epsilon \\[1ex] + \end{array}% + }{ + max sum (v_j,del - v_i,wt)^2 for i,j = 1, ..., n + s.t. Sv = 0 + a_i <= v_i <= b_i for i = 1, ..., n + } + with \eqn{\bold{S}}{S} being the stoichiometric matrix, \eqn{\alpha_i}{a_i} + and \eqn{\beta_i}{b_i} being the lower and upper bounds for flux (variable) + \eqn{i}. + The total number of fluxes of the optimization problem is denoted by \eqn{n}. + Here, \eqn{w} is the optimal wild type flux distribution. This can be set via + the argument \code{wtflux}. If \code{wtflux} is \code{NULL} (the default), the + wild type flux distribution will be calculated by a standard FBA. + All variables \eqn{y_i} are binary, with \eqn{y_i = 1} for a significant flux + change in \eqn{v_i} and \eqn{y_i = 0} otherwise. Thresholds determining the + significance of a flux change are given in \eqn{w^u} and \eqn{w^l}, with + \eqn{\delta}{delta} and \eqn{\epsilon}{epsilon} specifying absolute and + relative ranges in tolerance [Shlomi et al. 2005]. + + The Boolean argument \code{LPvariant} relax the binary contraints to + \eqn{0 \leq y_i \leq 1}{0 <= y_i <= 1} so that the problem becomes a linear + program. + The optimization can be executed by using \code{\link{optimizeProb}}. +} + +\note{ + If using \pkg{glpkAPI} as MIP solver, consider to set parameter + \code{PRESOLVE} to \code{GLP_ON}. +} + +\references{ + Shlomi, T., Berkman, O. and Ruppin, E. (2005) Regulatory on/off minimization + of metabolic flux changes after genetic pertubations. \emph{PNAS} \bold{102}, + 7695--7700. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Constructor function \code{\link{sysBiolAlg}} and + superclass \code{\linkS4class{sysBiolAlg}}. +} + +\examples{ + showClass("sysBiolAlg_room") +} + +\keyword{classes} diff --git a/man/writeProb-methods.Rd b/man/writeProb-methods.Rd new file mode 100644 index 0000000..15fb6da --- /dev/null +++ b/man/writeProb-methods.Rd @@ -0,0 +1,81 @@ +\name{writeProb-methods} + +\docType{methods} +\encoding{utf8} + +\alias{writeProb} +\alias{writeProb-methods} + +\alias{writeProb,optObj_clpAPI,character-method} +\alias{writeProb,optObj_cplexAPI,character-method} +\alias{writeProb,optObj_glpkAPI,character-method} +\alias{writeProb,optObj_lpSolveAPI,character-method} + +\title{Write Problem Object to File} + +\description{ + Write problem object to file (e.g. in lp format). +} + +\usage{ +\S4method{writeProb}{optObj_clpAPI,character}(lp, fname, ff = "lp") + +\S4method{writeProb}{optObj_cplexAPI,character}(lp, fname, ff = "lp") + +\S4method{writeProb}{optObj_glpkAPI,character}(lp, fname, ff = "lp", ...) + +\S4method{writeProb}{optObj_lpSolveAPI,character}(lp, fname, ff = "lp", ...) +} + +\section{Methods}{ + \describe{ + \item{\code{signature(lp = "optObj_clpAPI", fname = "character")}}{ + method to use with package \pkg{optObj_clpAPI}. Argument \code{ff} is + not used here. + } + \item{\code{signature(lp = "optObj_cplexAPI", fname = "character")}}{ + method to use with package \pkg{optObj_cplexAPI}. + } + \item{\code{signature(lp = "optObj_glpkAPI", fname = "character")}}{ + method to use with package \pkg{optObj_glpkAPI}. + } + \item{\code{signature(lp = "optObj_lpSolveAPI", fname = "character")}}{ + method to use with package \pkg{optObj_lpSolveAPI}. + } + } +} + +\arguments{ + \item{lp}{ + An object extending class \code{\linkS4class{optObj}}. + } + \item{fname}{ + A single character string giving the file name to write to. + } + \item{ff}{ + A single character string giving the file format to use, see Details.\cr + Default: \code{"lp"}. + } + \item{...}{ + Further arguments passed to the corresponding API routine. + } +} + +\details{ + Argument \code{"ff"} is unused with \pkg{clpAPI}. Valid values for + \pkg{cplexAPI} and \code{lpSolveAPI} are available in their documentations. + For \pkg{glpkAPI}, argument \code{"ff"} can be \code{"lp"} for LP file format, + \code{"mps"} for MPS file format or \code{"glpk"} for GLPK file format. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + Superclass \code{\linkS4class{optObj}} and constructor function + \code{\link{optObj}}. +} + +\keyword{methods} +\keyword{optimize} diff --git a/man/ypd.Rd b/man/ypd.Rd new file mode 100644 index 0000000..5f2ed42 --- /dev/null +++ b/man/ypd.Rd @@ -0,0 +1,137 @@ +\name{ypd} +\alias{ypd} + +\encoding{utf8} + +\title{ + In Sillico YPD Medium +} +\description{ + Apply in sillico medium to bakers yeast metabolic network model iND750 by + Duarte et al. 2004. +} +\usage{ + ypd(model, def_bnd = SYBIL_SETTINGS("MAXIMUM"), ver = "harrison2007") +} + +\arguments{ + \item{model}{ + An object of class \code{\link{modelorg}}. + } + \item{def_bnd}{ + A single numeric value. Absolute value for uppper and lower bounds for + reaction bounds.\cr + Default: \code{SYBIL_SETTINGS("MAXIMUM")}. + } + \item{ver}{ + A single character string giving the version of the YPD medium. Can be set + to \code{harrison2007} or \code{bilu2006} (see Details below).\cr + Default: \code{harrison2007}. + } +} + +\details{ + The function \code{ypd} identifies exchange reactions via the function + \code{\link{findExchReact}}. The lower bounds of all exchange fluxes is set + to zero (not allowing any flux into the network) and the upper bounds are set + to the value of \code{def_bnd} (default: output is unbounded). The lower bound + input of the input fluxes is set like in the table below. + + Two different versions of YPD medium are available: Harrison et al. 2007 and + Bilu et al. 2006. + + Harrison et al 2007: + \tabular{ll}{ + \code{EX_ala_L(e)} \tab \eqn{-0.5} \cr + \code{EX_arg_L(e)} \tab \eqn{-0.5} \cr + \code{EX_asn_L(e)} \tab \eqn{-0.5} \cr + \code{EX_asp_L(e)} \tab \eqn{-0.5} \cr + \code{EX_chol(e)} \tab \eqn{-0.5} \cr + \code{EX_cys_L(e)} \tab \eqn{-0.5} \cr + \code{EX_dcyt(e)} \tab \eqn{-0.5} \cr + \code{EX_ergst(e)} \tab \eqn{-0.5} \cr + \code{EX_glc(e)} \tab \eqn{-20} \cr + \code{EX_glu_L(e)} \tab \eqn{-0.5} \cr + \code{EX_gly(e)} \tab \eqn{-0.5} \cr + \code{EX_gua(e)} \tab \eqn{-0.5} \cr + \code{EX_h(e)} \tab \code{def_bnd * -1} \cr + \code{EX_hdca(e)} \tab \eqn{-0.5} \cr + \code{EX_his_L(e)} \tab \eqn{-0.5} \cr + \code{EX_leu_L(e)} \tab \eqn{-0.5} \cr + \code{EX_lys_L(e)} \tab \eqn{-0.5} \cr + \code{EX_met_L(e)} \tab \eqn{-0.5} \cr + \code{EX_nh4(e)} \tab \code{def_bnd * -1} \cr + \code{EX_o2(e)} \tab \eqn{-2} \cr + \code{EX_ocdca(e)} \tab \eqn{-0.5} \cr + \code{EX_pi(e)} \tab \code{def_bnd * -1} \cr + \code{EX_pro_L(e)} \tab \eqn{-0.5} \cr + \code{EX_ser_L(e)} \tab \eqn{-0.5} \cr + \code{EX_so4(e)} \tab \code{def_bnd * -1} \cr + \code{EX_thr_L(e)} \tab \eqn{-0.5} \cr + \code{EX_thymd(e)} \tab \eqn{-0.5} \cr + \code{EX_trp_L(e)} \tab \eqn{-0.5} \cr + \code{EX_ttdca(e)} \tab \eqn{-0.5} \cr + \code{EX_tyr_L(e)} \tab \eqn{-0.5} \cr + \code{EX_ura(e)} \tab \eqn{-0.5} \cr + } + + Bilu et al 2006: + \tabular{ll}{ + \code{EX_nh4(e)} \tab \code{def_bnd * -1} \cr + \code{EX_pi(e)} \tab \code{def_bnd * -1} \cr + \code{EX_so4(e)} \tab \code{def_bnd * -1} \cr + \code{EX_glc(e)} \tab \eqn{-20} \cr + \code{EX_o2(e)} \tab \eqn{-2} \cr + \code{EX_ala_L(e)} \tab \eqn{-0.5} \cr + \code{EX_arg_L(e)} \tab \eqn{-0.5} \cr + \code{EX_asn_L(e)} \tab \eqn{-0.5} \cr + \code{EX_asp_L(e)} \tab \eqn{-0.5} \cr + \code{EX_cys_L(e)} \tab \eqn{-0.5} \cr + \code{EX_his_L(e)} \tab \eqn{-0.5} \cr + \code{EX_leu_L(e)} \tab \eqn{-0.5} \cr + \code{EX_lys_L(e)} \tab \eqn{-0.5} \cr + \code{EX_met_L(e)} \tab \eqn{-0.5} \cr + \code{EX_pro_L(e)} \tab \eqn{-0.5} \cr + \code{EX_ser_L(e)} \tab \eqn{-0.5} \cr + \code{EX_thr_L(e)} \tab \eqn{-0.5} \cr + \code{EX_trp_L(e)} \tab \eqn{-0.5} \cr + \code{EX_tyr_L(e)} \tab \eqn{-0.5} \cr + \code{EX_dcyt(e)} \tab \eqn{-0.5} \cr + \code{EX_gly(e)} \tab \eqn{-0.5} \cr + \code{EX_gua(e)} \tab \eqn{-0.5} \cr + \code{EX_thymd(e)} \tab \eqn{-0.5} \cr + \code{EX_h2o(e)} \tab \code{def_bnd * -1} \cr + \code{EX_na1(e)} \tab \code{def_bnd * -1} \cr + \code{EX_k(e)} \tab \code{def_bnd * -1} \cr + \code{EX_co2(e)} \tab \code{def_bnd * -1} \cr + \code{EX_ade(e)} \tab \eqn{-0.5} \cr + \code{EX_gln_L(e)} \tab \eqn{-0.5} \cr + \code{EX_ile_L(e)} \tab \eqn{-0.5} \cr + \code{EX_phe_L(e)} \tab \eqn{-0.5} \cr + \code{EX_val_L(e)} \tab \eqn{-0.5} \cr + } +} + +\value{ + An instance of class \code{\link{modelorg}} with input fluxes set + corresponding to the desired YPD medium. +} + +\references{ + Harrison, R., Papp, B., Pal, C., Oliver, S. G. and Delnert, D. (2007) + Plasticity of genetic interactions in metabolic networks of yeast. + \emph{PNAS} \bold{104}, 2307--2312. + + Bilu, Y., Shlomi, T., Barkai, N. and Ruppin, E. (2006) Conservation of + expression and sequence of metabolic genes is reflected by activity across + metabolic states. \emph{PLoS Comput Biol} \bold{2}, 932--938. +} + +\author{ + Gabriel Gelius-Dietrich +} + +\seealso{ + \code{\linkS4class{modelorg}}, \code{\link{findExchReact}} and + \code{\link{SYBIL_SETTINGS}} +} diff --git a/vignettes/sybil.Rnw b/vignettes/sybil.Rnw new file mode 100644 index 0000000..a054974 --- /dev/null +++ b/vignettes/sybil.Rnw @@ -0,0 +1,1494 @@ +\documentclass[a4paper,headings=small,captions=tableheading]{scrartcl} +\usepackage[english]{babel} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage{textcomp,lmodern} +\typearea[current]{last} +\usepackage{fixltx2e,mparhack,mathdots} + + +\usepackage{xspace} +\usepackage{paralist} +\usepackage{footmisc} +\usepackage{booktabs} +\usepackage{natbib} +\usepackage{hyperref} + +\usepackage{microtype} + +\newcommand{\Comp}[1]{\texttt{#1}} + +\addtolength{\skip\footins}{0.5\baselineskip} +\usepackage{fnpos} + + +\hypersetup{ + pdftitle = {sybil -- Efficient Constrained Based Modelling in R}, + pdfauthor = {Gabriel Gelius-Dietrich}, + pdfsubject = {constrained based modelling}, + pdfkeywords = {Optimization, FBA, MOMA, ROOM}, + pdfborder = {0 0 0}, + pdfhighlight = {/N} +} + + +% glyphs in pdf figures +\pdfinclusioncopyfonts=1 + +\newcommand{\pkg}[1]{\emph{#1}} +\newcommand{\pkgname}{\pkg{sybil}\xspace} +\newcommand{\prgname}[1]{\textsc{#1}} + +%\newcommand{\cplex}{IBM\textregistered{} % +% ILOG\textregistered{} CPLEX\textregistered{}% +%} +\newcommand{\cplex}{IBM ILOG CPLEX} + +\title{sybil -- Efficient Constrained Based Modelling in R} +%\VignetteIndexEntry{sybil -- Efficient Constrained Based Modelling in R} +%\VignettePackage{sybil} +\author{Gabriel Gelius-Dietrich} + + +% ---------------------------------------------------------------------------- % +% entire document +% ---------------------------------------------------------------------------- % + +\begin{document} + + +\maketitle + +\tableofcontents + +% ---------------------------------------------------------------------------- % + +\section{Introduction} + +The R-package \pkgname{} is a Systems Biology Library for R, implementing +algorithms for constraint based analysis of metabolic networks. +Among other functions, \pkgname currently provides efficient methods for +flux-balance analysis (FBA), minimization of metabolic adjustment (MOMA), +regulatory on/off minimization (ROOM), flux variability Analysis and robustness +Analysis. +The package \pkgname{} makes use of the sparse matrix implementation in the +R-package \pkg{Matrix}. + + +% ---------------------------------------------------------------------------- % + +\section{Installation} + +The package \pkgname{} itself depends on an existing installation of the +package \pkg{Matrix}. In order to run optimizations, at least one of the +following additional R-packages and the corresponding libraries are required: +\pkg{glpkAPI}, \pkg{cplexAPI}, \pkg{clpAPI} or \pkg{lpSolveAPI}. +These packages are available from +CRAN\footnote{\url{http://cran.r-project.org/}\label{cranfoot}}. +Additionally, \pkg{sybilGUROBI}---supporting the Gurobi +optimizer\footnote{\url{http://www.gurobi.com}}---is available on request. + + +% ---------------------------------------------------------------------------- % + +\section{Input files} +\label{inputformats} + +Input files for \pkgname are text files containing a description of the +metabolic model to analyze. These descriptions are basically lists of +reactions. +Two fundamentally different types of text files are supported: +\begin{inparaenum}[i)] +\item in tabular form (section~\ref{tabmod}), or +\item in SBML format (section~\ref{sbmlmod}). +\end{inparaenum} + + +% ---------------------------------------------------------------------------- % + +\subsection{Tabular form} \label{tabmod} + +Models in tabular form can be read using the function \Comp{readTSVmod()} and +written using the function \Comp{modelorg2tsv()}. +Each metabolic model description consists of three tables: +\begin{enumerate} +\item A model description, containing a model name, the compartments of the + model and so on (section~\ref{moddesc}). +\item A list of all metabolites (section~\ref{metlist}). +\item A list of all reactions (section~\ref{reactlist}). +\end{enumerate} +A model must contain at least a list of all reactions. All other tables are +optional. The tables contain columns storing the required data. Some of these +columns are optional, but if a certain table exists, there must be a minimal set +of columns. The column names (the first line in each file) are used as keywords +and cannot be changed. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Field and entry delimiter} \label{delim} + +There are two important variables in connection with text based tables: The +fields (columns) of the tables are separated by the value stored in the variable +\Comp{fielddelim}. If a single entry of a field contains a list of entries, +they are separated by the value of the variable \Comp{entrydelim}. +The default values are given table~\ref{delimtab}. +\begin{table} +\centering +\caption{Field and entry delimiters and their default values.} +\label{delimtab} +\begin{tabular}{cc} +\toprule +variable & default value \\ +\midrule +\Comp{fielddelim} & \Comp{\textbackslash t} \\ +\Comp{entrydelim} & \Comp{,\textvisiblespace} \\ +\bottomrule +\end{tabular} +\end{table} +The default behavior is, that the columns of each table are separated by a +single \Comp{tab} character. If a column entry holds more than one entry, they +are separated by a comma followed by a single +whitespace \Comp{\textvisiblespace} (not a tab!). + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Model description} \label{moddesc} +Every column in this table can have at most one entry, meaning each entry will +be a single character string. If a model description file is used, there should +be at least the two columns \Comp{name} and \Comp{id}. If they are +missing---or if no model description file is used---they will be set to the file +name of the reaction list, which must be there (any file name extension and the +string \Comp{\_react} at the end of the file name, will be removed). The model +description file contains the following fields: +\begin{description} + +\item[name] +A single character string giving the model name. If this field is empty, the +filename of the reaction list is used. + +\item[id] +A single character string giving the model id. If this field is empty, the +filename of the reaction list is used. + +\item[description] +A single character string giving a model description (optional). + +\item[compartment] +A single character string containing the compartment names. The names must be +separated by the value of \Comp{fielddelim} (optional, see section~\ref{delim}). + +\item[abbreviation] +A single character string containing the compartment abbreviations. The +abbreviations must be in square brackets and separated by the value of +\Comp{fielddelim} as mentioned above (optional). + +\item[Nmetabolites] +A single integer value giving the number of metabolites in the model (optional). + +\item[Nreactions] +A single integer value giving the number of reactions in the model (optional). + +\item[Ngenes] +A single integer value giving the number of unique, independent genes in the +model (optional). + +\item[Nnnz] +A single integer value giving the number of non-zero elements in the +stoichiometric matrix of the model (optional). + +\end{description} +The file \Comp{Ec\_core\_desc.tsv} (in \Comp{extdata/}) contains an exemplarily +table for the core energy metabolism of \emph{E.~coli} +\citep{Palsson:2006fk,Orth:2010fk}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Metabolite list} \label{metlist} + +This table is used in order to match metabolite id's given in the list of +reactions to long metabolite names. This table is optional, but if it is used, +the columns \Comp{abbreviation} and \Comp{name} should not be empty. +\begin{description} + +\item[abbreviation] +A list of single character strings containing the metabolite abbreviations. + +\item[name] +A list of single character strings containing the metabolite names. + +\item[compartment] +A list of character strings containing the metabolite compartment names. Each +entry can contain more than one compartment name, separated by \Comp{fielddelim} +(optional, currently unused). + +\end{description} +The file \Comp{Ec\_core\_met.tsv} (in \Comp{extdata/}) contains an exemplarily +table for the core energy metabolism of \emph{E.~coli} +\citep{Palsson:2006fk,Orth:2010fk}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Reaction list} \label{reactlist} + +This table contains the reaction equations used in the metabolic network. +\begin{description} + +\item[abbreviation] +A list of single character strings containing the reaction abbreviations +(optional, if empty, a warning will be produced). Entries in the field +abbreviation are used as reaction id's, so they must be unique. If they are +missing, they will be set to $v_i,\ i \in \{1, \dots, n\}\ \forall i$ with +$n$ being the total number of reactions. + +\item[name] +A list of single character strings containing the reaction names (optional, if +empty, the reaction id's (abbreviations) are used as reaction names. + +\item[equation] +A list of single character strings containing the reaction equation. See +section~\ref{writeEQ} for a description of reaction equation strings. + +\item[reversible] +A list of single character strings indicating if a particular reaction is +reversible or not. If the entry is set to \Comp{Reversible} or \Comp{TRUE}, the +reaction is considered as reversible, otherwise not. If this column is not used, +the arrow symbol of the reaction string is used (optional, see +section~\ref{writeEQ}). + +\item[compartment] +A list of character strings containing the compartment names in which the +current reaction takes place. Each entry can contain more than one name, +separated by \Comp{fielddelim} (optional, currently unused). + +\item[lowbnd] +A list of numeric values containing the lower bounds of the reaction rates. +If not set, zero is used for an irreversible reaction and the value of +\Comp{def\_bnd * -1} for a reversible reaction. See documentation of the +function \Comp{readTSVmod} for the argument \Comp{def\_bnd} (optional). + +\item[uppbnd] +A list of numeric values containing the upper bounds of the reaction rates. +If not set, the value of \Comp{def\_bnd} is used. See documentation of the +function \Comp{readTSVmod} for the argument \Comp{def\_bnd} (optional). + +\item[obj\_coef] +A list of numeric values containing objective values for each reaction +(optional, if missing, zero is used). + +\item[rule] +A list of single character strings containing the gene to reaction associations +(optional). + +\item[subsystem] +A list of character strings containing the reaction subsystems. Each reaction +can belong to more than one subsystem. The entries are separated by +\Comp{fielddelim} (optional). + +\end{description} +The file \Comp{Ec\_core\_react.tsv} (in \Comp{extdata/}) contains an exemplarily +table for the core energy metabolism of \emph{E.~coli} +\citep{Palsson:2006fk,Orth:2010fk}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{How to write a reaction equation string} \label{writeEQ} + +\begin{figure}[t] +\centering +\includegraphics{net-crop} +\caption{Simple example network. A) showing a closed network, B) an open + network. Capital letters are used as metabolite id's, lower case + letters are used as compartment id's: b: boundary metabolite, + c:~cytosol and e: external metabolite. Internal reactions are named + $v_{1:7}$, transport reactions $b_{1:3}$. Reactions $v_3$ and $v_4$ are + reversible, all others are irreversible. + Metabolites A\textsubscript{b}, C\textsubscript{b} and + E\textsubscript{b} are boundary metabolites and will be removed in + order to obtain an open network.} +\label{netex} +\end{figure} + +Any reaction string can be written without space. They are not required +but showed here, in order to make the string more human readable. + +\paragraph{Compartment Flag} Each reaction string may start with a compartment +flag in square brackets followed by a colon. The compartment flag here gives the +location of all metabolites appearing in the reaction. +\begin{verbatim} +[c] : +\end{verbatim} +The compartment flag can consist of more than one letter and---if used---must be +an element of the field \Comp{abbreviation} in the model description. The letter +\Comp{b} is reserved for boundary metabolites (argument \Comp{extMetFlag} in +function \Comp{readTSVmod()}), which can be transported inside the system (those +metabolites are only used in closed systems and will be removed during file +parsing). + +If the reaction string does not start with a compartment flag, the flag may be +appended (without whitespace) to each metabolite id (e.\,g. for transport +reactions): +\begin{verbatim} +h2o[e] <==> h2o[c] +\end{verbatim} +If no compartment flag is found, it is set to \Comp{[unknown]}. + +\paragraph{Reaction Arrow} +All reactions must be written in the direction educt to product, so that all +metabolites left of the reaction arrow are considered as educts, all metabolites +on the right of the reaction arrow are products. + +The reaction arrow itself consists of one or more \Comp{=} or \Comp{-} symbols. +The last symbol must be a \Comp{>}. If a reaction arrow starts with \Comp{<}, it +is taken as reversible, if the field \Comp{reversible} in the reaction list is +empty. If the field \Comp{reversible} is set to \Comp{TRUE} or +\Comp{Reversible}, the reactions will be treated as a reversible reaction, +independent of the reaction arrow. Each reaction must contain exactly one +reaction arrow. + +\paragraph{Stoichiometric Coefficients} +Stoichiometric coefficients must be in round brackets in front of the +corresponding metabolite: +\begin{verbatim} +(2) h[c] + (0.5) o2[c] + q8h2[c] --> h2o[c] + (2) h[e] + q8[c] +\end{verbatim} +Setting the stoichiometric coefficient in brackets makes it possible for the +metabolite id to start with a number. + +\paragraph{Metabolite Id's} +The abbreviation of a metabolite name (a metabolite id) must be unique for the model and +must not contain \Comp{+}, \Comp{(} or \Comp{)} characters. + +\paragraph{Examples} + +A minimal reaction list without compartment flags for figure~\ref{netex}B +(open network): +\begin{verbatim} +equation +A --> B +B <==> D +D <==> E +B --> C + --> A +C --> +E --> +\end{verbatim} +The same as above including compartment flags and external metabolites and all +transport reactions for figure~\ref{netex}A (closed network). The reactions +which take place in only one compartment (do not include a transport of +metabolites across membranes) have their compartment flag at the beginning +of the line (\Comp{[c]} in this example). For transport reactions all +metabolites have their own compartment flag, e.\,g. in line 5 metabolite +\Comp{A} is transported from compartment \Comp{[e]} (external) to compartment +\Comp{[c]} (cytosol): +\begin{verbatim} +equation +[c]: A --> B +[c]: B <==> D +[c]: D <==> E +[c]: B --> C +A[e] --> A[c] +C[c] --> C[e] +E[c] --> E[e] +A[b] --> A[e] +C[e] --> C[b] +E[e] --> E[b] +\end{verbatim} +The same as above including reaction id's for figure~\ref{netex} (fields are +separated by tabulators): +\begin{verbatim} +abbreviation equation +v2 [c]: A --> B +v3 [c]: B <==> D +v4 [c]: D <==> E +v6 [c]: B --> C +v1 A[e] --> A[c] +v7 C[c] --> C[e] +v5 E[c] --> E[e] +b1 A[b] --> A[e] +b3 C[e] --> C[b] +b2 E[e] --> E[b] +\end{verbatim} + +% ---------------------------------------------------------------------------- % + +\subsection{SBML} \label{sbmlmod} + +In order to read model files written in systems biology markup language (SBML), +the package \pkg{sybilSBML} is required, which is available from +CRAN\footnote{\url{http://CRAN.R-project.org/package=sybilSBML}\label{sybilhome}}. + + +% ---------------------------------------------------------------------------- % + +\section{Usage} + +In the following sections, it is assumed, that package \pkg{glpkAPI} is +installed additionally to \pkgname, thus GLPK is used as optimization software. +Load \pkgname{} in a running R session: +<<>>= +library(sybil) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Documentation} + +Get a list of all functions provided with \pkgname: +<<>>= +library(help = "sybil") +@ +Get details of the usage of a particular function in \pkgname +(e.\,g. \Comp{doubleGeneDel()}): +<<>>= +help(doubleGeneDel) +@ +Search through help files for a specific topic +(e.\,g. ``flux variability analysis''): +<<>>= +help.search("flux variability analysis") +@ +Open this vignette: +<<eval=FALSE>>= +vignette("sybil") +@ +% Demo?? + + +% ---------------------------------------------------------------------------- % + +\subsection{Reading a model in tabular form} + +The package \pkgname can read metabolic network models written in tabular form +as described in section~\ref{tabmod}. A reconstruction of the central metabolism +of \emph{E. coli} \citep{Orth:2010fk,Palsson:2006fk} is included as an example +dataset. The example dataset consists of three files: +\begin{enumerate} +\item \Comp{Ec\_core\_desc.tsv} containing the model description, +\item \Comp{Ec\_core\_met.tsv} containing the metabolite list and +\item \Comp{Ec\_core\_react.tsv} containing the reaction list. +\end{enumerate} +These files are located in the directory \Comp{extdata/} in the package +\pkgname{}. The exact location of the files can be retrieved with the +\Comp{system.file()} command: +<<>>= +mp <- system.file(package = "sybil", "extdata") +@ +Now the model files can be read in by using the command \Comp{readTSVmod()}: +<<print=true>>= +mod <- readTSVmod(prefix = "Ec_core", fpath = mp, quoteChar = "\"") +@ +If the fields in the input files for function \Comp{readTSVmod()} are quoted, +argument \Comp{quoteChar} must be used. The value of \Comp{quoteChar} is passed +to the argument \Comp{quote} of the R~function \Comp{read.table()}. Argument +\Comp{fpath} gets the path to the directory containing the model files. Argument +\Comp{prefix} can be used, if the file names of the model files end like the +file names used in the above example. All have the same base name +\Comp{"Ec\_core"} which is used for argument \Comp{prefix}. Function +\Comp{readTSVmod()} now assumes, that the model files are named as follows: +\begin{itemize} +\item the model description file (if exists): \Comp{<prefix>\_desc}\,, +\item the list of metabolites (if exists): \Comp{<prefix>\_met} and +\item the list of reactions (must be there): \Comp{<prefix>\_react}\,. +\end{itemize} +The file name suffix depends on the field delimiter. If the fields are +tab-delimited, the default is \Comp{.tsv}\,. Function \Comp{readTSVmod()} +returns an object of class \Comp{modelorg}. +Models (instances of class \Comp{modelorg}, see section~\ref{classmod}) can be +converted to files in tabular form with the command \Comp{modelorg2tsv}: +<<eval=FALSE>>= +modelorg2tsv(mod, prefix = "Ec_core") +@ +This will generate the three files shown in the list above (see also +section~\ref{tabmod}). +Load the example dataset included in \pkgname. +<<>>= +data(Ec_core) +@ +The example model is a `ready to use' model, it contains a biomass objective +function and an uptake of glucose \citep{Orth:2010fk,Palsson:2006fk}. It is the +same model as used in the text files before. + + +% ---------------------------------------------------------------------------- % + +\subsection{Media conditions} \label{envir} + +The current set of exchange reactions in the model can be accessed with the +function \Comp{findExchReact()}. +<<print=true>>= +ex <- findExchReact(Ec_core) +@ +The subset of uptake reactions can be retrieved by method \Comp{uptReact}. +<<print=true>>= +upt <- uptReact(ex) +ex[upt] +@ +Function \Comp{findExchReact()} returns an object of class \Comp{reactId\_Exch} +(extending class \Comp{reactId}) which can be used to alter reaction bounds +with function \Comp{changeBounds()}. Make lactate the main carbon source instead +of glucose: +<<>>= +mod <- changeBounds(Ec_core, ex[c("EX_glc(e)", "EX_lac_D(e)")], lb = c(0, -10)) +findExchReact(mod) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Flux-balance analysis} \label{fba} + +Perform flux-balance analysis (FBA) by using method \Comp{optimizeProb} of class +\Comp{modelorg}. +Method \Comp{optimizeProb} performs flux-balance analysis +\citep{Edwards:2002kx,Orth:2010vn}. It returns a list containing the return +value of the optimization process (\Comp{"ok"}), the solution status +(\Comp{"stat"}), the value of the objective function after optimization +(\Comp{"obj"}), the resulting flux distribution---the phenotype of the metabolic +network---(\Comp{"fluxes"}) and results of pre- and post processing commands, if +given (\Comp{"preP"} and \Comp{"postP"}). Also, a vector of integers will be +returned (\Comp{"fldind"}). The flux value \Comp{fluxes[fldind[i]]} is the flux +value of reaction \Comp{i} in the model (see section~\ref{mtf}). +<<print=true>>= +optL <- optimizeProb(Ec_core, algorithm = "fba", retOptSol = FALSE) +@ +Perform FBA, return an object of class \Comp{optsol\_optimizeProb} +(extends class \Comp{optsol}, see section~\ref{classopt}, this is the default +behavior). +<<print=true>>= +opt <- optimizeProb(Ec_core, algorithm = "fba", retOptSol = TRUE) +@ +The variable \Comp{opt} contains an object of class \Comp{optsol\_optimizeProb}, +a data structure storing all results of the optimization and providing methods +to access the data (see section~\ref{classopt}). +Retrieve the value of the objective function after optimization. +<<>>= +lp_obj(opt) +@ +Translate the return and status codes of the optimization software into human +readable strings. +<<>>= +checkOptSol(opt) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Minimize total flux} \label{mtf} + +Usually, an FBA solution is not unique. There can be many equivalent flux +distributions supporting the same objective value. A method to decide for one +out of these solutions is to compute the flux distribution minimizing the total +absolute flux (MTF) but still supporting the objective value of the FBA +solution. At first, an objective value, for example calculated via FBA, is +required: +<<>>= +fba <- optimizeProb(Ec_core, algorithm = "fba") +@ +Get the optimized value of the objective function: +<<>>= +mod_obj(fba) +@ +Now, the objective value of the solution in \Comp{fba} is used to compute a +flux distribution with a minimized total absolute flux: +<<>>= +mtf <- optimizeProb(Ec_core, algorithm = "mtf", wtobj = mod_obj(fba)) +@ +The value of the objective function for the MTF algorithm now is +<<>>= +lp_obj(mtf) +@ +which is the minimized sum of all absolute flux values. The number of variables +of the MTF problem is three times the number of the variables of the FBA +solution +<<>>= +nvar(fluxdist(fba)) +nvar(fluxdist(mtf)) +@ +which is due to the different formulations of the two optimization problems. +Consult the documentation of class \Comp{sysBiolAlg} (section~\ref{classsba}) +for more detailed information on the algorithms. +<<>>= +help("sysBiolAlg_fba-class") +help("sysBiolAlg_mtf-class") +@ +There are also shortcuts available: +<<>>= +?fba +?mtf +@ +Method \Comp{getFluxDist} can be used to get the flux distribution of the MTF +solution; the values of the variables corresponding to the reactions in the +metabolic network. +<<>>= +fl <- getFluxDist(mtf) +length(fl) +@ +The flux distribution of the exchange reactions can be retrieved in a similar +way (variable \Comp{ex} contains the exchange reactions of the \emph{E. coli} +model, see section~\ref{envir}). +<<print=true>>= +fd <- getFluxDist(mtf, ex) +getNetFlux(fd) +@ +Function \Comp{getNetFlux()} the absolute flux values of the exchange reactions +grouped by flux direction. The value of the objective function given in the +model (here: biomass production) can be accessed by method \Comp{mod\_obj}: +<<>>= +mod_obj(mtf) +@ +which is of course the same value as for the FBA algorithm. + + +% ---------------------------------------------------------------------------- % + +\subsection{Genetic perturbations} \label{komut} + +To compute the metabolic phenotypes of \emph{in silico} knock-out mutants, +argument \Comp{gene} of method \Comp{optimizeProb} can be used. +<<print=true>>= +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0) +@ +Argument \Comp{gene} gets a character vector of gene locus tags present in the +used model. The flux boundaries of reactions affected by the genes given in +argument \Comp{gene} will be set to the values of arguments \Comp{lb} and +\Comp{ub}. If both arguments are set to zero, no flux through the affected +reactions is allowed. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Minimization of metabolic adjustment (MOMA)} \label{MOMA} + +The default algorithm used by method \Comp{optimizeProb} is +FBA \citep{Edwards:2002kx,Orth:2010vn}, implying the assumption, that the +phenotype of the mutant metabolic network is independent of the wild-type +phenotype. An alternative is the MOMA algorithm described in +\citet{Segre:2002fk} minimizing the hamiltonian distance of the wild-type +phenotype and the mutant phenotype (argument \Comp{algorithm = "lmoma"} computes +a linearized version of the MOMA algorithm; \Comp{algorithm = "moma"} runs the +quadratic formulation). +<<print=true>>= +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0, + algorithm = "lmoma", wtflux = getFluxDist(mtf)) +@ +The variable \Comp{ko} contains the solution of the linearized version of the +MOMA algorithm. A wild-type flux distribution can be set via argument +\Comp{wtflux}, here, the flux distribution computed through the MTF algorithm +was used. If argument \Comp{wtflux} is not set, a flux distribution based on +FBA will be used. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Regulatory on/off minimization (ROOM)} \label{ROOM} + +Another alternative is the ROOM algorithm (regulatory on/off minimization) +described in \citet{Shlomi:2005fk}. Set argument \Comp{algorithm} to \Comp{room} +in order to run ROOM. +<<eval=FALSE>>= +ko <- optimizeProb(Ec_core, gene = "b2276", lb = 0, ub = 0, + algorithm = "room", wtflux = getFluxDist(mtf), + solverParm = list(PRESOLVE = GLP_ON)) +@ +ROOM is a mixed integer programming problem which requires for GLPK to switch +on the pre-solver. See section \ref{optparm} for more information on setting +parameters to the mathematical programming software. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Multiple knock-outs} \label{multknockout} + +Method \Comp{optimizeProb} can be used to study the metabolic phenotype of one +knock-out mutant. The purpose of functions \Comp{oneGeneDel()}, +\Comp{doubleGeneDel()} and \Comp{geneDeletion()} is the simulation of multiple +\emph{in silico} knock-outs (see table~\ref{tabmultko}). +\begin{table} +\centering +\caption{Functions used to simulate multiple + \emph{in silico} knock-out mutants.} +\label{tabmultko} +\begin{tabular}{ll} +\toprule +function & purpose \\ +\midrule +\Comp{oneGeneDel()} & single gene knock-outs \\ +\Comp{doubleGeneDel()} & pairwise gene knock-outs \\ +\Comp{geneDeletion()} & simultaneous deletion of $n$ genes \\ +\bottomrule +\end{tabular} +\end{table} +Function \Comp{oneGeneDel()} simulates all possible single gene knock-out +mutants in a metabolic model (default algorithm is FBA). +<<print=true>>= +opt <- oneGeneDel(Ec_core) +@ +The function \Comp{oneGeneDel} gets an argument \Comp{geneList}, a character +vector containing the gene id's to knock out. If \Comp{geneList} is missing, +all genes are taken into account. The example model contains 137 independent +genes, so 137 optimizations will be performed. + +The result stored in the variable \Comp{opt} is an object of class +\Comp{optsol\_geneDel}, extending class \Comp{optsol\_optimizeProb} +(see section~\ref{fba}). Method \Comp{checkOptSol} gives an overview about the +results and status of the optimizations. Additionally, class \Comp{optsol} +contains a method \Comp{plot}, plotting a histogram of the values of the +objective function given in the model after optimization +(section~\ref{classopt}). +<<>>= +checkOptSol(opt) +@ +Plot the histogram: +\begin{center} +<<fig=TRUE>>= +plot(opt, nint = 20) +@ +\end{center} +Argument \Comp{algorithm} can be used here to use MOMA to compute the mutant +flux distributions. Additionally, a wild-type solution can be provided. +\begin{center} +<<fig=TRUE>>= +opt <- oneGeneDel(Ec_core, algorithm = "lmoma", wtflux = getFluxDist(mtf)) +checkOptSol(opt) +plot(opt, nint = 20) +@ +\end{center} +In order to perform all possible double-knock-out mutants, or $n$-knock-out +mutants, the function \Comp{geneDeletion} can be used. Perform single gene +deletions (in principle the same as before with \Comp{oneGeneDel}). +<<>>= +opt <- geneDeletion(Ec_core) +@ +Compute all double-knock-out mutants and all triple-knock-out mutants +<<eval=FALSE>>= +opt2 <- geneDeletion(Ec_core, combinations = 2) +opt3 <- geneDeletion(Ec_core, combinations = 3) +@ +which will result in 9317 optimizations for double-knock-outs and +419\,221~Optimizations for triple-knock-outs using the metabolic model of the +core energy metabolism of \emph{E.\,coli}. This model contains 137 genes. + + +% ---------------------------------------------------------------------------- % + +\subsection{Flux variability analysis} + +The function \Comp{fluxVar} performs a flux variability analysis with a given +model \citep{Mahadevan:2003fk}. The minimum and maximum flux values for each +reaction in the model are calculated, which still support a certain percentage +of a given optimal functional state $Z_{\mathrm{opt}}$. +\begin{center} +<<fig=TRUE>>= +opt <- fluxVar(Ec_core, percentage = 80, verboseMode = 0) +plot(opt) +@ +\end{center} +% The example below is based upon the metabolic model of the human red blood cell +% by \citet{Palsson:2006fk} and \citet{Price:2004fk}. +% <<>>= +% rbc <- readTSVmod(reactList = "rbc.tsv", fpath = mp, quoteChar = "\"") +% @ +% Perform flux variability analysis. +% \begin{center} +% <<fig=TRUE>>= +% opt <- fluxVar(Ec_core, percentage = 1, verboseMode = 0) +% plot(opt) +% @ +% \end{center} + + +% ---------------------------------------------------------------------------- % + +\subsection{Robustness analysis} + +The function \Comp{robAna} performs a robustness analysis with a given model. +The flux of a control reaction will be varied stepwise between the maximum and +minimum value the flux of the control reaction can reach \citep{Palsson:2006fk}. +The example below shows a flux variability analysis based upon the metabolic +model of the core energy metabolism of \emph{E.\,coli} using the exchange flux +of oxygen as control reaction. +\begin{center} +<<fig=TRUE>>= +opt <- robAna(Ec_core, ctrlreact = "EX_o2(e)", verboseMode = 0) +plot(opt) +@ +\end{center} + + +% ---------------------------------------------------------------------------- % + +\subsection{Phenotypic phase plane analysis} + +The function \Comp{phpp} performs a phenotypic phase plane +analysis \citep{Edwards:2001fk,Edwards:2002uq} with a given model. The flux of +two control reactions will be varied stepwise between a given maximum and +minimum value. The example below shows a phenotypic phase plane analysis based +upon the metabolic model of the core energy metabolism of \emph{E.\,coli} using +the exchange fluxes of oxygen and succinate as control reactions. First, the +uptake of glucose is switched off. +\begin{center} +<<fig=TRUE>>= +Ec_core_wo_glc <- changeUptake(Ec_core, off = "glc_D[e]") +opt <- phpp(Ec_core_wo_glc, + ctrlreact = c("EX_succ(e)", "EX_o2(e)"), + redCosts = TRUE, + numP = 25, + verboseMode = 0) +plot(opt) +@ +\end{center} +Plot reduced costs of succinate import flux and oxygen import flux. + +<<fig=TRUE, label=phpp_rf, include=FALSE>>= +plot(opt, "EX_succ(e)") +@ +<<fig=TRUE,label=phpp_rs, include=FALSE>>= +plot(opt, "EX_o2(e)") +@ + +\begin{minipage}{0.45\textwidth} +\begin{center} +\includegraphics[width=\textwidth]{sybil-phpp_rf} +\end{center} +\end{minipage} +\hfill +\begin{minipage}{0.45\textwidth} +\begin{center} +\includegraphics[width=\textwidth]{sybil-phpp_rs} +\end{center} +\end{minipage} + + +% ---------------------------------------------------------------------------- % + +\subsection{Summarizing simulation results} + +Each simulation generates an object of class \Comp{optsol} containing all +the results of the optimizations. In order to get a quick overview of the +results, the function \Comp{summaryOptsol()} can be used. At first, let's +compute all single gene knock-outs of the metabolic model of the core energy +metabolism of \emph{E.\,coli}: +<<>>= +opt <- oneGeneDel(Ec_core, algorithm = "fba", fld = "all") +@ +Generate a summary: +<<print=true>>= +sum <- summaryOptsol(opt, Ec_core) +@ +The function \Comp{summaryOptsol()} returns an object of class +\Comp{optsolSummary} and needs the object of class \Comp{optsol} (results of +simulations) and the corresponding object of class \Comp{modelorg} (the entire +metabolic network). The generated object of class \Comp{summaryOptsol} contains +some information about the flux distribution, substrates, products and limiting +reactions. + +The method \Comp{printExchange()} prints a subset of the flux distribution for +the exchange reactions in the model. Each column represents the environment of +one optimization. The symbol \Comp{"-"} indicates that the corresponding +metabolite is imported (is a substrate); the symbol \Comp{"+"} indicates, that +the corresponding metabolite excreted (is a product). +<<>>= +printExchange(sum, j = c(1:50), dense = TRUE) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Parallel computing} + +The package \pkgname{} provides basic support for the R-package \pkg{parallel} +in function \Comp{multidel()}. The following example shows the computation of +all possible triple-knock-out mutants using the model of the core energy +metabolism of \emph{E.\,coli}. The set of genes included in the analysis will +be reduced to genes, which are not lethal. A gene $i$ is considered as +``lethal'', if in a single-gene-knockout the deletion of gene $i$ results in a +maximum growth ratio of zero. +<<>>= +ref <- optimizeProb(Ec_core) +opt <- oneGeneDel(Ec_core) +let <- lethal(opt, wt = mod_obj(ref)) +nletid <- c(1:length(allGenes(Ec_core)))[! let] +@ + +\noindent +At first, a wild-type maximum growth rate is computed and stored in the variable +\Comp{ref}. Then, all single-gene knock-outs are computed. The variable +\Comp{let} contains pointers to the gene id's of genes, who's deletion is +lethal. The variable \Comp{nletid} contains pointers to the gene id's of all +genes, except for the lethal ones. +<<eval=FALSE>>= +gmat <- combn(nletid, 3) +@ +The variable \Comp{gmat} now contains a matrix with three rows, each column is +one combination of three values in \Comp{nletid}; one set of genes to knock-out +in one step. +<<eval=FALSE>>= +opt <- multiDel(Ec_core, nProc = 4, todo = "geneDeletion", del1 = gmat) +@ +The function \Comp{multiDel} performs a \Comp{geneDeletion} with the model +\Comp{Ec\_core} on four CPU's (argument \Comp{nProc}) on a shared memory +machine. Argument \Comp{del1} is the matrix containing the sets of genes to +delete. This matrix will be split up in smaller sub-matrices all having about the +same number of columns and three rows. The sub-matrices are passed to +\Comp{geneDeletion} and are processed on separate cores in parallel. The +resulting variable \Comp{opt} now contains a list of four objects of class +\Comp{optsol\_genedel}. Use \Comp{mapply} to access the values stored in the +\Comp{optsol} objects. +<<eval=FALSE>>= +mapply(checkOptSol, opt) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Interacting with the optimization process} + +Method \Comp{optimizeProb} provides a basic mechanism to run commands before +and or after solving the optimization problem. In order to retrieve the reduced +costs after the optimization, use argument \Comp{poCmd}. +<<>>= +opt <- optimizeProb(Ec_core, poCmd = list("getRedCosts")) +postProc(opt) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Optimization software} + +To solve optimization problems, +GLPK\footnote{Andrew Makhorin: GNU Linear Programming Kit, version~4.42 or +higher + +\url{http://www.gnu.org/software/glpk/glpk.html}}, +\cplex\footnote{\cplex{} version 12.2 (or higher) from the IBM Academic +Ini\-tia\-tive + +\url{https://www.ibm.com/developerworks/university/academicinitiative/}}, +COIN-OR Clp\footnote{COIN-OR linear programming version 1.12.0 or higher +\url{https://projects.coin-or.org/Clp}} +or lp\_solve\footnote{lp\_solve via R-package \pkg{lpSolveAPI} version 5.5.2.0-5 +or higher + +\url{http://lpsolve.sourceforge.net/5.5/index.htm}} +can be used (package \pkg{sybilGUROBI} providing support for Gurobi +optimization\footnote{\url{http://www.gurobi.com}} is available on request). +All functions performing optimizations, get the arguments +\Comp{solver} and \Comp{method}. The first setting the desired solver and the +latter setting the desired optimization algorithm. +Possible values for the argument \Comp{solver} are: +\begin{itemize} +\item \Comp{"glpkAPI"}, which is the default, +\item \Comp{"cplexAPI"}, +\item \Comp{"clpAPI"} or +\item \Comp{"lpSolveAPI"}. +\end{itemize} +Perform FBA, using GLPK as solver and ``simplex exact'' as algorithm. +<<eval=FALSE>>= +optimizeProb(Ec_core, method = "exact") +@ +Perform FBA, using \cplex{} as solver and ``dualopt'' as algorithm. +<<eval=FALSE>>= +optimizeProb(Ec_core, solver = "cplexAPI", method = "dualopt") +@ +The R-packages \pkg{glpkAPI}, \pkg{clpAPI} and \pkg{cplexAPI} +provide access to the C-API of the corresponding optimization software. +They are also available from CRAN\footref{cranfoot}. + + +% ---------------------------------------------------------------------------- % + +\subsection{Setting parameters to the optimization software} +\label{optparm} + +All functions performing optimizations can handle the argument +\Comp{solverParm} getting a list or data frame containing parameters used by the +optimization software. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{GLPK} + +For available parameters used by GLPK, see the GLPK and the \pkg{glpkAPI} +documentation. +<<eval=FALSE>>= +opt <- oneGeneDel(Ec_core, + solverParm = list(TM_LIM = 1000, + PRESOLVE = GLP_ON)) +@ +The above command performs a single gene deletion experiment +(see section~\ref{multknockout}), sets the time limit for each optimization to +one second and does pre-solving in each optimization. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{\cplex} + +For available parameters used by \cplex{}, see the \cplex{} and the +\pkg{cplexAPI} documentation. +<<eval=FALSE>>= +opt <- optimizeProb(Ec_core, + solverParm = list(CPX_PARAM_SCRIND = CPX_ON, + CPX_PARAM_EPRHS = 1E-09), + solver = "cplexAPI") +@ +The above command performs FBA, sets the messages to screen switch to ``on'' +and sets the feasibility tolerance to $10^{-9}$. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{COIN-OR Clp} + +At the time of writing, it is not possible to set any parameters when using +COIN-OR Clp. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{lpSolveAPI} + +See the \pkg{lpSolveAPI} documentation for parameters for \Comp{lp\_solve}. +<<eval=FALSE>>= +opt <- optimizeProb(Ec_core, + solverParm = list(verbose = "full", + timeout = 10), + solver = "lpSolveAPI") +@ +The above command performs FBA, sets the verbose mode to ``full'' +and sets the timeout to ten seconds. + + + +% ---------------------------------------------------------------------------- % + +\subsection{Setting parameters in sybil} + +Parameters to \pkgname{} can be set using the function \Comp{SYBIL\_SETTINGS}. +Parameter names and their default values are shown in table~\ref{sybilparm}, +all possible values are described in the \Comp{SYBIL\_SETTINGS} documentation. +<<>>= +help(SYBIL_SETTINGS) +@ +\begin{table} +\centering +\caption{Available parameters in \pkgname{} and their default values.} +\label{sybilparm} +\begin{tabular}{ll} +\toprule +parameter name & default value \\ +\midrule +\Comp{SOLVER} & \Comp{glpkAPI} \\ +\Comp{METHOD} & \Comp{simplex} \\ +\Comp{SOLVER\_CTRL\_PARM} & \Comp{as.data.frame(NA)} \\ +\Comp{ALGORITHM} & \Comp{fba} \\ +\Comp{TOLERANCE} & \Comp{1E-6} \\ +\Comp{MAXIMUM} & \Comp{1000} \\ +\Comp{OPT\_DIRECTION} & \Comp{max} \\ +\Comp{PATH\_TO\_MODEL} & \Comp{.} \\ +\bottomrule +\end{tabular} +\end{table} +The function \Comp{SYBIL\_SETTINGS} gets at most two arguments: +<<eval=FALSE>>= +SYBIL_SETTINGS("parameter name", value) +@ +the first one giving the name of the parameter to set (as character string) and +the second one giving the desired value. If \Comp{SYBIL\_SETTINGS} is called +with only one argument +<<eval=FALSE>>= +SYBIL_SETTINGS("parameter name") +@ +the current setting of \Comp{"parameter name"} will be returned. All parameters +and their values can be achieved by calling \Comp{SYBIL\_SETTINGS} without +any argument. +<<eval=FALSE>>= +SYBIL_SETTINGS() +@ + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Solver software specific} + +The two parameters \Comp{SOLVER} and \Comp{METHOD} depend on each other, e.\,g. +the method called \Comp{simplex} is only available when \Comp{glpkAPI} is used +as solver software. Each solver has its own specific set of methods available in +order to solve optimization problems. If one changes the parameter \Comp{SOLVER} +to, let's say \Comp{cplexAPI}, the parameter \Comp{METHOD} will automatically +be adjusted to the default method used by \Comp{cplexAPI}. +Set parameter solver to \cplex{} for every optimization: +<<>>= +SYBIL_SETTINGS("SOLVER", "cplexAPI", loadPackage = FALSE) +@ +Now, \cplex{} is used as default solver e.\,g. in \Comp{optimizeProb} or +\Comp{oneGeneDel}, and parameter \Comp{METHOD} has changed to the default method +in \pkg{cplexAPI}. Setting argument \Comp{loadPackage} to \Comp{FALSE} prevents +loading the API package. Get the current setting for \Comp{Method}: +<<>>= +SYBIL_SETTINGS("METHOD") +@ +Reset the solver to \Comp{glpkAPI}: +<<>>= +SYBIL_SETTINGS("SOLVER", "glpkAPI") +@ +Now, the default method again is \Comp{simplex} +<<>>= +SYBIL_SETTINGS("METHOD") +@ +It is not possible to set a wrong method for a given solver. If the desired +method is not available, always the default method is used. +Parameters to the solver software (parameter \Comp{SOLVER\_CTRL\_PARM}) must be +set as \Comp{list} or \Comp{data.frame} as described in section~\ref{optparm}. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Analysis specific} + +The parameter \Comp{ALGORITHM} controls the way gene deletion analysis will be +performed. The default setting \Comp{"fba"} will use flux-balance analysis (FBA) +as described in \citet{Edwards:2002kx} and \citet{Orth:2010vn}. Setting this +parameter to \Comp{"lmoma"}, results in a linearized version of the MOMA +algorithm described in \citet{Segre:2002fk} ("moma" will run the original +version). The linearized version of MOMA, like it is implemented in the COBRA +Toolbox \citep{Becker:2007uq,Schellenberger:2011fk}, can be used in functions +like \Comp{oneGeneDel()} via the Boolean argument \Comp{COBRAflag}. +Setting the parameter \Comp{"ALGORITHM"} to \Comp{"room"} will run a regulatory +on/off minimization as described in \citet{Shlomi:2005fk}. +See also section~\ref{komut} for details on gene deletion analysis. + + +% ---------------------------------------------------------------------------- % + +\section{Central data structures} + +\subsection{Class modelorg} \label{classmod} + +The class \Comp{modelorg} is the core datastructure to represent a metabolic +network, in particular the stoichiometric matrix $S$. +An example (E.\,coli core flux by \citep{Palsson:2006fk}) is shipped within +\pkgname and can be loaded this way: +<<>>= +data(Ec_core) +Ec_core +@ +The generic method \Comp{show} displays a short summary of the parameters of the +metabolic network. See +<<>>= +help("modelorg") +@ +for the list of available methods. All slots of an object of class +\Comp{modelorg} are accessible via setter and getter methods having the same +name as the slot. For example, slot \Comp{react\_num} contains the number of +reactions in the model (equals the number of columns in $S$). Access the +number of reactions in the \emph{E.\,coli} model. +<<>>= +react_num(Ec_core) +@ +Get all reaction is's: +<<>>= +id <- react_id(Ec_core) +@ +Change a reaction id: +<<>>= +react_id(Ec_core)[13] <- "biomass" +@ +Plot an image of the stoichiometric matrix $S$: +\begin{center} +<<fig=TRUE>>= +cg <- gray(0:8/8) +image(S(Ec_core), col.regions = c(cg, rev(cg))) +@ +\end{center} +Matrices in objects of class \Comp{modelorg} are stored in formats provided by +the \pkg{Matrix}-package\footnote{http://CRAN.R-project.org/package=Matrix}. + +Objects of class \Comp{modelorg} can easily be created. Sources are common file +formats like tab delimited files from the +BiGG database \citep{Schellenberger:2010fk}\footnote{\url{http://bigg.ucsd.edu}} +or SBML files (with package \pkg{sybilSBML}\footref{sybilhome}). +See section~\ref{inputformats} on +page \pageref{inputformats} about supported file formats and their description. +Read a reaction list generated from the BiGG database: +<<eval=FALSE>>= +mod <- readTSVmod(reactList = "reactionList.txt") +@ +Here, \Comp{"reactionList.txt"} is an from BiGG database exported reaction +list. Usually, these files do neither contain an objective function, nor upper +and lower bounds on the reaction rates. They need to be added to the returned +object of class \Comp{modelorg} using the methods \Comp{obj\_coef<-}, +\Comp{lowbnd<-} and \Comp{uppbnd<-}, or by adding the columns \Comp{obj\_coef}, +\Comp{lowbnd} and \Comp{uppbnd} to the input file. + + +% ---------------------------------------------------------------------------- % + +\subsection{Class optsol} \label{classopt} + +\begin{figure} + \centering + \includegraphics{optsol-class} + \caption{UML representation of class \Comp{optsol}.} + \label{optsol-class} +\end{figure} + +The derived classes of class \Comp{optsol} (optimization solution) are used to +store information and results from various optimization problems and their +biological relation. See +<<>>= +help("optsol") +@ +for the list of available methods to access the +data (figure~\ref{optsol-class}). A simple demonstration would be: +<<print=true>>= +os <- optimizeProb(Ec_core) +is(os) +@ +Retrieve objective value. +<<>>= +lp_obj(os) +@ +Retrieve flux distribution. +<<>>= +getFluxDist(os) +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Class optObj} \label{classoo} + +\begin{figure} + \centering + \includegraphics{optObj-class} + \caption{UML representation of class \Comp{optObj}.} + \label{optObj-class} +\end{figure} + +The class \Comp{optObj} is \pkgname's internal representation of an optimization +problem (figure~\ref{optObj-class}). Objects of this class harbor four slots: +\begin{inparaenum}[i)] +\item \Comp{oobj}: a pointer to the C-structure of the problem object (depending + on the solver software), +\item \Comp{solver}: the name of the solver, +\item \Comp{method}: the name of the optimization method used by the solver and +\item \Comp{probType}: single character string, describing the problem type + (e.\,g. \Comp{lp}: linear programming, or \Comp{mip}: mixed integer + programming). +\end{inparaenum} + +The package \pkgname provides several functions to alter the problem object. +Each function takes care of the special needs of every supported solver. The +following example should illustrate the purpose of class \Comp{optObj}. +Consider a linear programming problem, here written in lp formatted file +format: +\begin{verbatim} +Maximize + obj: + x_1 + x_2 +Subject To + r_1: + 0.5 x_1 + x_2 <= 4.5 + r_2: + 2 x_1 + x_2 <= 9 +Bounds + 0 <= x_1 <= 1000 + 0 <= x_2 <= 1000 +\end{verbatim} +In order to solve this lp problem with \pkgname{}, an object of class +\Comp{optObj} has to be created. The constructor function has the same name as +the class it builds. +<<print=true>>= +lp <- optObj(solver = "glpkAPI", method = "exact") +@ +The first argument is the used solver software, in this case it is GLPK. The +second optional argument gives the method, how the solver software has to solve +the problem. Here, it is the simplex exact algorithm of GLPK. The constructor +function \Comp{optObj()} (figure~\ref{optObj-const}) returns an object of class +\Comp{optObj\_glpkAPI} in this case. This class enables \pkgname to communicate +with the GLPK software. The constructor function \Comp{optObj()} calls the +function \Comp{checkDefaultMethod()} which tries to load the specified solver +package and also checks if all other arguments (\Comp{method} and \Comp{pType}) +are valid arguments. Each solver package has its own set of methods for specific +types of optimization (e.\,g. linear programming or quadratic programming) and +is thus available maybe not for all problem types. + +\begin{figure} + \centering + \includegraphics{optObj-const} + \caption{Work flow of the constructor function \Comp{optObj()}.} + \label{optObj-const} +\end{figure} + + +Initialize the new problem object. Each solver software needs to create +specific data structures to hold the problem and solution data. +<<print=true>>= +lp <- initProb(lp) +@ +Slot \Comp{oobj} holds a pointer to the problem object of GLPK. Now, we need to +allocate space for the problem data and load the data into the problem object. +<<>>= +cm <- Matrix(c(0.5, 2, 1, 1), nrow = 2) +loadLPprob(lp, nCols = 2, nRows = 2, mat = cm, + lb = c(0, 0), ub = rep(1000, 2), obj = c(1, 1), + rlb = c(0, 0), rub = c(4.5, 9), rtype = c("U", "U"), + lpdir = "max") +@ +The first command generates the constraint matrix in sparse format (see also +documentation in package \pkg{Matrix}). The second command loads the problem +data into the problem object. +<<>>= +lp +@ +All data are now set in the problem object, so it can be solved. +<<print=true>>= +status <- solveLp(lp) +@ +Translate the status code in a text string. +<<>>= +getMeanReturn(code = status, solver = solver(lp)) +@ +Check the solution status. +<<>>= +status <- getSolStat(lp) +getMeanStatus(code = status, solver = solver(lp)) +@ +Retrieve the value of the objective function and the values of the variables +after optimization. +<<>>= +getObjVal(lp) +getFluxDist(lp) +@ +Get the reduced costs. +<<>>= +getRedCosts(lp) +@ +Delete problem object and free all memory allocated by the solver software. +<<>>= +delProb(lp) +lp +@ + + +% ---------------------------------------------------------------------------- % + +\subsection{Class sysBiolAlg} \label{classsba} + +\begin{figure} + \centering + \includegraphics{sysBiolAlg-class} + \caption{UML representation of class \Comp{sysBiolAlg}.} + \label{sysBiolAlg-class} +\end{figure} + +The class \Comp{sysBiolAlg} holds objects of class \Comp{optObj} which are +prepared for a particular kind of algorithm, e.\,g. FBA, MOMA or ROOM +(figure~\ref{sysBiolAlg-class}). Class \Comp{optObj} takes care of the +communication between \pkgname and the solver software. Class \Comp{sysBiolAlg} +instead is responsible for the algorithm used to analyze a metabolic network. +The constructor function \Comp{sysBiolalg()} (figure~\ref{sysBiolAlg-const}) +gets at least two arguments: +\begin{inparaenum}[1.] +\item an object of class \Comp{modelorg} (section~\ref{classmod}) and +\item a single character string indicating the name of the desired algorithm. +\end{inparaenum} +Further arguments are passed through argument \Comp{\dots} to the corresponding +constructor of the class extending class \Comp{sysBiolAlg}. The base class +\Comp{sysBiolAlg} is virtual, no objects can be created from that class +directly. The constructor function builds an instance of a class extending the +base class: +<<>>= +ec <- sysBiolAlg(Ec_core, algorithm = "fba") +is(ec) +@ +Now, the variable \Comp{ec} contains an object of class \Comp{sysBiolAlg\_fba}. +Slot \Comp{problem} of that object is of class \Comp{optObj} and is prepared +for FBA. The optimization can be performed with method \Comp{optimizeProb}: +<<>>= +opt <- optimizeProb(ec) +@ +The return value of \Comp{optimizeProb} is discussed in section~\ref{fba}. +Method \Comp{optimizeProb} of class \Comp{sysBiolAlg} always returns a list, +not an object of class \Comp{optsol}. +In order to run a ROOM analysis create an object of class +\Comp{sysBiolAlg\_room}: +<<>>= +ecr <- sysBiolAlg(Ec_core, algorithm = "room", wtflux = opt$fluxes) +is(ecr) +ecr +@ +Argument \Comp{wtflux} gets the optimal flux distribution computed via FBA +earlier. It is used by the constructor method of class \Comp{sysBiolAlg\_room}. + +\begin{figure} + \centering + \includegraphics{sysBiolAlg-const} + \caption{Work flow of the constructor function \Comp{sysBiolAlg()}.} + \label{sysBiolAlg-const} +\end{figure} + +\begin{figure}[ht] + \centering + \includegraphics{sysBiolAlg-init} + \caption{Work flow of the constructor methods of classes extending + class \Comp{sysBiolAlg}. The gray shaded part is done by the + constructor method or the base class.} + \label{sysBiolAlg-init} +\end{figure} + + +% ---------------------------------------------------------------------------- % + +\subsubsection{Constructor methods} + +The base class \Comp{sysBiolAlg} contains a constructor method \Comp{initialize} +which is called by the constructor methods of the subclasses via +\Comp{callNextMethod()} (figure~\ref{sysBiolAlg-init}). Every subclass has its +own constructor method preparing all necessary data structures in order to call +the constructor of the base class. For example, for the ROOM algorithm, a +``wild type'' flux distribution is required (argument \Comp{wtflux} in the +example above). The constructor of class \Comp{sysBiolAlg\_room} generates all +data structures to build the optimization problem, e.\,g. the constraint matrix, +objective coefficients, right hand side, \dots{} It passes all these data to +the constructor of \Comp{sysBiolAlg} via a call to \Comp{callNextMethod()}. +This constructor generates the object of class \Comp{optObj} while taking care +on solver software specific details. + + +% ---------------------------------------------------------------------------- % + +\subsubsection{New algorithms} + +In order to extend the functionality of \pkgname with new algorithms, a new +class describing that algorithm is required. The function +\Comp{promptSysBiolAlg()} generates a skeletal structure of a new class definition +and a corresponding constructor method. To implement an algorithm named ``foo'', +run +<<eval=FALSE>>= +promptSysBiolAlg(algorithm = "foo") +@ +which generates a file \Comp{sysBiolAlg\_fooClass.R} containing the new class +definition. The class \Comp{sysBiolAlg\_foo} will extend class \Comp{sysBiolAlg} +directly and will not add any slots to the class. Additionally, an unfinished +method \Comp{initialize} is included. Here it is necessary to generate the data +structures required by the new algorithm. There are comments in the skeletal +structure guiding through the process. + + +%% maybe next chapter: how to extend sybil, example fluxVar or robAna + +% ---------------------------------------------------------------------------- % + +\newpage + +\bibliographystyle{abbrvnat} +\bibliography{sybil} + +\end{document} diff --git a/vignettes/sybil.bib b/vignettes/sybil.bib new file mode 100644 index 0000000..9a9078b --- /dev/null +++ b/vignettes/sybil.bib @@ -0,0 +1,224 @@ +%% This BibTeX bibliography file was created using BibDesk. +%% http://bibdesk.sourceforge.net/ + + +%% Created for Gabriel Gelius-Dietrich at 2013-07-29 09:43:52 +0200 + + +%% Saved with string encoding Unicode (UTF-8) + + + +@article{Edwards:2002uq, + Abstract = {Genome-scale metabolic maps can be reconstructed from annotated genome sequence data, biochemical literature, bioinformatic analysis, and strain-specific information. Flux-balance analysis has been useful for qualitative and quantitative analysis of metabolic reconstructions. In the past, FBA has typically been performed in one growth condition at a time, thus giving a limited view of the metabolic capabilities of a metabolic network. We have broadened the use of FBA to map the optimal metabolic flux distribution onto a single plane, which is defined by the availability of two key substrates. A finite number of qualitatively distinct patterns of metabolic pathway utilization were identified in this plane, dividing it into discrete phases. The characteristics of these distinct phases are interpreted using ratios of shadow prices in the form of isoclines. The isoclines can be used to classify the state of the metabolic network. This methodology gives rise to a "phase plane" analysis of the metabolic genotype-phenotype relation relevant for a range of growth conditions. Phenotype phase planes (PhPPs) were generated for Escherichia coli growth on two carbon sources (acetate and glucose) at all levels of oxygenation, and the resulting optimal metabolic phenotypes were studied. Supplementary information can be downloaded from our website (http://epicurus.che.udel.edu).}, + Author = {Edwards, Jeremy S and Ramakrishna, Ramprasad and Palsson, Bernhard {\O}}, + Date-Added = {2013-07-29 07:43:37 +0000}, + Date-Modified = {2013-07-29 07:43:52 +0000}, + Journal = {Biotechnol Bioeng}, + Journal-Full = {Biotechnology and bioengineering}, + Mesh = {Computational Biology; Data Interpretation, Statistical; Escherichia coli; Genome, Bacterial; Models, Biological; Phenotype}, + Month = {Jan}, + Number = {1}, + Pages = {27--36}, + Pmid = {11745171}, + Pst = {ppublish}, + Title = {Characterizing the metabolic phenotype: a phenotype phase plane analysis}, + Volume = {77}, + Year = {2002}} + +@article{Edwards:2001fk, + Abstract = {A significant goal in the post-genome era is to relate the annotated genome sequence to the physiological functions of a cell. Working from the annotated genome sequence, as well as biochemical and physiological information, it is possible to reconstruct complete metabolic networks. Furthermore, computational methods have been developed to interpret and predict the optimal performance of a metabolic network under a range of growth conditions. We have tested the hypothesis that Escherichia coli uses its metabolism to grow at a maximal rate using the E. coli MG1655 metabolic reconstruction. Based on this hypothesis, we formulated experiments that describe the quantitative relationship between a primary carbon source (acetate or succinate) uptake rate, oxygen uptake rate, and maximal cellular growth rate. We found that the experimental data were consistent with the stated hypothesis, namely that the E. coli metabolic network is optimized to maximize growth under the experimental conditions considered. This study thus demonstrates how the combination of in silico and experimental biology can be used to obtain a quantitative genotype-phenotype relationship for metabolism in bacterial cells.}, + Author = {Edwards, J S and Ibarra, R U and Palsson, B {\O}}, + Date-Added = {2013-07-29 07:42:09 +0000}, + Date-Modified = {2013-07-29 07:42:59 +0000}, + Doi = {10.1038/84379}, + Journal = {Nat Biotechnol}, + Journal-Full = {Nature biotechnology}, + Mesh = {Acetates; Biological Transport; Computer Simulation; Escherichia coli; Genome, Bacterial; Kinetics; Models, Biological; Oxygen Consumption; Succinates}, + Month = {Feb}, + Number = {2}, + Pages = {125--130}, + Pmid = {11175725}, + Pst = {ppublish}, + Title = {In silico predictions of \emph{Escherichia coli} metabolic capabilities are consistent with experimental data}, + Volume = {19}, + Year = {2001}, + Bdsk-Url-1 = {http://dx.doi.org/10.1038/84379}} + +@article{Shlomi:2005fk, + Abstract = {Predicting the metabolic state of an organism after a gene knockout is a challenging task, because the regulatory system governs a series of transient metabolic changes that converge to a steady-state condition. Regulatory on/off minimization (ROOM) is a constraint-based algorithm for predicting the metabolic steady state after gene knockouts. It aims to minimize the number of significant flux changes (hence on/off) with respect to the wild type. ROOM is shown to accurately predict steady-state metabolic fluxes that maintain flux linearity, in agreement with experimental flux measurements, and to correctly identify short alternative pathways used for rerouting metabolic flux in response to gene knockouts. ROOM's growth rate and flux predictions are compared with previously suggested algorithms, minimization of metabolic adjustment, and flux balance analysis (FBA). We find that minimization of metabolic adjustment provides accurate predictions for the initial transient growth rates observed during the early postperturbation state, whereas ROOM and FBA more successfully predict final higher steady-state growth rates. Although FBA explicitly maximizes the growth rate, ROOM does not, and only implicitly favors flux distributions having high growth rates. This indicates that, even though the cell has not evolved to cope with specific mutations, regulatory mechanisms aiming to minimize flux changes after genetic perturbations may indeed work to this effect. Further work is needed to identify metrics that characterize the complete trajectory from the initial to the final metabolic steady states after genetic perturbations.}, + Author = {Shlomi, Tomer and Berkman, Omer and Ruppin, Eytan}, + Date-Added = {2012-10-04 11:55:46 +0000}, + Date-Modified = {2012-10-04 11:56:02 +0000}, + Doi = {10.1073/pnas.0406346102}, + Journal = {Proc Natl Acad Sci U S A}, + Journal-Full = {Proceedings of the National Academy of Sciences of the United States of America}, + Mesh = {Algorithms; Carbon; Energy Metabolism; Escherichia coli; Gene Silencing; Models, Biological; Mutation; Saccharomyces cerevisiae; Signal Transduction}, + Month = {May}, + Number = {21}, + Pages = {7695--7700}, + Pmc = {PMC1140402}, + Pmid = {15897462}, + Pst = {ppublish}, + Title = {Regulatory on/off minimization of metabolic flux changes after genetic perturbations}, + Volume = {102}, + Year = {2005}, + Bdsk-Url-1 = {http://dx.doi.org/10.1073/pnas.0406346102}} + +@article{Mahadevan:2003fk, + Abstract = {Genome-scale constraint-based models of several organisms have now been constructed and are being used for model driven research. A key issue that may arise in the use of such models is the existence of alternate optimal solutions wherein the same maximal objective (e.g., growth rate) can be achieved through different flux distributions. Herein, we investigate the effects that alternate optimal solutions may have on the predicted range of flux values calculated using currently practiced linear (LP) and quadratic programming (QP) methods. An efficient LP-based strategy is described to calculate the range of flux variability that can be present in order to achieve optimal as well as suboptimal objective states. Sample results are provided for growth predictions of E. coli using glucose, acetate, and lactate as carbon substrates. These results demonstrate the extent of flux variability to be highly dependent on environmental conditions and network composition. In addition we examined the impact of alternate optima for growth under gene knockout conditions as calculated using QP-based methods. It was observed that calculations using QP-based methods can show significant variation in growth rate if the flux variability among alternate optima is high. The underlying biological significance and general source of such flux variability is further investigated through the identification of redundancies in the network (equivalent reaction sets) that lead to alternate solutions. Collectively, these results illustrate the variability inherent in metabolic flux distributions and the possible implications of this heterogeneity for constraint-based modeling approaches. These methods also provide an efficient and robust method to calculate the range of flux distributions that can be derived from quantitative fermentation data.}, + Author = {Mahadevan, R and Schilling, C H}, + Date-Added = {2012-03-15 12:54:11 +0000}, + Date-Modified = {2012-03-15 12:54:20 +0000}, + Journal = {Metab Eng}, + Journal-Full = {Metabolic engineering}, + Mesh = {Computer Simulation; Escherichia coli; Escherichia coli Proteins; Gene Expression Regulation; Genomics; Glucose; Lactic Acid; Models, Biological; Proteome; Reproducibility of Results; Sensitivity and Specificity; Signal Transduction; Stochastic Processes}, + Month = {Oct}, + Number = {4}, + Pages = {264--276}, + Pmid = {14642354}, + Pst = {ppublish}, + Title = {The effects of alternate optimal solutions in constraint-based genome-scale metabolic models}, + Volume = {5}, + Year = {2003}} + +@article{Price:2004fk, + Abstract = {Reconstruction of genome-scale metabolic networks is now possible using multiple different data types. Constraint-based modeling is an approach to interrogate capabilities of reconstructed networks by constraining possible cellular behavior through the imposition of physicochemical laws. As a result, a steady-state flux space is defined that contains all possible functional states of the network. Uniform random sampling of the steady-state flux space allows for the unbiased appraisal of its contents. Monte Carlo sampling of the steady-state flux space of the reconstructed human red blood cell metabolic network under simulated physiologic conditions yielded the following key results: 1), probability distributions for the values of individual metabolic fluxes showed a wide variety of shapes that could not have been inferred without computation; 2), pairwise correlation coefficients were calculated between all fluxes, determining the level of independence between the measurement of any two fluxes, and identifying highly correlated reaction sets; and 3), the network-wide effects of the change in one (or a few) variables (i.e., a simulated enzymopathy or fixing a flux range based on measurements) were computed. Mathematical models provide the most compact and informative representation of a hypothesis of how a cell works. Thus, understanding model predictions clearly is vital to driving forward the iterative model-building procedure that is at the heart of systems biology. Taken together, the Monte Carlo sampling procedure provides a broadening of the constraint-based approach by allowing for the unbiased and detailed assessment of the impact of the applied physicochemical constraints on a reconstructed network.}, + Author = {Price, Nathan D and Schellenberger, Jan and Palsson, Bernhard {\O}}, + Date-Added = {2012-03-14 12:58:24 +0000}, + Date-Modified = {2012-03-15 12:55:25 +0000}, + Doi = {10.1529/biophysj.104.043000}, + Journal = {Biophys J}, + Journal-Full = {Biophysical journal}, + Mesh = {Animals; Blood Proteins; Computer Simulation; Erythrocytes; Gene Expression Regulation, Enzymologic; Humans; Metabolism, Inborn Errors; Models, Biological; Models, Statistical; Multienzyme Complexes; Sample Size; Signal Transduction}, + Month = {Oct}, + Number = {4}, + Pages = {2172--2186}, + Pmc = {PMC1304643}, + Pmid = {15454420}, + Pst = {ppublish}, + Title = {Uniform sampling of steady-state flux spaces: means to design experiments and to interpret enzymopathies}, + Volume = {87}, + Year = {2004}, + Bdsk-Url-1 = {http://dx.doi.org/10.1529/biophysj.104.043000}} + +@article{Segre:2002fk, + Abstract = {An important goal of whole-cell computational modeling is to integrate detailed biochemical information with biological intuition to produce testable predictions. Based on the premise that prokaryotes such as Escherichia coli have maximized their growth performance along evolution, flux balance analysis (FBA) predicts metabolic flux distributions at steady state by using linear programming. Corroborating earlier results, we show that recent intracellular flux data for wild-type E. coli JM101 display excellent agreement with FBA predictions. Although the assumption of optimality for a wild-type bacterium is justifiable, the same argument may not be valid for genetically engineered knockouts or other bacterial strains that were not exposed to long-term evolutionary pressure. We address this point by introducing the method of minimization of metabolic adjustment (MOMA), whereby we test the hypothesis that knockout metabolic fluxes undergo a minimal redistribution with respect to the flux configuration of the wild type. MOMA employs quadratic programming to identify a point in flux space, which is closest to the wild-type point, compatibly with the gene deletion constraint. Comparing MOMA and FBA predictions to experimental flux data for E. coli pyruvate kinase mutant PB25, we find that MOMA displays a significantly higher correlation than FBA. Our method is further supported by experimental data for E. coli knockout growth rates. It can therefore be used for predicting the behavior of perturbed metabolic networks, whose growth performance is in general suboptimal. MOMA and its possible future extensions may be useful in understanding the evolutionary optimization of metabolism.}, + Author = {Segr{\`e}, Daniel and others}, + Date-Added = {2012-03-14 10:27:11 +0000}, + Date-Modified = {2012-03-14 10:27:11 +0000}, + Doi = {10.1073/pnas.232349399}, + Journal = {Proc Natl Acad Sci U S A}, + Journal-Full = {Proceedings of the National Academy of Sciences of the United States of America}, + Mesh = {Biomass; Computer Simulation; Escherichia coli; Glycolysis; Metabolism; Models, Biological; Pentose Phosphate Pathway; Predictive Value of Tests}, + Month = {Nov}, + Number = {23}, + Pages = {15112--15117}, + Pmc = {PMC137552}, + Pmid = {12415116}, + Pst = {ppublish}, + Title = {Analysis of optimality in natural and perturbed metabolic networks}, + Volume = {99}, + Year = {2002}, + Bdsk-Url-1 = {http://dx.doi.org/10.1073/pnas.232349399}} + +@article{Edwards:2002kx, + Author = {Edwards, Jeremy S and Covert, Markus and Palsson, Bernhard {\O}}, + Date-Added = {2012-03-14 10:26:04 +0000}, + Date-Modified = {2012-03-14 10:26:04 +0000}, + Journal = {Environ Microbiol}, + Journal-Full = {Environmental microbiology}, + Mesh = {Bacteria; Escherichia coli; Models, Biological}, + Month = {Mar}, + Number = {3}, + Pages = {133--140}, + Pmid = {12000313}, + Pst = {ppublish}, + Title = {Metabolic modelling of microbes: the flux-balance approach}, + Volume = {4}, + Year = {2002}} + +@article{Orth:2010vn, + Author = {Orth, Jeffrey D and Thiele, Ines and Palsson, Bernhard {\O}}, + Date-Added = {2012-03-14 10:26:04 +0000}, + Date-Modified = {2012-03-14 10:26:04 +0000}, + Doi = {10.1038/nbt.1614}, + Journal = {Nat Biotechnol}, + Journal-Full = {Nature biotechnology}, + Mesh = {Biomass; Escherichia coli; Metabolic Networks and Pathways; Models, Biological; Oxygen; Phenotype; Systems Biology}, + Month = {Mar}, + Number = {3}, + Pages = {245--248}, + Pmid = {20212490}, + Pst = {ppublish}, + Title = {What is flux balance analysis?}, + Volume = {28}, + Year = {2010}, + Bdsk-Url-1 = {http://dx.doi.org/10.1038/nbt.1614}} + +@booklet{Orth:2010fk, + Author = {Orth, Jeffrey D and Fleming, Ronan M T and Palsson, Bernhard {\O}}, + Date-Added = {2012-03-13 16:07:46 +0000}, + Date-Modified = {2012-03-13 16:10:39 +0000}, + Howpublished = {EcoSal Chapter 10.2.1}, + Title = {Reconstruction and Use of Microbial Metabolic Networks: the Core \emph{Escherichia coli} Metabolic Model as an Educational Guide}, + Year = {2010}} + +@article{Becker:2007uq, + Abstract = {The manner in which microorganisms utilize their metabolic processes can be predicted using constraint-based analysis of genome-scale metabolic networks. Herein, we present the constraint-based reconstruction and analysis toolbox, a software package running in the Matlab environment, which allows for quantitative prediction of cellular behavior using a constraint-based approach. Specifically, this software allows predictive computations of both steady-state and dynamic optimal growth behavior, the effects of gene deletions, comprehensive robustness analyses, sampling the range of possible cellular metabolic states and the determination of network modules. Functions enabling these calculations are included in the toolbox, allowing a user to input a genome-scale metabolic model distributed in Systems Biology Markup Language format and perform these calculations with just a few lines of code. The results are predictions of cellular behavior that have been verified as accurate in a growing body of research. After software installation, calculation time is minimal, allowing the user to focus on the interpretation of the computational results.}, + Author = {Becker, Scott A and others}, + Date-Added = {2012-03-09 14:26:51 +0000}, + Date-Modified = {2012-03-09 14:26:51 +0000}, + Doi = {10.1038/nprot.2007.99}, + Journal = {Nat Protoc}, + Journal-Full = {Nature protocols}, + Mesh = {Cells; Computational Biology; Computer Simulation; Metabolic Networks and Pathways; Models, Biological; Software; Systems Biology}, + Number = {3}, + Pages = {727--738}, + Pmid = {17406635}, + Pst = {ppublish}, + Title = {Quantitative prediction of cellular metabolism with constraint-based models: the {COBRA Toolbox}}, + Volume = {2}, + Year = {2007}, + Bdsk-Url-1 = {http://dx.doi.org/10.1038/nprot.2007.99}} + +@article{Schellenberger:2010fk, + Abstract = {BACKGROUND: Genome-scale metabolic reconstructions under the Constraint Based Reconstruction and Analysis (COBRA) framework are valuable tools for analyzing the metabolic capabilities of organisms and interpreting experimental data. As the number of such reconstructions and analysis methods increases, there is a greater need for data uniformity and ease of distribution and use. +DESCRIPTION: We describe BiGG, a knowledgebase of Biochemically, Genetically and Genomically structured genome-scale metabolic network reconstructions. BiGG integrates several published genome-scale metabolic networks into one resource with standard nomenclature which allows components to be compared across different organisms. BiGG can be used to browse model content, visualize metabolic pathway maps, and export SBML files of the models for further analysis by external software packages. Users may follow links from BiGG to several external databases to obtain additional information on genes, proteins, reactions, metabolites and citations of interest. +CONCLUSIONS: BiGG addresses a need in the systems biology community to have access to high quality curated metabolic models and reconstructions. It is freely available for academic use at http://bigg.ucsd.edu.}, + Author = {Schellenberger, Jan and Park, Junyoung O and Conrad, Tom M and Palsson, Bernhard {\O}}, + Date-Added = {2012-03-09 14:26:51 +0000}, + Date-Modified = {2012-03-09 14:26:51 +0000}, + Doi = {10.1186/1471-2105-11-213}, + Journal = {BMC Bioinformatics}, + Journal-Full = {BMC bioinformatics}, + Mesh = {Genome; Genomics; Knowledge Bases; Metabolic Networks and Pathways; Software}, + Pages = {213}, + Pmc = {PMC2874806}, + Pmid = {20426874}, + Pst = {epublish}, + Title = {{BiGG}: a Biochemical Genetic and Genomic knowledgebase of large scale metabolic reconstructions}, + Volume = {11}, + Year = {2010}, + Bdsk-Url-1 = {http://dx.doi.org/10.1186/1471-2105-11-213}} + +@article{Schellenberger:2011fk, + Author = {Schellenberger, Jan and Que, Richard and Fleming, Ronan M T and Thiele, Ines and Orth, Jeffrey D and Feist, Adam M and Zielinski, Daniel C and Bordbar, Aarash and Lewis, Nathan E and Rahmanian, Sorena and Kang, Joseph and Hyduke, Daniel R and Palsson, Bernhard {\O}}, + Date-Added = {2012-03-09 14:26:51 +0000}, + Date-Modified = {2012-03-09 14:26:51 +0000}, + Doi = {10.1038/nprot.2011.308}, + Journal = {Nat Protoc}, + Number = {9}, + Pages = {1290--1307}, + Title = {Quantitative prediction of cellular metabolism with constraint-based models: the {COBRA Toolbox} v2.0}, + Volume = {6}, + Year = {2011}, + Bdsk-Url-1 = {http://dx.doi.org/10.1038/nprot.2011.308}} + +@book{Palsson:2006fk, + Author = {Bernhard {\O}. Palsson}, + Date-Added = {2010-08-20 12:58:36 +0200}, + Date-Modified = {2010-08-20 12:58:36 +0200}, + Publisher = {Cambridge University Press}, + Title = {Systems Biology: Properties of Recontructed Networks}, + Year = {2006}} -- GitLab