Skip to content

Commit

Permalink
Add Seurat v5 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jashapiro committed Dec 9, 2024
1 parent 36296d9 commit 80f0703
Showing 1 changed file with 80 additions and 12 deletions.
92 changes: 80 additions & 12 deletions tests/testthat/test-make-seurat.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
test_that("SCE to Seurat with no id conversion works", {
sce <- readRDS(test_path("data", "scpca_sce.rds"))
seurat_obj <- sce_to_seurat(sce, use_symbols = FALSE)
expect_s4_class(seurat_obj, "Seurat")

expect_equal(dim(seurat_obj), dim(sce))
expect_setequal(rownames(seurat_obj), rownames(sce))
Expand All @@ -9,7 +10,11 @@ test_that("SCE to Seurat with no id conversion works", {
expect_equal(names(seurat_obj@assays), c("RNA", "spliced"))
expect_equal(Seurat::DefaultAssay(seurat_obj), "RNA")

# array contents
# assay types
expect_s4_class(seurat_obj[["RNA"]], "Assay")
expect_s4_class(seurat_obj[["spliced"]], "Assay")

# assay contents
expect_contains(
slotNames(seurat_obj[["RNA"]]),
c("counts", "data", "scale.data", "var.features", "meta.features")
Expand All @@ -18,9 +23,10 @@ test_that("SCE to Seurat with no id conversion works", {
expect_equal(seurat_obj[["RNA"]]$counts, counts(sce))
expect_equal(seurat_obj[["RNA"]]$data, logcounts(sce))

expect_setequal(
seurat_obj[["RNA"]]@var.features,
metadata(sce)$highly_variable_genes
expect_equal(
Seurat::VariableFeatures(seurat_obj[["RNA"]]),
metadata(sce)$highly_variable_genes,
ignore_attr = TRUE
)

expect_equal(names(seurat_obj@reductions), c("pca", "umap"))
Expand All @@ -40,6 +46,7 @@ test_that("SCE to Seurat with id conversion works as expected", {
expect_warning(
seurat_obj <- sce_to_seurat(sce, use_symbols = TRUE, reference = "sce")
)
expect_s4_class(seurat_obj, "Seurat")

new_genes <- suppressMessages(
ensembl_to_symbol(rownames(sce), unique = TRUE, sce = sce)
Expand All @@ -58,15 +65,20 @@ test_that("SCE to Seurat with id conversion works as expected", {
expect_equal(names(seurat_obj@assays), c("RNA", "spliced"))
expect_equal(Seurat::DefaultAssay(seurat_obj), "RNA")

# array contents
# assay types
expect_s4_class(seurat_obj[["RNA"]], "Assay")
expect_s4_class(seurat_obj[["spliced"]], "Assay")

# assay contents
expect_contains(
slotNames(seurat_obj[["RNA"]]),
c("counts", "data", "scale.data", "var.features", "meta.features")
)

expect_setequal(
seurat_obj[["RNA"]]@var.features,
hv_genes
expect_equal(
Seurat::VariableFeatures(seurat_obj[["RNA"]]),
hv_genes,
ignore_attr = TRUE
)
expect_equal(names(seurat_obj@reductions), c("pca", "umap"))
expect_equal(names(seurat_obj@reductions), c("pca", "umap"))
Expand All @@ -83,6 +95,7 @@ test_that("SCE to Seurat with id conversion works as expected", {
test_that("SCE to Seurat with id conversion and 10x reference works as expected", {
sce <- readRDS(test_path("data", "scpca_sce.rds"))
seurat_obj <- sce_to_seurat(sce, use_symbols = TRUE, reference = "10x2020")
expect_s4_class(seurat_obj, "Seurat")

new_genes <- suppressMessages(
ensembl_to_symbol(rownames(sce), unique = TRUE, reference = "10x2020")
Expand All @@ -101,15 +114,21 @@ test_that("SCE to Seurat with id conversion and 10x reference works as expected"
expect_equal(names(seurat_obj@assays), c("RNA", "spliced"))
expect_equal(Seurat::DefaultAssay(seurat_obj), "RNA")

# array contents

# assay types
expect_s4_class(seurat_obj[["RNA"]], "Assay")
expect_s4_class(seurat_obj[["spliced"]], "Assay")

# assay contents
expect_contains(
slotNames(seurat_obj[["RNA"]]),
c("counts", "data", "scale.data", "var.features", "meta.features")
)

expect_setequal(
seurat_obj[["RNA"]]@var.features,
hv_genes
expect_equal(
Seurat::VariableFeatures(seurat_obj[["RNA"]]),
hv_genes,
ignore_attr = TRUE
)
expect_equal(names(seurat_obj@reductions), c("pca", "umap"))
expect_equal(names(seurat_obj@reductions), c("pca", "umap"))
Expand All @@ -132,11 +151,60 @@ test_that("conversion works with altExps", {
)

seurat_obj <- sce_to_seurat(sce, use_symbols = FALSE)
expect_s4_class(seurat_obj, "Seurat")

expect_equal(dim(seurat_obj), dim(sce))
expect_setequal(rownames(seurat_obj), rownames(sce))
expect_setequal(colnames(seurat_obj), colnames(sce))

expect_setequal(names(seurat_obj@assays), c("RNA", "spliced", "alt1", "alt2"))
expect_equal(Seurat::DefaultAssay(seurat_obj), "RNA")

# assay types
expect_s4_class(seurat_obj[["RNA"]], "Assay")
expect_s4_class(seurat_obj[["spliced"]], "Assay")
expect_s4_class(seurat_obj[["alt1"]], "Assay")
expect_s4_class(seurat_obj[["alt2"]], "Assay")
})

test_that("Seurat v5 conversion works", {
sce <- readRDS(test_path("data", "scpca_sce.rds"))
seurat_obj <- sce_to_seurat(sce, use_symbols = FALSE, seurat_assay_version = "v5")
expect_s4_class(seurat_obj, "Seurat")

expect_equal(dim(seurat_obj), dim(sce))
expect_setequal(rownames(seurat_obj), rownames(sce))
expect_setequal(colnames(seurat_obj), colnames(sce))

expect_equal(names(seurat_obj@assays), c("RNA", "spliced"))
expect_equal(Seurat::DefaultAssay(seurat_obj), "RNA")

# assay types
expect_s4_class(seurat_obj[["RNA"]], "Assay5")
expect_s4_class(seurat_obj[["spliced"]], "Assay5")

# expected layers present
expect_contains(
names(seurat_obj[["RNA"]]@layers),
c("counts", "data", "scale.data")
)

expect_equal(seurat_obj[["RNA"]]$counts, counts(sce))
expect_equal(seurat_obj[["RNA"]]$data, logcounts(sce))

expect_equal(
Seurat::VariableFeatures(seurat_obj[["RNA"]]),
metadata(sce)$highly_variable_genes,
ignore_attr = TRUE
)

expect_equal(names(seurat_obj@reductions), c("pca", "umap"))
expect_equal(
dim(seurat_obj[["pca"]]),
dim(reducedDim(sce, "PCA"))
)
expect_equal(
dim(seurat_obj[["umap"]]),
dim(reducedDim(sce, "UMAP"))
)
})

0 comments on commit 80f0703

Please sign in to comment.