admin管理员组

文章数量:1794759

转录组—多分组的差异基因的聚类分析

转录组—多分组的差异基因的聚类分析

好久没写帖子了,实在是没有时间。

这次的需求是将以下这张图(全部分组差异基因聚类),去除control组之后重新聚类。并且EGA分组改为Model+TreatA、EGB分组改为Model+TreatB。

这张图的分组信息见下图,可见是一个多分组的差异基因的比较,具体做了以下的组间比较。

在以往的分析中,我们往往关注2分组之间的差异基因聚类(即使是多分组,也是把相应的2分组单独挑出来分析),但是有一点是即使在不同的组间分析中,不管是用limma、还是edgeR、deseq2分析,计算后对应的基因矩阵值的是一致的。

我们先把每个分组,如B_vs_A、C_vs_A等,每个分组的差异基因保存出来,如下图,每个分组的DEG.xlsx,包含了该分组的全部差异基因(logFC=1、adj.P<0.05)。

基本思路是把,取每个分组(不包含A组,即control组)的差异基因的gene_id列,取出来做并集。然后在总的(包含全部基因、全部分组的基因表达矩阵)中,提取对应的行,再做聚类分析。

按照需求,在全部基因、全部分组的基因表达矩阵(下图)中,去除control组信息。

代码如下

代码语言:r复制
rm(list = ls()) 
#CvsB数据导入
library(dplyr)
library(readxl)
ega_model <- read_xlsx("../C_vs_B/DEG.xlsx")
ega_model <- as.data.frame(ega_model)
dim(ega_model)

egb_model <- read_xlsx("../D_vs_B/DEG.xlsx")
egb_model <- as.data.frame(egb_model)
dim(egb_model)

ega_egb <- read_xlsx("../C_vs_D/DEG.xlsx")
ega_egb <- as.data.frame(ega_egb)
dim(ega_egb)

tmp <- union(ega_model$gene_id,egb_model$gene_id)
geneid_union <- union(tmp,ega_egb$gene_id)
length(tmp)
length(geneid_union)#12670

#总表中把这些差异基因找出
exp <- read_xlsx("../Deg_genes_fpkm_of_all_samples.xlsx")
exp <- as.data.frame(exp)
dim(exp)
colnames(exp)
exp_filtered <- exp[exp$gene_id %in% geneid_union, ]
dim(exp_filtered)#12760


rownames(exp_filtered) <- exp_filtered$gene_id 
exp_filtered <- exp_filtered[, c("Model1", "Model2", "Model3",
                      "EGA1", "EGA2", "EGA3",
                      "EGB1", "EGB2", "EGB3")]

colnames(exp_filtered) <- gsub("^EGA", "Model+Treat A", colnames(exp_filtered))
colnames(exp_filtered) <- gsub("^EGB", "Model+Treat B", colnames(exp_filtered))


dim(exp_filtered)
#43884A 
#热图聚类绘制
library(pheatmap)
group_list <- c(rep("Model", 3), rep("Model+Treat A", 3), rep("Model+Treat B", 3))
annotation=data.frame(group=group_list)
rownames(annotation)=colnames(exp_filtered)
exp_filtered = t(scale(t(exp_filtered)))#使用t函数进行转置,然后scale每一列标准化,再次进行转置。
exp_filtered[exp_filtered > 3] = 3
exp_filtered[exp_filtered < -3] = -3

annotation_colors <- list(
  group = c("Model" = "#43884a",          # Model 颜色
           "Model+Treat A" = "#7E2F8a",  # Model+Treat A 颜色
           "Model+Treat B" = "#282e66")  # Model+Treat B 颜色
)

# 绘制热图
pheatmap(exp_filtered,
         annotation = annotation, 
         annotation_colors = annotation_colors,  # 添加自定义颜色
         show_colnames = TRUE,
         show_rownames = FALSE,
         cluster_cols = TRUE,
         fontsize = 9,
         height = 6,
         color = colorRampPalette(c("#282e66", "white", "#C43530"))(50),
         filename = "DEG_heatmap_anno_del_con1.pdf"# 显示 -3 到 3 的刻度标签# 自定义热图颜色
)

pheatmap(exp_filtered,
         annotation = annotation, 
         annotation_colors = annotation_colors,  # 添加自定义颜色
         show_colnames = TRUE,
         show_rownames = FALSE,
         cluster_cols = TRUE,
         fontsize = 9,
         height = 6,
         color = colorRampPalette(c("#282e66", "white", "#C43530"))(50),                   # 自定义热图颜色
         filename = "DEG_heatmap_anno_del_con.pdf"# 设置图例的刻度标签
)

最后结果如下,包含了除control分组中的全部差异基因聚类。

本文标签: 转录组多分组的差异基因的聚类分析