Skip to content

Commit

Permalink
add seurat v5 compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbibby1 committed Feb 12, 2024
1 parent 04aa7d7 commit 27b829a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre")),
person(given = "Divyansh", family = "Agarwal", role = c("aut")))
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions R/CompareSeurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ compare_seurat <- function(seurat_object,
downsample = 500,
min_genes = 15,
max_genes = 500,
seurat_v5 = FALSE,
parallel = FALSE,
cores = NULL) {

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
27 changes: 22 additions & 5 deletions R/SeuratExtract.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
}

}


1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 27b829a

Please sign in to comment.