Skip to content

Commit

Permalink
Merge pull request #93 from jasenfinch/devel
Browse files Browse the repository at this point in the history
v0.15.2
  • Loading branch information
jasenfinch committed Aug 14, 2023
2 parents 1020689 + ef69040 commit 20a96f5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion 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/
Expand Down
6 changes: 6 additions & 0 deletions 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.
Expand Down
5 changes: 0 additions & 5 deletions R/randomForest-permute.R
@@ -1,4 +1,3 @@
nPerm <- function(n,k){choose(n,k) * factorial(k)}

#' @importFrom stats runif

Expand Down Expand Up @@ -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,
Expand Down
24 changes: 17 additions & 7 deletions R/transform.R
Expand Up @@ -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 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.
Expand Down Expand Up @@ -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 * median(tics)
}

dat(d) <- normalised_data %>%
as_tibble()

return(d)
}
)
Expand Down
6 changes: 4 additions & 2 deletions man/transform.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vignettes/quick_start.Rmd
Expand Up @@ -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}
Expand Down

0 comments on commit 20a96f5

Please sign in to comment.