| 
									
										
										
										
											2022-05-19 16:24:23 +02:00
										 |  |  | #' Create a comparison editor. | 
					
						
							|  |  |  | #' | 
					
						
							|  |  |  | #' @param options Global application options | 
					
						
							|  |  |  | #' @noRd | 
					
						
							|  |  |  | comparison_editor_ui <- function(id, options) { | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |   verticalLayout( | 
					
						
							| 
									
										
										
										
											2022-08-18 12:21:00 +02:00
										 |  |  |     h5("Comparison"), | 
					
						
							| 
									
										
										
										
											2024-02-18 14:29:23 +01:00
										 |  |  |     popover( | 
					
						
							|  |  |  |       title = "Comparison genes", | 
					
						
							|  |  |  |       help = paste0( | 
					
						
							|  |  |  |         "Select your genes of interest to compare their scores with the ", | 
					
						
							|  |  |  |         "reference genes. This will not influence the computation of scores, ", | 
					
						
							|  |  |  |         "but it will update the visualizations and summary statistics. Select ", | 
					
						
							|  |  |  |         "\"Your genes\" and use the other controls below for selecting or ", | 
					
						
							|  |  |  |         "pasting the genes. You can also use predefined gene sets for ", | 
					
						
							|  |  |  |         "comparison." | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       div(class = "label", "Comparison genes") | 
					
						
							|  |  |  |     ), | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |     selectInput( | 
					
						
							|  |  |  |       NS(id, "comparison_genes"), | 
					
						
							| 
									
										
										
										
											2024-02-18 14:29:23 +01:00
										 |  |  |       label = NULL, | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |       choices = c( | 
					
						
							| 
									
										
										
										
											2022-06-22 13:55:47 +02:00
										 |  |  |         "Your genes", | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |         "Random genes", | 
					
						
							| 
									
										
										
										
											2022-08-18 09:02:53 +02:00
										 |  |  |         names(options$comparison_gene_sets) | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |       ) | 
					
						
							|  |  |  |     ), | 
					
						
							|  |  |  |     conditionalPanel( | 
					
						
							|  |  |  |       condition = sprintf( | 
					
						
							| 
									
										
										
										
											2022-06-22 13:55:47 +02:00
										 |  |  |         "input['%s'] == 'Your genes'", | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |         NS(id, "comparison_genes") | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       gene_selector_ui(NS(id, "custom_genes")) | 
					
						
							| 
									
										
										
										
											2021-12-06 13:54:22 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |   ) | 
					
						
							| 
									
										
										
										
											2021-12-06 13:54:22 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-19 16:24:23 +02:00
										 |  |  | #' Create a server for the comparison editor. | 
					
						
							|  |  |  | #' | 
					
						
							|  |  |  | #' @param id ID for namespacing the inputs and outputs. | 
					
						
							|  |  |  | #' @param preset A reactive containing the current preset. | 
					
						
							|  |  |  | #' @param options Global application options | 
					
						
							|  |  |  | #' | 
					
						
							|  |  |  | #' @return A reactive containing the comparison gene IDs. | 
					
						
							|  |  |  | #' | 
					
						
							|  |  |  | #' @noRd | 
					
						
							|  |  |  | comparison_editor_server <- function(id, preset, options) { | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |   moduleServer(id, function(input, output, session) { | 
					
						
							|  |  |  |     custom_gene_ids <- gene_selector_server("custom_genes") | 
					
						
							| 
									
										
										
										
											2022-01-26 14:48:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |     reactive({ | 
					
						
							| 
									
										
										
										
											2022-06-22 13:55:47 +02:00
										 |  |  |       if (input$comparison_genes == "Random genes") { | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |         preset <- preset() | 
					
						
							|  |  |  |         gene_pool <- preset$gene_ids | 
					
						
							|  |  |  |         reference_gene_ids <- preset$reference_gene_ids | 
					
						
							|  |  |  |         gene_pool <- gene_pool[!gene_pool %chin% reference_gene_ids] | 
					
						
							|  |  |  |         gene_pool[sample(length(gene_pool), length(reference_gene_ids))] | 
					
						
							| 
									
										
										
										
											2022-06-22 13:55:47 +02:00
										 |  |  |       } else if (input$comparison_genes == "Your genes") { | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |         custom_gene_ids() | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2022-08-18 09:02:53 +02:00
										 |  |  |         options$comparison_gene_sets[[input$comparison_genes]] | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-12-06 13:54:22 +01:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2022-05-26 12:44:09 +02:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2021-12-06 13:54:22 +01:00
										 |  |  | } |