1写在前面
上一期我们介绍了质控(quality control
, QC
)的意义和方法。
本期我们介绍一下高表达基因的可视化
,以及简单的主成分分析
(PCA
)。🥰
2用到的包
rm(list = ls())
library(tidyverse)
library(SingleCellExperiment)
library(scater)
3示例数据
这里我们用一下之前介绍的counts
文件和annotation
文件,然后通过SingleCellExperiment
创建SingleCellExperiment
格式的文件,并且经过初步过滤
,ID转换
等。
load("umi.Rdata")
umi
![alt](https://i-blog.csdnimg.cn/blog_migrate/74bd598616881f573a5cc307cc60723a.png)
4高表达基因的可视化
4.1 初步绘图
这里我们可以看到高表达的多是一些线粒体或核糖体基因。
不过大多数的dataset
都是这样的。😂
umi %>%
plotHighestExprs(exprs_values = "counts",
feature_names_to_plot = "SYMBOL",
colour_cells_by="detected")
![alt](https://i-blog.csdnimg.cn/blog_migrate/2f261390821dc115af0a6c11706244aa.png)
4.2 过滤一下
这里我们过滤一下看看,过滤条件:
-
在 2
个或更多细胞中检测到的基因; -
counts
> 1。
keep_feature <- nexprs(umi, byrow = TRUE, detection_limit = 1) >= 2
rowData(umi)$discard <- ! keep_feature
table(rowData(umi)$discard)
![alt](https://i-blog.csdnimg.cn/blog_migrate/676e14342c86c02b5313e5bcb81e7ba9.png)
在这里我们过滤掉了4205个基因。
4.3 正式过滤
我们先取个log
吧,并存在umi
里,然后再用前面的过滤条件过滤一下。
assay(umi, "logcounts_raw") <- log2(counts(umi) + 1)
umi.qc <- umi[! rowData(umi)$discard,! colData(umi)$discard]
5降维与可视化-PCA
5.1 PCA
我们常用的降维方法包括PCA
、UMAP
和tSNE
。🤒
Note! 👀 这里需要跟大家强调一下log-transformation
和normalization
的重要性。
5.2 质控前
举个栗子🌰
不进行log-transformation
或normalization
。
聚成一团,根本没法看啊。🫠
umi <- runPCA(umi, exprs_values = "counts")
dim(reducedDim(umi, "PCA"))
plotPCA(umi, colour_by = "batch", size_by = "detected", shape_by = "individual")
![alt](https://i-blog.csdnimg.cn/blog_migrate/cfa32c4e6e65a407885821a8cb8579ae.png)
取个log 🥳
在这里我们用下之前做完log-transformation
后的数据。
可以看到不同replicate
, individual
, sequencing depth
,明显分开,形成一个个小的group
。😘
umi <- runPCA(umi, exprs_values = "logcounts_raw")
dim(reducedDim(umi, "PCA"))
plotPCA(umi, colour_by = "batch", size_by = "detected", shape_by = "individual")
![alt](https://i-blog.csdnimg.cn/blog_migrate/119cc9946f1ef3b2efaf30d641731826.png)
Note! 这里我只做了log-transformation
,大家在实际应用中还应纳入normalization
,CPM
、TPM
等方法,大家自行挑选吧。
5.3 质控后
我们来看一下过滤掉表达低的基因后有什么变化吧,当然也是要取log
的。😂
umi.qc <- runPCA(umi.qc, exprs_values = "logcounts_raw")
dim(reducedDim(umi.qc, "PCA"))
plotPCA(umi.qc, colour_by = "batch", size_by = "detected", shape_by = "individual")
![alt](https://i-blog.csdnimg.cn/blog_migrate/19866026b94cd84012100aab44eaa76b.png)
这里可以看到NA19098.r2
经过质控后,不再形成一组离群值了。
Note! 这里说明一下,scater
包在计算PCA
时,只用了top 500
的基因,如果想改的话可以使用ntop
。
😉 嘿嘿,我们试一下用所有基因来做PCA
试试。(^▽^)
umi.qc <- runPCA(umi.qc, exprs_values = "logcounts_raw", ntop = nrow(umi.qc))
dim(reducedDim(umi.qc, "PCA"))
plotPCA(umi.qc, colour_by = "batch", size_by = "detected", shape_by = "individual")
![alt](https://i-blog.csdnimg.cn/blog_migrate/7c226c9ba8603575575b68df8f159a1a.png)
6降维与可视化-tSNE
6.1 质控前
set.seed(123)
umi <- runTSNE(umi, exprs_values = "logcounts_raw", perplexity = 130)
plotTSNE(umi, colour_by = "batch", size_by = "detected", shape_by = "individual")
![alt](https://i-blog.csdnimg.cn/blog_migrate/3f44c70630ce508a3b242646fe55b5eb.png)
Note! 这里补充一下perplexity
一般取总细胞数/5
后四舍五入取整。🤒
6.2 质控后
set.seed(123)
umi.qc <- runTSNE(umi.qc, exprs_values = "logcounts_raw", perplexity = 130)
plotTSNE(umi.qc, colour_by = "batch", size_by = "detected", shape_by = "individual")
![alt](https://i-blog.csdnimg.cn/blog_migrate/e3e19aff25356c05c35d7489763c1a83.png)
同样的,经过质控后,NA19098.r2
也不再形成一组离群值了。
6.3 改下perplexity
我们在这里改一下perplexity
,分别为10
和220
,看看有什么变化。
umi.qc <- runTSNE(umi.qc, exprs_values = "logcounts_raw", perplexity = 10)
plotTSNE(umi.qc, colour_by = "batch", size_by = "detected", shape_by = "individual")
umi.qc <- runTSNE(umi.qc, exprs_values = "logcounts_raw", perplexity = 220)
plotTSNE(umi.qc, colour_by = "batch", size_by = "detected", shape_by = "individual")
![10](https://i-blog.csdnimg.cn/blog_migrate/485112ab7df324ca9a9c9903b92f15e6.png)
![220](https://i-blog.csdnimg.cn/blog_migrate/1fab46e42ba3358f40783e8e94d8294d.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5904106b072d2d02d0b06c50dc41fa86.png)
需要示例数据的小伙伴,在公众号回复
scRNAseq
获取吧!点个在看吧各位~ ✐.ɴɪᴄᴇ ᴅᴀʏ 〰
本文由 mdnice 多平台发布