Skip to content

Commit

Permalink
Rename subsampleCounts to rarefyAssay (microbiome#536)
Browse files Browse the repository at this point in the history
Co-authored-by: TuomasBorman <[email protected]>
Co-authored-by: Tuomas Borman <[email protected]>
  • Loading branch information
3 people authored May 20, 2024
1 parent 0d264b8 commit cc5c228
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 34 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.12
Version: 1.13.13
Authors@R:
c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"),
email = "[email protected]",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export(perSampleDominantFeatures)
export(perSampleDominantTaxa)
export(performDMNgroupCV)
export(plotNMDS)
export(rarefyAssay)
export(readQZA)
export(relAbundanceCounts)
export(relabundance)
Expand Down Expand Up @@ -197,6 +198,7 @@ exportMethods(mergeSamples)
exportMethods(perSampleDominantFeatures)
exportMethods(perSampleDominantTaxa)
exportMethods(performDMNgroupCV)
exportMethods(rarefyAssay)
exportMethods(relAbundanceCounts)
exportMethods(relabundance)
exportMethods(right_join)
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ Changes in version 1.13.x
relAbundanceCounts
+ rename getRare* functions to getRare, getUnique* functions to getUnique,
getTop* functions to getTop and getPrevalent* functions to getPrevalent
+ Rename subsampleCounts to rarefyAssay
18 changes: 18 additions & 0 deletions R/deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,21 @@ setMethod(
getPrevalent(x,...)
}
)

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

#' @rdname deprecate
#' @export
setMethod(
"subsampleCounts", signature = c(x = "SummarizedExperiment"),
function(x, ...){
.Deprecated(
msg = "'subsampleCounts' is deprecated. ",
"Use 'rarefyAssay' instead.")
rarefyAssay(x, ...)
}
)
24 changes: 11 additions & 13 deletions R/subsampleCounts.R → R/rarefyAssay.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Subsample Counts
#'
#' \code{subsampleCounts} will randomly subsample counts in
#' \code{rarefyAssay} will randomly subsample counts in
#' \code{SummarizedExperiment} and return the a modified object in which each
#' sample has same number of total observations/counts/reads.
#'
#' @details
#' Although the subsampling approach is highly debated in microbiome research,
#' we include the \code{subsampleCounts} function because there may be some
#' we include the \code{rarefyAssay} function because there may be some
#' instances where it can be useful.
#' Note that the output of \code{subsampleCounts} is not the equivalent as the
#' Note that the output of \code{rarefyAssay} is not the equivalent as the
#' input and any result have to be verified with the original dataset.
#' To maintain the reproducibility, please define the seed using set.seed()
#' before implement this function.
Expand Down Expand Up @@ -58,11 +58,11 @@
#' microbial differential abundance strategies depend upon data characteristics.
#' Microbiome. 2017 Dec;5(1):1-8.
#'
#' @return \code{subsampleCounts} return \code{x} with subsampled data.
#' @return \code{rarefyAssay} return \code{x} with subsampled data.
#'
#' @author Sudarshan A. Shetty and Felix G.M. Ernst
#'
#' @name subsampleCounts
#' @name rarefyAssay
#'
#' @examples
#' # When samples in TreeSE are less than specified min_size, they will be removed.
Expand All @@ -71,7 +71,7 @@
#' data(GlobalPatterns)
#' tse <- GlobalPatterns
#' set.seed(123)
#' tse.subsampled <- subsampleCounts(tse,
#' tse.subsampled <- rarefyAssay(tse,
#' min_size = 60000,
#' name = "subsampled"
#' )
Expand All @@ -81,22 +81,20 @@
#'
NULL

#' @rdname subsampleCounts
#' @aliases rarifyCounts
#' @rdname rarefyAssay
#' @export
setGeneric("subsampleCounts", signature = c("x"),
setGeneric("rarefyAssay", signature = c("x"),
function(x, assay.type = assay_name, assay_name = "counts",
min_size = min(colSums2(assay(x))),
replace = TRUE,
name = "subsampled", verbose = TRUE, ...)
standardGeneric("subsampleCounts"))
standardGeneric("rarefyAssay"))

#' @importFrom SummarizedExperiment assay assay<-
#' @importFrom DelayedMatrixStats colSums2 rowSums2
#' @rdname subsampleCounts
#' @aliases rarifyCounts
#' @rdname rarefyAssay
#' @export
setMethod("subsampleCounts", signature = c(x = "SummarizedExperiment"),
setMethod("rarefyAssay", signature = c(x = "SummarizedExperiment"),
function(x, assay.type = assay_name, assay_name = "counts",
min_size = min(colSums2(assay(x))),
replace = TRUE,
Expand Down
6 changes: 6 additions & 0 deletions man/deprecate.Rd

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

23 changes: 11 additions & 12 deletions man/subsampleCounts.Rd → man/rarefyAssay.Rd

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

2 changes: 1 addition & 1 deletion pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ reference:
- contents:
- meltSE
- relabundance
- subsampleCounts
- rarefyAssay
- subsetSamples
- subtitle: Datasets
- contents:
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-8subsample.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
context("subsampleCounts")
test_that("subsampleCounts", {
context("rarefyAssay")
test_that("rarefyAssay", {
seed = 1938
set.seed(seed)
data(GlobalPatterns, package="mia")

expect_warning(tse.subsampled <- subsampleCounts(GlobalPatterns,
expect_warning(tse.subsampled <- rarefyAssay(GlobalPatterns,
min_size = 60000,
name = "subsampled",
replace = TRUE))
Expand Down Expand Up @@ -37,7 +37,7 @@ test_that("subsampleCounts", {
# When replace = FALSE
seed = 1938
set.seed(seed)
expect_warning(tse.subsampled.rp <- subsampleCounts(GlobalPatterns,
expect_warning(tse.subsampled.rp <- rarefyAssay(GlobalPatterns,
min_size = 60000,
name = "subsampled",
replace = FALSE))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-9cluster.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
context("subsampleCounts")
test_that("subsampleCounts", {
context("rarefyAssay")
test_that("rarefyAssay", {
library(bluster)
data(GlobalPatterns, package="mia")

Expand Down
2 changes: 1 addition & 1 deletion vignettes/mia.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Sub-sampling to equal number of counts per sample. Also known as rarefying.
```{r}
data(GlobalPatterns, package = "mia")
tse.subsampled <- subsampleCounts(GlobalPatterns,
tse.subsampled <- rarefyAssay(GlobalPatterns,
min_size = 60000,
name = "subsampled",
replace = TRUE,
Expand Down

0 comments on commit cc5c228

Please sign in to comment.