Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
^pkgdown$
^data-raw$
^\.bumpversion\.toml$
^Makefile$

^CODE_OF_CONDUCT\.md$
^inst/rmd/rnasum.html$
Expand Down
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# All available hooks: https://pre-commit.com/hooks.html
# R specific hooks: https://github.com/lorenzwalthert/precommit
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.3.9017
hooks:
- id: use-tidy-description
- id: readme-rmd-rendered
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=200']
- id: file-contents-sorter
files: '^\.Rbuildignore$'
- repo: local
hooks:
- id: forbid-to-commit
Expand Down
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ License: MIT + file LICENSE
Depends:
R (>= 4.1.0)
Remotes:
umccr/RNAsum.data,
sahirbhatnagar/manhattanly
umccr/RNAsum.data
biocViews: Software, RNASeq, Workflow
Imports:
assertthat,
Expand All @@ -38,7 +37,6 @@ Imports:
htmlwidgets,
knitr,
limma,
manhattanly,
matrixStats,
optparse,
pdftools,
Expand Down
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2026
COPYRIGHT HOLDER: RNAsum authors
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: all pkgdown

check:
@R -e "devtools::check()" --quiet --no-restore --no-save

pkgdown:
@R -e "pkgdown::build_site()" --quiet --no-restore --no-save

roxydoc:
@R -e "devtools::document()" --quiet --no-restore --no-save

build:
@R -e "pak::local_install(upgrade = FALSE, dependencies = FALSE)" --quiet --no-restore --no-save

1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export(pca)
export(pcgr_expr)
export(pcgr_tiers_tsv_read)
export(perc_rank)
export(plot_cnv_manhattan)
export(ppl_cnv_som_gene_read)
export(prepare2write)
export(purple_cnv_summary)
Expand Down
1 change: 1 addition & 0 deletions R/exprTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' @param type Type.
#' @param civic_clin_evid civic_clin_evid tibble from reference genes.
#' @param scaling Scaling
#' @param batch_rm Remove batch-associated effects between datasets.
#'
#' @importFrom dplyr %>%
#' @return Table with coloured cells indicating expression values for selected genes
Expand Down
6 changes: 3 additions & 3 deletions R/kallisto.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#' @return Tibble with the counts per gene transcript, or NULL if any of the
#' input params are NULL.
#' @examples
#' x <- system.file("rawdata/test_data/quant/abundance.tsv", package = "RNAsum")
#' x <- system.file("rawdata/test_data/kallisto/abundance.tsv", package = "RNAsum")
#' tx2gene <- NULL
#' (kc <- kallisto_counts(x, tx2gene)) # NULL since no tx2gene specified
#' @testexamples
#' expect_null(sc)
#' expect_null(kc)
#' @export
kallisto_counts <- function(x, tx2gene = NULL) {
if (is.null(x) || is.null(tx2gene)) {
Expand All @@ -29,7 +29,7 @@ kallisto_counts <- function(x, tx2gene = NULL) {
txi_kallisto <- tximport::tximport(files = x, type = "kallisto", tx2gene = tx2gene)
counts <- txi_kallisto[["counts"]] |>
tibble::as_tibble(rownames = "rowname", .name_repair = make.names) |>
dplyr::rename(count = X) |>
dplyr::rename(count = .data$X) |>
dplyr::filter(!grepl("PAR_Y", .data$rowname))

counts <- counts |>
Expand Down
253 changes: 253 additions & 0 deletions R/manhattan.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
#' Manhattan Plot for Copynumber Data
#'
#' @param cnv_data CN data frame including Gene, P, Diff_Perc, Diff_Z_score,
#' Alterations, GENEBIOTYPE, ENSEMBL, SEQNAME, GENESEQSTART, GENESEQEND,
#' Immunic_Cycle_Role.
#' @param genes_to_highlight Atomic vector of gene names to highlight.
#' @param title Plot title.
#' @param show_legend Show legend.
#' @param point_size Point size.
#' @param highlight_size Highlight size.
#' @param cn_top Top CN threshold.
#' @param cn_bottom Bottom CN threshold.
#'
#' @returns Plotly object.
#'
#' @examples
#' \dontrun{
#' cnv_data <- data.annot
#' genes_to_highlight <- unique(data.sub$Gene)
#' }
#' @export
plot_cnv_manhattan <- function(
cnv_data,
genes_to_highlight = NULL,
title = "",
show_legend = TRUE,
point_size = 3,
highlight_size = 8,
cn_top = NULL,
cn_bottom = NULL
) {
chr_lengths <- cnv_data |>
dplyr::group_by(.data$SEQNAME) |>
dplyr::summarize(max_pos = max(.data$GENESEQSTART), .groups = "drop") |>
dplyr::arrange(.data$SEQNAME) |>
dplyr::mutate(offset = cumsum(c(0, utils::head(.data$max_pos, -1))))

plot_data <- cnv_data |>
dplyr::left_join(chr_lengths, by = "SEQNAME") |>
dplyr::mutate(
pos_cum = .data$GENESEQSTART + .data$offset,
is_highlighted = .data$Gene %in% genes_to_highlight
)

data_normal <- plot_data |>
dplyr::filter(!.data$is_highlighted)
data_highlight <- plot_data |>
dplyr::filter(.data$is_highlighted)

chr_centers <- plot_data |>
dplyr::group_by(.data$SEQNAME) |>
dplyr::summarize(
center = (min(.data$pos_cum) + max(.data$pos_cum)) / 2,
.groups = "drop"
) |>
dplyr::arrange(.data$SEQNAME)

chr_bands <- plot_data |>
dplyr::group_by(.data$SEQNAME) |>
dplyr::summarize(
xmin = min(.data$pos_cum),
xmax = max(.data$pos_cum),
.groups = "drop"
) |>
dplyr::arrange(.data$SEQNAME) |>
dplyr::mutate(
color = ifelse(
seq_len(dplyr::n()) %% 2 == 0,
"rgba(220, 220, 220, 0.3)",
"rgba(180, 180, 180, 0.3)"
)
)

y_max <- max(plot_data$P, cn_top, na.rm = TRUE) * 1.05
y_min <- min(plot_data$P, cn_bottom, na.rm = TRUE)
x_min <- min(plot_data$pos_cum, na.rm = TRUE)
x_max <- max(plot_data$pos_cum, na.rm = TRUE)

chr_label <- function(chr) {
dplyr::case_when(
chr == 23L ~ "X",
chr == 24L ~ "Y",
chr == 25L ~ "MT",
.default = as.character(chr)
)
}

p <- plotly::plot_ly()

for (i in seq_len(nrow(chr_bands))) {
p <- p |>
plotly::add_ribbons(
x = c(chr_bands$xmin[i], chr_bands$xmax[i]),
ymin = rep(y_min, 2),
ymax = rep(y_max, 2),
fillcolor = chr_bands$color[i],
line = list(width = 0),
showlegend = FALSE,
hoverinfo = "skip"
)
}

for (chr in sort(unique(data_normal$SEQNAME))) {
chr_data <- data_normal |>
dplyr::filter(.data$SEQNAME == chr)
color <- ifelse(chr %% 2 == 0, "#404040", "#808080")

p <- p |>
plotly::add_trace(
data = chr_data,
x = ~pos_cum,
y = ~P,
type = "scatter",
mode = "markers",
marker = list(size = point_size, color = color, opacity = 0.6),
text = ~ paste0(
"<b>",
Gene,
"</b><br>",
"(",
format(GENESEQSTART, big.mark = ","),
", ",
round(P, 2),
") chr",
chr_label(SEQNAME),
"<br>",
"Gene: ",
Gene,
"<br>",
"Diff_Z_score: ",
round(Diff_Z_score, 2),
"<br>",
"Diff_Perc: ",
round(Diff_Perc, 1),
"<br>",
"Alterations: ",
Alterations
),
hoverinfo = "text",
showlegend = FALSE,
name = paste("Chr", chr_label(chr))
)
}

if (nrow(data_highlight) > 0) {
unique_genes <- unique(data_highlight$Gene)
for (gene_name in unique_genes) {
gene_data <- data_highlight |>
dplyr::filter(.data$Gene == gene_name)
p <- p |>
plotly::add_trace(
data = gene_data,
x = ~pos_cum,
y = ~P,
type = "scatter",
mode = "markers",
marker = list(
size = highlight_size,
color = "#E74C3C",
line = list(color = "#C0392B", width = 1),
opacity = 0.9
),
text = ~ paste0(
"<b>",
Gene,
"</b><br>",
"(",
format(GENESEQSTART, big.mark = ","),
", ",
round(P, 2),
") chr",
chr_label(SEQNAME),
"<br>",
"Gene: ",
Gene,
"<br>",
"Diff_Z_score: ",
round(Diff_Z_score, 2),
"<br>",
"Diff_Perc: ",
round(Diff_Perc, 1),
"<br>",
"Alterations: ",
Alterations
),
hoverinfo = "text",
name = gene_name,
showlegend = show_legend
)
}
}

if (!is.null(cn_top)) {
p <- p |>
plotly::add_segments(
x = x_min,
xend = x_max,
y = cn_top,
yend = cn_top,
line = list(color = "gray", width = 1, dash = "dash"),
inherit = FALSE,
showlegend = FALSE,
hoverinfo = "skip"
)
}
if (!is.null(cn_bottom)) {
p <- p |>
plotly::add_segments(
x = x_min,
xend = x_max,
y = cn_bottom,
yend = cn_bottom,
line = list(color = "gray", width = 1, dash = "dash"),
inherit = FALSE,
showlegend = FALSE,
hoverinfo = "skip"
)
}

p1 <- p |>
plotly::layout(
title = list(text = title, x = 0.5, xanchor = "center"),
xaxis = list(
title = list(text = "Chromosome"),
tickmode = "array",
tickvals = chr_centers$center,
ticktext = vapply(chr_centers$SEQNAME, chr_label, character(1)),
showgrid = FALSE,
zeroline = FALSE
),
yaxis = list(
title = list(text = "CN value"),
showgrid = TRUE,
gridcolor = "rgba(200, 200, 200, 0.5)",
zeroline = TRUE
),
hovermode = "closest",
plot_bgcolor = "white",
paper_bgcolor = "white",
legend = list(
orientation = "v",
yanchor = "top",
y = 1,
xanchor = "left",
x = 1.02,
bgcolor = "rgba(255, 255, 255, 0.8)",
bordercolor = "rgba(0, 0, 0, 0.2)",
borderwidth = 1
),
margin = list(r = 150)
)
p1
}
3 changes: 2 additions & 1 deletion R/refdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#' Get a list of paths to internal and external reference data, based on a
#' selected dataset name.
#' @param dataset Reference RNAsum dataset of interest.
#' @param batch_rm Remove batch-associated effects between datasets.
#'
#' @return List with paths to internal and external reference datasets
#' (Counts, Targets and Name).
#'
#' @examples
#' x <- get_refdata(dataset = "TEST")
#' @export
get_refdata <- function(dataset, batch_rm) {
get_refdata <- function(dataset, batch_rm = FALSE) {
assertthat::assert_that(dataset %in% names(RNAsum::REFERENCE_DATASETS))
refdata_dir <- system.file("extdata", package = "RNAsum.data")
d_clean <- base::strsplit(dataset, split = "-", fixed = TRUE)[[1]][1]
Expand Down
1 change: 0 additions & 1 deletion R/utils_shortcuts.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dummy1 <- function() {
ggforce::geom_sina
ggplot2::ggplot
limma::removeBatchEffect
manhattanly::manhattanly
optparse::make_option
preprocessCore::normalize.quantiles
ragg::agg_png
Expand Down
Loading