diff --git a/workflow/apps/r/calculate_interaction_zscores5.R b/workflow/apps/r/calculate_interaction_zscores5.R index a69d8f67..c663bd28 100644 --- a/workflow/apps/r/calculate_interaction_zscores5.R +++ b/workflow/apps/r/calculate_interaction_zscores5.R @@ -115,15 +115,17 @@ load_and_process_data <- function(easy_results_file, sd = 3) { df <- df %>% filter(!(.[[1]] %in% c("", "Scan"))) %>% filter(!is.na(ORF) & ORF != "" & !Gene %in% c("BLANK", "Blank", "blank") & Drug != "BMH21") %>% + # Rename columns + rename(L = l, num = Num., AUC = AUC96, scan = Scan) %>% mutate( - across(c(Col, Row, Num.), as.numeric), - across(c(L, K, r, scan, AUC96, LstBackgrd, X1stBackgrd), as.numeric), + across(c(Col, Row, num), as.numeric), + across(c(L, K, r, scan, AUC, LstBackgrd, X1stBackgrd), as.numeric), delta_bg = last_bg - first_bg, delta_bg_tolerance = mean(delta_bg, na.rm = TRUE) + (sd * sd(delta_bg, na.rm = TRUE)), NG = if_else(L == 0 & !is.na(L), 1, 0), DB = if_else(delta_bg >= delta_bg_tolerance, 1, 0), SM = 0, - OrfRep = if_else(ORF == "YDL227C", "YDL227C", OrfRep), + OrfRep = if_else(ORF == "YDL227C", "YDL227C", OrfRep), # should these be hardcoded? conc_num = as.numeric(gsub("[^0-9\\.]", "", Conc)), conc_num_factor = as.numeric(as.factor(conc_num)) - 1 ) @@ -290,7 +292,6 @@ 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), @@ -321,7 +322,6 @@ interaction_plot_configs <- function(df, variable) { ) } - generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_num", title, x_label = NULL, y_label = NULL, ylim_vals = NULL) { @@ -376,7 +376,7 @@ generate_and_save_plots <- function(df, output_dir, file_prefix, plot_configs) { # If custom annotations for interaction plots are required if (!is.null(config$annotations)) { for (annotation in config$annotations) { - plot <- plot + + plot <- plot + annotate( "text", x = annotation$x, y = annotation$y, label = annotation$label ) @@ -390,8 +390,6 @@ generate_and_save_plots <- function(df, output_dir, file_prefix, plot_configs) { save_plots(file_prefix, plots, output_dir) } - - # Ensure all plots are saved and printed to PDF save_plots <- function(file_name, plot_list, output_dir) { # Save to PDF