Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update alias_to_symbol_seurat() behavior for v5 objects #299

Merged
merged 1 commit into from
Aug 28, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nichenetr
Type: Package
Title: NicheNet: Modeling Intercellular Communication by Linking Ligands to Target Genes
Version: 2.1.5
Version: 2.1.6
Authors@R: c(person("Robin", "Browaeys", role = c("aut")),
person("Chananchida", "Sang-aram", role = c("aut", "cre"), email = "[email protected]"))
Description: This package allows you the investigate intercellular communication from a computational perspective. More specifically, it allows to investigate how interacting cells influence each other's gene expression. Functionalities of this package (e.g. including predicting extracellular upstream regulators and their affected target genes) build upon a probabilistic model of ligand-target links that was inferred by data-integration.
Expand Down
7 changes: 4 additions & 3 deletions R/supporting_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ convert_alias_to_symbols = function(aliases, organism, verbose = TRUE){
#' @description \code{alias_to_symbol_seurat} Convert aliases to official gene symbols in a Seurat Object. Makes use of `convert_alias_to_symbols`
#' @usage alias_to_symbol_seurat(seurat_obj, organism)
#'
#' @param seurat_obj Seurat object
#' @param seurat_obj Seurat object, v4 or below. For Seurat v5, a warning is thrown and the same object will be returned.
#' @param organism Is Seurat object data from "mouse" or "human"
#'
#' @return Seurat object
Expand All @@ -219,13 +219,14 @@ alias_to_symbol_seurat = function(seurat_obj, organism) {

# Stop if obj_version is seurat v5
if (obj_version >= 5){
stop("This function is not supported for Seurat v5 objects. Consider using `convert_alias_to_symbols` on your original expression matrix and creating a new Seurat object instead.
warning("This function is not supported for Seurat v5 objects, so the same object will be returned. Consider using `convert_alias_to_symbols` on your original expression matrix and creating a new Seurat object instead.
If this is not feasible, consider checking out Seurat.utils::RenameGenesSeurat.")

return(seurat_obj)
}

assays <- Assays(seurat_obj)


convert_newnames <- function(feature_names, organism, verbose = FALSE) {
newnames <- convert_alias_to_symbols(feature_names, organism = organism, verbose = verbose)

Expand Down
2 changes: 1 addition & 1 deletion man/alias_to_symbol_seurat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-prioritization.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("Wrapper function for seurat", {
if (as.numeric(substr(packageVersion("Seurat"), 1, 1)) < 5){
seurat_obj_test = alias_to_symbol_seurat(seurat_obj_test, "mouse")
} else if (grepl("^5", packageVersion("Seurat")) & grepl("^5", seurat_obj_test@version)){
expect_error(alias_to_symbol_seurat(seurat_obj_test, "mouse"))
expect_warning(alias_to_symbol_seurat(seurat_obj_test, "mouse"))
}

lr_network_filtered <- lr_network %>% filter(from %in% rownames(seurat_obj_test), to %in% rownames(seurat_obj_test))
Expand Down Expand Up @@ -138,7 +138,7 @@ test_that("Prioritization scheme works", {
pct <- pcts[i]

if (grepl("^5", packageVersion("Seurat"))){
expect_error(alias_to_symbol_seurat(seurat_obj_test, "mouse"))
expect_warning(alias_to_symbol_seurat(seurat_obj_test, "mouse"))
} else {
seurat_obj_test <- alias_to_symbol_seurat(seurat_obj_test, "mouse")
}
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-symbol_conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ test_that("Seurat alias conversion works", {
seurat_object_lite = readRDS(url("https://zenodo.org/record/3531889/files/seuratObj_test.rds"))

seurat_object_lite2 = seurat_object_lite %>% alias_to_symbol_seurat(organism = "mouse")
testthat::expect_equal(typeof(seurat_object_lite2), "S4")
expect_equal(typeof(seurat_object_lite2), "S4")

seurat_object_lite <- UpdateSeuratObject(seurat_object_lite)

if (grepl("^5", packageVersion("Seurat")) & grepl("^5", seurat_object_lite@version)){
expect_error(alias_to_symbol_seurat(seurat_object_lite, "mouse"))
expect_warning(alias_to_symbol_seurat(seurat_object_lite, "mouse"))
same_seurat_obj <- suppressWarnings(alias_to_symbol_seurat(seurat_object_lite, "mouse"))
expect_true(all(rownames(seurat_object_lite) == rownames(same_seurat_obj)))
} else {
seurat_object_lite2 = seurat_object_lite %>% alias_to_symbol_seurat(organism = "mouse")
testthat::expect_equal(typeof(seurat_object_lite2), "S4")
expect_equal(typeof(seurat_object_lite2), "S4")
}

})
Loading