mirror of
				https://github.com/johrpan/geposanui.git
				synced 2025-10-26 19:27:24 +01:00 
			
		
		
		
	Allow using all species for processing
This commit is contained in:
		
							parent
							
								
									b69b3e9d2d
								
							
						
					
					
						commit
						3fd8ef6269
					
				
					 4 changed files with 83 additions and 26 deletions
				
			
		
							
								
								
									
										10
									
								
								process.R
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								process.R
									
										
									
									
									
								
							|  | @ -7,16 +7,10 @@ library(rlog) | ||||||
| #' account when regarding them as TPE-OLD candidates. | #' account when regarding them as TPE-OLD candidates. | ||||||
| #' | #' | ||||||
| #' @param input Data from [`load_input()`]. | #' @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) |     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_ids <- input$genes[, id] | ||||||
|     gene_count <- length(gene_ids) |     gene_count <- length(gene_ids) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,18 +5,12 @@ library(ggplot2) | ||||||
| #' | #' | ||||||
| #' @param input Input data from [`load_input()`]. | #' @param input Input data from [`load_input()`]. | ||||||
| #' @param results Results from [`process_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) { |     if (length(gene_ids) < 1) { | ||||||
|         return(ggplot()) |         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] |     species_ids <- species[, id] | ||||||
| 
 | 
 | ||||||
|     data <- merge( |     data <- merge( | ||||||
|  | @ -60,5 +54,6 @@ scatter_plot <- function(gene_ids, input, results) { | ||||||
|                 shape = in_cluster |                 shape = in_cluster | ||||||
|             ), |             ), | ||||||
|             size = 5 |             size = 5 | ||||||
|         ) |         ) + | ||||||
|  |         theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) | ||||||
| } | } | ||||||
							
								
								
									
										78
									
								
								server.R
									
										
									
									
									
								
							
							
						
						
									
										78
									
								
								server.R
									
										
									
									
									
								
							|  | @ -7,14 +7,65 @@ source("process.R") | ||||||
| source("scatter_plot.R") | source("scatter_plot.R") | ||||||
| source("util.R") | source("util.R") | ||||||
| 
 | 
 | ||||||
| data <- run_cached("input", load_input, "input") | # Initialize global static data | ||||||
| results <- run_cached("results", process_input, data) | 
 | ||||||
| merged <- merge(results, data$genes, by.x = "gene", by.y = "id") | inputs <- run_cached("input", load_input, "input") | ||||||
| setorder(merged, -cluster_length) | 
 | ||||||
|  | #' 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) { | server <- function(input, output) { | ||||||
|     filtered <- reactive({ |     #' This expression applies all user defined filters to the available | ||||||
|         merged[ |     #' results. | ||||||
|  |     results <- reactive({ | ||||||
|  |         results <- if (input$species == "all") { | ||||||
|  |             results_all | ||||||
|  |         } else { | ||||||
|  |             results_replicative | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         results[ | ||||||
|             cluster_length >= input$length & |             cluster_length >= input$length & | ||||||
|                 cluster_mean >= input$range[1] * 1000000 & |                 cluster_mean >= input$range[1] * 1000000 & | ||||||
|                 cluster_mean <= input$range[2] * 1000000 |                 cluster_mean <= input$range[2] * 1000000 | ||||||
|  | @ -23,7 +74,7 @@ server <- function(input, output) { | ||||||
| 
 | 
 | ||||||
|     output$genes <- renderDT({ |     output$genes <- renderDT({ | ||||||
|         datatable( |         datatable( | ||||||
|             filtered()[, .(.I, name, chromosome, cluster_length, cluster_mean)], |             results()[, .(.I, name, chromosome, cluster_length, cluster_mean)], | ||||||
|             rownames = FALSE, |             rownames = FALSE, | ||||||
|             colnames = c( |             colnames = c( | ||||||
|                 "Rank", |                 "Rank", | ||||||
|  | @ -37,7 +88,16 @@ server <- function(input, output) { | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     output$scatter <- renderPlot({ |     output$scatter <- renderPlot({ | ||||||
|         gene_ids <- filtered()[input$genes_rows_selected, gene] |         results <- results() | ||||||
|         scatter_plot(gene_ids, data, 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
									
										
									
									
									
								
							
							
						
						
									
										8
									
								
								ui.R
									
										
									
									
									
								
							|  | @ -7,6 +7,14 @@ ui <- fluidPage( | ||||||
|         position = "right", |         position = "right", | ||||||
|         sidebarPanel( |         sidebarPanel( | ||||||
|             h3("Candidate selection"), |             h3("Candidate selection"), | ||||||
|  |             selectInput( | ||||||
|  |                 "species", | ||||||
|  |                 "Species to include", | ||||||
|  |                 choices = list( | ||||||
|  |                     "All qualified" = "all", | ||||||
|  |                     "Replicatively aging" = "replicative" | ||||||
|  |                 ) | ||||||
|  |             ), | ||||||
|             sliderInput( |             sliderInput( | ||||||
|                 "range", |                 "range", | ||||||
|                 "Gene position (Mbp)", |                 "Gene position (Mbp)", | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue