mirror of
https://github.com/johrpan/geposan.git
synced 2025-10-26 18:57:25 +01:00
Add option to show all chromosomes in positions plot
This commit is contained in:
parent
d83dfa0574
commit
a1e6147466
3 changed files with 36 additions and 20 deletions
|
|
@ -17,7 +17,7 @@ Encoding: UTF-8
|
||||||
LazyData: true
|
LazyData: true
|
||||||
LazyDataCompression: xz
|
LazyDataCompression: xz
|
||||||
Roxygen: list(markdown = TRUE)
|
Roxygen: list(markdown = TRUE)
|
||||||
RoxygenNote: 7.1.2
|
RoxygenNote: 7.2.0
|
||||||
Depends:
|
Depends:
|
||||||
R (>= 2.10)
|
R (>= 2.10)
|
||||||
Imports:
|
Imports:
|
||||||
|
|
|
||||||
38
R/plots.R
38
R/plots.R
|
|
@ -385,7 +385,9 @@ plot_chromosomes <- function(ranking) {
|
||||||
#' Plot scores in relation to chromosomal position of genes.
|
#' Plot scores in relation to chromosomal position of genes.
|
||||||
#'
|
#'
|
||||||
#' @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. If this is `NULL` all,
|
||||||
|
#' chromosomes will be included and the x-axis will show distances instead of
|
||||||
|
#' positions.
|
||||||
#' @param gene_sets Named list of vectors of genes to highlight. The list names
|
#' @param gene_sets Named list of vectors of genes to highlight. The list names
|
||||||
#' will be used as labels.
|
#' will be used as labels.
|
||||||
#'
|
#'
|
||||||
|
|
@ -394,22 +396,23 @@ plot_chromosomes <- function(ranking) {
|
||||||
#'
|
#'
|
||||||
#' @export
|
#' @export
|
||||||
plot_scores_by_position <- function(ranking,
|
plot_scores_by_position <- function(ranking,
|
||||||
chromosome_name,
|
chromosome_name = NULL,
|
||||||
gene_sets = NULL) {
|
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.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
distance_data <- if (!is.null(chromosome_name)) {
|
||||||
chromosome_name_ <- chromosome_name
|
chromosome_name_ <- chromosome_name
|
||||||
|
|
||||||
data <- merge(
|
|
||||||
ranking,
|
|
||||||
geposan::distances[
|
geposan::distances[
|
||||||
species == "hsapiens" &
|
species == "hsapiens" &
|
||||||
chromosome_name == chromosome_name_
|
chromosome_name == chromosome_name_
|
||||||
],
|
]
|
||||||
by = "gene"
|
} else {
|
||||||
)
|
geposan::distances[species == "hsapiens"]
|
||||||
|
}
|
||||||
|
|
||||||
|
data <- merge(ranking, distance_data, by = "gene")
|
||||||
|
|
||||||
data <- merge(
|
data <- merge(
|
||||||
data,
|
data,
|
||||||
|
|
@ -434,16 +437,23 @@ plot_scores_by_position <- function(ranking,
|
||||||
index <- index + 1
|
index <- index + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Use distances instead of positions in case all chromosomes are included.
|
||||||
|
if (is.null(chromosome_name)) {
|
||||||
|
data[, x := distance]
|
||||||
|
} else {
|
||||||
|
data[, x := start_position]
|
||||||
|
}
|
||||||
|
|
||||||
plotly::plot_ly() |>
|
plotly::plot_ly() |>
|
||||||
plotly::add_markers(
|
plotly::add_markers(
|
||||||
data = data,
|
data = data,
|
||||||
x = ~start_position,
|
x = ~x,
|
||||||
y = ~score,
|
y = ~score,
|
||||||
name = ~gene_set,
|
name = ~gene_set,
|
||||||
text = ~ glue::glue(
|
text = ~ glue::glue(
|
||||||
"<b>{name}</b><br>",
|
"<b>{name}</b><br>",
|
||||||
"Position: ",
|
if (is.null(chromosome_name)) "Distance: " else "Position: ",
|
||||||
"{round(start_position / 1000000, digits = 2)} MBp<br>",
|
"{round(x / 1000000, digits = 2)} MBp<br>",
|
||||||
"Score: {round(score, digits = 2)}<br>",
|
"Score: {round(score, digits = 2)}<br>",
|
||||||
"Rank: {rank}<br>",
|
"Rank: {rank}<br>",
|
||||||
"Percentile: {round(percentile * 100, digits = 2)}%"
|
"Percentile: {round(percentile * 100, digits = 2)}%"
|
||||||
|
|
@ -451,7 +461,11 @@ plot_scores_by_position <- function(ranking,
|
||||||
hoverinfo = "text",
|
hoverinfo = "text",
|
||||||
) |>
|
) |>
|
||||||
plotly::layout(
|
plotly::layout(
|
||||||
xaxis = list(title = "Position (Bp)"),
|
xaxis = list(title = if (is.null(chromosome_name)) {
|
||||||
|
"Distance (Bp)"
|
||||||
|
} else {
|
||||||
|
"Position (Bp)"
|
||||||
|
}),
|
||||||
yaxis = list(title = "Score")
|
yaxis = list(title = "Score")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@
|
||||||
\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, gene_sets = NULL)
|
plot_scores_by_position(ranking, chromosome_name = NULL, 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. If this is \code{NULL} all,
|
||||||
|
chromosomes will be included and the x-axis will show distances instead of
|
||||||
|
positions.}
|
||||||
|
|
||||||
\item{gene_sets}{Named list of vectors of genes to highlight. The list names
|
\item{gene_sets}{Named list of vectors of genes to highlight. The list names
|
||||||
will be used as labels.}
|
will be used as labels.}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue