Skip to content

Commit

Permalink
Pass delayed and fill to combineCols() of altExps (#68)
Browse files Browse the repository at this point in the history
This ensures that the treatment of the alternative experiment's assays
is consistent with that of the main experiment.

Identified in LTLA/mumosa#5 (comment)
  • Loading branch information
PeteHaitch authored and LTLA committed Mar 15, 2023
1 parent 467f02c commit 45f87e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: SingleCellExperiment
Version: 1.20.0
Date: 2022-08-29
Version: 1.20.1
Date: 2023-03-15
Title: S4 Classes for Single Cell Data
Authors@R: c(
person("Aaron", "Lun", role=c("aut", "cph"), email="[email protected]"),
Expand Down
2 changes: 1 addition & 1 deletion R/combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ setMethod("combineCols", "SingleCellExperiment", function(x, ..., delayed=TRUE,
}

tryCatch({
new.altexps[[i]] <- SummarizedExperimentByColumn(do.call(combineCols, c(collated, list(use.names=use.names))))
new.altexps[[i]] <- SummarizedExperimentByColumn(do.call(combineCols, c(collated, list(use.names=use.names, delayed=delayed, fill=fill))))
}, error=function(e) {
warning("failed to combine '", i, "' in 'altExps(<", class(ans), ">)':\n ", conditionMessage(e))
})
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/test-sce-combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,35 @@ test_that("cbind handles errors in the internal fields correctly", {
sce4 <- rbind(A=sce, B=sce)
expect_identical(objectVersion(sce4), objectVersion(sce))
})

test_that("combineCols passes on delay when combining altExps", {
sce.combined <- combineCols(sce, sce, use.names=FALSE, delayed=FALSE)
expect_is(assay(altExp(sce.combined)), "matrix")

sce.combined2 <- combineCols(sce, sce, use.names=FALSE, delayed=TRUE)
expect_is(assay(altExp(sce.combined2)), "DelayedMatrix")
})

test_that("combineCols passes on fill when combining altExps", {
sce1 <- sce[1:6, 1:10]
rownames(sce1) <- LETTERS[seq_len(nrow(sce1))]
colnames(sce1) <- letters[seq_len(ncol(sce1))]
altExp(sce1) <- altExp(sce1)[1:6, ]

sce2 <- sce[1:14, 11:20]
rownames(sce2) <- LETTERS[1:14]
colnames(sce2) <- letters[seq_len(ncol(sce2)) + ncol(sce1)]
altExp(sce2) <- altExp(sce2)[4:7, ]

sce.combined1 <- combineCols(sce1, sce2, use.names=TRUE)
expect_true(anyNA(assay(sce.combined1)))

sce.combined2 <- combineCols(sce1, sce2, use.names=TRUE, fill = -1)
expect_true(any(assay(sce.combined2) == -1))

sce.combined3 <- combineCols(sce1, sce2, use.names=TRUE)
expect_true(anyNA(assay(altExp(sce.combined3))))

sce.combined4 <- combineCols(sce1, sce2, use.names=TRUE, fill = -1)
expect_true(any(assay(sce.combined4) == -1))
})

0 comments on commit 45f87e8

Please sign in to comment.