From 9189d8c5caad18d123af7b1eba044afe0f65e2bf Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 29 Apr 2024 16:06:50 -0400 Subject: [PATCH 1/3] updates --- DESCRIPTION | 10 +++---- R/MultiAssayExperiment-helpers.R | 26 ++++++++++++------- .../test-MultiAssayExperiment-helpers.R | 8 ++++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1c77ab1..ae97d39 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,11 +11,11 @@ Authors@R: c( person("Vincent J", "Carey", , , c("aut", "ctb")), person("Levi", "Waldron", , "lwaldron.research@gmail.com", "aut"), person("MultiAssay", "SIG", , "biocmultiassay@googlegroups.com", "ctb")) -Description: MultiAssayExperiment harmonizes data management of multiple - experimental assays performed on an overlapping set of specimens. It - provides a familiar Bioconductor user experience by extending concepts - from SummarizedExperiment, supporting an open-ended mix of standard - data classes for individual assays, and allowing subsetting by genomic +Description: Harmonize data management of multiple experimental assays + performed on an overlapping set of specimens. It provides a familiar + Bioconductor user experience by extending concepts from + SummarizedExperiment, supporting an open-ended mix of standard data + classes for individual assays, and allowing subsetting by genomic ranges or rownames. Facilities are provided for reshaping data into wide and long formats for adaptability to graphing and downstream analysis. diff --git a/R/MultiAssayExperiment-helpers.R b/R/MultiAssayExperiment-helpers.R index 2f50964..f3176aa 100644 --- a/R/MultiAssayExperiment-helpers.R +++ b/R/MultiAssayExperiment-helpers.R @@ -348,19 +348,27 @@ setMethod("mergeReplicates", "ANY", object <- Biobase::exprs(object) if (is(object, "SummarizedExperiment") || is(object, "RaggedExperiment")) object <- assay(object, i = i) - if (is(object, "matrix")) - object <- as.data.frame(object) ## use stats::reshape instead of reshape2::melt if (nullROWS) rownames(object) <- rowNAMES - object <- stats::reshape(object, idvar = "rowname", - ids = rownames(object), times = names(object), - timevar = "colname", varying = list(names(object)), - direction = "long", v.names = "value") - ## Reshape leaves rownames even if new.row.names = NULL - rownames(object) <- NULL - object[, c("rowname", "colname", "value")] + # if (requireNamespace("reshape2", quietly = TRUE)) { + if (FALSE) { + object <- reshape2::melt( + object, varnames = c("rowname", "colname"), value.name = "value" + ) + } else { + if (is.matrix(object)) + object <- as.data.frame(object) + object <- stats::reshape(object, idvar = "rowname", + ids = rownames(object), times = names(object), + timevar = "colname", varying = list(names(object)), + direction = "long", v.names = "value") + ## Reshape leaves rownames even if new.row.names = NULL + rownames(object) <- NULL + object[, c("rowname", "colname", "value")] + } + object } .longFormatElist <- function(object, i) { diff --git a/tests/testthat/test-MultiAssayExperiment-helpers.R b/tests/testthat/test-MultiAssayExperiment-helpers.R index 0749190..3506461 100644 --- a/tests/testthat/test-MultiAssayExperiment-helpers.R +++ b/tests/testthat/test-MultiAssayExperiment-helpers.R @@ -238,3 +238,11 @@ test_that("renaming helpers work", { newaffynames ) }) + + +test_that(".longFormatANY works", { + denv <- new.env(parent = emptyenv()) + data("miniACC", package="MultiAssayExperiment", envir = denv) + miniACC <- denv[["miniACC"]] + +}) From 00627904c58c93754c2b4536c15991b95d92fe9c Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Mon, 29 Apr 2024 22:49:17 -0400 Subject: [PATCH 2/3] update longFormat to use reshape2 --- DESCRIPTION | 1 + R/MultiAssayExperiment-helpers.R | 31 +++++-------------- .../test-MultiAssayExperiment-helpers.R | 9 ++++++ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae97d39..7b0784e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -43,6 +43,7 @@ Suggests: maftools (>= 2.7.10), R.rsp, RaggedExperiment, + reshape2, rmarkdown, survival, survminer, diff --git a/R/MultiAssayExperiment-helpers.R b/R/MultiAssayExperiment-helpers.R index f3176aa..be28e4d 100644 --- a/R/MultiAssayExperiment-helpers.R +++ b/R/MultiAssayExperiment-helpers.R @@ -340,35 +340,20 @@ setMethod("mergeReplicates", "ANY", .longFormatANY <- function(object, i) { rowNAMES <- rownames(object) - nullROWS <- is.null(rowNAMES) - if (nullROWS) - rowNAMES <- as.character(seq_len(nrow(object))) + if (is.null(rowNAMES)) + rowNames <- as.character(seq_len(nrow(object))) if (is(object, "ExpressionSet")) object <- Biobase::exprs(object) if (is(object, "SummarizedExperiment") || is(object, "RaggedExperiment")) object <- assay(object, i = i) - ## use stats::reshape instead of reshape2::melt - if (nullROWS) - rownames(object) <- rowNAMES - # if (requireNamespace("reshape2", quietly = TRUE)) { - if (FALSE) { - object <- reshape2::melt( - object, varnames = c("rowname", "colname"), value.name = "value" - ) - } else { - if (is.matrix(object)) - object <- as.data.frame(object) - object <- stats::reshape(object, idvar = "rowname", - ids = rownames(object), times = names(object), - timevar = "colname", varying = list(names(object)), - direction = "long", v.names = "value") - ## Reshape leaves rownames even if new.row.names = NULL - rownames(object) <- NULL - object[, c("rowname", "colname", "value")] - } - object + if (!requireNamespace("reshape2", quietly = TRUE)) + stop("Package 'reshape2' is required for 'longFormat()' conversion") + + reshape2::melt( + object, varnames = c("rowname", "colname"), value.name = "value" + ) } .longFormatElist <- function(object, i) { diff --git a/tests/testthat/test-MultiAssayExperiment-helpers.R b/tests/testthat/test-MultiAssayExperiment-helpers.R index 3506461..a675440 100644 --- a/tests/testthat/test-MultiAssayExperiment-helpers.R +++ b/tests/testthat/test-MultiAssayExperiment-helpers.R @@ -245,4 +245,13 @@ test_that(".longFormatANY works", { data("miniACC", package="MultiAssayExperiment", envir = denv) miniACC <- denv[["miniACC"]] + expect_silent( + longdf <- longFormat(miniACC) + ) + expect_true( + all( + as.character(longdf[["rowname"]]) %in% + Reduce(union, rownames(miniACC)) + ) + ) }) From 2377b9c4660287afe03e6b648ef0e153ab068bdc Mon Sep 17 00:00:00 2001 From: LiNk-NY Date: Wed, 1 May 2024 17:41:52 -0400 Subject: [PATCH 3/3] remove stats; not used --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7b0784e..6dbd6d8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,7 +33,6 @@ Imports: IRanges, methods, S4Vectors (>= 0.23.19), - stats, tidyr, utils Suggests: