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)
## [1] "SC3" "21"  "20" 
## [1] "Monocle" "20"      "4"      
## [1] "SC3" "11"  "12" 
## [1] "SC3" "22"  "28" 
## [1] "SC3" "11"  "24" 
## [1] "SC3" "22"  "4"  
## [1] "Seurat" "10"     "2"

The output from Dune is a list with four components:

names(merger)
## [1] "initialMat" "currentMat" "merges"     "ImpARI"

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()
## R version 4.0.0 (2020-04-24)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.11-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.11-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] Dune_1.0.1         purrr_0.3.4        knitr_1.28         tidyr_1.1.0       
## [5] ggplot2_3.3.1      dplyr_1.0.0        RColorBrewer_1.1-2
## 
## loaded via a namespace (and not attached):
##  [1] SummarizedExperiment_1.18.1 progress_1.2.2             
##  [3] tidyselect_1.1.0            xfun_0.14                  
##  [5] lattice_0.20-41             colorspace_1.4-1           
##  [7] vctrs_0.3.0                 generics_0.0.2             
##  [9] viridisLite_0.3.0           htmltools_0.4.0            
## [11] stats4_4.0.0                gganimate_1.0.5            
## [13] yaml_2.2.1                  rlang_0.4.6                
## [15] pillar_1.4.4                glue_1.4.1                 
## [17] withr_2.2.0                 tweenr_1.0.1               
## [19] BiocParallel_1.22.0         BiocGenerics_0.34.0        
## [21] matrixStats_0.56.0          GenomeInfoDbData_1.2.3     
## [23] lifecycle_0.2.0             stringr_1.4.0              
## [25] zlibbioc_1.34.0             munsell_0.5.0              
## [27] gtable_0.3.0                evaluate_0.14              
## [29] labeling_0.3                Biobase_2.48.0             
## [31] IRanges_2.22.2              GenomeInfoDb_1.24.0        
## [33] parallel_4.0.0              Rcpp_1.0.4.6               
## [35] scales_1.1.1                DelayedArray_0.14.0        
## [37] S4Vectors_0.26.1            magick_2.3                 
## [39] XVector_0.28.0              farver_2.0.3               
## [41] hms_0.5.3                   digest_0.6.25              
## [43] stringi_1.4.6               GenomicRanges_1.40.0       
## [45] grid_4.0.0                  tools_4.0.0                
## [47] bitops_1.0-6                magrittr_1.5               
## [49] RCurl_1.98-1.2              tibble_3.0.1               
## [51] crayon_1.3.4                pkgconfig_2.0.3            
## [53] ellipsis_0.3.1              Matrix_1.2-18              
## [55] prettyunits_1.1.1           rmarkdown_2.2              
## [57] mclust_5.4.6                R6_2.4.1                   
## [59] compiler_4.0.0