Skip to content

Commit

Permalink
add reorder.rows to dotplot_pwys so that it can leave ordering as is
Browse files Browse the repository at this point in the history
  • Loading branch information
jdreyf committed Jan 30, 2024
1 parent 51b6303 commit f568486
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ezlimmaplot
Title: Bioinformatics plots using limma and ggplot2, some from output of ezlimma
Version: 0.0.3.9000
Version: 0.0.3.9001
Authors@R: c(person("Jonathan", "Dreyfuss", role = c("aut", "cre"), email = "[email protected]"),
person("Hui", "Pan", role = "aut"),
person("Grace", "Daher", role="ctb"))
Expand Down
7 changes: 4 additions & 3 deletions R/dotplot_pwys.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @param ntop Integer number of top pathways to show.
#' @param name Name of file to create. Set to \code{NA} to plot to screen instead of to file; otherwise, "_dotplot.pdf" is appended to the name.
#' @param mixed Character string. Should mixed statistics be included, should they be the only statistics included, or should they be excluded?
#' @param reorder.rows Boolean; reorder pathways by significance before selecting \code{ntop} pathways? If not, order of \code{tab} is retained.
#' @param caption Logical; should the caption explaining the color bar title be included?
#' @param colorbar.title Character title of color bar.
#' @inheritParams ezheat
Expand All @@ -24,7 +25,7 @@
# https://github.com/YuLab-SMU/enrichplot/blob/0a01deaa5901b8af37d78c561e5f8200b4748b59/R/dotplot.R
# prefix.v=NULL; name = NA; type.sig="p"; cut.sig=0.05; ntop = 20; pwys_nm_size = 100; width = 8; height = 8; mixed="include"; caption=TRUE; colorbar.title = "Prop P<5%"
dotplot_pwys <- function(tab, prefix.v=NULL, name = NA, type.sig=c("p", "FDR"), cut.sig=0.05, ntop = 20, pwys_nm_size = 100, width = 8, height = 8,
mixed = c("include", "exclude", "only"), caption=TRUE, colorbar.title = "Prop P<5%"){
mixed = c("include", "exclude", "only"), reorder.rows=TRUE, caption=TRUE, colorbar.title = "Prop P<5%"){
type.sig <- match.arg(type.sig)
mixed <- match.arg(mixed)
stopifnot(mixed == "exclude" | any(grepl("Mixed", colnames(tab))), cut.sig > 0, cut.sig <= 1)
Expand Down Expand Up @@ -52,8 +53,8 @@ dotplot_pwys <- function(tab, prefix.v=NULL, name = NA, type.sig=c("p", "FDR"),
# filter out non-significant comparison x pathway rows
# could do this in for loop separately for Mixed and not Mixed, but here I only need to do it once
# then subset to 1st ntop rows: this does not cause error or warning even if ntop > nrow(ds)
ds <- ds |> dplyr::arrange(!!rlang::sym(type.sig)) |>
dplyr::filter(!!rlang::sym(type.sig) < cut.sig)
if (reorder.rows) ds <- ds |> dplyr::arrange(!!rlang::sym(type.sig))
ds <- ds |> dplyr::filter(!!rlang::sym(type.sig) < cut.sig)
ds <- ds |> dplyr::filter(Pwy %in% (ds |> dplyr::slice(1:ntop) |> dplyr::pull(Pwy)))
if (nrow(ds) == 0) stop("No pathways had ", type.sig, " < ", cut.sig, ".")
pwy.max.nchar <- ds |> dplyr::pull(Pwy) |> nchar() |> max()
Expand Down
3 changes: 3 additions & 0 deletions man/dotplot_pwys.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/testthat/test-dotplot_pwys.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ test_that("dotplot_pwy works", {
res <- rc2 |> dplyr::arrange(desc(First3.p)) |>
dotplot_pwys(ntop=1)
expect_equal(unique(res$data$Pwy), "pwy1")
res2 <- rc2 |> dplyr::arrange(desc(First3.p)) |>
dotplot_pwys(ntop=1, reorder.rows = FALSE)
expect_equal(unique(res2$data$Pwy), "mother of all pathways")
unlink(x = "pwy_dotplot.pdf")

expect_error(dotplot_pwys(rc2, name = NA, cut.sig = 10**-6))
Expand Down

0 comments on commit f568486

Please sign in to comment.