Skip to content

Commit

Permalink
change transformCounts to transformAssay (#396)
Browse files Browse the repository at this point in the history
Co-authored-by: Leo Lahti <[email protected]>
  • Loading branch information
ake123 and antagomir authored Jul 21, 2023
1 parent c1a92d7 commit 660d37b
Show file tree
Hide file tree
Showing 30 changed files with 211 additions and 205 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export(subsetSamples)
export(subsetTaxa)
export(testExperimentCrossAssociation)
export(testExperimentCrossCorrelation)
export(transformCounts)
export(transformAssay)
export(transformFeatures)
export(transformSamples)
export(unsplitByRanks)
Expand Down Expand Up @@ -176,7 +176,7 @@ exportMethods(taxonomyRanks)
exportMethods(taxonomyTree)
exportMethods(testExperimentCrossAssociation)
exportMethods(testExperimentCrossCorrelation)
exportMethods(transformCounts)
exportMethods(transformAssay)
exportMethods(transformFeatures)
exportMethods(transformSamples)
exportMethods(unsplitByRanks)
Expand Down
4 changes: 2 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Changes in version 0.99.0
+ Submitted to Bioconductor

Changes in version 1.1.x
+ split transformCounts into transformSamples and transformFeatures
+ split transformAssay into transformSamples and transformFeatures
+ added log_modulo_skewness as a diversity index
+ added functions for summarizing dominant taxa information
+ added wrapper for adding dominant taxa information to colData
Expand Down Expand Up @@ -67,7 +67,7 @@ Changes in version 1.7.x
+ mergeSEs: fix bug related to equally named variables that are different class
+ mergeSEs: option for merging multiple assays
+ calculateUnifrac: option for specifying the tree from TreeSE
+ transformCounts: utilize vegan package
+ transformAssay: utilize vegan package
+ calculateUnifrac: subset tree based on data
+ agglomerateByRank: take into account multiple trees
+ loadFromBiom: name columns of rowData based on prefixes
Expand Down
4 changes: 2 additions & 2 deletions R/agglomerate.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
#' # If assay contains binary or negative values, summing might lead to meaningless
#' # values, and you will get a warning. In these cases, you might want to do
#' # agglomeration again at chosen taxonomic level.
#' tse <- transformCounts(GlobalPatterns, method = "pa")
#' tse <- transformAssay(GlobalPatterns, method = "pa")
#' tse <- agglomerateByRank(tse, rank = "Genus")
#' tse <- transformCounts(tse, method = "pa")
#' tse <- transformAssay(tse, method = "pa")
#'
#' # removing empty labels by setting na.rm = TRUE
#' sum(is.na(rowData(GlobalPatterns)$Family))
Expand Down
2 changes: 1 addition & 1 deletion R/calculateOverlap.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' @examples
#' data(esophagus)
#' tse <- esophagus
#' tse <- transformCounts(tse, method = "relabundance")
#' tse <- transformAssay(tse, method = "relabundance")
#' overlap <- calculateOverlap(tse, assay_name = "relabundance")
#' overlap
#'
Expand Down
4 changes: 2 additions & 2 deletions R/cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @param ... Additional parameters to use altExps for example
#' @inheritParams bluster::clusterRows
#' @inheritParams runDMN
#' @inheritParams transformCounts
#' @inheritParams transformAssay
#'
#'
#' @details
Expand Down Expand Up @@ -160,4 +160,4 @@ setMethod("cluster", signature = c(x = "SummarizedExperiment"),
call. = FALSE)
}
}
}
}
4 changes: 2 additions & 2 deletions R/getExperimentCrossAssociation.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
#' mae[[1]] <- mae[[1]][1:20, 1:10]
#' mae[[2]] <- mae[[2]][1:20, 1:10]
#' # Transform data
#' mae[[1]] <- transformCounts(mae[[1]], method = "rclr")
#' mae[[1]] <- transformAssay(mae[[1]], method = "rclr")
#'
#' # Calculate cross-correlations
#' result <- getExperimentCrossAssociation(mae, method = "pearson", assay.type2 = "nmr")
Expand All @@ -151,7 +151,7 @@
#' # Use altExp option to specify alternative experiment from the experiment
#' altExp(mae[[1]], "Phylum") <- agglomerateByRank(mae[[1]], rank = "Phylum")
#' # Transform data
#' altExp(mae[[1]], "Phylum") <- transformCounts(altExp(mae[[1]], "Phylum"), method = "relabundance")
#' altExp(mae[[1]], "Phylum") <- transformAssay(altExp(mae[[1]], "Phylum"), method = "relabundance")
#' # When mode = matrix, matrix is returned
#' result <- getExperimentCrossAssociation(mae, experiment2 = 2,
#' assay.type1 = "relabundance", assay.type2 = "nmr",
Expand Down
2 changes: 1 addition & 1 deletion R/makephyloseqFromTreeSummarizedExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#' # they can be chosen with assay.type.
#'
#' # Counts relative abundances table
#' tse <- transformCounts(tse, method = "relabundance")
#' tse <- transformAssay(tse, method = "relabundance")
#' phy2 <- makePhyloseqFromTreeSE(tse, assay.type = "relabundance")
#' phy2
NULL
Expand Down
88 changes: 44 additions & 44 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ setGeneric("mergeCols",
if(length(levels(f)) == nrow(x)){
return(x)
}

archetype <- .norm_archetype(f, archetype)
# merge assays
assays <- assays(x)
Expand All @@ -177,9 +177,9 @@ setGeneric("mergeCols",
# Check if assays include binary or negative values
if( all(assay == 0 | assay == 1) ){
warning(paste0("'",assay.type,"'", " includes binary values."),
"\nAgglomeration of it might lead to meaningless values.",
"\nCheck the assay, and consider doing transformation again manually",
" with agglomerated data.",
"\nAgglomeration of it might lead to meaningless values.",
"\nCheck the assay, and consider doing transformation again manually",
" with agglomerated data.",
call. = FALSE)
}
if( !all( assay >= 0 | is.na(assay) ) ){
Expand Down Expand Up @@ -232,17 +232,17 @@ setGeneric("mergeCols",
#' @rdname merge-methods
#' @export
setMethod("mergeRows", signature = c(x = "SummarizedExperiment"),
function(x, f, archetype = 1L, ...){
.merge_rows(x, f, archetype = archetype, ...)
}
function(x, f, archetype = 1L, ...){
.merge_rows(x, f, archetype = archetype, ...)
}
)

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

.merge_tree <- function(tree, links){
Expand Down Expand Up @@ -330,44 +330,44 @@ setMethod("mergeCols", signature = c(x = "SummarizedExperiment"),
#' @importFrom ape keep.tip
#' @export
setMethod("mergeRows", signature = c(x = "TreeSummarizedExperiment"),
function(x, f, archetype = 1L, mergeTree = FALSE, mergeRefSeq = FALSE, ...){
# input check
if(!.is_a_bool(mergeTree)){
stop("'mergeTree' must be TRUE or FALSE.", call. = FALSE)
}
if(!.is_a_bool(mergeRefSeq)){
stop("'mergeRefSeq' must be TRUE or FALSE.", call. = FALSE)
}
# for optionally merging referenceSeq
refSeq <- NULL
if(mergeRefSeq){
refSeq <- referenceSeq(x)
}
#
x <- callNextMethod(x, f, archetype = 1L, ...)
# optionally merge rowTree
x <- .merge_trees(x, mergeTree, 1)
# optionally merge referenceSeq
if(!is.null(refSeq)){
referenceSeq(x) <- .merge_refseq_list(refSeq, f, rownames(x), ...)
}
x
}
function(x, f, archetype = 1L, mergeTree = FALSE, mergeRefSeq = FALSE, ...){
# input check
if(!.is_a_bool(mergeTree)){
stop("'mergeTree' must be TRUE or FALSE.", call. = FALSE)
}
if(!.is_a_bool(mergeRefSeq)){
stop("'mergeRefSeq' must be TRUE or FALSE.", call. = FALSE)
}
# for optionally merging referenceSeq
refSeq <- NULL
if(mergeRefSeq){
refSeq <- referenceSeq(x)
}
#
x <- callNextMethod(x, f, archetype = 1L, ...)
# optionally merge rowTree
x <- .merge_trees(x, mergeTree, 1)
# optionally merge referenceSeq
if(!is.null(refSeq)){
referenceSeq(x) <- .merge_refseq_list(refSeq, f, rownames(x), ...)
}
x
}
)

#' @rdname merge-methods
#' @importFrom ape keep.tip
#' @export
setMethod("mergeCols", signature = c(x = "TreeSummarizedExperiment"),
function(x, f, archetype = 1L, mergeTree = FALSE, ...){
# input check
if(!.is_a_bool(mergeTree)){
stop("'mergeTree' must be TRUE or FALSE.", call. = FALSE)
}
#
x <- callNextMethod(x, f, archetype = 1L, ...)
# optionally merge colTree
x <- .merge_trees(x, mergeTree, 2)
return(x)
}
function(x, f, archetype = 1L, mergeTree = FALSE, ...){
# input check
if(!.is_a_bool(mergeTree)){
stop("'mergeTree' must be TRUE or FALSE.", call. = FALSE)
}
#
x <- callNextMethod(x, f, archetype = 1L, ...)
# optionally merge colTree
x <- .merge_trees(x, mergeTree, 2)
return(x)
}
)
4 changes: 2 additions & 2 deletions R/mergeSEs.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
#' tse_temp
#'
#' # Merge all available assays
#' tse <- transformCounts(tse, method="relabundance")
#' ts1 <- transformCounts(tse1, method="relabundance")
#' tse <- transformAssay(tse, method="relabundance")
#' ts1 <- transformAssay(tse1, method="relabundance")
#' tse_temp <- mergeSEs(tse, tse1, assay.type = assayNames(tse))
#'
NULL
Expand Down
2 changes: 1 addition & 1 deletion R/relabundance.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' @examples
#' data(GlobalPatterns)
#' # Calculates relative abundances
#' GlobalPatterns <- transformCounts(GlobalPatterns, method="relabundance")
#' GlobalPatterns <- transformAssay(GlobalPatterns, method="relabundance")
#' # Fetches calculated relative abundances
#' # head(assay(GlobalPatterns, "relabundance"))
NULL
Expand Down
4 changes: 2 additions & 2 deletions R/runCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
#' GlobalPatterns <- runRDA(GlobalPatterns, data ~ SampleType)
#' plotReducedDim(GlobalPatterns,"CCA", colour_by = "SampleType")
#'
#' # To scale values when using *RDA functions, use transformCounts(MARGIN = "features",
#' # To scale values when using *RDA functions, use transformAssay(MARGIN = "features",
#' tse <- GlobalPatterns
#' tse <- transformCounts(tse, MARGIN = "features", method = "z")
#' tse <- transformAssay(tse, MARGIN = "features", method = "z")
#' # Data might include taxa that do not vary. Remove those because after z-transform
#' # their value is NA
#' tse <- tse[ rowSums( is.na( assay(tse, "z") ) ) == 0, ]
Expand Down
Loading

0 comments on commit 660d37b

Please sign in to comment.