diff --git a/workflow/apps/r/calculate_interaction_zscores5.R b/workflow/apps/r/calculate_interaction_zscores5.R index a8a1e5ca..a261e8ee 100644 --- a/workflow/apps/r/calculate_interaction_zscores5.R +++ b/workflow/apps/r/calculate_interaction_zscores5.R @@ -230,17 +230,20 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c bg_sd_r <- df %>% filter(conc_num_factor == 0) %>% pull(sd_r) %>% first() bg_sd_AUC <- df %>% filter(conc_num_factor == 0) %>% pull(sd_AUC) %>% first() - # Calculate interaction scores + # First mutate block to calculate NG, DB, SM print("Calculating interaction scores part 1") interaction_scores <- df %>% group_by(across(all_of(group_vars)), conc_num, conc_num_factor) %>% mutate( NG = sum(NG, na.rm = TRUE), DB = sum(DB, na.rm = TRUE), - SM = sum(SM, na.rm = TRUE) - ) %>% + SM = sum(SM, na.rm = TRUE), + N = ~sum(!is.na(L)), # Count of non-NA values + ) + + # Second mutate block to calculate variables and Delta using NG + interaction_scores <- interaction_scores %>% mutate(across(all_of(variables), list( - N = ~sum(!is.na(.)), # Count of non-NA values mean = ~mean(., na.rm = TRUE), median = ~median(., na.rm = TRUE), max = ~max(., na.rm = TRUE), @@ -269,7 +272,7 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c Delta_L = if_else(SM == 1, mean_L - WT_L, Delta_L) # disregard shift for set to max values in Z score calculation ) %>% ungroup() - + # Calculate linear models and interaction scores per gene print("Calculating interaction scores part 2") interaction_scores_all <- interaction_scores %>% @@ -296,6 +299,7 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c return(list(zscores_calculations = interaction_scores_all, zscores_interactions = interaction_scores)) } + interaction_plot_configs <- function(df, variable) { ylim_vals <- switch(variable, "L" = c(-65, 65), @@ -715,8 +719,6 @@ main <- function() { reference_strain <- process_strains(df_reference) # TODO double-check deletion_strains <- process_strains(df_deletion) # TODO double-check - # TODO we may need to add "num" to grouping vars - # Calculate interactions variables <- c("L", "K", "r", "AUC") # We are recalculating some of the data here