Skip to content

Commit

Permalink
Deprecate functions taxonomyTree and addTaxonomyTree
Browse files Browse the repository at this point in the history
  • Loading branch information
thpralas committed Feb 21, 2024
1 parent 61f2d16 commit 1e0b96f
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 32 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ exportMethods(addNotContaminantQC)
exportMethods(addPerSampleDominantFeatures)
exportMethods(addPerSampleDominantTaxa)
exportMethods(addTaxonomyTree)
exportMethods(addTree)
exportMethods(agglomerateByPrevalence)
exportMethods(agglomerateByRank)
exportMethods(bestDMNFit)
Expand Down Expand Up @@ -130,6 +131,7 @@ exportMethods(getBestDMNFit)
exportMethods(getDMN)
exportMethods(getExperimentCrossAssociation)
exportMethods(getExperimentCrossCorrelation)
exportMethods(getHierarchyTree)
exportMethods(getPrevalence)
exportMethods(getPrevalentAbundance)
exportMethods(getPrevalentFeatures)
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 40 additions & 0 deletions R/deprecate.R
Original file line number Diff line number Diff line change
@@ -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)
}

This comment has been minimized.

Copy link
@TuomasBorman

TuomasBorman Feb 21, 2024

Contributor

The idea is correct. However, the names seems to be inccorrect,

addTaxonomyTree: addHierarchyTree

This comment has been minimized.

Copy link
@thpralas

thpralas Feb 22, 2024

Author Collaborator

I am not sure to understand, is the problem here that I renamed addTaxonomyTree to addTree instead of addHierarchyTree?

This comment has been minimized.

Copy link
@thpralas

thpralas Feb 23, 2024

Author Collaborator

What is incorrect in this part of the code ? When I use the deprecated functions, I get the warning intended. Is that the new name of the function that is not correct ?

)

#' @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)
}
)
6 changes: 3 additions & 3 deletions R/splitOn.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

This comment has been minimized.

Copy link
@TuomasBorman

TuomasBorman Feb 21, 2024

Contributor

Can you create an issue? This is not manipulating the rowTree this is adding a new one!! This is a bug. @thpralas

This comment has been minimized.

Copy link
@thpralas

thpralas Feb 22, 2024

Author Collaborator

I described the bug in the issue but do I have to add a reproducible example before submitting? I don't know if this is useful here

This comment has been minimized.

Copy link
@TuomasBorman

TuomasBorman Feb 22, 2024

Contributor

No, this is ok since I know what is the issue. Thanks!

This comment has been minimized.

Copy link
@TuomasBorman

TuomasBorman Feb 22, 2024

Contributor

Hmm, where is the issue. I cannot see it here https://github.com/microbiome/mia/issues

This comment has been minimized.

Copy link
@thpralas

thpralas Feb 23, 2024

Author Collaborator

Sorry about that, now the issue is submitted I think.

This comment has been minimized.

Copy link
@TuomasBorman

TuomasBorman Feb 23, 2024

Contributor

No worries, I was just wondering where it is

} else {
# Otherwise, the returned value is TreeSE
x <- addTaxonomyTree(x)
x <- addTree(x)
}
}
x
Expand Down Expand Up @@ -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]])
}
Expand Down
26 changes: 15 additions & 11 deletions R/taxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.

This comment has been minimized.

Copy link
@TuomasBorman

TuomasBorman Feb 21, 2024

Contributor

\code{rowTree}

#'
#'
#' \code{IdTaxaToDataFrame} extracts taxonomic results from results of
#' \code{\link[DECIPHER:IdTaxa]{IdTaxa}}.
#'
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions man/deprecate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions man/taxonomy-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/transformAssay.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-2taxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1e0b96f

Please sign in to comment.