diff --git a/NAMESPACE b/NAMESPACE index 69ed7b847..2f54503e5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -157,6 +157,7 @@ export(separate_hierarchy) export(setup_analysis) export(sim_lfq_data) export(sim_lfq_data_peptide_config) +export(sim_lfq_data_protein_2Factor_config) export(sim_lfq_data_protein_config) export(spread_response_by_IsotopeLabel) export(squeezeVarRob) diff --git a/R/simulate_LFQ_data.R b/R/simulate_LFQ_data.R index 4a4b6e44d..6c86d2162 100644 --- a/R/simulate_LFQ_data.R +++ b/R/simulate_LFQ_data.R @@ -16,8 +16,10 @@ #' @param prop proportion of down (D), up (U) and not regulated (N) #' @examples #' -#' sim_lfq_data(Nprot = 10) +#' res <- sim_lfq_data(Nprot = 10) #' res <- sim_lfq_data(Nprot = 10, PEPTIDE = TRUE) +#' + sim_lfq_data <- function( Nprot = 20, N = 4, @@ -208,3 +210,46 @@ sim_lfq_data_protein_config <- function(Nprot = 10, with_missing = TRUE, weight_ return(list(data = adata, config = config)) } + +#' Simulate data, protein, with config with 2 factros Treatment and Background +#' @param description Nprot number of proteins +#' @param with_missing add missing values, default TRUE +#' @param seed seed for reproducibility, if NULL no seed is set. +#' @export +#' @examples +#' x <- sim_lfq_data_protein_2Factor_config() +#' stopifnot("data.frame" %in% class(x$data)) +#' stopifnot("AnalysisConfiguration" %in% class(x$config)) +#' +sim_lfq_data_protein_2Factor_config <- function(Nprot = 10, + with_missing = TRUE, + weight_missing = 0.2, + seed = 1234){ + if (!is.null(seed)) { + set.seed(seed) + } + res <- sim_lfq_data(Nprot = 10, PEPTIDE = FALSE, + fc = list(A = c(D = -2, U = 2, N = 0), B = c(D = 1, U = -4), C = c(D = -1, U = -4)), + prop = list(A = c(D = 10, U = 10), B = c(D = 5, U = 20), C = c(D = 15, U = 25))) + res <- res |> mutate(Treatment = case_when(group %in% c("Ctrl", "A") ~ "A", TRUE ~ "B")) + res <- res |> mutate(Background = case_when(group %in% c("Ctrl", "C") ~ "Z", TRUE ~ "X")) + if (with_missing) { + data <- data[!which_missing(data$abundance,weight_missing = weight_missing),] + } + data$isotopeLabel <- "light" + data$qValue <- 0 + + atable <- AnalysisTableAnnotation$new() + atable$fileName = "sample" + atable$nr_children = "nr_peptides" + atable$factors["Treatment"] = "Treatment" + atable$factors["Background"] = "Background" + atable$hierarchy[["protein_Id"]] = c("proteinID", "idtype2") + atable$set_response("abundance") + + config <- AnalysisConfiguration$new(atable) + adata <- setup_analysis(data, config) + return(list(data = adata, config = config)) +} + + diff --git a/R/tidyMS_missigness_V2.R b/R/tidyMS_missigness_V2.R index 766ce18d9..c32cd9f1e 100644 --- a/R/tidyMS_missigness_V2.R +++ b/R/tidyMS_missigness_V2.R @@ -45,7 +45,7 @@ MissingHelpers <- R6::R6Class( get_stats = function(){ if (is.null(self$stats)) { self$stats = prolfqua::summarize_stats(self$data, self$config) - self$stats = prolfqua::make_interaction_column(self$stats, columns = self$config$table$factor_keys_depth()) + self$stats = prolfqua::make_interaction_column(self$stats, columns = self$config$table$factor_keys_depth(), sep = ":") } return(self$stats) }, diff --git a/man/sim_lfq_data.Rd b/man/sim_lfq_data.Rd index 52d328b52..69d173b18 100644 --- a/man/sim_lfq_data.Rd +++ b/man/sim_lfq_data.Rd @@ -29,6 +29,7 @@ simulate protein level data with two groups } \examples{ -sim_lfq_data(Nprot = 10) +res <- sim_lfq_data(Nprot = 10) res <- sim_lfq_data(Nprot = 10, PEPTIDE = TRUE) + } diff --git a/man/sim_lfq_data_protein_2Factor_config.Rd b/man/sim_lfq_data_protein_2Factor_config.Rd new file mode 100644 index 000000000..f39e0ebeb --- /dev/null +++ b/man/sim_lfq_data_protein_2Factor_config.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/simulate_LFQ_data.R +\name{sim_lfq_data_protein_2Factor_config} +\alias{sim_lfq_data_protein_2Factor_config} +\title{Simulate data, protein, with config with 2 factros Treatment and Background} +\usage{ +sim_lfq_data_protein_2Factor_config( + Nprot = 10, + with_missing = TRUE, + weight_missing = 0.2, + seed = 1234 +) +} +\arguments{ +\item{with_missing}{add missing values, default TRUE} + +\item{seed}{seed for reproducibility, if NULL no seed is set.} + +\item{description}{Nprot number of proteins} +} +\description{ +Simulate data, protein, with config with 2 factros Treatment and Background +} +\examples{ +x <- sim_lfq_data_protein_2Factor_config() +stopifnot("data.frame" \%in\% class(x$data)) +stopifnot("AnalysisConfiguration" \%in\% class(x$config)) + +}