From 86f7524879fe1eedad46b5aa46e4f15b509685e2 Mon Sep 17 00:00:00 2001 From: HDash <16350928+HDash@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:51:31 +0100 Subject: [PATCH 01/13] Run rworkflows on all branches except gh-pages --- .github/workflows/rworkflows.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rworkflows.yml b/.github/workflows/rworkflows.yml index e845542..323fb1f 100644 --- a/.github/workflows/rworkflows.yml +++ b/.github/workflows/rworkflows.yml @@ -6,12 +6,16 @@ name: rworkflows - main - devel - RELEASE_** + - '*' + - '!gh-pages' pull_request: branches: - master - main - devel - RELEASE_** + - '*' + - '!gh-pages' jobs: rworkflows: permissions: write-all From 647711b75d93680b30443da32ced046ad9ce3076 Mon Sep 17 00:00:00 2001 From: HDash <16350928+HDash@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:00:22 +0100 Subject: [PATCH 02/13] Replace `magrittr` import by `dplyr::%>%` --- R/utils_pipe.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/utils_pipe.R b/R/utils_pipe.R index 4bb07bf..d6d4fbb 100644 --- a/R/utils_pipe.R +++ b/R/utils_pipe.R @@ -2,13 +2,14 @@ #' #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. #' -#' Generated by \code{\link[usethis]{use_pipe}}. +#' Generated by \code{\link[usethis]{use_pipe}}. Modified to import from +#' \code{dplyr} instead of \code{magrittr}. #' #' @name %>% #' @rdname pipe #' @keywords internal #' @export -#' @importFrom magrittr %>% +#' @importFrom dplyr %>% #' @usage lhs \%>\% rhs #' @param lhs A value or the magrittr placeholder. #' @param rhs A function call using the magrittr semantics. @@ -17,4 +18,6 @@ #' seq_len(10) %>% sum #' #' @return The result of calling `rhs(lhs)`. +#' +#' @keywords internal NULL From e37f4a78c71338ae822da55b29e9c1c4d30ee17e Mon Sep 17 00:00:00 2001 From: HDash <16350928+HDash@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:27:10 +0100 Subject: [PATCH 03/13] Internalise some functions and move utility functions to utilities.R --- DESCRIPTION | 3 +- NAMESPACE | 13 +- NEWS.md | 9 ++ R/bpapply.R | 2 +- R/check_ENCODE.R | 2 +- R/check_dep.R | 25 ---- R/check_duplicates.R | 16 --- R/confirm_meme_install.R | 24 ---- R/format_exptype.R | 44 ------ R/get_df_enrichment.R | 2 +- R/messager.R | 29 ---- R/plot_enrichment_individual.R | 2 +- R/pretty_number.R | 27 ---- R/report_command.R | 3 +- R/report_header.R | 2 +- R/segregate_seqs.R | 2 +- R/to_plotly.R | 2 +- R/trim_seqs.R | 2 +- R/use_cache.R | 22 --- R/utilities.R | 217 ++++++++++++++++++++++++++++++ R/utils_pipe.R | 23 ---- README.md | 28 ++-- inst/markdown/MotifPeeker.Rmd | 42 +++--- man/bpapply.Rd | 1 + man/check_ENCODE.Rd | 1 + man/check_dep.Rd | 2 +- man/check_duplicates.Rd | 2 +- man/confirm_meme_install.Rd | 2 +- man/format_exptype.Rd | 3 +- man/get_df_enrichment.Rd | 1 + man/messager.Rd | 2 +- man/pipe.Rd | 5 +- man/plot_enrichment_individual.Rd | 1 + man/pretty_number.Rd | 3 +- man/report_command.Rd | 2 +- man/report_header.Rd | 1 + man/segregate_seqs.Rd | 1 + man/to_plotly.Rd | 1 + man/trim_seqs.Rd | 1 + man/use_cache.Rd | 2 +- 40 files changed, 293 insertions(+), 279 deletions(-) delete mode 100644 R/check_dep.R delete mode 100644 R/check_duplicates.R delete mode 100644 R/confirm_meme_install.R delete mode 100644 R/format_exptype.R delete mode 100644 R/messager.R delete mode 100644 R/pretty_number.R delete mode 100644 R/use_cache.R create mode 100644 R/utilities.R delete mode 100644 R/utils_pipe.R diff --git a/DESCRIPTION b/DESCRIPTION index d769cf3..885b1b8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: MotifPeeker Title: Benchmarking Epigenomic Profiling Methods Using Motif Enrichment -Version: 0.99.4 +Version: 0.99.5 Authors@R: c( person(given = "Hiranyamaya", family = "Dash", @@ -57,7 +57,6 @@ Imports: BSgenome, memes, S4Vectors, - magrittr, dplyr, purrr, tidyr, diff --git a/NAMESPACE b/NAMESPACE index d1d79f3..193002b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,31 +2,20 @@ export("%>%") export(MotifPeeker) -export(bpapply) export(calc_frip) -export(check_ENCODE) export(check_JASPAR) export(check_genome_build) export(denovo_motifs) export(find_motifs) -export(format_exptype) export(get_JASPARCORE) export(get_df_distances) -export(get_df_enrichment) export(motif_enrichment) export(motif_similarity) -export(plot_enrichment_individual) export(plot_enrichment_overall) -export(pretty_number) export(read_motif_file) export(read_peak_file) -export(report_command) -export(report_header) export(save_peak_file) -export(segregate_seqs) export(summit_to_motif) -export(to_plotly) -export(trim_seqs) import(BiocParallel) import(dplyr) import(ggplot2) @@ -55,10 +44,10 @@ importFrom(Rsamtools,countBam) importFrom(S4Vectors,queryHits) importFrom(S4Vectors,subjectHits) importFrom(SummarizedExperiment,assay) +importFrom(dplyr,"%>%") importFrom(heatmaply,heatmaply) importFrom(htmltools,tagList) importFrom(htmlwidgets,JS) -importFrom(magrittr,"%>%") importFrom(memes,meme_is_installed) importFrom(memes,runAme) importFrom(memes,runFimo) diff --git a/NEWS.md b/NEWS.md index 6a754c0..a75e928 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# MotifPeeker 0.99.5 + +## Miscellaneous + +* Replace `magrittr` import by `dplyr::%>%`. +* Reduce the number of exported functions. +* Move utility functions to 'utilities.R'. + + # MotifPeeker 0.99.4 ## Miscellaneous diff --git a/R/bpapply.R b/R/bpapply.R index ece2700..8686a49 100644 --- a/R/bpapply.R +++ b/R/bpapply.R @@ -22,7 +22,7 @@ #' res <- bpapply(x, half_it, workers = 2) #' print(res) #' -#' @export +#' @keywords internal bpapply <- function( X, FUN, diff --git a/R/check_ENCODE.R b/R/check_ENCODE.R index ae1426b..f4156c2 100644 --- a/R/check_ENCODE.R +++ b/R/check_ENCODE.R @@ -18,7 +18,7 @@ #' check_ENCODE("ENCFF920TXI", expect_format = c("bed", "gz")) #' } #' -#' @export +#' @keywords internal check_ENCODE <- function(encode_id, expect_format, verbose = FALSE) { if (!all(is.character(encode_id))) return(encode_id) ### Validate ENCODE ID ### diff --git a/R/check_dep.R b/R/check_dep.R deleted file mode 100644 index d0bed15..0000000 --- a/R/check_dep.R +++ /dev/null @@ -1,25 +0,0 @@ -#' Check attached dependency -#' -#' Stop execution if a package is not attached. -#' -#' @param pkg a character string of the package name -#' @param fatal a logical value indicating whether to stop execution if the -#' package is not attached. -#' @param custom_msg a custom message to display if the package is not attached. -#' -#' @return Null -#' -#' @keywords internal -check_dep <- function(pkg, fatal = TRUE, custom_msg = NULL){ - if (is.null(custom_msg)) { - custom_msg <- paste("Package", shQuote(pkg), "is required to run this", - "function.") - } - if (!requireNamespace(pkg, quietly = TRUE)) { - if (fatal) { - stopper(custom_msg) - } else { - warning(custom_msg) - } - } -} diff --git a/R/check_duplicates.R b/R/check_duplicates.R deleted file mode 100644 index 56d19f9..0000000 --- a/R/check_duplicates.R +++ /dev/null @@ -1,16 +0,0 @@ -#' Check for duplicates -#' -#' Checks for duplicated items in a vector or list and throw an error if found. -#' -#' @param x A vector or list. -#' -#' @returns Null -#' -#' @keywords internal -check_duplicates <- function(x) { - stp_msg <- paste("Duplicated items found in the label list. Please input", - "unique experiment and motif labels.") - if (any(duplicated(x))) { - stopper(stp_msg) - } -} diff --git a/R/confirm_meme_install.R b/R/confirm_meme_install.R deleted file mode 100644 index 18c5bd9..0000000 --- a/R/confirm_meme_install.R +++ /dev/null @@ -1,24 +0,0 @@ -#' Stop if MEME suite is not installed -#' -#' @inheritParams memes::runFimo -#' -#' @importFrom memes meme_is_installed -#' -#' @returns Null -#' -#' @seealso \code{\link[memes]{check_meme_install}} -#' -#' @keywords internal -confirm_meme_install <- function(meme_path = NULL) { - stp_msg <- paste( - "Cannot find MEME suite installation. If installed, try setting the", - "path", shQuote("MEME_BIN"), "environment varaible, or use the", - shQuote("meme_path"), "parameter in the MotifPeeker function call.", - "\nFor more information, see the memes pacakge documention-", - "\nhttps://github.com/snystrom/memes#detecting-the-meme-suite" - ) - - if (!memes::meme_is_installed(meme_path)) { - stopper(stp_msg) - } -} diff --git a/R/format_exptype.R b/R/format_exptype.R deleted file mode 100644 index 3650c94..0000000 --- a/R/format_exptype.R +++ /dev/null @@ -1,44 +0,0 @@ -#' Format exp_type -#' -#' Format input exp_type to look pretty. -#' -#' @param exp_type A character depicting the type of experiment. -#' Supported experimental types are: -#' \itemize{ -#' \item \code{chipseq}: ChIP-seq data -#' \item \code{tipseq}: TIP-seq data -#' \item \code{cuttag}: CUT&Tag data -#' \item \code{cutrun}: CUT&Run data -#' \item \code{other}: Other experiment type data -#' \item \code{unknown}: Unknown experiment type data -#' } -#' Any item not mentioned above will be returned as-is. -#' -#' @return A character vector of formatted exp_type. -#' -#' @examples -#' format_exptype("chipseq") -#' -#' @export -format_exptype <- function(exp_type) { - if (is.na(exp_type)) { - exp_type <- "unknown" - } - - exp_type <- tolower(exp_type) - exp_types <- c( - "tipseq" = "TIP-Seq", - "chipseq" = "ChIP-Seq", - "cutrun" = "CUT&RUN", - "cuttag" = "CUT&Tag", - "other" = "Other", - "unknown" = "Unknown" - ) - - if (!exp_type %in% names(exp_types)) { - return(exp_type) - } - - exp_type <- exp_types[[exp_type]] - return(exp_type) -} diff --git a/R/get_df_enrichment.R b/R/get_df_enrichment.R index e72f8f6..5669430 100644 --- a/R/get_df_enrichment.R +++ b/R/get_df_enrichment.R @@ -58,7 +58,7 @@ #' #' @family generate data.frames #' -#' @export +#' @keywords internal get_df_enrichment <- function(result, segregated_peaks, user_motifs, diff --git a/R/messager.R b/R/messager.R deleted file mode 100644 index c55e80d..0000000 --- a/R/messager.R +++ /dev/null @@ -1,29 +0,0 @@ -#' Print messages -#' -#' Conditionally print messages. -#' Allows developers to easily control verbosity of functions, -#' and meet Bioconductor requirements that dictate the message -#' must first be stored to a variable before passing to \link[base]{message}. -#' -#' -#' @param v Whether to print messages or not. -#' @param parallel Whether to enable message print when wrapped -#' in parallelised functions. -#' -#' @return Null -#' -#' @keywords internal -messager <- function(..., - v = Sys.getenv("VERBOSE") != "FALSE", - parallel = TRUE) { - msg <- paste(...) - - message_parallel <- function(...) { - system2("echo", args = paste0(..., collpase = "")) - } - if(isTRUE(parallel)){ - if(v) try({message_parallel(msg)}) - } else { - if (v) try({message(msg)}) - } -} diff --git a/R/plot_enrichment_individual.R b/R/plot_enrichment_individual.R index b71e39d..c23b561 100644 --- a/R/plot_enrichment_individual.R +++ b/R/plot_enrichment_individual.R @@ -61,7 +61,7 @@ #' #' @family plot functions #' -#' @export +#' @keywords internal plot_enrichment_individual <- function(result, enrichment_df, comparison_i, diff --git a/R/pretty_number.R b/R/pretty_number.R deleted file mode 100644 index f50caf7..0000000 --- a/R/pretty_number.R +++ /dev/null @@ -1,27 +0,0 @@ -#' Convert numbers to more readable strings -#' -#' Format raw numbers to more readable strings. For example, 1000 will be -#' converted to "1K". Supported suffixes are "K", "M", and "B". -#' -#' @param x A number. -#' @param decimal_digits Number of decimal digits to round to. -#' -#' @return A character string of the formatted number. \code{NA} is returned as -#' "NA". -#' -#' @examples -#' print(pretty_number(134999)) -#' -#' @export -pretty_number <- function(x, decimal_digits = 2) { - if (is.na(x)) return("NA") - if (x < 1e3) { - return(as.character(round(x, decimal_digits))) - } else if (x < 1e6) { - return(paste0(round(x / 1e3, decimal_digits), "K")) - } else if (x < 1e9) { - return(paste0(round(x / 1e6, decimal_digits), "M")) - } else { - return(paste0(round(x / 1e9, decimal_digits), "B")) - } -} diff --git a/R/report_command.R b/R/report_command.R index dc0cece..78674d7 100644 --- a/R/report_command.R +++ b/R/report_command.R @@ -14,8 +14,7 @@ #' exp_labels = c("exp1", "exp2"), #' genome_build = "hg19")) #' -#' -#' @export +#' @keywords internal report_command <- function(params) { tab_spaces <- paste(rep(" ", nchar("MotifPeeker)")), collapse = "") diff --git a/R/report_header.R b/R/report_header.R index 1f79293..bcbd08d 100644 --- a/R/report_header.R +++ b/R/report_header.R @@ -9,7 +9,7 @@ #' @examples #' report_header() #' -#' @export +#' @keywords internal report_header <- function() { paste0( "