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)
# Set the memory limit to 30GB (30 * 1024 * 1024 * 1024 bytes)
soft_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
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") %>%
mutate(
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),
min = ~min(.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
), .names = "{.fn}_{.col}"))
return(summary_stats)
}
calculate_interaction_scores <- function(df_ref, df, max_conc, variables, group_vars = c("OrfRep", "Gene", "num")) {
# Calculate total concentration variables
@@ -323,14 +321,13 @@ calculate_interaction_scores <- function(df_ref, df, max_conc, variables, group_
) %>%
ungroup()
interactions_scores_all <- interactions_scores_all %>%
interaction_scores_all <- interactions_scores_all %>%
arrange(desc(Z_lm_L)) %>%
arrange(desc(NG))
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",
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)
}
generate_and_save_plots <- function(df, output_dir, file_prefix, variables, plot_type = "scatter", include_qc = FALSE, ylim_vals = NULL) {
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)
}
# Ensure all plots are saved and printed to PDF
save_plots <- function(file_name, plot_list, output_dir) {
# Save to PDF
@@ -426,8 +420,6 @@ save_plots <- function(file_name, plot_list, output_dir) {
})
}
generate_interaction_plots <- function(df, output_file) {
message("Generating interaction plots")
@@ -472,8 +464,6 @@ generate_interaction_plots <- function(df, output_file) {
dev.off()
}
generate_cpp_correlation_plots <- function(df_na_rm, lm_list, output_dir) {
lm_summaries <- lapply(lm_list, summary)
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)
}
# Function to create and save all ranked plots
create_ranked_plots <- function(df, output_dir) {
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_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") {
plot_list <- list()