diff --git a/DESCRIPTION b/DESCRIPTION index bc9378415e2a4755981a70877eb2d2f264014e2c..f31336a01503bc6b8eed349b22ff4400843a53dc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: sybil Type: Package Title: Efficient Constrained Based Modelling in R -Version: 1.3.4 -Date: 2015-04-18 +Version: 2.0.0 +Date: 2016-05-12 Authors@R: c( person(c("C.", "Jonathan"), "Fritzemeier", role = c("cre", "ctb"), email = "clausjonathan.fritzemeier@uni-duesseldorf.de"), person("Gabriel", "Gelius-Dietrich", role = c("aut")), @@ -52,8 +52,8 @@ Collate: generics.R validmodelorg.R validoptsol.R validreactId.R sysBiolAlg_fbaEasyConstraintClass.R sysBiolAlg_fvClass.R sysBiolAlg_lmomaClass.R sysBiolAlg_momaClass.R sysBiolAlg_mtfClass.R sysBiolAlg_mtfEasyConstraintClass.R - sysBiolAlg_roomClass.R sybilLogClass.R -Packaged: 2016-01-27 12:34:14 UTC; jonathan + sysBiolAlg_roomClass.R sybilLogClass.R upgradeModelorg.R +Packaged: 2016-05-12 12:34:14 UTC; jonathan Author: C. Jonathan Fritzemeier [cre, ctb], Gabriel Gelius-Dietrich [aut], Rajen Piernikarczyk [ctb], diff --git a/R/addReact.R b/R/addReact.R index 101842d1dd21afc70518a1f98eaec010bce4a061..c99b64caf4e061719f39edeb9dc112d0bd896fda 100644 --- a/R/addReact.R +++ b/R/addReact.R @@ -53,6 +53,10 @@ addReact <- function(model, if (!is(model, "modelorg")) { stop("needs an object of class modelorg!") } + + if(!.hasSlot(model, "version")){ + validObject(model) + } if (length(met) != length(Scoef)) { stop("arguments 'met' and 'Scoef' must have the same length") @@ -290,13 +294,14 @@ addReact <- function(model, # 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) - } + + # not needed for modelorg version 2.0 +# 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) } diff --git a/R/geneDel.R b/R/geneDel.R index f69dad53e2d81e30d72d10da1367826db1fb6eaf..874bb63b25c45afdb81f3a2b7c7864c53c733967 100644 --- a/R/geneDel.R +++ b/R/geneDel.R @@ -41,6 +41,10 @@ geneDel <- function(model, genes, checkId = FALSE) { stop("needs an object of class modelorg!") } + if(!.hasSlot(model, "version")){ + validObject(model) + } + if (isTRUE(checkId)) { if (is(genes, "character")) { # Check if all genes are there diff --git a/R/generics.R b/R/generics.R index e249177a90f6bd4c028d15b46d8cf90591daf192..3c393a8a8b4959a34676de49fddf99dc658848a8 100644 --- a/R/generics.R +++ b/R/generics.R @@ -126,6 +126,10 @@ setGeneric(name = "checkStat", def = function(opt) { standardGeneric("checkStat") } ) +setGeneric(name = "checkVersion", + def = function(object, ...) { standardGeneric("checkVersion") } +) + setGeneric(name = "chlb", def = function(object) { standardGeneric("chlb") } ) @@ -945,6 +949,13 @@ setGeneric(name = "verblevel<-", def = function(object, value) { standardGeneric("verblevel<-") } ) +setGeneric(name = "version", + def = function(object) { standardGeneric("version") } +) +setGeneric(name = "version<-", + def = function(object, value) { standardGeneric("version<-") } +) + setGeneric(name = "writeProb", def = function(lp, fname, ff = "lp", ...) { standardGeneric("writeProb") } ) diff --git a/R/modelorgClass.R b/R/modelorgClass.R index 9f8702a5f2d758b418d0111498ec3af373625243..8f8343ad72c5e8e56772e43151c96e8615d0ba8a 100644 --- a/R/modelorgClass.R +++ b/R/modelorgClass.R @@ -55,6 +55,7 @@ setClass("modelorg", lowbnd = "numeric", # vector reactions lower bounds uppbnd = "numeric", # vector reactions upper bounds obj_coef = "numeric", # vector objective coefficients + version = "character", # version to be compatible with changes in the class gprRules = "character", genes = "list", gpr = "character", @@ -113,6 +114,7 @@ setMethod(f = "initialize", .Object@S <- Matrix::Matrix(0, 0, 0) .Object@rxnGeneMat <- Matrix::Matrix(0, 0, 0) .Object@subSys <- Matrix::Matrix(0, 0, length(subSys)) + .Object@version <- SYBIL_SETTINGS("MODELORG_VERSION") if (!is.null(subSys)) { colnames(.Object@subSys) <- as.character(subSys) } @@ -548,6 +550,21 @@ setReplaceMethod("subSys", signature(object = "modelorg"), } ) +# reaction sub systems +setMethod("version", signature(object = "modelorg"), + function(object) { + return(object@version) + } +) + +setReplaceMethod("version", signature(object = "modelorg"), + function(object, value) { + object@version <- value + stopifnot(validObject(object)) + return(object) + } +) + #------------------------------------------------------------------------------# # other methods # @@ -1073,11 +1090,22 @@ setMethod("singletonMetabolites", signature(object = "modelorg"), } ) +#------------------------------------------------------------------------------# - - +setMethod("checkVersion", signature(object = "modelorg"), + function(object) { + if(!.hasSlot(object, "version")){ + stop("No version slot found. Please use upgradeModelorg on object") + } + + if(compareVersion(version(object), SYBIL_SETTINGS("MODELORG_VERSION")) == 0){ + return(TRUE) + } + stop(paste0("modelorg has version ", object(version), ", but you need at least version ", version)) + } +) diff --git a/R/parseBoolean.R b/R/parseBoolean.R index 653aecc2e37b9de4f45c91a9fc7737693cdc3eb8..b10a46d4233ab51d2145a2d4db5ae4860a5c39c3 100644 --- a/R/parseBoolean.R +++ b/R/parseBoolean.R @@ -88,7 +88,7 @@ gene_uniq <- unique(genes) newTok <- match(genes, gene_uniq) - newTok <- sapply(newTok, function(x) paste("x(", x, ")", sep = "")) + newTok <- sapply(newTok, function(x) paste("x[", x, "]", sep = "")) # rule <- diff --git a/R/readTSVmod.R b/R/readTSVmod.R index f66c1bda4435b43d10a4b502b9f47db00ae40b81..0bd26047b9f48a5f650c781535aa5bed8c065c2f 100644 --- a/R/readTSVmod.R +++ b/R/readTSVmod.R @@ -949,13 +949,14 @@ readTSVmod <- function(prefix, suffix, if (isTRUE(RruleL[i])) { geneInd <- match(Rgenes[[i]], allGenes) rxnGeneMat[i, geneInd] <- TRUE + + # not needed for version 2.0 modelorgs +# for (j in 1 : length(geneInd)) { +# pat <- paste("x(", j, ")", sep = "") +# repl <- paste("x[", geneInd[j], "]", sep = "") - 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) - } +# Rrules[i] <- gsub(pat, repl, Rrules[i], fixed = TRUE) +# } } } diff --git a/R/rmReact.R b/R/rmReact.R index bacbd822b7be08940bbb53aabcb9df37a80a08bc..6e13204f342e6e07a36bf88107a8fdab6daeb5b7 100644 --- a/R/rmReact.R +++ b/R/rmReact.R @@ -38,30 +38,33 @@ 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(model, "modelorg")) { + stop("needs an object of class modelorg!") + } + + if(!.hasSlot(model, "version")){ + validObject(model) + } + + # 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"))) { diff --git a/R/settings.R b/R/settings.R index da9dc9e2b7cfe67fe69098ad86a0c9014a14c8d3..7cff1f7780be6984028825ea650bbe7f098bda2e 100644 --- a/R/settings.R +++ b/R/settings.R @@ -42,6 +42,9 @@ SYBIL_SETTINGS <- function(parm, value, ...) { } switch(parm, + "MODELORG_VERSION" = { + stop("this value must not be set by the user!") + }, "SOLVER" = { diff --git a/R/upgradeModelorg.R b/R/upgradeModelorg.R new file mode 100644 index 0000000000000000000000000000000000000000..f85fa69ca8ca2724bf63cac4a80ed7a86969b879 --- /dev/null +++ b/R/upgradeModelorg.R @@ -0,0 +1,70 @@ +# upgradeModelorg.R +# FBA and friends with R. +# +# Copyright (C) 2010-2016 Claus Jonathan Fritzemeier, Dpt. for Bioinformatics, +# Institute for Informatics, Heinrich-Heine-University, Duesseldorf, Germany. +# All right reserved. +# Email: clausjonathan.fritzemeier@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: upgradeModelorg +# +# Takes an instance of a old modelorg version and returns one updated to the +# current version. +# + + +upgradeModelorg <- function(object){ + stopifnot(is(object, "modelorg")) + + if(!.hasSlot(object, "version")){ + # object is from a time before versions were introduced. + # just add version slot and run again. + object@version <- "2.0" + + rules <- lapply(gpr(object), sybil:::.parseBoolean) + genes(object) <- sapply(rules, "[[", "gene") + gprRules(object) <- sapply(rules, "[[", "rule") + + #recursively upgrad to latest version. + return(upgradeModelorg(object)) + } + + if(compareVersion(version(object), SYBIL_SETTINGS("MODELORG_VERSION")) == 0){ + stopifnot(validObject(object)) + return(object) + } + + stop("unsupported version of modelorg") +} + + + + + + + + + + + + + + + diff --git a/R/validmodelorg.R b/R/validmodelorg.R index aba3fc6994dd245b0cb5f67f0cf60e6b1fc9a1fb..0be179668724efeca658e9e3f2856d708594229e 100644 --- a/R/validmodelorg.R +++ b/R/validmodelorg.R @@ -38,6 +38,15 @@ return("needs an object of class modelorg!") } + if(compareVersion(version(object), SYBIL_SETTINGS("MODELORG_VERSION")) != 0){ + if(compareVersion(version(object), SYBIL_SETTINGS("MODELORG_VERSION")) == -1){ + return("You are using an old version of the modelorg-Class. Use upgradeModelorg to get a compatible object!") + } + if(compareVersion(version(object), SYBIL_SETTINGS("MODELORG_VERSION")) == 1){ + return("You are using a new version of the modelorg-Class. Plase upgrade your sybil package!") + } + } + if ((length(mod_id(object)) != 1) || (length(mod_name(object)) != 1)) { return("mod_id and mod_name must have a length of 1!") } diff --git a/R/zzz.R b/R/zzz.R index 864d5d0f63c78a07d6a8149ca40ea8f17aa2489c..0dc683d56bcb26be60ced5f674ee03c8236bf822 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -36,6 +36,7 @@ # settings in sybil .SYBILenv$settings <- list( + MODELORG_VERSION = "2.0", SOLVER = "glpkAPI", METHOD = "simplex", TOLERANCE = 1E-6,