Before debugging

This commit is contained in:
2024-09-04 21:27:31 -04:00
parent 0eb460b4ee
commit 93c3b82140

View File

@@ -10,7 +10,6 @@ suppressMessages({
options(warn = 2, max.print = 1000) options(warn = 2, max.print = 1000)
# Set the memory limit to 30GB (30 * 1024 * 1024 * 1024 bytes) # Set the memory limit to 30GB (30 * 1024 * 1024 * 1024 bytes)
soft_limit <- 30 * 1024 * 1024 * 1024 soft_limit <- 30 * 1024 * 1024 * 1024
hard_limit <- 30 * 1024 * 1024 * 1024 hard_limit <- 30 * 1024 * 1024 * 1024
@@ -115,7 +114,7 @@ load_and_process_data <- function(easy_results_file, sd = 3) {
# Clean and convert columns to numeric where appropriate # Clean and convert columns to numeric where appropriate
df <- df %>% df <- df %>%
filter(!(pull(select(., 1)) %in% c("", "Scan"))) %>% filter(!(.data[[1]] %in% c("", "Scan"))) %>%
filter(!is.na(ORF) & ORF != "" & !Gene %in% c("BLANK", "Blank", "blank") & Drug != "BMH21") %>% filter(!is.na(ORF) & ORF != "" & !Gene %in% c("BLANK", "Blank", "blank") & Drug != "BMH21") %>%
mutate( mutate(
Col = as.numeric(Col), Col = as.numeric(Col),
@@ -200,14 +199,13 @@ calculate_summary_stats <- function(df, variables, group_vars = c("conc_num", "c
max = ~max(.x, na.rm = TRUE), max = ~max(.x, na.rm = TRUE),
min = ~min(.x, na.rm = TRUE), min = ~min(.x, na.rm = TRUE),
sd = ~sd(.x, na.rm = TRUE), sd = ~sd(.x, na.rm = TRUE),
se = sd / sqrt(N - 1), # TODO why - 1? se = sd / sqrt(N - 1),
z_max = (max - mean) / sd z_max = (max - mean) / sd
), .names = "{.fn}_{.col}")) ), .names = "{.fn}_{.col}"))
return(summary_stats) return(summary_stats)
} }
calculate_interaction_scores <- function(df_ref, df, max_conc, variables, group_vars = c("OrfRep", "Gene", "num")) { calculate_interaction_scores <- function(df_ref, df, max_conc, variables, group_vars = c("OrfRep", "Gene", "num")) {
# Calculate total concentration variables # Calculate total concentration variables
@@ -323,14 +321,13 @@ calculate_interaction_scores <- function(df_ref, df, max_conc, variables, group_
) %>% ) %>%
ungroup() ungroup()
interactions_scores_all <- interactions_scores_all %>% interaction_scores_all <- interactions_scores_all %>%
arrange(desc(Z_lm_L)) %>% arrange(desc(Z_lm_L)) %>%
arrange(desc(NG)) arrange(desc(NG))
return(list(zscores_calculations = interaction_scores_all, zscores_interactions = interaction_scores)) return(list(zscores_calculations = interaction_scores_all, zscores_interactions = interaction_scores))
} }
generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_num", 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) { title, x_label = NULL, y_label = NULL, ylim_vals = NULL) {
@@ -362,7 +359,6 @@ generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_
return(plot) return(plot)
} }
generate_and_save_plots <- function(df, output_dir, file_prefix, variables, plot_type = "scatter", include_qc = FALSE, ylim_vals = NULL) { generate_and_save_plots <- function(df, output_dir, file_prefix, variables, plot_type = "scatter", include_qc = FALSE, ylim_vals = NULL) {
plots <- list() plots <- list()
@@ -396,8 +392,6 @@ generate_and_save_plots <- function(df, output_dir, file_prefix, variables, plot
save_plots(file_prefix, plots, output_dir) save_plots(file_prefix, plots, output_dir)
} }
# Ensure all plots are saved and printed to PDF # Ensure all plots are saved and printed to PDF
save_plots <- function(file_name, plot_list, output_dir) { save_plots <- function(file_name, plot_list, output_dir) {
# Save to PDF # Save to PDF
@@ -426,8 +420,6 @@ save_plots <- function(file_name, plot_list, output_dir) {
}) })
} }
generate_interaction_plots <- function(df, output_file) { generate_interaction_plots <- function(df, output_file) {
message("Generating interaction plots") message("Generating interaction plots")
@@ -472,8 +464,6 @@ generate_interaction_plots <- function(df, output_file) {
dev.off() dev.off()
} }
generate_cpp_correlation_plots <- function(df_na_rm, lm_list, output_dir) { generate_cpp_correlation_plots <- function(df_na_rm, lm_list, output_dir) {
lm_summaries <- lapply(lm_list, summary) lm_summaries <- lapply(lm_list, summary)
plot_titles <- c("Interaction L vs. Interaction K", "Interaction L vs. Interaction r", "Interaction L vs. Interaction AUC", plot_titles <- c("Interaction L vs. Interaction K", "Interaction L vs. Interaction r", "Interaction L vs. Interaction AUC",
@@ -516,7 +506,6 @@ adjust_missing_and_rank <- function(df) {
return(df) return(df)
} }
# Function to create and save all ranked plots # Function to create and save all ranked plots
create_ranked_plots <- function(df, output_dir) { create_ranked_plots <- function(df, output_dir) {
df_adjusted <- adjust_missing_and_rank(df) df_adjusted <- adjust_missing_and_rank(df)
@@ -528,7 +517,6 @@ create_ranked_plots <- function(df, output_dir) {
generate_and_save_ranked_plots(df_adjusted, output_dir, "RankPlots_lm_naRM") generate_and_save_ranked_plots(df_adjusted, output_dir, "RankPlots_lm_naRM")
} }
generate_plots <- function(df, x_var, y_vars, plot_type, color_var = "conc_num", title_prefix = "", generate_plots <- function(df, x_var, y_vars, plot_type, color_var = "conc_num", title_prefix = "",
x_label = NULL, y_label = NULL, ylim_vals = NULL, output_dir, file_prefix = "plot") { x_label = NULL, y_label = NULL, ylim_vals = NULL, output_dir, file_prefix = "plot") {
plot_list <- list() plot_list <- list()