diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index cf9fd121..6ed02ff8 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -31,10 +31,10 @@ jobs: uses: actions/checkout@v2 - name: Setup R - uses: r-lib/actions/setup-r@2fac31217e602dd30286b4c984a0ccf1afb18cbd - # uses: r-lib/actions/setup-r@master - # with: - # install-r: false + # uses: r-lib/actions/setup-r@2fac31217e602dd30286b4c984a0ccf1afb18cbd + uses: r-lib/actions/setup-r@v1 + with: + install-r: false # pandoc is already installed in the docker container # - uses: r-lib/actions/setup-pandoc@master diff --git a/DESCRIPTION b/DESCRIPTION index ad31809a..eafd4919 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: FacileData Type: Package Title: A fluent API for accessing multi-assay high-throughput genomics data -Version: 0.11.7 +Version: 0.11.8 Authors@R: c( person("Steve", "Lianoglou", , "lianoglou@dnli.com", c("aut", "cre"), comment = c(ORCID = "0000-0002-0924-1754")), diff --git a/NAMESPACE b/NAMESPACE index fa8326aa..06830d5c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,11 +3,16 @@ S3method("fds<-",data.frame) S3method("fds<-",default) S3method("fds<-",tbl) +S3method(adata,DGEList) +S3method(adata,EList) +S3method(adata,ExpressionSet) +S3method(adata,SummarizedExperiment) S3method(anti_join,facile_frame) S3method(arrange,facile_frame) S3method(as.DGEList,FacileDataSet) S3method(as.DGEList,data.frame) S3method(as.DGEList,facile_frame) +S3method(as.DGEList,matrix) S3method(as.DGEList,tbl) S3method(as.ExpressionSet,FacileDataSet) S3method(as.ExpressionSet,data.frame) @@ -28,8 +33,15 @@ S3method(covariate_definitions,FacileDataSet) S3method(default_assay,FacileDataSet) S3method(default_assay,default) S3method(distinct,facile_frame) +S3method(ds_annot,ExpressionSet) +S3method(ds_annot,SummarizedExperiment) +S3method(ds_annot,default) S3method(facet_frame,FacileDataSet) S3method(facet_frame,default) +S3method(fdata,DGEList) +S3method(fdata,EList) +S3method(fdata,ExpressionSet) +S3method(fdata,SummarizedExperiment) S3method(fds,FacileDataStore) S3method(fds,default) S3method(features,FacileDataSet) @@ -41,6 +53,7 @@ S3method(fetch_assay_score,default) S3method(fetch_custom_sample_covariates,FacileDataSet) S3method(fetch_custom_sample_covariates,default) S3method(fetch_feature_info,FacileDataSet) +S3method(fetch_feature_info,default) S3method(fetch_sample_covariates,FacileDataSet) S3method(fetch_sample_covariates,default) S3method(fetch_sample_covariates,facile_frame) @@ -67,6 +80,10 @@ S3method(name,FacileDataSet) S3method(organism,FacileDataSet) S3method(organism,default) S3method(organism,facile_frame) +S3method(pdata,DGEList) +S3method(pdata,EList) +S3method(pdata,ExpressionSet) +S3method(pdata,SummarizedExperiment) S3method(pdata_metadata,DGEList) S3method(pdata_metadata,EList) S3method(pdata_metadata,ExpressionSet) @@ -89,6 +106,7 @@ S3method(ungroup,facile_frame) S3method(with_assay_covariates,data.frame) S3method(with_assay_covariates,facile_frame) S3method(with_assay_data,data.frame) +S3method(with_assay_data,default) S3method(with_assay_data,facile_frame) S3method(with_assay_data,tbl) S3method(with_feature_info,data.frame) diff --git a/R/api.R b/R/api.R index 8a77b9da..bd7ce568 100644 --- a/R/api.R +++ b/R/api.R @@ -404,6 +404,8 @@ fetch_feature_info <- function(x, feature_type, feature_ids = NULL, ...) { UseMethod("fetch_feature_info", x) } +#' @noRd +#' @export fetch_feature_info.default <- function(x, feature_type, feature_ids = NULL, ...) { stop("Implement fetch_feature_info for class: ", class(x)[1L]) } @@ -581,6 +583,8 @@ with_assay_data <- function(x, features, assay_name = NULL, UseMethod("with_assay_data", x) } +#' @noRd +#' @export with_assay_data.default <- function(x, features, assay_name = NULL, normalized = TRUE, aggregate = FALSE, aggregate.by = "ewm", diff --git a/R/as.BiocAssayContainers.R b/R/as.BiocAssayContainers.R index e7c906be..8bd98349 100644 --- a/R/as.BiocAssayContainers.R +++ b/R/as.BiocAssayContainers.R @@ -61,6 +61,7 @@ as.DGEList <- function(x, ...) { } #' @noRd +#' @export #' @method as.DGEList matrix #' @rdname as.BiocContainer #' @importFrom edgeR DGEList calcNormFactors @@ -164,8 +165,9 @@ as.DGEList.matrix <- function(x, covariates = TRUE, feature_ids = NULL, is.neg <- which(x < 0, arr.ind = TRUE) if (nrow(is.neg)) x[is.neg] <- x[is.neg] * -1 - y <- DGEList(x, genes = genes, lib.size = sample.stats[["libsize"]], - norm.factors = sample.stats[["normfactor"]]) + y <- DGEList(x, genes = genes, lib.size = sample.stats[["libsize"]]) + # This avoids the warning when norm factors don't multiply to 1 + y$samples$norm.factors <- sample.stats[["normfactor"]] y$samples <- cbind( y$samples, diff --git a/R/as.FacileDataSet.R b/R/as.FacileDataSet.R index 71d3c566..1bfd6d5d 100644 --- a/R/as.FacileDataSet.R +++ b/R/as.FacileDataSet.R @@ -302,6 +302,9 @@ as.FacileDataSet.list <- function(x, path, assay_name, assay_type, #' no such slot, unfortunately, and thus gets the default. SE has a #' metadata slot and can provide url and description. eSet just has #' a character annotation and can provide a description. +#' +#' This is an internal helper function. +#' #' @param x SummarizedExperiment, ExpressionSet or DGEList #' @param validate single logical, check results #' @param meta a list of description stuff for the dataset, this can act to @@ -311,6 +314,8 @@ ds_annot <- function(x, meta = NULL, validate = FALSE, ...) { UseMethod("ds_annot") } +#' @noRd +#' @export ds_annot.SummarizedExperiment <- function(x, meta = NULL, validate = FALSE, ...) { ns4 <- tryCatch(loadNamespace("S4Vectors"), error = function(e) NULL) @@ -321,12 +326,16 @@ ds_annot.SummarizedExperiment <- function(x, meta = NULL, validate = FALSE, out } +#' @noRd +#' @export ds_annot.ExpressionSet <- function(x, meta = NULL, validate = FALSE, ...) { out <- .merge_ds_annot(NULL, meta) if (validate) .ds_annot_validate(out) out } +#' @noRd +#' @export ds_annot.default <- function(x, meta = NULL, validate = FALSE, ...) { out <- .merge_ds_annot(NULL, meta) if (validate) .ds_annot_validate(out) @@ -359,23 +368,27 @@ ds_annot.default <- function(x, meta = NULL, validate = FALSE, ...) { #' BioC-container specific fData extraction functions #' -#' not for export #' @param x SummarizedExperiment, ExpressionSet or DGEList #' @param validate single logical, check results #' @param ... additional args (ignored for now) fdata <- function(x, validate = FALSE, ...) { UseMethod("fdata") } + +#' @noRd +#' @export fdata.SummarizedExperiment <- function(x, validate = FALSE, ...) { ns <- tryCatch(loadNamespace("SummarizedExperiment"), error = function(e) NULL) if (is.null(ns)) stop("SummarizedExperiment required") ns4 <- tryCatch(loadNamespace("S4Vectors"), error = function(e) NULL) if (is.null(ns4)) stop("S4Vectors required") - # out <- ns$as.data.frame(ns$mcols(x)) - out <- ns4$as.data.frame.DataTable(ns$rowData(x)) + out <- ns4$.as.data.frame.DataFrame(ns$rowData(x)) if (validate) validate.fdata(out, ...) else out } + +#' @noRd +#' @export fdata.ExpressionSet <- function(x, validate = FALSE, ...) { ns <- tryCatch(loadNamespace("Biobase"), error = function(e) NULL) if (is.null(ns)) stop("Biobase required") @@ -383,11 +396,17 @@ fdata.ExpressionSet <- function(x, validate = FALSE, ...) { out <- ns$fData(x) if (validate) validate.fdata(out, ...) else out } + +#' @noRd +#' @export fdata.DGEList <- function(x, validate = FALSE, ...) { # stopifnot(requireNamespace("edgeR", quietly = TRUE)) out <- x$genes if (validate) validate.fdata(out, ...) else out } + +#' @noRd +#' @export fdata.EList <- function(x, validate = FALSE, ...) { out <- x$genes if (validate) validate.fdata(out, ...) else out @@ -425,14 +444,16 @@ validate.fdata <- function(x, ...) { #' Bioc-container specific pData extraction functions #' -#' not for export +#' This is an internal function, but exported so it is registered and found +#' post R 4.0 #' @param x SummarizedExperiment, ExpressionSet or DGEList #' @param ... additional args, ignored for now pdata <- function(x, covariate_metadata = NULL, ...) { - UseMethod("pdata") + UseMethod("pdata", x) } #' @noRd +#' @export pdata.SummarizedExperiment <- function(x, covariate_metadata = NULL, ...) { ns <- tryCatch(loadNamespace("SummarizedExperiment"), error = function(e) NULL) if (is.null(ns)) stop("SummarizedExperiment required") @@ -440,11 +461,12 @@ pdata.SummarizedExperiment <- function(x, covariate_metadata = NULL, ...) { if (is.null(ns4)) stop("S4Vectors required") df <- ns$colData(x) - ds <- ns4$as.data.frame.DataTable(df) + ds <- ns4$.as.data.frame.DataFrame(df) validate.pdata(ds, ...) } #' @noRd +#' @export pdata.ExpressionSet <- function(x, covariate_metadata = NULL, ...) { ns <- tryCatch(loadNamespace("Biobase"), error = function(e) NULL) if (is.null(ns)) stop("Biobase required") @@ -452,6 +474,7 @@ pdata.ExpressionSet <- function(x, covariate_metadata = NULL, ...) { } #' @noRd +#' @export pdata.DGEList <- function(x, covariate_metadata = NULL, ...) { # stopifnot(requireNamespace("edgeR", quietly = TRUE)) ignore.cols <- c("lib.size", "norm.factors") @@ -463,10 +486,12 @@ pdata.DGEList <- function(x, covariate_metadata = NULL, ...) { } #' @noRd +#' @export pdata.EList <- function(x, covariate_metadata = NULL, ...) { validate.pdata(x$targets, ...) } +#' @noRd validate.pdata <- function(x, ...) { x } @@ -530,13 +555,15 @@ pdata_metadata.EList <- function(x, ...) { #' Bioc-container specific assay data extraction functions #' #' Get assay matrix +#' #' @param x SummarizedExperiment, ExpressionSet or DGEList #' @param ... additional args, ignored for now adata <- function(x, assay = NULL, ...) { - UseMethod("adata") + UseMethod("adata", x) } #' @noRd +#' @export adata.SummarizedExperiment <- function(x, assay = NULL, ...) { ns <- tryCatch(loadNamespace("SummarizedExperiment"), error = function(e) NULL) if (is.null(ns)) stop("SummarizedExperiment required") @@ -549,6 +576,7 @@ adata.SummarizedExperiment <- function(x, assay = NULL, ...) { } #' @noRd +#' @export adata.ExpressionSet <- function(x, assay = NULL, ...) { ns <- tryCatch(loadNamespace("Biobase"), error = function(e) NULL) if (is.null(ns)) stop("Biobase required") @@ -561,6 +589,7 @@ adata.ExpressionSet <- function(x, assay = NULL, ...) { } #' @noRd +#' @export adata.DGEList <- function(x, assay = NULL, ...) { # stopifnot(requireNamespace("edgeR", quietly = TRUE)) # DGEList only has one assay @@ -568,6 +597,7 @@ adata.DGEList <- function(x, assay = NULL, ...) { } #' @noRd +#' @export adata.EList <- function(x, assay = NULL, ...) { # EList only has one assay x[["E"]] diff --git a/R/assay-data.R b/R/assay-data.R index 331237fb..048983fc 100644 --- a/R/assay-data.R +++ b/R/assay-data.R @@ -115,7 +115,7 @@ fetch_assay_data.FacileDataSet <- function(x, features, samples = NULL, #' @export #' @noRd -fetch_assay_data.facile_frame <- function(x, features, samples = NULL, +fetch_assay_data.facile_frame <- function(x, features = NULL, samples = NULL, assay_name = NULL, normalized = FALSE, batch = NULL, main = NULL, diff --git a/R/biocbox.R b/R/biocbox.R index 22eaa52d..faa7c25e 100644 --- a/R/biocbox.R +++ b/R/biocbox.R @@ -22,7 +22,7 @@ biocbox.FacileDataStore <- function(x, class = NULL, assay_name = NULL, #' DGEList lib.size calculated from the data that made its way into the DGEList) #' #' @export -#' +#' @rdname biocbox #' @param sample_covariates If `NULL` (default), all sample covariates will #' be included over samples in x. If a data.frame, we will treat the #' extra columns as custom covariates, and include them in the outgoing diff --git a/man/FacileData-package.Rd b/man/FacileData-package.Rd index 14ed509c..3bdeaa51 100644 --- a/man/FacileData-package.Rd +++ b/man/FacileData-package.Rd @@ -28,7 +28,7 @@ Useful links: Authors: \itemize{ \item Vincent Rouilly \email{rouilly.vincent@gene.com} - \item Peter Haverty \email{haverty.peter@gene.com} + \item Peter Haverty (@phaverty on github) } Other contributors: diff --git a/man/biocbox.Rd b/man/biocbox.Rd index 5c10079f..e1db2f2b 100644 --- a/man/biocbox.Rd +++ b/man/biocbox.Rd @@ -1,13 +1,32 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/api.R +% Please edit documentation in R/api.R, R/biocbox.R \name{biocbox} \alias{biocbox} +\alias{biocbox.facile_frame} \title{Materialize a Bioconductor assay container from some facile object.} \usage{ biocbox(x, ...) + +\method{biocbox}{facile_frame}( + x, + class = NULL, + assay_name = NULL, + features = NULL, + sample_covariates = NULL, + feature_covariates = NULL, + normalized = FALSE, + with_fds = FALSE, + custom_key = Sys.getenv("USER"), + ... +) } \arguments{ \item{x}{A facile object} + +\item{sample_covariates}{If \code{NULL} (default), all sample covariates will +be included over samples in x. If a data.frame, we will treat the +extra columns as custom covariates, and include them in the outgoing +box, along with the internal ones.} } \description{ Most often, this will be from some facile_frame to create a Bioconductor @@ -19,3 +38,15 @@ The FacileAnalysis package, for example, uses this function to materialize bioconductor objects of different flavors from different analysis results, ie. a DGEList, or perhaps a limma fit object, etc. } +\section{facile_frame}{ + +We can materialize a Bioconductor data container for a given assay over a set +of samples. + +There is a default bioc class provided for different assay types, however +the class type can be overrided by the \code{class} parameter. This function +simply puts the assay data requested into the container. There is no +sepcial functionality that happens downstream of that (for instance, +DGEList lib.size calculated from the data that made its way into the DGEList) +} + diff --git a/man/ds_annot.Rd b/man/ds_annot.Rd index 65bdad8d..ebdf1e6f 100644 --- a/man/ds_annot.Rd +++ b/man/ds_annot.Rd @@ -22,3 +22,6 @@ no such slot, unfortunately, and thus gets the default. SE has a metadata slot and can provide url and description. eSet just has a character annotation and can provide a description. } +\details{ +This is an internal helper function. +} diff --git a/man/fdata.Rd b/man/fdata.Rd index a1843c6f..0b744f8e 100644 --- a/man/fdata.Rd +++ b/man/fdata.Rd @@ -14,5 +14,5 @@ fdata(x, validate = FALSE, ...) \item{...}{additional args (ignored for now)} } \description{ -not for export +BioC-container specific fData extraction functions } diff --git a/man/pdata.Rd b/man/pdata.Rd index 2fd1793e..474fcb90 100644 --- a/man/pdata.Rd +++ b/man/pdata.Rd @@ -12,5 +12,6 @@ pdata(x, covariate_metadata = NULL, ...) \item{...}{additional args, ignored for now} } \description{ -not for export +This is an internal function, but exported so it is registered and found +post R 4.0 }