| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  | library(data.table) | 
					
						
							|  |  |  | library(DT) | 
					
						
							|  |  |  | library(shiny) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 23:10:52 +02:00
										 |  |  | source("init.R") | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  | source("scatter_plot.R") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | server <- function(input, output) { | 
					
						
							| 
									
										
										
										
											2021-09-18 23:33:37 +02:00
										 |  |  |     #' This reactive expression applies all user defined filters as well as the | 
					
						
							|  |  |  |     #' desired ranking weights to the results. | 
					
						
							| 
									
										
										
										
											2021-08-29 13:25:12 +02:00
										 |  |  |     results <- reactive({ | 
					
						
							| 
									
										
										
										
											2021-09-18 23:33:37 +02:00
										 |  |  |         # Select the species preset. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-29 13:25:12 +02:00
										 |  |  |         results <- if (input$species == "all") { | 
					
						
							|  |  |  |             results_all | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             results_replicative | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 23:33:37 +02:00
										 |  |  |         # Apply user defined filters. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         results <- results[ | 
					
						
							| 
									
										
										
										
											2021-08-26 11:20:50 +02:00
										 |  |  |             cluster_length >= input$length & | 
					
						
							|  |  |  |                 cluster_mean >= input$range[1] * 1000000 & | 
					
						
							|  |  |  |                 cluster_mean <= input$range[2] * 1000000 | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2021-09-18 23:33:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Compute scoring factors and the weighted score. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cluster_max <- results[, max(cluster_length)] | 
					
						
							|  |  |  |         results[, cluster_score := cluster_length / cluster_max] | 
					
						
							| 
									
										
										
										
											2021-09-19 09:57:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-18 23:33:37 +02:00
										 |  |  |         results[, score := input$clustering / 100 * cluster_score + | 
					
						
							|  |  |  |             input$correlation / 100 * r_mean] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Order the results based on their score. The resulting index will be | 
					
						
							|  |  |  |         # used as the "rank". | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         setorder(results, -score) | 
					
						
							| 
									
										
										
										
											2021-08-26 11:20:50 +02:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2021-08-25 15:01:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |     output$genes <- renderDT({ | 
					
						
							|  |  |  |         datatable( | 
					
						
							| 
									
										
										
										
											2021-09-18 23:10:52 +02:00
										 |  |  |             results()[, .(.I, name, cluster_length, r_mean)], | 
					
						
							| 
									
										
										
										
											2021-08-26 12:51:43 +02:00
										 |  |  |             rownames = FALSE, | 
					
						
							| 
									
										
										
										
											2021-08-25 15:01:18 +02:00
										 |  |  |             colnames = c( | 
					
						
							|  |  |  |                 "Rank", | 
					
						
							|  |  |  |                 "Gene", | 
					
						
							|  |  |  |                 "Cluster length", | 
					
						
							| 
									
										
										
										
											2021-09-18 23:10:52 +02:00
										 |  |  |                 "Correlation" | 
					
						
							| 
									
										
										
										
											2021-08-25 15:01:18 +02:00
										 |  |  |             ), | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |             style = "bootstrap" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-29 15:29:34 +02:00
										 |  |  |     output$synposis <- renderText({ | 
					
						
							|  |  |  |         results <- results() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         sprintf( | 
					
						
							|  |  |  |             "Found %i candidates including %i/%i verified and %i/%i suggested \ | 
					
						
							|  |  |  |             TPE-OLD genes.", | 
					
						
							|  |  |  |             results[, .N], | 
					
						
							|  |  |  |             results[verified == TRUE, .N], | 
					
						
							| 
									
										
										
										
											2021-09-16 00:06:54 +02:00
										 |  |  |             genes[verified == TRUE, .N], | 
					
						
							| 
									
										
										
										
											2021-08-29 15:29:34 +02:00
										 |  |  |             results[suggested == TRUE, .N], | 
					
						
							| 
									
										
										
										
											2021-09-16 00:06:54 +02:00
										 |  |  |             genes[suggested == TRUE, .N] | 
					
						
							| 
									
										
										
										
											2021-08-29 15:29:34 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |     output$scatter <- renderPlot({ | 
					
						
							| 
									
										
										
										
											2021-08-29 13:25:12 +02:00
										 |  |  |         results <- results() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         gene_ids <- results[input$genes_rows_selected, gene] | 
					
						
							| 
									
										
										
										
											2021-09-16 00:06:54 +02:00
										 |  |  |         genes <- genes[id %chin% gene_ids] | 
					
						
							| 
									
										
										
										
											2021-08-29 13:25:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         species <- if (input$species == "all") { | 
					
						
							| 
									
										
										
										
											2021-09-16 00:06:54 +02:00
										 |  |  |             species | 
					
						
							| 
									
										
										
										
											2021-08-29 13:25:12 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-09-16 00:06:54 +02:00
										 |  |  |             species[replicative == TRUE] | 
					
						
							| 
									
										
										
										
											2021-08-29 13:25:12 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-16 00:06:54 +02:00
										 |  |  |         scatter_plot(results, species, genes, distances) | 
					
						
							| 
									
										
										
										
											2021-06-24 22:38:16 +02:00
										 |  |  |     }) | 
					
						
							|  |  |  | } |