The BR_*() functions
accept a SingleCellExperiment as well as a Seurat object,
and give the same text. The plots are drawn with scater instead of
Seurat. The differences to know:
colLabels() (the label
column of colData) unless you pass group.by.
Seurat’s equivalent is the active identity.BR_ElbowPlot() needs the varExplained
attribute that scater::runPCA() stores on the PCA.BR_FeaturePlot() describes the logcounts
assay by default (layer = "counts" to change it).We build an SCE from the counts of pbmc_small and run a
standard scater workflow. As labels we reuse the clusters that came with
the data.
library(scBrailleR)
library(scater)
data("pbmc_small", package = "SeuratObject")
sce <- SingleCellExperiment(
assays = list(counts = SeuratObject::LayerData(pbmc_small, layer = "counts"))
)
sce <- logNormCounts(sce)
#> Warning in .library_size_factors(assay(x, assay.type), ...): 'librarySizeFactors' is deprecated.
#> Use 'scrapper::centerSizeFactors' instead.
#> See help("Deprecated")
#> Warning in .local(x, ...): 'normalizeCounts' is deprecated.
#> Use 'scrapper::normalizeCounts' instead.
#> See help("Deprecated")
set.seed(1)
sce <- runPCA(sce, ncomponents = 15)
sce <- runTSNE(sce, dimred = "PCA", perplexity = 10)
colLabels(sce) <- pbmc_small$RNA_snn_res.1
sce
#> class: SingleCellExperiment
#> dim: 230 80
#> metadata(0):
#> assays(2): counts logcounts
#> rownames(230): MS4A1 CD79B ... SPON2 S100B
#> rowData names(0):
#> colnames(80): ATGCCAGAACGACT CATGGCCTGTGCAT ... GGAACACTTCAGAC
#> CTTGATTGATCTTC
#> colData names(2): sizeFactor label
#> reducedDimNames(2): PCA TSNE
#> mainExpName: NULL
#> altExpNames(0):BrailleR::VI(BR_ElbowPlot(sce))
#> Elbow plot of 15 principal components from reduction PCA.
#> Standard deviations range from 6.18 (PC1) to 1.49 (PC15).
#> Estimated elbow at PC5 (sdev 2.42). PCs 1-5 together account for 77.4% of the variance among the 15 PCs shown. The elbow is sharp.BrailleR::VI(BR_DimPlot(sce, reduction = "TSNE"))
#> TSNE embedding of 80 cells, coloured by label, across 3 groups.
#> Axes: TSNE1 in [-17.36, 12.39]; TSNE2 in [-23.78, 21.72].
#> Group 0: n=36 (45.0%), centred near (-8.31, -15.95), spread (5.15, 9.52).
#> Group 1: n=25 (31.2%), centred near (9.10, 17.95), spread (2.28, 3.11).
#> Group 2: n=19 (23.8%), centred near (8.43, -5.04), spread (0.82, 2.38).
#> Most isolated group: 2 (nearest centroid is 0 at distance 19.98, 14.3x its own spread).
#> Closest pair: 0 and 2 (centroid distance 19.98, 2.9x 0's spread).
#>
#> Overall density grid (4x4 bins of equal width; rows = TSNE2 descending, cols = TSNE1 ascending; row/col sums in margins):
#> 1 2 3 4 Sum
#> 4 9 0 1 30 40
#> 3 0 0 0 0 0
#> 2 0 0 0 10 10
#> 1 3 27 0 0 30
#> Sum 12 27 1 40 80
#>
#> Modal-cluster grid (label of the most-populous group in each bin; '.' = empty bin):
#> 1 2 3 4
#> 4 0 . 1 1
#> 3 . . . .
#> 2 . . . 2
#> 1 0 0 . .BrailleR::VI(BR_FeaturePlot(sce, c("CD3E", "LYZ"), reduction = "TSNE"))
#> Feature plot of 2 features (CD3E, LYZ) on the TSNE embedding of 80 cells, values from logcounts.
#>
#> CD3E: expressed in 25 cells (31.2%), maximum 3.87, median 1.93 among expressing cells.
#> Highest mean expression in bin row 1, column 1 (mean 1.85), where group 0 is most common.
#> Top groups by mean: 0 (mean 1.07, 44% expressing); 2 (mean 0.61, 42% expressing); 1 (mean 0.03, 4% expressing).
#> Mean-expression grid (4x4 bins; rows = TSNE2 descending, cols = TSNE1 ascending; '.' = empty bin):
#> 1 2 3 4
#> 4 0.16 . 0.00 0.06
#> 3 . . . .
#> 2 . . . 0.52
#> 1 1.85 1.38 . .
#>
#> LYZ: expressed in 51 cells (63.7%), maximum 5.85, median 3.08 among expressing cells.
#> Highest mean expression in bin row 4, column 4 (mean 4.25), where group 1 is most common.
#> Top groups by mean: 1 (mean 4.27, 100% expressing); 2 (mean 1.76, 58% expressing); 0 (mean 0.75, 42% expressing).
#> Mean-expression grid (4x4 bins; rows = TSNE2 descending, cols = TSNE1 ascending; '.' = empty bin):
#> 1 2 3 4
#> 4 0.64 . 2.14 4.25
#> 3 . . . .
#> 2 . . . 1.10
#> 1 2.29 0.50 . .See vignette("seurat", package = "scBrailleR") for how
to read each part of the output; the meaning is identical.
If the SCE has no label column,
BR_FeaturePlot() still describes where each gene is
expressed but cannot say which group that is, and
BR_DimPlot() asks for group.by:
sce$label <- NULL
BrailleR::VI(BR_FeaturePlot(sce, "LYZ", reduction = "TSNE"))
#> Feature plot of 1 feature (LYZ) on the TSNE embedding of 80 cells, values from logcounts.
#>
#> LYZ: expressed in 51 cells (63.7%), maximum 5.85, median 3.08 among expressing cells.
#> Highest mean expression in bin row 4, column 4 (mean 4.25).
#> Mean-expression grid (4x4 bins; rows = TSNE2 descending, cols = TSNE1 ascending; '.' = empty bin):
#> 1 2 3 4
#> 4 0.64 . 2.14 4.25
#> 3 . . . .
#> 2 . . . 1.10
#> 1 2.29 0.50 . .
BR_DimPlot(sce)
#> Error in `BR_DimPlot()`:
#> ! colData has no column 'label'; set group.by