diff --git a/NAMESPACE b/NAMESPACE index f558daa..586f7a8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,9 +6,9 @@ export(Comparator) export(DifferentialAbundanceResult) export(alphaDiv) export(betaDiv) -export(differentialAbundance) export(getAbundances) export(getGroupLabels) +export(internalDiffAbund) export(rankedAbundance) export(removeIncompleteSamples) exportClasses(AbsoluteAbundanceData) diff --git a/R/method-differentialAbundance.R b/R/method-differentialAbundance.R index 929ef16..b0a0a0c 100644 --- a/R/method-differentialAbundance.R +++ b/R/method-differentialAbundance.R @@ -246,16 +246,16 @@ setMethod("maaslin", signature("AbundanceData", "Comparator"), function(data, co #' @importFrom purrr discard #' @useDynLib microbiomeComputations #' @export -#' @rdname differentialAbundance-methods -setGeneric("differentialAbundance", - function(data, comparator, method = c('DESeq2', 'Maaslin2'), pValueFloor = P_VALUE_FLOOR, verbose = c(TRUE, FALSE)) standardGeneric("differentialAbundance"), +#' @rdname internalDiffAbund-methods +setGeneric("internalDiffAbund", + function(data, comparator, method = c('DESeq2', 'Maaslin2'), pValueFloor = P_VALUE_FLOOR, verbose = c(TRUE, FALSE)) standardGeneric("internalDiffAbund"), signature = c("data", "comparator") ) # this is consistent regardless of rel vs abs abund. the statistical methods will differ depending on that. -#' @rdname differentialAbundance-methods -#' @aliases differentialAbundance,AbundanceData,Comparator-method -setMethod("differentialAbundance", signature("AbundanceData", "Comparator"), function(data, comparator, method = c('DESeq2', 'Maaslin2'), pValueFloor = P_VALUE_FLOOR, verbose = c(TRUE, FALSE)) { +#' @rdname internalDiffAbund-methods +#' @aliases internalDiffAbund,AbundanceData,Comparator-method +setMethod("internalDiffAbund", signature("AbundanceData", "Comparator"), function(data, comparator, method = c('DESeq2', 'Maaslin2'), pValueFloor = P_VALUE_FLOOR, verbose = c(TRUE, FALSE)) { data <- cleanComparatorVariable(data, comparator, verbose) recordIdColumn <- data@recordIdColumn ancestorIdColumns <- data@ancestorIdColumns diff --git a/man/differentialAbundance-methods.Rd b/man/internalDiffAbund-methods.Rd similarity index 86% rename from man/differentialAbundance-methods.Rd rename to man/internalDiffAbund-methods.Rd index 5f78989..d2c7824 100644 --- a/man/differentialAbundance-methods.Rd +++ b/man/internalDiffAbund-methods.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/method-differentialAbundance.R -\name{differentialAbundance} -\alias{differentialAbundance} -\alias{differentialAbundance,AbundanceData,Comparator-method} +\name{internalDiffAbund} +\alias{internalDiffAbund} +\alias{internalDiffAbund,AbundanceData,Comparator-method} \title{Differential abundance} \usage{ -differentialAbundance( +internalDiffAbund( data, comparator, method = c("DESeq2", "Maaslin2"), @@ -13,7 +13,7 @@ differentialAbundance( verbose = c(TRUE, FALSE) ) -\S4method{differentialAbundance}{AbundanceData,Comparator}( +\S4method{internalDiffAbund}{AbundanceData,Comparator}( data, comparator, method = c("DESeq2", "Maaslin2"), diff --git a/tests/testthat/test-differentialAbundance.R b/tests/testthat/test-differentialAbundance.R index d12beab..bf3eb26 100644 --- a/tests/testthat/test-differentialAbundance.R +++ b/tests/testthat/test-differentialAbundance.R @@ -1,6 +1,6 @@ # Tests for differential abundance methods -test_that('differentialAbundance returns a correctly formatted data.table', { +test_that('internalDiffAbund returns a correctly formatted data.table', { testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -56,7 +56,7 @@ test_that('differentialAbundance returns a correctly formatted data.table', { ) ) - result <- differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) expect_equal(length(result@droppedColumns), 182) dt <- result@data expect_equal(names(dt), c('SampleID')) @@ -93,7 +93,7 @@ test_that('differentialAbundance returns a correctly formatted data.table', { ) ) ) - result <- differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) expect_equal(length(result@droppedColumns), 407) dt <- result@data expect_equal(names(dt), c('SampleID')) @@ -128,7 +128,7 @@ test_that('differentialAbundance returns a correctly formatted data.table', { groupB = groupBBins ) - result <- differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) dt <- result@data expect_equal(names(dt), c('SampleID')) expect_s3_class(dt, 'data.table') @@ -159,7 +159,7 @@ test_that('differentialAbundance returns a correctly formatted data.table', { groupB = groupBBins ) - result <- differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) dt <- result@data expect_equal(names(dt), c('SampleID')) expect_s3_class(dt, 'data.table') @@ -172,7 +172,7 @@ test_that('differentialAbundance returns a correctly formatted data.table', { }) -test_that("differentialAbundance can handle messy inputs", { +test_that("internalDiffAbund can handle messy inputs", { testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -233,7 +233,7 @@ test_that("differentialAbundance can handle messy inputs", { ) ) - result <- differentialAbundance(testDataMessy, comparator=comparatorVariable, method='DESeq2', verbose=F) + result <- internalDiffAbund(testDataMessy, comparator=comparatorVariable, method='DESeq2', verbose=F) dt <- result@data expect_equal(names(dt), c('SampleID')) expect_s3_class(dt, 'data.table') @@ -267,7 +267,7 @@ test_that("differentialAbundance can handle messy inputs", { groupB = groupBBins ) - result <- differentialAbundance(testDataMessy, comparator=comparatorVariable, method='DESeq2', verbose=F) + result <- internalDiffAbund(testDataMessy, comparator=comparatorVariable, method='DESeq2', verbose=F) dt <- result@data expect_equal(names(dt), c('SampleID')) expect_s3_class(dt, 'data.table') @@ -298,7 +298,7 @@ test_that("differentialAbundance can handle messy inputs", { groupA = groupABins, groupB = groupBBins ) - result <- differentialAbundance(testDataMessy, comparator=comparatorVariable, method='DESeq2', verbose=T) + result <- internalDiffAbund(testDataMessy, comparator=comparatorVariable, method='DESeq2', verbose=T) dt <- result@data expect_equal(names(dt), c('SampleID')) expect_s3_class(dt, 'data.table') @@ -313,7 +313,7 @@ test_that("differentialAbundance can handle messy inputs", { }) -test_that("differentialAbundance returns a ComputeResult with the correct slots" , { +test_that("internalDiffAbund returns a ComputeResult with the correct slots" , { testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -365,13 +365,13 @@ test_that("differentialAbundance returns a ComputeResult with the correct slots" ) ) - result <- differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', verbose=F) expect_equal(result@parameters, 'recordIdColumn = entity.SampleID, comparatorColName = entity.binA, method = DESeq2, groupA =binA_a, groupB = binA_b') expect_equal(result@recordIdColumn, 'entity.SampleID') expect_equal(class(result@droppedColumns), 'character') }) -test_that("differentialAbundance fails with improper inputs", { +test_that("internalDiffAbund fails with improper inputs", { testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -421,11 +421,11 @@ test_that("differentialAbundance fails with improper inputs", { groupB = groupBBins ) - expect_error(differentialAbundance(testData, comparator=comparisonVariable, method='DESeq2', verbose=F)) + expect_error(internalDiffAbund(testData, comparator=comparisonVariable, method='DESeq2', verbose=F)) }) -test_that("differentialAbundance catches DESeq2 errors", { +test_that("internalDiffAbund catches DESeq2 errors", { testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -474,12 +474,12 @@ test_that("differentialAbundance catches DESeq2 errors", { sampleMetadata = sampleMetadata, recordIdColumn = 'entity.SampleID') - expect_error(differentialAbundance(testData, comparator=comparisonVariable, method='DESeq2', verbose=T)) + expect_error(internalDiffAbund(testData, comparator=comparisonVariable, method='DESeq2', verbose=T)) }) -test_that("differentialAbundance method Maaslin2 does stuff",{ +test_that("internalDiffAbund method Maaslin2 does stuff",{ testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -538,7 +538,7 @@ test_that("differentialAbundance method Maaslin2 does stuff",{ ) ) - result <- differentialAbundance(testData, + result <- internalDiffAbund(testData, comparator = comparatorVariable, method='Maaslin2', verbose=F) @@ -546,7 +546,7 @@ test_that("differentialAbundance method Maaslin2 does stuff",{ stats <- result@statistics@statistics - resultCounts <- differentialAbundance(testCountsData, + resultCounts <- internalDiffAbund(testCountsData, comparator = comparatorVariable, method='Maaslin2', verbose=F) @@ -560,7 +560,7 @@ test_that("differentialAbundance method Maaslin2 does stuff",{ expect_equal(stats, statsCounts) }) -test_that("toJSON for DifferentialAbundanceResult works",{ +test_that("toJSON for internalDiffAbundResult works",{ testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -609,7 +609,7 @@ test_that("toJSON for DifferentialAbundanceResult works",{ ) ) - result <- differentialAbundance(testData, + result <- internalDiffAbund(testData, comparator = comparatorVariable, method='Maaslin2', verbose=F) @@ -678,29 +678,29 @@ test_that("The smallest pvalue we can get is our p value floor", { ) # Try with different p value floors - result <- differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', pValueFloor = 0, verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', pValueFloor = 0, verbose=F) expect_equal(min(result@statistics@statistics$pValue), 0) expect_equal(min(result@statistics@statistics$adjustedPValue, na.rm=T), 0) # Confirmed NAs are for pvalue=1 - result <- differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', pValueFloor = P_VALUE_FLOOR, verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', pValueFloor = P_VALUE_FLOOR, verbose=F) expect_equal(min(result@statistics@statistics$pValue), P_VALUE_FLOOR) expect_equal(min(result@statistics@statistics$adjustedPValue, na.rm=T), result@statistics@adjustedPValueFloor) # Confirmed NAs are for pvalue=1 # Repeat with Maaslin2 - result <- differentialAbundance(testData, comparator=comparatorVariable, method='Maaslin2', pValueFloor = 0, verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='Maaslin2', pValueFloor = 0, verbose=F) expect_equal(min(result@statistics@statistics$pValue), 0) expect_equal(min(result@statistics@statistics$adjustedPValue), 0) - result <- differentialAbundance(testData, comparator=comparatorVariable, method='Maaslin2', pValueFloor = P_VALUE_FLOOR, verbose=F) + result <- internalDiffAbund(testData, comparator=comparatorVariable, method='Maaslin2', pValueFloor = P_VALUE_FLOOR, verbose=F) expect_equal(min(result@statistics@statistics$pValue), P_VALUE_FLOOR) expect_equal(min(result@statistics@statistics$adjustedPValue), result@statistics@adjustedPValueFloor) }) -test_that("differentialAbundance fails if comparator has one value", { +test_that("internalDiffAbund fails if comparator has one value", { testOTU_path <- testthat::test_path('testdata','testOTU.rda') load(testOTU_path) @@ -734,6 +734,6 @@ test_that("differentialAbundance fails if comparator has one value", { groupB = veupathUtils::BinList(S4Vectors::SimpleList(c(veupathUtils::Bin(binLabel="binB")))) ) - expect_error(differentialAbundance(testData, comparator=comparatorVariable, method='DESeq2', verbose=F)) - expect_error(differentialAbundance(testData, comparator=comparatorVariable, method='Maaslin2', verbose=F)) + expect_error(internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', verbose=F)) + expect_error(internalDiffAbund(testData, comparator=comparatorVariable, method='Maaslin2', verbose=F)) }) \ No newline at end of file