library(dplyr) library(Seurat) library(patchwork) library(mclust) library(robin)
tabMur <- system.file("example/filtered_tabulamuris_mtx.rds", package="robin") tabData <- readRDS(file=tabMur) SingleCellData <- CreateSeuratObject(counts = tabData, project = "singleCell", min.cells = round(dim(tabData)[2]*5/100), min.features = 0) SingleCellData
SingleCellData <- NormalizeData(SingleCellData, normalization.method = "LogNormalize", scale.factor = 10000) SingleCellData[["RNA"]]@layers$counts[1:5,1:5]
SingleCellData <- FindVariableFeatures(object = SingleCellData, selection.method="vst", nfeatures = 2000)
SingleCellData <- ScaleData(SingleCellData, do.center = TRUE, do.scale = TRUE) SingleCellData[["RNA"]]@layers$scale.data[1:5,1:5]
SingleCellData <- RunPCA(SingleCellData, features = VariableFeatures(object = SingleCellData))
SingleCellData <- FindNeighbors(SingleCellData, dims = 1:50) SingleCellData@graphs$RNA_snn[1:5,1:5] # Adjacency matrix
AdjSNN <- SingleCellData@graphs$RNA_snn graphSingleCell <- graph_from_adjacency_matrix(AdjSNN,mode="directed",weighted = TRUE,add.colnames = "NA",diag=FALSE) edge <- as_edgelist(graphSingleCell) graph <- igraph::graph_from_edgelist(edge, directed=FALSE) graph <- igraph::simplify(graph) graph
We apply the compare procedure to see which is the algorithm that better fits our network.
#Infomap comp_I <- robinCompare(graph=graph, method1="louvain", method2="infomap") #Walktrap comp_W <- robinCompare(graph=graph, method1="louvain", method2="walktrap") #LabelProp comp_La <- robinCompare(graph=graph, method1="louvain", method2="labelProp") #Fastgreedy comp_F <- robinCompare(graph=graph, method1="louvain", method2="fastGreedy") plotMultiCompare(comp_F,comp_La, comp_I, comp_W)
The lowest curve is the most stable algorithm. Louvain and Walktrap are the best algorithms in our example.
Due to the fact that Louvain is one of the best algorithm for our network we apply the robust procedure with the Louvain algorithm to see if the communities detected are statistically significant.
graphRandom <- random(graph=graph) proc <- robinRobust(graph=graph, graphRandom=graphRandom, method="louvain") plot(proc) robinFDATest(proc) robinGPTest(proc) set.seed(100) cluster_louvain(graph) mc <- membershipCommunities(graph=graph, method="louvain")
The communities given by Louvain are statistically significant.
Once we found the best clustering algorithm, we can use the found communities for identifying marker genes, to subsequently find cell types.
SingleCellData$seurat_clusters = mc Idents(SingleCellData) <- "seurat_clusters" markers <- FindAllMarkers(SingleCellData, only.pos = TRUE, logfc.threshold = 0.25) markers %>% group_by(cluster) %>% dplyr::filter(avg_log2FC > 1) %>% slice_head(n = 10) %>% ungroup() -> top10 DoHeatmap(SingleCellData, features = top10$gene) + NoLegend()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.