From a79cd7b70d8a59ef9f0d99aa0ff6ebc1939f6a2c Mon Sep 17 00:00:00 2001 From: Witold Wolski Date: Wed, 28 Aug 2024 15:03:35 +0200 Subject: [PATCH] limit factors key depth --- NAMESPACE | 1 + R/AnalysisConfiguration.R | 52 +++++++++++++++++++++++++- R/LFQDataStats.R | 11 +++++- man/AnalysisConfiguration.Rd | 3 +- man/AnalysisParameters.Rd | 3 +- man/AnalysisTableAnnotation.Rd | 3 +- man/INTERNAL_FUNCTIONS_BY_FAMILY.Rd | 3 +- man/R6_extract_values.Rd | 3 +- man/complete_cases.Rd | 3 +- man/concrete_AnalysisConfiguration.Rd | 3 +- man/make_interaction_column.Rd | 3 +- man/make_reduced_hierarchy_config.Rd | 3 +- man/sample_subset.Rd | 3 +- man/separate_factors.Rd | 3 +- man/separate_hierarchy.Rd | 3 +- man/setup_analysis.Rd | 3 +- man/spread_response_by_IsotopeLabel.Rd | 3 +- man/table_factors.Rd | 36 +++++++++++++++++- man/table_factors_size.Rd | 46 +++++++++++++++++++++++ 19 files changed, 170 insertions(+), 18 deletions(-) create mode 100644 man/table_factors_size.Rd diff --git a/NAMESPACE b/NAMESPACE index 5f6f24733..34b1639f1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -169,6 +169,7 @@ export(summarize_stats_quantiles) export(summary_ROPECA_median_p.scaled) export(table_facade) export(table_factors) +export(table_factors_size) export(tidy_to_wide) export(tidy_to_wide_config) export(transform_work_intensity) diff --git a/R/AnalysisConfiguration.R b/R/AnalysisConfiguration.R index 07b3befdc..d1c3ff5ff 100644 --- a/R/AnalysisConfiguration.R +++ b/R/AnalysisConfiguration.R @@ -329,12 +329,62 @@ sample_subset <- function(size, pdata, config){ #' stopifnot(all(xt$n == 4)) #' table_factors <- function(pdata, configuration){ - factorsTab <- pdata |> dplyr::select(c(configuration$table$fileName, configuration$table$sampleName, configuration$table$factor_keys())) |> + factorsTab <- pdata |> + dplyr::select(c(configuration$table$fileName, configuration$table$sampleName, configuration$table$factor_keys())) |> dplyr::distinct() |> arrange(!!sym(configuration$table$sampleName)) return(factorsTab) } +#' Table of distinct factors (sample annotation) +#' @param pdata data.frame +#' @param config AnalysisConfiguration +#' +#' @export +#' @keywords internal +#' @family configuration +#' @examples +#' +#' +#' istar <- sim_lfq_data_peptide_config() +#' +#' +#' xx <- table_factors(istar$data,istar$config ) +#' xx +#' xt <- xx |> dplyr::group_by(!!!rlang::syms(istar$config$table$factor_keys())) |> +#' dplyr::summarize(n = dplyr::n()) +#' xt +#' stopifnot(all(xt$n == 4)) +#' +table_factors <- function(pdata, configuration){ + factorsTab <- pdata |> + dplyr::select(c(configuration$table$fileName, configuration$table$sampleName, configuration$table$factor_keys())) |> + dplyr::distinct() |> + arrange(!!sym(configuration$table$sampleName)) + return(factorsTab) +} + +#' Table of distinct factors (sample annotation) +#' @param pdata data.frame +#' @param config AnalysisConfiguration +#' +#' @export +#' @keywords internal +#' @family configuration +#' @examples +#' +#' +#' istar <- sim_lfq_data_peptide_config() +#' +#' +#' xx <- table_factors_size(istar$data,istar$config ) +#' stopifnot(all(xt$n == 4)) +#' +table_factors_size <- function(pdata, configuration){ + xx <- table_factors(pdata, configuration) + xx <- xx |> dplyr::group_by(dplyr::across(configuration$table$factor_keys_depth())) |> dplyr::summarize(n = dplyr::n()) + return(xx) +} # Functions - summarize hierarchies diff --git a/R/LFQDataStats.R b/R/LFQDataStats.R index 08ff08ffc..195518ec3 100644 --- a/R/LFQDataStats.R +++ b/R/LFQDataStats.R @@ -75,15 +75,22 @@ LFQDataStats <- R6::R6Class( stats <- match.arg(stats) self$lfq = lfqdata self$stat <- if (!self$lfq$is_transformed()) {"CV"} else {"sd"} + + tb <- table_factors_size(lfqdata$data,lfqdata$config ) + fd <- config$table$factor_keys_depth() + if ( all(tb$n == 1) ) { + fd <- head(fd, n = length(fd) - 1) + } + if (stats == "interaction" ) { - self$statsdf <- prolfqua::summarize_stats(self$lfq$data, self$lfq$config) + self$statsdf <- prolfqua::summarize_stats(self$lfq$data, self$lfq$config, factor_key = fd) } else if (stats == "all" ) { self$statsdf <- prolfqua::summarize_stats_all(self$lfq$data, self$lfq$config) } else if (stats == "everything" ) { self$statsdf <- bind_rows( - prolfqua::summarize_stats(self$lfq$data, self$lfq$config), + prolfqua::summarize_stats(self$lfq$data, self$lfq$config, factor_key = fd), prolfqua::summarize_stats_all(self$lfq$data, self$lfq$config) ) } diff --git a/man/AnalysisConfiguration.Rd b/man/AnalysisConfiguration.Rd index 88d9a5d79..0ef04ab9a 100644 --- a/man/AnalysisConfiguration.Rd +++ b/man/AnalysisConfiguration.Rd @@ -21,7 +21,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \section{Public fields}{ diff --git a/man/AnalysisParameters.Rd b/man/AnalysisParameters.Rd index 2b1b8eea1..1399ac9ec 100644 --- a/man/AnalysisParameters.Rd +++ b/man/AnalysisParameters.Rd @@ -21,7 +21,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \section{Public fields}{ diff --git a/man/AnalysisTableAnnotation.Rd b/man/AnalysisTableAnnotation.Rd index 4cc76154c..80f74e166 100644 --- a/man/AnalysisTableAnnotation.Rd +++ b/man/AnalysisTableAnnotation.Rd @@ -35,7 +35,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \section{Public fields}{ diff --git a/man/INTERNAL_FUNCTIONS_BY_FAMILY.Rd b/man/INTERNAL_FUNCTIONS_BY_FAMILY.Rd index 3b556e650..54c3e664f 100644 --- a/man/INTERNAL_FUNCTIONS_BY_FAMILY.Rd +++ b/man/INTERNAL_FUNCTIONS_BY_FAMILY.Rd @@ -43,7 +43,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} Other deprecated: \code{\link{intensity_summary_by_hkeys}()}, diff --git a/man/R6_extract_values.Rd b/man/R6_extract_values.Rd index 1555d17ad..7117e81a0 100644 --- a/man/R6_extract_values.Rd +++ b/man/R6_extract_values.Rd @@ -27,7 +27,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/complete_cases.Rd b/man/complete_cases.Rd index 634a6eab6..962689fe5 100644 --- a/man/complete_cases.Rd +++ b/man/complete_cases.Rd @@ -38,7 +38,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/concrete_AnalysisConfiguration.Rd b/man/concrete_AnalysisConfiguration.Rd index 58cb02eb1..58695163f 100644 --- a/man/concrete_AnalysisConfiguration.Rd +++ b/man/concrete_AnalysisConfiguration.Rd @@ -71,6 +71,7 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} diff --git a/man/make_interaction_column.Rd b/man/make_interaction_column.Rd index f51aa2eb9..f207e9b43 100644 --- a/man/make_interaction_column.Rd +++ b/man/make_interaction_column.Rd @@ -37,7 +37,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/make_reduced_hierarchy_config.Rd b/man/make_reduced_hierarchy_config.Rd index d35f56296..983a9102d 100644 --- a/man/make_reduced_hierarchy_config.Rd +++ b/man/make_reduced_hierarchy_config.Rd @@ -43,7 +43,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/sample_subset.Rd b/man/sample_subset.Rd index f94c4f624..945fcd807 100644 --- a/man/sample_subset.Rd +++ b/man/sample_subset.Rd @@ -31,7 +31,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/separate_factors.Rd b/man/separate_factors.Rd index 357f4ebbd..904d93d16 100644 --- a/man/separate_factors.Rd +++ b/man/separate_factors.Rd @@ -36,7 +36,8 @@ Other configuration: \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/separate_hierarchy.Rd b/man/separate_hierarchy.Rd index 21ccc5ed6..02ea4dc07 100644 --- a/man/separate_hierarchy.Rd +++ b/man/separate_hierarchy.Rd @@ -40,7 +40,8 @@ Other configuration: \code{\link{separate_factors}()}, \code{\link{setup_analysis}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/setup_analysis.Rd b/man/setup_analysis.Rd index b22121606..86c488cfb 100644 --- a/man/setup_analysis.Rd +++ b/man/setup_analysis.Rd @@ -40,7 +40,8 @@ Other configuration: \code{\link{separate_factors}()}, \code{\link{separate_hierarchy}()}, \code{\link{spread_response_by_IsotopeLabel}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/spread_response_by_IsotopeLabel.Rd b/man/spread_response_by_IsotopeLabel.Rd index caa45311e..f8583742e 100644 --- a/man/spread_response_by_IsotopeLabel.Rd +++ b/man/spread_response_by_IsotopeLabel.Rd @@ -42,7 +42,8 @@ Other configuration: \code{\link{separate_factors}()}, \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, -\code{\link{table_factors}()} +\code{\link{table_factors}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/table_factors.Rd b/man/table_factors.Rd index f51243d6c..a750b9dad 100644 --- a/man/table_factors.Rd +++ b/man/table_factors.Rd @@ -4,6 +4,8 @@ \alias{table_factors} \title{Table of distinct factors (sample annotation)} \usage{ +table_factors(pdata, configuration) + table_factors(pdata, configuration) } \arguments{ @@ -12,11 +14,25 @@ table_factors(pdata, configuration) \item{config}{AnalysisConfiguration} } \description{ +Table of distinct factors (sample annotation) + Table of distinct factors (sample annotation) } \examples{ +istar <- sim_lfq_data_peptide_config() + + +xx <- table_factors(istar$data,istar$config ) +xx +xt <- xx |> dplyr::group_by(!!!rlang::syms(istar$config$table$factor_keys())) |> + dplyr::summarize(n = dplyr::n()) +xt +stopifnot(all(xt$n == 4)) + + + istar <- sim_lfq_data_peptide_config() @@ -43,7 +59,25 @@ Other configuration: \code{\link{separate_factors}()}, \code{\link{separate_hierarchy}()}, \code{\link{setup_analysis}()}, -\code{\link{spread_response_by_IsotopeLabel}()} +\code{\link{spread_response_by_IsotopeLabel}()}, +\code{\link{table_factors_size}()} + +Other configuration: +\code{\link{AnalysisConfiguration}}, +\code{\link{AnalysisParameters}}, +\code{\link{AnalysisTableAnnotation}}, +\code{\link{INTERNAL_FUNCTIONS_BY_FAMILY}}, +\code{\link{R6_extract_values}()}, +\code{\link{complete_cases}()}, +\code{\link{concrete_AnalysisConfiguration}}, +\code{\link{make_interaction_column}()}, +\code{\link{make_reduced_hierarchy_config}()}, +\code{\link{sample_subset}()}, +\code{\link{separate_factors}()}, +\code{\link{separate_hierarchy}()}, +\code{\link{setup_analysis}()}, +\code{\link{spread_response_by_IsotopeLabel}()}, +\code{\link{table_factors_size}()} } \concept{configuration} \keyword{internal} diff --git a/man/table_factors_size.Rd b/man/table_factors_size.Rd new file mode 100644 index 000000000..539e5c8ed --- /dev/null +++ b/man/table_factors_size.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AnalysisConfiguration.R +\name{table_factors_size} +\alias{table_factors_size} +\title{Table of distinct factors (sample annotation)} +\usage{ +table_factors_size(pdata, configuration) +} +\arguments{ +\item{pdata}{data.frame} + +\item{config}{AnalysisConfiguration} +} +\description{ +Table of distinct factors (sample annotation) +} +\examples{ + + +istar <- sim_lfq_data_peptide_config() + + +xx <- table_factors_size(istar$data,istar$config ) +stopifnot(all(xt$n == 4)) + +} +\seealso{ +Other configuration: +\code{\link{AnalysisConfiguration}}, +\code{\link{AnalysisParameters}}, +\code{\link{AnalysisTableAnnotation}}, +\code{\link{INTERNAL_FUNCTIONS_BY_FAMILY}}, +\code{\link{R6_extract_values}()}, +\code{\link{complete_cases}()}, +\code{\link{concrete_AnalysisConfiguration}}, +\code{\link{make_interaction_column}()}, +\code{\link{make_reduced_hierarchy_config}()}, +\code{\link{sample_subset}()}, +\code{\link{separate_factors}()}, +\code{\link{separate_hierarchy}()}, +\code{\link{setup_analysis}()}, +\code{\link{spread_response_by_IsotopeLabel}()}, +\code{\link{table_factors}()} +} +\concept{configuration} +\keyword{internal}