From 1e0b96fd4b8970ace3085651dc5155826c51d232 Mon Sep 17 00:00:00 2001 From: thpralas Date: Wed, 21 Feb 2024 15:36:23 +0200 Subject: [PATCH] Deprecate functions taxonomyTree and addTaxonomyTree --- DESCRIPTION | 4 ++-- NAMESPACE | 2 ++ NEWS | 1 + R/deprecate.R | 40 +++++++++++++++++++++++++++++++++ R/splitOn.R | 6 ++--- R/taxonomy.R | 26 ++++++++++++--------- man/deprecate.Rd | 28 +++++++++++++++++++++++ man/taxonomy-methods.Rd | 22 +++++++++--------- man/transformAssay.Rd | 7 +++--- tests/testthat/test-2taxonomy.R | 4 ++-- 10 files changed, 108 insertions(+), 32 deletions(-) create mode 100644 R/deprecate.R create mode 100644 man/deprecate.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 529c850ca..089d7bfa7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mia Type: Package -Version: 1.11.3 +Version: 1.11.4 Authors@R: c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"), email = "felix.gm.ernst@outlook.com", @@ -84,5 +84,5 @@ Suggests: URL: https://github.com/microbiome/mia BugReports: https://github.com/microbiome/mia/issues Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 6e305f41f..f6798088d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -103,6 +103,7 @@ exportMethods(addNotContaminantQC) exportMethods(addPerSampleDominantFeatures) exportMethods(addPerSampleDominantTaxa) exportMethods(addTaxonomyTree) +exportMethods(addTree) exportMethods(agglomerateByPrevalence) exportMethods(agglomerateByRank) exportMethods(bestDMNFit) @@ -130,6 +131,7 @@ exportMethods(getBestDMNFit) exportMethods(getDMN) exportMethods(getExperimentCrossAssociation) exportMethods(getExperimentCrossCorrelation) +exportMethods(getHierarchyTree) exportMethods(getPrevalence) exportMethods(getPrevalentAbundance) exportMethods(getPrevalentFeatures) diff --git a/NEWS b/NEWS index baa204b6c..4e706b785 100644 --- a/NEWS +++ b/NEWS @@ -97,3 +97,4 @@ Changes in version 1.9.x Changes in version 1.11.x + loadFromMetaphlan: support strain rank + agglomerateByRank: agglomerate tree fix ++ Deprecate taxonomyTree, addTaxonomyTree diff --git a/R/deprecate.R b/R/deprecate.R new file mode 100644 index 000000000..4e112804e --- /dev/null +++ b/R/deprecate.R @@ -0,0 +1,40 @@ +#' These functions will be deprecated. Please use other functions instead. +#' +#' @param x a \code{\link{SummarizedExperiment}} object - +#' +#' @param ... - +#' +#' @name deprecate +NULL + +#' @rdname deprecate +setGeneric("addTaxonomyTree", + signature = "x", + function(x, ...) + standardGeneric("addTaxonomyTree")) + +#' @rdname deprecate +#' @export +setMethod("addTaxonomyTree", signature = c(x = "SummarizedExperiment"), + function(x){ + .Deprecated(msg = paste0("'addTaxonomyTree' is deprecated.\n", + "Use 'addTree' instead.")) + addTree(x) + } +) + +#' @rdname deprecate +setGeneric("taxonomyTree", + signature = "x", + function(x, ...) + standardGeneric("taxonomyTree")) + +#' @rdname deprecate +#' @export +setMethod("taxonomyTree", signature = c(x = "SummarizedExperiment"), + function(x){ + .Deprecated(msg = paste0("'taxonomyTree' is deprecated.\n", + "Use 'getHierarchyTree' instead.")) + getHierarchyTree(x) + } +) diff --git a/R/splitOn.R b/R/splitOn.R index 516203f59..e2d069125 100644 --- a/R/splitOn.R +++ b/R/splitOn.R @@ -290,10 +290,10 @@ setMethod("splitOn", signature = c(x = "TreeSummarizedExperiment"), if( update_rowTree ){ # If the returned value is a list, go through all of them if( class(x) == "SimpleList" ){ - x <- SimpleList(lapply(x, addTaxonomyTree)) + x <- SimpleList(lapply(x, addTree)) } else { # Otherwise, the returned value is TreeSE - x <- addTaxonomyTree(x) + x <- addTree(x) } } x @@ -386,7 +386,7 @@ setGeneric("unsplitOn", if( class_x == "TreeSummarizedExperiment" ){ # Update or add old tree from the first element of list if( update_rowTree ){ - ans <- addTaxonomyTree(ans) + ans <- addTree(ans) } else{ rowTree(ans) <- rowTree(ses[[1L]]) } diff --git a/R/taxonomy.R b/R/taxonomy.R index 05e8debea..7852f3b45 100644 --- a/R/taxonomy.R +++ b/R/taxonomy.R @@ -18,12 +18,16 @@ #' the lowest taxonomic information possible. If data from different levels, #' is to be mixed, the taxonomic level is prepended by default. #' -#' \code{taxonomyTree} generates a \code{phylo} tree object from the available +#' \code{getHierarchyTree} generates a hierarchy tree from the available #' taxonomic information. Internally it uses #' \code{\link[TreeSummarizedExperiment:toTree]{toTree}} and #' \code{\link[TreeSummarizedExperiment:resolveLoop]{resolveLoop}} to sanitize #' data if needed. #' +#' \code{addTree} calculates hierarchy tree from the available taxonomic +#' information and add it to rowTree. +#' +#' #' \code{IdTaxaToDataFrame} extracts taxonomic results from results of #' \code{\link[DECIPHER:IdTaxa]{IdTaxa}}. #' @@ -40,11 +44,11 @@ #' object #' #' @param rank a single character defining a taxonomic rank. Must be a value of -#' \code{taxonomyRanks()} function. +#' \code{taxonomyRanks()} function #' #' @param empty.fields a \code{character} value defining, which values should be #' regarded as empty. (Default: \code{c(NA, "", " ", "\t")}). They will be -#' removed if \code{na.rm = TRUE} before agglomeration. +#' removed if \code{na.rm = TRUE} before agglomeration #' #' @param with_rank \code{TRUE} or \code{FALSE}: Should the level be add as a #' suffix? For example: "Phylum:Crenarchaeota" (default: @@ -126,7 +130,7 @@ #' # adding a rowTree() based on the available taxonomic information. Please #' # note that any tree already stored in rowTree() will be overwritten. #' x <- GlobalPatterns -#' x <- addTaxonomyTree(x) +#' x <- addTree(x) #' x NULL @@ -380,14 +384,14 @@ setMethod("getTaxonomyLabels", signature = c(x = "SummarizedExperiment"), } #' @rdname taxonomy-methods -setGeneric("taxonomyTree", +setGeneric("getHierarchyTree", signature = "x", function(x, ...) - standardGeneric("taxonomyTree")) + standardGeneric("getHierarchyTree")) #' @rdname taxonomy-methods #' @export -setMethod("taxonomyTree", signature = c(x = "SummarizedExperiment"), +setMethod("getHierarchyTree", signature = c(x = "SummarizedExperiment"), function(x){ # Input check # If there is no rowData it is not possible to create rowTree @@ -422,17 +426,17 @@ setMethod("taxonomyTree", signature = c(x = "SummarizedExperiment"), ) #' @rdname taxonomy-methods -setGeneric("addTaxonomyTree", +setGeneric("addTree", signature = "x", function(x, ...) - standardGeneric("addTaxonomyTree")) + standardGeneric("addTree")) #' @rdname taxonomy-methods #' @export -setMethod("addTaxonomyTree", signature = c(x = "SummarizedExperiment"), +setMethod("addTree", signature = c(x = "SummarizedExperiment"), function(x){ # - tree <- taxonomyTree(x) + tree <- getHierarchyTree(x) x <- as(x,"TreeSummarizedExperiment") rownames(x) <- getTaxonomyLabels(x, with_rank = TRUE, resolve_loops = TRUE, diff --git a/man/deprecate.Rd b/man/deprecate.Rd new file mode 100644 index 000000000..56ec43586 --- /dev/null +++ b/man/deprecate.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deprecate.R +\name{deprecate} +\alias{deprecate} +\alias{addTaxonomyTree} +\alias{addTaxonomyTree,SummarizedExperiment-method} +\alias{taxonomyTree} +\alias{taxonomyTree,SummarizedExperiment-method} +\title{These functions will be deprecated. Please use other functions instead.} +\usage{ +addTaxonomyTree(x, ...) + +\S4method{addTaxonomyTree}{SummarizedExperiment}(x) + +taxonomyTree(x, ...) + +\S4method{taxonomyTree}{SummarizedExperiment}(x) +} +\arguments{ +\item{x}{a \code{\link{SummarizedExperiment}} object -} + +\item{...}{\itemize{ +\item +}} +} +\description{ +These functions will be deprecated. Please use other functions instead. +} diff --git a/man/taxonomy-methods.Rd b/man/taxonomy-methods.Rd index 74d530b9f..4cd296cbf 100644 --- a/man/taxonomy-methods.Rd +++ b/man/taxonomy-methods.Rd @@ -12,10 +12,9 @@ \alias{checkTaxonomy,SummarizedExperiment-method} \alias{getTaxonomyLabels} \alias{getTaxonomyLabels,SummarizedExperiment-method} -\alias{taxonomyTree} -\alias{taxonomyTree,SummarizedExperiment-method} -\alias{addTaxonomyTree} -\alias{addTaxonomyTree,SummarizedExperiment-method} +\alias{getHierarchyTree,SummarizedExperiment-method} +\alias{addTree} +\alias{addTree,SummarizedExperiment-method} \alias{mapTaxonomy} \alias{mapTaxonomy,SummarizedExperiment-method} \alias{IdTaxaToDataFrame} @@ -58,13 +57,11 @@ getTaxonomyLabels(x, ...) ... ) -taxonomyTree(x, ...) +\S4method{getHierarchyTree}{SummarizedExperiment}(x) -\S4method{taxonomyTree}{SummarizedExperiment}(x) +addTree(x, ...) -addTaxonomyTree(x, ...) - -\S4method{addTaxonomyTree}{SummarizedExperiment}(x) +\S4method{addTree}{SummarizedExperiment}(x) mapTaxonomy(x, ...) @@ -146,12 +143,15 @@ creation. the lowest taxonomic information possible. If data from different levels, is to be mixed, the taxonomic level is prepended by default. -\code{taxonomyTree} generates a \code{phylo} tree object from the available +\code{getHierarchyTree} generates a hierarchy tree from the available taxonomic information. Internally it uses \code{\link[TreeSummarizedExperiment:toTree]{toTree}} and \code{\link[TreeSummarizedExperiment:resolveLoop]{resolveLoop}} to sanitize data if needed. +\code{addTree} calculates hierarchy tree from the available taxonomic +information and add it to rowTree. + \code{IdTaxaToDataFrame} extracts taxonomic results from results of \code{\link[DECIPHER:IdTaxa]{IdTaxa}}. @@ -192,7 +192,7 @@ mapTaxonomy(GlobalPatterns, taxa = "Escherichia",to="Family") # adding a rowTree() based on the available taxonomic information. Please # note that any tree already stored in rowTree() will be overwritten. x <- GlobalPatterns -x <- addTaxonomyTree(x) +x <- addTree(x) x } \seealso{ diff --git a/man/transformAssay.Rd b/man/transformAssay.Rd index e5933e487..f49a71e98 100644 --- a/man/transformAssay.Rd +++ b/man/transformAssay.Rd @@ -120,9 +120,10 @@ reference sample's column in returned assay when calculating alr. (default: \code{ref_vals = NA})} }} -\item{pseudocount}{TRUE or FALSE, should the minimum value of \code{assay.type} -be added to assay values. Alternatively, a numeric value specifying the value -to be added. (default: \code{pseudocount = FALSE})} +\item{pseudocount}{TRUE, FALSE, or a numeric value. When TRUE, +automatically adds the minimum positive value of \code{assay.type}. +When FALSE, does not add any pseudocount (pseudocount = 0). +Alternatively, a user-specified numeric value can be added as pseudocount.} \item{MARGIN}{A single character value for specifying whether the transformation is applied sample (column) or feature (row) wise. diff --git a/tests/testthat/test-2taxonomy.R b/tests/testthat/test-2taxonomy.R index 9daaab994..ad660e001 100644 --- a/tests/testthat/test-2taxonomy.R +++ b/tests/testthat/test-2taxonomy.R @@ -69,9 +69,9 @@ test_that("taxonomy", { c("Family:j","Phylum:a","Family:k","Family:l","Family:m", "Family:n","Family:o_1","Phylum:c","Family:o_2")) - # addTaxonomyTree + # addTree data(GlobalPatterns, package="mia") - expect_warning(GlobalPatterns <- addTaxonomyTree(GlobalPatterns)) + expect_warning(GlobalPatterns <- addTree(GlobalPatterns)) expect_equal(dim(GlobalPatterns),c(19216,26)) expect_equal(rowTree(GlobalPatterns)$Nnode, 1089) expect_equal(length(rowTree(GlobalPatterns)$tip.label), 1645)