本期我们介绍一下scRNA-seq
基本信息的可视化方法。✌️
rm(list = ls())
library(tidyverse)
library(scater)
library(SingleCellExperiment)
library(ggsci)
library(scater)
这里我们用一下上期介绍的counts
文件和annotation
文件,然后通过SingleCellExperiment
包创建SingleCellExperiment
格式的文件。
counts <- read.table("./molecules.txt", sep = "\t")
annotation <- read.table("./annotation.txt", sep = "\t", header = TRUE)
counts
annotation
# 注意assays必须是matrix
tung <- SingleCellExperiment(
assays = list(counts = as.matrix(counts)),
colData = annotation
)
assay(tung, "logcounts") <- log2(counts(tung) + 1)
colData(tung)$total_counts <- colSums(counts(tung))
tung
这里我们对每个batch
的总count
的分布情况进行可视化。😘
大家可以在colData
中找到相应信息。
cell_info <- as.data.frame(colData(tung))
head(cell_info)
这里的可视化我们以ggplot
为例。🌰
cell_info %>%
ggplot(aes(x = batch, y = total_counts)) +
geom_violin(aes(fill= batch)) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+
scale_fill_npg()
如果我们想把每个batch
中某个特定gene
的表达分布可视化,这就相对比较复杂了,因为gene
表达信息是在counts
文件中,而batch
信息是在colData
中。🤯
如果要把这两部分信息放在一起,我们需要做大量的数据处理,然后整合在一个data.frame
。😔
这里我们可以使用scater
包的ggcells()
函数进行可视化,非常简单。🤩
上面我们介绍了使用ggplot
对细胞信息进行可视化,这里我们用scater
包也可以实现,无需提取colData
。
tung %>%
ggcells(aes(x = batch, y = total_counts)) +
geom_violin(aes(fill = batch)) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+
scale_fill_lancet()
tung %>%
ggcells(aes(x = batch, y = ENSG00000198938), exprs_values = "logcounts") +
geom_violin(aes(fill = batch)) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+
scale_fill_aaas()
最后祝大家早日不卷!~