diff --git a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R index b9777440..49d5cbf2 100644 --- a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R +++ b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R @@ -597,13 +597,13 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs, page_width grid_layout$nrow <- ceiling(num_plots / grid_layout$ncol) } - total_spots <- grid_layout$nrow * grid_layout$ncol - num_plots <- length(static_plots) + # total_spots <- grid_layout$nrow * grid_layout$ncol + # num_plots <- length(static_plots) - if (num_plots < total_spots) { - message("Filling ", total_spots - num_plots, " empty spots with nullGrob()") - static_plots <- c(static_plots, replicate(total_spots - num_plots, nullGrob(), simplify = FALSE)) - } + # if (num_plots < total_spots) { + # message("Filling ", total_spots - num_plots, " empty spots with nullGrob()") + # static_plots <- c(static_plots, replicate(total_spots - num_plots, nullGrob(), simplify = FALSE)) + # } grid.arrange( grobs = static_plots, @@ -739,36 +739,16 @@ generate_scatter_plot <- function(plot, config) { slope <- config$lm_line$slope color <- ifelse(!is.null(config$lm_line$color), config$lm_line$color, "blue") linewidth <- ifelse(!is.null(config$lm_line$linewidth), config$lm_line$linewidth, 1) + y_min <- intercept + slope * x_min + y_max <- intercept + slope * x_max + + # Ensure y-values are within y-limits (if any) + if (!is.null(config$ylim_vals)) { + y_min_within_limits <- y_min >= config$ylim_vals[1] && y_min <= config$ylim_vals[2] + y_max_within_limits <- y_max >= config$ylim_vals[1] && y_max <= config$ylim_vals[2] - # Ensure none of the values are NA and calculate y-values - if (!is.na(x_min) && !is.na(x_max) && !is.na(intercept) && !is.na(slope)) { - y_min <- intercept + slope * x_min - y_max <- intercept + slope * x_max - - # Ensure y-values are within y-limits (if any) - if (!is.null(config$ylim_vals)) { - y_min_within_limits <- y_min >= config$ylim_vals[1] && y_min <= config$ylim_vals[2] - y_max_within_limits <- y_max >= config$ylim_vals[1] && y_max <= config$ylim_vals[2] - - # Adjust or skip based on whether the values fall within limits - if (y_min_within_limits && y_max_within_limits) { - # Ensure x-values are also valid - if (!is.na(x_min) && !is.na(x_max)) { - plot <- plot + annotate( - "segment", - x = x_min, - xend = x_max, - y = y_min, - yend = y_max, - color = color, - linewidth = linewidth - ) - } - } else { - message("Skipping linear regression line due to y-values outside of limits") - } - } else { - # If no y-limits are provided, proceed with the annotation + # Adjust or skip based on whether the values fall within limits + if (y_min_within_limits && y_max_within_limits) { plot <- plot + annotate( "segment", x = x_min, @@ -778,9 +758,20 @@ generate_scatter_plot <- function(plot, config) { color = color, linewidth = linewidth ) + } else { + message("Skipping linear regression line due to y-values outside of limits") } } else { - message("Skipping linear regression line due to missing or invalid values") + # If no y-limits are provided, proceed with the annotation + plot <- plot + annotate( + "segment", + x = x_min, + xend = x_max, + y = y_min, + yend = y_max, + color = color, + linewidth = linewidth + ) } } @@ -1052,7 +1043,7 @@ generate_interaction_plot_configs <- function(df_summary, df_interactions, type) NG_value <- first(group_data_filtered$NG, default = 0) DB_value <- first(group_data_filtered$DB, default = 0) SM_value <- first(group_data_filtered$SM, default = 0) - + lm_intercept_col <- paste0("lm_intercept_", var) lm_slope_col <- paste0("lm_slope_", var) lm_intercept_value <- first(group_data_filtered[[lm_intercept_col]], default = 0) @@ -1485,7 +1476,7 @@ main <- function() { message("Generating quality control plots in parallel") # future::plan(future::multicore, workers = parallel::detectCores()) - future::plan(future::multisession, workers = 3) # generate 3 plots in parallel + future::plan(future::multisession, workers = 3) # generate 3 plot files in parallel plot_configs <- list( list(out_dir = out_dir_qc, filename = "L_vs_K_before_quality_control",