diff --git a/DESCRIPTION b/DESCRIPTION index 5c434284fd9ec74697cd5c77a25ccb41db2e7d9e..112c110518cd7fa748330debbb03b4ccb360962e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: sybil Type: Package Title: Efficient Constrained Based Modelling -Version: 2.1.5 -Date: 2019-03-07 +Version: 2.2.0 +Date: 2021-05-31 Authors@R: c( person("Mayo", "Roettger", role = c("cre"), email = "mayo.roettger@hhu.de"), person("Gabriel", "Gelius-Dietrich", role = "aut"), @@ -18,7 +18,7 @@ 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/lehrstuehle-und-arbeitsgruppen/computational-cell-biology/software/sybil.html + https://www.cs.hhu.de/lehrstuehle-und-arbeitsgruppen/computational-cell-biology/software-contributions/sybil Description: This Systems Biology Package (Gelius-Dietrich et. al. (2012) <doi:10.1186/1752-0509-7-125>) implements 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. The package is easily extendable for additional algorithms. Most of the current LP/MILP solvers are supported via additional packages. LazyLoad: yes License: GPL-3 | file LICENSE @@ -56,7 +56,7 @@ Collate: generics.R validmodelorg.R validoptsol.R validreactId.R validreact.R sysBiolAlg_mtfClass.R sysBiolAlg_mtfEasyConstraintClass.R sysBiolAlg_roomClass.R sybilLogClass.R upgradeModelorg.R mergeReact2Modelorg.R -Packaged: 2019-03-07 10:20:00 UTC; mayo +Packaged: 2021-05-31 10:32:00 UTC; mayo Author: Mayo Roettger [cre], Gabriel Gelius-Dietrich [aut], C. Jonathan Fritzemeier [ctb], diff --git a/R/modelorg2ExPA.R b/R/modelorg2ExPA.R index 53f0c6b22709425c6b5180ca9da401ba979293e9..9afaf6892b55592f29e758c6bde7ba5b16ce16c3 100644 --- a/R/modelorg2ExPA.R +++ b/R/modelorg2ExPA.R @@ -37,8 +37,6 @@ modelorg2ExPA <- function(model, filepath = ".", suffix = "expa", tol = SYBIL_SETTINGS("TOLERANCE")) { - - on.exit( closeAllConnections() ) if (!is(model, "modelorg")) { stop("needs an object of class modelorg!") @@ -57,8 +55,9 @@ modelorg2ExPA <- function(model, fh <- try(file(tofile, "wt"), silent = TRUE) if (is(fh, "try-error")) { - warning("cannot write ExPA file!") - fh <- FALSE + stop("cannot write ExPA file ", sQuote(fh)) + } else { + on.exit(close(fh)) } # exclude reactions @@ -171,12 +170,6 @@ modelorg2ExPA <- function(model, } - # ------------------------------------------------------------------------ # - - if (is(fh, "file")) { - close(fh) - } - #--------------------------------------------------------------------------# # end #--------------------------------------------------------------------------# diff --git a/R/modelorg2tsv.R b/R/modelorg2tsv.R index e266531b0ee13367f5e40e55799e73c4705af5fa..cc4e11251b2d42b0cb9eaf8f2f25cb4e9bff5dc4 100644 --- a/R/modelorg2tsv.R +++ b/R/modelorg2tsv.R @@ -36,7 +36,6 @@ modelorg2tsv <- function(model, prefix, suffix, extMetFlag = "b", fpath = SYBIL_SETTINGS("PATH_TO_MODEL"), ...) { - ## on.exit( closeAllConnections() ) if (!is(model, "modelorg")) { stop("needs an object of class modelorg!") diff --git a/R/optObj_clpAPIClass.R b/R/optObj_clpAPIClass.R index be6050b2be0c2578b0740799a996b8c2bac646b0..0561d0f42638756331f12946adeffc8c9532537f 100644 --- a/R/optObj_clpAPIClass.R +++ b/R/optObj_clpAPIClass.R @@ -107,25 +107,45 @@ setMethod("backupProb", signature(lp = "optObj_clpAPI"), setMethod("setSolverParm", signature(lp = "optObj_clpAPI"), function(lp, solverParm) { + # at the moment, only parameters 'numberIterations', 'maximumIterations', + # and 'maximumSeconds' can be set by this function. In clpAPI, + # these are actually set by three individual functions. In order to + # stay similar to e.g. cplexAPI, we also use the setSolverParm method + # for clpAPI in sybil. + out <- NULL + + if ( ! ((is.data.frame(solverParm)) || (is.list(solverParm))) ) { + stop(sQuote(solverParm), " must be list or data.frame") + } - 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") -# } + 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) + numericParm <- sapply(solverParm, is.numeric) + num <- solverParm[numericParm] + if (length(num) != length(solverParm)) { + stop(sQuote(solverParm), " contains non numeric values") + } + + if (length(num) > 0) { + # get parameter names: + numericp <- names(num) + + for (i in seq(along = num)) { + if (numericp[i] == "numberIterations") { + out <- clpAPI::setNumberIterationsCLP(lp@oobj, num[["numberIterations"]]) + } else if (numericp[i] == "maximumIterations") { + out <- clpAPI::setMaximumIterationsCLP(lp@oobj, num[["maximumIterations"]]) + } else if (numericp[i] == "maximumSeconds") { + out <- clpAPI::setMaximumSecondsCLP(lp@oobj, num[["maximumSeconds"]]) + } else { + stop(sQuote("solverParm"), " contains unknown parameter ", sQuote(numericp)) + } + } + } return(out) - } ) @@ -138,9 +158,14 @@ setMethod("getSolverParm", signature(lp = "optObj_clpAPI"), out <- FALSE - wrong_solver_msg(lp, "getSolverParm") - + out <- list( + "hitMaximumIterations" = clpAPI::getHitMaximumIterationsCLP(lp@oobj), + "maximumIterations" = clpAPI::getMaximumIterationsCLP(lp@oobj), + "maximumSeconds" = clpAPI::getMaximumSecondsCLP(lp@oobj) + ) + return(out) + } ) diff --git a/R/optObj_cplexAPIClass.R b/R/optObj_cplexAPIClass.R index 4a0a22ba26fc7ef6104722298ed01feaa5634aae..f596696c921bd8768e6f8f4ac9864a78b533fbe5 100644 --- a/R/optObj_cplexAPIClass.R +++ b/R/optObj_cplexAPIClass.R @@ -124,8 +124,11 @@ setMethod("setSolverParm", signature(lp = "optObj_cplexAPI"), intdbl <- sapply(solverParm, is.integer) strparm <- sapply(solverParm, is.numeric) + # parameters of type integer: int <- solverParm[intdbl] + # parameters of type double: dbl <- solverParm[intdbl == FALSE & strparm == TRUE] + # parameters of type character: char <- solverParm[strparm == FALSE] if (length(int) > 0) { @@ -137,6 +140,7 @@ setMethod("setSolverParm", signature(lp = "optObj_cplexAPI"), } if (length(dbl) > 0) { + # get dblp <- sapply(names(dbl), function(x) eval(parse(text = x))) dblv <- unlist(dbl) for (i in seq(along = dbl)) { diff --git a/R/parseBoolean.R b/R/parseBoolean.R index 4546b26b778bcd49ff2c08ff4d31cb58a54af7bd..09a9658564d4e5ecbd20c3280d6f535df484682f 100644 --- a/R/parseBoolean.R +++ b/R/parseBoolean.R @@ -84,13 +84,17 @@ # number of entries num_genes <- length(genes) - + + + # vector with unique gene numbers like "x[1]", "x[2]", "x[1]", ... + # 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) @@ -98,8 +102,9 @@ #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) { + # replace gene names in rule by their newTok string (which is x[gene_number]): + 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]] @@ -208,6 +213,8 @@ # gene = "bla" # rule = "blubber" + + # return vector with unique gene names and the rule where numbers correspond to unique gene names return(list(gene = gene_uniq, rule = rule)) } diff --git a/R/promptSysBiolAlg.R b/R/promptSysBiolAlg.R index cb4b9f77578acfe1d97fc003acc642bc3ee75194..cbc589800f092e65ff7344e4f89c4d60e6a5a3d8 100644 --- a/R/promptSysBiolAlg.R +++ b/R/promptSysBiolAlg.R @@ -36,8 +36,6 @@ promptSysBiolAlg <- function(algorithm, ...) { stopifnot(is(algorithm, "character")) - - on.exit( closeAllConnections() ) # classname cname <- paste(prefix, algorithm, sep = sep) @@ -52,6 +50,8 @@ promptSysBiolAlg <- function(algorithm, if (is(sbfh, "try-error")) { stop("can not write to file ", sQuote(sbfh)) + } else { + on.exit(close(sbfh)) } #--------------------------------------------------------------------------# @@ -168,10 +168,6 @@ promptSysBiolAlg <- function(algorithm, # end #--------------------------------------------------------------------------# - if ( (is(sbfh, "file")) && (isOpen(sbfh)) ) { - close(sbfh) - } - message("created file ", sQuote(sbfile)) return(invisible(NULL)) diff --git a/inst/CITATION b/inst/CITATION index ca690fab8d65938f6d5b3562cc45eeea79deaf45..ee480b838a180262d5364b99cf980b21a5f2c77b 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -13,7 +13,7 @@ citEntry( year = "2013", number = "1", pages = "125", - url = "http://www.biomedcentral.com/1752-0509/7/125", + url = "https://bmcsystbiol.biomedcentral.com/articles/10.1186/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 index 5c3f25db53dc30de4eebb3e5f0ae6b4908b92ceb..d561fa06bea48c25dcbff9a5d637e77cb2baed6e 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -7,6 +7,24 @@ \newcommand{\CRANpkg}{\href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}} % ---------------------------------------------------------------------------- % +\section{Changes in version 2.2.0 2021-05-31}{ + \itemize{ + \item Changes to functions \code{modelorg2ExPA} and \code{promptSysBiolAlg}, + where \code{closeAllConnections} was called \code{on.exit} of the function. + The two functions now only close the connections that they have opened. + \item It is now possible to use the functions \code{setSolverParm} and + \code{getSolverParm} in combination with package \code{clpAPI} to set the + number of iterations, to set or get the maximum number of iterations or + maximum number of seconds and to check, if the maximum number of iterations + (or time) was hit. See also \code{setSolverParm-methods} and + \code{getSolverParm-methods} in the manual. + \item Updated URLs in DESCRIPTION, inst/CITATION and inst/NEWS.Rd and + corrected keyword definition for CRAN submission. + \ + } +} +% ---------------------------------------------------------------------------- % + \section{Changes in version 2.1.5 2019-03-07}{ \itemize{ \item Minor changes removing invalid URLs for CRAN submission. @@ -43,7 +61,7 @@ \section{Changes in version 2.1.1 2018-07-17}{ \itemize{ \item Package sybilSBML gets rejected on CRAN, but can be downloaded - at \url{http://www.cs.hhu.de/en/research-groups/computational-cell-biology/software.html}. + at \url{https://www.cs.hhu.de/en/research-groups/computational-cell-biology/software.html}. \item Documentation for \code{react-class} and related methods. \ } diff --git a/man/getSolverParm-methods.Rd b/man/getSolverParm-methods.Rd index 1ac106f1c5145f8a060172a4b930ef0f95a1a5e8..7a2ebe4358d5b8a0c7bff7ce70a3753fa1ddfcbb 100644 --- a/man/getSolverParm-methods.Rd +++ b/man/getSolverParm-methods.Rd @@ -30,9 +30,13 @@ \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. + method to use with package \pkg{optObj_clpAPI}. This method calls + functions \code{clpAPI::getHitMaximumIterationsCLP}, + \code{clpAPI::getMaximumIterationsCLP} and \code{clpAPI::getMaximumSecondsCLP} + and returns a list containing \code{hitMaximumIterations}, + \code{maximumIterations} and \code{maximumSeconds} respectively. + \code{hitMaximumIterations} should be TRUE, if maximum number of + iteration (or time) bound was hit. } \item{\code{signature(lp = "optObj_cplexAPI")}}{ method to use with package \pkg{optObj_cplexAPI}. This method writes diff --git a/man/setSolverParm-methods.Rd b/man/setSolverParm-methods.Rd index a2b03d54d4fb501fae99cc8bd58c2ad6d23c4d6f..2c4cdd4ff634028c67adba6c8bc46dd702d16e4a 100644 --- a/man/setSolverParm-methods.Rd +++ b/man/setSolverParm-methods.Rd @@ -34,9 +34,11 @@ \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. + method to use with package \pkg{optObj_clpAPI}. It is possible + to set \code{numberIterations}, \code{maximumIterations} and + \code{maximumSeconds}, which call the respective functions + \code{setNumberIterationsCLP}, \code{setMaximumIterationsCLP} and + \code{setMaximumSecondsCLP} in clpAPI. } \item{\code{signature(lp = "optObj_cplexAPI")}}{ method to use with package \pkg{optObj_cplexAPI}. In order to set diff --git a/man/upgradeModelorg.Rd b/man/upgradeModelorg.Rd index 4109f58983ef1c0699b8bf357994cb372ab6d2e2..1b21640511ed9341963a2803e50e6e0ab219f8cf 100644 --- a/man/upgradeModelorg.Rd +++ b/man/upgradeModelorg.Rd @@ -44,5 +44,6 @@ upgradeModelorg(Ec_core) } -\keyword{upgrade, version} +\keyword{upgrade} +\keyword{version}