diff --git a/DESCRIPTION b/DESCRIPTION index 7b821e2..0db0896 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: SCPA Title: Single Cell Pathway Analysis -Version: 1.5.4 +Version: 1.6 Authors@R: c(person(given = "Jack", family = "Bibby", email = "jack.bibby@nih.gov", role = c("aut", "cre")), person(given = "Divyansh", family = "Agarwal", role = c("aut"))) diff --git a/NEWS.md b/NEWS.md index eb42b76..143e20c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +## SCPA v1.6 + +#### Major changes + +Updated compatability with Seurat v5 + - Specify Seurat version in `compare_seurat()` and `seurat_extract()` with `seurat_v5 = TRUE` option + ## SCPA v1.5.4 ### Minor changes diff --git a/R/CompareSeurat.R b/R/CompareSeurat.R index 563475c..3dff0c7 100644 --- a/R/CompareSeurat.R +++ b/R/CompareSeurat.R @@ -52,6 +52,7 @@ compare_seurat <- function(seurat_object, downsample = 500, min_genes = 15, max_genes = 500, + seurat_v5 = FALSE, parallel = FALSE, cores = NULL) { @@ -68,7 +69,8 @@ compare_seurat <- function(seurat_object, samples[[i]] <- seurat_extract(seurat_object, assay = assay, meta1 = group1, - value_meta1 = i) + value_meta1 = i, + seurat_v5 = seurat_v5) } } @@ -80,7 +82,8 @@ compare_seurat <- function(seurat_object, meta1 = group1, value_meta1 = i, meta2 = group2, - value_meta2 = group2_population) + value_meta2 = group2_population, + seurat_v5 = seurat_v5) } } diff --git a/R/SeuratExtract.R b/R/SeuratExtract.R index 5734ee8..5f98c2b 100644 --- a/R/SeuratExtract.R +++ b/R/SeuratExtract.R @@ -31,11 +31,20 @@ seurat_extract <- function(seu_obj, value_meta1 = NULL, meta2 = NULL, value_meta2 = NULL, - pseudocount = 0.001) { + pseudocount = 0.001, + seurat_v5 = FALSE) { + + if (seurat_v5 == FALSE) { + message("Expecting Seurat object < version 5. If using v5 object, specify seurat_v5 = T") + } if (is.null(meta1) && is.null(meta2)) { message("No metadata selected. Will convert whole Seurat object to matrix") - seu_obj <- as.matrix(Seurat::GetAssay(seu_obj, assay)@data) + pseudocount + if (seurat_v5 == FALSE) { + seu_obj <- as.matrix(Seurat::GetAssay(seu_obj, assay)@data) + pseudocount + } else { + seu_obj <- as.matrix(SeuratObject::LayerData(seu_obj, assay = assay, layer = "data")) + pseudocount + } message("Extracting data from the ", assay, " assay") return(seu_obj) } @@ -44,7 +53,11 @@ seurat_extract <- function(seu_obj, message(paste0("Extracting cells where ", meta1, " == ", value_meta1)) met_1 <- Seurat::FetchData(object = seu_obj, vars = meta1) seu_obj <- seu_obj[, which(met_1 == value_meta1)] - seu_obj <- as.matrix(Seurat::GetAssay(seu_obj, assay)@data) + pseudocount + if (seurat_v5 == FALSE) { + seu_obj <- as.matrix(Seurat::GetAssay(seu_obj, assay)@data) + pseudocount + } else { + seu_obj <- as.matrix(SeuratObject::LayerData(seu_obj, assay = assay, layer = "data")) + pseudocount + } message("Extracting data from the ", assay, " assay") return(seu_obj) } @@ -55,11 +68,15 @@ seurat_extract <- function(seu_obj, met_1 <- Seurat::FetchData(object = seu_obj, vars = meta1) met_2 <- Seurat::FetchData(object = seu_obj, vars = meta2) seu_obj <- seu_obj[, which(met_1 == value_meta1 & met_2 == value_meta2)] - seu_obj <- as.matrix(Seurat::GetAssay(seu_obj, assay)@data) + pseudocount + if (seurat_v5 == FALSE) { + seu_obj <- as.matrix(Seurat::GetAssay(seu_obj, assay)@data) + pseudocount + } else { + seu_obj <- as.matrix(SeuratObject::LayerData(seu_obj, assay = assay, layer = "data")) + pseudocount + } message("Extracting data from the ", assay, " assay") return(seu_obj) } -} +} diff --git a/README.Rmd b/README.Rmd index 7204ef3..72be3af 100644 --- a/README.Rmd +++ b/README.Rmd @@ -28,6 +28,7 @@ knitr::opts_chunk$set( 1. [Improvements/changes/updates](https://jackbibby1.github.io/SCPA/news/index.html) to SCPA ### Recent updates +- Compatability with Seurat v5 objects to use the layer system in `seurat_extract()` and `compare_seurat()` (v1.6) through specifying `seurat_v5 = TRUE`. Currently default is FALSE, but this will change after a while - Ability to specify [multiple gmt files](https://jackbibby1.github.io/SCPA/articles/using_gene_sets.html#using-a-gmt-file) as your pathway input (v1.5.2) - [Parallel processing](https://jackbibby1.github.io/SCPA/articles/parallel_implementation.html) implemented to speed up analyses (v1.5.0) - Much more efficient usage of memory, so this shouldn't be limiting (v1.3.0) diff --git a/README.md b/README.md index 4ed551e..a8ec693 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ ### Recent updates +- Compatability with Seurat v5 objects to use the layer system in + `seurat_extract()` and `compare_seurat()` (v1.6) - Ability to specify [multiple gmt files](https://jackbibby1.github.io/SCPA/articles/using_gene_sets.html#using-a-gmt-file) as your pathway input (v1.5.2)