Skip to content

Commit

Permalink
Warn about gene id conversions,
Browse files Browse the repository at this point in the history
  • Loading branch information
jashapiro committed Dec 9, 2024
1 parent 9ef3821 commit 36296d9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions R/convert-gene-ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ ensembl_to_symbol <- function(
}

if (seurat_compatible) {
if (any(grepl("_", gene_symbols))) {
warning("Replacing underscores ('_') with dashes ('-') in gene symbols for Seurat compatibility.")
}
gene_symbols <- gsub("_", "-", gene_symbols)
}

Expand Down
4 changes: 2 additions & 2 deletions R/make-seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ sce_to_seurat <- function(
# convert and set functions depending on assay version requested
if (seurat_assay_version == "v5") {
create_seurat_assay <- SeuratObject::CreateAssay5Object
sobj[["RNA"]] <- as(sobj[["RNA"]], "Assay5")
suppressWarnings(sobj[["RNA"]] <- as(sobj[["RNA"]], "Assay5"))
} else {
create_seurat_assay <- SeuratObject::CreateAssayObject
sobj[["RNA"]] <- as(sobj[["RNA"]], "Assay")
suppressWarnings(sobj[["RNA"]] <- as(sobj[["RNA"]], "Assay"))
}

# add spliced data if present
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-convert-gene-ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ test_that("gene symbol conversion in seurat compatibility mode works", {
expect_equal(gene_symbols, c("TP53", "MYCN"))

ensembl_ids <- c("ENSG00000285609", "ENSG00000252254", "ENSG00000283274")
gene_symbols <- ensembl_to_symbol(ensembl_ids, unique = FALSE, seurat_compatible = TRUE)
expect_warning( # this includes name changes for compatibility, so a warning is expected
gene_symbols <- ensembl_to_symbol(ensembl_ids, unique = FALSE, seurat_compatible = TRUE)
)
expect_equal(gene_symbols, c("5S-rRNA", "Y-RNA", "5-8S-rRNA"))
})

Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-make-seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ test_that("SCE to Seurat with no id conversion works", {

test_that("SCE to Seurat with id conversion works as expected", {
sce <- readRDS(test_path("data", "scpca_sce.rds"))
seurat_obj <- sce_to_seurat(sce, use_symbols = TRUE, reference = "sce")
expect_warning(
seurat_obj <- sce_to_seurat(sce, use_symbols = TRUE, reference = "sce")
)

new_genes <- suppressMessages(
ensembl_to_symbol(rownames(sce), unique = TRUE, sce = sce)
Expand Down

0 comments on commit 36296d9

Please sign in to comment.