R语言可视化12: (sc)RNAseq 数据可视化 - scRNAtoolVis

scRNAtoolVis适用于各种单细胞RNA-seq数据分析场景,包括但不限于:
单细胞Marker基因表达热图:通过热图展示不同细胞亚群中Marker基因的表达水平。
单细胞火山图:快速识别差异表达基因。
单细胞散点图:直观展示细胞间的差异和相似性。

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

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

# 安装并加载所需的R包
# install.packages("devtools")
# devtools::install_github("junjunlab/scRNAtoolVis")
library(scRNAtoolVis)

load('scRNA_harmony.Rdata')
head('scRNA_harmony.Rdata')
                                   orig.ident  nCount_RNA  nFeature_RNA    Condition   Sample  RNA_snn_res.0.8 seurat_clusters              celltype             celltype_anno   GEO_accession
GSE200997_T_cac1_AAACCTGAGAATAGGG           T         922           504        Tumor   T_cac1                5               5      Epithelial_cells    Epithelial tumor cells       GSE200997
GSE200997_T_cac1_AAACCTGAGCAGCGTA           T       11519          3177        Tumor   T_cac1               11              11           Fibroblasts                      CAFs       GSE200997
GSE200997_T_cac1_AAACCTGCAATCTGCA           T         831           465        Tumor   T_cac1                5               5      Epithelial_cells    Epithelial tumor cells       GSE200997
GSE200997_T_cac1_AAACCTGGTCTTGCGG           T         527           329        Tumor   T_cac1                5               5      Epithelial_cells    Epithelial tumor cells       GSE200997
GSE200997_T_cac1_AAACCTGGTGTGCCTG           T        8388          2887        Tumor   T_cac1.              10              10  Embryonic_stem_cells    Epithelial tumor cells       GSE200997
GSE200997_T_cac1_AAACGGGTCGTTACAG           T        8485          2293        Tumor   T_cac1                4               4      Epithelial_cells    Epithelial tumor cells       GSE200997
GSE200997_T_cac1_AAACGGGTCTCAACTT           T         653           473        Tumor   T_cac1                1               1               T_cells                CD8 T cell       GSE200997
GSE200997_T_cac1_AAACGGGTCTTGCCGT           T        4978          1728        Tumor   T_cac1                4               4      Epithelial_cells    Epithelial tumor cells       GSE200997
GSE200997_T_cac1_AAAGATGCAAGACACG           T        9214          2258        Tumor   T_cac1                4               4      Epithelial_cells    Epithelial tumor cells       GSE200997
GSE200997_T_cac1_AAAGATGCACAACTGT           T        5978          2081        Tumor   T_cac1               10              10  Embryonic_stem_cells    Epithelial tumor cells       GSE200997

2. UMAP/tSNE图(clusterCornerAxes / featureCornerAxes)

clusterCornerAxes(object = scRNA_harmony,reduction = 'umap',
                  clusterCol = "celltype_anno",  # 分组依据的集群名称,默认 "seurat_clusters"
                  pSize = 0.1,
                  arrowType = 'open', # 箭头的类型,默认 "closed"
                  lineTextcol = 'grey50', # 角线和标签颜色, 默认 "black"
                  cornerTextSize = 3.5,
                  # keySize = 2, # 图注的大小
                  show.legend = F, # 不显示图注
                  cellLabel = T, cellLabelSize = 5, # 细胞标签及字体大小
                  noSplit = T,
                  # themebg = 'bwCorner', # 主题
                  addCircle = TRUE,   # 添加圆圈
                  cicAlpha = 0.1, cicDelta = 0.5
                  nbin = 200)
scRNAtoolVis-1
featureCornerAxes(object = scRNA_harmony, reduction = 'umap',
                  groupFacet = 'celltype',
                  # groupFacet = NULL,
                  relLength = 0.5,
                  relDist = 0.2,
                  features = c("CD37","FCMR","TNFRSF13C"),
                  show.legend = F # 去除图例
                  )
scRNAtoolVis-2

3. Marker基因表达热图(averageHeatmap)

markers <- FindAllMarkers(object = scRNA_harmony, test.use="wilcox" ,
                         only.pos = TRUE,
                         logfc.threshold = 0.25)

top5_gene = markers %>% group_by(cluster) %>% top_n(n = 5, wt=avg_log2FC)

averageHeatmap(object = scRNA_harmony,
               markerGene = top5_gene$gene,
               # group.by = 'celltype_anno',
               # htCol = c("#339933", "#FFCC00", "#FF0033"), # 修改热图的颜色
               gene.order = top5_gene$gene,
               # width = 12, height = 16,
               myanCol = celltype_colors, # 自定义注释集群颜色
               column_split = 1:14, # 分割列
               row_split = rep(1:14, each = 5),  # 分割行
               border = T)
scRNAtoolVis-3

4. 火山图(averageHeatmap)

# 获取所有簇的标签
clusters <- levels(scRNA_harmony@active.ident)

# 创建一个列表来存储每个簇中健康和重度分组的差异表达基因
markers_list <- list()


# 对每个簇中的健康和重度分组分别运行 FindMarkers
for (cluster in clusters) {
  # 提取当前簇中的细胞
  cells_in_cluster <- WhichCells(scRNA_harmony, idents = cluster)
  
  # 提取健康和重度分组的细胞
  cells_TLS_High <- cells_in_cluster[scRNA_harmony$TLS[cells_in_cluster] == "TLS_High"]
  cells_TLS_Low <- cells_in_cluster[scRNA_harmony$TLS[cells_in_cluster] == "TLS_Low"]
  
  if (length(cells_TLS_High) > 0 && length(cells_TLS_Low) > 0) {
    # 运行 FindMarkers
    markers <- FindMarkers(scRNA_harmony, ident.1 = cells_TLS_Low, ident.2 = cells_TLS_High)
    
    # 将结果存储在列表中
    comparison_name <- paste0("TLS_", cluster, "_Low_vs_High")
    markers_list[[comparison_name]] <- markers
  }
}

# 添加cluster列
markers_list[["TLS_CD4 memory T cells_Low_vs_High"]]$cluster = 'CD4 memory T cells'
markers_list[["TLS_CD8 T cell_Low_vs_High"]]$cluster = 'CD8 T cell'
markers_list[["TLS_Plasma_Low_vs_High"]]$cluster = 'Plasma'
markers_list[["TLS_Tregs_Low_vs_High"]]$cluster = 'Tregs'
markers_list[["TLS_Epithelial tumor cells_Low_vs_High"]]$cluster = 'Epithelial tumor cells'
markers_list[["TLS_B activated_Low_vs_High"]]$cluster = 'B activated'
markers_list[["TLS_Macro_Mono_Low_vs_High"]]$cluster = 'Macro_Mono'
markers_list[["TLS_Endothelial Cell_Low_vs_High"]]$cluster = 'Endothelial Cell'
markers_list[["TLS_CAFs_Low_vs_High"]]$cluster = 'CAFs'
markers_list[["TLS_T cell_Low_vs_High"]]$cluster = 'T cell'
markers_list[["TLS_B cells_Low_vs_High"]]$cluster = 'B cells'
markers_list[["TLS_MEP_Low_vs_High"]]$cluster = 'MEP'
markers_list[["TLS_Memory B cells_Low_vs_High"]]$cluster = 'Memory B cells'
markers_list[["TLS_DC cell_Low_vs_High"]]$cluster = 'DC cell'


markers_list[["TLS_CD4 memory T cells_Low_vs_High"]]$gene = row.names(markers_list[["TLS_CD4 memory T cells_Low_vs_High"]])
markers_list[["TLS_CD8 T cell_Low_vs_High"]]$gene = row.names(markers_list[["TLS_CD8 T cell_Low_vs_High"]])
markers_list[["TLS_Plasma_Low_vs_High"]]$gene = row.names(markers_list[["TLS_Plasma_Low_vs_High"]])
markers_list[["TLS_Tregs_Low_vs_High"]]$gene = row.names(markers_list[["TLS_Tregs_Low_vs_High"]])
markers_list[["TLS_Epithelial tumor cells_Low_vs_High"]]$gene = row.names(markers_list[["TLS_Epithelial tumor cells_Low_vs_High"]])
markers_list[["TLS_B activated_Low_vs_High"]]$gene = row.names(markers_list[["TLS_B activated_Low_vs_High"]])
markers_list[["TLS_Macro_Mono_Low_vs_High"]]$gene = row.names(markers_list[["TLS_Macro_Mono_Low_vs_High"]])
markers_list[["TLS_Endothelial Cell_Low_vs_High"]]$gene = row.names(markers_list[["TLS_Endothelial Cell_Low_vs_High"]])
markers_list[["TLS_CAFs_Low_vs_High"]]$gene = row.names(markers_list[["TLS_CAFs_Low_vs_High"]])
markers_list[["TLS_T cell_Low_vs_High"]]$gene = row.names(markers_list[["TLS_T cell_Low_vs_High"]])
markers_list[["TLS_B cells_Low_vs_High"]]$gene = row.names(markers_list[["TLS_B cells_Low_vs_High"]])
markers_list[["TLS_MEP_Low_vs_High"]]$gene = row.names(markers_list[["TLS_MEP_Low_vs_High"]])
markers_list[["TLS_Memory B cells_Low_vs_High"]]$gene = row.names(markers_list[["TLS_Memory B cells_Low_vs_High"]])
markers_list[["TLS_DC cell_Low_vs_High"]]$gene = row.names(markers_list[["TLS_DC cell_Low_vs_High"]])

# 使用bind_rows合并数据框
merged_markers <- bind_rows(markers_list)
merged_markers$cluster = factor(merged_markers$cluster, levels = c("Epithelial_cells","Fibroblasts","Embryonic_stem_cells","T_cells","B_cell",
                                                                   "Monocyte","Endothelial_cells","Macrophage","Gametocytes","Tissue_stem_cells","MEP" ))

markerVolcano(markers = merged_markers,
              topn = 5,
              labelCol = c('#C6DADF','#E26EB8','#918FBE','#A2C5A6','#EED784','#B088BB','#DEDCED','#6E8BD5','#D4B796',
                           '#F5BDC8','#DAB6F7','#EFE2E6','#F0BDD8','#77A1EC','#F8D39C','#F17591','#50C2FB','#EEB96A'
                           ,'#81C28F','#E3ECC1','#F9E3DC','#A133CC','#DFB9D5','#EFC1ED','#FAE3DC'))
scRNAtoolVis-4

5. 散点图(jjDotPlot)

jjDotPlot(object = scRNA_harmony,
          gene = top5_gene$gene,
          id = 'celltype_anno',
          xtree = T,
          point.shape = 22,
          dot.col = c('blue','white','red'),
          rescale.min = -2,
          rescale.max = 2,
          midpoint = 0,
          anno = T
          )
scRNAtoolVis-5
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容