Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: use reshape2::melt instead of stats::reshape #329

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", , "[email protected]", "aut"),
person("MultiAssay", "SIG", , "[email protected]", "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))
)
)
})
Loading