Skip to content

Commit

Permalink
new generic function agglomerateByVariable (microbiome#507)
Browse files Browse the repository at this point in the history
Co-authored-by: Tuomas Borman <[email protected]>
Co-authored-by: TuomasBorman <[email protected]>
  • Loading branch information
3 people authored May 8, 2024
1 parent 989206b commit 13f7dce
Show file tree
Hide file tree
Showing 17 changed files with 592 additions and 531 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.13.2
Version: 1.13.3
Authors@R:
c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"),
email = "[email protected]",
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(addPerSampleDominantTaxa)
export(addTaxonomyTree)
export(agglomerateByPrevalence)
export(agglomerateByRank)
export(agglomerateByVariable)
export(bestDMNFit)
export(calculateDMN)
export(calculateDMNgroup)
Expand Down Expand Up @@ -124,6 +125,7 @@ exportMethods(addPerSampleDominantTaxa)
exportMethods(addTaxonomyTree)
exportMethods(agglomerateByPrevalence)
exportMethods(agglomerateByRank)
exportMethods(agglomerateByVariable)
exportMethods(bestDMNFit)
exportMethods(calculateCCA)
exportMethods(calculateDMN)
Expand Down Expand Up @@ -288,7 +290,6 @@ importFrom(SummarizedExperiment,rowRanges)
importFrom(ape,cophenetic.phylo)
importFrom(ape,drop.tip)
importFrom(ape,is.rooted)
importFrom(ape,keep.tip)
importFrom(ape,node.depth)
importFrom(ape,node.depth.edgelength)
importFrom(ape,prop.part)
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ Changes in version 1.11.x
Changes in version 1.13.x
+ Added new functions getMediation and addMediation
+ replace getExperiment* and testExperiment* functions with getCrossAssociation
+ Replace mergeRows and mergeCols with new function agglomerateByVariable
246 changes: 153 additions & 93 deletions R/agglomerate.R

Large diffs are not rendered by default.

192 changes: 174 additions & 18 deletions R/deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,169 @@ setMethod("taxonomyTree", signature = c(x = "SummarizedExperiment"),
}
)

#' @rdname deprecate
#' @export
setGeneric("mergeRows",
signature = "x",
function(x, ...)
standardGeneric("mergeRows"))

#' @rdname deprecate
#' @export
setMethod("mergeRows", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeRows' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'rows' instead."))
agglomerateByVariable(x, MARGIN = "rows", ...)
}
)

#' @rdname deprecate
#' @export
setMethod("mergeRows", signature = c(x = "TreeSummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeRows' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'rows' instead."))
agglomerateByVariable(x, MARGIN = "rows", ...)
}
)

#' @rdname deprecate
#' @export
setGeneric("mergeCols",
signature = "x",
function(x, ...)
standardGeneric("mergeCols"))

#' @rdname deprecate
#' @export
setMethod("mergeCols", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeCols' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'cols' instead."))
agglomerateByVariable(x, MARGIN = "cols", ...)
}
)

#' @rdname deprecate
#' @export
setMethod("mergeCols", signature = c(x = "TreeSummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeCols' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'cols' instead."))
agglomerateByVariable(x, MARGIN = "cols", ...)
}
)

#' @rdname deprecate
#' @export
setGeneric("mergeFeatures",
signature = "x",
function(x, ...)
standardGeneric("mergeFeatures"))

#' @rdname deprecate
#' @export
setMethod("mergeFeatures", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeFeatures' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'rows' instead."))
agglomerateByVariable(x, MARGIN = "rows", ...)
}
)

#' @rdname deprecate
#' @export
setMethod("mergeFeatures", signature = c(x = "TreeSummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeFeatures' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'rows' instead."))
agglomerateByVariable(x, MARGIN = "rows", ...)
}
)

#' @rdname deprecate
#' @export
setGeneric("mergeSamples",
signature = "x",
function(x, ...)
standardGeneric("mergeSamples"))

#' @rdname deprecate
#' @export
setMethod("mergeSamples", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeSamples' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'cols' instead."))
agglomerateByVariable(x, MARGIN = "cols", ...)
}
)

#' @rdname deprecate
#' @export
setMethod("mergeSamples", signature = c(x = "TreeSummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeSamples' is deprecated. ",
"Use 'agglomerateByVariable' with ",
"parameter MARGIN = 'cols' instead."))
agglomerateByVariable(x, MARGIN = "cols", ...)
}
)

#' @rdname deprecate
#' @export
setGeneric("mergeFeaturesByRank",
signature = "x",
function(x, ...)
standardGeneric("mergeFeaturesByRank"))

#' @rdname deprecate
#' @export
setMethod("mergeFeaturesByRank", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeFeaturesByRank' is deprecated. ",
"Use 'agglomerateByRank' instead."))
x <- agglomerateByRank(x, ...)
x
}
)

#' @rdname deprecate
#' @export
setMethod("mergeFeaturesByRank", signature = c(x = "SingleCellExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeFeaturesByRank' is deprecated. ",
"Use 'agglomerateByRank' instead."))
x <- agglomerateByRank(x, ...)
x
}
)

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

#' @rdname deprecate
#' @export
setMethod("mergeFeaturesByPrevalence", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0(
"'mergeFeaturesByPrevalence' is deprecated. ",
"Use agglomerateByPrevalence instead."))
x <- agglomerateByPrevalence(x, ...)
x
}
)

#' @rdname deprecate
#' @export
setGeneric("getExperimentCrossAssociation", signature = c("x"),
Expand Down Expand Up @@ -89,6 +252,17 @@ setMethod("getExperimentCrossAssociation", signature = "SummarizedExperiment",
}
)

#' @rdname deprecate
#' @export
setMethod("mergeFeaturesByRank", signature = c(x = "TreeSummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0("'mergeFeaturesByRank' is deprecated. ",
"Use 'agglomerateByRank' instead."))
x <- agglomerateByRank(x, ...)
x
}
)

#' @rdname deprecate
#' @export
setGeneric("testExperimentCrossAssociation", signature = c("x"),
Expand Down Expand Up @@ -140,24 +314,6 @@ setMethod("getExperimentCrossCorrelation", signature = c(x = "ANY"),
}
)

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

#' @rdname deprecate
#' @export
setMethod("mergeFeaturesByPrevalence", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(msg = paste0(
"'mergeFeaturesByPrevalence' is deprecated. ",
"Use agglomerateByPrevalence instead."))
x <- agglomerateByPrevalence(x, ...)
x
}
)

#' @rdname deprecate
#' @export
loadFromBiom <- function(...) {
Expand Down
4 changes: 3 additions & 1 deletion R/getPrevalence.R
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,9 @@ setMethod("agglomerateByPrevalence", signature = c(x = "SummarizedExperiment"),
pr <- getPrevalentTaxa(x, rank = NULL, ...)
f <- rownames(x) %in% pr
if(any(!f)){
other_x <- mergeRows(x[!f,], factor(rep(1L,sum(!f))), check_assays = FALSE)
other_x <- agglomerateByVariable(x[!f,], MARGIN = "rows",
factor(rep(1L,sum(!f))),
check_assays = FALSE)
rowData(other_x)[,colnames(rowData(other_x))] <- NA
# set the other label
rownames(other_x) <- other_label
Expand Down
Loading

0 comments on commit 13f7dce

Please sign in to comment.