Repository navigation
Expand file tree
/
Copy pathplot_cnetplot_neighborhood.R
More file actions
55 lines (47 loc) · 1.98 KB
/
Copy pathplot_cnetplot_neighborhood.R
File metadata and controls
55 lines (47 loc) · 1.98 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
library(dplyr)
library(ggplot2)
library(clusterProfiler)
library(org.Hs.eg.db)
drugs <- read.csv("./data/neighborhood_final_LINCS_ad_gene_nw_modified_with_symbols.csv") %>%
pull("Source") %>%
unique()
top_bottom <- c("bottom", "top")
universe_genes <- read.csv("./data/universe_genes_LINCS.csv") %>% pull(gene) %>% unique()
for (drug in drugs){
df_drug <- read.csv("./data/neighborhood_final_LINCS_ad_gene_nw_modified_with_symbols.csv") %>%
filter(Source == drug)
for (name in top_bottom){
if (name == "top"){
gene_list <- df_drug %>%
filter(Weight == 1) %>%
pull(Target) %>%
unique()
} else {
gene_list <- df_drug %>%
filter(Weight == -1)%>%
pull(Target)%>%
unique()
}
if (length(gene_list) == 0) next
enrich_results <- enrichGO(
gene = gene_list,
OrgDb = org.Hs.eg.db,
keyType = "SYMBOL",
universe = universe_genes,
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.05
)
df_result <- as.data.frame(enrich_results)
if (nrow(df_result) == 0) next
write.csv(df_result, file = paste0("./data/neighborhood/enr_", name, "_neighborhood_", drug, ".csv"), row.names = FALSE)
cnet <- cnetplot(enrich_results,
layout = 'circle',
showCategory = 5,
color_edge = "category")
title <- paste0("Gene-concept network of", name, "5 enriched BPs for neighborhood of ", drug, " based on ORA")
cnet <- cnet + ggplot2::ggtitle(title)
ggplot2::ggsave(paste0("./img/neighborhood/cnetplot_", name, "_neighborhood_", drug, ".png"), cnet, width = 15, height = 15)
}
}