knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This package aims at making seurat
objects (r CRANpkg("Seurat")
package)
accessible for downstream
processing using common Bioconductor methods and classes.
In particular, the most readily equivalent Bioconductor class apt
to store the various components of a seurat
object is the
SingleCellExperiment
class (r Biocpkg("SingleCellExperiment")
package).
Indeed, the SingleCellExperiment
class contains slots to store:
any number of assays, that encompasses the @raw.data
, @data
, and
@scaled.data
slots of a seurat
object.
sample meta-data, that corresponds to the @meta.data
slot of a seurat
object.
feature meta-data, that encompasses the presence of individual genes in the
@var.genes
slot of a seurat
object
any number of reduced dimensions sets of coordinates, that are usually
stored under the @dr
slot of a seurat
object
The r Githubpkg("kevinrue/BioSeurat")
package is currently hosted
on GitHub, and may be installed as follows:
devtools::install_github("kevinrue/BioSeurat", build_vignettes = TRUE)
Let us load the various packages required for this vignette;:
stopifnot( require(Seurat), require(SingleCellExperiment), require(BioSeurat) )
Let us load both r CRANpkg("Seurat")
and r Biocpkg("SingleCellExperiment")
to set up the workspace
seurat
objectLet us use the demonstration object of the r CRANpkg("Seurat")
package:
pbmc_raw <- read.table( file = system.file('extdata', 'pbmc_raw.txt', package = 'Seurat'), as.is = TRUE ) pbmc_small <- CreateSeuratObject(raw.data = pbmc_raw) pbmc_small
This minimal seurat
object can be converted to a SingleCellExperiment
as follows:
pbmc_sce <- as(pbmc_small, "SingleCellExperiment") pbmc_sce
seurat
objectThe NormalizeData
function merely updates the @data
slot of seurat
objects (while also storing the associated parameters in
the @calc.params
slot):
pbmc_small <- NormalizeData(object = pbmc_small) names(pbmc_small@calc.params)
As a consequence, this seurat
object can be converted to a
SingleCellExperiment
without additional difficulty:
pbmc_sce <- as(pbmc_small, "SingleCellExperiment") pbmc_sce
Note: the normalisation parameters stored in the @calc.params
slot
are not transferred to the SingleCellExperiment
object.
seurat
objectThe ScaleData
function populates the @scale.data
slot of seurat
objects (while also storing the associated parameters in
the @calc.params
slot):
pbmc_small <- ScaleData( object = pbmc_small, vars.to.regress = c("nUMI"), display.progress = FALSE) dim(pbmc_small@scale.data)
The additional information in the @scale.data
slot is stored as an additional
assay of the same name in the resulting SingleCellExperiment
object:
pbmc_sce <- as(pbmc_small, "SingleCellExperiment") pbmc_sce
The FindVariableGenes
function populates the @var.genes
and @hvg.info
slots of seurat
objects (while also storing the associated parameters in
the @calc.params
slot):
pbmc_small <- FindVariableGenes(object = pbmc_small, do.plot = FALSE) head(pbmc_small@var.genes)
The information in the @hvg.info
slot, as well as the presence of individual
genes in the @var.genes
slot are stored as columns
in the @rowData
slot of the resulting SingleCellExperiment
object:
pbmc_sce <- as(pbmc_small, "SingleCellExperiment") pbmc_sce
Functions such as RunPCA
and RunTSNE
add their respective coordinates
under the @dr
slot (while also storing the associated parameters in
the @calc.params
slot):
pbmc_small <- RunPCA(pbmc_small, do.print = FALSE) names(pbmc_small@dr) pbmc_small <- RunTSNE(pbmc_small, reduction.use = "pca", dims.use = 1:5, perplexity=10) names(pbmc_small@dr)
Every cell embedding in the @dr
slot will be transferred to the
reducedDims
slot of the resulting SingleCellExperiment
object:
pbmc_sce <- as(pbmc_small, "SingleCellExperiment") pbmc_sce
The RunCCA
function combines two seurat
objects, and stores
the reduced dimensions obtained by canonical-correlation analysis (CCA)
under the @dr
slot (while also storing the associated parameters in
the @calc.params
slot).
pbmc1 <- SubsetData(pbmc_small,cells.use = pbmc_small@cell.names[1:40]) pbmc2 <- SubsetData(pbmc_small,cells.use = pbmc_small@cell.names[41:80]) pbmc1@meta.data$group <- "group1" pbmc2@meta.data$group <- "group2" pbmc_cca <- RunCCA(pbmc1, pbmc2) pbmc_cca <- AlignSubspace( pbmc_cca,reduction.type = "cca", grouping.var = "group", dims.align = 1:2) names(pbmc_cca@dr)
Naturally, PCA and t-SNE reduced dimensions from the original two seurat
objects are not transferred to the new combined seurat
objects.
If desired, they need to be re-computed on the new object:
pbmc_cca <- RunPCA(pbmc_cca, do.print = FALSE) names(pbmc_cca@dr) pbmc_cca <- RunTSNE(pbmc_cca, reduction.use = "pca", dims.use = 1:5, perplexity=10) names(pbmc_cca@dr)
Overall, CCA-aligned reduced dimensions are treated no differently than
other dimensionality reduction embeddings; they are also transferred to
the reducedDims
slot of the resulting SingleCellExperiment
object:
pbmc_sce <- as(pbmc_cca, "SingleCellExperiment") pbmc_sce
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.