diff --git a/R/as_Seurat.R b/R/as_Seurat.R index 59e813d0..a23b128a 100644 --- a/R/as_Seurat.R +++ b/R/as_Seurat.R @@ -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." )) } @@ -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 } diff --git a/R/from_Seurat.R b/R/from_Seurat.R index b1d7a8c4..c28b041d 100644 --- a/R/from_Seurat.R +++ b/R/from_Seurat.R @@ -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) diff --git a/R/from_SingleCellExperiment.R b/R/from_SingleCellExperiment.R index 20417fb6..ec018a85 100644 --- a/R/from_SingleCellExperiment.R +++ b/R/from_SingleCellExperiment.R @@ -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", diff --git a/tests/testthat/test-as_Seurat.R b/tests/testthat/test-as_Seurat.R index 96bd4856..56227e3c 100644 --- a/tests/testthat/test-as_Seurat.R +++ b/tests/testthat/test-as_Seurat.R @@ -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() @@ -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)), @@ -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")) ) }) @@ -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)), diff --git a/tests/testthat/test-from_Seurat.R b/tests/testthat/test-from_Seurat.R index ad3e3bf4..73e73a81 100644 --- a/tests/testthat/test-from_Seurat.R +++ b/tests/testthat/test-from_Seurat.R @@ -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)]] @@ -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 + } ) ) }) @@ -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 ) ) })