Skip to content

Commit

Permalink
#392 Deprecate mergeRows/mergeCols and agglomerateByRank/Prevalence (#…
Browse files Browse the repository at this point in the history
…404)

Signed-off-by: Daenarys8 <[email protected]>
  • Loading branch information
Daenarys8 authored Jul 26, 2023
1 parent 4268b62 commit 531768d
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 64 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mia
Type: Package
Version: 1.9.9
Version: 1.9.10
Authors@R:
c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"),
email = "[email protected]",
Expand Down
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ export(makeTreeSummarizedExperimentFromDADA2)
export(makeTreeSummarizedExperimentFromPhyloseq)
export(meltAssay)
export(mergeCols)
export(mergeFeatures)
export(mergeFeaturesByPrevalence)
export(mergeRows)
export(mergeSEs)
export(mergeSamples)
export(perSampleDominantFeatures)
export(perSampleDominantTaxa)
export(performDMNgroupCV)
Expand Down Expand Up @@ -149,8 +152,12 @@ exportMethods(makeTreeSummarizedExperimentFromPhyloseq)
exportMethods(mapTaxonomy)
exportMethods(meltAssay)
exportMethods(mergeCols)
exportMethods(mergeFeatures)
exportMethods(mergeFeaturesByPrevalence)
exportMethods(mergeFeaturesByRank)
exportMethods(mergeRows)
exportMethods(mergeSEs)
exportMethods(mergeSamples)
exportMethods(perSampleDominantFeatures)
exportMethods(perSampleDominantTaxa)
exportMethods(performDMNgroupCV)
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ Changes in version 1.9.x
+ Added Tengeler2020 dataset
+ *RDA & *CCA: calculate also statistical significance
+ altExp support for meltAssay
+ Deprecate mergeRows, mergeCols, agglomerateByRank, agglomerateByPrevalence
47 changes: 47 additions & 0 deletions R/agglomerate.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,22 @@
#' taxonomyRanks(enterotype)
NULL

#' @rdname agglomerate-methods
#' @aliases mergeFeaturesByRank
setGeneric("agglomerateByRank",
signature = "x",
function(x, ...)
standardGeneric("agglomerateByRank"))

#' @rdname agglomerate-methods
#' @aliases agglomerateByRank
setGeneric("mergeFeaturesByRank",
signature = "x",
function(x, ...)
standardGeneric("mergeFeaturesByRank"))

#' @rdname agglomerate-methods
#' @aliases mergeFeaturesByRank
#'
#' @importFrom SummarizedExperiment rowData rowData<-
#'
Expand Down Expand Up @@ -209,6 +218,22 @@ setMethod("agglomerateByRank", signature = c(x = "SummarizedExperiment"),
}
)

#' @rdname agglomerate-methods
#' @aliases agglomerateByRank
#'
#' @importFrom SummarizedExperiment rowData rowData<-
#'
#' @export
setMethod("mergeFeaturesByRank", signature = c(x = "SummarizedExperiment"),
function(x, rank = taxonomyRanks(x)[1], onRankOnly = FALSE, na.rm = FALSE,
empty.fields = c(NA, "", " ", "\t", "-", "_"), ...){
.Deprecated(old="agglomerateByRank", new="mergeFeaturesByRank", "Now agglomerateByRank is deprecated. Use mergeFeaturesByRank instead.")
x <- agglomerateByRank(x, rank = rank, onRankOnly = onRankOnly, na.rm = na.rm,
empty.fields = empty.fields, ...)
x
}
)

#' @rdname agglomerate-methods
#' @importFrom SingleCellExperiment altExp altExp<- altExps<-
#' @export
Expand All @@ -229,6 +254,18 @@ setMethod("agglomerateByRank", signature = c(x = "SingleCellExperiment"),
}
)

#' @rdname agglomerate-methods
#' @aliases agglomerateByRank
#' @importFrom SingleCellExperiment altExp altExp<- altExps<-
#' @export
setMethod("mergeFeaturesByRank", signature = c(x = "SingleCellExperiment"),
function(x, ..., altexp = NULL, strip_altexp = TRUE){
.Deprecated(old="agglomerateByRank", new="mergeFeaturesByRank", "Now agglomerateByRank is deprecated. Use mergeFeaturesByRank instead.")
x <- agglomerateByRank(x, ..., altexp = altexp, strip_altexp = strip_altexp)
x
}
)


#' @rdname agglomerate-methods
#' @export
Expand Down Expand Up @@ -263,6 +300,16 @@ setMethod("agglomerateByRank", signature = c(x = "TreeSummarizedExperiment"),
}
)

#' @rdname agglomerate-methods
#' @aliases agglomerateByRank
#' @export
setMethod("mergeFeaturesByRank", signature = c(x = "TreeSummarizedExperiment"),
function(x, ..., agglomerateTree = FALSE){
.Deprecated(old="agglomerateByRank", new="mergeFeaturesByRank", "Now agglomerateByRank is deprecated. Use mergeFeaturesByRank instead.")
x <- agglomerateByRank(x, ..., agglomerateTree = agglomerateTree)
x
}
)
################################ HELP FUNCTIONS ################################

.remove_with_empty_taxonomic_info <-
Expand Down
20 changes: 20 additions & 0 deletions R/getPrevalence.R
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,22 @@ setMethod("getPrevalentAbundance", signature = c(x = "SummarizedExperiment"),
############################# agglomerateByPrevalence ##########################

#' @rdname getPrevalence
#' @aliases mergeFeaturesByPrevalence
#' @export
setGeneric("agglomerateByPrevalence", signature = "x",
function(x, ...)
standardGeneric("agglomerateByPrevalence"))

#' @rdname getPrevalence
#' @aliases agglomerateByPrevalence
#' @export
setGeneric("mergeFeaturesByPrevalence", signature = "x",
function(x, ...)
standardGeneric("mergeFeaturesByPrevalence"))


#' @rdname getPrevalence
#' @aliases mergeFeaturesByPRevalence
#' @export
setMethod("agglomerateByPrevalence", signature = c(x = "SummarizedExperiment"),
function(x, rank = taxonomyRanks(x)[1L], other_label = "Other", ...){
Expand Down Expand Up @@ -608,3 +617,14 @@ setMethod("agglomerateByPrevalence", signature = c(x = "SummarizedExperiment"),
}
)


#' @rdname getPrevalence
#' @aliases agglomerateByPrevalence
#' @export
setMethod("mergeFeaturesByPrevalence", signature = c(x = "SummarizedExperiment"),
function(x, rank = taxonomyRanks(x)[1L], other_label = "Other", ...){
.Deprecated(old="agglomerateByPrevalence", new="mergeFeaturesByPrevalence", "Now agglomerateByPrevalence is deprecated. Use mergeFeaturesByPrevalence instead.")
x <- agglomerateByPrevalence(x, rank = rank, other_label = other_label, ...)
x
})

64 changes: 64 additions & 0 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,37 @@
NULL

#' @rdname merge-methods
#' @aliases mergeFeatures
#' @export
setGeneric("mergeRows",
signature = "x",
function(x, f, archetype = 1L, ...)
standardGeneric("mergeRows"))

#' @rdname merge-methods
#' @aliases mergeSamples
#' @export
setGeneric("mergeCols",
signature = "x",
function(x, f, archetype = 1L, ...)
standardGeneric("mergeCols"))

#' @rdname merge-methods
#' @aliases mergeRows
#' @export
setGeneric("mergeFeatures",
signature = "x",
function(x, f, archetype = 1L, ...)
standardGeneric("mergeFeatures"))

#' @rdname merge-methods
#' @aliases mergeCols
#' @export
setGeneric("mergeSamples",
signature = "x",
function(x, f, archetype = 1L, ...)
standardGeneric("mergeSamples"))

.norm_f <- function(i, f, dim_type = c("rows","columns")){
dim_type <- match.arg(dim_type)
if(!is.character(f) && !is.factor(f)){
Expand Down Expand Up @@ -230,6 +248,7 @@ setGeneric("mergeCols",
}

#' @rdname merge-methods
#' @aliases mergeFeatures
#' @export
setMethod("mergeRows", signature = c(x = "SummarizedExperiment"),
function(x, f, archetype = 1L, ...){
Expand All @@ -238,13 +257,34 @@ setMethod("mergeRows", signature = c(x = "SummarizedExperiment"),
)

#' @rdname merge-methods
#' @aliases mergeSmaples
#' @export
setMethod("mergeCols", signature = c(x = "SummarizedExperiment"),
function(x, f, archetype = 1L, ...){
.merge_cols(x, f, archetype = archetype, ...)
}
)

#' @rdname merge-methods
#' @aliases mergeRows
#' @export
setMethod("mergeFeatures", signature = c(x = "SummarizedExperiment"),
function(x, f, archetype = 1L, ...){
.Deprecated(old="mergeRows", new="mergeFeatures", "Now mergeRows is deprecated. Use mergeFeatures instead.")
.merge_rows(x, f, archetype = archetype, ...)
}
)

#' @rdname merge-methods
#' @aliases mergeCols
#' @export
setMethod("mergeSamples", signature = c(x = "SummarizedExperiment"),
function(x, f, archetype = 1L, ...){
.Deprecated(old="mergeCols", new="mergeSamples", "Now mergeCols is deprecated. Use mergeSamples instead.")
.merge_cols(x, f, archetype = archetype, ...)
}
)

.merge_tree <- function(tree, links){
tips <- sort(setdiff(tree$edge[, 2], tree$edge[, 1]))
drop_tip <- tips[!(tips %in% unique(links$nodeNum[links$isLeaf]))]
Expand Down Expand Up @@ -371,3 +411,27 @@ setMethod("mergeCols", signature = c(x = "TreeSummarizedExperiment"),
return(x)
}
)

#' @rdname merge-methods
#' @importFrom ape keep.tip
#' @aliases mergeRows
#' @export
setMethod("mergeFeatures", signature = c(x = "TreeSummarizedExperiment"),
function(x, f, archetype = 1L, mergeTree = FALSE, mergeRefSeq = FALSE, ...){
.Deprecated(old="mergeRows", new="mergeFeatures", "Now mergeRows is deprecated. Use mergeFeatures instead.")
x <- mergeRows(x = x, f = f, archetype = 1L, mergeTree = mergeTree, mergeRefSeq = mergeRefSeq, ...)
return(x)
}
)

#' @rdname merge-methods
#' @importFrom ape keep.tip
#' @aliases mergeCols
#' @export
setMethod("mergeSamples", signature = c(x = "TreeSummarizedExperiment"),
function(x, f, archetype = 1L, mergeTree = FALSE, ...){
.Deprecated(old="mergeCols", new="mergeSamples", "Now mergeCols is deprecated. Use mergeSamples instead.")
x <- mergeCols(x, f, archetype = 1L, mergeTree =mergeTree, ...)
return(x)
}
)
47 changes: 34 additions & 13 deletions man/agglomerate-methods.Rd

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

12 changes: 12 additions & 0 deletions man/getPrevalence.Rd

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

Loading

0 comments on commit 531768d

Please sign in to comment.