Skip to content
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
5 changes: 3 additions & 2 deletions R/as_Seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ as_Seurat <- function(
!"counts" %in% names(layers_mapping) &&
!"data" %in% names(layers_mapping)
) {
cli_warn(c(
cli_warn(paste(
"No {.val counts} or {.val data} layer found in {.arg names(layers_mapping)},",
"this may lead to unexpected results when using the resulting Seurat object."
"this may lead to unexpected results when using the resulting {.cls Seurat} object."
))
}

Expand All @@ -381,6 +381,7 @@ as_Seurat <- function(
# and remove the counts layer
if (!"counts" %in% names(layers_mapping)) {
SeuratObject::LayerData(obj, layer = dummy_counts) <- counts
SeuratObject::DefaultLayer(obj[[assay_name]]) <- dummy_counts
obj[[assay_name]]$counts <- NULL
}

Expand Down
6 changes: 0 additions & 6 deletions R/from_Seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ from_Seurat <- function(
output_class = c("InMemory", "HDF5AnnData"),
...
) {
lifecycle::deprecate_soft(
when = "0.99.0",
what = "from_Seurat()",
with = "as_AnnData()"
)

check_requires("Converting Seurat to AnnData", c("SeuratObject", "Seurat"))

output_class <- match.arg(output_class)
Expand Down
6 changes: 0 additions & 6 deletions R/from_SingleCellExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ from_SingleCellExperiment <- function(
output_class = c("InMemory", "HDF5AnnData"),
...
) {
lifecycle::deprecate_soft(
when = "0.99.0",
what = "from_SingleCellExperiment()",
with = "as_AnnData()"
)

check_requires(
"Converting SingleCellExperiment to AnnData",
"SingleCellExperiment",
Expand Down
14 changes: 8 additions & 6 deletions tests/testthat/test-as_Seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ known_issues <- read_known_issues()
ad <- generate_dataset(n_obs = 10L, n_vars = 20L, format = "AnnData")
ad$obsm[["X_pca"]] <- matrix(1:50, 10, 5)
ad$varm[["PCs"]] <- matrix(1:100, 20, 5)
ad$layers["counts"] <- ad$layers["numeric_csparse"]

# Remove column names to avoid warnings
for (name in c("integer", "numeric", "integer_with_nas", "numeric_with_nas")) {
colnames(ad$obsm[[name]]) <- NULL
}

seu <- ad$as_Seurat()

Expand Down Expand Up @@ -137,7 +143,6 @@ test_that("as_Seurat retains pca dimred", {
test_that("as_Seurat works with list mappings", {
expect_no_error(
ad$as_Seurat(
x_mapping = "counts",
object_metadata_mapping = as.list(.as_Seurat_guess_object_metadata(ad)),
layers_mapping = as.list(.as_Seurat_guess_layers(ad)),
assay_metadata_mapping = as.list(.as_Seurat_guess_assay_metadata(ad)),
Expand All @@ -156,10 +161,7 @@ test_that("as_Seurat works with list mappings", {

test_that("as_Seurat works with a vector reduction_mapping", {
expect_no_error(
ad$as_Seurat(
x_mapping = "counts",
reduction_mapping = c(numeric = "numeric_matrix")
)
ad$as_Seurat(reduction_mapping = c(numeric = "numeric_matrix"))
)
})

Expand All @@ -169,7 +171,7 @@ test_that("as_Seurat works with unnamed mappings", {
object_metadata_mapping = unname(.as_Seurat_guess_object_metadata(ad)),
layers_mapping = c(
na.omit(unname(.as_Seurat_guess_layers(ad))),
counts = NA
data = NA
),
assay_metadata_mapping = unname(.as_Seurat_guess_assay_metadata(ad)),
graph_mapping = unname(.as_Seurat_guess_graphs(ad)),
Expand Down
36 changes: 22 additions & 14 deletions tests/testthat/test-from_Seurat.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
skip_if_not_installed("Seurat")
library(Seurat)

`%||%` <- rlang::`%||%`

known_issues <- read_known_issues()

suppressWarnings({
counts <- matrix(rbinom(20000, 1000, .001), nrow = 100)
obj <- CreateSeuratObject(counts = counts)
obj <- NormalizeData(obj)
obj <- FindVariableFeatures(obj)
obj <- ScaleData(obj)
obj <- RunPCA(obj, npcs = 10L)
obj <- FindNeighbors(obj)
obj <- RunUMAP(obj, dims = 1:10)
})
counts <- matrix(rbinom(20000, 1000, .001), nrow = 100)
obj <- CreateSeuratObject(counts = as(counts, "CsparseMatrix"))
obj <- NormalizeData(obj, verbose = FALSE)
obj <- FindVariableFeatures(obj, verbose = FALSE)
obj <- ScaleData(obj, verbose = FALSE)
obj <- RunPCA(obj, npcs = 10L, verbose = FALSE)
obj <- FindNeighbors(obj, verbose = FALSE)
obj <- RunUMAP(obj, dims = 1:10, verbose = FALSE)

active_assay <- obj[[DefaultAssay(obj)]]

Expand Down Expand Up @@ -199,8 +199,16 @@ test_that("as_AnnData (Seurat) works with list mappings", {
obsm_mapping = as.list(.from_Seurat_guess_obsms(obj, active_assay)),
varm_mapping = as.list(.from_Seurat_guess_varms(obj, active_assay)),
obsp_mapping = as.list(.from_Seurat_guess_obsps(obj, active_assay)),
varp_mapping = as.list(.from_Seurat_guess_varps(obj)),
uns_mapping = as.list(.from_Seurat_guess_uns(obj))
varp_mapping = if (length(as.list(.from_Seurat_guess_varps(obj))) > 0) {
as.list(.from_Seurat_guess_varps(obj))
} else {
FALSE
},
uns_mapping = if (length(as.list(.from_Seurat_guess_uns(obj))) > 0) {
as.list(.from_Seurat_guess_uns(obj))
} else {
FALSE
}
)
)
})
Expand All @@ -216,8 +224,8 @@ test_that("as_AnnData (Seurat) works with unnamed mappings", {
obsm_mapping = unname(.from_Seurat_guess_obsms(obj, active_assay)),
varm_mapping = unname(.from_Seurat_guess_varms(obj, active_assay)),
obsp_mapping = unname(.from_Seurat_guess_obsps(obj, active_assay)),
varp_mapping = unname(.from_Seurat_guess_varps(obj)),
uns_mapping = unname(.from_Seurat_guess_uns(obj))
varp_mapping = unname(.from_Seurat_guess_varps(obj)) %||% FALSE,
uns_mapping = unname(.from_Seurat_guess_uns(obj)) %||% FALSE
)
)
})
Expand Down
Loading