Skip to content

Commit

Permalink
using simulated data in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wolski committed Apr 22, 2024
1 parent 85158f9 commit e211fe0
Show file tree
Hide file tree
Showing 29 changed files with 274 additions and 314 deletions.
7 changes: 2 additions & 5 deletions R/AnalysisConfiguration.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ make_reduced_hierarchy_config <- function(config, workIntensity , hierarchy ){
#' # debug(make_interaction_column)
#' x <- make_interaction_column(xx, c("B","A"))
#' x <- make_interaction_column(xx, c("A"))
#' bb <- prolfqua_data('data_ionstar')$filtered()
#' bb$config <- old2new(bb$config)
#' stopifnot(nrow(bb$data) == 25780)
#' config <- bb$config$clone(deep=TRUE)
#' bb <- prolfqua::sim_lfq_data_protein_config()
#' config <- bb$config
#' analysis <- bb$data
#'
#' config$table$factor_keys()
#' config$table$factorDepth <- 1
#' make_interaction_column(analysis,
#' config$table$factor_keys_depth())
Expand Down
8 changes: 5 additions & 3 deletions R/ContrastsSimpleImpute.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#'
#' Contr <- c("dil.b_vs_a" = "group_A - group_Ctrl")
#' csi <- ContrastsMissing$new(lProt, contrasts = Contr)
#' csi$get_contrast_sides()
#'
#' res <- csi$get_contrasts()
#'
ContrastsMissing <- R6::R6Class(
Expand Down Expand Up @@ -120,8 +122,8 @@ ContrastsMissing <- R6::R6Class(

result <- dplyr::inner_join(result, pooled, by = self$lfqdata$config$table$hierarchy_keys_depth())

result_sd_zero <- result[result$n == 0, ]
resultnot_zero <- result[result$n > 0,]
result_sd_zero <- result[result$nrMeasured == 0, ]
resultnot_zero <- result[result$nrMeasured > 0,]
meandf <- resultnot_zero |> summarize(n = 1, df = 1, sd = mean(sd, na.rm = TRUE), sdT = mean(sdT, na.rm = TRUE))

meandf$sd <- ifelse(meandf$sd > 0, meandf$sd, self$minsd)
Expand All @@ -144,7 +146,7 @@ ContrastsMissing <- R6::R6Class(
result <- self$p.adjust(result, column = "p.value", group_by_col = "contrast", newname = "FDR")

if (!all) {
result <- select(result, -all_of( c("isSingular", "not_na" , "mean" ,"n.groups", "n", "meanAll") ) )
result <- select(result, -all_of( c("isSingular", "nrMeasured" , "mean" ,"n.groups", "n", "meanAll") ) )
}

}
Expand Down
2 changes: 1 addition & 1 deletion R/LFQDataStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' lfqstats$stats_wide()
#' lfqstats$violin()
#' runallfuncs(lfqstats)
#' x<-lfqstats
#' x <- lfqstats
#'
#' #study variance of normalized data
#'
Expand Down
14 changes: 7 additions & 7 deletions R/simulate_LFQ_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ sim_lfq_data <- function(
#' add missing values to x vector based on the values of x
#' @export
#' @param x vector of intensities
#' @param weight_missing greater weight more missing
#'
#'
which_missing <- function(x){
which_missing <- function(x, weight_missing = 0.2){
missing_prop <- pnorm(x, mean = mean(x), sd = sd(x))
# sample TRUE or FALSE with propability in missing_prop
samplemiss <- function(missing_prop) {
mp <- c((1 - missing_prop)*0.2, missing_prop*3)
mp <- c((1 - missing_prop)*weight_missing, missing_prop*3)
mp <- mp / sum(mp)
sample(c(TRUE, FALSE), size = 1, replace = TRUE, prob = mp)
}
Expand All @@ -151,13 +151,13 @@ which_missing <- function(x){
#' x <- sim_lfq_data_peptide_config()
#' stopifnot("data.frame" %in% class(x$data))
#' stopifnot("AnalysisConfiguration" %in% class(x$config))
sim_lfq_data_peptide_config <- function(Nprot = 10, with_missing = TRUE, seed = 1234){
sim_lfq_data_peptide_config <- function(Nprot = 10, with_missing = TRUE, weight_missing = 0.2, seed = 1234){
if (!is.null(seed)) {
set.seed(seed)
}
data <- sim_lfq_data(Nprot = Nprot, PEPTIDE = TRUE)
if (with_missing) {
not_missing <- !which_missing(data$abundance)
not_missing <- !which_missing(data$abundance, weight_missing = weight_missing)
data <- data[not_missing,]
}
data$isotopeLabel <- "light"
Expand Down Expand Up @@ -185,13 +185,13 @@ sim_lfq_data_peptide_config <- function(Nprot = 10, with_missing = TRUE, seed =
#' stopifnot("data.frame" %in% class(x$data))
#' stopifnot("AnalysisConfiguration" %in% class(x$config))
#'
sim_lfq_data_protein_config <- function(Nprot = 10, with_missing = TRUE, seed = 1234){
sim_lfq_data_protein_config <- function(Nprot = 10, with_missing = TRUE, weight_missing = 0.2, seed = 1234){
if (!is.null(seed)) {
set.seed(seed)
}
data <- sim_lfq_data(Nprot = Nprot, PEPTIDE = FALSE)
if (with_missing) {
data <- data[!which_missing(data$abundance),]
data <- data[!which_missing(data$abundance,weight_missing = weight_missing),]
}
data$isotopeLabel <- "light"
data$qValue <- 0
Expand Down
29 changes: 12 additions & 17 deletions R/tidyMS_R6Model.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,30 @@ LR_test <- function(modelProteinF,
#'
#' @export
#' @examples
#' # library(tidyverse)
#' D <- prolfqua_data('data_ionstar')$normalized()
#' D$config <- old2new(D$config)
#' D$data <- dplyr::filter(D$data ,protein_Id %in% sample(protein_Id, 100))
#'
#' D <- prolfqua::sim_lfq_data_peptide_config(Nprot = 20, weight_missing = 0.1)
#' D$data$abundance |> is.na() |> sum()
#' D <- prolfqua::sim_lfq_data_peptide_config(Nprot = 20, weight_missing = 0.1, seed =3)
#' D$data$abundance |> is.na() |> sum()
#' modelName <- "f_condtion_r_peptide"
#' formula_randomPeptide <-
#' strategy_lmer("transformedIntensity ~ dilution. + (1 | peptide_Id) + (1 | sampleName)",
#' strategy_lmer("abundance ~ group_ + (1 | peptide_Id) + (1 | sampleName)",
#' model_name = modelName)
#'
#'
#' pepIntensity <- D$data
#' config <- D$config
#'
#'
#'
#' mod <- prolfqua:::build_model(
#' pepIntensity,
#' mod <- prolfqua::build_model(
#' D$data,
#' formula_randomPeptide,
#' modelName = modelName,
#' subject_Id = config$table$hierarchy_keys_depth())
#' mod$get_anova()
#' subject_Id = D$config$table$hierarchy_keys_depth())
#' aovtable <- mod$get_anova()
#'
#' mod <- prolfqua:::build_model(
#' LFQData$new(pepIntensity, config),
#' mod <- prolfqua::build_model(
#' LFQData$new(D$data, D$config),
#' formula_randomPeptide,
#' modelName = modelName)
#' model_summary(mod)
#'
#'
build_model <- function(data,
model_strategy,
subject_Id = if ("LFQData" %in% class(data)) {data$subject_Id()} else {"protein_Id"},
Expand Down
4 changes: 0 additions & 4 deletions R/tidyMS_aggregation.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,18 @@ plot_hierarchies_line <- function(res,
#' config$table$is_response_transformed <- FALSE
#' #debug(plot_hierarchies_line_df)
#' res <- plot_hierarchies_line_df(istar_data, config)
#' res[[1]]
#'
#' config$table$is_response_transformed <- TRUE
#' res <- plot_hierarchies_line_df(istar_data, config)
#' res[[1]]
#'
#' istar <- prolfqua_data('data_ionstar')$filtered()
#' istar_data <- istar$data |> dplyr::filter(protein_Id %in% sample(protein_Id, 20))
#' config <- old2new(istar$config)
#' res <- plot_hierarchies_line_df(istar_data, config)
#' config$table$is_response_transformed
#' res[[1]]
#' config$table$is_response_transformed <- TRUE
#' res <- plot_hierarchies_line_df(istar_data, config)
#' config$table$is_response_transformed
#' res[[1]]
#'
#' #TODO make it work for other hiearachy levels.
#' config$table$hierarchyDepth = 2
Expand Down
Loading

0 comments on commit e211fe0

Please sign in to comment.