Skip to content

Commit

Permalink
Merge branch 'master' into install
Browse files Browse the repository at this point in the history
  • Loading branch information
csangara authored Aug 28, 2024
2 parents c44b091 + 7bda2d8 commit 157b0ce
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
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")
}

})
2 changes: 1 addition & 1 deletion vignettes/seurat_steps.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ DE_table_top_ligands <- lapply(
DE_table_top_ligands <- DE_table_top_ligands %>% reduce(., full_join) %>%
column_to_rownames("gene")
vis_ligand_lfc <- as.matrix(DE_table_top_ligands[rev(best_upstream_ligands), ])
vis_ligand_lfc <- as.matrix(DE_table_top_ligands[rev(best_upstream_ligands), , drop = FALSE])
p_lfc <- make_threecolor_heatmap_ggplot(vis_ligand_lfc,
"Prioritized ligands", "LFC in Sender",
Expand Down
2 changes: 1 addition & 1 deletion vignettes/seurat_steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ DE_table_top_ligands <- lapply(
DE_table_top_ligands <- DE_table_top_ligands %>% reduce(., full_join) %>%
column_to_rownames("gene")

vis_ligand_lfc <- as.matrix(DE_table_top_ligands[rev(best_upstream_ligands), ])
vis_ligand_lfc <- as.matrix(DE_table_top_ligands[rev(best_upstream_ligands), , drop = FALSE])

p_lfc <- make_threecolor_heatmap_ggplot(vis_ligand_lfc,
"Prioritized ligands", "LFC in Sender",
Expand Down

0 comments on commit 157b0ce

Please sign in to comment.