diff --git a/DESCRIPTION b/DESCRIPTION index c757faf3d..e19ec6b91 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mia Type: Package -Version: 1.13.19 +Version: 1.13.20 Authors@R: c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"), email = "felix.gm.ernst@outlook.com", diff --git a/NEWS b/NEWS index a391b392a..adc135ddc 100644 --- a/NEWS +++ b/NEWS @@ -136,3 +136,4 @@ Changes in version 1.13.x + Fix bug in mergeFeaturesByPrevalence + new aliases calculateDPCoA to getDPCoA, calculateNMDS to getNMDS, calculateRDA to getRDA, calculateCCA to getCCA ++ add informative error message in rarefyAssay on assays with strictly-negative values \ No newline at end of file diff --git a/R/rarefyAssay.R b/R/rarefyAssay.R index 934e35935..08a9428d0 100644 --- a/R/rarefyAssay.R +++ b/R/rarefyAssay.R @@ -106,32 +106,39 @@ setMethod("rarefyAssay", signature = c(x = "SummarizedExperiment"), .check_assay_present(assay.type, x) if(any(assay(x, assay.type) %% 1 != 0)){ warning("assay contains non-integer values. Only counts table ", - "is applicable...") + "is applicable...", call. = FALSE) + } + if(any(assay(x, assay.type) < 0)){ + stop("assay contains strictly-negative values. Only counts ", + "table is applicable...", call. = FALSE) } if(!is.logical(verbose)){ - stop("`verbose` has to be logical i.e. TRUE or FALSE") + stop("`verbose` has to be logical i.e. TRUE or FALSE", + call. = FALSE) } if(!is.logical(replace)){ - stop("`replace` has to be logical i.e. TRUE or FALSE") + stop("`replace` has to be logical i.e. TRUE or FALSE", + call. = FALSE) } # Check name if(!.is_non_empty_string(name) || name == assay.type){ stop("'name' must be a non-empty single character value and be ", - "different from `assay.type`.", - call. = FALSE) + "different from `assay.type`.", + call. = FALSE) } #set.seed(seed) # Make sure min_size is of length 1. if(length(min_size) > 1){ stop("`min_size` had more than one value. ", - "Specifiy a single integer value.") + "Specify a single integer value.", call. = FALSE) min_size <- min_size[1] } if(!is.numeric(min_size) || as.integer(min_size) != min_size && min_size <= 0){ - stop("min_size needs to be a positive integer value.") + stop("min_size needs to be a positive integer value.", + call. = FALSE) } # get samples with less than min number of reads if(min(colSums2(assay(x, assay.type))) < min_size){ @@ -139,7 +146,7 @@ setMethod("rarefyAssay", signature = c(x = "SummarizedExperiment"), # Return NULL, if no samples were found after subsampling if( !any(!colnames(x) %in% rmsams) ){ stop("No samples were found after subsampling.", - call. = FALSE) + call. = FALSE) } if(verbose){ message(length(rmsams), " samples removed ", @@ -168,7 +175,6 @@ setMethod("rarefyAssay", signature = c(x = "SummarizedExperiment"), } ) - ## Modified Sub sampling function from phyloseq internals .subsample_assay <- function(x, min_size, replace){ # Create replacement species vector