```{css, echo=FALSE} pre code { white-space: pre !important; overflow-x: scroll !important; word-break: keep-all !important; word-wrap: initial !important; }

```r
knitr::opts_chunk$set(collapse = TRUE, comment = "#>",
                      echo=TRUE, message=FALSE, warnings=FALSE
                      )

In this tutorial, we show the use of the MRtree with SOUP clustering on a Mouse brain data (@RN135, GEO:GSE60361). SOUP is a Semi-soft clustering method provided by SOUP package (@RN195). Make sure to install the SOUP package following the instructions on \url{https://github.com/lingxuez/SOUPR} (R >= 3.4.2).

Load the package

library(mrtree)

The data is provided in the SOUP package, so we use this for convenience.

zeisel = SOUP::zeisel
counts = t(zeisel$counts)
true.labels = as.character(zeisel$cell.info$cell.type)
true.labels=plyr::mapvalues(true.labels,
                            from=c('pyramidal CA1','pyramidal SS'),
                            to = c('excitatoryCA1','excitatorySS')) # no space in labels
counts = counts[rownames(counts) %in% zeisel$select.genes,] # use the selected genes
dim(counts)

Perform SOUP clustering with the targeted number of clusters as input for resolution parameters Ks=2:12.

set.seed(123)
Ks = 2:12
counts = counts[rownames(counts) %in% zeisel$select.genes,]
# takes a few minutes
clust.out = sc_clustering.soup(exprs=counts, Ks=Ks, type='count', estimate.k=F,
                              pure.prop=0.8, ext.prop=NULL, scale.factor=1e6)

Perform MRtree. Show the resulted tree plot

out = mrtree(clust.out$labelmat, prefix='soup_K')

hc = plot_tree(labelmat = out$labelmat.mrtree,  ref.labels = true.labels,
               plot.piechart = F, node.size = 0.3, tip.label.dist = 8,  bottom.margin = 48,
               legend.title=' ')
hc

Stability analysis shows the optimal cut is obtained at K=7.

# stability analysis
stab.out = stability_plot(out); stab.out$plot

Compare the initial SOUP clustering results with MRtree results.

# accuracy of cluster
ks.flat = apply(out$labelmat.flat, 2, FUN=function(x) length(unique(x)))
ks.mrtree = apply(out$labelmat.mrtree, 2, FUN=function(x) length(unique(x)))
amri.flat = sapply(1:ncol(out$labelmat.flat), function(i) AMRI(out$labelmat.flat[,i], true.labels)$amri)
amri.flat = aggregate(amri.flat, by=list(k=ks.flat), FUN=mean)
amri.recon = sapply(1:ncol(out$labelmat.mrtree), function(i) AMRI(out$labelmat.mrtree[,i], true.labels)$amri)

df = rbind(data.frame(k=amri.flat$k, amri=amri.flat$x, method='SOUP flat'),
           data.frame(k=ks.mrtree, amri=amri.recon, method='MRtree'))
ggplot2::ggplot(data=df, aes(x=k, y=amri, color=method)) + geom_point()+geom_line() + theme_bw() + ylab('AMRI')

Reference



pengminshi/MRtree documentation built on March 6, 2023, 4:20 p.m.