Vignette for Dune: merging clusters to improve replicability through ARI merging

Installation

if (!requireNamespace("BiocManager", quietly = TRUE)) {
  install.packages("BiocManager")
}
BiocManager::install("Dune")

We use a subset of the Allen Smart-Seq nuclei dataset. Run ?Dune::nuclei for more details on pre-processing.

suppressPackageStartupMessages({
  library(RColorBrewer)
  library(dplyr)
  library(ggplot2)
  library(tidyr)
  library(knitr)
  library(purrr)
  library(Dune)
})
data("nuclei", package = "Dune")
theme_set(theme_classic())

Initial visualization

We have a dataset of $1744$ cells, with the results from 3 clustering algorithms: Seurat3, Monocle3 and SC3. The Allen Institute also produce hand-picked cluster and subclass labels. Finally, we included the coordinates from a t-SNE representation, for visualization.

ggplot(nuclei, aes(x = x, y = y, col = subclass_label)) +
  geom_point()

We can also see how the three clustering algorithm partitioned the dataset initially:

walk(c("SC3", "Seurat", "Monocle"), function(clus_algo){
  df <- nuclei
  df$clus_algo <- nuclei[, clus_algo]
  p <- ggplot(df, aes(x = x, y = y, col = as.character(clus_algo))) +
    geom_point(size = 1.5) +
    # guides(color = FALSE) +
    labs(title = clus_algo, col = "clusters") +
    theme(legend.position = "bottom")
  print(p)
})

Merging with Dune

Initial ARI

The adjusted Rand Index between the three methods can be computed.

plotARIs(nuclei %>% select(SC3, Seurat, Monocle))

As we can see, the ARI between the three methods is initially quite low.

Actual merging

We can now try to merge clusters with the Dune function. At each step, the algorithm will print which clustering label is merged (by its number, so 1~SC3 and so on), as well as the pair of clusters that get merged.

merger <- Dune(clusMat = nuclei %>% select(SC3, Seurat, Monocle), verbose = TRUE)

The output from Dune is a list with four components:

names(merger)

initialMat is the initial matrix. of cluster labels. currentMat is the final matrix of cluster labels. merges is a matrix that recapitulates what has been printed above, while ImpARI list the ARI improvement over the merges.

ARI improvement

We can now see how much the ARI has improved:

plotARIs(clusMat = merger$currentMat)

The methods now look much more similar, as can be expected.

We can also see how the number of clusters got reduced.

plotPrePost(merger)

For SC3 for example, we can visualize how the clusters got merged:

ConfusionPlot(merger$initialMat[, "SC3"], merger$currentMat[, "SC3"]) +
  labs(x = "Before merging", y = "After merging")

Finally, the ARIImp function tracks mean ARI improvement as pairs of clusters get merged down.

ARItrend(merger)

Session

sessionInfo()


Try the Dune package in your browser

Any scripts or data that you put into this service are public.

Dune documentation built on Nov. 8, 2020, 7:55 p.m.