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

faster logmap labels #209

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

faster logmap labels #209

wants to merge 1 commit into from

Conversation

mihem
Copy link

@mihem mihem commented May 27, 2024

Issue initially reported here:
satijalab/seurat#7879

Integration preprocessing took long (~10min in my case with 120 000 cells and 61 layers). Time was nearly completely spent on Seurat:::CreateIntegrationGroup , more specifically on:

    as.data.frame(x = labels(
      object = cmap,
      values = Cells(x = object[[assay]], layer = scale.layer)

Slow computing here was caused by the sapply function in seurat-object

seurat-object/R/logmap.R

Lines 238 to 247 in 58bf437

obs <- sapply(
X = values,
FUN = function(x) {
vals <- colnames(x = object)[which(x = object[x, , drop = TRUE])]
p()
return(vals)
},
simplify = FALSE,
USE.NAMES = TRUE
)

I rewrote this (also thanks to ChatGPT) using logical indexing.
This speeds up computation > 1000x in my use case from 10 min to less than 1 s. So "real" integration steps start nearly instantaneously.

For a reproducible example use:

library(Seurat)
library(SeuratData)
options(future.globals.maxSize = 1e9)

remotes::install_github("mihem/seurat-object@faster_logmap")

InstallData("pbmcsca")
obj <- LoadData("pbmcsca")

obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method)

obj <- NormalizeData(obj)
obj <- FindVariableFeatures(obj)
obj <- ScaleData(obj)

layers <- Layers(object = obj, assay = "RNA", search = "data")
scale.layer <- Layers(object = obj, search = "scale.data")

system.time(
    groups <- Seurat:::CreateIntegrationGroups(obj[["RNA"]], layers = layers, scale.layer = scale.layer)
)

@mihem
Copy link
Author

mihem commented May 28, 2024

@Gesmira or @dcollins15
Would be nice if you could review that,. simple changes but enormous speedup.

@mihem
Copy link
Author

mihem commented Jul 18, 2024

An news here? already some weeks old @Gesmira @igrabski?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant