Standardize output filenames
This commit is contained in:
@@ -1295,9 +1295,9 @@ main <- function() {
|
||||
group_vars = c("OrfRep", "Gene", "num", "conc_num", "conc_num_factor")
|
||||
)$df_with_stats
|
||||
reference_results <- calculate_interaction_scores(df_reference_stats, max_conc, bg_stats, group_vars = c("OrfRep", "Gene", "num"))
|
||||
zscores_calculations_reference <- reference_results$calculations
|
||||
zscores_interactions_reference <- reference_results$interactions
|
||||
zscores_interactions_reference_joined <- reference_results$interactions_joined
|
||||
zscore_calculations_reference <- reference_results$calculations
|
||||
zscore_interactions_reference <- reference_results$interactions
|
||||
zscore_interactions_reference_joined <- reference_results$interactions_joined
|
||||
|
||||
message("Calculating deletion strain(s) interactions scores")
|
||||
df_deletion_stats <- calculate_summary_stats(
|
||||
@@ -1306,97 +1306,97 @@ main <- function() {
|
||||
group_vars = c("OrfRep", "Gene", "conc_num", "conc_num_factor")
|
||||
)$df_with_stats
|
||||
deletion_results <- calculate_interaction_scores(df_deletion_stats, max_conc, bg_stats, group_vars = c("OrfRep"))
|
||||
zscores_calculations <- deletion_results$calculations
|
||||
zscores_interactions <- deletion_results$interactions
|
||||
zscores_interactions_joined <- deletion_results$interactions_joined
|
||||
zscore_calculations <- deletion_results$calculations
|
||||
zscore_interactions <- deletion_results$interactions
|
||||
zscore_interactions_joined <- deletion_results$interactions_joined
|
||||
|
||||
# Writing Z-Scores to file
|
||||
write.csv(zscores_calculations_reference, file = file.path(out_dir, "RF_ZScores_Calculations.csv"), row.names = FALSE)
|
||||
write.csv(zscores_calculations, file = file.path(out_dir, "ZScores_Calculations.csv"), row.names = FALSE)
|
||||
write.csv(zscores_interactions_reference, file = file.path(out_dir, "RF_ZScores_Interaction.csv"), row.names = FALSE)
|
||||
write.csv(zscores_interactions, file = file.path(out_dir, "ZScores_Interaction.csv"), row.names = FALSE)
|
||||
write.csv(zscore_calculations_reference, file = file.path(out_dir, "zscore_calculations_reference.csv"), row.names = FALSE)
|
||||
write.csv(zscore_calculations, file = file.path(out_dir, "zscore_calculations.csv"), row.names = FALSE)
|
||||
write.csv(zscore_interactions_reference, file = file.path(out_dir, "zscore_interactions_reference.csv"), row.names = FALSE)
|
||||
write.csv(zscore_interactions, file = file.path(out_dir, "zscore_interactions.csv"), row.names = FALSE)
|
||||
|
||||
# Create interaction plots
|
||||
message("Generating reference interaction plots")
|
||||
reference_plot_configs <- generate_interaction_plot_configs(zscores_interactions_reference_joined, interaction_vars)
|
||||
generate_and_save_plots(out_dir, "RF_interactionPlots", reference_plot_configs, grid_layout = list(ncol = 4, nrow = 3))
|
||||
reference_plot_configs <- generate_interaction_plot_configs(zscore_interactions_reference_joined, interaction_vars)
|
||||
generate_and_save_plots(out_dir, "interaction_plots_reference", reference_plot_configs, grid_layout = list(ncol = 4, nrow = 3))
|
||||
|
||||
message("Generating deletion interaction plots")
|
||||
deletion_plot_configs <- generate_interaction_plot_configs(zscores_interactions_joined, interaction_vars)
|
||||
generate_and_save_plots(out_dir, "InteractionPlots", deletion_plot_configs, grid_layout = list(ncol = 4, nrow = 3))
|
||||
deletion_plot_configs <- generate_interaction_plot_configs(zscore_interactions_joined, interaction_vars)
|
||||
generate_and_save_plots(out_dir, "interaction_plots", deletion_plot_configs, grid_layout = list(ncol = 4, nrow = 3))
|
||||
|
||||
# Define conditions for enhancers and suppressors
|
||||
# TODO Add to study config?
|
||||
threshold <- 2
|
||||
enhancer_condition_L <- zscores_interactions$Avg_Zscore_L >= threshold
|
||||
suppressor_condition_L <- zscores_interactions$Avg_Zscore_L <= -threshold
|
||||
enhancer_condition_K <- zscores_interactions$Avg_Zscore_K >= threshold
|
||||
suppressor_condition_K <- zscores_interactions$Avg_Zscore_K <= -threshold
|
||||
enhancer_condition_L <- zscore_interactions$Avg_Zscore_L >= threshold
|
||||
suppressor_condition_L <- zscore_interactions$Avg_Zscore_L <= -threshold
|
||||
enhancer_condition_K <- zscore_interactions$Avg_Zscore_K >= threshold
|
||||
suppressor_condition_K <- zscore_interactions$Avg_Zscore_K <= -threshold
|
||||
|
||||
# Subset data
|
||||
enhancers_L <- zscores_interactions[enhancer_condition_L, ]
|
||||
suppressors_L <- zscores_interactions[suppressor_condition_L, ]
|
||||
enhancers_K <- zscores_interactions[enhancer_condition_K, ]
|
||||
suppressors_K <- zscores_interactions[suppressor_condition_K, ]
|
||||
enhancers_L <- zscore_interactions[enhancer_condition_L, ]
|
||||
suppressors_L <- zscore_interactions[suppressor_condition_L, ]
|
||||
enhancers_K <- zscore_interactions[enhancer_condition_K, ]
|
||||
suppressors_K <- zscore_interactions[suppressor_condition_K, ]
|
||||
|
||||
# Save enhancers and suppressors
|
||||
message("Writing enhancer/suppressor csv files")
|
||||
write.csv(enhancers_L, file = file.path(out_dir, "ZScores_Interaction_Deletion_Enhancers_L.csv"), row.names = FALSE)
|
||||
write.csv(suppressors_L, file = file.path(out_dir, "ZScores_Interaction_Deletion_Suppressors_L.csv"), row.names = FALSE)
|
||||
write.csv(enhancers_K, file = file.path(out_dir, "ZScores_Interaction_Deletion_Enhancers_K.csv"), row.names = FALSE)
|
||||
write.csv(suppressors_K, file = file.path(out_dir, "ZScores_Interaction_Deletion_Suppressors_K.csv"), row.names = FALSE)
|
||||
write.csv(enhancers_L, file = file.path(out_dir, "zscore_interactions_deletion_enhancers_L.csv"), row.names = FALSE)
|
||||
write.csv(suppressors_L, file = file.path(out_dir, "zscore_interactions_deletion_suppressors_L.csv"), row.names = FALSE)
|
||||
write.csv(enhancers_K, file = file.path(out_dir, "zscore_interactions_deletion_enhancers_K.csv"), row.names = FALSE)
|
||||
write.csv(suppressors_K, file = file.path(out_dir, "zscore_interactions_deletion_suppressors_K.csv"), row.names = FALSE)
|
||||
|
||||
# Combine conditions for enhancers and suppressors
|
||||
enhancers_and_suppressors_L <- zscores_interactions[enhancer_condition_L | suppressor_condition_L, ]
|
||||
enhancers_and_suppressors_K <- zscores_interactions[enhancer_condition_K | suppressor_condition_K, ]
|
||||
enhancers_and_suppressors_L <- zscore_interactions[enhancer_condition_L | suppressor_condition_L, ]
|
||||
enhancers_and_suppressors_K <- zscore_interactions[enhancer_condition_K | suppressor_condition_K, ]
|
||||
|
||||
# Save combined enhancers and suppressors
|
||||
write.csv(enhancers_and_suppressors_L,
|
||||
file = file.path(out_dir, "ZScores_Interaction_Deletion_Enhancers_and_Suppressors_L.csv"), row.names = FALSE)
|
||||
file = file.path(out_dir, "zscore_interactions_deletion_enhancers_and_suppressors_L.csv"), row.names = FALSE)
|
||||
write.csv(enhancers_and_suppressors_K,
|
||||
file = file.path(out_dir, "ZScores_Interaction_Deletion_Enhancers_and_Suppressors_K.csv"), row.names = FALSE)
|
||||
file = file.path(out_dir, "zscore_interaction_deletion_enhancers_and_suppressors_K.csv"), row.names = FALSE)
|
||||
|
||||
# Handle linear model based enhancers and suppressors
|
||||
lm_threshold <- 2
|
||||
enhancers_lm_L <- zscores_interactions[zscores_interactions$Z_lm_L >= lm_threshold, ]
|
||||
suppressors_lm_L <- zscores_interactions[zscores_interactions$Z_lm_L <= -lm_threshold, ]
|
||||
enhancers_lm_K <- zscores_interactions[zscores_interactions$Z_lm_K >= lm_threshold, ]
|
||||
suppressors_lm_K <- zscores_interactions[zscores_interactions$Z_lm_K <= -lm_threshold, ]
|
||||
enhancers_lm_L <- zscore_interactions[zscore_interactions$Z_lm_L >= lm_threshold, ]
|
||||
suppressors_lm_L <- zscore_interactions[zscore_interactions$Z_lm_L <= -lm_threshold, ]
|
||||
enhancers_lm_K <- zscore_interactions[zscore_interactions$Z_lm_K >= lm_threshold, ]
|
||||
suppressors_lm_K <- zscore_interactions[zscore_interactions$Z_lm_K <= -lm_threshold, ]
|
||||
|
||||
# Save linear model based enhancers and suppressors
|
||||
message("Writing linear model enhancer/suppressor csv files")
|
||||
write.csv(enhancers_lm_L,
|
||||
file = file.path(out_dir, "ZScores_Interaction_Deletion_Enhancers_L_lm.csv"), row.names = FALSE)
|
||||
file = file.path(out_dir, "zscore_interactions_deletion_enhancers_lm_L.csv"), row.names = FALSE)
|
||||
write.csv(suppressors_lm_L,
|
||||
file = file.path(out_dir, "ZScores_Interaction_Deletion_Suppressors_L_lm.csv"), row.names = FALSE)
|
||||
file = file.path(out_dir, "zscore_interactions_deletion_suppressors_lm_L.csv"), row.names = FALSE)
|
||||
write.csv(enhancers_lm_K,
|
||||
file = file.path(out_dir, "ZScores_Interaction_Deletion_Enhancers_K_lm.csv"), row.names = FALSE)
|
||||
file = file.path(out_dir, "zscore_interactions_deletion_enhancers_lm_K.csv"), row.names = FALSE)
|
||||
write.csv(suppressors_lm_K,
|
||||
file = file.path(out_dir, "ZScores_Interaction_Deletion_Suppressors_K_lm.csv"), row.names = FALSE)
|
||||
file = file.path(out_dir, "zscore_interactions_deletion_suppressors_lm_K.csv"), row.names = FALSE)
|
||||
|
||||
message("Generating rank plots")
|
||||
rank_plot_configs <- generate_rank_plot_configs(
|
||||
df = zscores_interactions_joined,
|
||||
df = zscore_interactions_joined,
|
||||
variables = interaction_vars,
|
||||
is_lm = FALSE,
|
||||
adjust = TRUE
|
||||
)
|
||||
generate_and_save_plots(out_dir = out_dir, filename = "RankPlots",
|
||||
generate_and_save_plots(out_dir = out_dir, filename = "rank_plots",
|
||||
plot_configs = rank_plot_configs, grid_layout = list(ncol = 3, nrow = 2))
|
||||
|
||||
message("Generating ranked linear model plots")
|
||||
rank_lm_plot_configs <- generate_rank_plot_configs(
|
||||
df = zscores_interactions_joined,
|
||||
df = zscore_interactions_joined,
|
||||
variables = interaction_vars,
|
||||
is_lm = TRUE,
|
||||
adjust = TRUE
|
||||
)
|
||||
generate_and_save_plots(out_dir = out_dir, filename = "RankPlots_lm",
|
||||
generate_and_save_plots(out_dir = out_dir, filename = "rank_plots_lm",
|
||||
plot_configs = rank_lm_plot_configs, grid_layout = list(ncol = 3, nrow = 2))
|
||||
|
||||
message("Filtering and reranking plots")
|
||||
# Formerly X_NArm
|
||||
zscores_interactions_filtered <- zscores_interactions_joined %>%
|
||||
zscore_interactions_filtered <- zscore_interactions_joined %>%
|
||||
filter(!is.na(Z_lm_L) & !is.na(Avg_Zscore_L)) %>%
|
||||
mutate(
|
||||
Overlap = case_when(
|
||||
@@ -1418,7 +1418,7 @@ main <- function() {
|
||||
|
||||
message("Generating filtered ranked plots")
|
||||
rank_plot_filtered_configs <- generate_rank_plot_configs(
|
||||
df = zscores_interactions_filtered,
|
||||
df = zscore_interactions_filtered,
|
||||
variables = interaction_vars,
|
||||
is_lm = FALSE,
|
||||
adjust = FALSE,
|
||||
@@ -1433,7 +1433,7 @@ main <- function() {
|
||||
|
||||
message("Generating filtered ranked linear model plots")
|
||||
rank_plot_lm_filtered_configs <- generate_rank_plot_configs(
|
||||
df = zscores_interactions_filtered,
|
||||
df = zscore_interactions_filtered,
|
||||
variables = interaction_vars,
|
||||
is_lm = TRUE,
|
||||
adjust = FALSE,
|
||||
@@ -1441,15 +1441,15 @@ main <- function() {
|
||||
)
|
||||
generate_and_save_plots(
|
||||
out_dir = out_dir,
|
||||
filename = "RankPlots_lm_na_rm",
|
||||
filename = "rank_plots_lm_na_rm",
|
||||
plot_configs = rank_plot_lm_filtered_configs,
|
||||
grid_layout = list(ncol = 3, nrow = 2))
|
||||
|
||||
message("Generating correlation plots")
|
||||
correlation_plot_configs <- generate_correlation_plot_configs(zscores_interactions_filtered)
|
||||
message("Generating correlation curve parameter pair plots")
|
||||
correlation_plot_configs <- generate_correlation_plot_configs(zscore_interactions_filtered)
|
||||
generate_and_save_plots(
|
||||
out_dir = out_dir,
|
||||
filename = "Correlation_CPPs",
|
||||
filename = "correlation_cpps",
|
||||
plot_configs = correlation_plot_configs,
|
||||
grid_layout = list(ncol = 2, nrow = 2))
|
||||
})
|
||||
|
||||
@@ -9,11 +9,11 @@ suppressMessages({
|
||||
parse_arguments <- function() {
|
||||
if (interactive()) {
|
||||
args <- c(
|
||||
"/home/bryan/documents/develop/scripts/hartmanlab/workflow/out/20240116_jhartman2_DoxoHLD",
|
||||
"/home/bryan/documents/develop/hartmanlab/workflow/out/20240116_jhartman2_DoxoHLD",
|
||||
3, # sd value
|
||||
"/home/bryan/documents/develop/scripts/hartmanlab/workflow/out/20240116_jhartman2_DoxoHLD/20240822_jhartman2_DoxoHLD/exp1",
|
||||
"/home/bryan/documents/develop/hartmanlab/workflow/out/20240116_jhartman2_DoxoHLD/20240822_jhartman2_DoxoHLD/exp1",
|
||||
"Experiment 1: Doxo versus HLD",
|
||||
"/home/bryan/documents/develop/scripts/hartmanlab/workflow/out/20240116_jhartman2_DoxoHLD/20240822_jhartman2_DoxoHLD/exp2",
|
||||
"/home/bryan/documents/develop/hartmanlab/workflow/out/20240116_jhartman2_DoxoHLD/20240822_jhartman2_DoxoHLD/exp2",
|
||||
"Experiment 2: HLD versus Doxo"
|
||||
)
|
||||
} else {
|
||||
@@ -42,7 +42,7 @@ dir.create(args$out_dir, showWarnings = FALSE, recursive = TRUE)
|
||||
combine_zscores <- function(experiments, out_dir) {
|
||||
combined_data <- lapply(names(experiments), function(exp_name) {
|
||||
exp_dir <- experiments[[exp_name]]
|
||||
zscore_file <- file.path(exp_dir, "zscores", "zscores_interaction.csv")
|
||||
zscore_file <- file.path(exp_dir, "zscores", "zscore_interactions.csv")
|
||||
|
||||
if (!file.exists(zscore_file)) {
|
||||
stop("Z-score file does not exist for ", exp_name, " at ", zscore_file)
|
||||
|
||||
@@ -1432,6 +1432,7 @@ wrapper calculate_interaction_zscores
|
||||
# * More variables can be read in from the config file to allow more configuration
|
||||
# * Add gene names, other threshold values, etc.
|
||||
# * Dataframe columns and output file columns should be standardized in calculate_interactions()
|
||||
# * Need to decide if conc_num_factor is numeric or factor
|
||||
#
|
||||
# INPUT
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user