Add gprofiler integration

This commit is contained in:
Elias Projahn 2022-06-02 10:17:49 +02:00
parent d1398a10f8
commit 90c9d18f26
4 changed files with 111 additions and 4 deletions

View file

@ -25,5 +25,6 @@ Imports:
DT, DT,
plotly, plotly,
glue, glue,
gprofiler2,
shiny, shiny,
shinyvs shinyvs

View file

@ -76,17 +76,80 @@ server <- function(input, output, session) {
highlighted_genes = custom_genes() highlighted_genes = custom_genes()
)) ))
output$selected_genes <- DT::renderDataTable({ selected_genes <- reactive({
selected_points <- plotly::event_data("plotly_selected") selected_points <- plotly::event_data("plotly_selected")
ranked_data()[rank %in% selected_points$x]
})
data <- if (is.null(selected_points)) { output$selected_genes <- DT::renderDataTable({
data <- if (length(selected_genes()) > 0) {
ranked_data() ranked_data()
} else { } else {
ranked_data()[rank %in% selected_points$x] selected_genes()
} }
genes_table(data) genes_table(data)
}) })
gsea_genes <- reactive({
sort(if (input$gsea_set == "top") {
ranked_data()[rank >= input$gsea_ranks, gene]
} else if (input$gsea_set == "selected") {
selected_genes()[, gene]
} else {
custom_genes()
})
})
gsea_result <- reactive({
withProgress(
message = "Querying g:Profiler",
value = 0.0,
{ # nolint
setProgress(0.2)
gprofiler2::gost(gsea_genes())
}
)
}) |>
bindCache(gsea_genes()) |>
bindEvent(input$gsea_run, ignoreNULL = FALSE)
output$gsea_plot <- plotly::renderPlotly({
gprofiler2::gostplot(gsea_result(), interactive = TRUE)
})
output$gsea_details <- DT::renderDT({
data <- data.table(gsea_result()$result)
setorder(data, p_value)
data[, total_ratio := term_size / effective_domain_size]
data[, query_ratio := intersection_size / query_size]
data <- data[, .(
source,
term_name,
total_ratio,
query_ratio,
p_value
)]
DT::datatable(
data,
rownames = FALSE,
colnames = c(
"Source",
"Term",
"Total ratio",
"Query ratio",
"p-value"
),
options = list(
pageLength = 25
)
) |>
DT::formatRound("p_value", digits = 4) |>
DT::formatPercentage(c("total_ratio", "query_ratio"), digits = 1)
})
} }
#' Create a displayable data table from the gene results data. #' Create a displayable data table from the gene results data.

View file

@ -2,6 +2,13 @@
#' @noRd #' @noRd
custom_css <- function() { custom_css <- function() {
tags$head( tags$head(
tags$style(".nav-hidden { height: 0 }") tags$style(HTML(
".nav-hidden { height: 0 }",
".flow-layout > div {",
"display: inline-block;",
"vertical-align: top;",
"margin-right: 12px;",
"}"
))
) )
} }

36
R/ui.R
View file

@ -81,6 +81,42 @@ ui <- function() {
)), )),
div(class = "p-1"), div(class = "p-1"),
DT::dataTableOutput("selected_genes") DT::dataTableOutput("selected_genes")
),
tabPanel(
"GSEA",
value = "gsea",
div(
class = "flow-layout",
selectInput(
"gsea_set",
label = NULL,
list(
"Top genes" = "top",
"Selected genes" = "selected",
"Your genes" = "custom"
)
),
conditionalPanel(
"input.gsea_set == 'top'",
sliderInput(
"gsea_ranks",
label = NULL,
min = 10,
max = 1000,
value = 100,
step = 10,
ticks = FALSE
)
),
actionButton(
"gsea_run",
"Update analysis",
class = "btn-primary"
)
),
plotly::plotlyOutput("gsea_plot"),
div(class = "p-2"),
DT::dataTableOutput("gsea_details")
) )
) )
) )