forked from gmw12/shiny_PD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShiny_Wiki_v1.R
104 lines (79 loc) · 4.05 KB
/
Shiny_Wiki_v1.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
run_wiki <- function(session, input, output){
require(clusterProfiler)
comp_string <- input$select_data_comp_wiki
comp_number <- which(grepl(comp_string, dpmsr_set$y$stats$groups$comp_name))
cat(file=stderr(), str_c("Run wiki...1" ), "\n")
data_in <- dpmsr_set$data$stats[[comp_string]]
if(input$wiki_direction == 'Up') {
go_df <- subset(data_in, data_in$Stats == "Up" )
}else if (input$wiki_direction == 'Down') {
go_df <- subset(data_in, data_in$Stats == "Down" )
}else{
go_df <- subset(data_in, data_in$Stats == "Up" | data_in$Stats == "Down")
}
cat(file=stderr(), str_c("Run wiki...2" ), "\n")
atest <- go_df$Accession
test.df <- bitr(atest, fromType = "UNIPROT",
toType = c("ENTREZID", "ENSEMBL", "SYMBOL","GENENAME","PATH", "ONTOLOGY"),
OrgDb = tax_db)
cat(file=stderr(), str_c("Run wiki...3" ), "\n")
universe.df <- bitr(data_in$Accession, fromType = "UNIPROT",
toType = c("ENTREZID", "ENSEMBL", "SYMBOL","GENENAME","PATH", "ONTOLOGY"),
OrgDb = tax_db)
# wp2gene <<- gmt_get(tax_choice)
#wp2gene <- read.gmt(wpgmtfile)
#dpmsr_set$pathway$wp2gene <<- dpmsr_set$pathway$wp2gene %>% tidyr::separate(ont, c("name","version","wpid","org"), "%")
cat(file=stderr(), str_c("Run wiki...4" ), "\n")
wpid2gene <- wp2gene %>% dplyr::select(wpid, gene) #TERM2GENE
wpid2name <- wp2gene %>% dplyr::select(wpid, name) #TERM2NAME
cat(file=stderr(), str_c("Run wiki...5" ), "\n")
ewp <- enricher(gene=test.df$ENTREZID, universe=universe.df$ENTREZID, TERM2GENE = wpid2gene, TERM2NAME = wpid2name)
ewp <- setReadable(ewp, tax_db, keyType = "ENTREZID")
cat(file=stderr(), str_c("Run wiki...6" ), "\n")
Simple_Excel_bg(ewp@result, "Wiki", str_c(dpmsr_set$file$string, "Wiki_", input$select_data_comp_wiki, "_",
input$select_ont_wiki,input$select_level_wiki, ".xlsx", collapse = " "))
#ggo_result <<- ggo@result[1:5]
#ggo_result <- ggo_result[order(-ggo_result$Count),]
gc()
return(ewp@result)
}
run_profile <- function(session, input, output){
require(clusterProfiler)
cat(file=stderr(), "run_profile ...1", "\n")
comp_string <- input$select_data_comp_profile
comp_number <- which(grepl(comp_string, dpmsr_set$y$stats$groups$comp_name))
cat(file=stderr(), str_c("Run go profile..." ), "\n")
data_in <- dpmsr_set$data$stats[[comp_string]]
cat(file=stderr(), "run_profile ...2", "\n")
if(input$profile_direction == 'Up') {
go_df <- subset(data_in, data_in$Stats == "Up" )
}else if (input$profile_direction == 'Down') {
go_df <- subset(data_in, data_in$Stats == "Down" )
}else{
go_df <- subset(data_in, data_in$Stats == "Up" | data_in$Stats == "Down")
}
atest <- go_df$Accession
cat(file=stderr(), "run_profile ...3", "\n")
test.df <- bitr(atest, fromType = "UNIPROT",
toType = c("ENTREZID", "ENSEMBL", "SYMBOL","GENENAME","PATH", "ONTOLOGY"),
OrgDb = tax_db)
cat(file=stderr(), "run_profile ...4", "\n")
ggo <- groupGO(gene = test.df$ENTREZID,
OrgDb = tax_db,
ont = input$select_ont_profile,
level = as.numeric(input$select_level_profile),
readable = TRUE)
Simple_Excel_bg(ggo, "Go_Profile", str_c(dpmsr_set$file$string, "GO_Profile_", input$select_data_comp_profile, "_",
input$select_ont_profile,input$select_level_profile, ".xlsx", collapse = " "))
#ggo_result <<- ggo@result[1:5]
#ggo_result <- ggo_result[order(-ggo_result$Count),]
#test_ggo <<- ggo
#save profile png
profile_plot_name <- str_c(dpmsr_set$file$string, "GO_Profile_", input$select_data_comp_profile, "_",
input$select_ont_profile,input$select_level_profile, ".png", collapse = " ")
p <- barplot(ggo, title = str_c("Go Profile ", input$select_ont_profile, " level=", input$select_level_profile),
drop=TRUE, showCategory=12, order=TRUE)
ggsave(profile_plot_name, p, width=10, height=8)
gc()
return(ggo)
}