| 
									
										
										
										
											2021-10-20 15:34:52 +02:00
										 |  |  | # Draw a plot displaying the rank of reference genes. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # The input table should contain the following columns: | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  - `gene` Gene IDs of genes to display. | 
					
						
							|  |  |  | #  - `name` Name of genes to display. | 
					
						
							|  |  |  | #  - `score` Score of the genes. | 
					
						
							|  |  |  | #  - `rank` Rank of the genes based on the score. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # @param results Results to display. | 
					
						
							|  |  |  | # @param reference_gene_ids IDs of reference genes. | 
					
						
							| 
									
										
										
										
											2021-11-02 13:41:03 +01:00
										 |  |  | # @param max_rank Last rank of the included genes. | 
					
						
							|  |  |  | rank_plot <- function(results, reference_gene_ids, max_rank) { | 
					
						
							| 
									
										
										
										
											2021-10-20 15:34:52 +02:00
										 |  |  |     plot <- plotly::plot_ly() |> plotly::add_trace( | 
					
						
							| 
									
										
										
										
											2021-10-15 13:16:51 +02:00
										 |  |  |         data = results, | 
					
						
							|  |  |  |         x = ~rank, | 
					
						
							|  |  |  |         y = ~score, | 
					
						
							|  |  |  |         name = "All genes", | 
					
						
							|  |  |  |         type = "scatter", | 
					
						
							|  |  |  |         mode = "line", | 
					
						
							|  |  |  |         hoverinfo = "skip" | 
					
						
							| 
									
										
										
										
											2021-10-20 15:34:52 +02:00
										 |  |  |     ) |> plotly::add_trace( | 
					
						
							| 
									
										
										
										
											2021-10-15 13:16:51 +02:00
										 |  |  |         data = results[gene %chin% reference_gene_ids], | 
					
						
							|  |  |  |         x = ~rank, | 
					
						
							|  |  |  |         y = ~score, | 
					
						
							|  |  |  |         color = ~gene, | 
					
						
							|  |  |  |         name = ~name, | 
					
						
							|  |  |  |         width = 10, | 
					
						
							|  |  |  |         type = "bar" | 
					
						
							| 
									
										
										
										
											2021-10-20 15:34:52 +02:00
										 |  |  |     )  |> plotly::layout( | 
					
						
							| 
									
										
										
										
											2021-10-15 13:16:51 +02:00
										 |  |  |         xaxis = list(title = "Ranks"), | 
					
						
							|  |  |  |         yaxis = list(title = "Score") | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2021-10-15 18:33:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-02 13:41:03 +01:00
										 |  |  |     first_not_included_rank <- max_rank + 1 | 
					
						
							|  |  |  |     last_rank <- results[, .N] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 18:33:21 +02:00
										 |  |  |     if (first_not_included_rank <= last_rank) { | 
					
						
							| 
									
										
										
										
											2021-10-20 15:34:52 +02:00
										 |  |  |         plot <- plot |> plotly::layout( | 
					
						
							| 
									
										
										
										
											2021-10-15 18:33:21 +02:00
										 |  |  |             shapes = list( | 
					
						
							|  |  |  |                 type = "rect", | 
					
						
							|  |  |  |                 fillcolor = "black", | 
					
						
							|  |  |  |                 opacity = 0.1, | 
					
						
							|  |  |  |                 x0 = first_not_included_rank, | 
					
						
							|  |  |  |                 x1 = last_rank, | 
					
						
							|  |  |  |                 y0 = 0.0, | 
					
						
							|  |  |  |                 y1 = 1.0 | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     plot | 
					
						
							| 
									
										
										
										
											2021-10-19 14:15:28 +02:00
										 |  |  | } |