道理你都懂,还是做不好单细胞。沉下心来,再看一遍道理。
积土成山,风雨兴焉;积水成渊,蛟龙生焉;积善成德,而神明自得,圣心备焉.故不积跬步,无以至千里;不积小流,无以成江海.骐骥一跃,不能十步;驽马十驾,功在不舍.锲而舍之,朽木不折;锲而不舍,金石可镂.-- 荀子《劝学》
当初怎么背下来的这篇古文。
雨水:降雨开始,雨量渐增。
在单细胞数据分析过程中,往往需要看不同的参数下的数据表现,也往往需要循环某个列表(基因集或者分组),这时候向量化测试效率就比较高了。
向量(vector)是R编程里最底层也是最核心的结构,并且从广泛意义上的数据类型而言,R中的矩阵和数组甚至是列表都是向量。提升代码效率的有效途径便是向量化(vectorize),即将运算符或者函数作用在向量的每一个元素上的一种理念。
多个聚类的resolution参数:
> library(Seurat)
> library(SeuratData)
> library(pbmc3k.SeuratData)
> library(clustree)
载入需要的程辑包:ggraph
载入需要的程辑包:ggplot2
Warning messages:
1: 程辑包‘clustree’是用R版本4.0.4 来建造的
2: 程辑包‘ggraph’是用R版本4.0.3 来建造的
> .libPaths()
[1] "C:/Users/Nano/Documents/R/win-library/4.0" "C:/Program Files/R/R-4.0.2/library"
> library(tidyverse)
-- Attaching packages --------------------------------------------------- tidyverse 1.3.0 --
√ tibble 3.0.4 √ dplyr 1.0.2
√ tidyr 1.1.2 √ stringr 1.4.0
√ readr 1.4.0 √ forcats 0.5.0
√ purrr 0.3.4
-- Conflicts ------------------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
Warning messages:
1: 程辑包‘tidyverse’是用R版本4.0.3 来建造的
2: 程辑包‘tibble’是用R版本4.0.3 来建造的
3: 程辑包‘tidyr’是用R版本4.0.3 来建造的
4: 程辑包‘readr’是用R版本4.0.3 来建造的
5: 程辑包‘purrr’是用R版本4.0.3 来建造的
6: 程辑包‘dplyr’是用R版本4.0.3 来建造的
7: 程辑包‘stringr’是用R版本4.0.3 来建造的
8: 程辑包‘forcats’是用R版本4.0.3 来建造的
> library(cowplot)
> pbmc3k.final <- FindClusters(pbmc3k.final,dims=1:20,resolution = seq(from=0,by=.2,length=10))
Warning: The following arguments are not used: dims
Warning: The following arguments are not used: dims
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 1.0000
Number of communities: 1
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.9348
Number of communities: 6
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8884
Number of communities: 9
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8567
Number of communities: 10
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8288
Number of communities: 11
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8033
Number of communities: 11
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.7790
Number of communities: 11
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.7565
Number of communities: 13
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.7354
Number of communities: 14
Elapsed time: 0 seconds
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 2638
Number of edges: 96033
Running Louvain algorithm...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.7173
Number of communities: 15
Elapsed time: 0 seconds
> clustree(pbmc3k.final)
Warning message:
The `add` argument of `group_by()` is deprecated as of dplyr 1.0.0.
Please use the `.add` argument instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
参考
Seurat Weekly NO.09 ||UMAP图分不开怎么办?