diff --git a/DESCRIPTION b/DESCRIPTION index d0dccdc..9835d07 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -89,4 +89,4 @@ Collate: 'workflow.R' VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.1.1 +RoxygenNote: 7.3.2 diff --git a/R/DsATAC-class.R b/R/DsATAC-class.R index 8f18576..3f62578 100644 --- a/R/DsATAC-class.R +++ b/R/DsATAC-class.R @@ -608,7 +608,7 @@ setMethod("regionAggregation", } # DelayedArray if (.object@diskDump){ - rsFun <- BiocGenerics::rowSums + rsFun <- DelayedArray::rowSums } #sort the regions @@ -837,7 +837,7 @@ setMethod("mergeSamples", if(countAggrFun=="sum"){ mergeFun <- function(X){rowSums(X, na.rm=TRUE)} if (.object@diskDump) { - mergeFun <- function(X){BiocGenerics::rowSums(X, na.rm=TRUE)} + mergeFun <- function(X){DelayedArray::rowSums(X, na.rm=TRUE)} } else if (.object@sparseCounts) { mergeFun <- function(X){Matrix::rowSums(X, na.rm=TRUE)} } @@ -1785,8 +1785,8 @@ setMethod("transformCounts", } # DelayedArray if (.object@diskDump){ - rsFun <- BiocGenerics::rowSums - csFun <- BiocGenerics::colSums + rsFun <- DelayedArray::rowSums + csFun <- DelayedArray::colSums } if (method == "quantile"){ diff --git a/R/DsAcc-class.R b/R/DsAcc-class.R index 1a60b7b..c9eb359 100644 --- a/R/DsAcc-class.R +++ b/R/DsAcc-class.R @@ -74,36 +74,36 @@ DsAcc <- function(siteCoord, sampleAnnot, genome, diskDump=FALSE){ ################################################################################ # Getters ################################################################################ +# Ensure that the generic function is defined if (!isGeneric("getSamples")) { - setGeneric( - "getSamples", - function(.object) standardGeneric("getSamples"), - signature=c(".object") - ) + setGeneric( + "getSamples", + function(.object) standardGeneric("getSamples"), + signature = c(".object") + ) } + #' getSamples-methods #' #' Return sample IDs in a dataset #' #' @param .object \code{\linkS4class{DsAcc}} object #' @return Character vector of sample IDs in the dataset -#' +#' @description Returns the sample IDs in the dataset #' @rdname getSamples-DsAcc-method #' @docType methods #' @aliases getSamples #' @aliases getSamples,DsAcc-method -#' @author Fabian Mueller #' @export setMethod("getSamples", - signature( - .object="DsAcc" - ), - function( - .object - ) { - return(rownames(.object@sampleAnnot)) - } + signature( + .object = "DsAcc" + ), + function(.object) { + return(rownames(.object@sampleAnnot)) + } ) + #------------------------------------------------------------------------------- #' Retrieve the number of samples contained in a DsAcc object #' diff --git a/R/utils_motifs.R b/R/utils_motifs.R index c0ab193..f7621cf 100644 --- a/R/utils_motifs.R +++ b/R/utils_motifs.R @@ -3,102 +3,114 @@ ################################################################################ ################################################################################ -# motifmatchr helpers +# motifmatchr helpers ################################################################################ #' prepareMotifmatchr #' -#' prepare objects for a \code{motifmatchr} analysis +#' Prepare objects for a \code{motifmatchr} analysis +#' #' @param genome character string specifying genome assembly -#' @param motifs either a character string (currently only "jaspar" and sets contained in \code{chromVARmotifs} ("homer", "encode", "cisbp") are supported) or an object containing PWMs -#' that can be used by \code{motifmatchr::matchMotifs} (such as an \code{PFMatrixList} or \code{PWMatrixList} object) +#' @param motifs either a character string (currently "jaspar2018", "jaspar2020", "jaspar_vert" and sets contained in \code{chromVARmotifs} ("homer", "encode", "cisbp") are supported) +#' or an object containing PWMs that can be used by \code{motifmatchr::matchMotifs} (such as a \code{PFMatrixList} or \code{PWMatrixList} object) #' @return a list containing objects to be used as arguments for \code{motifmatchr} -#' @author Fabian Mueller #' @export -prepareMotifmatchr <- function(genome, motifs){ - res <- list() - - # get the species name and the genome sequence object based on the object - genomeObj <- genome - if (!is.element("BSgenome", class(genomeObj))){ - genomeObj <- getGenomeObject(genome) - } - spec <- organism(genomeObj) - - # get the motif PWMs - motifL <- TFBSTools::PWMatrixList() - if (is.character(motifs)){ - if (is.element("jaspar", motifs)){ - # copied code from chromVAR, but updated the JASPAR version - opts <- list() - opts["species"] <- spec - opts["collection"] <- "CORE" - # gets the non-redundant set by default - mlCur <- TFBSTools::getMatrixSet(JASPAR2018::JASPAR2018, opts) - if (!isTRUE(all.equal(TFBSTools::name(mlCur), names(mlCur)))){ - names(mlCur) <- paste(names(mlCur), TFBSTools::name(mlCur), sep = "_") - } - motifL <- c(motifL, TFBSTools::toPWM(mlCur)) - } - if (is.element("jaspar_vert", motifs)){ - # JASPER for all vertebrate TFBS - opts <- list() - opts["tax_group"] <- "vertebrates" - opts["collection"] <- "CORE" - # gets the non-redundant set by default - mlCur <- TFBSTools::getMatrixSet(JASPAR2018::JASPAR2018, opts) - if (!isTRUE(all.equal(TFBSTools::name(mlCur), names(mlCur)))){ - names(mlCur) <- paste(names(mlCur), TFBSTools::name(mlCur), sep = "_") - } - motifL <- c(motifL, TFBSTools::toPWM(mlCur)) - } - if (is.element("jaspar2016", motifs)){ - motifL <- c(motifL, TFBSTools::toPWM(chromVAR::getJasparMotifs(species=spec))) - } - if (is.element("homer", motifs)){ - if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) - data("homer_pwms") - motifL <- c(motifL, chromVARmotifs::homer_pwms) - } - if (is.element("encode", motifs)){ - if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) - data("encode_pwms") - motifL <- c(motifL, chromVARmotifs::encode_pwms) - } - if (is.element("cisbp", motifs)){ - if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) - if (spec == "Mus musculus"){ - data("mouse_pwms_v1") - motifL <- c(motifL, chromVARmotifs::mouse_pwms_v1) - } else if (spec == "Homo sapiens"){ - data("human_pwms_v1") - motifL <- c(motifL, chromVARmotifs::human_pwms_v1) - } else { - logger.warning(c("Could not find cisBP annotation for species", spec)) - } - } - if (is.element("cisbp_v2", motifs)){ - if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) - if (spec == "Mus musculus"){ - data("mouse_pwms_v2") - motifL <- c(motifL, chromVARmotifs::mouse_pwms_v2) - } else if (spec == "Homo sapiens"){ - data("human_pwms_v2") - motifL <- c(motifL, chromVARmotifs::human_pwms_v2) - } else { - logger.warning(c("Could not find cisBP annotation for species", spec)) - } - } - if (length(motifL) < 1) { - logger.error(c("No motifs were loaded. Unsupported motifs (?) :", motifs)) - } - } else if (is.element("PWMatrixList", class(motifs)) || is.element("PFMatrixList", class(motifs))) { - motifL <- motifs - } else { - logger.error(c("unsupported value for motifs:", motifs)) - } - res[["genome"]] <- genomeObj - res[["motifs"]] <- motifL - return(res) +prepareMotifmatchr <- function(genome, motifs) { + res <- list() + + # get the species name and the genome sequence object based on the object + genomeObj <- genome + if (!is.element("BSgenome", class(genomeObj))) { + genomeObj <- getGenomeObject(genome) + } + spec <- provider(genomeObj) # Extract the provider (e.g., "Homo sapiens" or "Mus musculus") + + # get the motif PWMs + motifL <- TFBSTools::PWMatrixList() + if (is.character(motifs)) { + if (is.element("jaspar2020", motifs)) { + # Added block for JASPAR2020 + opts <- list() + opts["species"] <- 9606 + opts["collection"] <- "CORE" + # gets the non-redundant set by default + mlCur <- TFBSTools::getMatrixSet(JASPAR2020::JASPAR2020, opts) + if (!isTRUE(all.equal(TFBSTools::name(mlCur), names(mlCur)))) { + names(mlCur) <- paste(names(mlCur), TFBSTools::name(mlCur), sep = "_") + } + motifL <- c(motifL, TFBSTools::toPWM(mlCur)) + } + if (is.element("jaspar2018", motifs)) { + # copied code from chromVAR, but updated the JASPAR version + opts <- list() + opts["species"] <- spec + opts["collection"] <- "CORE" + # gets the non-redundant set by default + mlCur <- TFBSTools::getMatrixSet(JASPAR2018::JASPAR2018, opts) + if (!isTRUE(all.equal(TFBSTools::name(mlCur), names(mlCur)))) { + names(mlCur) <- paste(names(mlCur), TFBSTools::name(mlCur), sep = "_") + } + motifL <- c(motifL, TFBSTools::toPWM(mlCur)) + } + if (is.element("jaspar_vert", motifs)) { + # JASPAR for all vertebrate TFBS + opts <- list() + opts["tax_group"] <- "vertebrates" + opts["collection"] <- "CORE" + # gets the non-redundant set by default + mlCur <- TFBSTools::getMatrixSet(JASPAR2018::JASPAR2018, opts) + if (!isTRUE(all.equal(TFBSTools::name(mlCur), names(mlCur)))) { + names(mlCur) <- paste(names(mlCur), TFBSTools::name(mlCur), sep = "_") + } + motifL <- c(motifL, TFBSTools::toPWM(mlCur)) + } + if (is.element("jaspar2016", motifs)) { + motifL <- c(motifL, TFBSTools::toPWM(chromVAR::getJasparMotifs(species = spec))) + } + if (is.element("homer", motifs)) { + if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) + data("homer_pwms") + motifL <- c(motifL, chromVARmotifs::homer_pwms) + } + if (is.element("encode", motifs)) { + if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) + data("encode_pwms") + motifL <- c(motifL, chromVARmotifs::encode_pwms) + } + if (is.element("cisbp", motifs)) { + if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) + if (spec == "Mus musculus") { + data("mouse_pwms_v1") + motifL <- c(motifL, chromVARmotifs::mouse_pwms_v1) + } else if (spec == "Homo sapiens") { + data("human_pwms_v1") + motifL <- c(motifL, chromVARmotifs::human_pwms_v1) + } else { + logger.warning(c("Could not find cisBP annotation for species", spec)) + } + } + if (is.element("cisbp_v2", motifs)) { + if (!requireNamespace("chromVARmotifs")) logger.error(c("Could not load dependency: chromVARmotifs")) + if (spec == "Mus musculus") { + data("mouse_pwms_v2") + motifL <- c(motifL, chromVARmotifs::mouse_pwms_v2) + } else if (spec == "Homo sapiens") { + data("human_pwms_v2") + motifL <- c(motifL, chromVARmotifs::human_pwms_v2) + } else { + logger.warning(c("Could not find cisBP annotation for species", spec)) + } + } + if (length(motifL) < 1) { + logger.error(c("No motifs were loaded. Unsupported motifs (?) :", motifs)) + } + } else if (is.element("PWMatrixList", class(motifs)) || is.element("PFMatrixList", class(motifs))) { + motifL <- motifs + } else { + logger.error(c("unsupported value for motifs:", motifs)) + } + res[["genome"]] <- genomeObj + res[["motifs"]] <- motifL + return(res) } #' getMotifOccurrences diff --git a/man/ChrAccR.Rd b/man/ChrAccR.Rd index ce5bb32..ad93828 100644 --- a/man/ChrAccR.Rd +++ b/man/ChrAccR.Rd @@ -2,8 +2,13 @@ % Please edit documentation in R/ChrAccR.R \docType{package} \name{ChrAccR} +\alias{ChrAccR-package} \alias{ChrAccR} \title{ChrAccR: Analyzing chromatin accessibility data in R.} \description{ Tools for analyzing chromatin accessibility data in R. Currently supports ATAC-seq and NOMe-seq data analysis. } +\author{ +\strong{Maintainer}: Fabian Mueller \email{muellerf@stanford.edu} (\href{https://orcid.org/0000-0001-5809-2321}{ORCID}) + +} diff --git a/man/callPeaks-DsATAC-method.Rd b/man/callPeaks-DsATAC-method.Rd index 8d0aac8..1cd8cc4 100644 --- a/man/callPeaks-DsATAC-method.Rd +++ b/man/callPeaks-DsATAC-method.Rd @@ -10,8 +10,8 @@ .object, samples = getSamples(.object), method = "macs2_summit_fw_no", - methodOpts = list(macs2.exec = "macs2", macs2.params = c("--shift", "-75", - "--extsize", "150", "-p", "0.01"), fixedWidth = 250, genomeSizesFromObject = FALSE) + methodOpts = list(macs2.exec = "macs2", macs2.params = c("--shift", "-75", "--extsize", + "150", "-p", "0.01"), fixedWidth = 250, genomeSizesFromObject = FALSE) ) } \arguments{ diff --git a/man/computeDiffAcc.rnb.nome.Rd b/man/computeDiffAcc.rnb.nome.Rd index 39e8388..b342de0 100644 --- a/man/computeDiffAcc.rnb.nome.Rd +++ b/man/computeDiffAcc.rnb.nome.Rd @@ -50,7 +50,5 @@ an \code{RnBDiffMeth} object. See class description for details. computes differential accessibility for NOMe datasets using \code{RnBeads} functionality } \author{ -Fabian Mueller - Fabian Mueller } diff --git a/man/createReport_differential-DsATAC-method.Rd b/man/createReport_differential-DsATAC-method.Rd index 23dce55..083a864 100644 --- a/man/createReport_differential-DsATAC-method.Rd +++ b/man/createReport_differential-DsATAC-method.Rd @@ -6,7 +6,7 @@ \alias{createReport_differential} \title{createReport_differential-methods} \usage{ -\S4method{createReport_differential}{DsATAC}(.object, reportDir) +\S4method{createReport_differential}{DsATAC}(.object, reportDir, chromVarObj = NULL) } \arguments{ \item{.object}{\code{\linkS4class{DsATAC}} object} diff --git a/man/getSamples-DsAcc-method.Rd b/man/getSamples-DsAcc-method.Rd index 8b4bca4..018ac94 100644 --- a/man/getSamples-DsAcc-method.Rd +++ b/man/getSamples-DsAcc-method.Rd @@ -15,8 +15,8 @@ Character vector of sample IDs in the dataset } \description{ -Return sample IDs in a dataset +Returns the sample IDs in the dataset } -\author{ -Fabian Mueller +\details{ +Return sample IDs in a dataset } diff --git a/man/prepareMotifmatchr.Rd b/man/prepareMotifmatchr.Rd index 14104ef..615fa05 100644 --- a/man/prepareMotifmatchr.Rd +++ b/man/prepareMotifmatchr.Rd @@ -9,15 +9,12 @@ prepareMotifmatchr(genome, motifs) \arguments{ \item{genome}{character string specifying genome assembly} -\item{motifs}{either a character string (currently only "jaspar" and sets contained in \code{chromVARmotifs} ("homer", "encode", "cisbp") are supported) or an object containing PWMs -that can be used by \code{motifmatchr::matchMotifs} (such as an \code{PFMatrixList} or \code{PWMatrixList} object)} +\item{motifs}{either a character string (currently "jaspar2018", "jaspar2020", "jaspar_vert" and sets contained in \code{chromVARmotifs} ("homer", "encode", "cisbp") are supported) +or an object containing PWMs that can be used by \code{motifmatchr::matchMotifs} (such as a \code{PFMatrixList} or \code{PWMatrixList} object)} } \value{ a list containing objects to be used as arguments for \code{motifmatchr} } \description{ -prepare objects for a \code{motifmatchr} analysis -} -\author{ -Fabian Mueller +Prepare objects for a \code{motifmatchr} analysis }