-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTEP4_DE_enrichment.R
More file actions
81 lines (62 loc) · 2.28 KB
/
STEP4_DE_enrichment.R
File metadata and controls
81 lines (62 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
load("Data/STEP2_de_result.RData")
load("Data/STEP1_input.RData")
source("utils.R")
#===模式生物的KEGG富集分析,enrichKEGG ===
data(geneList, package="DOSE")
gene <- names(geneList)[abs(geneList) > 2]
kk <- enrichKEGG(gene = gene,
organism = 'hsa',
pvalueCutoff = 0.05)
head(kk)
#====非模式物种的KEGG富集分析enricher======
#第一步:准备数据
# ===1-关键基因的列表:pull将一个二维数据转化成一个一维数据,即直接返回一个向量
gene <- filter(de_result,
abs(log2FoldChange) > 1 & padj < 0.05) %>%
pull(id)
# ===2-TERM与基因对应关系信息
pathway2gene <- select(gene_mapper,
GID = Gene_Id,
KO = Ko,
Pathway = Pathway) %>%
dplyr::select(Pathway, GID) %>%
separate_rows(Pathway, sep=",", convert = F) %>%
filter(str_detect(Pathway, "ko")) %>%
mutate(Pathway = str_remove(Pathway, "ko"))
#===3-TERM2name用于获得kegg中path对应的name(描述)
library(magrittr)
get_path2name <- function(){
keggpathid2name.df <- clusterProfiler:::kegg_list("pathway")
keggpathid2name.df[,1] %<>% gsub("path:map", "", .)
colnames(keggpathid2name.df) <- c("path_id","path_name")
return(keggpathid2name.df)
}
pathway2name <-get_path2name()
head(pathway2name)
#===4-所有基因的FC信息
gene_list <- de_result$log2FoldChange
names(gene_list) <- de_result$id #有名字的向量
sort(gene_list, decreasing = T)
#第二步:KEGG富集分析
library(clusterProfiler)
de_ekp <- enricher(gene,
TERM2GENE = pathway2gene,
TERM2NAME = pathway2name,
pvalueCutoff = 0.05,
qvalueCutoff = 0.05)
de_ekp_df <- as.data.frame(de_ekp)
head(de_ekp_df)
save(de_ekp, de_ekp_df, file = "Data/STEP4_KEGG_enrichment.RData")
library(enrichplot)
barplot()
barplot(de_ekp, showCategory = 15)
dotplot(de_ekp, showCategory = 15)
cnetplot(de_ekp,
foldChange = gene_list,
#如果是个圈的话,这里可以选择节点标签 category | gene | all | none
node_label = "category",
circular = T,
colorEdge = T)
emapplot(de_ekp, showCategory = 10, pie = 'count')
library(pathview)
?pathview