Skip to content

Commit

Permalink
Merge pull request #8271 from bnprks/develop
Browse files Browse the repository at this point in the history
Improve BPCells compatibility (JackStraw + RunPCA)
  • Loading branch information
dcollins15 authored Dec 19, 2024
2 parents 727c71a + 91c8dd7 commit ab5374e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Seurat
Version: 5.1.0.9011
Version: 5.1.0.9012
Title: Tools for Single Cell Genomics
Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) <doi:10.1038/nbt.3192>, Macosko E, Basu A, Satija R, et al (2015) <doi:10.1016/j.cell.2015.05.002>, Stuart T, Butler A, et al (2019) <doi:10.1016/j.cell.2019.05.031>, and Hao, Hao, et al (2020) <doi:10.1101/2020.10.12.335331> for more details.
Authors@R: c(
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- Fixed `RunPCA` to avoid converting `BPCells` matrices into dense matrices - significantly reduces the function's memory usage when running on `BPCells` matrices
- Added `features` parameter to `LeverageScore` and `SketchData`
- Updated `SketchData`'s `ncells` parameter to accept integer vector
- Updated `JackStraw` to support `BPCells` matrices
- Updated `RunPCA` to use the `BPCells`-provided SVD solver on `BPCells` matrices

# Seurat 5.1.0 (2024-05-08)

Expand Down
11 changes: 7 additions & 4 deletions R/dimensional_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -865,19 +865,22 @@ RunPCA.default <- function(
}
if (inherits(x = object, what = 'matrix')) {
RowVar.function <- RowVar
svd.function <- irlba
} else if (inherits(x = object, what = 'dgCMatrix')) {
RowVar.function <- RowVarSparse
svd.function <- irlba
} else if (inherits(x = object, what = 'IterableMatrix')) {
RowVar.function <- function(x) {
return(BPCells::matrix_stats(
matrix = x,
row_stats = 'variance'
)$row_stats['variance',])
}
}
svd.function <- function(A, nv, ...) BPCells::svds(A=A, k = nv)
}
if (rev.pca) {
npcs <- min(npcs, ncol(x = object) - 1)
pca.results <- irlba(A = object, nv = npcs, ...)
pca.results <- svd.function(A = object, nv = npcs, ...)
total.variance <- sum(RowVar.function(x = t(x = object)))
sdev <- pca.results$d/sqrt(max(1, nrow(x = object) - 1))
if (weight.by.var) {
Expand All @@ -891,7 +894,7 @@ RunPCA.default <- function(
total.variance <- sum(RowVar.function(x = object))
if (approx) {
npcs <- min(npcs, nrow(x = object) - 1)
pca.results <- irlba(A = t(x = object), nv = npcs, ...)
pca.results <- svd.function(A = t(x = object), nv = npcs, ...)
feature.loadings <- pca.results$v
sdev <- pca.results$d/sqrt(max(1, ncol(object) - 1))
if (weight.by.var) {
Expand Down Expand Up @@ -2335,7 +2338,7 @@ JackRandom <- function(
rand.genes <- sample(x = rownames(x = scaled.data), size = 3)
}
data.mod <- scaled.data
data.mod[rand.genes, ] <- MatrixRowShuffle(x = scaled.data[rand.genes, ])
data.mod[rand.genes, ] <- MatrixRowShuffle(x = as.matrix(scaled.data[rand.genes, ]))
temp.object <- RunPCA(
object = data.mod,
assay = "temp",
Expand Down

0 comments on commit ab5374e

Please sign in to comment.