mirror of
				https://github.com/johrpan/ubigen.git
				synced 2025-10-26 19:57:24 +01:00 
			
		
		
		
	Add rankings comparison section
This commit is contained in:
		
							parent
							
								
									8439066921
								
							
						
					
					
						commit
						bd8a829fe5
					
				
					 2 changed files with 120 additions and 7 deletions
				
			
		
							
								
								
									
										62
									
								
								R/server.R
									
										
									
									
									
								
							
							
						
						
									
										62
									
								
								R/server.R
									
										
									
									
									
								
							|  | @ -105,24 +105,76 @@ server <- function(custom_dataset = NULL) { | |||
|       highlighted_genes = custom_genes() | ||||
|     )) | ||||
| 
 | ||||
|     selected_genes <- reactive({ | ||||
|     selected_top_genes <- reactive({ | ||||
|       selected_points <- plotly::event_data("plotly_selected") | ||||
|       ranked_data()[rank %in% selected_points$x] | ||||
|     }) | ||||
| 
 | ||||
|     genes_table_server("selected_genes", reactive({ | ||||
|       if (nrow(selected_genes()) > 0) { | ||||
|         selected_genes() | ||||
|     genes_table_server("selected_top_genes", reactive({ | ||||
|       if (nrow(selected_top_genes()) > 0) { | ||||
|         selected_top_genes() | ||||
|       } else { | ||||
|         ranked_data() | ||||
|       } | ||||
|     })) | ||||
| 
 | ||||
|     output$rankings_plot <- plotly::renderPlotly({ | ||||
|       handle_axis <- function(ranking_id) { | ||||
|         if (ranking_id == "gtex_all") { | ||||
|           list( | ||||
|             ranking = rank_genes(ubigen::gtex_all), | ||||
|             label = "GTEx (across tissues and conditions)" | ||||
|           ) | ||||
|         } else if (ranking_id == "gtex_tissues") { | ||||
|           list( | ||||
|             ranking = rank_genes(ubigen::gtex_tissues), | ||||
|             label = "GTEx (across tissues)" | ||||
|           ) | ||||
|         } else if (ranking_id == "hpa_tissues") { | ||||
|           list( | ||||
|             ranking = rank_genes(ubigen::hpa_tissues), | ||||
|             label = "Human Protein Atlas (across tissues)" | ||||
|           ) | ||||
|         } else if (ranking_id == "cmap") { | ||||
|           list( | ||||
|             ranking = rank_genes(ubigen::cmap), | ||||
|             label = "CMap" | ||||
|           ) | ||||
|         } else { | ||||
|           list( | ||||
|             ranking = ranked_data(), | ||||
|             label = "Custom" | ||||
|           ) | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|       x <- handle_axis(input$ranking_x) | ||||
|       y <- handle_axis(input$ranking_y) | ||||
| 
 | ||||
|       rankings_comparison_plot( | ||||
|         x$ranking, | ||||
|         y$ranking, | ||||
|         label_x = x$label, | ||||
|         label_y = y$label, | ||||
|         highlighted_genes = custom_genes(), | ||||
|         use_percentiles = input$rankings_comparison_mode == "percentiles" | ||||
|       ) | ||||
|     }) | ||||
| 
 | ||||
|     selected_comparison_genes <- reactive({ | ||||
|       selected_points <- plotly::event_data("plotly_selected") | ||||
|       ranked_data()[gene %chin% selected_points$customdata] | ||||
|     }) | ||||
| 
 | ||||
|     genes_table_server("selected_comparison_genes", reactive({ | ||||
|       selected_comparison_genes() | ||||
|     })) | ||||
| 
 | ||||
|     gsea_genes <- reactive({ | ||||
|       sort(if (input$gsea_set == "top") { | ||||
|         ranked_data()[rank >= input$gsea_ranks, gene] | ||||
|       } else if (input$gsea_set == "selected") { | ||||
|         selected_genes()[, gene] | ||||
|         selected_top_genes()[, gene] | ||||
|       } else { | ||||
|         custom_genes() | ||||
|       }) | ||||
|  |  | |||
							
								
								
									
										65
									
								
								R/ui.R
									
										
									
									
									
								
							
							
						
						
									
										65
									
								
								R/ui.R
									
										
									
									
									
								
							|  | @ -126,7 +126,8 @@ ui <- function(custom_dataset = NULL) { | |||
|                 value = "top_genes", | ||||
|                 div(paste0( | ||||
|                   "Hover over the markers to see details on each gene. Click ", | ||||
|                   "or drag within the figure to select genes of interest." | ||||
|                   "or drag within the figure to select genes of interest. ", | ||||
|                   "Double-click removes the selection." | ||||
|                 )), | ||||
|                 plotly::plotlyOutput("scores_plot"), | ||||
|                 div(class = "p-1"), | ||||
|  | @ -137,7 +138,67 @@ ui <- function(custom_dataset = NULL) { | |||
|                   "on." | ||||
|                 )), | ||||
|                 div(class = "p-1"), | ||||
|                 genes_table_ui("selected_genes") | ||||
|                 genes_table_ui("selected_top_genes") | ||||
|               ), | ||||
|               tabPanel( | ||||
|                 "Compare rankings", | ||||
|                 value = "rankings", | ||||
|                 div( | ||||
|                   class = "flow-layout", | ||||
|                   selectInput( | ||||
|                     "ranking_y", | ||||
|                     label = NULL, | ||||
|                     list( | ||||
|                       "Custom" = "custom", | ||||
|                       "GTEx (across tissues and conditions)" = "gtex_all", | ||||
|                       "GTEx (across tissues)" = "gtex_tissues", | ||||
|                       "Human Protein Atlas (across tissues)" = "hpa_tissues", | ||||
|                       "CMap" = "cmap" | ||||
|                     ), | ||||
|                     selected = "cmap" | ||||
|                   ), | ||||
|                   span( | ||||
|                     style = paste0( | ||||
|                       "display: inline-block;", | ||||
|                       "margin-right: 12px;", | ||||
|                       "padding: 0.375rem 0.75rem;" | ||||
|                     ), | ||||
|                     "~" | ||||
|                   ), | ||||
|                   selectInput( | ||||
|                     "ranking_x", | ||||
|                     label = NULL, | ||||
|                     list( | ||||
|                       "Custom" = "custom", | ||||
|                       "GTEx (across tissues and conditions)" = "gtex_all", | ||||
|                       "GTEx (across tissues)" = "gtex_tissues", | ||||
|                       "Human Protein Atlas (across tissues)" = "hpa_tissues", | ||||
|                       "CMap" = "cmap" | ||||
|                     ) | ||||
|                   ), | ||||
|                   selectInput( | ||||
|                     "rankings_comparison_mode", | ||||
|                     label = NULL, | ||||
|                     list( | ||||
|                       "Compare scores" = "scores", | ||||
|                       "Compare percentiles" = "percentiles" | ||||
|                     ) | ||||
|                   ) | ||||
|                 ), | ||||
|                 div(class = "p-1"), | ||||
|                 div(paste0( | ||||
|                   "Hover over the markers to see the HGNC symbols for the ", | ||||
|                   "genes. Click or draw within the figure to select genes of ", | ||||
|                   "interest. Double-click removes the selection." | ||||
|                 )), | ||||
|                 div(class = "p-1"), | ||||
|                 plotly::plotlyOutput( | ||||
|                   "rankings_plot", | ||||
|                   width = "800px", | ||||
|                   height = "800px" | ||||
|                 ), | ||||
|                 div(class = "p-1"), | ||||
|                 genes_table_ui("selected_comparison_genes") | ||||
|               ), | ||||
|               tabPanel( | ||||
|                 "GSEA", | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue