From 557d85bc85cb3768165fa8c5e9a5615e1f82c029 Mon Sep 17 00:00:00 2001 From: Bryan Roessler Date: Fri, 13 Sep 2024 19:51:40 -0400 Subject: [PATCH] Fix some scatter plot aes --- .../apps/r/calculate_interaction_zscores.R | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R index dbe5cded..01c668e9 100644 --- a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R +++ b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R @@ -203,20 +203,7 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c AUC = df %>% filter(conc_num_factor == 0) %>% pull(sd_AUC) %>% first() ) - # Grab these values from the original df before mutating the new stats stats <- df %>% - mutate( - WT_L = mean_L, - WT_K = mean_K, - WT_r = mean_r, - WT_AUC = mean_AUC, - WT_sd_L = sd_L, - WT_sd_K = sd_K, - WT_sd_r = sd_r, - WT_sd_AUC = sd_AUC - ) - - stats <- stats %>% group_by(OrfRep, Gene, num, conc_num, conc_num_factor) %>% summarise( N = sum(!is.na(L)), @@ -233,8 +220,20 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c ), .names = "{.fn}_{.col}") ) - stats <- stats %>% + stats <- df %>% group_by(OrfRep, Gene, num) %>% + mutate( + WT_L = mean_L, + WT_K = mean_K, + WT_r = mean_r, + WT_AUC = mean_AUC, + WT_sd_L = sd_L, + WT_sd_K = sd_K, + WT_sd_r = sd_r, + WT_sd_AUC = sd_AUC + ) + + stats <- stats %>% mutate( Raw_Shift_L = first(mean_L) - bg_means$L, Raw_Shift_K = first(mean_K) - bg_means$K, @@ -343,7 +342,7 @@ calculate_interaction_scores <- function(df, max_conc, variables, group_vars = c "Zscore_L", "Zscore_K", "Zscore_r", "Zscore_AUC", "NG", "SM", "DB") - df <- df %>% select(-any_of(setdiff(names(calculations), OrfRep, Gene, num, conc_num, conc_num_factor))) + df <- df %>% select(-any_of(setdiff(names(calculations), c("OrfRep", "Gene", "num", "conc_num", "conc_num_factor")))) df <- left_join(df, calculations, by = c("OrfRep", "Gene", "num", "conc_num", "conc_num_factor")) # df <- df %>% select(-any_of(setdiff(names(interactions), group_vars))) # df <- left_join(df, interactions, by = group_vars) @@ -412,24 +411,20 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la saveWidget(combined_plot, file = file.path(output_dir, paste0(file_name, ".html")), selfcontained = TRUE) } -generate_scatter_plot <- function(plot, config, interactive = FALSE) { +generate_scatter_plot <- function(plot, config) { - # Add the interactive `text` aesthetic if `interactive` is TRUE - if (interactive) { - plot <- if (!is.null(config$delta_bg_point) && config$delta_bg_point) { + # Add the interactive text aesthetics to the scatter points + plot <- + if (!is.null(config$delta_bg_point) && config$delta_bg_point) { plot + geom_point(aes(text = paste("ORF:", OrfRep, "Gene:", Gene, "delta_bg:", delta_bg)), shape = config$shape %||% 3, size = config$size %||% 0.2) } else if (!is.null(config$gene_point) && config$gene_point) { plot + geom_point(aes(text = paste("ORF:", OrfRep, "Gene:", Gene)), shape = config$shape %||% 3, size = config$size %||% 0.2, position = "jitter") } else { - plot + geom_point(shape = config$shape %||% 3, size = config$size %||% 0.2) + plot + geom_point(shape = config$shape %||% 3, size = config$size %||% 0.2, + position = config$position %||% "identity") } - } else { - # For non-interactive plots, just add `geom_point` - plot <- plot + geom_point(shape = config$shape %||% 3, size = config$size %||% 0.2, - position = if (!is.null(config$position) && config$position == "jitter") "jitter" else "identity") - } # Add smooth line if specified if (!is.null(config$add_smooth) && config$add_smooth) {