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

bindCOLS error workaround in runMultiUMAP function #7

Merged
merged 1 commit into from
Sep 28, 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
7 changes: 7 additions & 0 deletions R/runMultiUMAP.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,18 @@ setGeneric("calculateMultiUMAP", function(x, ...) standardGeneric("calculateMult
#' @rdname runMultiUMAP
#' @importFrom utils head
#' @importFrom uwot umap
#' @importFrom DelayedArray DelayedArray
setMethod("calculateMultiUMAP", "ANY", function(x, ..., metric="euclidean") {
if (length(x)==0) {
stop("'x' must contain one or more matrices")
}
mult.metrics <- .compute_multi_modal_metrics(x, metric=metric)

# Work around Bioconductor/DelayedArray#100 for the time being.
if (any(vapply(x, is, class="DelayedArray", TRUE))) {
x <- lapply(x, DelayedArray)
}

combined <- as.matrix(do.call(cbind, x))
umap(combined, metric=mult.metrics, ...)
})
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-multi-umap.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,23 @@ test_that("multi-modal UMAP works as expected", {
output2 <- runMultiUMAP(sce, assays=1, dimreds=1, altexps=1, altexp.assay=1, n_components=10)
expect_identical(output, reducedDim(output2, "MultiUMAP"))
})

test_that("multi-modal UMAP works with mixed DelayedArrays and matrices", {
set.seed(9999)
output1 <- calculateMultiUMAP(things)

set.seed(9999)
output2 <- calculateMultiUMAP(lapply(things, DelayedArray::DelayedArray))
expect_identical(output1, output2)

# Same result for SCEs.
sce <- SingleCellExperiment(list(X=DelayedArray::DelayedArray(t(stuff))),
reducedDims=list(Y=stuff[,1:5]), altExps=list(Z=SummarizedExperiment(t(stuff[,1:20]))))

set.seed(9999)
output3 <- calculateMultiUMAP(things, n_components=10)

set.seed(9999)
output4 <- runMultiUMAP(sce, assays=1, dimreds=1, altexps=1, altexp.assay=1, n_components=10)
expect_identical(output3, reducedDim(output4, "MultiUMAP"))
})