1. 三個(gè)數(shù)據(jù)集差異基因火山圖(每10個(gè)腫瘤和正常組織樣本)
導(dǎo)入表達(dá)矩陣,選擇NT組的前10和TP組的前10個(gè)樣本進(jìn)行差異分析
library(TCGAbiolinks)
# 導(dǎo)入dataFilt表達(dá)矩陣
load("dataFilt.RData")
# selection of normal samples "NT"
samplesNT <- TCGAquery_SampleTypes(barcode = colnames(dataFilt),
typesample = c("NT"))
# selection of tumor samples "TP"
samplesTP <- TCGAquery_SampleTypes(barcode = colnames(dataFilt),
typesample = c("TP"))
# Diff.expr.analysis (DEA)
DEG.LUAD.edgeR <- TCGAanalyze_DEA(mat1 = dataFilt[,samplesNT[1:10]],
mat2 = dataFilt[,samplesTP[1:10]],
pipeline="edgeR",
batch.factors = c("TSS"),
Cond1type = "Normal",
Cond2type = "Tumor",
voom =FALSE,
method = "glmLRT",
# fdr.cut = 0.01, #保留FDR<0.01的基因
# logFC.cut = 1 #保留logFC>1的基因
)
# ----------------------- DEA -------------------------------
# there are Cond1 type Normal in 10 samples
# there are Cond2 type Tumor in 10 samples
# there are 12980 features as miRNA or genes
# I Need about 8.7 seconds for this DEA. [Processing 30k elements /s]
# ----------------------- END DEA -------------------------------
繪制第一個(gè)火山圖
valcano_data <- data.frame(genes=rownames(DEG.LUAD.edgeR),
logFC=DEG.LUAD.edgeR$logFC,
FDR=DEG.LUAD.edgeR$FDR,
group=rep("NotSignificant",
nrow(DEG.LUAD.edgeR)),
stringsAsFactors = F)
valcano_data[which(valcano_data['FDR'] < 0.05 &
valcano_data['logFC'] > 1.5),"group"] <- "Increased"
valcano_data[which(valcano_data['FDR'] < 0.05 &
valcano_data['logFC'] < -1.5),"group"] <- "Decreased"
cols = c("darkgrey","#00B2FF","orange")
names(cols) = c("NotSignificant","Increased","Decreased")
library(ggplot2)
vol1 <- ggplot(valcano_data, aes(x = logFC, y = -log10(FDR), color = group))+
scale_colour_manual(values = cols) +
ggtitle(label = "Volcano Plot 1", subtitle = "LUAD 1-10 samples volcano plot") +
geom_point(size = 2.5, alpha = 1, na.rm = T) +
theme_bw(base_size = 14) +
theme(legend.position = "right") +
xlab(expression(log[2]("logFC"))) +
ylab(expression(-log[10]("FDR"))) +
geom_hline(yintercept = 1.30102, colour="#990000", linetype="dashed") +
geom_vline(xintercept = 1.5849, colour="#990000", linetype="dashed") +
geom_vline(xintercept = -1.5849, colour="#990000", linetype="dashed")+
scale_y_continuous(trans = "log1p")
選擇NT組的11-20和TP組的11-20樣本進(jìn)行差異分析
# Diff.expr.analysis (DEA)
DEG.LUAD.edgeR2 <- TCGAanalyze_DEA(mat1 = dataFilt[,samplesNT[11:20]],
mat2 = dataFilt[,samplesTP[11:20]],
pipeline="edgeR",
batch.factors = c("TSS"),
Cond1type = "Normal",
Cond2type = "Tumor",
voom =FALSE,
method = "glmLRT",
# fdr.cut = 0.01, #保留FDR<0.01的基因
# logFC.cut = 1 #保留logFC>1的基因
)
# ----------------------- DEA -------------------------------
# there are Cond1 type Normal in 10 samples
# there are Cond2 type Tumor in 10 samples
# there are 12980 features as miRNA or genes
# I Need about 8.7 seconds for this DEA. [Processing 30k elements /s]
# ----------------------- END DEA -------------------------------
繪制第2個(gè)火山圖
valcano_data2 <- data.frame(genes=rownames(DEG.LUAD.edgeR2),
logFC=DEG.LUAD.edgeR2$logFC,
FDR=DEG.LUAD.edgeR2$FDR,
group=rep("NotSignificant",
nrow(DEG.LUAD.edgeR2)),
stringsAsFactors = F)
valcano_data2[which(valcano_data2['FDR'] < 0.05 &
valcano_data2['logFC'] > 1.5),"group"] <- "Increased"
valcano_data2[which(valcano_data2['FDR'] < 0.05 &
valcano_data2['logFC'] < -1.5),"group"] <- "Decreased"
cols = c("darkgrey","#00B2FF","orange")
names(cols) = c("NotSignificant","Increased","Decreased")
library(ggplot2)
vol2 <- ggplot(valcano_data2, aes(x = logFC, y = -log10(FDR), color = group))+
scale_colour_manual(values = cols) +
ggtitle(label = "Volcano Plot 2", subtitle = "LUAD 11-20 volcano plot") +
geom_point(size = 2.5, alpha = 1, na.rm = T) +
theme_bw(base_size = 14) +
theme(legend.position = "right") +
xlab(expression(log[2]("logFC"))) +
ylab(expression(-log[10]("FDR"))) +
geom_hline(yintercept = 1.30102, colour="#990000", linetype="dashed") +
geom_vline(xintercept = 1.5849, colour="#990000", linetype="dashed") +
geom_vline(xintercept = -1.5849, colour="#990000", linetype="dashed")+
scale_y_continuous(trans = "log1p")
選擇NT組的21-30和TP組的21-30樣本進(jìn)行差異分析
# Diff.expr.analysis (DEA)
DEG.LUAD.edgeR3 <- TCGAanalyze_DEA(mat1 = dataFilt[,samplesNT[21:30]],
mat2 = dataFilt[,samplesTP[21:30]],
pipeline="edgeR",
batch.factors = c("TSS"),
Cond1type = "Normal",
Cond2type = "Tumor",
voom =FALSE,
method = "glmLRT",
# fdr.cut = 0.01, #保留FDR<0.01的基因
# logFC.cut = 1 #保留logFC>1的基因
)
# ----------------------- DEA -------------------------------
# there are Cond1 type Normal in 10 samples
# there are Cond2 type Tumor in 10 samples
# there are 12980 features as miRNA or genes
# I Need about 8.7 seconds for this DEA. [Processing 30k elements /s]
# ----------------------- END DEA -------------------------------
繪制第3個(gè)火山圖
valcano_data3 <- data.frame(genes=rownames(DEG.LUAD.edgeR3),
logFC=DEG.LUAD.edgeR3$logFC,
FDR=DEG.LUAD.edgeR3$FDR,
group=rep("NotSignificant",
nrow(DEG.LUAD.edgeR3)),
stringsAsFactors = F)
valcano_data3[which(valcano_data3['FDR'] < 0.05 &
valcano_data3['logFC'] > 1.5),"group"] <- "Increased"
valcano_data3[which(valcano_data3['FDR'] < 0.05 &
valcano_data3['logFC'] < -1.5),"group"] <- "Decreased"
cols = c("darkgrey","#00B2FF","orange")
names(cols) = c("NotSignificant","Increased","Decreased")
library(ggplot2)
vol3 <- ggplot(valcano_data3, aes(x = logFC, y = -log10(FDR), color = group))+
scale_colour_manual(values = cols) +
ggtitle(label = "Volcano Plot 3", subtitle = "LUAD 21-30 volcano plot") +
geom_point(size = 2.5, alpha = 1, na.rm = T) +
theme_bw(base_size = 14) +
theme(legend.position = "right") +
xlab(expression(log[2]("logFC"))) +
ylab(expression(-log[10]("FDR"))) +
geom_hline(yintercept = 1.30102, colour="#990000", linetype="dashed") +
geom_vline(xintercept = 1.5849, colour="#990000", linetype="dashed") +
geom_vline(xintercept = -1.5849, colour="#990000", linetype="dashed")+
scale_y_continuous(trans = "log1p")
library(cowplot)
library(patchwork)
vol1+vol2+vol3
2. upset圖和韋恩圖分析
提取3個(gè)數(shù)據(jù)的差異基因列表
DEG1_up <- valcano_data[valcano_data$group=="Increased", "genes"]
DEG1_down <- valcano_data[valcano_data$group=="Decreased", "genes"]
DEG2_up <- valcano_data[valcano_data2$group=="Increased", "genes"]
DEG2_down <- valcano_data[valcano_data2$group=="Decreased", "genes"]
DEG3_up <- valcano_data[valcano_data3$group=="Increased", "genes"]
DEG3_down <- valcano_data[valcano_data3$group=="Decreased", "genes"]
用Y叔開發(fā)的ggupset做Upset圖
# devtools::install_github("GuangchuangYu/yyplot")
# devtools::install_github("GuangchuangYu/UpSetR")
# install.packages("venneuler")
# remove.packages("ggplot2")
# install.packages("ggimage")
# if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
# BiocManager::install("ComplexHeatmap")
# 上調(diào)基因
lt_up = list(TCGA_1 = DEG1_up,
TCGA_2 = DEG2_up,
TCGA_3 = DEG3_up)
dat_up<- ComplexHeatmap::list_to_matrix(lt_up)
dat_plot_up <- data.frame(dat_up)
require(UpSetR)
p1 <- upset(dat_plot_up, sets=c("TCGA_3", "TCGA_2", "TCGA_1"),
keep.order = TRUE)
require(ggplotify)
g1 <- as.ggplot(p1) + ggtitle("Up regulated")
# 下調(diào)基因
lt_down = list(TCGA_1 = DEG1_down,
TCGA_2 = DEG2_down,
TCGA_3 = DEG3_down)
dat_down<- ComplexHeatmap::list_to_matrix(lt_down)
dat_plot_down <- data.frame(dat_down)
require(UpSetR)
p2 <- upset(dat_plot_down, , sets=c("TCGA_3", "TCGA_2", "TCGA_1"),
keep.order = TRUE)
require(ggplotify)
g2 <- as.ggplot(p2) + ggtitle("Down regulated")
# 拼圖
library(cowplot)
library(patchwork)
g1+g2
做韋恩圖
require(yyplot)
library("ggsci")
g3 <- ggvenn(dat_plot_up) + theme_void() +
scale_fill_jco() + ggtitle("Up regulated genes")
g4 <- ggvenn(dat_plot_down) + theme_void() +
scale_fill_jco() + ggtitle("Down regulated genes")
g3 + g4
upset和韋恩圖拼接
require(ggimage)
g1_3 <- g1 + geom_subview(subview=g3+theme_void(), x=.78, y=.8, w=.5, h=.5)
g2_4 <- g2 + geom_subview(subview=g4+theme_void(), x=.78, y=.8, w=.5, h=.5)
g1_3+g2_4
3. 火山圖、upset圖+韋恩圖合并
(vol1|vol2|vol3)/
(g1_3|g2_4)
挑選出三個(gè)數(shù)據(jù)集中共同上調(diào)或下調(diào)的基因
up_common <- Reduce(intersect, list(DEG1_up, DEG2_up, DEG3_up))
down_common <- Reduce(intersect, list(DEG1_down, DEG2_down, DEG3_down))
background_genes <- Reduce(union, list(DEG1_up, DEG2_up, DEG3_up,
DEG1_down, DEG2_down, DEG3_down))
up_common_df <- data.frame(gene=up_common,
logFC=valcano_data[valcano_data$genes %in%
up_common,
"logFC"])
down_common_df <- data.frame(gene=down_common,
logFC=valcano_data[valcano_data$genes %in%
down_common,
"logFC"])
background_genes_df <- data.frame(gene=background_genes,
logFC=valcano_data[valcano_data$genes %in%
background_genes,
"logFC"], stringsAsFactors = F)
all_gene_df <- valcano_data[, c("genes", "logFC")]
save(list=c("up_common_df", "down_common_df", "background_genes_df", "all_gene_df"),
file="filtered_genes.RData")