Skip to content

Commit

Permalink
Update documentation and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
johanna0321 committed May 17, 2024
1 parent 21ccf03 commit 3c805e5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(floor_peaks)
export(impute_missing_peaks)
export(is_has_label)
export(lipid_components)
export(median_polish_predict_dilutions)
export(merge_compounds_tbl)
export(merge_samples_tbl)
export(normalize_peaks)
Expand Down
25 changes: 14 additions & 11 deletions R/mutate_mzroll_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,24 +453,26 @@ normalize_peaks_median_polish <- function(mzroll_list,
#' Using `median_polish_scaling_factor` output from `normalize_peaks_median_polish`,
#' predict sample-wise dilutions
#'
#' @details This function performs an inverse-normalization on the scaling factors,
#' @details This function performs an inverse-log transformation on the scaling factors,
#' and scales the samples based on the observed maximum scaling factor. Assumes that
#' median polish is perform on log2 transformed data
#'
#' @param mzroll_list data in triple omic structure
#' @param scaling_factor scaling factor, defaults to `median_polish_scaling_factor`
#' and must be a `samples` column in `mzroll_list`
#' @param norm_scale_varname variable in samples to add for dilution predictions
#' @param group_var optional grouping variable on which to calculate maximum dilution
#' @param group_var optional grouping variable on which to calculate maximum dilution,
#' must be a `samples` column in `mzroll_list`
#'
#' @return a \code{mzroll_list} with \code{norm_scale_varname} variable added to
#' samples
#'
#' @export
median_polish_predict_dilutions <- function (mzroll_list,
scaling_factor = "median_polish_scaling_factor",
norm_scale_varname = "median_polish_predicted_dilutions",
group_vars = NULL) {
median_polish_predict_dilutions <- function(mzroll_list,
scaling_factor = "median_polish_scaling_factor",
norm_scale_varname = "median_polish_predicted_dilutions",
group_vars = NULL) {

test_mzroll_list(mzroll_list)

checkmate::assertString(scaling_factor)
Expand All @@ -487,21 +489,22 @@ median_polish_predict_dilutions <- function (mzroll_list,
dplyr::mutate(temp_scaling_factor = !!rlang::sym(scaling_factor)) %>%
dplyr::mutate(inverse_log_scaling_factor = 2^temp_scaling_factor)

if(!is.null(group_var) && any(group_vars %in% colnames(mzroll_list$samples))) {
if(!is.null(group_vars) && any(group_vars %in% colnames(mzroll_list$samples))) {

updated_samples <- updated_samples %>%
dplyr::group_by(group_vars) %>%
dplyr::mutate(m = max(inverse_log_scaling_factor)) %>%
dplyr::ungroup()
dplyr::group_by_at(group_vars) %>%
dplyr::mutate(m = max(inverse_log_scaling_factor))

} else {

max_temp <- max(updated_samples$inverse_log_scaling_factor, na.rm = T)
updated_samples <- updated_samples %>%
dplyr::mutate(m = max(inverse_log_scaling_factor))
dplyr::mutate(m = .env$max_temp)

}

updated_samples <- updated_samples %>%
dplyr::ungroup() %>%
dplyr::rowwise() %>%
dplyr::mutate(`:=`(!!rlang::sym(norm_scale_varname),
inverse_log_scaling_factor/m)) %>%
Expand Down
37 changes: 37 additions & 0 deletions man/median_polish_predict_dilutions.Rd

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

4 changes: 3 additions & 1 deletion man/normalize_peaks.Rd

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

0 comments on commit 3c805e5

Please sign in to comment.