2021-10-20 15:34:52 +02:00
|
|
|
# Java script function to replace gene IDs with Ensembl gene links.
|
|
|
|
|
js_link <- DT::JS("function(row, data) {
|
2021-10-01 09:50:04 +02:00
|
|
|
let id = data[1];
|
|
|
|
|
var name = data[2];
|
|
|
|
|
if (!name) name = 'Unknown';
|
|
|
|
|
let url = `https://www.ensembl.org/Homo_sapiens/Gene/Summary?g=${id}`;
|
|
|
|
|
$('td:eq(1)', row).html(`<a href=\"${url}\" target=\"_blank\">${name}</a>`);
|
|
|
|
|
}")
|
|
|
|
|
|
2021-10-16 17:02:39 +02:00
|
|
|
server <- function(input, output, session) {
|
2021-10-21 14:56:19 +02:00
|
|
|
preset <- preset_editor_server("preset_editor")
|
2021-11-02 14:28:04 +01:00
|
|
|
|
2021-10-20 15:34:52 +02:00
|
|
|
# Compute the results according to the preset.
|
2021-10-19 16:44:29 +02:00
|
|
|
analysis <- reactive({
|
2021-10-21 14:56:19 +02:00
|
|
|
preset <- preset()
|
2021-08-29 13:25:12 +02:00
|
|
|
|
2021-10-19 14:15:28 +02:00
|
|
|
# Perform the analysis cached based on the preset's hash.
|
2021-11-14 22:34:46 +01:00
|
|
|
analysis <- withProgress(
|
2021-10-19 15:05:01 +02:00
|
|
|
message = "Analyzing genes",
|
2021-11-14 22:34:46 +01:00
|
|
|
value = 0.0,
|
|
|
|
|
{ # nolint
|
2021-10-21 17:26:28 +02:00
|
|
|
geposan::analyze(preset, function(progress) {
|
|
|
|
|
setProgress(progress)
|
|
|
|
|
})
|
2021-10-19 15:05:01 +02:00
|
|
|
}
|
|
|
|
|
)
|
2021-10-19 14:15:28 +02:00
|
|
|
|
2021-11-14 22:34:46 +01:00
|
|
|
analysis
|
|
|
|
|
})
|
2021-10-16 21:46:59 +02:00
|
|
|
|
2021-11-14 22:34:46 +01:00
|
|
|
# Rank the results.
|
2021-11-17 22:58:55 +01:00
|
|
|
ranking <- methods_server("methods", analysis)
|
2021-10-20 11:20:20 +02:00
|
|
|
|
2021-11-14 22:34:46 +01:00
|
|
|
# Add gene information to the results.
|
|
|
|
|
results <- reactive({
|
|
|
|
|
merge(
|
|
|
|
|
ranking(),
|
|
|
|
|
geposan::genes,
|
|
|
|
|
by.x = "gene",
|
|
|
|
|
by.y = "id",
|
|
|
|
|
sort = FALSE
|
|
|
|
|
)
|
2021-08-26 11:20:50 +02:00
|
|
|
})
|
2021-08-25 15:01:18 +02:00
|
|
|
|
2021-11-02 13:41:03 +01:00
|
|
|
# Apply the filters.
|
2021-11-02 14:28:04 +01:00
|
|
|
results_filtered <- filters_server("filters", results)
|
2021-10-15 13:16:51 +02:00
|
|
|
|
2021-12-06 13:54:22 +01:00
|
|
|
comparison_gene_ids <- comparison_editor_server("comparison_editor", preset)
|
|
|
|
|
|
2021-10-20 15:34:52 +02:00
|
|
|
output$genes <- DT::renderDT({
|
2021-10-15 11:46:15 +02:00
|
|
|
columns <- c("rank", "gene", "name", "chromosome", method_ids, "score")
|
|
|
|
|
column_names <- c("", "Gene", "", "Chromosome", method_names, "Score")
|
2021-10-15 09:26:57 +02:00
|
|
|
|
2021-10-20 15:34:52 +02:00
|
|
|
dt <- DT::datatable(
|
2021-10-15 15:03:40 +02:00
|
|
|
results_filtered()[, ..columns],
|
2021-08-26 12:51:43 +02:00
|
|
|
rownames = FALSE,
|
2021-10-15 09:26:57 +02:00
|
|
|
colnames = column_names,
|
2021-10-01 09:50:04 +02:00
|
|
|
style = "bootstrap",
|
|
|
|
|
options = list(
|
|
|
|
|
rowCallback = js_link,
|
2021-10-15 11:46:15 +02:00
|
|
|
columnDefs = list(list(visible = FALSE, targets = 2)),
|
2021-11-17 23:08:20 +01:00
|
|
|
pageLength = 25
|
2021-10-01 09:50:04 +02:00
|
|
|
)
|
2021-06-24 22:38:16 +02:00
|
|
|
)
|
2021-09-30 13:25:39 +02:00
|
|
|
|
2021-10-20 15:34:52 +02:00
|
|
|
DT::formatPercentage(dt, c(method_ids, "score"), digits = 1)
|
2021-06-24 22:38:16 +02:00
|
|
|
})
|
|
|
|
|
|
2021-10-07 12:59:04 +02:00
|
|
|
output$copy <- renderUI({
|
2021-10-15 15:03:40 +02:00
|
|
|
results <- results_filtered()
|
2021-10-07 12:59:04 +02:00
|
|
|
|
|
|
|
|
gene_ids <- results[, gene]
|
|
|
|
|
names <- results[name != "", name]
|
|
|
|
|
|
|
|
|
|
genes_text <- paste(gene_ids, collapse = "\n")
|
|
|
|
|
names_text <- paste(names, collapse = "\n")
|
|
|
|
|
|
|
|
|
|
splitLayout(
|
2021-10-15 13:59:00 +02:00
|
|
|
cellWidths = "auto",
|
2021-10-20 15:34:52 +02:00
|
|
|
rclipboard::rclipButton(
|
2021-10-07 12:59:04 +02:00
|
|
|
"copy_ids_button",
|
|
|
|
|
"Copy gene IDs",
|
|
|
|
|
genes_text,
|
2021-10-15 13:59:00 +02:00
|
|
|
icon = icon("clipboard")
|
2021-10-07 12:59:04 +02:00
|
|
|
),
|
2021-10-20 15:34:52 +02:00
|
|
|
rclipboard::rclipButton(
|
2021-10-07 12:59:04 +02:00
|
|
|
"copy_names_button",
|
|
|
|
|
"Copy gene names",
|
|
|
|
|
names_text,
|
2021-10-15 13:59:00 +02:00
|
|
|
icon = icon("clipboard")
|
2021-10-07 12:59:04 +02:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-10-20 15:34:52 +02:00
|
|
|
output$scatter <- plotly::renderPlotly({
|
2021-11-15 15:12:42 +01:00
|
|
|
preset <- preset()
|
2021-12-02 17:22:27 +01:00
|
|
|
gene_sets <- list("Reference genes" = preset$reference_gene_ids)
|
|
|
|
|
comparison_gene_ids <- comparison_gene_ids()
|
2021-08-29 13:25:12 +02:00
|
|
|
|
2021-11-15 15:12:42 +01:00
|
|
|
if (length(comparison_gene_ids) >= 1) {
|
2021-12-02 17:22:27 +01:00
|
|
|
gene_sets <- c(
|
|
|
|
|
gene_sets,
|
|
|
|
|
list("Comparison genes" = comparison_gene_ids)
|
|
|
|
|
)
|
2021-11-15 15:12:42 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-02 17:22:27 +01:00
|
|
|
geposan::plot_positions(preset$species_ids, gene_sets)
|
2021-06-24 22:38:16 +02:00
|
|
|
})
|
2021-10-07 12:18:47 +02:00
|
|
|
|
2021-10-20 15:34:52 +02:00
|
|
|
output$rank_plot <- plotly::renderPlotly({
|
2021-12-02 17:22:27 +01:00
|
|
|
preset <- preset()
|
|
|
|
|
gene_sets <- list("Reference genes" = preset$reference_gene_ids)
|
|
|
|
|
comparison_gene_ids <- comparison_gene_ids()
|
2021-11-15 14:22:33 +01:00
|
|
|
|
|
|
|
|
if (length(comparison_gene_ids) >= 1) {
|
2021-12-02 17:22:27 +01:00
|
|
|
gene_sets <- c(
|
|
|
|
|
gene_sets,
|
|
|
|
|
list("Comparison genes" = comparison_gene_ids)
|
|
|
|
|
)
|
2021-11-15 14:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-15 09:35:47 +01:00
|
|
|
geposan::plot_scores(
|
|
|
|
|
ranking(),
|
2021-11-15 14:22:33 +01:00
|
|
|
gene_sets = gene_sets,
|
2021-11-15 09:35:47 +01:00
|
|
|
max_rank = results_filtered()[, max(rank)]
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2021-12-06 14:24:31 +01:00
|
|
|
output$rankings_plot <- plotly::renderPlotly({
|
|
|
|
|
preset <- preset()
|
|
|
|
|
gene_sets <- list("Reference genes" = preset$reference_gene_ids)
|
|
|
|
|
comparison_gene_ids <- comparison_gene_ids()
|
|
|
|
|
|
|
|
|
|
if (length(comparison_gene_ids) >= 1) {
|
|
|
|
|
gene_sets <- c(
|
|
|
|
|
gene_sets,
|
|
|
|
|
list("Comparison genes" = comparison_gene_ids)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
all <- ranking()
|
|
|
|
|
clusteriness <- geposan::ranking(all, list(clusteriness = 1))
|
|
|
|
|
correlation <- geposan::ranking(all, list(correlation = 1))
|
|
|
|
|
neural <- geposan::ranking(all, list(neural = 1))
|
|
|
|
|
adjacency <- geposan::ranking(all, list(adjacency = 1))
|
|
|
|
|
proximity <- geposan::ranking(all, list(proximity = 1))
|
|
|
|
|
|
|
|
|
|
rankings <- list(
|
|
|
|
|
"Clusteriness" = clusteriness,
|
|
|
|
|
"Correlation" = correlation,
|
|
|
|
|
"Neural" = neural,
|
|
|
|
|
"Adjacency" = adjacency,
|
|
|
|
|
"Proximity" = proximity,
|
|
|
|
|
"Combined" = all
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
geposan::plot_rankings(rankings, gene_sets)
|
|
|
|
|
})
|
|
|
|
|
|
2021-11-15 09:35:47 +01:00
|
|
|
output$boxplot <- plotly::renderPlotly({
|
2021-12-02 17:22:27 +01:00
|
|
|
preset <- preset()
|
|
|
|
|
gene_sets <- list("Reference genes" = preset$reference_gene_ids)
|
|
|
|
|
comparison_gene_ids <- comparison_gene_ids()
|
2021-11-15 14:22:33 +01:00
|
|
|
|
|
|
|
|
if (length(comparison_gene_ids) >= 1) {
|
2021-12-02 17:22:27 +01:00
|
|
|
gene_sets <- c(
|
|
|
|
|
gene_sets,
|
|
|
|
|
list("Comparison genes" = comparison_gene_ids)
|
|
|
|
|
)
|
2021-11-15 14:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-02 17:22:27 +01:00
|
|
|
geposan::plot_boxplot(ranking(), gene_sets)
|
2021-10-15 15:03:40 +02:00
|
|
|
})
|
|
|
|
|
|
2021-12-08 14:38:38 +01:00
|
|
|
gost <- reactive({
|
|
|
|
|
withProgress(
|
|
|
|
|
message = "Querying g:Profiler",
|
|
|
|
|
value = 0.0,
|
|
|
|
|
{ # nolint
|
|
|
|
|
setProgress(0.2)
|
|
|
|
|
gprofiler2::gost(results_filtered()[, gene])
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
output$gost_plot <- plotly::renderPlotly({
|
|
|
|
|
gprofiler2::gostplot(
|
|
|
|
|
gost(),
|
|
|
|
|
capped = FALSE,
|
|
|
|
|
interactive = TRUE
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
output$gost_details <- DT::renderDT({
|
|
|
|
|
data <- data.table(gost()$result)
|
|
|
|
|
setorder(data, p_value)
|
|
|
|
|
|
|
|
|
|
data[, total_ratio := term_size / effective_domain_size]
|
|
|
|
|
data[, query_ratio := intersection_size / query_size]
|
2021-10-20 15:34:52 +02:00
|
|
|
|
2021-12-08 14:38:38 +01:00
|
|
|
dt <- DT::datatable(
|
|
|
|
|
data[, .(source, term_name, total_ratio, query_ratio, p_value)],
|
|
|
|
|
rownames = FALSE,
|
|
|
|
|
colnames = c(
|
|
|
|
|
"Source",
|
|
|
|
|
"Term",
|
|
|
|
|
"Total ratio",
|
|
|
|
|
"Query ratio",
|
|
|
|
|
"p-Value"
|
|
|
|
|
),
|
|
|
|
|
style = "bootstrap",
|
|
|
|
|
options = list(
|
|
|
|
|
pageLength = 25
|
2021-10-20 15:34:52 +02:00
|
|
|
)
|
2021-12-08 14:38:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
dt <- DT::formatRound(dt, "p_value", digits = 4)
|
|
|
|
|
dt <- DT::formatPercentage(
|
|
|
|
|
dt,
|
|
|
|
|
c("total_ratio", "query_ratio"),
|
|
|
|
|
digits = 1
|
|
|
|
|
)
|
2021-10-07 12:18:47 +02:00
|
|
|
})
|
2021-10-19 14:15:28 +02:00
|
|
|
}
|