From 9e4d0dc5e5ad140341ac7e1f935cffa5728ee8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9otime=20Pralas?= <151254073+thpralas@users.noreply.github.com> Date: Mon, 20 May 2024 19:27:28 +0300 Subject: [PATCH] Rename countDominant* functions to summarizeDominance (#528) Co-authored-by: Tuomas Borman <60338854+TuomasBorman@users.noreply.github.com> Co-authored-by: TuomasBorman --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ NEWS | 1 + R/deprecate.R | 32 +++++++++++++++++++++++++ R/summaries.R | 36 +++++++---------------------- man/deprecate.Rd | 12 ++++++++++ man/summaries.Rd | 24 ++++++++----------- tests/testthat/test-5dominantTaxa.R | 22 +++++++++--------- tests/testthat/test-8summaries.R | 6 ++--- 9 files changed, 79 insertions(+), 58 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 91a5a05ce..15bb4f6fc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mia Type: Package -Version: 1.13.7 +Version: 1.13.8 Authors@R: c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"), email = "felix.gm.ernst@outlook.com", diff --git a/NAMESPACE b/NAMESPACE index 7415f1a19..976ba604a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -104,6 +104,7 @@ export(subsetByRareTaxa) export(subsetFeatures) export(subsetSamples) export(subsetTaxa) +export(summarizeDominance) export(taxonomyTree) export(testExperimentCrossAssociation) export(testExperimentCrossCorrelation) @@ -202,6 +203,7 @@ exportMethods(subsetByRareTaxa) exportMethods(subsetFeatures) exportMethods(subsetSamples) exportMethods(subsetTaxa) +exportMethods(summarizeDominance) exportMethods(summary) exportMethods(taxonomyRankEmpty) exportMethods(taxonomyRanks) diff --git a/NEWS b/NEWS index 97b59fe11..8d5697a90 100644 --- a/NEWS +++ b/NEWS @@ -121,3 +121,4 @@ Changes in version 1.13.x + getHierarchyTree: bugfix related to empty cells in rowData + agglomerateByRank: bugfix: trees was not pruned correctly + rename meltAssay to meltSE ++ Rename countDominantFeatures and countDominantTaxa to summarizeDominance diff --git a/R/deprecate.R b/R/deprecate.R index 35d11e693..bd26c2913 100644 --- a/R/deprecate.R +++ b/R/deprecate.R @@ -362,6 +362,38 @@ loadFromHumann <- function(...) { importHUMAnN(...) } +#' @rdname deprecate +#' @export +setGeneric("countDominantFeatures", signature = c("x"), + function(x, ...) + standardGeneric("countDominantFeatures")) + +#' @rdname deprecate +#' @export +setMethod("countDominantFeatures", signature = c(x = "SummarizedExperiment"), + function(x, ...){ + .Deprecated(msg = "'countDominantFeatures' function is deprecated. ", + "Use 'summarizeDominance' instead.") + summarizeDominance(x, ...) + } +) + +#' @rdname deprecate +#' @export +setGeneric("countDominantTaxa", signature = c("x"), + function(x, ...) + standardGeneric("countDominantTaxa")) + +#' @rdname deprecate +#' @export +setMethod("countDominantTaxa", signature = c(x = "SummarizedExperiment"), + function(x, ...){ + .Deprecated(msg = "'countDominantTaxa' function is deprecated. ", + "Use 'summarizeDominance' instead.") + summarizeDominance(x, ...) + } +) + #' @rdname deprecate #' @export setGeneric("full_join", signature = c("x"), diff --git a/R/summaries.R b/R/summaries.R index 3a742db43..0185ab6e1 100644 --- a/R/summaries.R +++ b/R/summaries.R @@ -78,13 +78,13 @@ #' na.rm = TRUE)) #' #' # Gets the overview of dominant taxa -#' dominant_taxa <- countDominantFeatures(GlobalPatterns, +#' dominant_taxa <- summarizeDominance(GlobalPatterns, #' rank = "Genus") #' dominant_taxa #' #' # With group, it is possible to group observations based on specified groups #' # Gets the overview of dominant taxa -#' dominant_taxa <- countDominantFeatures(GlobalPatterns, +#' dominant_taxa <- summarizeDominance(GlobalPatterns, #' rank = "Genus", #' group = "SampleType", #' na.rm = TRUE) @@ -231,29 +231,28 @@ setMethod("getUniqueTaxa", signature = c(x = "SummarizedExperiment"), #' @param name The column name for the features. The default is 'dominant_taxa'. #' #' @param ... Additional arguments passed on to \code{agglomerateByRank()} when -#' \code{rank} is specified for \code{countDominantFeatures}. +#' \code{rank} is specified for \code{summarizeDominance}. #' #' #' @details -#' \code{countDominantFeatures} returns information about most dominant +#' \code{summarizeDominance} returns information about most dominant #' taxa in a tibble. Information includes their absolute and relative #' abundances in whole data set. #' #' #' @return -#' The \code{countDominantFeatures} returns an overview in a tibble. It contains dominant taxa +#' The \code{summarizeDominance} returns an overview in a tibble. It contains dominant taxa #' in a column named \code{*name*} and its abundance in the data set. #' #' @export -setGeneric("countDominantFeatures",signature = c("x"), +setGeneric("summarizeDominance",signature = c("x"), function(x, group = NULL, name = "dominant_taxa", ...) - standardGeneric("countDominantFeatures")) + standardGeneric("summarizeDominance")) #' @rdname summaries -#' @aliases countDominantTaxa #' @export -setMethod("countDominantFeatures", signature = c(x = "SummarizedExperiment"), +setMethod("summarizeDominance", signature = c(x = "SummarizedExperiment"), function(x, group = NULL, name = "dominant_taxa", ...){ # Input check # group check @@ -294,25 +293,6 @@ setMethod("countDominantFeatures", signature = c(x = "SummarizedExperiment"), } ) - -#' @rdname summaries -#' @aliases countDominantFeatures -#' @export -setGeneric("countDominantTaxa", signature = c("x"), - function(x, ...) - standardGeneric("countDominantTaxa")) - -#' @rdname summaries -#' @aliases countDominantFeatures -#' @export -setMethod("countDominantTaxa", signature = c(x = "SummarizedExperiment"), - function(x, ...){ - .Deprecated(old ="countDominantTaxa", new = "countDominantFeatures", msg = "The 'countDominantTaxa' function is deprecated. Use 'countDominantFeatures' instead.") - countDominantFeatures(x, ...) - } -) - - ################################ HELP FUNCTIONS ################################ #' @importFrom S4Vectors as.data.frame diff --git a/man/deprecate.Rd b/man/deprecate.Rd index 3d15e959a..39a1cdf4e 100644 --- a/man/deprecate.Rd +++ b/man/deprecate.Rd @@ -41,6 +41,10 @@ \alias{loadFromMothur} \alias{loadFromMetaphlan} \alias{loadFromHumann} +\alias{countDominantFeatures} +\alias{countDominantFeatures,SummarizedExperiment-method} +\alias{countDominantTaxa} +\alias{countDominantTaxa,SummarizedExperiment-method} \alias{full_join} \alias{full_join,ANY-method} \alias{inner_join} @@ -134,6 +138,14 @@ loadFromMetaphlan(...) loadFromHumann(...) +countDominantFeatures(x, ...) + +\S4method{countDominantFeatures}{SummarizedExperiment}(x, ...) + +countDominantTaxa(x, ...) + +\S4method{countDominantTaxa}{SummarizedExperiment}(x, ...) + full_join(x, ...) \S4method{full_join}{ANY}(x, ...) diff --git a/man/summaries.Rd b/man/summaries.Rd index 6c11e4b66..9b11d0156 100644 --- a/man/summaries.Rd +++ b/man/summaries.Rd @@ -10,10 +10,8 @@ \alias{getUniqueTaxa} \alias{getUniqueFeatures,SummarizedExperiment-method} \alias{getUniqueTaxa,SummarizedExperiment-method} -\alias{countDominantFeatures} -\alias{countDominantFeatures,SummarizedExperiment-method} -\alias{countDominantTaxa} -\alias{countDominantTaxa,SummarizedExperiment-method} +\alias{summarizeDominance} +\alias{summarizeDominance,SummarizedExperiment-method} \alias{summary,SummarizedExperiment-method} \title{Summarizing microbiome data} \usage{ @@ -49,13 +47,9 @@ getUniqueTaxa(x, ...) \S4method{getUniqueTaxa}{SummarizedExperiment}(x, ...) -countDominantFeatures(x, group = NULL, name = "dominant_taxa", ...) +summarizeDominance(x, group = NULL, name = "dominant_taxa", ...) -\S4method{countDominantFeatures}{SummarizedExperiment}(x, group = NULL, name = "dominant_taxa", ...) - -countDominantTaxa(x, ...) - -\S4method{countDominantTaxa}{SummarizedExperiment}(x, ...) +\S4method{summarizeDominance}{SummarizedExperiment}(x, group = NULL, name = "dominant_taxa", ...) \S4method{summary}{SummarizedExperiment}(object, assay.type = assay_name, assay_name = "counts") } @@ -82,7 +76,7 @@ will be disabled.)} specified to argument \code{method}. Default is TRUE.} \item{...}{Additional arguments passed on to \code{agglomerateByRank()} when -\code{rank} is specified for \code{countDominantFeatures}.} +\code{rank} is specified for \code{summarizeDominance}.} \item{rank}{A single character defining a taxonomic rank. Must be a value of the output of \code{taxonomyRanks()}.} @@ -102,7 +96,7 @@ The \code{getTopFeatures} returns a vector of the most \code{top} abundant The \code{getUniqueFeatures} returns a vector of unique taxa present at a particular rank -The \code{countDominantFeatures} returns an overview in a tibble. It contains dominant taxa +The \code{summarizeDominance} returns an overview in a tibble. It contains dominant taxa in a column named \code{*name*} and its abundance in the data set. The \code{summary} returns a list with two \code{tibble}s @@ -119,7 +113,7 @@ object. The \code{getUniqueFeatures} is a basic function to access different taxa at a particular taxonomic rank. -\code{countDominantFeatures} returns information about most dominant +\code{summarizeDominance} returns information about most dominant taxa in a tibble. Information includes their absolute and relative abundances in whole data set. @@ -150,13 +144,13 @@ getTopFeatures(agglomerateByRank(GlobalPatterns, na.rm = TRUE)) # Gets the overview of dominant taxa -dominant_taxa <- countDominantFeatures(GlobalPatterns, +dominant_taxa <- summarizeDominance(GlobalPatterns, rank = "Genus") dominant_taxa # With group, it is possible to group observations based on specified groups # Gets the overview of dominant taxa -dominant_taxa <- countDominantFeatures(GlobalPatterns, +dominant_taxa <- summarizeDominance(GlobalPatterns, rank = "Genus", group = "SampleType", na.rm = TRUE) diff --git a/tests/testthat/test-5dominantTaxa.R b/tests/testthat/test-5dominantTaxa.R index 1a2597259..40276aea0 100644 --- a/tests/testthat/test-5dominantTaxa.R +++ b/tests/testthat/test-5dominantTaxa.R @@ -79,24 +79,24 @@ test_that("perSampleDominantFeatures", { test_perSampleDominantFeatures(GlobalPatterns) - test_that("countDominantFeatures", { + test_that("summarizeDominance", { - test_countDominantFeatures <- function(tse){ - expect_equal(countDominantFeatures(tse, group = "SampleType")$dominant_taxa, + test_summarizeDominance <- function(tse){ + expect_equal(summarizeDominance(tse, group = "SampleType")$dominant_taxa, c("331820", "549656", "550960", "319044", "189047", "279599", "329744", "12812", "534609", "557211", "87194", "484436", "64396", "98605", "256977", "36155","71074", "114821", "360229")) - expect_equal(countDominantFeatures(tse, + expect_equal(summarizeDominance(tse, rank = "Kingdom")$dominant_taxa[1], c("Bacteria")) - expect_equal(countDominantFeatures(tse, rank = "Order", digits = 3)$rel_freq, + expect_equal(summarizeDominance(tse, rank = "Order", digits = 3)$rel_freq, c(0.231, 0.115, 0.077, 0.077, 0.077, 0.077, 0.038, 0.038, 0.038, 0.038, 0.038, 0.038, 0.038, 0.038, 0.038)) # check sample type - sample.type <- countDominantFeatures(tse, rank = "Class", + sample.type <- summarizeDominance(tse, rank = "Class", group = "SampleType")$SampleType expect_equal(as.character(sample.type), @@ -109,8 +109,8 @@ test_that("perSampleDominantFeatures", { assay(tse1)[1, 1] <- max(assay(tse1)[, 1]) # Calculate info about dominant taxa - count_dominant <- countDominantFeatures(tse) - count_dominant1 <- countDominantFeatures(tse1) + count_dominant <- summarizeDominance(tse) + count_dominant1 <- summarizeDominance(tse1) # count_dominant1 should have one extra row, since there are more dominant taxa expect_equal( nrow(count_dominant1), nrow(count_dominant) + 1) @@ -120,8 +120,8 @@ test_that("perSampleDominantFeatures", { expect_true(count_dominant$dominant_taxa[1] %in% count_dominant1$dominant_taxa) # Now the row lengths should be equal - count_dominant <- countDominantFeatures(tse, complete = F) - expect_warning(count_dominant1 <- countDominantFeatures(tse1, complete = F)) + count_dominant <- summarizeDominance(tse, complete = F) + expect_warning(count_dominant1 <- summarizeDominance(tse1, complete = F)) expect_equal(nrow(count_dominant1), nrow(count_dominant)) @@ -129,7 +129,7 @@ test_that("perSampleDominantFeatures", { # TSE object data(GlobalPatterns, package="mia") - test_countDominantFeatures(GlobalPatterns) + test_summarizeDominance(GlobalPatterns) }) }) diff --git a/tests/testthat/test-8summaries.R b/tests/testthat/test-8summaries.R index dae496001..697e27ab2 100644 --- a/tests/testthat/test-8summaries.R +++ b/tests/testthat/test-8summaries.R @@ -55,10 +55,10 @@ test_that("summaries", { assay.type = "counts") ) expect_equal( getUniqueTaxa(GlobalPatterns, "Phylum", sort = TRUE), getUniqueFeatures(GlobalPatterns, "Phylum", sort = TRUE) ) - expect_equal( countDominantTaxa(GlobalPatterns), - countDominantFeatures(GlobalPatterns)) + expect_equal( summarizeDominance(GlobalPatterns), + summarizeDominance(GlobalPatterns)) # Test with multiple equal dominant taxa in one sample assay(GlobalPatterns)[1, 1] <- max(assay(GlobalPatterns)[, 1]) - expect_warning(countDominantFeatures(GlobalPatterns, complete = FALSE)) + expect_warning(summarizeDominance(GlobalPatterns, complete = FALSE)) })