美文网首页
R语言可视化11: (sc)RNAseq 数据可视化 - dit

R语言可视化11: (sc)RNAseq 数据可视化 - dit

作者: cc的生信随记 | 来源:发表于2024-02-10 17:13 被阅读0次

dittoSeq 是一款对单细胞和批量 RNA 测序数据进行分析和可视化的工具,提供了多种可视化效果,并且允许自定义。
对于单细胞数据,dittoSeq 直接处理在其他软件包(Seurat、scater、scran 等)中预处理的数据。对于批量 RNAseq 数据,dittoSeq 的导入函数会将各种不同结构的批量 RNAseq 数据转换为 dittoSeq 帮助程序和可视化函数可以使用的集合结构

1. \color{green}{scRNA- seq}数据

dittoSeq 本身可与 Seurat 和 SingleCellExperiment 对象配合使用,只需加载数据即可

# 安装并加载所需的R包
# BiocManager::install("dittoSeq")
library(dittoSeq)
library(dplyr)

load("sce.Rdata") # 加载自己的单细胞数据

dittoPlot(sce,
          "MS4A1", # 感兴趣的基因
          group.by = "orig.ident", # 讲将细胞/样本分组的选项
          plots = c("vlnplot", "boxplot"), # 设置绘图类型,包括:jitter, boxplot, vlnplot, ridgeplot。注意顺序
          boxplot.fill = F, # 是否显示异常值
          boxplot.color = 'white', # 箱线图线条颜色
          theme = theme(axis.text = element_text(size = 12, color = 'black'),
                        axis.line = element_line(size = 1),
                        axis.title.y = element_text(size = 15, color = 'black'),
                        plot.title = element_text(size=15, hjust=0.5, color = 'black')),
          ylab = 'Expression',
          y.breaks = seq(0, 5, 1),
          max = 5, min = 0,
          xlab = '',
          x.labels.rotate =F,
          main = "MS4A1",
          legend.show = F)
dittoSeq-1

1.2 细胞比例图

# seurat等单细胞可视化工具在查看细胞比例柱状图时,需先进行细胞比例计算,这里可以直接作图。数据可以表示为百分比或计数,由"scale"输入控制的
p1 <- dittoBarPlot(sce, "Major.CellType", group.by = "orig.ident")
p2 <- dittoBarPlot(sce, "Major.CellType", group.by = "orig.ident", scale = "count")

p1|p2
dittoSeq-2
# dittoFreqPlot可按每种细胞类型分面,sample.by可将组内的细胞分组,group.by成单独的样本
dittoFreqPlot(sce, "Major.CellType", sample.by = "orig.ident", group.by = "class")
dittoSeq-3

2. \color{green}{Bulk} \color{green}{RNA- seq}数据

# 加载数据(制作模拟的表达数据和条件数据)
exp <- matrix(rpois(20000, 5), ncol=20)
colnames(exp) <- paste0("donor", seq_len(ncol(exp)))
rownames(exp) <- paste0("gene", seq_len(nrow(exp)))
logexp <- logexp <- log2(exp + 1)

logexp[1:3,1:6]
##         donor1   donor2   donor3   donor4   donor5   donor6
## gene1 2.584963 1.584963 3.000000 2.000000 2.584963 2.584963
## gene2 1.000000 2.807355 2.584963 2.584963 2.807355 1.584963
## gene3 2.000000 3.000000 2.000000 2.807355 1.584963 3.000000

pca <- matrix(rnorm(20000), nrow=20)
conditions <- factor(rep(1:4, 5))
sex <- c(rep("M", 9), rep("F", 11))

# dittoSeq 本身可处理存储为 SummarizedExperiment 对象的批量 RNAseq 数据
library(SummarizedExperiment)
bulkSE <- SummarizedExperiment(
  assays = list(counts = exp,
                logcounts = logexp), # 每个相当于一个表达矩阵,可存储counts矩阵、TPM矩阵和FPKM矩阵等
  colData = data.frame(conditions = conditions,
                       sex = sex) # 可添加行信息(基因信息,比如gene id, gene name, gene type等)和列信息(样本信息,比如生存时间、生存状态等)
)

# 或者,也可以使用 importDittoBulk() 函数将以其他形式存储的批量数据转换为 SingleCellExperiment 结构
bulkSCE <- importDittoBulk(
    x = list(counts = exp,
             logcounts = logexp), # x可以是 DGEList、DESeqDataSet、SummarizedExperiment 或数据矩阵列表
    metadata = data.frame(conditions = conditions,
                          sex = sex),
    reductions = list(pca = pca)
    )

# meta数据和降维也可以后续添加
bulkSCE$conditions <- conditions
bulkSCE$sex <- sex

bulkSCE <- addDimReduction(
  object = bulkSCE,
  embeddings = pca,
  name = "pca",
  key = "PC")

# 可视化
dittoDimPlot(bulkSCE, "sex", size = 3, do.ellipse = TRUE)

dittoBarPlot(bulkSCE, "sex", group.by = "conditions")

dittoBoxPlot(bulkSCE, "gene1", group.by = "sex")

dittoHeatmap(bulkSCE, getGenes(bulkSCE)[1:10],
             annot.by = c("conditions", "sex"))
dittoSeq-4

3. \color{green}{其他参数}设置

3.1 dittoDimPlot & dittoScatterPlot

# dittoScatterPlot() 的轴是基因表达数据或meta数据,dittoDimPlot() 的轴是降维,如 tsne、pca、umap 或类似数据
dittoScatterPlot(
  object = sce,
  x.var = "nCount_RNA", y.var = "nFeature_RNA",
  color.var = "percent.mito")

dittoDimPlot(sce, "cluster",
             do.label = TRUE,
             labels.repel = FALSE,
             
             add.trajectory.lineages = list(
               c("9","3"),
               c("8","7","2","4"),
               c("8","7","1"),
               c("5","11","6"),
               c("10","0")),
             trajectory.cluster.meta = "cluster")
dittoSeq-5

3.2 dittoDimHex & dittoScatterHex

# 与“Plot”版本类似,绘图区域被分成六边形箱
dittoScatterHex(
  object = sce,
  x.var = "PPY", y.var = "INS",
  color.var = "label",
  colors = c(1:4,7), max.density = 15)

dittoDimHex(sce, "INS")
dittoSeq-6

3.3 dittoPlot (and dittoRidgePlot + dittoBoxPlot wrappers)

# dittoPlot() 是主函数,dittoRidgePlot() 和 dittoBoxPlot() 本质上只是将输入图的默认值从 c(“jitter”, “vlnplot”) 调整为c(“ridgeplot”) 或  or c(“boxplot”,“jitter”)
dittoPlot(sce, "ENO1", group.by = "label",
          plots = c("jitter", "vlnplot", "boxplot"), # <- order matters
          
          # change the color and size of jitter points
          jitter.color = "blue", jitter.size = 0.5,
          
          # change the outline color and width, and remove the fill of boxplots
          boxplot.color = "white", boxplot.width = 0.1,
          boxplot.fill = FALSE,
          
          # change how the violin plot widths are normalized across groups
          vlnplot.scaling = "count"
)


dittoRidgePlot(sce, "ENO1", group.by = "label")

dittoBoxPlot(sce, "ENO1", group.by = "label")
dittoSeq-7

3.4 dittoHeatmap

# Pick Genes
genes <- c("SST", "REG1A", "PPY", "INS", "CELA3A", "PRSS2", "CTRB1",
           "CPA1", "CTRB2" , "REG3A", "REG1B", "PRSS1", "GCG", "CPB1",
           "SPINK1", "CELA3B", "CLPS", "OLFM4", "ACTG1", "FTL")


dittoHeatmap(sce, genes,
             annot.by = c("label", "donor"),
             order.by = "donor",
             scaled.to.max = TRUE,
             show_colnames = FALSE,
             show_rownames = FALSE)

# Highlight certain genes
dittoHeatmap(sce, genes, 
             annot.by = c("label", "donor"),
             highlight.features = genes[1:3],
             complex = TRUE)
dittoSeq-8

3.5 Multi-Plotters (创建多个图,或将多个变量的数据汇总在一个图中)

3.5.1 dittoDotPlot

delta.genes <- c(
  "SST", "RBP4", "LEPR", "PAPPA2", "LY6H",
  "CBLN4", "GPX3", "BCHE", "HHEX", "DPYSL3",
  "SERPINA1", "SEC11C", "ANXA2", "CHGB", "RGS2",
  "FXYD6", "KCNIP1", "SMOC1", "RPL10", "LRFN5")


dittoDotPlot(sce, vars = delta.genes, 
             group.by = "label",
             scale = FALSE)
dittoSeq-9

3.5.2 multi_dittoPlot & dittoPlotVarsAcrossGroups

multi_dittoPlot(sce, delta.genes[1:6], 
                group.by = "label",
                vlnplot.lineweight = 0.2, jitter.size = 0.3)

dittoPlotVarsAcrossGroups(sce, delta.genes, 
                          group.by = "label",
                          main = "Delta-cell Markers")
dittoSeq-10

3.5.3 multi_dittoDimPlot & multi_dittoDimPlotVaryCells

multi_dittoDimPlot(sce, delta.genes[1:6])

multi_dittoDimPlotVaryCells(sce, delta.genes[1],
                            vary.cells.meta = "label")
dittoSeq-11

相关文章

网友评论

      本文标题:R语言可视化11: (sc)RNAseq 数据可视化 - dit

      本文链接:https://www.haomeiwen.com/subject/zghvodtx.html