mirror of
https://github.com/johrpan/geposanui.git
synced 2025-10-26 11:17:24 +01:00
Adapt to geposan changes and add new methods
This commit is contained in:
parent
9709360d45
commit
f485eadaf5
4 changed files with 61 additions and 49 deletions
40
R/data.R
40
R/data.R
|
|
@ -71,13 +71,23 @@ genes <- geposan::genes[, .(
|
|||
methods <- list(
|
||||
list(
|
||||
id = "clusteriness",
|
||||
name = "Clustering",
|
||||
description = "Clustering of genes"
|
||||
name = "Clustering (distances)",
|
||||
description = "Clustering of genes (distances)"
|
||||
),
|
||||
list(
|
||||
id = "clusteriness_positions",
|
||||
name = "Clustering (positions)",
|
||||
description = "Clustering of genes (positions)"
|
||||
),
|
||||
list(
|
||||
id = "correlation",
|
||||
name = "Correlation",
|
||||
description = "Correlation with known genes"
|
||||
name = "Correlation (distances)",
|
||||
description = "Correlation with known genes (distances)"
|
||||
),
|
||||
list(
|
||||
id = "correlation_positions",
|
||||
name = "Correlation (positions)",
|
||||
description = "Correlation with known genes (positions)"
|
||||
),
|
||||
list(
|
||||
id = "proximity",
|
||||
|
|
@ -91,6 +101,12 @@ methods <- list(
|
|||
)
|
||||
)
|
||||
|
||||
# IDs of methods for geposan.
|
||||
method_ids <- sapply(methods, function(method) method$id)
|
||||
|
||||
# Names of methods for geposan.
|
||||
method_names <- sapply(methods, function(method) method$name)
|
||||
|
||||
# Gene IDs of known or suggested TPE-OLD genes.
|
||||
genes_tpe_old <- genes[suggested | verified == TRUE, id]
|
||||
|
||||
|
|
@ -99,17 +115,17 @@ species_replicative <- species[replicative == TRUE, id]
|
|||
|
||||
# Preset for [geposan] including all species and TPE-OLD genes for reference.
|
||||
preset_all_species <- geposan::preset(
|
||||
methods = c("clusteriness", "correlation", "proximity", "neural"),
|
||||
species = species$id,
|
||||
genes = genes$id,
|
||||
reference_genes = genes_tpe_old
|
||||
methods = method_ids,
|
||||
species_ids = species$id,
|
||||
gene_ids = genes$id,
|
||||
reference_gene_ids = genes_tpe_old
|
||||
)
|
||||
|
||||
# Preset for [geposan] including only replicatively aging species as well as
|
||||
# TPE-OLD genes for reference.
|
||||
preset_replicative_species <- geposan::preset(
|
||||
methods = c("clusteriness", "correlation", "proximity", "neural"),
|
||||
species = species_replicative,
|
||||
genes = genes$id,
|
||||
reference_genes = genes_tpe_old
|
||||
methods = method_ids,
|
||||
species_ids = species_replicative,
|
||||
gene_ids = genes$id,
|
||||
reference_gene_ids = genes_tpe_old
|
||||
)
|
||||
|
|
|
|||
15
R/methods.R
15
R/methods.R
|
|
@ -46,9 +46,11 @@ methods_ui <- function(id) {
|
|||
# Construct server for the methods editor.
|
||||
#
|
||||
# @param analysis The reactive containing the results to be weighted.
|
||||
# @param min_n_species A reactive containing the minimum number of species to
|
||||
# require for genes to be included in the ranking.
|
||||
#
|
||||
# @return A reactive containing the weighted results.
|
||||
methods_server <- function(id, analysis) {
|
||||
methods_server <- function(id, analysis, min_n_species) {
|
||||
moduleServer(id, function(input, output, session) {
|
||||
observeEvent(input$optimize_button, {
|
||||
method_ids <- NULL
|
||||
|
|
@ -60,11 +62,12 @@ methods_server <- function(id, analysis) {
|
|||
}
|
||||
}
|
||||
|
||||
weights <- geposan::optimize_weights(
|
||||
weights <- geposan::optimal_weights(
|
||||
analysis(),
|
||||
method_ids,
|
||||
genes_tpe_old,
|
||||
target = input$target
|
||||
target = input$target,
|
||||
min_n_species = min_n_species()
|
||||
)
|
||||
|
||||
for (method_id in method_ids) {
|
||||
|
|
@ -95,7 +98,11 @@ methods_server <- function(id, analysis) {
|
|||
}
|
||||
}
|
||||
|
||||
geposan::ranking(analysis(), weights)
|
||||
geposan::ranking(
|
||||
analysis(),
|
||||
weights,
|
||||
min_n_species = min_n_species()
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,15 +82,10 @@ preset_editor_server <- function(id) {
|
|||
|
||||
observeEvent(input$apply_button, {
|
||||
result(geposan::preset(
|
||||
methods <- c(
|
||||
"clusteriness",
|
||||
"correlation",
|
||||
"proximity",
|
||||
"neural"
|
||||
),
|
||||
species = input$species,
|
||||
genes = genes$id,
|
||||
reference_genes = input$reference_genes
|
||||
methods = method_ids,
|
||||
species_ids = input$species,
|
||||
gene_ids = genes$id,
|
||||
reference_gene_ids = input$reference_genes
|
||||
))
|
||||
})
|
||||
|
||||
|
|
|
|||
42
R/server.R
42
R/server.R
|
|
@ -24,45 +24,39 @@ server <- function(input, output, session) {
|
|||
preset <- preset()
|
||||
|
||||
# Perform the analysis cached based on the preset's hash.
|
||||
results <- withProgress(
|
||||
analysis <- withProgress(
|
||||
message = "Analyzing genes",
|
||||
value = 0.0, {
|
||||
value = 0.0,
|
||||
{ # nolint
|
||||
geposan::analyze(preset, function(progress) {
|
||||
setProgress(progress)
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
# Add all gene information to the results.
|
||||
results <- merge(
|
||||
results,
|
||||
genes,
|
||||
by.x = "gene",
|
||||
by.y = "id"
|
||||
)
|
||||
|
||||
# Count included species from the preset per gene.
|
||||
genes_n_species <- geposan::distances[
|
||||
species %chin% preset$species_ids,
|
||||
.(n_species = .N),
|
||||
by = "gene"
|
||||
]
|
||||
|
||||
setkey(genes_n_species, gene)
|
||||
|
||||
# Exclude genes with too few species.
|
||||
results[genes_n_species[gene, n_species] >= input$n_species]
|
||||
analysis
|
||||
})
|
||||
|
||||
min_n_species <- reactive(input$n_species)
|
||||
|
||||
# Rank the results.
|
||||
results <- methods_server("methods", analysis)
|
||||
ranking <- methods_server("methods", analysis, min_n_species)
|
||||
|
||||
# Add gene information to the results.
|
||||
results <- reactive({
|
||||
merge(
|
||||
ranking(),
|
||||
geposan::genes,
|
||||
by.x = "gene",
|
||||
by.y = "id",
|
||||
sort = FALSE
|
||||
)
|
||||
})
|
||||
|
||||
# Apply the filters.
|
||||
results_filtered <- filters_server("filters", results)
|
||||
|
||||
output$genes <- DT::renderDT({
|
||||
method_ids <- sapply(methods, function(method) method$id)
|
||||
method_names <- sapply(methods, function(method) method$name)
|
||||
columns <- c("rank", "gene", "name", "chromosome", method_ids, "score")
|
||||
column_names <- c("", "Gene", "", "Chromosome", method_names, "Score")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue