-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
131 lines (114 loc) · 3.86 KB
/
app.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# Purpose: Interactive Shiny App that allows the user to select multiple PanelApp panels using the
# PanelApp API. Network analysis is then performed to identify
source("chooser.R")
source("webGestaltAPI.R")
library(shiny)
library(tidyverse)
library(jsonlite)
library(ggplot2)
library(plotly)
library(igraph)
library(WebGestaltR)
library(RCy3)
library(waiter)
# Define functions
getPanelAppList <- function() {
api_query <- "https://panelapp.genomicsengland.co.uk/WebServices/list_panels/?format=json"
json_data <- fromJSON(api_query, flatten=TRUE)
panelApp_panels <- tibble(panel_name = json_data$result$Name,
panel_id = json_data$result$Panel_Id,
num_of_gene = json_data$result$Number_of_Genes,
version = json_data$result$CurrentVersion
)
return(panelApp_panels)
}
panel_list <- getPanelAppList()
getPanelGenes <- function(panel_id){
api_query <- paste0("https://panelapp.genomicsengland.co.uk/WebServices/get_panel/",
panel_id,
"/?format=json")
json_data <- fromJSON(api_query, flatten=TRUE)
panel_genes <- tibble(gene_symbol = json_data$result$Genes$GeneSymbol,
evidence = json_data$result$Genes$LevelOfConfidence)
return(panel_genes)
}
ui <- navbarPage(
"PanelApp Pathway Analysis",
tabPanel(
"Select Panels",
titlePanel("Select Panels"),
chooserInput(
"mychooser",
"Available PanelApp Panels",
"Selected PanelApp Panels",
panel_list$panel_name,
c(),
size = 10,
multiple = TRUE
),
actionButton("runAll", label="Run Analysis"),
p("Click the button to analyze panels")
),
tabPanel("Available PanelApp Panels",
titlePanel("Available Panels"),
DT::dataTableOutput("panel_table")
),
tabPanel("Imported genes",
titlePanel("Genes Selected for Analysis"),
DT::dataTableOutput("gene_table")
),
tabPanel("Network Analysis",
"Place html help file here"
),
tabPanel("WebGestaltAPI",
"Place html help file here"
),
tabPanel("WebGestalt Table",
titlePanel("WebGestalt Output"),
DT::dataTableOutput("wg_table")
),
tabPanel("HPO Analysis",
"Place html help file here"
),
tabPanel("GTex Analysis",
"Place html help file here"
),
tabPanel("Panel Candidates",
"Place html help file here"
),
tabPanel("Help",
"Place html help file here"
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
# Render selected panel
#output$selection <- renderPrint({
# input$mychooser[1]
#})
# Display selected genes in table
output$panel_table <- DT::renderDataTable({
DT::datatable(as.data.frame(panel_list))
})
# Display selected genes in table
output$gene_table <- DT::renderDataTable({
selected_panels <- panel_list[panel_list$panel_name %in% unlist(input$mychooser[2]),]
# Use panel_id from selected panels to get panel genes
selected_genes <- lapply(selected_panels$panel_id, getPanelGenes)
# getPanelGenes(panel)
DT::datatable(as.data.frame(selected_genes))
})
# Display WebGestalt output in table
output$wg_table <- DT::renderDataTable({
selected_panels <- panel_list[panel_list$panel_name %in% unlist(input$mychooser[2]),]
# Use panel_id from selected panels to get panel genes
selected_genes <- lapply(selected_panels$panel_id, getPanelGenes)
outputDirectory <- getwd()
DT::datatable(callWebGestalt(unlist(selected_genes), outputDirectory))
})
}
# Currently hardcoded output directory (file written over every time app is run)
html_temp_file <- paste0(outputDirectory, "/Project_temp_webGestalt/Report_temp_webGestalt.html")
# Run the application
shinyApp(ui = ui, server = server)