From 89bd6446928a149747d9ecec7d6f1778ee029a31 Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Fri, 21 Nov 2025 09:52:31 -0500 Subject: [PATCH 1/7] veupathutils -> mbioutils --- R/class-AbundanceData.R | 4 +-- R/method-alphaDiv.R | 34 ++++++++++----------- R/method-betaDiv.R | 38 +++++++++++------------ R/method-correlation.R | 26 ++++++++-------- R/method-differentialAbundance.R | 48 +++++++++++++++--------------- R/method-rankedAbundance.R | 36 +++++++++++----------- R/methods-AbundanceData.R | 12 ++++---- R/methods-Comparator.R | 2 +- R/methods-json.R | 2 +- R/microbiomeComputations-package.R | 2 +- R/utils.R | 4 +-- 11 files changed, 104 insertions(+), 104 deletions(-) diff --git a/R/class-AbundanceData.R b/R/class-AbundanceData.R index 789fbe3..132e1b0 100644 --- a/R/class-AbundanceData.R +++ b/R/class-AbundanceData.R @@ -37,7 +37,7 @@ check_abundance_data <- function(object) { #' @slot removeEmptyRecords A logical indicating whether empty (all NA/ zero) samples should be removed. #' @name AbundanceData-class #' @rdname AbundanceData-class -#' @importFrom veupathUtils SampleMetadata -#' @importFrom veupathUtils CollectionWithMetadata +#' @importFrom mbioUtils SampleMetadata +#' @importFrom mbioUtils CollectionWithMetadata #' @export AbundanceData <- setClass("AbundanceData", contains = "CollectionWithMetadata", validity = check_abundance_data) \ No newline at end of file diff --git a/R/method-alphaDiv.R b/R/method-alphaDiv.R index abd26e3..ad9d49f 100644 --- a/R/method-alphaDiv.R +++ b/R/method-alphaDiv.R @@ -8,7 +8,7 @@ #' @return ComputeResult object #' @importFrom vegan diversity #' @importFrom stringi stri_trans_totitle -#' @import veupathUtils +#' @import mbioUtils #' @import data.table #' @importFrom methods new slot validObject #' @importFrom stats as.dist as.formula median quantile var @@ -29,8 +29,8 @@ setMethod("alphaDiv", signature("AbundanceData"), function(data, method = c('sha naToZero <- data@imputeZero # Initialize and check inputs - method <- veupathUtils::matchArg(method) - verbose <- veupathUtils::matchArg(verbose) + method <- mbioUtils::matchArg(method) + verbose <- mbioUtils::matchArg(verbose) # Check that incoming df meets requirements if (!'data.table' %in% class(df)) { @@ -38,7 +38,7 @@ setMethod("alphaDiv", signature("AbundanceData"), function(data, method = c('sha } computeMessage <- '' - veupathUtils::logWithTime(paste("Received df table with", nrow(df), "samples and", (ncol(df)-1), "taxa."), verbose) + mbioUtils::logWithTime(paste("Received df table with", nrow(df), "samples and", (ncol(df)-1), "taxa."), verbose) # Compute alpha diversity if (identical(method, 'shannon') | identical(method, 'simpson')){ @@ -58,41 +58,41 @@ setMethod("alphaDiv", signature("AbundanceData"), function(data, method = c('sha result@ancestorIdColumns <- ancestorIdColumns # Handle errors or return positive computeMessage - if (veupathUtils::is.error(alphaDivDT)) { - veupathUtils::logWithTime(paste('Alpha diversity computation FAILED with parameters, method =', method), verbose) + if (mbioUtils::is.error(alphaDivDT)) { + mbioUtils::logWithTime(paste('Alpha diversity computation FAILED with parameters, method =', method), verbose) stop() } else { computeMessage <- paste('Computed', method, 'alpha diversity.') - veupathUtils::logWithTime(paste(method, 'alpha diversity computation complete.'), verbose) + mbioUtils::logWithTime(paste(method, 'alpha diversity computation complete.'), verbose) } # Assemble data table dt <- data.table::as.data.table(df[, ..allIdColumns]) dt$alphaDiversity <- alphaDivDT - entity <- veupathUtils::strSplit(recordIdColumn, ".", 4, 1) + entity <- mbioUtils::strSplit(recordIdColumn, ".", 4, 1) result@computationDetails <- computeMessage result@parameters <- paste('method =', method) result@recordIdColumn <- recordIdColumn result@ancestorIdColumns <- ancestorIdColumns - computedVariableMetadata <- veupathUtils::VariableMetadata( - variableClass = veupathUtils::VariableClass(value = "computed"), - variableSpec = veupathUtils::VariableSpec(variableId = names(dt[, -..allIdColumns]), entityId = entity), - plotReference = veupathUtils::PlotReference(value = "yAxis"), + computedVariableMetadata <- mbioUtils::VariableMetadata( + variableClass = mbioUtils::VariableClass(value = "computed"), + variableSpec = mbioUtils::VariableSpec(variableId = names(dt[, -..allIdColumns]), entityId = entity), + plotReference = mbioUtils::PlotReference(value = "yAxis"), displayName = computedVarLabel, displayRangeMin = 0, displayRangeMax = max(max(dt$alphaDiversity, na.rm = TRUE),1), - dataType = veupathUtils::DataType(value = "NUMBER"), - dataShape = veupathUtils::DataShape(value = "CONTINUOUS") + dataType = mbioUtils::DataType(value = "NUMBER"), + dataShape = mbioUtils::DataShape(value = "CONTINUOUS") ) - result@computedVariableMetadata <- veupathUtils::VariableMetadataList(S4Vectors::SimpleList(computedVariableMetadata)) - names(dt) <- veupathUtils::stripEntityIdFromColumnHeader(names(dt)) + result@computedVariableMetadata <- mbioUtils::VariableMetadataList(S4Vectors::SimpleList(computedVariableMetadata)) + names(dt) <- mbioUtils::stripEntityIdFromColumnHeader(names(dt)) result@data <- dt validObject(result) - veupathUtils::logWithTime(paste('Alpha diversity computation completed with parameters method=', method), verbose) + mbioUtils::logWithTime(paste('Alpha diversity computation completed with parameters method=', method), verbose) return(result) }) diff --git a/R/method-betaDiv.R b/R/method-betaDiv.R index 3629fa4..b2a8790 100644 --- a/R/method-betaDiv.R +++ b/R/method-betaDiv.R @@ -11,7 +11,7 @@ #' @importFrom vegan vegdist #' @importFrom ape pcoa #' @importFrom stringi stri_replace_all_fixed -#' @import veupathUtils +#' @import mbioUtils #' @import data.table #' @useDynLib microbiomeComputations #' @rdname betaDiv-methods @@ -31,8 +31,8 @@ setMethod("betaDiv", signature("AbundanceData"), function(data, method = c('bray allIdColumns <- c(recordIdColumn, ancestorIdColumns) # Initialize and check inputs - method <- veupathUtils::matchArg(method) - verbose <- veupathUtils::matchArg(verbose) + method <- mbioUtils::matchArg(method) + verbose <- mbioUtils::matchArg(verbose) # Check that incoming df meets requirements - consider moving to a validateOTU function or similar if (!'data.table' %in% class(df)) { @@ -40,7 +40,7 @@ setMethod("betaDiv", signature("AbundanceData"), function(data, method = c('bray } computeMessage <- '' - veupathUtils::logWithTime(paste("Received df table with", nrow(df), "samples and", (ncol(df)-1), "taxa."), verbose) + mbioUtils::logWithTime(paste("Received df table with", nrow(df), "samples and", (ncol(df)-1), "taxa."), verbose) # Compute beta diversity using given dissimilarity method if (identical(method, 'bray') | identical(method, 'jaccard')) { @@ -62,11 +62,11 @@ setMethod("betaDiv", signature("AbundanceData"), function(data, method = c('bray result@ancestorIdColumns <- ancestorIdColumns # Handle errors or return positive computeMessage - if (veupathUtils::is.error(dist)) { - veupathUtils::logWithTime(paste('Beta diversity computation FAILED with parameters method=', method, ', k=', k), verbose) + if (mbioUtils::is.error(dist)) { + mbioUtils::logWithTime(paste('Beta diversity computation FAILED with parameters method=', method, ', k=', k), verbose) stop() } else { - veupathUtils::logWithTime("Computed dissimilarity matrix.", verbose) + mbioUtils::logWithTime("Computed dissimilarity matrix.", verbose) computeMessage <- paste(method, "dissimilarity matrix computation successful.") } @@ -80,7 +80,7 @@ setMethod("betaDiv", signature("AbundanceData"), function(data, method = c('bray dt <- cbind(dt, df[, ..allIdColumns]) data.table::setcolorder(dt, allIdColumns) - veupathUtils::logWithTime("Finished ordination step.", verbose) + mbioUtils::logWithTime("Finished ordination step.", verbose) # Extract percent variance eigenvecs <- pcoa$values$Relative_eig @@ -91,7 +91,7 @@ setMethod("betaDiv", signature("AbundanceData"), function(data, method = c('bray # For now returning data and percentVar for how much is in the plot. percentVar <- percentVar[1:k] - entity <- veupathUtils::strSplit(recordIdColumn,".", 4, 1) + entity <- mbioUtils::strSplit(recordIdColumn,".", 4, 1) result@computationDetails <- paste(computeMessage, ', pcoaVariance =', percentVar) result@parameters <- paste('method =', method) @@ -99,30 +99,30 @@ setMethod("betaDiv", signature("AbundanceData"), function(data, method = c('bray displayNames <- paste0(axesNames, " ", sprintf(percentVar,fmt = '%#.1f'), "%") makeVariableMetadataObject <- function(displayName) { - axisName <- veupathUtils::strSplit(displayName, " ") + axisName <- mbioUtils::strSplit(displayName, " ") #bit hacky, see if you can think of something better plotRef <- ifelse(grepl('Axis1', displayName, fixed=T), 'xAxis', 'yAxis') - veupathUtils::VariableMetadata( - variableClass = veupathUtils::VariableClass(value = "computed"), - variableSpec = veupathUtils::VariableSpec(variableId = axisName, entityId = entity), - plotReference = veupathUtils::PlotReference(value = plotRef), + mbioUtils::VariableMetadata( + variableClass = mbioUtils::VariableClass(value = "computed"), + variableSpec = mbioUtils::VariableSpec(variableId = axisName, entityId = entity), + plotReference = mbioUtils::PlotReference(value = plotRef), displayName = displayName, displayRangeMin = min(dt[[axisName]]), displayRangeMax = max(dt[[axisName]]), - dataType = veupathUtils::DataType(value = "NUMBER"), - dataShape = veupathUtils::DataShape(value = "CONTINUOUS") + dataType = mbioUtils::DataType(value = "NUMBER"), + dataShape = mbioUtils::DataShape(value = "CONTINUOUS") ) } - computedVariableMetadata <- veupathUtils::VariableMetadataList(lapply(displayNames, makeVariableMetadataObject)) + computedVariableMetadata <- mbioUtils::VariableMetadataList(lapply(displayNames, makeVariableMetadataObject)) result@computedVariableMetadata <- computedVariableMetadata - names(dt) <- veupathUtils::stripEntityIdFromColumnHeader(names(dt)) + names(dt) <- mbioUtils::stripEntityIdFromColumnHeader(names(dt)) result@data <- dt validObject(result) - veupathUtils::logWithTime(paste('Beta diversity computation completed with parameters recordIdColumn=', recordIdColumn, ', method =', method, ', k =', k, ', verbose =', verbose), verbose) + mbioUtils::logWithTime(paste('Beta diversity computation completed with parameters recordIdColumn=', recordIdColumn, ', method =', method, ', k =', k, ', verbose =', verbose), verbose) return(result) }) \ No newline at end of file diff --git a/R/method-correlation.R b/R/method-correlation.R index 3fb91be..a221baf 100644 --- a/R/method-correlation.R +++ b/R/method-correlation.R @@ -1,12 +1,12 @@ -correlationGeneric <- getGeneric("correlation", package = "veupathUtils") -selfCorrelationGeneric <- getGeneric("selfCorrelation", package = "veupathUtils") +correlationGeneric <- getGeneric("correlation", package = "mbioUtils") +selfCorrelationGeneric <- getGeneric("selfCorrelation", package = "mbioUtils") setClassUnion("missingOrNULL", c("missing", "NULL")) #' Self Correlation #' #' This function returns correlation coefficients for variables in one AbundanceData object against itself. It generally serves as a -#' convenience wrapper around veupathUtils::correlation, with the exception that it additionally supports sparcc. +#' convenience wrapper around mbioUtils::correlation, with the exception that it additionally supports sparcc. #' #' @param data An AbundanceData object #' @param method string defining the type of correlation to run. The currently supported values are 'spearman','pearson' and 'sparcc' @@ -16,31 +16,31 @@ setClassUnion("missingOrNULL", c("missing", "NULL")) #' @param varianceThreshold numeric threshold to filter features by variance across samples #' @param stdDevThreshold numeric threshold to filter features by standard deviation across samples #' @return ComputeResult object -#' @import veupathUtils +#' @import mbioUtils #' @export #' @rdname selfCorrelation-methods #' @aliases selfCorrelation,AbundanceData-method setMethod(selfCorrelationGeneric, signature("AbundanceData"), function(data, method = c('spearman','pearson','sparcc'), format = c('ComputeResult', 'data.table'), verbose = c(TRUE, FALSE), proportionNonZeroThreshold = 0.5, varianceThreshold = 0, stdDevThreshold = 0) { - format <- veupathUtils::matchArg(format) - method <- veupathUtils::matchArg(method) - verbose <- veupathUtils::matchArg(verbose) + format <- mbioUtils::matchArg(format) + method <- mbioUtils::matchArg(method) + verbose <- mbioUtils::matchArg(verbose) #prefilters applied - data <- veupathUtils::pruneFeatures(data, predicateFactory('proportionNonZero', proportionNonZeroThreshold), verbose) - data <- veupathUtils::pruneFeatures(data, predicateFactory('variance', varianceThreshold), verbose) - data <- veupathUtils::pruneFeatures(data, predicateFactory('sd', stdDevThreshold), verbose) + data <- mbioUtils::pruneFeatures(data, predicateFactory('proportionNonZero', proportionNonZeroThreshold), verbose) + data <- mbioUtils::pruneFeatures(data, predicateFactory('variance', varianceThreshold), verbose) + data <- mbioUtils::pruneFeatures(data, predicateFactory('sd', stdDevThreshold), verbose) abundances <- getAbundances(data, FALSE, FALSE, verbose) - corrResult <- veupathUtils::correlation(abundances, NULL, method = method, format = 'data.table', verbose = verbose) + corrResult <- mbioUtils::correlation(abundances, NULL, method = method, format = 'data.table', verbose = verbose) - veupathUtils::logWithTime(paste("Received df table with", nrow(abundances), "samples and", (ncol(abundances)-1), "features with abundances."), verbose) + mbioUtils::logWithTime(paste("Received df table with", nrow(abundances), "samples and", (ncol(abundances)-1), "features with abundances."), verbose) if (format == 'data.table') { return(corrResult) } else { - result <- veupathUtils::buildCorrelationComputeResult(corrResult, data, NULL, method, verbose) + result <- mbioUtils::buildCorrelationComputeResult(corrResult, data, NULL, method, verbose) result@computationDetails <- 'selfCorrelation' return(result) } diff --git a/R/method-differentialAbundance.R b/R/method-differentialAbundance.R index b0a0a0c..89b35fd 100644 --- a/R/method-differentialAbundance.R +++ b/R/method-differentialAbundance.R @@ -1,17 +1,17 @@ # a helper, to reuse and separate some logic cleanComparatorVariable <- function(data, comparator, verbose = c(TRUE, FALSE)) { - verbose <- veupathUtils::matchArg(verbose) + verbose <- mbioUtils::matchArg(verbose) if (!inherits(data, 'AbundanceData')) stop("data must be of the AbundanceData class.") if (!inherits(comparator, 'Comparator')) stop("comparator must be of the Comparator class.") - comparatorColName <- veupathUtils::getColName(comparator@variable@variableSpec) + comparatorColName <- mbioUtils::getColName(comparator@variable@variableSpec) data <- removeIncompleteSamples(data, comparatorColName, verbose) abundances <- getAbundances(data, verbose = verbose) - sampleMetadata <- veupathUtils::getSampleMetadata(data) + sampleMetadata <- mbioUtils::getSampleMetadata(data) recordIdColumn <- data@recordIdColumn - veupathUtils::logWithTime(paste("Received abundance table with", nrow(abundances), "samples and", (ncol(abundances)-1), "taxa."), verbose) + mbioUtils::logWithTime(paste("Received abundance table with", nrow(abundances), "samples and", (ncol(abundances)-1), "taxa."), verbose) # Subset to only include samples with metadata defined in groupA and groupB if (identical(comparator@variable@dataShape@value, "CONTINUOUS")) { @@ -26,8 +26,8 @@ cleanComparatorVariable <- function(data, comparator, verbose = c(TRUE, FALSE)) # Collect all instances where the comparatorColName has values in the bins from each group. # So inGroupA is a vector with 0 if the value in comparatorColName is not within any of the group A bins and >0 otherwise. - inGroupA <- veupathUtils::whichValuesInBinList(sampleMetadata[[comparatorColName]], comparator@groupA) - inGroupB <- veupathUtils::whichValuesInBinList(sampleMetadata[[comparatorColName]], comparator@groupB) + inGroupA <- mbioUtils::whichValuesInBinList(sampleMetadata[[comparatorColName]], comparator@groupA) + inGroupB <- mbioUtils::whichValuesInBinList(sampleMetadata[[comparatorColName]], comparator@groupB) # Eventually move this check to Comparator validation. See #47 if ((any(inGroupA * inGroupB) > 0)) { @@ -70,13 +70,13 @@ cleanComparatorVariable <- function(data, comparator, verbose = c(TRUE, FALSE)) if (length(unique(sampleMetadata[[comparatorColName]])) < 2) { stop("The comparator variable must have at least two values/ groups within the subset.") } - veupathUtils::logWithTime(paste0("Found ",length(keepSamples)," samples with a value for ", comparatorColName, " in either groupA or groupB. The calculation will continue with only these samples."), verbose) + mbioUtils::logWithTime(paste0("Found ",length(keepSamples)," samples with a value for ", comparatorColName, " in either groupA or groupB. The calculation will continue with only these samples."), verbose) # Subset the abundance data based on the kept samples abundances <- abundances[get(recordIdColumn) %in% keepSamples, ] data@data <- abundances - data@sampleMetadata <- veupathUtils::SampleMetadata( + data@sampleMetadata <- mbioUtils::SampleMetadata( data = sampleMetadata, recordIdColumn = data@sampleMetadata@recordIdColumn ) @@ -115,13 +115,13 @@ setGeneric("deseq", ) setMethod("deseq", signature("AbsoluteAbundanceData", "Comparator"), function(data, comparator, verbose = c(TRUE, FALSE)) { - verbose <- veupathUtils::matchArg(verbose) + verbose <- mbioUtils::matchArg(verbose) recordIdColumn <- data@recordIdColumn ancestorIdColumns <- data@ancestorIdColumns allIdColumns <- c(recordIdColumn, ancestorIdColumns) - sampleMetadata <- veupathUtils::getSampleMetadata(data) - comparatorColName <- veupathUtils::getColName(comparator@variable@variableSpec) + sampleMetadata <- mbioUtils::getSampleMetadata(data) + comparatorColName <- mbioUtils::getColName(comparator@variable@variableSpec) # First, remove id columns and any columns that are all 0s. cleanedData <- purrr::discard(data@data[, -..allIdColumns], function(col) {identical(union(unique(col), c(0, NA)), c(0, NA))}) @@ -137,7 +137,7 @@ setMethod("deseq", signature("AbsoluteAbundanceData", "Comparator"), function(da # and ANCOMBC expect the order to match, and will not perform this check. if (!identical(rownames(sampleMetadata), colnames(counts))){ # Reorder sampleMetadata to match counts - veupathUtils::logWithTime("Sample order differs between data and metadata. Reordering data based on the metadata sample order.", verbose) + mbioUtils::logWithTime("Sample order differs between data and metadata. Reordering data based on the metadata sample order.", verbose) data.table::setcolorder(counts, rownames(sampleMetadata)) } @@ -157,8 +157,8 @@ setMethod("deseq", signature("AbsoluteAbundanceData", "Comparator"), function(da deseq_output <- DESeq2::DESeq(dds) }) - if (veupathUtils::is.error(deseq_output)) { - veupathUtils::logWithTime(paste0('Differential abundance FAILED with parameters recordIdColumn=', recordIdColumn, ', method = DESeq2', ', verbose =', verbose), verbose) + if (mbioUtils::is.error(deseq_output)) { + mbioUtils::logWithTime(paste0('Differential abundance FAILED with parameters recordIdColumn=', recordIdColumn, ', method = DESeq2', ', verbose =', verbose), verbose) stop() } @@ -187,13 +187,13 @@ setGeneric("maaslin", # this leaves room for us to grow into dedicated params (normalization and analysis method etc) for counts if desired setMethod("maaslin", signature("AbundanceData", "Comparator"), function(data, comparator, verbose = c(TRUE, FALSE)) { - verbose <- veupathUtils::matchArg(verbose) + verbose <- mbioUtils::matchArg(verbose) recordIdColumn <- data@recordIdColumn ancestorIdColumns <- data@ancestorIdColumns allIdColumns <- c(recordIdColumn, ancestorIdColumns) - sampleMetadata <- veupathUtils::getSampleMetadata(data) - comparatorColName <- veupathUtils::getColName(comparator@variable@variableSpec) + sampleMetadata <- mbioUtils::getSampleMetadata(data) + comparatorColName <- mbioUtils::getColName(comparator@variable@variableSpec) abundances <- data@data # First, remove id columns and any columns that are all 0s. @@ -238,7 +238,7 @@ setMethod("maaslin", signature("AbundanceData", "Comparator"), function(data, co #' The default value uses the P_VALUE_FLOOR=1e-200 constant defined in this package. #' @param verbose boolean indicating if timed logging is desired #' @return ComputeResult object -#' @import veupathUtils +#' @import mbioUtils #' @import data.table #' @import DESeq2 #' @importFrom Maaslin2 Maaslin2 @@ -260,11 +260,11 @@ setMethod("internalDiffAbund", signature("AbundanceData", "Comparator"), functio recordIdColumn <- data@recordIdColumn ancestorIdColumns <- data@ancestorIdColumns allIdColumns <- c(recordIdColumn, ancestorIdColumns) - comparatorColName <- veupathUtils::getColName(comparator@variable@variableSpec) + comparatorColName <- mbioUtils::getColName(comparator@variable@variableSpec) ## Initialize and check inputs - method <- veupathUtils::matchArg(method) - verbose <- veupathUtils::matchArg(verbose) + method <- mbioUtils::matchArg(method) + verbose <- mbioUtils::matchArg(verbose) ## Compute differential abundance @@ -286,7 +286,7 @@ setMethod("internalDiffAbund", signature("AbundanceData", "Comparator"), functio } else { stop('Unaccepted differential abundance method. Accepted methods are "DESeq2" and "Maaslin2".') } - veupathUtils::logWithTime(paste0('Completed method=',method,'. Formatting results.'), verbose) + mbioUtils::logWithTime(paste0('Completed method=',method,'. Formatting results.'), verbose) # Sometimes p-values can be very small, even smaller than the smallest representable number (gives p-value=0). The smallest # representable number changes based on env, so to avoid inconsistency set a p-value floor so that any @@ -326,11 +326,11 @@ setMethod("internalDiffAbund", signature("AbundanceData", "Comparator"), functio # The resulting data should contain only the samples actually used. result@data <- data@data[, ..allIdColumns] - names(result@data) <- veupathUtils::stripEntityIdFromColumnHeader(names(result@data)) + names(result@data) <- mbioUtils::stripEntityIdFromColumnHeader(names(result@data)) validObject(result) - veupathUtils::logWithTime(paste('Differential abundance computation completed with parameters recordIdColumn = ', recordIdColumn,", comparatorColName = ", comparatorColName, ', method = ', method, ', groupA =', getGroupLabels(comparator, "groupA"), ', groupB = ', getGroupLabels(comparator, "groupB")), verbose) + mbioUtils::logWithTime(paste('Differential abundance computation completed with parameters recordIdColumn = ', recordIdColumn,", comparatorColName = ", comparatorColName, ', method = ', method, ', groupA =', getGroupLabels(comparator, "groupA"), ', groupB = ', getGroupLabels(comparator, "groupB")), verbose) return(result) }) diff --git a/R/method-rankedAbundance.R b/R/method-rankedAbundance.R index eeee7c5..2a3c60c 100644 --- a/R/method-rankedAbundance.R +++ b/R/method-rankedAbundance.R @@ -7,7 +7,7 @@ #' @param cutoff integer indicating the maximium number of taxa to be kept after ranking. #' @param verbose boolean indicating if timed logging is desired #' @return ComputeResult object -#' @import veupathUtils +#' @import mbioUtils #' @import data.table #' @importFrom S4Vectors SimpleList #' @export @@ -27,8 +27,8 @@ setMethod("rankedAbundance", signature("AbundanceData"), function(data, method = allIdColumns <- c(recordIdColumn, ancestorIdColumns) # Initialize and check inputs - method <- veupathUtils::matchArg(method) - verbose <- veupathUtils::matchArg(verbose) + method <- mbioUtils::matchArg(method) + verbose <- mbioUtils::matchArg(verbose) # Check that incoming df meets requirements if (!'data.table' %in% class(df)) { @@ -36,7 +36,7 @@ setMethod("rankedAbundance", signature("AbundanceData"), function(data, method = } computeMessage <- '' - veupathUtils::logWithTime(paste("Received df table with", nrow(df), "samples and", (ncol(df)-1), "taxa."), verbose) + mbioUtils::logWithTime(paste("Received df table with", nrow(df), "samples and", (ncol(df)-1), "taxa."), verbose) # Reshape back to sample, taxonomicLevel, abundance formattedDT <- data.table::melt(df, measure.vars=colnames(df[, -..allIdColumns]), variable.factor=F, variable.name='TaxonomicLevel', value.name="Abundance") @@ -55,42 +55,42 @@ setMethod("rankedAbundance", signature("AbundanceData"), function(data, method = keepCols <- c(allIdColumns, topN) dt = df[, ..keepCols] - veupathUtils::logWithTime("Finished ranking taxa", verbose) + mbioUtils::logWithTime("Finished ranking taxa", verbose) result <- new("ComputeResult") result@name <- 'rankedAbundance' result@recordIdColumn <- recordIdColumn result@ancestorIdColumns <- ancestorIdColumns - entity <- veupathUtils::strSplit(recordIdColumn,".", 4, 1) + entity <- mbioUtils::strSplit(recordIdColumn,".", 4, 1) result@computationDetails <- computeMessage result@parameters <- paste0('method = ',method, ', isCutoff = ', isCutoff) - collectionMemberVariableIds <- unlist(lapply(names(dt[, -..allIdColumns]), veupathUtils::strSplit, ".", 4, 2)) + collectionMemberVariableIds <- unlist(lapply(names(dt[, -..allIdColumns]), mbioUtils::strSplit, ".", 4, 2)) makeVariableSpecs <- function(variableId) { - veupathUtils::VariableSpec(variableId = variableId, entityId = entity) + mbioUtils::VariableSpec(variableId = variableId, entityId = entity) } - computedVariableMetadata <- veupathUtils::VariableMetadata( - variableClass = veupathUtils::VariableClass(value = "computed"), - variableSpec = veupathUtils::VariableSpec(variableId = "rankedAbundance", entityId = entity), - plotReference = veupathUtils::PlotReference(value = "xAxis"), + computedVariableMetadata <- mbioUtils::VariableMetadata( + variableClass = mbioUtils::VariableClass(value = "computed"), + variableSpec = mbioUtils::VariableSpec(variableId = "rankedAbundance", entityId = entity), + plotReference = mbioUtils::PlotReference(value = "xAxis"), displayName = "To be determined by client", displayRangeMin = 0, displayRangeMax = 1, - dataType = veupathUtils::DataType(value = "NUMBER"), - dataShape = veupathUtils::DataShape(value = "CONTINUOUS"), + dataType = mbioUtils::DataType(value = "NUMBER"), + dataShape = mbioUtils::DataShape(value = "CONTINUOUS"), isCollection = TRUE, - members = veupathUtils::VariableSpecList(S4Vectors::SimpleList(lapply(collectionMemberVariableIds, makeVariableSpecs))) + members = mbioUtils::VariableSpecList(S4Vectors::SimpleList(lapply(collectionMemberVariableIds, makeVariableSpecs))) ) - result@computedVariableMetadata <- veupathUtils::VariableMetadataList(S4Vectors::SimpleList(computedVariableMetadata)) - names(dt) <- veupathUtils::stripEntityIdFromColumnHeader(names(dt)) + result@computedVariableMetadata <- mbioUtils::VariableMetadataList(S4Vectors::SimpleList(computedVariableMetadata)) + names(dt) <- mbioUtils::stripEntityIdFromColumnHeader(names(dt)) result@data <- dt validObject(result) - veupathUtils::logWithTime(paste('Ranked abundance computation completed with parameters recordIdColumn=', recordIdColumn, ', method =', method, ', cutoff =', cutoff, ', naToZero = ', naToZero, ', verbose =', verbose), verbose) + mbioUtils::logWithTime(paste('Ranked abundance computation completed with parameters recordIdColumn=', recordIdColumn, ', method =', method, ', cutoff =', cutoff, ', naToZero = ', naToZero, ', verbose =', verbose), verbose) return(result) }) diff --git a/R/methods-AbundanceData.R b/R/methods-AbundanceData.R index 65fa2e0..13f6664 100644 --- a/R/methods-AbundanceData.R +++ b/R/methods-AbundanceData.R @@ -18,11 +18,11 @@ setGeneric("getAbundances", #' @rdname getAbundances #' @aliases getAbundances,AbundanceData-method setMethod("getAbundances", signature("AbundanceData"), function(object, ignoreImputeZero = c(FALSE, TRUE), includeIds = c(TRUE, FALSE), verbose = c(TRUE, FALSE)) { - ignoreImputeZero <- veupathUtils::matchArg(ignoreImputeZero) - includeIds <- veupathUtils::matchArg(includeIds) - verbose <- veupathUtils::matchArg(verbose) + ignoreImputeZero <- mbioUtils::matchArg(ignoreImputeZero) + includeIds <- mbioUtils::matchArg(includeIds) + verbose <- mbioUtils::matchArg(verbose) - dt <- veupathUtils::getCollectionData(object, variableNames = NULL, ignoreImputeZero = ignoreImputeZero, includeIds = includeIds, verbose = verbose) + dt <- mbioUtils::getCollectionData(object, variableNames = NULL, ignoreImputeZero = ignoreImputeZero, includeIds = includeIds, verbose = verbose) return(dt) }) @@ -47,9 +47,9 @@ setGeneric("removeIncompleteSamples", #' @rdname removeIncompleteSamples #' @aliases removeIncompleteSamples,AbundanceData-method setMethod("removeIncompleteSamples", signature("AbundanceData"), function(object, colName = character(), verbose = c(TRUE, FALSE)) { - verbose <- veupathUtils::matchArg(verbose) + verbose <- mbioUtils::matchArg(verbose) - object <- veupathUtils::removeIncompleteRecords(object, colName = colName, verbose = verbose) + object <- mbioUtils::removeIncompleteRecords(object, colName = colName, verbose = verbose) return(object) }) \ No newline at end of file diff --git a/R/methods-Comparator.R b/R/methods-Comparator.R index 5a78046..00aa734 100644 --- a/R/methods-Comparator.R +++ b/R/methods-Comparator.R @@ -15,7 +15,7 @@ setGeneric("getGroupLabels", #' @rdname Comparator-methods #' @aliases getGroupLabels,Comparator-method setMethod("getGroupLabels", signature("Comparator"), function(object, group = c("groupA", "groupB")) { - group <- veupathUtils::matchArg(group) + group <- mbioUtils::matchArg(group) groupBinList <- slot(object, group) diff --git a/R/methods-json.R b/R/methods-json.R index 5e62e04..828eef9 100644 --- a/R/methods-json.R +++ b/R/methods-json.R @@ -1,4 +1,4 @@ -toJSONGeneric <- getGeneric("toJSON", package = "veupathUtils") +toJSONGeneric <- getGeneric("toJSON", package = "mbioUtils") setMethod(toJSONGeneric, signature("DifferentialAbundanceResult"), function(object, ...) { tmp <- character() diff --git a/R/microbiomeComputations-package.R b/R/microbiomeComputations-package.R index 62e3678..3c0b019 100644 --- a/R/microbiomeComputations-package.R +++ b/R/microbiomeComputations-package.R @@ -5,5 +5,5 @@ # roxygen namespace tags. Modify with care! ## usethis namespace: start ## usethis namespace: end -#' @import veupathUtils +#' @import mbioUtils NULL diff --git a/R/utils.R b/R/utils.R index 43da403..6911325 100644 --- a/R/utils.R +++ b/R/utils.R @@ -26,10 +26,10 @@ # } #' @import data.table -#' @import veupathUtils +#' @import mbioUtils rankTaxa <- function(df, method=c('median','max','q3','variance')) { - method <- veupathUtils::matchArg(method) + method <- mbioUtils::matchArg(method) #### Notes: Assume df has rows as samples and at least columns Abundance and TaxonomicLevel if (identical(method, 'median')) { From 2213f87379fd6a8dbcf2ae53646825f92eeb28a1 Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Fri, 21 Nov 2025 09:53:57 -0500 Subject: [PATCH 2/7] update tests for renamed dep --- tests/testthat/test-Comparator.R | 44 ++--- tests/testthat/test-correlation.R | 2 +- tests/testthat/test-differentialAbundance.R | 170 ++++++++++---------- 3 files changed, 108 insertions(+), 108 deletions(-) diff --git a/tests/testthat/test-Comparator.R b/tests/testthat/test-Comparator.R index 52cddff..72b57cc 100644 --- a/tests/testthat/test-Comparator.R +++ b/tests/testthat/test-Comparator.R @@ -1,15 +1,15 @@ test_that('Comparator validation works', { - groupABinList <- veupathUtils::BinList( + groupABinList <- mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_a" )) ) ) - groupBBinList <- veupathUtils::BinList( + groupBBinList <- mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_b" )) ) @@ -18,24 +18,24 @@ test_that('Comparator validation works', { # Ensure Comparator has a variableId expect_error(microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( - dataShape = veupathUtils::DataShape(value="BINARY") + variable = mbioUtils::VariableMetadata( + dataShape = mbioUtils::DataShape(value="BINARY") ), groupA = groupABinList, groupB = groupBBinList )) # Ensure Comparator has no overlap in groupA and groupB - groupBBinList <- veupathUtils::BinList( + groupBBinList <- mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_a" )) ) ) expect_error(microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( - dataShape = veupathUtils::DataShape(value="BINARY") + variable = mbioUtils::VariableMetadata( + dataShape = mbioUtils::DataShape(value="BINARY") ), groupA = groupABinList, groupB = groupBBinList @@ -43,8 +43,8 @@ test_that('Comparator validation works', { # Ensure Comparator requires bin starts and ends when variable is continuous expect_error(microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( - dataShape = veupathUtils::DataShape(value="CONTINUOUS") + variable = mbioUtils::VariableMetadata( + dataShape = mbioUtils::DataShape(value="CONTINUOUS") ), groupA = groupABinList, groupB = groupBBinList @@ -52,8 +52,8 @@ test_that('Comparator validation works', { # Ensure Comparator requires both groupA and groupB expect_error(microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( - dataShape = veupathUtils::DataShape(value="CONTINUOUS") + variable = mbioUtils::VariableMetadata( + dataShape = mbioUtils::DataShape(value="CONTINUOUS") ), groupA = groupABinList )) @@ -63,21 +63,21 @@ test_that('Comparator validation works', { test_that("getGroupLabels returns bin labels", { # With a continuous variable - bin1 <- veupathUtils::Bin(binStart='2', binEnd='3', binLabel="[2, 3)") - bin2 <- veupathUtils::Bin(binStart='3', binEnd='4', binLabel="[3, 4)") - bin3 <- veupathUtils::Bin(binStart='4', binEnd='5', binLabel="[4, 5)") - bin4 <- veupathUtils::Bin(binStart='5', binEnd='6', binLabel="[5, 6)") + bin1 <- mbioUtils::Bin(binStart='2', binEnd='3', binLabel="[2, 3)") + bin2 <- mbioUtils::Bin(binStart='3', binEnd='4', binLabel="[3, 4)") + bin3 <- mbioUtils::Bin(binStart='4', binEnd='5', binLabel="[4, 5)") + bin4 <- mbioUtils::Bin(binStart='5', binEnd='6', binLabel="[5, 6)") - groupABins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) - groupBBins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin3, bin4))) + groupABins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) + groupBBins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin3, bin4))) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'contA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CONTINUOUS") + dataShape = mbioUtils::DataShape(value="CONTINUOUS") ), groupA = groupABins, groupB = groupBBins diff --git a/tests/testthat/test-correlation.R b/tests/testthat/test-correlation.R index 76ca75a..4c31bcb 100644 --- a/tests/testthat/test-correlation.R +++ b/tests/testthat/test-correlation.R @@ -14,7 +14,7 @@ test_that("correlation returns an appropriately structured result for assay agai df <- df[, c("entity.SampleID", keepCols), with = FALSE] nSamples <- dim(df)[1] - sampleMetadata <- veupathUtils::SampleMetadata( + sampleMetadata <- mbioUtils::SampleMetadata( data = data.frame(list( "entity.SampleID" = df[["entity.SampleID"]], "entity.contA" = rnorm(nSamples), diff --git a/tests/testthat/test-differentialAbundance.R b/tests/testthat/test-differentialAbundance.R index bf3eb26..55c1c3c 100644 --- a/tests/testthat/test-differentialAbundance.R +++ b/tests/testthat/test-differentialAbundance.R @@ -33,23 +33,23 @@ test_that('internalDiffAbund returns a correctly formatted data.table', { # A Binary comparator variable comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'binA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="BINARY") + dataShape = mbioUtils::DataShape(value="BINARY") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_a" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_b" )) ) @@ -71,23 +71,23 @@ test_that('internalDiffAbund returns a correctly formatted data.table', { # When defined groups end up subsetting the incoming data comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'cat4', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CATEGORICAL") + dataShape = mbioUtils::DataShape(value="CATEGORICAL") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="cat4_a" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="cat4_b" )) ) @@ -108,21 +108,21 @@ test_that('internalDiffAbund returns a correctly formatted data.table', { # With a continuous variable - bin1 <- veupathUtils::Bin(binStart='2', binEnd='3', binLabel="[2, 3)") - bin2 <- veupathUtils::Bin(binStart='3', binEnd='4', binLabel="[3, 4)") - bin3 <- veupathUtils::Bin(binStart='4', binEnd='5', binLabel="[4, 5)") - bin4 <- veupathUtils::Bin(binStart='5', binEnd='6', binLabel="[5, 6)") + bin1 <- mbioUtils::Bin(binStart='2', binEnd='3', binLabel="[2, 3)") + bin2 <- mbioUtils::Bin(binStart='3', binEnd='4', binLabel="[3, 4)") + bin3 <- mbioUtils::Bin(binStart='4', binEnd='5', binLabel="[4, 5)") + bin4 <- mbioUtils::Bin(binStart='5', binEnd='6', binLabel="[5, 6)") - groupABins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) - groupBBins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin3, bin4))) + groupABins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) + groupBBins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin3, bin4))) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'contA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CONTINUOUS") + dataShape = mbioUtils::DataShape(value="CONTINUOUS") ), groupA = groupABins, groupB = groupBBins @@ -148,12 +148,12 @@ test_that('internalDiffAbund returns a correctly formatted data.table', { groupBBins <- BinList(S4Vectors::SimpleList(c(bin3, bin4))) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'dateA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CONTINUOUS") + dataShape = mbioUtils::DataShape(value="CONTINUOUS") ), groupA = groupABins, groupB = groupBBins @@ -206,27 +206,27 @@ test_that("internalDiffAbund can handle messy inputs", { # With only some comparisonVariable values found in the metadata comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'cat4', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CATEGORICAL") + dataShape = mbioUtils::DataShape(value="CATEGORICAL") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="cat4_a" - ), veupathUtils::Bin( + ), mbioUtils::Bin( binLabel="cat4_c" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="cat4_b" - ), veupathUtils::Bin( + ), mbioUtils::Bin( binLabel="test" )) ) @@ -247,21 +247,21 @@ test_that("internalDiffAbund can handle messy inputs", { # With a continuous variable that has NAs - bin1 <- veupathUtils::Bin(binStart='2', binEnd='3', binLabel="[2, 3)") - bin2 <- veupathUtils::Bin(binStart='3', binEnd='4', binLabel="[3, 4)") - bin3 <- veupathUtils::Bin(binStart='4', binEnd='5', binLabel="[4, 5)") - bin4 <- veupathUtils::Bin(binStart='5', binEnd='6', binLabel="[5, 6)") + bin1 <- mbioUtils::Bin(binStart='2', binEnd='3', binLabel="[2, 3)") + bin2 <- mbioUtils::Bin(binStart='3', binEnd='4', binLabel="[3, 4)") + bin3 <- mbioUtils::Bin(binStart='4', binEnd='5', binLabel="[4, 5)") + bin4 <- mbioUtils::Bin(binStart='5', binEnd='6', binLabel="[5, 6)") - groupABins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) - groupBBins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin3, bin4))) + groupABins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) + groupBBins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin3, bin4))) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'contA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CONTINUOUS") + dataShape = mbioUtils::DataShape(value="CONTINUOUS") ), groupA = groupABins, groupB = groupBBins @@ -280,20 +280,20 @@ test_that("internalDiffAbund can handle messy inputs", { # With a categorical variable that has NAs - bin1 <- veupathUtils::Bin(binLabel="cat4_a") - bin2 <- veupathUtils::Bin(binLabel="cat4_b") - bin3 <- veupathUtils::Bin(binLabel="cat4_c") + bin1 <- mbioUtils::Bin(binLabel="cat4_a") + bin2 <- mbioUtils::Bin(binLabel="cat4_b") + bin3 <- mbioUtils::Bin(binLabel="cat4_c") - groupABins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) - groupBBins <- veupathUtils::BinList(S4Vectors::SimpleList(c(bin3))) + groupABins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin1, bin2))) + groupBBins <- mbioUtils::BinList(S4Vectors::SimpleList(c(bin3))) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'cat4', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CATEGORICAL") + dataShape = mbioUtils::DataShape(value="CATEGORICAL") ), groupA = groupABins, groupB = groupBBins @@ -342,23 +342,23 @@ test_that("internalDiffAbund returns a ComputeResult with the correct slots" , { recordIdColumn = 'entity.SampleID') comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'binA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="BINARY") + dataShape = mbioUtils::DataShape(value="BINARY") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_a" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_b" )) ) @@ -403,19 +403,19 @@ test_that("internalDiffAbund fails with improper inputs", { # Fail when bins in Group A and Group B overlap - bin1 <- veupathUtils::Bin(binStart=2, binEnd=3, binLabel="[2, 3)") - bin2 <- veupathUtils::Bin(binStart=3, binEnd=4, binLabel="[3, 4)") - bin3 <- veupathUtils::Bin(binStart=3, binEnd=5, binLabel="[3, 5)") - bin4 <- veupathUtils::Bin(binStart=5, binEnd=6, binLabel="[5, 6)") + bin1 <- mbioUtils::Bin(binStart=2, binEnd=3, binLabel="[2, 3)") + bin2 <- mbioUtils::Bin(binStart=3, binEnd=4, binLabel="[3, 4)") + bin3 <- mbioUtils::Bin(binStart=3, binEnd=5, binLabel="[3, 5)") + bin4 <- mbioUtils::Bin(binStart=5, binEnd=6, binLabel="[5, 6)") groupABins <- BinList(S4Vectors::SimpleList(c(bin1, bin2))) groupBBins <- BinList(S4Vectors::SimpleList(c(bin3, bin4))) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'contA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CONTINUOUS") + dataShape = mbioUtils::DataShape(value="CONTINUOUS") ), groupA = groupABins, groupB = groupBBins @@ -444,23 +444,23 @@ test_that("internalDiffAbund catches DESeq2 errors", { ) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'binA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="BINARY") + dataShape = mbioUtils::DataShape(value="BINARY") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_a" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_b" )) ) @@ -515,23 +515,23 @@ test_that("internalDiffAbund method Maaslin2 does stuff",{ ) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'cat4', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CATEGORICAL") + dataShape = mbioUtils::DataShape(value="CATEGORICAL") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="cat4_a" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="cat4_b" )) ) @@ -586,23 +586,23 @@ test_that("toJSON for internalDiffAbundResult works",{ ) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'binA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="CATEGORICAL") + dataShape = mbioUtils::DataShape(value="CATEGORICAL") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_a" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_b" )) ) @@ -654,23 +654,23 @@ test_that("The smallest pvalue we can get is our p value floor", { # A Binary comparator variable comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'binA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="BINARY") + dataShape = mbioUtils::DataShape(value="BINARY") ), - groupA = veupathUtils::BinList( + groupA = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_a" )) ) ), - groupB = veupathUtils::BinList( + groupB = mbioUtils::BinList( S4Vectors::SimpleList( - c(veupathUtils::Bin( + c(mbioUtils::Bin( binLabel="binA_b" )) ) @@ -723,15 +723,15 @@ test_that("internalDiffAbund fails if comparator has one value", { ) comparatorVariable <- microbiomeComputations::Comparator( - variable = veupathUtils::VariableMetadata( + variable = mbioUtils::VariableMetadata( variableSpec = VariableSpec( variableId = 'binA', entityId = 'entity' ), - dataShape = veupathUtils::DataShape(value="BINARY") + dataShape = mbioUtils::DataShape(value="BINARY") ), - groupA = veupathUtils::BinList(S4Vectors::SimpleList(c(veupathUtils::Bin(binLabel="binA")))), - groupB = veupathUtils::BinList(S4Vectors::SimpleList(c(veupathUtils::Bin(binLabel="binB")))) + groupA = mbioUtils::BinList(S4Vectors::SimpleList(c(mbioUtils::Bin(binLabel="binA")))), + groupB = mbioUtils::BinList(S4Vectors::SimpleList(c(mbioUtils::Bin(binLabel="binB")))) ) expect_error(internalDiffAbund(testData, comparator=comparatorVariable, method='DESeq2', verbose=F)) From 02feddf1057c930ee88004c1671d38237d25c25d Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Fri, 21 Nov 2025 09:54:07 -0500 Subject: [PATCH 3/7] update docs --- DESCRIPTION | 12 +++++++----- NAMESPACE | 6 +++--- man/selfCorrelation-methods.Rd | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cd47385..28513ae 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: microbiomeComputations Title: Compute Results for Microbiome Analyses -Version: 5.1.6 +Version: 5.1.7 Authors@R: c(person(given = "Danielle", family = "Callan", @@ -20,14 +20,16 @@ Imports: purrr, Rcpp (>= 0.11.0), S4Vectors, - SpiecEasi, + SpiecEasi (>= 1.0.7), stringi, vegan, - veupathUtils (>= 2.7.0) + mbioUtils (>= 0.1.0) Depends: R (>= 2.10) Remotes: - VEuPathDB/veupathUtils + microbiomeDB/mbioUtils, + zdk123/SpiecEasi@v1.0.7, + bioc::Maaslin2 LinkingTo: Rcpp URL: https://github.com/microbiomeDB/microbiomeComputations, https://microbiomedb.github.io/microbiomeComputations/ BugReports: https://github.com/microbiomeDB/microbiomeComputations/issues @@ -36,7 +38,7 @@ License: Apache License (>= 2) Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.3 Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 586f7a8..67bd822 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,12 +18,14 @@ exportClasses(DifferentialAbundanceResult) exportMethods(selfCorrelation) import(DESeq2) import(data.table) +import(mbioUtils) import(methods) -import(veupathUtils) importFrom(Maaslin2,Maaslin2) importFrom(Rcpp,sourceCpp) importFrom(S4Vectors,SimpleList) importFrom(ape,pcoa) +importFrom(mbioUtils,CollectionWithMetadata) +importFrom(mbioUtils,SampleMetadata) importFrom(methods,new) importFrom(methods,slot) importFrom(methods,validObject) @@ -38,6 +40,4 @@ importFrom(stringi,stri_replace_all_fixed) importFrom(stringi,stri_trans_totitle) importFrom(vegan,diversity) importFrom(vegan,vegdist) -importFrom(veupathUtils,CollectionWithMetadata) -importFrom(veupathUtils,SampleMetadata) useDynLib(microbiomeComputations) diff --git a/man/selfCorrelation-methods.Rd b/man/selfCorrelation-methods.Rd index 74408af..abc7fad 100644 --- a/man/selfCorrelation-methods.Rd +++ b/man/selfCorrelation-methods.Rd @@ -34,5 +34,5 @@ ComputeResult object } \description{ This function returns correlation coefficients for variables in one AbundanceData object against itself. It generally serves as a -convenience wrapper around veupathUtils::correlation, with the exception that it additionally supports sparcc. +convenience wrapper around mbioUtils::correlation, with the exception that it additionally supports sparcc. } From 980ef74da08761bb91d7f2d1a278fcea6ec1ae85 Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Fri, 21 Nov 2025 10:03:19 -0500 Subject: [PATCH 4/7] clarify deps --- DESCRIPTION | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 28513ae..992ca2a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,9 +27,7 @@ Imports: Depends: R (>= 2.10) Remotes: - microbiomeDB/mbioUtils, - zdk123/SpiecEasi@v1.0.7, - bioc::Maaslin2 + microbiomeDB/mbioUtils LinkingTo: Rcpp URL: https://github.com/microbiomeDB/microbiomeComputations, https://microbiomedb.github.io/microbiomeComputations/ BugReports: https://github.com/microbiomeDB/microbiomeComputations/issues From cd9e5748e6350cc9c588d6cceb3e7fe724f5ebe3 Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Fri, 21 Nov 2025 10:19:11 -0500 Subject: [PATCH 5/7] clarify deps --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 992ca2a..55a2df6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,9 @@ Imports: Depends: R (>= 2.10) Remotes: - microbiomeDB/mbioUtils + microbiomeDB/mbioUtils, + zdk123/SpiecEasi@v1.0.7 +biocViews: LinkingTo: Rcpp URL: https://github.com/microbiomeDB/microbiomeComputations, https://microbiomedb.github.io/microbiomeComputations/ BugReports: https://github.com/microbiomeDB/microbiomeComputations/issues From c17fd40791b62cbd22b53c9616fb1557525a45bb Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Fri, 21 Nov 2025 10:43:18 -0500 Subject: [PATCH 6/7] for now guarantee deps in gh actions manually --- .github/workflows/R-CMD-check.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 14159b7..bff08d8 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -39,6 +39,12 @@ jobs: http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true + - name: Install Bioconductor packages + run: | + if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") + BiocManager::install(c("Maaslin2", "DESeq2", "S4Vectors"), ask = FALSE, update = FALSE) + shell: Rscript {0} + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::rcmdcheck From 92532ba5104a40d47b7c3e022eda62b136505a89 Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Fri, 21 Nov 2025 11:14:56 -0500 Subject: [PATCH 7/7] see if maaslin will install from gh --- .github/workflows/R-CMD-check.yaml | 6 +++--- README.md | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index bff08d8..509c91d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -39,10 +39,10 @@ jobs: http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - name: Install Bioconductor packages + - name: Install Maaslin2 from GitHub run: | - if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") - BiocManager::install(c("Maaslin2", "DESeq2", "S4Vectors"), ask = FALSE, update = FALSE) + if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes") + remotes::install_github("biobakery/Maaslin2") shell: Rscript {0} - uses: r-lib/actions/setup-r-dependencies@v2 diff --git a/README.md b/README.md index 9e9aeba..788d305 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,21 @@ Use the R package [remotes](https://cran.r-project.org/web/packages/remotes/inde remotes::install_github('microbiomeDB/microbiomeComputations') ``` +### Note on Maaslin2 Installation + +The `Maaslin2` package from Bioconductor may not have pre-compiled binaries available for all platforms (particularly ARM64 macOS). If you encounter installation issues, you can install it from source: + +```R +if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") +BiocManager::install("Maaslin2", type = "source") +``` + +Alternatively, you can install the development version directly from GitHub: + +```R +remotes::install_github("biobakery/Maaslin2") +``` + ## Usage ``` # df is a data frame of abundance values with samples as rows. One column should hold the sample id, all other columns are assumed to be taxa