bbknnR Tutorial

Setup library and data

library(bbknnR)
library(Seurat)
#> Loading required package: SeuratObject
#> Loading required package: sp
#> 'SeuratObject' was built under R 4.6.0 but the current version is
#> 4.6.1; it is recomended that you reinstall 'SeuratObject' as the ABI
#> for R may have changed
#> 'SeuratObject' was built with package 'Matrix' 1.7.5 but the current
#> version is 1.7.6; it is recomended that you reinstall 'SeuratObject' as
#> the ABI for 'Matrix' may have changed
#> 
#> Attaching package: 'SeuratObject'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, t
#> v5.6 adds significant improvements in speed and efficiency, particularly for large datasets.
#> For more information, see https://satijalab.org/seurat/articles/announcements.
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(patchwork)
data("panc8_small")

Run BBKNN

Note that RunBBKNN() also compute t-SNE and UMAP by default.

panc8_small <- RunBBKNN(panc8_small, batch_key = "tech")
#> Find BBKNN for each batch: 
#>   neighbors_within_batch: 3
#>   n_pcs: 50
#>   method: 'annoy'
#>   metric: 'euclidean'
#> Compute connectivity graph with 'trim = 150'
#> BBKNN finish!
#> Running UMAP...
#> Running tSNE...

Find Clusters using bbknn graph

panc8_small <- FindClusters(panc8_small, graph.name = "RNA_bbknn")
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 500
#> Number of edges: 6035
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.7193
#> Number of communities: 5
#> Elapsed time: 0 seconds

Visualization

p1 <- DimPlot(panc8_small, reduction = "umap", group.by = "celltype", label = TRUE,
             label.size = 3 , repel = TRUE) + NoLegend()
p2 <- DimPlot(panc8_small, reduction = "umap", group.by = "tech")
p3 <- DimPlot(panc8_small, reduction = "umap")

wrap_plots(list(p1, p2, p3), ncol = 1)

p1 <- DimPlot(panc8_small, reduction = "tsne", group.by = "celltype", label = TRUE,
             label.size = 3 , repel = TRUE) + NoLegend()
p2 <- DimPlot(panc8_small, reduction = "tsne", group.by = "tech")
p3 <- DimPlot(panc8_small, reduction = "tsne")

wrap_plots(list(p1, p2, p3), ncol = 1)