Browse code

Default pseudocount half of the minimum value (#613)

Tuomas Borman authored on 21/07/2024 08:36:17 • GitHub committed on 21/07/2024 08:36:17
Showing 3 changed files

... ...
@@ -27,7 +27,7 @@
27 27
 #'   abundance table.
28 28
 #' 
29 29
 #' @param pseudocount TRUE, FALSE, or a numeric value. When TRUE,
30
-#'   automatically adds the minimum positive value of \code{assay.type}.
30
+#'   automatically adds half of the minimum positive value of \code{assay.type}.
31 31
 #'   When FALSE, does not add any pseudocount (pseudocount = 0).
32 32
 #'   Alternatively, a user-specified numeric value can be added as pseudocount.
33 33
 #'
... ...
@@ -40,10 +40,9 @@
40 40
 #' }
41 41
 #' @details
42 42
 #'
43
-#' These \code{transformCount} function provides a variety of options for transforming abundance data.
44
-#' The transformed data is calculated and stored in a new \code{assay}. The previously available
45
-#' wrappers transformSamples, transformFeatures
46
-#' ZTransform, and relAbundanceCounts have been deprecated.
43
+#' \code{transformAssay} function provides a variety of options for
44
+#' transforming abundance data. The transformed data is calculated and stored
45
+#' in a new \code{assay}.
47 46
 #'
48 47
 #' The \code{transformAssay} provides sample-wise (column-wise) or feature-wise
49 48
 #' (row-wise) transformation to the abundance table
... ...
@@ -377,13 +376,11 @@ setMethod("transformAssay", signature = c(x = "SummarizedExperiment"),
377 376
             stop("The assay contains missing or negative values. ",
378 377
                  "'pseudocount' must be specified manually.", call. = FALSE)
379 378
         }
380
-        # If pseudocount TRUE, set it to
381
-        # a) counts: non-zero minimum value
382
-        # b) non-integers: half of non-zero minimum value
379
+        # If pseudocount TRUE, set it to  half of non-zero minimum value
383 380
         # else set it to zero.
384 381
         # Get min value
385 382
         value <- min(mat[mat>0])
386
-        value <- ifelse(all(mat %% 1 == 0), value, value / 2)
383
+        value <- value/2
387 384
         pseudocount <- ifelse(pseudocount, value, 0)
388 385
         # Report pseudocount if positive value
389 386
         if ( pseudocount > 0 ){
... ...
@@ -393,13 +390,16 @@ setMethod("transformAssay", signature = c(x = "SummarizedExperiment"),
393 390
     # Give warning if pseudocount should not be added
394 391
     # Case 1: only positive values
395 392
     if( pseudocount != 0 && all(mat > 0, na.rm = TRUE) ){
396
-        warning("The assay contains only positive values. ",
397
-                "Applying a pseudocount may be unnecessary.", call. = FALSE)
393
+        warning(
394
+            "The assay contains only positive values. ",
395
+            "Applying a pseudocount may be unnecessary.", call. = FALSE)
398 396
     }
399 397
     # Case 2: some negative values
400 398
     if( pseudocount != 0 && any(mat < 0, na.rm = TRUE) ){
401
-        warning("The assay contains some negative values. ",
402
-                "Applying a pseudocount may produce meaningless data.", call. = FALSE)
399
+        warning(
400
+            "The assay contains some negative values. ",
401
+            "Applying a pseudocount may produce meaningless data.",
402
+            call. = FALSE)
403 403
     }
404 404
     # Add pseudocount
405 405
     mat <- mat + pseudocount
... ...
@@ -56,7 +56,7 @@ transformation is applied sample (column) or feature (row) wise.
56 56
 abundance table.}
57 57
 
58 58
 \item{pseudocount}{TRUE, FALSE, or a numeric value. When TRUE,
59
-automatically adds the minimum positive value of \code{assay.type}.
59
+automatically adds half of the minimum positive value of \code{assay.type}.
60 60
 When FALSE, does not add any pseudocount (pseudocount = 0).
61 61
 Alternatively, a user-specified numeric value can be added as pseudocount.}
62 62
 
... ...
@@ -77,10 +77,9 @@ Variety of transformations for abundance data, stored in \code{assay}.
77 77
 See details for options.
78 78
 }
79 79
 \details{
80
-These \code{transformCount} function provides a variety of options for transforming abundance data.
81
-The transformed data is calculated and stored in a new \code{assay}. The previously available
82
-wrappers transformSamples, transformFeatures
83
-ZTransform, and relAbundanceCounts have been deprecated.
80
+\code{transformAssay} function provides a variety of options for
81
+transforming abundance data. The transformed data is calculated and stored
82
+in a new \code{assay}.
84 83
 
85 84
 The \code{transformAssay} provides sample-wise (column-wise) or feature-wise
86 85
 (row-wise) transformation to the abundance table
... ...
@@ -210,12 +210,14 @@ test_that("transformAssay", {
210 210
         expect_equal(assay(tse, "rel_pseudo1"), assay(tse, "rel_pseudo2"),
211 211
                      check.attributes = FALSE)
212 212
         
213
-        # Check that pseudocount = TRUE is the same as pseudocount = min
213
+        # Check that pseudocount = TRUE is the same as pseudocount = half of
214
+        # the minimum value
214 215
         # and pseudocount = FALSE is the same as pseudocount = 0
215 216
         tse <- transformAssay(tse, method = "relabundance", pseudocount = TRUE, name = "pseudo_true")
217
+        pseudocount <- (min(assay(tse, "counts")[assay(tse, "counts") > 0])) / 2
216 218
         tse <- transformAssay(
217 219
             tse, method = "relabundance", name = "pseudo_min",
218
-            pseudocount = (min(assay(tse, "counts")[assay(tse, "counts") > 0])),
220
+            pseudocount = pseudocount,
219 221
         )
220 222
         tse <- transformAssay(tse, method = "relabundance", pseudocount = FALSE, name = "pseudo_false")
221 223
         tse <- transformAssay(tse, method = "relabundance", pseudocount = 0, name = "pseudo_zero")