Allow using all species for processing

This commit is contained in:
Elias Projahn 2021-08-29 13:25:12 +02:00
parent b69b3e9d2d
commit 3fd8ef6269
4 changed files with 83 additions and 26 deletions

View file

@ -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)

View file

@ -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))
}

View file

@ -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)
})
}

8
ui.R
View file

@ -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)",