Skip to content

Commit

Permalink
extend testing, improve handling of 1 per group
Browse files Browse the repository at this point in the history
  • Loading branch information
wolski committed Jan 10, 2025
1 parent de81c44 commit f2d3976
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
18 changes: 17 additions & 1 deletion R/LFQDataStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#'
#'
#' lfqdata <- LFQData$new(bb$data, bb$config)
#' # LFQDataStats$debug("violin")
#' lfqstats <- lfqdata$get_Stats()
#' stopifnot(ncol(lfqstats$stats_wide()) == 30)
#' lfqstats$violin()
Expand All @@ -58,6 +59,17 @@
#' stopifnot(ncol(lfqstats$stats_wide()) == 20)
#' runallfuncs(lfqstats)
#'
#' # Group size 1
#' bb <- prolfqua::sim_lfq_data_peptide_config(N=1)
#' table_factors_size(bb$data,bb$config )
#' lfqdata <- LFQData$new(bb$data, bb$config)
#' # LFQDataStats$debug("initialize")
#' lfqstats <- lfqdata$get_Stats()
#'
#' # stopifnot(ncol(lfqstats$stats_wide()) == 30)
#' lfqstats$violin()
#' runallfuncs(lfqstats)

LFQDataStats <- R6::R6Class(
"LFQDataStats",
public = list(
Expand All @@ -78,7 +90,11 @@ LFQDataStats <- R6::R6Class(

tb <- table_factors_size(lfqdata$data,lfqdata$config )
if ( all(tb$n == 1) ) {
self$lfq$config$table$factorDepth <- self$lfq$config$table$factorDepth - 1
if(self$lfq$config$table$factorDepth > 1){
self$lfq$config$table$factorDepth <- self$lfq$config$table$factorDepth - 1
} else {
stats = "all"
}
}

if (stats == "interaction" ) {
Expand Down
4 changes: 2 additions & 2 deletions R/simulate_LFQ_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ sim_lfq_data_peptide_config <- function(
Nprot = 10,
with_missing = TRUE,
weight_missing = 0.2,
seed = 1234){
seed = 1234, N = 4){
if (!is.null(seed)) {
set.seed(seed)
}
data <- sim_lfq_data(Nprot = Nprot, PEPTIDE = TRUE)
data <- sim_lfq_data(Nprot = Nprot, PEPTIDE = TRUE, N = N)

not_missing <- !which_missing(data$abundance, weight_missing = weight_missing)
# data <- data[not_missing,]
Expand Down
6 changes: 3 additions & 3 deletions R/tidyMS_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ poolvar <- function(res1, config, method = c("V1","V2")){
#' stopifnot(nrow(stats) == 20)
#' stats <- summarize_stats(res2$data, res2$config, factor_key = NULL)
#' stopifnot(nrow(stats) == 10)
#'
#' # TODO (WEW) add test when there is one level per group.
summarize_stats <- function(pdata, config, factor_key = config$table$factor_keys_depth()){
pdata <- complete_cases(pdata, config)
intsym <- sym(config$table$get_response())
Expand All @@ -193,11 +193,11 @@ summarize_stats <- function(pdata, config, factor_key = config$table$factor_keys
if (config$table$is_response_transformed == FALSE) {
hierarchyFactor <- hierarchyFactor |> dplyr::mutate(CV = sd/meanAbundance * 100)
}
if (is.null(factor_key)) {
if (is.null(factor_key) || length(factor_key) == 0) {
hierarchyFactor <- dplyr::mutate(hierarchyFactor, !!config$table$factor_keys()[1] := "All")
}
hierarchyFactor <- ungroup(hierarchyFactor)
if (!is.null(factor_key)) {
if (length(factor_key) > 0 && !is.null(factor_key)) {
hierarchyFactor <- prolfqua::make_interaction_column(hierarchyFactor, columns = factor_key, sep = ":")
} else{
hierarchyFactor$interaction <- "All"
Expand Down
11 changes: 11 additions & 0 deletions man/LFQDataStats.Rd

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

3 changes: 2 additions & 1 deletion man/sim_lfq_data_peptide_config.Rd

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

2 changes: 1 addition & 1 deletion man/summarize_stats.Rd

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

0 comments on commit f2d3976

Please sign in to comment.