-
Notifications
You must be signed in to change notification settings - Fork 1
/
enrich_cluster.R
89 lines (78 loc) · 2.58 KB
/
enrich_cluster.R
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
82
83
84
85
86
87
88
library("clusterProfiler")
source('enrichr_v2.R')
options(ggrepel.max.overlaps = Inf)
##########################
#GO.ont = 'CC', 'BP', 'MO'
##########################
compareGO <- function(input.ls, GO.ont){
enrich <- compareCluster(geneCluster =input.ls,
fun = "enrichGO",
keyType = "SYMBOL",
ont = GO.ont,
OrgDb = "org.Hs.eg.db",
pAdjustMethod= "BH",
minGSSize = 1,
pvalueCutoff = 0.05,
qvalueCutoff = 0.05)
return(enrich)
}
plot_GO <- function(input_ls, GO.ont, gender, font_size, output_name){
en.GO <- compareGO(input_ls,GO.ont)
GO.plot <- dotplot(en.GO,by = 'count',
title = paste0(GO.ont," of ",gender,"-biased genes"), font.size = font_size)
png(paste0("plt_enrich_img/",output_name,"_",GO.ont,"_",gender,".png"),
units="in", width=7, height=7.5, res=300)
print(GO.plot)
dev.off()
ego.df <- as.data.frame(en.GO)
write.table(ego.df,
paste0("enrich_table/",
output_name,"_",GO.ont,"_",gender,".txt"))
}
#########################
##### KEGG #########
#########################
compareKEGG <- function(input.ls){
input.ls.keg <- lapply(input.ls, function(x)
{gene.df <- GenetoENTREZ(x)
return(gene.df$ENTREZID)})
length(input.ls.keg)
names(input.ls.keg) <- names(input.ls)
enrich <- compareCluster(geneCluster =input.ls.keg,
fun = "enrichKEGG",
pAdjustMethod= "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.05)
return(enrich)
}
GenetoENTREZ <- function(symbol){
library(org.Hs.eg.db)
hs <- org.Hs.eg.db
entrez.df <- AnnotationDbi::select(hs,
keys = symbol,
columns = c("ENTREZID", "SYMBOL"),
keytype = "SYMBOL")
return(entrez.df)
}
plot_KEG <- function(input_ls, gender, output_name){
en <- compareKEGG(input_ls)
enplot <- dotplot(en,by = 'count',
title = paste0("KEGG pathway of ",gender,"-biased genes"), font.size = 12)
png(paste0("plt_enrich_img/",output_name,"_",gender,"_KEGG.png"), units="in", width=7, height=7.5, res=300)
print(enplot)
dev.off()
en.df <- as.data.frame(en)
write.table(en.df,paste0("enrich_table/",output_name,"_",gender,"_KEGG.txt"))
}
###############
## DisGeNET ###
###############
plot_Dis <- function(RRA_df, gender, output_name){
Dis <- run_plt_enrich(RRA_df, "DisGeNET (CURATED)", "disgenet2r",gender)
png(paste0("plt_enrich_img/",
output_name,"_",gender,
"_DisGeNET_curated.png"),
units="in", width=7, height=7.5, res=300)
print(Dis)
dev.off()
}