Skip to content

Commit

Permalink
bug fix: use reshape2::melt instead of stats::reshape (#329)
Browse files Browse the repository at this point in the history
stats::reshape would munge values (typically gene names)
  • Loading branch information
LiNk-NY committed May 1, 2024
1 parent 1ebad2f commit 82691c6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -33,7 +33,6 @@ Imports:
IRanges,
methods,
S4Vectors (>= 0.23.19),
stats,
tidyr,
utils
Suggests:
Expand All @@ -43,6 +42,7 @@ Suggests:
maftools (>= 2.7.10),
R.rsp,
RaggedExperiment,
reshape2,
rmarkdown,
survival,
survminer,
Expand Down
25 changes: 9 additions & 16 deletions R/MultiAssayExperiment-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -340,27 +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)
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))
stop("Package 'reshape2' is required for 'longFormat()' conversion")

reshape2::melt(
object, varnames = c("rowname", "colname"), value.name = "value"
)
}

.longFormatElist <- function(object, i) {
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-MultiAssayExperiment-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,20 @@ test_that("renaming helpers work", {
newaffynames
)
})


test_that(".longFormatANY works", {
denv <- new.env(parent = emptyenv())
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))
)
)
})

0 comments on commit 82691c6

Please sign in to comment.