From 5cec6a846f4791ada2199bc0945337988ce19205 Mon Sep 17 00:00:00 2001 From: Charlotte Soneson Date: Tue, 27 Jan 2026 17:38:53 +0100 Subject: [PATCH 1/3] Bump version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cc6fd2a..13c9afb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: monaLisa Type: Package Title: Binned Motif Enrichment Analysis and Visualization -Version: 1.17.0 +Version: 1.17.1 Authors@R: c( person("Dania", "Machlab", email = "dania.machlab@gmail.com", role = c("aut"), comment = c(ORCID = "0000-0002-2578-6930")), @@ -61,7 +61,7 @@ Suggests: TxDb.Mmusculus.UCSC.mm10.knownGene License: GPL (>= 3) Encoding: UTF-8 -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 VignetteBuilder: knitr biocViews: MotifAnnotation, From 16e9b9be5f3cd198a67daef0af1ddf2e95d3ef03 Mon Sep 17 00:00:00 2001 From: Charlotte Soneson Date: Tue, 27 Jan 2026 17:54:15 +0100 Subject: [PATCH 2/3] Restrict glmnet usage to gaussian and binomial cases (univariate output) --- NAMESPACE | 2 +- R/stability_selection.R | 19 +++++++++++++------ man/randLassoStabSel.Rd | 7 +++++-- tests/testthat/test_stability_selection.R | 10 ++++++++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 9461372..705b6e7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -120,7 +120,6 @@ importFrom(ggplot2,theme) importFrom(ggplot2,theme_classic) importFrom(ggplot2,ylim) importFrom(glmnet,glmnet) -importFrom(glmnet,predict.glmnet) importFrom(grDevices,col2rgb) importFrom(grDevices,colorRampPalette) importFrom(grid,gpar) @@ -150,6 +149,7 @@ importFrom(stats,model.matrix) importFrom(stats,p.adjust) importFrom(stats,pbinom) importFrom(stats,ppois) +importFrom(stats,predict) importFrom(stats,quantile) importFrom(stats,reorder) importFrom(stats,runif) diff --git a/R/stability_selection.R b/R/stability_selection.R index b53ec13..05f4385 100644 --- a/R/stability_selection.R +++ b/R/stability_selection.R @@ -41,8 +41,8 @@ #' #' @seealso \code{\link[stabs]{glmnet.lasso}} and \code{\link[glmnet]{glmnet}} #' -#' @importFrom glmnet glmnet predict.glmnet -#' @importFrom stats model.matrix runif +#' @importFrom glmnet glmnet +#' @importFrom stats model.matrix runif predict #' @importFrom cli cli_abort cli_inform #' #' @keywords internal @@ -71,7 +71,7 @@ x, y, dfmax = q - 1, penalty.factor = 1/stats::runif(ncol(x), weakness, 1), ...) - selected <- glmnet::predict.glmnet(fit, type = "nonzero") + selected <- predict(fit, type = "nonzero") selected <- selected[[length(selected)]] ret <- logical(ncol(x)) ret[selected] <- TRUE @@ -92,7 +92,9 @@ #' package, but implements the randomized lasso version. #' #' @param x The predictor matrix. -#' @param y The response vector. +#' @param y The response vector. This should be a numeric vector (also for +#' the binomial case - in this case it will be converted to a factor +#' internally by \code{glmnet}). #' @param weakness Value between 0 and 1 (default = 0.8). #' It affects how strict the method will be in selecting predictors. The #' closer it is to 0, the more stringent the selection. A weakness value @@ -105,7 +107,8 @@ #' \code{cutoff} and \code{PFER}). #' The available arguments to \code{.glmnetRandomizedLasso} are the same as #' the ones for \code{\link[stabs]{glmnet.lasso}}. A typical use case would -#' be to define the \code{family} argument to \code{\link[glmnet]{glmnet}}. +#' be to define the \code{family} argument to \code{\link[glmnet]{glmnet}} +#' (currently "gaussian" and "binomial" are supported). #' @param cutoff Value between 0 and 1 (default = 0.8) which is the cutoff #' for the selection probability. Any variable with a selection probability #' that is higher than the set cutoff will be selected. @@ -238,7 +241,7 @@ randLassoStabSel <- function(x, y, weakness=0.8, cutoff=0.8, PFER=2, if (!is(x, "matrix")) { cli_abort("{.arg x} must be a {.cls matrix}") } - .assertVector(y, type = "numeric") + .assertVector(x = y, type = "numeric") if (nrow(x) != length(y)) { cli_abort(paste0( "nrow of {.arg x} and length of {.arg y} are not equal. The rows of ", @@ -268,6 +271,10 @@ randLassoStabSel <- function(x, y, weakness=0.8, cutoff=0.8, PFER=2, paste(names(glmnet.args)[i], collapse = ","))) glmnet.args <- glmnet.args[!i] } + if ("family" %in% names(glmnet.args) && + !glmnet.args$family %in% c("binomial", "gaussian")) { + cli_abort("currently only binomial and gaussian families are supported") + } } # run randomized lasso stability selection diff --git a/man/randLassoStabSel.Rd b/man/randLassoStabSel.Rd index d18e95f..7144c9f 100644 --- a/man/randLassoStabSel.Rd +++ b/man/randLassoStabSel.Rd @@ -18,7 +18,9 @@ randLassoStabSel( \arguments{ \item{x}{The predictor matrix.} -\item{y}{The response vector.} +\item{y}{The response vector. This should be a numeric vector (also for +the binomial case - in this case it will be converted to a factor +internally by \code{glmnet}).} \item{weakness}{Value between 0 and 1 (default = 0.8). It affects how strict the method will be in selecting predictors. The @@ -45,7 +47,8 @@ use in \code{\link[parallel]{mclapply}}, which is the default way \code{cutoff} and \code{PFER}). The available arguments to \code{.glmnetRandomizedLasso} are the same as the ones for \code{\link[stabs]{glmnet.lasso}}. A typical use case would -be to define the \code{family} argument to \code{\link[glmnet]{glmnet}}.} +be to define the \code{family} argument to \code{\link[glmnet]{glmnet}} +(currently "gaussian" and "binomial" are supported).} \item{...}{Additional parameters that can be passed on to \code{\link[stabs]{stabsel}}.} diff --git a/tests/testthat/test_stability_selection.R b/tests/testthat/test_stability_selection.R index 7135a39..fcaf51d 100644 --- a/tests/testthat/test_stability_selection.R +++ b/tests/testthat/test_stability_selection.R @@ -5,11 +5,11 @@ test_that("randLassoStabSel() works properly", { Y <- rnorm(n = 500, mean = 2, sd = 1) X <- matrix(data = NA, nrow = length(Y), ncol = 50) for (i in seq_len(ncol(X))) { - X[ ,i] <- runif(n = 500, min = 0, max = 3) + X[, i] <- runif(n = 500, min = 0, max = 3) } s_cols <- sample(x = seq_len(ncol(X)), size = 10, replace = FALSE) for (i in seq_along(s_cols)) { - X[ ,s_cols[i]] <- X[ ,s_cols[i]] + Y + X[, s_cols[i]] <- X[, s_cols[i]] + Y } X2 <- X @@ -61,6 +61,12 @@ test_that("randLassoStabSel() works properly", { x = 3, weakness = 0.1)) }, "Ignoring the following elements") expect_identical(ssbnf, ssbnf2) + + expect_error(randLassoStabSel(x = X, y = factor(Y > 2)), + ".y. must be of class .numeric.") + expect_error(randLassoStabSel(x = X, y = as.numeric(Y > 2), + glmnet.args = list(family = "multinomial")), + "currently only binomial and gaussian") }) test_that("randLassoStabSel() is deterministic", { From dcedeeb904f2b418f1040ab9919b1b10025dea77 Mon Sep 17 00:00:00 2001 From: Charlotte Soneson Date: Tue, 27 Jan 2026 19:02:27 +0100 Subject: [PATCH 3/3] Update NEWS --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 5989bf4..ef8cd05 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# monaLisa 1.17.1 + +* clarifications of supported families for the stability selection + # monaLisa 1.15.3 * minor updates to adjust to breaking changes in `ggplot2` version 4