diff --git a/R/data.R b/R/data.R index 39bc399..0d7e897 100644 --- a/R/data.R +++ b/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 ) diff --git a/R/methods.R b/R/methods.R index 1f6f143..e901230 100644 --- a/R/methods.R +++ b/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() + ) }) }) } diff --git a/R/preset_editor.R b/R/preset_editor.R index b24384d..3f0e996 100644 --- a/R/preset_editor.R +++ b/R/preset_editor.R @@ -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 )) }) diff --git a/R/server.R b/R/server.R index 081b4f0..788ce5d 100644 --- a/R/server.R +++ b/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")