diff --git a/process.R b/process.R index 342a0fb..acccc98 100644 --- a/process.R +++ b/process.R @@ -7,16 +7,10 @@ library(rlog) #' account when regarding them as TPE-OLD candidates. #' #' @param input Data from [`load_input()`]. -process_input <- function(input) { +#' @param species_ids IDs of species to include in the analysis. +process_input <- function(input, species_ids) { results <- data.table(gene = input$genes$id) - # Exclude species with naturally or artificially short chromosomes as well - # as non-replicatively aging species. - species_ids <- input$species[ - median_distance >= 7500000 & group == "replicative", - id - ] - gene_ids <- input$genes[, id] gene_count <- length(gene_ids) diff --git a/scatter_plot.R b/scatter_plot.R index 78d5f8f..aa73190 100644 --- a/scatter_plot.R +++ b/scatter_plot.R @@ -5,18 +5,12 @@ library(ggplot2) #' #' @param input Input data from [`load_input()`]. #' @param results Results from [`process_input()`]. -scatter_plot <- function(gene_ids, input, results) { +#' @param species Species to be displayed. +scatter_plot <- function(gene_ids, input, results, species) { if (length(gene_ids) < 1) { return(ggplot()) } - # Exclude species with naturally or artificially short chromosomes as well - # as non-replicatively aging species. - # TODO: Sync with process_input(). - species <- input$species[ - median_distance >= 7500000 & group == "replicative" - ] - species_ids <- species[, id] data <- merge( @@ -60,5 +54,6 @@ scatter_plot <- function(gene_ids, input, results) { shape = in_cluster ), size = 5 - ) + ) + + theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) } \ No newline at end of file diff --git a/server.R b/server.R index a3c9043..5d1f75f 100644 --- a/server.R +++ b/server.R @@ -7,14 +7,65 @@ source("process.R") source("scatter_plot.R") source("util.R") -data <- run_cached("input", load_input, "input") -results <- run_cached("results", process_input, data) -merged <- merge(results, data$genes, by.x = "gene", by.y = "id") -setorder(merged, -cluster_length) +# Initialize global static data + +inputs <- run_cached("input", load_input, "input") + +#' All species excluding species with naturally or artificially short +#' chromosomes. +species_qualified <- inputs$species[median_distance >= 7500000] + +#' All known replicatively aging species with long enough chromosomes. +species_replicative <- species_qualified[group == "replicative"] + +#' Results computed from [`species_qualified`]. +results_all <- run_cached( + "results_all", + process_input, + inputs, + species_qualified[, id] +) + +#' Results computed from [`species_replicative`]. +results_replicative <- run_cached( + "results_replicative", + process_input, + inputs, + species_replicative[, id] +) + +# Add gene information to results for display. + +results_all <- merge( + results_all, + inputs$genes, + by.x = "gene", + by.y = "id" +) + +results_replicative <- merge( + results_replicative, + inputs$genes, + by.x = "gene", + by.y = "id" +) + +# Order results by cluster length descendingly. +# TODO: Once other methods have been added, this has to be dynamic. +setorder(results_all, -cluster_length) +setorder(results_replicative, -cluster_length) server <- function(input, output) { - filtered <- reactive({ - merged[ + #' This expression applies all user defined filters to the available + #' results. + results <- reactive({ + results <- if (input$species == "all") { + results_all + } else { + results_replicative + } + + results[ cluster_length >= input$length & cluster_mean >= input$range[1] * 1000000 & cluster_mean <= input$range[2] * 1000000 @@ -23,7 +74,7 @@ server <- function(input, output) { output$genes <- renderDT({ datatable( - filtered()[, .(.I, name, chromosome, cluster_length, cluster_mean)], + results()[, .(.I, name, chromosome, cluster_length, cluster_mean)], rownames = FALSE, colnames = c( "Rank", @@ -37,7 +88,16 @@ server <- function(input, output) { }) output$scatter <- renderPlot({ - gene_ids <- filtered()[input$genes_rows_selected, gene] - scatter_plot(gene_ids, data, results) + results <- results() + + gene_ids <- results[input$genes_rows_selected, gene] + + species <- if (input$species == "all") { + species_qualified + } else { + species_replicative + } + + scatter_plot(gene_ids, inputs, results, species) }) } \ No newline at end of file diff --git a/ui.R b/ui.R index 6a2e108..292b7e1 100644 --- a/ui.R +++ b/ui.R @@ -7,6 +7,14 @@ ui <- fluidPage( position = "right", sidebarPanel( h3("Candidate selection"), + selectInput( + "species", + "Species to include", + choices = list( + "All qualified" = "all", + "Replicatively aging" = "replicative" + ) + ), sliderInput( "range", "Gene position (Mbp)",