TCGA差异分析——limma, DEseq2, edgeR

TCGA转录组数据

转录组数据的差异分析与芯片数据的差异分析有不同,这里我们使用count数据,因为这几种包中包装了标准化的函数,只需要程序化的输入两个数据,count矩阵和group数据,就能得到差异分析的结果。那么三种差异分析的包有什么差异呢?

一、数据整理

这里我们需要count矩阵,以及对应的分组信息

rm(list = ls())
library(tidyverse)
library(limma)
library(stringr)
library(xlsx)
library(edgeR)
load("count_exp.Rdata")
cli <- read.xlsx2("../2.clinical/cli.xlsx",sheetIndex = 2)
#-------------------------------------------------------------------------
group <- cli[,c(1,10)]         

dat <- count_exp[,str_sub(colnames(count_exp),1,15)%in%group$Sample.ID]
group <- group[group$Sample.ID%in%str_sub(colnames(count_exp),1,15),]
dat <- dat[,match(group$Sample.ID,str_sub(colnames(dat),1,15))] %>% 
  as.data.frame()
Group <- factor(rep(c("re","non_re"),times=c(26,47)),levels = c("non_re","re"))
table(Group)

二、limma包

#-----limma------------------------------------------------------------------
design <- model.matrix(~0+Group)
colnames(design)= levels(Group)
rownames(design)=colnames(dat)

dge <- DGEList(counts=dat)
dge <- calcNormFactors(dge)

v <- voom(dge,design, normalize="quantile")
fit <- lmFit(v, design)

constrasts = paste(rev(levels(Group)),collapse = "-")
cont.matrix <- makeContrasts(contrasts=constrasts,levels = design) 
fit2=contrasts.fit(fit,cont.matrix)
fit2=eBayes(fit2)

DEG = topTable(fit2, coef=constrasts, n=Inf)
DEG = na.omit(DEG)

logFC_t=1
P.Value_t = 0.05
k1 = (DEG$P.Value < P.Value_t)&(DEG$logFC < -logFC_t)
k2 = (DEG$P.Value < P.Value_t)&(DEG$logFC > logFC_t)
change = ifelse(k1,"down",ifelse(k2,"up","stable"))
DEG$change <- change

DEG_limma <- DEG
save(DEG_limma,group,file = "DEG_limma.Rdata")

二、DESeq2包

#--DESeq2----------------------------------------------------------------------------
library(DESeq2)
dat <- apply(dat,2,as.integer)    #整数转换
rownames(dat) <- rownames(count_exp)
colData <- data.frame(row.names =colnames(dat), 
                      condition=Group)
dds <- DESeqDataSetFromMatrix(
  countData = dat,
  colData = colData,
  design = ~ condition)
dds <- DESeq(dds)
res <- results(dds, contrast = c("condition",rev(levels(Group))))
resOrdered <- res[order(res$pvalue),] # 按照P值排序
DEG <- as.data.frame(resOrdered)
DEG = na.omit(DEG)
head(DEG)

logFC_t=1
P.Value_t = 0.05
k1 = (DEG$padj < P.Value_t)&(DEG$log2FoldChange < -logFC_t)
k2 = (DEG$padj < P.Value_t)&(DEG$log2FoldChange > logFC_t)
change = ifelse(k1,"down",ifelse(k2,"up","stable"))
DEG$change <- change

#down stable     up 
#131  17964     40 

DEG_DEseq2 <- DEG
save(DEG_DEseq2,group,file = "DEG_DEseq2.Rdata")

三、edegR包

#---edgeR------------------------------------------------------------------
library(edgeR)

dge <- DGEList(counts=dat,group=Group)
dge$samples$lib.size <- colSums(dge$counts)
dge <- calcNormFactors(dge) 

design <- model.matrix(~0+Group)
rownames(design)<-colnames(dge)
colnames(design)<-levels(Group)

dge <- estimateGLMCommonDisp(dge, design)
dge <- estimateGLMTrendedDisp(dge, design)
dge <- estimateGLMTagwiseDisp(dge, design)

fit <- glmFit(dge, design)
fit2 <- glmLRT(fit, contrast=c(-1,1)) 

DEG=topTags(fit2, n=nrow(exp))
DEG=as.data.frame(DEG)

logFC_t=1
P.Value_t = 0.05
k1 = (DEG$PValue < P.Value_t)&(DEG$logFC < -logFC_t)
k2 = (DEG$PValue < P.Value_t)&(DEG$logFC > logFC_t)
change = ifelse(k1,"down",ifelse(k2,"up","stable"))
DEG$change <- change

#down stable     up 
# 891  18206    408 

DEG_edgeR <- DEG
save(DEG_edgeR,group,file = "DEG_edgeR.Rdata")

看看三个包的基因交叉情况

这里,我们使用upset图进行绘制

代码如下:

rm(list = ls())
load("DEG_limma.Rdata")
load("DEG_DEseq2.Rdata")
load("DEG_edgeR.Rdata")
UP=function(df){
  rownames(df)[df$change=="up"]
}
DOWN=function(df){
  rownames(df)[df$change=="down"]
}
DIFF=function(df){
  rownames(df)[df$change != "stable"]
}
  


up = intersect(intersect(UP(DEG_DEseq2),UP(DEG_edgeR)),UP(DEG_limma))
down = intersect(intersect(DOWN(DEG_DEseq2),DOWN(DEG_edgeR)),DOWN(DEG_limma))


#上调、下调基因分别画维恩图
up_genes = list(UP(DEG_DEseq2),
                UP(DEG_edgeR),
                UP(DEG_limma))

down_genes = list(DOWN(DEG_DEseq2),
                  DOWN(DEG_edgeR),
                  DOWN(DEG_limma))
library(gplots)
venn(up_genes,show.plot = T)
venn(down_genes)

#汇集信息,绘制upset图
library(UpSetR)
input <- c("DEG_DEseq2"=171,
           "DEG_edgeR"=1299,
           "DEG_limma"=178,
           "DEG_limma&DEG_edgeR"=121,
           "DEG_limma&DEG_DEseq2"=47,
           "DEG_DEseq2&DEG_edgeR"=141,
           "DEG_limma&DEG_edgeR&DEG_DEseq2"=44)
data <- fromExpression(input)
upset(data)
upset

最后

可以看到,三个包得到的差异基因还是有差异的,在在这里,我的样本数目较少,使用的TCGA晚期复发-未晚期复发的数据。

你可能感兴趣的:(TCGA差异分析——limma, DEseq2, edgeR)