单细胞Seurat数据对象创建思维导图

在我们分析单细胞数据的时候,需要想象力的一点就是要理解数据结构。平时我们都是如何看数据结构的呢?

  1. library(Seurat)
  2. library(tidyverse)
  3. pbmc<-CreateSeuratObject(pbmc_small@assays$RNA@counts)
  4. pbmc%>% NormalizeData() %>% FindVariableFeatures() %>%
  5. ScaleData() %>% RunPCA() %>% FindNeighbors() %>% RunUMAP(1:10) %>%
  6. FindClusters(dims=1:0)-> pbmc
  7. pbmc
  8.  
  9. An object of class Seurat
  10. 230 features across 80 samples within 1 assay
  11. Active assay: RNA (230 features)
  12. 2 dimensional reductions calculated: pca, umap

在R里面我们用的是str(...),如:

  1. str(pbmc)
  2.  
  3. Formal class 'Seurat' [package "Seurat"] with 13 slots
  4. ..@ assays :List of 1
  5. .. ..$ RNA:Formal class 'Assay' [package "Seurat"] with 8 slots
  6. .. .. .. ..@ counts :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  7. .. .. .. .. .. ..@ i : int [1:4456] 1 5 8 11 22 30 33 34 36 38 ...
  8. .. .. .. .. .. ..@ p : int [1:81] 0 47 99 149 205 258 306 342 387 423 ...
  9. .. .. .. .. .. ..@ Dim : int [1:2] 230 80
  10. .. .. .. .. .. ..@ Dimnames:List of 2
  11. .. .. .. .. .. .. ..$ : chr [1:230] "MS4A1" "CD79B" "CD79A" "HLA-DRA" ...
  12. .. .. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  13. .. .. .. .. .. ..@ x : num [1:4456] 1 1 3 1 1 4 1 5 1 1 ...
  14. .. .. .. .. .. ..@ factors : list()
  15. .. .. .. ..@ data :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  16. .. .. .. .. .. ..@ i : int [1:4456] 1 5 8 11 22 30 33 34 36 38 ...
  17. .. .. .. .. .. ..@ p : int [1:81] 0 47 99 149 205 258 306 342 387 423 ...
  18. .. .. .. .. .. ..@ Dim : int [1:2] 230 80
  19. .. .. .. .. .. ..@ Dimnames:List of 2
  20. .. .. .. .. .. .. ..$ : chr [1:230] "MS4A1" "CD79B" "CD79A" "HLA-DRA" ...
  21. .. .. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  22. .. .. .. .. .. ..@ x : num [1:4456] 4.97 4.97 6.06 4.97 4.97 ...
  23. .. .. .. .. .. ..@ factors : list()
  24. .. .. .. ..@ scale.data : num [1:230, 1:80] -0.409 1.64 -0.428 -1.375 -0.329 ...
  25. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  26. .. .. .. .. .. ..$ : chr [1:230] "MS4A1" "CD79B" "CD79A" "HLA-DRA" ...
  27. .. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  28. .. .. .. ..@ key : chr "rna_"
  29. .. .. .. ..@ assay.orig : NULL
  30. .. .. .. ..@ var.features : chr [1:230] "PPBP" "IGLL5" "VDAC3" "CD1C" ...
  31. .. .. .. ..@ meta.features:'data.frame': 230 obs. of 5 variables:
  32. .. .. .. .. ..$ vst.mean : num [1:230] 0.388 0.6 0.7 13.425 0.3 ...
  33. .. .. .. .. ..$ vst.variance : num [1:230] 1.025 1.281 4.365 725.463 0.871 ...
  34. .. .. .. .. ..$ vst.variance.expected : num [1:230] 1.141 2.664 4.029 745.145 0.642 ...
  35. .. .. .. .. ..$ vst.variance.standardized: num [1:230] 0.898 0.481 1.083 0.974 1.356 ...
  36. .. .. .. .. ..$ vst.variable : logi [1:230] TRUE TRUE TRUE TRUE TRUE TRUE ...
  37. .. .. .. ..@ misc : NULL
  38. ..@ meta.data :'data.frame': 80 obs. of 5 variables:
  39. .. ..$ orig.ident : Factor w/ 1 level "SeuratProject": 1 1 1 1 1 1 1 1 1 1 ...
  40. .. ..$ nCount_RNA : num [1:80] 70 85 87 127 173 70 64 72 52 100 ...
  41. .. ..$ nFeature_RNA : int [1:80] 47 52 50 56 53 48 36 45 36 41 ...
  42. .. ..$ RNA_snn_res.0.8: Factor w/ 3 levels "0","1","2": 2 2 2 2 2 2 2 2 2 2 ...
  43. .. ..$ seurat_clusters: Factor w/ 3 levels "0","1","2": 2 2 2 2 2 2 2 2 2 2 ...
  44. ..@ active.assay: chr "RNA"
  45. ..@ active.ident: Factor w/ 3 levels "0","1","2": 2 2 2 2 2 2 2 2 2 2 ...
  46. .. ..- attr(*, "names")= chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  47. ..@ graphs :List of 2
  48. .. ..$ RNA_nn :Formal class 'Graph' [package "Seurat"] with 7 slots
  49. .. .. .. ..@ assay.used: chr "RNA"
  50. .. .. .. ..@ i : int [1:1600] 0 1 2 3 4 5 6 7 8 9 ...
  51. .. .. .. ..@ p : int [1:81] 0 10 17 40 57 101 124 141 153 178 ...
  52. .. .. .. ..@ Dim : int [1:2] 80 80
  53. .. .. .. ..@ Dimnames :List of 2
  54. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  55. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  56. .. .. .. ..@ x : num [1:1600] 1 1 1 1 1 1 1 1 1 1 ...
  57. .. .. .. ..@ factors : list()
  58. .. ..$ RNA_snn:Formal class 'Graph' [package "Seurat"] with 7 slots
  59. .. .. .. ..@ assay.used: chr "RNA"
  60. .. .. .. ..@ i : int [1:4174] 0 1 2 3 4 5 6 7 8 9 ...
  61. .. .. .. ..@ p : int [1:81] 0 68 132 181 230 277 326 375 424 487 ...
  62. .. .. .. ..@ Dim : int [1:2] 80 80
  63. .. .. .. ..@ Dimnames :List of 2
  64. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  65. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  66. .. .. .. ..@ x : num [1:4174] 1 0.6 0.6 0.6 0.538 ...
  67. .. .. .. ..@ factors : list()
  68. ..@ neighbors : list()
  69. ..@ reductions :List of 2
  70. .. ..$ pca :Formal class 'DimReduc' [package "Seurat"] with 9 slots
  71. .. .. .. ..@ cell.embeddings : num [1:80, 1:50] 3.12 3.56 2.4 3.43 2.78 ...
  72. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  73. .. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  74. .. .. .. .. .. ..$ : chr [1:50] "PC_1" "PC_2" "PC_3" "PC_4" ...
  75. .. .. .. ..@ feature.loadings : num [1:230, 1:50] 0.05711 0.00738 0.03005 -0.04766 0.05598 ...
  76. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  77. .. .. .. .. .. ..$ : chr [1:230] "PPBP" "IGLL5" "VDAC3" "CD1C" ...
  78. .. .. .. .. .. ..$ : chr [1:50] "PC_1" "PC_2" "PC_3" "PC_4" ...
  79. .. .. .. ..@ feature.loadings.projected: num[0 , 0 ]
  80. .. .. .. ..@ assay.used : chr "RNA"
  81. .. .. .. ..@ global : logi FALSE
  82. .. .. .. ..@ stdev : num [1:50] 5.75 5.21 4.32 3.62 2.77 ...
  83. .. .. .. ..@ key : chr "PC_"
  84. .. .. .. ..@ jackstraw :Formal class 'JackStrawData' [package "Seurat"] with 4 slots
  85. .. .. .. .. .. ..@ empirical.p.values : num[0 , 0 ]
  86. .. .. .. .. .. ..@ fake.reduction.scores : num[0 , 0 ]
  87. .. .. .. .. .. ..@ empirical.p.values.full: num[0 , 0 ]
  88. .. .. .. .. .. ..@ overall.p.values : num[0 , 0 ]
  89. .. .. .. ..@ misc :List of 1
  90. .. .. .. .. ..$ total.variance: num 230
  91. .. ..$ umap:Formal class 'DimReduc' [package "Seurat"] with 9 slots
  92. .. .. .. ..@ cell.embeddings : num [1:80, 1:2] 5.07 5.31 4.72 5.06 5.45 ...
  93. .. .. .. .. ..- attr(*, "scaled:center")= num [1:2] 1.78 -8.75
  94. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  95. .. .. .. .. .. ..$ : chr [1:80] "ATGCCAGAACGACT" "CATGGCCTGTGCAT" "GAACCTGATGAACC" "TGACTGGATTCTCA" ...
  96. .. .. .. .. .. ..$ : chr [1:2] "UMAP_1" "UMAP_2"
  97. .. .. .. ..@ feature.loadings : num[0 , 0 ]
  98. .. .. .. ..@ feature.loadings.projected: num[0 , 0 ]
  99. .. .. .. ..@ assay.used : chr "RNA"
  100. .. .. .. ..@ global : logi TRUE
  101. .. .. .. ..@ stdev : num(0)
  102. .. .. .. ..@ key : chr "UMAP_"
  103. .. .. .. ..@ jackstraw :Formal class 'JackStrawData' [package "Seurat"] with 4 slots
  104. .. .. .. .. .. ..@ empirical.p.values : num[0 , 0 ]
  105. .. .. .. .. .. ..@ fake.reduction.scores : num[0 , 0 ]
  106. .. .. .. .. .. ..@ empirical.p.values.full: num[0 , 0 ]
  107. .. .. .. .. .. ..@ overall.p.values : num[0 , 0 ]
  108. .. .. .. ..@ misc : list()
  109. ..@ images : list()
  110. ..@ project.name: chr "SeuratProject"
  111. ..@ misc : list()
  112. ..@ version :Classes 'package_version', 'numeric_version' hidden list of 1
  113. .. ..$ : int [1:3] 3 1 2
  114. ..@ commands :List of 7
  115. .. ..$ NormalizeData.RNA :Formal class 'SeuratCommand' [package "Seurat"] with 5 slots
  116. .. .. .. ..@ name : chr "NormalizeData.RNA"
  117. .. .. .. ..@ time.stamp : POSIXct[1:1], format: "2020-06-01 22:43:27"
  118. .. .. .. ..@ assay.used : chr "RNA"
  119. .. .. .. ..@ call.string: chr "NormalizeData(.)"
  120. .. .. .. ..@ params :List of 5
  121. .. .. .. .. ..$ assay : chr "RNA"
  122. .. .. .. .. ..$ normalization.method: chr "LogNormalize"
  123. .. .. .. .. ..$ scale.factor : num 10000
  124. .. .. .. .. ..$ margin : num 1
  125. .. .. .. .. ..$ verbose : logi TRUE
  126. .. ..$ FindVariableFeatures.RNA:Formal class 'SeuratCommand' [package "Seurat"] with 5 slots
  127. .. .. .. ..@ name : chr "FindVariableFeatures.RNA"
  128. .. .. .. ..@ time.stamp : POSIXct[1:1], format: "2020-06-01 22:43:28"
  129. .. .. .. ..@ assay.used : chr "RNA"
  130. .. .. .. ..@ call.string: chr "FindVariableFeatures(.)"
  131. .. .. .. ..@ params :List of 12
  132. .. .. .. .. ..$ assay : chr "RNA"
  133. .. .. .. .. ..$ selection.method : chr "vst"
  134. .. .. .. .. ..$ loess.span : num 0.3
  135. .. .. .. .. ..$ clip.max : chr "auto"
  136. .. .. .. .. ..$ mean.function :function (mat, display_progress)
  137. .. .. .. .. ..$ dispersion.function:function (mat, display_progress)
  138. .. .. .. .. ..$ num.bin : num 20
  139. .. .. .. .. ..$ binning.method : chr "equal_width"
  140. .. .. .. .. ..$ nfeatures : num 2000
  141. .. .. .. .. ..$ mean.cutoff : num [1:2] 0.1 8
  142. .. .. .. .. ..$ dispersion.cutoff : num [1:2] 1 Inf
  143. .. .. .. .. ..$ verbose : logi TRUE
  144. .. ..$ ScaleData.RNA :Formal class 'SeuratCommand' [package "Seurat"] with 5 slots
  145. .. .. .. ..@ name : chr "ScaleData.RNA"
  146. .. .. .. ..@ time.stamp : POSIXct[1:1], format: "2020-06-01 22:43:28"
  147. .. .. .. ..@ assay.used : chr "RNA"
  148. .. .. .. ..@ call.string: chr "ScaleData(.)"
  149. .. .. .. ..@ params :List of 10
  150. .. .. .. .. ..$ features : chr [1:230] "PPBP" "IGLL5" "VDAC3" "CD1C" ...
  151. .. .. .. .. ..$ assay : chr "RNA"
  152. .. .. .. .. ..$ model.use : chr "linear"
  153. .. .. .. .. ..$ use.umi : logi FALSE
  154. .. .. .. .. ..$ do.scale : logi TRUE
  155. .. .. .. .. ..$ do.center : logi TRUE
  156. .. .. .. .. ..$ scale.max : num 10
  157. .. .. .. .. ..$ block.size : num 1000
  158. .. .. .. .. ..$ min.cells.to.block: num 80
  159. .. .. .. .. ..$ verbose : logi TRUE
  160. .. ..$ RunPCA.RNA :Formal class 'SeuratCommand' [package "Seurat"] with 5 slots
  161. .. .. .. ..@ name : chr "RunPCA.RNA"
  162. .. .. .. ..@ time.stamp : POSIXct[1:1], format: "2020-06-01 22:43:29"
  163. .. .. .. ..@ assay.used : chr "RNA"
  164. .. .. .. ..@ call.string: chr "RunPCA(.)"
  165. .. .. .. ..@ params :List of 10
  166. .. .. .. .. ..$ assay : chr "RNA"
  167. .. .. .. .. ..$ npcs : num 50
  168. .. .. .. .. ..$ rev.pca : logi FALSE
  169. .. .. .. .. ..$ weight.by.var : logi TRUE
  170. .. .. .. .. ..$ verbose : logi TRUE
  171. .. .. .. .. ..$ ndims.print : int [1:5] 1 2 3 4 5
  172. .. .. .. .. ..$ nfeatures.print: num 30
  173. .. .. .. .. ..$ reduction.name : chr "pca"
  174. .. .. .. .. ..$ reduction.key : chr "PC_"
  175. .. .. .. .. ..$ seed.use : num 42
  176. .. ..$ FindNeighbors.RNA.pca :Formal class 'SeuratCommand' [package "Seurat"] with 5 slots
  177. .. .. .. ..@ name : chr "FindNeighbors.RNA.pca"
  178. .. .. .. ..@ time.stamp : POSIXct[1:1], format: "2020-06-01 22:43:29"
  179. .. .. .. ..@ assay.used : chr "RNA"
  180. .. .. .. ..@ call.string: chr "FindNeighbors(.)"
  181. .. .. .. ..@ params :List of 13
  182. .. .. .. .. ..$ reduction : chr "pca"
  183. .. .. .. .. ..$ dims : int [1:10] 1 2 3 4 5 6 7 8 9 10
  184. .. .. .. .. ..$ assay : chr "RNA"
  185. .. .. .. .. ..$ k.param : num 20
  186. .. .. .. .. ..$ compute.SNN : logi TRUE
  187. .. .. .. .. ..$ prune.SNN : num 0.0667
  188. .. .. .. .. ..$ nn.method : chr "rann"
  189. .. .. .. .. ..$ annoy.metric: chr "euclidean"
  190. .. .. .. .. ..$ nn.eps : num 0
  191. .. .. .. .. ..$ verbose : logi TRUE
  192. .. .. .. .. ..$ force.recalc: logi FALSE
  193. .. .. .. .. ..$ do.plot : logi FALSE
  194. .. .. .. .. ..$ graph.name : chr [1:2] "RNA_nn" "RNA_snn"
  195. .. ..$ RunUMAP.RNA.pca :Formal class 'SeuratCommand' [package "Seurat"] with 5 slots
  196. .. .. .. ..@ name : chr "RunUMAP.RNA.pca"
  197. .. .. .. ..@ time.stamp : POSIXct[1:1], format: "2020-06-01 22:43:33"
  198. .. .. .. ..@ assay.used : chr "RNA"
  199. .. .. .. ..@ call.string: chr "RunUMAP(., 1:10)"
  200. .. .. .. ..@ params :List of 20
  201. .. .. .. .. ..$ dims : int [1:10] 1 2 3 4 5 6 7 8 9 10
  202. .. .. .. .. ..$ reduction : chr "pca"
  203. .. .. .. .. ..$ assay : chr "RNA"
  204. .. .. .. .. ..$ umap.method : chr "uwot"
  205. .. .. .. .. ..$ n.neighbors : int 30
  206. .. .. .. .. ..$ n.components : int 2
  207. .. .. .. .. ..$ metric : chr "cosine"
  208. .. .. .. .. ..$ learning.rate : num 1
  209. .. .. .. .. ..$ min.dist : num 0.3
  210. .. .. .. .. ..$ spread : num 1
  211. .. .. .. .. ..$ set.op.mix.ratio : num 1
  212. .. .. .. .. ..$ local.connectivity : int 1
  213. .. .. .. .. ..$ repulsion.strength : num 1
  214. .. .. .. .. ..$ negative.sample.rate: int 5
  215. .. .. .. .. ..$ uwot.sgd : logi FALSE
  216. .. .. .. .. ..$ seed.use : int 42
  217. .. .. .. .. ..$ angular.rp.forest : logi FALSE
  218. .. .. .. .. ..$ verbose : logi TRUE
  219. .. .. .. .. ..$ reduction.name : chr "umap"
  220. .. .. .. .. ..$ reduction.key : chr "UMAP_"
  221. .. ..$ FindClusters :Formal class 'SeuratCommand' [package "Seurat"] with 5 slots
  222. .. .. .. ..@ name : chr "FindClusters"
  223. .. .. .. ..@ time.stamp : POSIXct[1:1], format: "2020-06-01 22:43:33"
  224. .. .. .. ..@ assay.used : chr "RNA"
  225. .. .. .. ..@ call.string: chr "FindClusters(., dims = 1:0)"
  226. .. .. .. ..@ params :List of 10
  227. .. .. .. .. ..$ graph.name : chr "RNA_snn"
  228. .. .. .. .. ..$ modularity.fxn : num 1
  229. .. .. .. .. ..$ resolution : num 0.8
  230. .. .. .. .. ..$ method : chr "matrix"
  231. .. .. .. .. ..$ algorithm : num 1
  232. .. .. .. .. ..$ n.start : num 10
  233. .. .. .. .. ..$ n.iter : num 10
  234. .. .. .. .. ..$ random.seed : num 0
  235. .. .. .. .. ..$ group.singletons: logi TRUE
  236. .. .. .. .. ..$ verbose : logi TRUE
  237. ..@ tools : list()

别说看了,拉鼠标手都能拉疼。那么我们能不能基于str(pbmc)的结果做一个思维导图呢?就像这样:

单细胞Seurat数据对象创建思维导图-图片1

如果能够这样查看,那不是美滋滋的吗?

需求有了,就差行动了,我们来找代码:

  1. library(mindr)
  2. (out <- capture.output(str(pbmc)))
  3. out2 <- paste(out, collapse="n")
  4.  
  5. mm(gsub("\.\.@","# ",gsub("\.\. ","#",out2)),type ="text",root= "Seurat")

单细胞Seurat数据对象创建思维导图-图片2

这下好了,你对单细胞Seurat数据对象做了什么一目了然。

发表评论

匿名网友

拖动滑块以完成验证
加载中...