diff --git a/DESCRIPTION b/DESCRIPTION index 5ec4c05..a1c238c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ Authors@R: person( comment = c(ORCID = "0000-0003-2641-0916")) License: Artistic-2.0 Encoding: UTF-8 -Version: 0.99.2 +Version: 0.99.4 Depends: R (>= 4.3.0) Imports: AnnotationHub, GenomicRanges, utils Suggests: knitr, rmarkdown, testthat (>= 3.0.0), BiocStyle diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..5408960 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +# methylTFRAnnotationsMm10 0.99.4 + +- Fix some notes found in bioccheck \ No newline at end of file diff --git a/R/aaa-utils.R b/R/aaa-utils.R index cd3aeb9..8e6fd34 100644 --- a/R/aaa-utils.R +++ b/R/aaa-utils.R @@ -1,16 +1,18 @@ #' @noRd -.local_dir <- function() { ... } +.local_dir <- function() { + ... +} .PKG_NAME <- "methylTFRAnnotationMm10" .MOTIF_SETS <- c("altius", "cisbpv2", "jaspar2020") .ASSEMBLY <- "Mm10" #' @keywords internal .local_dir <- function() { - d <- getOption( - "methylTFRAnnotationMm10.datadir", - Sys.getenv("METHYL_TFRANNOTATION_Mm10_DIR", "") - ) - if (nzchar(d)) d else NULL + d <- getOption( + "methylTFRAnnotationMm10.datadir", + Sys.getenv("METHYL_TFRANNOTATION_Mm10_DIR", "") + ) + if (nzchar(d)) d else NULL } #' @keywords internal @@ -22,37 +24,39 @@ #' on the hub, and so users who have downloaded the files by hand #' can point at them. .resolve_resource <- function(file) { - dir <- .local_dir() - if (!is.null(dir)) { - path <- file.path(dir, file) - if (!file.exists(path)) { - stop( - "Annotation file not found: ", path, - "\n(reading from a local directory because ", - .PKG_NAME, ".datadir is set)" - ) - } - return(readRDS(path)) - } - hub <- AnnotationHub::AnnotationHub() - hits <- AnnotationHub::query(hub, .PKG_NAME) - idx <- match(file, hits$title) - if (is.na(idx)) { - stop( - "Resource not found on AnnotationHub: ", file, - "\nAvailable: ", paste(hits$title, collapse = ", ") - ) + dir <- .local_dir() + if (!is.null(dir)) { + path <- file.path(dir, file) + if (!file.exists(path)) { + stop( + "Annotation file not found: ", path, + "\n(reading from a local directory because ", + .PKG_NAME, ".datadir is set)" + ) } - hits[[names(hits)[idx]]] + return(readRDS(path)) + } + hub <- AnnotationHub::AnnotationHub() + hits <- AnnotationHub::query(hub, .PKG_NAME) + idx <- match(file, hits$title) + if (is.na(idx)) { + stop( + "Resource not found on AnnotationHub: ", file, + "\nAvailable: ", paste(hits$title, collapse = ", ") + ) + } + hits[[names(hits)[idx]]] } #' @keywords internal #' @noRd .check_motif_set <- function(motifSet) { - motifSet <- tolower(motifSet) - if (length(motifSet) != 1 || !motifSet %in% .MOTIF_SETS) { - stop("Invalid motif set. Available: ", - paste(.MOTIF_SETS, collapse = ", ")) - } - motifSet + motifSet <- tolower(motifSet) + if (length(motifSet) != 1 || !motifSet %in% .MOTIF_SETS) { + stop( + "Invalid motif set. Available: ", + paste(.MOTIF_SETS, collapse = ", ") + ) + } + motifSet } diff --git a/R/getGCfreq.R b/R/getGCfreq.R index 05a2c9e..b08dd43 100644 --- a/R/getGCfreq.R +++ b/R/getGCfreq.R @@ -1,32 +1,34 @@ #' @title getGCfreq -#' @description Load the motif GC frequency table for a motif set. Downloaded from AnnotationHub on first use and cached locally thereafter. -#' @param motifSet Motif set to load. One of: altius, cisbpv2, jaspar2020, jaspar2020_distal. +#' @description Load the motif GC frequency table for a motif set. +#' Downloaded from AnnotationHub on first use and cached locally thereafter. +#' @param motifSet Motif set to load. One of: altius, cisbpv2, jaspar2020, +#' jaspar2020_distal. #' @return A named \code{list} of five-row matrices, one per motif. #' @import GenomicRanges #' @importFrom utils packageVersion #' @examples -#' # 1. Create a dummy object and save it to a temporary directory +#' # 1. Create a dummy object and save it to a temporary directory #' # to bypass AnnotationHub during package checks. #' mock_dir <- tempdir() #' mock_file <- file.path(mock_dir, "altius_motif_gcfreq.rds") -#' +#' #' # (Mocking a 5-row matrix as expected by the function output) #' mock_data <- list(mock_motif_1 = matrix(0.25, nrow = 5, ncol = 4)) #' saveRDS(mock_data, mock_file) -#' +#' #' # 2. Temporarily point the package's local directory to tempdir() #' old_opt <- getOption("methylTFRAnnotationMm10.datadir") #' options(methylTFRAnnotationMm10.datadir = mock_dir) -#' +#' #' # 3. Run the function (it will now read the mock file) #' x <- getGCfreq(motifSet = "altius") -#' +#' #' # 4. Restore options and clean up the temporary file #' options(methylTFRAnnotationMm10.datadir = old_opt) #' file.remove(mock_file) -#' +#' #' @export getGCfreq <- function(motifSet = "altius") { - motifSet <- .check_motif_set(motifSet) - .resolve_resource(paste0(motifSet, "_motif_gcfreq.rds")) + motifSet <- .check_motif_set(motifSet) + .resolve_resource(paste0(motifSet, "_motif_gcfreq.rds")) } diff --git a/R/getGenomeGC.R b/R/getGenomeGC.R index 3e75b6b..0e5f9bb 100644 --- a/R/getGenomeGC.R +++ b/R/getGenomeGC.R @@ -11,26 +11,26 @@ #' # 1. Create a dummy object and save it to a temporary directory #' mock_dir <- tempdir() #' mock_file <- file.path(mock_dir, "genomewide_GC_mm10.rds") -#' +#' #' # Mocking a GRanges object with the expected metadata columns #' mock_gr <- GenomicRanges::GRanges("chr1:1-100") #' mock_gr$GC_bias <- 0.5 #' mock_gr$GC_bin <- 1L #' saveRDS(mock_gr, mock_file) -#' +#' #' # 2. Temporarily point the package to tempdir #' old_opt <- getOption("methylTFRAnnotationMm10.datadir") #' options(methylTFRAnnotationMm10.datadir = mock_dir) -#' +#' #' # 3. Run the function #' gc <- getGenomeGC() -#' +#' #' # 4. Restore options and clean up #' options(methylTFRAnnotationMm10.datadir = old_opt) #' file.remove(mock_file) -#' +#' #' @export getGenomeGC <- function(assembly = .ASSEMBLY) { - assembly <- tolower(assembly) - .resolve_resource(paste0("genomewide_GC_", assembly, ".rds")) -} \ No newline at end of file + assembly <- tolower(assembly) + .resolve_resource(paste0("genomewide_GC_", assembly, ".rds")) +} diff --git a/R/getTFbindsites.R b/R/getTFbindsites.R index 9cbe93e..9c809cf 100644 --- a/R/getTFbindsites.R +++ b/R/getTFbindsites.R @@ -1,6 +1,8 @@ #' @title getTFbindsites -#' @description Retrieve transcription factor binding sites for a motif set. Downloaded from AnnotationHub on first use and cached locally thereafter. -#' @param motifSet Motif set to load. One of: altius, cisbpv2, jaspar2020, jaspar2020_distal. +#' @description Retrieve transcription factor binding sites for a motif set. +#' Downloaded from AnnotationHub on first use and cached locally thereafter. +#' @param motifSet Motif set to load. One of: altius, cisbpv2, jaspar2020, +#' jaspar2020_distal. #' @return A \code{GRangesList}, one element per motif. #' @import GenomicRanges #' @importFrom utils packageVersion @@ -8,26 +10,26 @@ #' # 1. Create a dummy object and save it to a temp directory #' mock_dir <- tempdir() #' mock_file <- file.path(mock_dir, "altius_tf_bindsites.rds") -#' +#' #' # Mocking a GRangesList as expected by the function output #' mock_grl <- GenomicRanges::GRangesList( -#' mock_motif_1 = GenomicRanges::GRanges("chr1:100-200") +#' mock_motif_1 = GenomicRanges::GRanges("chr1:100-200") #' ) #' saveRDS(mock_grl, mock_file) -#' +#' #' # 2. Point the local directory option to the temp directory #' old_opt <- getOption("methylTFRAnnotationMm10.datadir") #' options(methylTFRAnnotationMm10.datadir = mock_dir) -#' +#' #' # 3. Run the function #' x <- getTFbindsites() -#' +#' #' # 4. Restore options and clean up #' options(methylTFRAnnotationMm10.datadir = old_opt) #' file.remove(mock_file) -#' +#' #' @export getTFbindsites <- function(motifSet = "altius") { - motifSet <- .check_motif_set(motifSet) - .resolve_resource(paste0(motifSet, "_tf_bindsites.rds")) + motifSet <- .check_motif_set(motifSet) + .resolve_resource(paste0(motifSet, "_tf_bindsites.rds")) } diff --git a/man/getGCfreq.Rd b/man/getGCfreq.Rd index 0660ac7..d91b5ae 100644 --- a/man/getGCfreq.Rd +++ b/man/getGCfreq.Rd @@ -7,16 +7,18 @@ getGCfreq(motifSet = "altius") } \arguments{ -\item{motifSet}{Motif set to load. One of: altius, cisbpv2, jaspar2020, jaspar2020_distal.} +\item{motifSet}{Motif set to load. One of: altius, cisbpv2, jaspar2020, +jaspar2020_distal.} } \value{ A named \code{list} of five-row matrices, one per motif. } \description{ -Load the motif GC frequency table for a motif set. Downloaded from AnnotationHub on first use and cached locally thereafter. +Load the motif GC frequency table for a motif set. +Downloaded from AnnotationHub on first use and cached locally thereafter. } \examples{ -# 1. Create a dummy object and save it to a temporary directory +# 1. Create a dummy object and save it to a temporary directory # to bypass AnnotationHub during package checks. mock_dir <- tempdir() mock_file <- file.path(mock_dir, "altius_motif_gcfreq.rds") diff --git a/man/getTFbindsites.Rd b/man/getTFbindsites.Rd index 34b33a2..1bd4b28 100644 --- a/man/getTFbindsites.Rd +++ b/man/getTFbindsites.Rd @@ -7,13 +7,15 @@ getTFbindsites(motifSet = "altius") } \arguments{ -\item{motifSet}{Motif set to load. One of: altius, cisbpv2, jaspar2020, jaspar2020_distal.} +\item{motifSet}{Motif set to load. One of: altius, cisbpv2, jaspar2020, +jaspar2020_distal.} } \value{ A \code{GRangesList}, one element per motif. } \description{ -Retrieve transcription factor binding sites for a motif set. Downloaded from AnnotationHub on first use and cached locally thereafter. +Retrieve transcription factor binding sites for a motif set. +Downloaded from AnnotationHub on first use and cached locally thereafter. } \examples{ # 1. Create a dummy object and save it to a temp directory @@ -22,7 +24,7 @@ mock_file <- file.path(mock_dir, "altius_tf_bindsites.rds") # Mocking a GRangesList as expected by the function output mock_grl <- GenomicRanges::GRangesList( - mock_motif_1 = GenomicRanges::GRanges("chr1:100-200") + mock_motif_1 = GenomicRanges::GRanges("chr1:100-200") ) saveRDS(mock_grl, mock_file) diff --git a/tests/testthat/test-accessors.R b/tests/testthat/test-accessors.R index 2922ae9..e9fb3ce 100644 --- a/tests/testthat/test-accessors.R +++ b/tests/testthat/test-accessors.R @@ -1,16 +1,17 @@ test_that("motif set validation rejects unknown sets", { - expect_error(getGCfreq("not_a_motif_set"), "Invalid motif set") - expect_error(getGCfreq(c("a", "b")), "Invalid motif set") + expect_error(getGCfreq("not_a_motif_set"), "Invalid motif set") + expect_error(getGCfreq(c("a", "b")), "Invalid motif set") }) test_that("motif set validation is case insensitive", { - expect_identical(methylTFRAnnotationMm10:::.check_motif_set("ALTIUS"), "altius") + expect_identical(methylTFRAnnotationMm10:::.check_motif_set("ALTIUS"), "altius") }) test_that("metadata.csv covers every declared motif set", { - md <- utils::read.csv(system.file("extdata", "metadata.csv", package = "methylTFRAnnotationMm10")) - for (s in methylTFRAnnotationMm10:::.MOTIF_SETS) { - expect_true(any(grepl(paste0("^", s, "_"), md$Title)), - info = s) - } + md <- utils::read.csv(system.file("extdata", "metadata.csv", package = "methylTFRAnnotationMm10")) + for (s in methylTFRAnnotationMm10:::.MOTIF_SETS) { + expect_true(any(grepl(paste0("^", s, "_"), md$Title)), + info = s + ) + } }) diff --git a/vignettes/methylTFRAnnotationMm10.Rmd b/vignettes/methylTFRAnnotationMm10.Rmd index bdace61..0c5e8a2 100644 --- a/vignettes/methylTFRAnnotationMm10.Rmd +++ b/vignettes/methylTFRAnnotationMm10.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r, include = FALSE} +```{r setup, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ``` @@ -17,11 +17,11 @@ knitr::opts_chunk$set(collapse = TRUE, comment = "#>") compute bias-corrected transcription factor deviation scores on Mm10: - **binding sites**, one `GRanges` per motif, each range extended - so that methylation can be read across the footprint window; + so that methylation can be read across the footprint window; - **motif GC frequency tables**, recording how each motif's binding - sites distribute across genome-wide GC quintiles; + sites distribute across genome-wide GC quintiles; - **the genome-wide GC distribution**, which assigns each - methylation call to a GC bin. + methylation call to a GC bin. The GC tables are what make the deviation score bias-corrected. A motif whose binding sites sit in GC-rich sequence will overlap CpG @@ -30,8 +30,8 @@ hypomethylated; without the correction that difference in sequence composition would read as a difference in factor activity. The data are too large to ship inside the package, so they are -hosted on AnnotationHub and downloaded on first use. Subsequent -calls are served from the local AnnotationHub cache. +hosted on `AnnotationHub` and downloaded on first use. Subsequent +calls are served from the local `AnnotationHub` cache. ```{r dummy, include = FALSE} @@ -40,7 +40,7 @@ mock_dir <- tempdir() # 1. Mock TF bindsites mock_grl <- GenomicRanges::GRangesList( - mock_motif_1 = GenomicRanges::GRanges("chr1:100-200") + mock_motif_1 = GenomicRanges::GRanges("chr1:100-200") ) saveRDS(mock_grl, file.path(mock_dir, "altius_tf_bindsites.rds")) @@ -61,25 +61,25 @@ options(methylTFRAnnotationMm10.datadir = mock_dir) # Usage -```{r, eval = FALSE} +```{r usage, eval = FALSE} library(methylTFRAnnotationMm10) tf_bindsites <- getTFbindsites("altius") -gcfreqs <- getGCfreq("altius") -gc_dist <- getGenomeGC() +gcfreqs <- getGCfreq("altius") +gc_dist <- getGenomeGC() ``` These are passed straight to `methylTFR::run_methyltfr()`. # Available motif sets -```{r, eval = FALSE} +```{r available_motifs, eval = FALSE} methylTFRAnnotationMm10:::.MOTIF_SETS ``` # Session info -```{r} +```{r session_info} sessionInfo() ``` @@ -87,4 +87,4 @@ sessionInfo() ```{r cleanup, include = FALSE} # HIDDEN CHUNK: Clean up the options options(methylTFRAnnotationMm10.datadir = old_opt) -``` \ No newline at end of file +```