UMAP图分不开怎么办?
2021-02-02 本文已影响0人
周运来就是我
在这里,与国际同行一起学习数据分析。
在单细胞数据分析过程中,往往需要看不同的参数下的数据表现,也往往需要循环某个列表(基因集或者分组),这时候向量化测试效率就比较高了。
向量(vector)是R编程里最底层也是最核心的结构,并且从广泛意义上的数据类型而言,R中的矩阵和数组甚至是列表都是向量。提升代码效率的有效途径便是向量化(vectorize),即将运算符或者函数作用在向量的每一个元素上的一种理念。
多个聚类的resolution
参数:
library(Seurat)
library(SeuratData,lib.loc = 'F:\\EE\\software\\R\\R-4.0.2\\library')
library(pbmc3k.SeuratData,lib.loc = 'F:\\EE\\software\\R\\R-4.0.2\\library')
library(clustree,lib.loc = 'F:\\EE\\software\\R\\R-4.0.2\\library')
.libPaths()
library(tidyverse)
library(cowplot)
pbmc3k.final <- FindClusters(pbmc3k.final,dims=1:20,resolution = seq(from=0,by=.2,length=10))
clustree(pbmc3k.final)

分群可视化,其实是map
函数的应用。
Idents(pbmc3k.final) <- "seurat_annotations"
p=list()
p<- map(c(levels(Idents(pbmc3k.final))),function(x){DimPlot(pbmc3k.final, cells.highlight = CellsByIdentities(object = pbmc3k.final, idents = x))})
plot_grid(plotlist = p)

下面来看另一个例子:调节UMAP结构。那么我们就看看可视化有什么参数可以调节:
- 3D
- 调RunUMAP的参数
- 换可视化方法
今天我们来看看n.neighbors和epochs,negative.sample.rate 这几个函数的影响:
map(c(2,seq(from=5,by=50,length=10)) , function(x) { pbmc3k.final %>% RunUMAP(n.neighbors = x,n.epochs=200,dims = 1:20) %>% DimPlot()}) %>% cowplot::plot_grid(plotlist = .)

c(2,seq(from=5,by=50,length=10) )
[1] 2 5 55 105 155 205 255 305 355 405 455
map(c(2,seq(from=5,by=50,length=10)) , function(x) { pbmc3k.final %>% RunUMAP(n.neighbors = 50,n.epochs=x,dims = 1:20) %>% DimPlot()}) %>% cowplot::plot_grid(plotlist = .)

map(c(2,seq(from=1,by=5,length=10)) , function(x) { pbmc3k.final %>% RunUMAP(n.neighbors = 50,n.epochs=500,negative.sample.rate = x,dims = 1:20) %>% DimPlot()}) %>% cowplot::plot_grid(plotlist = .)

好了,节目的最后,放一张大佬的小道消息:
