From 45e387951561467764b334689629ac0199f5bdbe Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Tue, 13 Jun 2023 14:57:08 +0100 Subject: [PATCH 1/6] Remove permutation cap --- R/randomForest-permute.R | 5 ----- 1 file changed, 5 deletions(-) diff --git a/R/randomForest-permute.R b/R/randomForest-permute.R index c86b3e8..39f2635 100644 --- a/R/randomForest-permute.R +++ b/R/randomForest-permute.R @@ -1,4 +1,3 @@ -nPerm <- function(n,k){choose(n,k) * factorial(k)} #' @importFrom stats runif @@ -35,10 +34,6 @@ permutations <- function(x,cls,rf,n,type){ i <- factor(i) } - if (nPerm(length(i),length(unique(i))) < n) { - n <- nPerm(length(i),length(unique(i))) - } - permutation_results <- future_map(1:n, ~permute(x = x, cls = cls, From b12735fa544cf2ccc744ae481b19e5c734a0ee04 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Wed, 14 Jun 2023 12:27:36 +0100 Subject: [PATCH 2/6] bump version to 0.15.2 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e4831be..3478eb9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: metabolyseR Title: Methods for Pre-Treatment, Data Mining and Correlation Analyses of Metabolomics Data -Version: 0.15.1 +Version: 0.15.2 Authors@R: person("Jasen", "Finch", email = "jsf9@aber.ac.uk", role = c("aut", "cre")) Description: A tool kit for pre-treatment, modelling, feature selection and correlation analyses of metabolomics data. URL: https://jasenfinch.github.io/metabolyseR/ From 12d5529e52c61aa1f06af41bf219612ff80c298d Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Wed, 9 Aug 2023 16:00:06 +0100 Subject: [PATCH 3/6] Enable refactoring of TIC normalised feature intensities by multiplying by the maximum TIC --- R/transform.R | 24 +++++++++++++++++------- man/transform.Rd | 6 ++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/R/transform.R b/R/transform.R index 434fc2b..1e99ff3 100644 --- a/R/transform.R +++ b/R/transform.R @@ -3,6 +3,7 @@ #' @description Methods for data scaling, transformation and normalisation. #' @param d S4 object of class `AnalysisData` #' @param add value to add prior to transformation +#' @param refactor TRUE/FALSE. Re-factor the normalised intensity values to a range consistent with the raw values by multiplying by the maximum sample TIC. #' @return An S4 object of class `AnalysisData` containing the transformed data. #' @details #' Prior to downstream analyses, metabolomics data often require transformation to fulfil the assumptions of a particular statistical/data mining technique. @@ -237,19 +238,28 @@ setMethod('transformSQRT',signature = 'AnalysisData', #' @rdname transform #' @export -setGeneric("transformTICnorm", function(d) +setGeneric("transformTICnorm", function(d,refactor = TRUE) standardGeneric("transformTICnorm")) #' @rdname transform setMethod('transformTICnorm',signature = 'AnalysisData', - function(d){ - dat(d) <- d %>% - dat() %>% - base::split(seq_len(nrow(.))) %>% - map(~{. / sum(.)}) %>% - bind_rows() %>% + function(d, refactor = TRUE){ + + raw_data <- dat(d) + + tics <- rowSums(raw_data) + + normalised_data <- raw_data %>% + {. / tics} + + if (refactor){ + normalised_data <- normalised_data * max(tics) + } + + dat(d) <- normalised_data %>% as_tibble() + return(d) } ) diff --git a/man/transform.Rd b/man/transform.Rd index e7a9be7..01cab99 100644 --- a/man/transform.Rd +++ b/man/transform.Rd @@ -61,9 +61,9 @@ transformSQRT(d) \S4method{transformSQRT}{AnalysisData}(d) -transformTICnorm(d) +transformTICnorm(d, refactor = TRUE) -\S4method{transformTICnorm}{AnalysisData}(d) +\S4method{transformTICnorm}{AnalysisData}(d, refactor = TRUE) transformVast(d) @@ -73,6 +73,8 @@ transformVast(d) \item{d}{S4 object of class \code{AnalysisData}} \item{add}{value to add prior to transformation} + +\item{refactor}{TRUE/FALSE. Re-factor the normalised intensity values to a range consistent with the raw values by multiplying by the maximum sample TIC.} } \value{ An S4 object of class \code{AnalysisData} containing the transformed data. From 60bd627b8b43ffce9a543c9e0c3fbed804cef303 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Wed, 9 Aug 2023 16:21:43 +0100 Subject: [PATCH 4/6] Add a log10 transformation to the pre-treatment in the quick start analysis --- vignettes/quick_start.Rmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vignettes/quick_start.Rmd b/vignettes/quick_start.Rmd index 790f081..b9f0651 100644 --- a/vignettes/quick_start.Rmd +++ b/vignettes/quick_start.Rmd @@ -70,7 +70,8 @@ A total ion count normalisation will also be applied. ```{r pre_treat} d <- d %>% occupancyMaximum(cls = 'day', occupancy = 2/3) %>% - transformTICnorm() + transformTICnorm() %>% + transformLog10() ``` ```{r pre_treat_result} From 5580369e1c4588cd4e134269aa381421296fb9bb Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Wed, 9 Aug 2023 16:35:15 +0100 Subject: [PATCH 5/6] refactor by the median TIC --- R/transform.R | 4 ++-- man/transform.Rd | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/transform.R b/R/transform.R index 1e99ff3..527f17e 100644 --- a/R/transform.R +++ b/R/transform.R @@ -3,7 +3,7 @@ #' @description Methods for data scaling, transformation and normalisation. #' @param d S4 object of class `AnalysisData` #' @param add value to add prior to transformation -#' @param refactor TRUE/FALSE. Re-factor the normalised intensity values to a range consistent with the raw values by multiplying by the maximum sample TIC. +#' @param refactor TRUE/FALSE. Re-factor the normalised intensity values to a range consistent with the raw values by multiplying by the median sample TIC. #' @return An S4 object of class `AnalysisData` containing the transformed data. #' @details #' Prior to downstream analyses, metabolomics data often require transformation to fulfil the assumptions of a particular statistical/data mining technique. @@ -254,7 +254,7 @@ setMethod('transformTICnorm',signature = 'AnalysisData', {. / tics} if (refactor){ - normalised_data <- normalised_data * max(tics) + normalised_data <- normalised_data * median(tics) } dat(d) <- normalised_data %>% diff --git a/man/transform.Rd b/man/transform.Rd index 01cab99..9922414 100644 --- a/man/transform.Rd +++ b/man/transform.Rd @@ -74,7 +74,7 @@ transformVast(d) \item{add}{value to add prior to transformation} -\item{refactor}{TRUE/FALSE. Re-factor the normalised intensity values to a range consistent with the raw values by multiplying by the maximum sample TIC.} +\item{refactor}{TRUE/FALSE. Re-factor the normalised intensity values to a range consistent with the raw values by multiplying by the median sample TIC.} } \value{ An S4 object of class \code{AnalysisData} containing the transformed data. From ef690408bbafc09b17638e5b5a24d3b837b1dc03 Mon Sep 17 00:00:00 2001 From: jasenfinch Date: Mon, 14 Aug 2023 14:46:22 +0100 Subject: [PATCH 6/6] Update the package NEWS --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index ea059d4..dd64624 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# metabolyseR 0.15.2 + +* Added the argument `refactor` to the method [`transformTICnorm()`](https://jasenfinch.github.io/metabolyseR/reference/transform.html) to enable the feature intensities of total ion count (TIC) normalised data to be refactored back to a range consistent with the original data by multiplying the normalised values by the median TIC. + +* Removed the permutation cap when the `perm` argument of [`randomForest()`](https://jasenfinch.github.io/metabolyseR/reference/randomForest.html) is less than the total number of permutations possible. + # metabolyseR 0.15.1 * The class occupancy methods now throw a helpful error message if no features are available on which to compute class occupancy.