Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/satijalab/seurat-wrappers/llms.txt

Use this file to discover all available pages before exploring further.

fastMNN identifies mutual nearest neighbors (MNNs) between datasets in a shared low-dimensional space and uses them to estimate and remove batch effects. SeuratWrappers provides two functions: RunFastMNN() for Seurat v4 workflows (operating on a list of Seurat objects), and FastMNNIntegration() for Seurat v5 workflows (used via IntegrateLayers()).

Citation

If you use fastMNN in your work, please cite:
Batch effects in single-cell RNA-sequencing data are corrected by matching mutual nearest neighbors Laleh Haghverdi, Aaron T L Lun, Michael D Morgan & John C Marioni Nature Biotechnology, 2018 doi: 10.1038/nbt.4091 Bioconductor: https://bioconductor.org/packages/release/bioc/html/batchelor.html

Installation

# Install batchelor from Bioconductor
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
BiocManager::install("batchelor")

# Install SeuratWrappers
remotes::install_github('satijalab/seurat-wrappers')

Seurat v4: RunFastMNN

RunFastMNN() takes a list of Seurat objects and returns a single merged Seurat object with a corrected MNN embedding.

Workflow

1

Load libraries and data

library(Seurat)
library(SeuratData)
library(SeuratWrappers)

InstallData("pbmcsca")
data("pbmcsca")
2

Normalize and find variable features

pbmcsca <- NormalizeData(pbmcsca)
pbmcsca <- FindVariableFeatures(pbmcsca)
3

Run fastMNN on split objects

Split the merged object by batch variable and pass the list to RunFastMNN(). The function selects integration features, converts to SingleCellExperiment internally, and returns the merged object with an mnn reduction.
pbmcsca <- RunFastMNN(
  object.list = SplitObject(pbmcsca, split.by = "Method")
)
4

Downstream analysis

Use the mnn reduction for UMAP, neighbor graph, and clustering.
pbmcsca <- RunUMAP(pbmcsca, reduction = "mnn", dims = 1:30)
pbmcsca <- FindNeighbors(pbmcsca, reduction = "mnn", dims = 1:30)
pbmcsca <- FindClusters(pbmcsca)
DimPlot(pbmcsca, group.by = c("Method", "ident", "CellType"), ncol = 3)

Examples

Interferon-stimulated and control PBMC

InstallData("ifnb")
data("ifnb")
ifnb <- NormalizeData(ifnb)
ifnb <- FindVariableFeatures(ifnb)
ifnb <- RunFastMNN(object.list = SplitObject(ifnb, split.by = "stim"))
ifnb <- RunUMAP(ifnb, reduction = "mnn", dims = 1:30)
ifnb <- FindNeighbors(ifnb, reduction = "mnn", dims = 1:30)
ifnb <- FindClusters(ifnb)
DimPlot(ifnb, group.by = c("stim", "ident", "seurat_annotations"), ncol = 3)

Eight human pancreatic islet datasets

InstallData("panc8")
data("panc8")
panc8 <- NormalizeData(panc8)
panc8 <- FindVariableFeatures(panc8)
# Subset to compatible protocols
panc8 <- RunFastMNN(
  object.list = SplitObject(panc8, split.by = "replicate")[
    c("celseq", "celseq2", "fluidigmc1", "smartseq2")
  ]
)
panc8 <- RunUMAP(panc8, reduction = "mnn", dims = 1:30)
panc8 <- FindNeighbors(panc8, reduction = "mnn", dims = 1:30)
panc8 <- FindClusters(panc8)
DimPlot(panc8, group.by = c("replicate", "ident", "celltype"), ncol = 3)

Parameters

object.list
list
required
A list of two or more Seurat objects to integrate. Each must have variable features computed.
assay
character
default:"NULL"
Assay to use. Defaults to the default assay of the first object in the list.
features
integer or character vector
default:"2000"
Either a numeric value specifying how many variable features to select across all datasets, or an explicit character vector of feature names to use for batch correction.
reduction.name
character
default:"mnn"
Name under which the corrected MNN embedding is stored in the returned Seurat object.
reduction.key
character
default:"mnn_"
Key prefix for the MNN reduction dimensions.
reconstructed.assay
character
default:"mnn.reconstructed"
Name of the assay containing the low-rank reconstructed expression matrix. Variable features of this assay are set to the integration features.
verbose
logical
default:"TRUE"
Whether to print progress messages during feature selection.

Seurat v5: FastMNNIntegration

FastMNNIntegration() is designed for the Seurat v5 IntegrateLayers() framework. It operates on a merged Seurat object with split layers rather than a list of separate objects.

Workflow

1

Preprocess a merged object with split layers

obj <- SeuratData::LoadData("pbmcsca")
obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method)
obj <- NormalizeData(obj)
obj <- FindVariableFeatures(obj)
obj <- ScaleData(obj)
obj <- RunPCA(obj)
2

Integrate layers with FastMNNIntegration

Pass FastMNNIntegration as the method argument. The corrected reduction is stored under new.reduction.
obj <- IntegrateLayers(
  object = obj,
  method = FastMNNIntegration,
  new.reduction = 'integrated.mnn',
  verbose = FALSE
)
3

Pass additional fastMNN parameters

Any extra arguments are forwarded to batchelor::fastMNN(). For example, to control the number of mutual nearest neighbors:
obj <- IntegrateLayers(
  object = obj,
  method = FastMNNIntegration,
  new.reduction = 'integrated.mnn',
  k = 15,
  verbose = FALSE
)

Parameters

object
Seurat
required
A merged Seurat object with split layers (Seurat v5 format).
groups
data.frame
default:"NULL"
A one-column data frame with grouping information identifying which batch each cell belongs to.
layers
character vector
default:"NULL"
Layer names to integrate. Defaults to all data layers found in the object.
features
integer or character vector
default:"2000"
Number of variable features to select, or an explicit feature list.
new.reduction
character
default:"integrated.mnn"
Name under which the corrected embedding is stored.
reduction.key
character
default:"mnn_"
Key prefix for the MNN reduction dimensions.
reconstructed.assay
character
default:"mnn.reconstructed"
Name of the assay containing the reconstructed expression matrix.
verbose
logical
default:"TRUE"
Whether to print progress messages.
The FastMNNIntegration function has attr(x = FastMNNIntegration, which = 'Seurat.method') <- 'integration' set, which registers it as a valid integration method for IntegrateLayers().

Build docs developers (and LLMs) love