| 
									
										
										
										
											2021-12-06 13:54:22 +01:00
										 |  |  | # Create a comparison editor. | 
					
						
							|  |  |  | comparison_editor_ui <- function(id) { | 
					
						
							|  |  |  |     verticalLayout( | 
					
						
							|  |  |  |         h3("Comparison"), | 
					
						
							|  |  |  |         selectInput( | 
					
						
							|  |  |  |             NS(id, "comparison_genes"), | 
					
						
							|  |  |  |             "Comparison genes", | 
					
						
							|  |  |  |             choices = list( | 
					
						
							|  |  |  |                 "None" = "none", | 
					
						
							|  |  |  |                 "Random genes" = "random", | 
					
						
							|  |  |  |                 "Verified or suggested TPE-OLD genes" = "tpeold", | 
					
						
							|  |  |  |                 "Only verified TPE-OLD genes" = "verified", | 
					
						
							|  |  |  |                 "Only suggested TPE-OLD genes" = "suggested", | 
					
						
							|  |  |  |                 "Customize" = "custom" | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2021-12-08 13:46:59 +01:00
										 |  |  |         conditionalPanel( | 
					
						
							|  |  |  |             condition = sprintf( | 
					
						
							|  |  |  |                 "input['%s'] == 'custom'", | 
					
						
							|  |  |  |                 NS(id, "comparison_genes") | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2021-12-15 12:41:35 +01:00
										 |  |  |             selectInput( | 
					
						
							|  |  |  |                 NS(id, "identifier_type"), | 
					
						
							|  |  |  |                 "Gene identifiers", | 
					
						
							|  |  |  |                 choices = list( | 
					
						
							|  |  |  |                     "HGNC symbols" = "hgnc", | 
					
						
							|  |  |  |                     "Ensembl gene IDs" = "ensembl" | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             textAreaInput( | 
					
						
							| 
									
										
										
										
											2021-12-08 13:46:59 +01:00
										 |  |  |                 inputId = NS(id, "custom_comparison_genes"), | 
					
						
							| 
									
										
										
										
											2021-12-15 12:41:35 +01:00
										 |  |  |                 label = "Enter comparison genes", | 
					
						
							|  |  |  |                 height = "250px" | 
					
						
							| 
									
										
										
										
											2021-12-06 13:54:22 +01: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. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # @return A reactive containing the comparison gene IDs. | 
					
						
							|  |  |  | comparison_editor_server <- function(id, preset) { | 
					
						
							|  |  |  |     moduleServer(id, function(input, output, session) { | 
					
						
							|  |  |  |         reactive({ | 
					
						
							|  |  |  |             if (input$comparison_genes == "none") { | 
					
						
							|  |  |  |                 NULL | 
					
						
							|  |  |  |             } else if (input$comparison_genes == "random") { | 
					
						
							|  |  |  |                 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))] | 
					
						
							|  |  |  |             } else if (input$comparison_genes == "tpeold") { | 
					
						
							|  |  |  |                 genes[verified | suggested == TRUE, id] | 
					
						
							|  |  |  |             } else if (input$comparison_genes == "verified") { | 
					
						
							|  |  |  |                 genes[verified == TRUE, id] | 
					
						
							|  |  |  |             } else if (input$comparison_genes == "suggested") { | 
					
						
							|  |  |  |                 genes[suggested == TRUE, id] | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2021-12-15 12:41:35 +01:00
										 |  |  |                 inputs <- strsplit(input$custom_comparison_genes, "\\s+")[[1]] | 
					
						
							|  |  |  |                 if (input$identifier_type == "hgnc") { | 
					
						
							|  |  |  |                     geposan::genes[name %chin% inputs, id] | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     geposan::genes[id %chin% inputs, id] | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-12-06 13:54:22 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | } |