mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 18:57:25 +01:00
Implement gene set highlighting in positions plot
This commit is contained in:
parent
7e53015168
commit
e41d02c659
2 changed files with 26 additions and 2 deletions
23
R/plots.R
23
R/plots.R
|
|
@ -385,12 +385,16 @@ plot_chromosomes <- function(ranking) {
|
||||||
#'
|
#'
|
||||||
#' @param ranking The ranking to visualize.
|
#' @param ranking The ranking to visualize.
|
||||||
#' @param chromosome_name The chromosome to visualize.
|
#' @param chromosome_name The chromosome to visualize.
|
||||||
|
#' @param gene_sets Named list of vectors of genes to highlight. The list names
|
||||||
|
#' will be used as labels.
|
||||||
#'
|
#'
|
||||||
#' @return A `plotly` figure.
|
#' @return A `plotly` figure.
|
||||||
#' @seealso ranking()
|
#' @seealso ranking()
|
||||||
#'
|
#'
|
||||||
#' @export
|
#' @export
|
||||||
plot_scores_by_position <- function(ranking, chromosome_name) {
|
plot_scores_by_position <- function(ranking,
|
||||||
|
chromosome_name,
|
||||||
|
gene_sets = NULL) {
|
||||||
if (!requireNamespace("plotly", quietly = TRUE)) {
|
if (!requireNamespace("plotly", quietly = TRUE)) {
|
||||||
stop("Please install \"plotly\" to use this function.")
|
stop("Please install \"plotly\" to use this function.")
|
||||||
}
|
}
|
||||||
|
|
@ -406,11 +410,28 @@ plot_scores_by_position <- function(ranking, chromosome_name) {
|
||||||
by = "gene"
|
by = "gene"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data[, `:=`(gene_set = "All genes", color = base_color())]
|
||||||
|
|
||||||
|
index <- 1
|
||||||
|
for (gene_set_name in names(gene_sets)) {
|
||||||
|
gene_set_genes <- gene_sets[[gene_set_name]]
|
||||||
|
data[
|
||||||
|
gene %chin% gene_set_genes,
|
||||||
|
`:=`(
|
||||||
|
gene_set = gene_set_name,
|
||||||
|
color = gene_set_color(index)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
index <- index + 1
|
||||||
|
}
|
||||||
|
|
||||||
plotly::plot_ly() |>
|
plotly::plot_ly() |>
|
||||||
plotly::add_markers(
|
plotly::add_markers(
|
||||||
data = data,
|
data = data,
|
||||||
x = ~start_position,
|
x = ~start_position,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
|
name = ~gene_set,
|
||||||
hoverinfo = "skip"
|
hoverinfo = "skip"
|
||||||
) |>
|
) |>
|
||||||
plotly::layout(
|
plotly::layout(
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,15 @@
|
||||||
\alias{plot_scores_by_position}
|
\alias{plot_scores_by_position}
|
||||||
\title{Plot scores in relation to chromosomal position of genes.}
|
\title{Plot scores in relation to chromosomal position of genes.}
|
||||||
\usage{
|
\usage{
|
||||||
plot_scores_by_position(ranking, chromosome_name)
|
plot_scores_by_position(ranking, chromosome_name, gene_sets = NULL)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{ranking}{The ranking to visualize.}
|
\item{ranking}{The ranking to visualize.}
|
||||||
|
|
||||||
\item{chromosome_name}{The chromosome to visualize.}
|
\item{chromosome_name}{The chromosome to visualize.}
|
||||||
|
|
||||||
|
\item{gene_sets}{Named list of vectors of genes to highlight. The list names
|
||||||
|
will be used as labels.}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
A \code{plotly} figure.
|
A \code{plotly} figure.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue