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 ## An object of class Seurat
## 8694 features across 532 samples within 1 assay
## Active assay: RNA (8694 features, 0 variable features)
## 1 layer present: counts
SingleCellData <- NormalizeData(SingleCellData, normalization.method = "LogNormalize", scale.factor = 10000)## Normalizing layer: counts
## 5 x 5 sparse Matrix of class "dgCMatrix"
##
## [1,] . . . . .
## [2,] . . 1 . 1
## [3,] . . 1 . 1
## [4,] 1 . 1 . .
## [5,] 1 1 2 . .
SingleCellData <- FindVariableFeatures(object = SingleCellData, selection.method="vst", nfeatures = 2000)## Finding variable features for layer counts
## Centering and scaling data matrix
## [,1] [,2] [,3] [,4] [,5]
## [1,] -0.2119967 -0.2119967 -0.2119967 -0.2119967 -0.2119967
## [2,] -0.2464207 -0.2464207 -0.2464207 6.4241312 -0.2464207
## [3,] -0.2325839 -0.2325839 -0.2325839 -0.2325839 -0.2325839
## [4,] -0.3036820 -0.3036820 -0.3036820 -0.3036820 -0.3036820
## [5,] -0.2199427 -0.2199427 -0.2199427 -0.2199427 -0.2199427
## PC_ 1
## Positive: Coro1a, Arhgdib, Laptm5, Srgn, Gmfg, Cd74, Ptprcap, Cd37, Ctss, H2-Aa
## Klf2, Ltb, H2-Ab1, Lcp1, Tmsb4x, H2-Eb1, Slfn2, Cytip, Plac8, Ptpn6
## Cd79a, Cd79b, Ifi27l2a, Cd2, H2-DMa, Ly86, Napsa, Unc93b1, Vim, Selplg
## Negative: Perp, Dsp, S100a14, Trim29, Serpinb5, Sfn, Rab25, Dmkn, Krt6a, Aqp3
## Lgals7, Gpx2, Lypd3, Tacstd2, Them5, Anxa8, Pkp1, Calm4, Ckmt1, Sytl1
## Lad1, Fam25c, Sdc1, Mt4, Gsto1, Sbsn, Avpi1, Ovol1, Gsta4, Calml3
## PC_ 2
## Positive: Coro1a, Arhgdib, Laptm5, Ly6d, Ptprcap, Gmfg, Cd37, Ltb, Ptpn6, Ctss
## Lcp1, Pycard, Cd79b, Cd79a, Cytip, H2-Aa, Cd74, Napsa, Cd2, H2-Ab1
## Selplg, Cd48, Ly86, H2-DMa, Slfn2, H2-Eb1, Rplp0, Tbc1d10c, Ms4a1, 2010001M09Rik
## Negative: Bgn, Serpinh1, Sparc, Col1a2, Igfbp7, Col3a1, Plac9, Gsn, Col6a1, Col1a1
## Mgp, Serping1, Timp2, Nbl1, Fstl1, Ltbp4, Rcn3, Fxyd1, Pcolce, Mxra8
## Rarres2, Ppap2b, Prelp, Cd63, Timp3, Cebpd, Dcn, Col6a2, Lhfp, Mmp2
## PC_ 3
## Positive: Tmsb4x, Rplp0, Dynll1, Klf4, Cdkn1a, S100a6, Cd9, Tuba1a, Sparc, Dcn
## Btg2, Vim, Plac9, Tppp3, Gsn, Gja1, Serpinh1, Ptrf, Mt2, Gadd45b
## Dnajb1, Atf3, Hspb1, Anxa1, Socs3, Cebpd, Klf6, Csrp1, Tnfrsf12a, Bgn
## Negative: Aldob, Slc27a2, Pck1, Ttc36, Pah, Fbp1, Cml1, Acaa1b, Pcbd1, Stard10
## Hrsp12, Sardh, Fah, Cat, Ephx2, Acsl1, Aldh1l1, Sord, 4931406C07Rik, Dhcr24
## Khk, Gstz1, Pecr, Phyh, Acox1, Ass1, Aldh6a1, Pcx, Ugt2b34, Gcdh
## PC_ 4
## Positive: Wif1, Chad, Mia1, Fxyd1, Col11a1, Acan, Scara3, Ucma, Fn1, Serpine2
## Col6a1, Col9a2, Mgp, Cytl1, 1500015O10Rik, Meg3, Rcn3, 3110079O15Rik, Bgn, Col8a1
## Col2a1, Gpc6, Lect1, Mmp2, Col9a1, Cpe, Hapln1, Sdc4, Dkk3, Vasn
## Negative: Ecscr, Cdh5, Ptprb, Egfl7, Rasip1, Esam, Eltd1, Gpr116, Emcn, Eng
## Slc9a3r2, Mmrn2, Cd93, Pecam1, Apold1, Tie1, Flt1, Myct1, Podxl, Fabp4
## Tinagl1, Sox17, Slfn5, Cldn5, Sdpr, Ehd4, Tek, Plvap, Cd36, Tm4sf1
## PC_ 5
## Positive: Cytl1, Chad, Mia1, Wif1, Ucma, Col9a2, 3110079O15Rik, Col11a1, Col2a1, Acan
## Cpe, Hapln1, Lect1, Col9a3, 1500015O10Rik, Col9a1, Pla2g5, Mfi2, Col27a1, Comp
## Fzd9, Fmod, S100b, Col8a1, Sox9, Gpc6, Omd, Mdfi, Crim1, Tsc22d1
## Negative: Olfml3, Clec3b, Pdgfra, Serping1, Inmt, Mfap5, Rarres2, Mfap4, Dpep1, C1ra
## Tcf21, Tnfsf13b, Gyg, Ifi27l2a, C1s, Ppp1r14a, Ms4a4d, Tnxb, Fhl1, Ogn
## Nid1, Fgf7, Hsd11b1, Serpina3n, Abca8a, Alox5ap, Gpc3, C1qtnf7, Spon1, Lyz1
## Computing nearest neighbor graph
## Computing SNN
## 5 x 5 sparse Matrix of class "dgCMatrix"
## 10X_P4_7_CCTACACGTAAGGATT 10X_P7_6_ACACCGGGTAGCGTGA
## 10X_P4_7_CCTACACGTAAGGATT 1.0000000 0.1428571
## 10X_P7_6_ACACCGGGTAGCGTGA 0.1428571 1.0000000
## 10X_P7_9_TGATTTCAGCAGGTCA . .
## 10X_P8_14_CGAATGTAGAAGGTGA . .
## 10X_P4_6_CGATGGCCATCACAAC . .
## 10X_P7_9_TGATTTCAGCAGGTCA 10X_P8_14_CGAATGTAGAAGGTGA
## 10X_P4_7_CCTACACGTAAGGATT . .
## 10X_P7_6_ACACCGGGTAGCGTGA . .
## 10X_P7_9_TGATTTCAGCAGGTCA 1.0000000 .
## 10X_P8_14_CGAATGTAGAAGGTGA . 1
## 10X_P4_6_CGATGGCCATCACAAC 0.2121212 .
## 10X_P4_6_CGATGGCCATCACAAC
## 10X_P4_7_CCTACACGTAAGGATT .
## 10X_P7_6_ACACCGGGTAGCGTGA .
## 10X_P7_9_TGATTTCAGCAGGTCA 0.2121212
## 10X_P8_14_CGAATGTAGAAGGTGA .
## 10X_P4_6_CGATGGCCATCACAAC 1.0000000
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## IGRAPH ca3ae37 U--- 532 14421 --
## + edges from ca3ae37:
## [1] 1-- 2 1-- 8 1-- 13 1-- 14 1-- 17 1-- 27 1-- 42 1-- 63 1-- 65 1-- 71
## [11] 1-- 79 1-- 95 1-- 99 1--102 1--116 1--131 1--132 1--159 1--161 1--164
## [21] 1--172 1--179 1--194 1--197 1--205 1--220 1--258 1--260 1--264 1--267
## [31] 1--270 1--312 1--315 1--325 1--327 1--328 1--351 1--368 1--378 1--386
## [41] 1--391 1--393 1--395 1--397 1--406 1--407 1--409 1--420 1--421 1--426
## [51] 1--427 1--432 1--452 1--458 1--459 1--464 1--472 1--473 1--476 1--478
## [61] 1--495 1--496 1--497 1--501 1--502 1--503 1--510 1--518 2-- 8 2-- 13
## [71] 2-- 14 2-- 27 2-- 42 2-- 63 2-- 65 2-- 71 2-- 79 2-- 95 2-- 99 2--102
## [81] 2--116 2--131 2--132 2--159 2--161 2--164 2--172 2--179 2--194 2--197
## + ... omitted several edges
We apply the compare procedure to see which is the algorithm that better fits our network.
## [1] "Unweighted Network Parallel Function"
## Detected robin method type independent
## It can take time ... It depends on the size of the network.
## [1] "Unweighted Network Parallel Function"
## Detected robin method type independent
## It can take time ... It depends on the size of the network.
## [1] "Unweighted Network Parallel Function"
## Detected robin method type independent
## It can take time ... It depends on the size of the network.
## [1] "Unweighted Network Parallel Function"
## Detected robin method type independent
## It can take time ... It depends on the size of the network.
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")## [1] "Unweighted Network Parallel Function"
## Detected robin method type independent
## It can take time ... It depends on the size of the network.
## [1] "First step: basis expansion"
## Swapping 'y' and 'argvals', because 'y' is simpler,
## and 'argvals' should be; now dim(argvals) = 13 ; dim(y) = 13 x 20
## [1] "Second step: joint univariate tests"
## [1] "Third step: interval-wise combination and correction"
## [1] "creating the p-value matrix: end of row 2 out of 9"
## [1] "creating the p-value matrix: end of row 3 out of 9"
## [1] "creating the p-value matrix: end of row 4 out of 9"
## [1] "creating the p-value matrix: end of row 5 out of 9"
## [1] "creating the p-value matrix: end of row 6 out of 9"
## [1] "creating the p-value matrix: end of row 7 out of 9"
## [1] "creating the p-value matrix: end of row 8 out of 9"
## [1] "creating the p-value matrix: end of row 9 out of 9"
## [1] "Interval Testing Procedure completed"
## TableGrob (1 x 2) "arrange": 2 grobs
## z cells name grob
## 1 1 (1-1,1-1) arrange gtable[layout]
## 2 2 (1-1,2-2) arrange gtable[layout]
## $adj.pvalue
## [1] 0.3241 0.0048 0.0014 0.0014 0.0014 0.0014 0.0014 0.0014 0.0067
##
## $pvalues
## [1] 0.3241 0.0014 0.0014 0.0014 0.0014 0.0014 0.0014 0.0014 0.0014
## Profile 1
## Profile 2
## [1] 74.73205
## IGRAPH clustering multi level, groups: 8, mod: 0.75
## + groups:
## $`1`
## [1] 1 2 8 13 14 17 27 42 63 65 71 79 95 99 102 116 131 132
## [19] 159 161 164 172 179 194 197 205 206 220 258 260 264 267 270 312 315 325
## [37] 327 328 338 351 368 378 386 391 393 395 397 406 407 409 420 421 424 426
## [55] 427 432 442 452 458 459 464 469 472 473 476 478 495 496 497 501 502 503
## [73] 510 518
##
## $`2`
## [1] 3 5 9 25 33 53 59 60 70 77 88 98 101 114 120 134 145 148
## [19] 152 169 170 176 214 215 241 244 262 275 282 283 289 296 304 305 308 309
## + ... omitted several groups/vertices
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()## Warning in DoHeatmap(SingleCellData, features = top10$gene): The following
## features were omitted as they were not found in the scale.data layer for the
## RNA assay: Rac2, Cd52