# Parallelize 'scater' functions

+ =

The futurize package allows you to easily turn sequential code into parallel code by piping the sequential code to the `futurize()` function. Easy!

# TL;DR

    library(futurize)
    plan(multisession)
    library(scater)

    sce <- scuttle::logNormCounts(sce)
    sce <- runPCA(sce) |> futurize()
    sce <- runUMAP(sce) |> futurize()

# 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
    sce <- scuttle::mockSCE()
    sce <- scuttle::logNormCounts(sce)

    sce <- runPCA(sce)

Here `runPCA()` runs sequentially, but we can easily make it run in parallel by piping to `futurize()`:

    library(futurize)

    sce <- runPCA(sce) |> 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()`:

- `calculatePCA()`
- `calculateTSNE()`
- `calculateUMAP()`
- `runPCA()`
- `runTSNE()`
- `runUMAP()`
- `runColDataPCA()`
- `nexprs()`
- `getVarianceExplained()`
- `plotRLE()`