mirror of
https://github.com/johrpan/ubigen.git
synced 2025-10-26 19:57:24 +01:00
Add gene selector for custom genes
This commit is contained in:
parent
780e608ee1
commit
5f5670171d
8 changed files with 168 additions and 36 deletions
56
R/plots.R
56
R/plots.R
|
|
@ -1,35 +1,59 @@
|
|||
#' Create a plot showing an overview over the provided ranking.
|
||||
#'
|
||||
#' @param ranked_data The ranking to visualize.
|
||||
#' @param highlighted_genes Genes that will be marked.
|
||||
#' @param sample_proportion Proportion of rows to use as the shown sample.
|
||||
#'
|
||||
#' @return A `plotly` figure.
|
||||
#' @noRd
|
||||
overview_plot <- function(ranked_data, sample_proportion = 0.05) {
|
||||
plotly::plot_ly() |>
|
||||
overview_plot <- function(ranked_data,
|
||||
highlighted_genes = NULL,
|
||||
sample_proportion = 0.05) {
|
||||
figure <- plotly::plot_ly() |>
|
||||
plotly::add_lines(
|
||||
data = ranked_data[sample(
|
||||
nrow(ranked_data),
|
||||
sample_proportion * nrow(ranked_data)
|
||||
)],
|
||||
x = ~rank,
|
||||
y = ~score
|
||||
y = ~score,
|
||||
hoverinfo = "skip"
|
||||
) |>
|
||||
plotly::layout(
|
||||
xaxis = list(title = "Ranks"),
|
||||
yaxis = list(title = "Score")
|
||||
)
|
||||
|
||||
if (!is.null(highlighted_genes)) {
|
||||
figure <- figure |>
|
||||
plotly::add_markers(
|
||||
data = ranked_data[gene %chin% highlighted_genes],
|
||||
x = ~rank,
|
||||
y = ~score,
|
||||
text = ~ glue::glue(
|
||||
"<b>{hgnc_name}</b><br>",
|
||||
"Score: {round(score, digits = 2)}<br>",
|
||||
"Rank: {rank}<br>",
|
||||
"Percentile: {round(percentile * 100, digits = 2)}%"
|
||||
),
|
||||
hoverinfo = "text",
|
||||
showlegend = FALSE
|
||||
)
|
||||
}
|
||||
|
||||
figure
|
||||
}
|
||||
|
||||
#' Create plot showing the distribution of scores using `plotly`.
|
||||
#'
|
||||
#' @param ranked_data Data on genes with precomputed ranks.
|
||||
#' @param highlighted_genes Genes that will be marked.
|
||||
#' @param ranks How may ranks the x-axis should include. If this parameter is
|
||||
#' `NULL`, all ranks will be shown.
|
||||
#'
|
||||
#' @return A `plotly` figure for rendering.
|
||||
#' @noRd
|
||||
scores_plot <- function(ranked_data, ranks = 1000) {
|
||||
scores_plot <- function(ranked_data, highlighted_genes = NULL, ranks = 1000) {
|
||||
data <- if (is.null(ranks)) {
|
||||
ranked_data
|
||||
} else {
|
||||
|
|
@ -42,20 +66,26 @@ scores_plot <- function(ranked_data, ranks = 1000) {
|
|||
glue::glue("Ranks (1 to {ranks})")
|
||||
}
|
||||
|
||||
data[, group := data.table::fifelse(
|
||||
gene %chin% highlighted_genes,
|
||||
"Your genes",
|
||||
"All genes"
|
||||
)]
|
||||
|
||||
plotly::plot_ly() |>
|
||||
plotly::add_markers(
|
||||
data = data,
|
||||
x = ~rank,
|
||||
y = ~score,
|
||||
text = ~hgnc_name,
|
||||
customdata = ~percentile,
|
||||
hovertemplate = paste0(
|
||||
"<b>%{text}</b><br>",
|
||||
"Rank: %{x}<br>",
|
||||
"Score: %{y:.2}<br>",
|
||||
"Percentile: %{customdata:.2%}",
|
||||
"<extra></extra>"
|
||||
)
|
||||
name = ~group,
|
||||
text = ~ glue::glue(
|
||||
"<b>{hgnc_name}</b><br>",
|
||||
"Score: {round(score, digits = 2)}<br>",
|
||||
"Rank: {rank}<br>",
|
||||
"Percentile: {round(percentile * 100, digits = 2)}%"
|
||||
),
|
||||
hoverinfo = "text",
|
||||
showlegend = FALSE
|
||||
) |>
|
||||
plotly::layout(
|
||||
xaxis = list(title = ranks_label),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue