Skip to content

Clustering

Material

Download the presentation

Exercises

This chapter uses the gbm dataset

The method implemented in Seurat first constructs a SNN graph based on the euclidean distance in PCA space, and refine the edge weights between any two cells based on the shared overlap in their local neighborhoods (Jaccard similarity). This step is performed using the FindNeighbors() function, and takes as input the previously defined dimensionality of the dataset.

gbm <- Seurat::FindNeighbors(gbm, dims = 1:25)

To cluster the cells, Seurat next implements modularity optimization techniques such as the Louvain algorithm (default) or SLM [SLM, Blondel et al., Journal of Statistical Mechanics], to iteratively group cells together, with the goal of optimizing the standard modularity function. The FindClusters() function implements this procedure, and contains a resolution parameter that sets the ‘granularity’ of the downstream clustering, with increased values leading to a greater number of clusters.

gbm <- Seurat::FindClusters(gbm, resolution = seq(0.1, 0.8, by=0.1))

Cluster id of each cell is added to the metadata object, as a new column for each resolution tested:

head(gbm@meta.data)

To view how clusters sub-divide at increasing resolution:

library(clustree)
clustree::clustree(gbm@meta.data[,grep("RNA_snn_res", colnames(gbm@meta.data))],
                   prefix = "RNA_snn_res.")

You can view the UMAP coloring each cell according to a cluster id like this:

Seurat::DimPlot(gbm, group.by = "RNA_snn_res.0.1")

Exercise: Visualise clustering based on a few more resolutions. Taking the clustering and the UMAP plots into account what do you consider as a good resolution to perform the clustering?

Answer

Of course, there is no ‘optimal’ resolution, but based on resolution of 0.2, it seems that clustering fits the UMAP well:

Seurat::DimPlot(gbm, group.by = "RNA_snn_res.0.2")

Save the dataset and clear environment

Now, save the dataset so you can use it later today:

saveRDS(gbm, "gbm_day2_part1.rds")

Clear your environment:

rm(list = ls())
gc()
.rs.restartR()