Forráskód Böngészése

Fix some scatter plot aes

Bryan Roessler 7 hónapja
szülő
commit
557d85bc85
1 módosított fájl, 20 hozzáadás és 25 törlés
  1. 20 25
      qhtcp-workflow/apps/r/calculate_interaction_zscores.R

+ 20 - 25
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,9 +220,21 @@ 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,
       Raw_Shift_r = first(mean_r) - bg_means$r,
@@ -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) {