Parallelize 'scater' functions
Henrik Bengtsson
Source:vignettes/futurize-81-scater.md
futurize-81-scater.Rmd
+
=

The futurize package allows you to easily turn
sequential code into parallel code by piping the sequential code to the
futurize() function. Easy!
Introduction
This vignette demonstrates how to use this approach to parallelize the scater functions.
The scater Bioconductor package provides tools for single-cell RNA-seq data analysis, including dimensionality reduction methods such as PCA, t-SNE, and UMAP, which can be parallelized across cells.
Example: Running PCA in parallel
The runPCA() function performs PCA on a
SingleCellExperiment object:
library(scater)
# Simulate data
set.seed(42)
n_genes <- 200L
n_cells <- 100L
counts <- matrix(
rpois(n_genes * n_cells, lambda = 10),
nrow = n_genes,
ncol = n_cells,
dimnames = list(
paste0("gene", seq_len(n_genes)),
paste0("cell", seq_len(n_cells))
)
)
sce <- SingleCellExperiment::SingleCellExperiment(
assays = list(counts = counts)
)
sce <- scuttle::logNormCounts(sce)
sce <- runPCA(sce)Here runPCA() runs sequentially, but we can easily make
it run in parallel by piping to futurize():
This will distribute the work across the available parallel workers, given that we have set up parallel workers, e.g.
plan(multisession)The built-in multisession backend parallelizes on your
local computer and works on all operating systems. There are other parallel
backends to choose from, including alternatives to parallelize
locally as well as distributed across remote machines, e.g.
plan(future.mirai::mirai_multisession)and
plan(future.batchtools::batchtools_slurm)Supported Functions
The following scater functions are supported by
futurize():