From 529b6c27ed18fea33489e4a2b07a5d65ca38352d Mon Sep 17 00:00:00 2001 From: Alex Adrian-Hamazaki Date: Thu, 8 Jan 2026 11:39:54 -0800 Subject: [PATCH 1/3] feature(plot_state_hm): Add option to scale plot by nubmer of cells \n Setting scale_y to True makes the saved plot scale to how many cells you are plotting --- R/heatmap_plot.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/R/heatmap_plot.R b/R/heatmap_plot.R index 25a77c2..b005ee3 100644 --- a/R/heatmap_plot.R +++ b/R/heatmap_plot.R @@ -135,11 +135,13 @@ generate_state_hm <- function( #' #' @param total_hm ComplexHeatmap::Heatmap of the combined tree and states. #' @param file_name optional string of where to save a png image of the heatmap. +#' @param png_height optional height of png file #' @return ComplexHeatmap::draw or nothing if a file is written. #' @export output_hm_image <- function( hm, file_name = NULL, png_height = 1600, png_width = 2800, png_res = 144) { + print(png_height) if (!is.null(file_name)) { # open a file to dump it to grDevices::png( @@ -514,6 +516,8 @@ make_clone_palette <- function(clone_ids) { #' in the heatmap. Will default to the name of the column being plotted. #' @param legend_11plus bool. Default FALSE. For HMMCopy state values, #' state 11 is really 11+, so we replace 11s with 11+ for the plot in the +#' @param scale_y bool. Default FALSE. Scale the y size of the saved image accoring +#' to the number of cells in the heatmap #' legend. #' @export plot_state_hm <- function( @@ -537,6 +541,7 @@ plot_state_hm <- function( hm_legend_title = NULL, legend_11plus = FALSE, color_tree_clones = FALSE, + scale_y = FALSE, ...) { check_args() @@ -634,9 +639,20 @@ plot_state_hm <- function( legend_11plus = legend_11plus ) + # If scale_y is true, scale image height to number of cells + if (scale_y) { + message("Scaling Image Size by number of cells") + ncells <- length(unique(states_df$cell_id)) + message(ncells) + png_height <- ncells*15 + } else { + png_height <- 1600 + } + output_hm_image( hm_p, file_name = file_name, + png_height = png_height, ... ) } From 3711f1b295e31b73099d67b48dce5da63c13886c Mon Sep 17 00:00:00 2001 From: Alex Adrian-Hamazaki Date: Fri, 9 Jan 2026 11:56:10 -0800 Subject: [PATCH 2/3] feature(plot_state_hm): Expose cell_height \n Enable option to choose how much height to give each cell --- DESCRIPTION | 2 +- R/heatmap_plot.R | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 97d2989..3d3cea6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dlptools Title: DLPTools: Handling DLP+ Data -Version: 1.1.0 +Version: 1.1.1 Authors@R: c( person("Ben", "Furman", email = "bfurman@bccrc.ca", role = c("aut", "cre")), person("Aparicio Lab Past and Present", role = "aut") diff --git a/R/heatmap_plot.R b/R/heatmap_plot.R index b005ee3..1cc56c6 100644 --- a/R/heatmap_plot.R +++ b/R/heatmap_plot.R @@ -391,7 +391,6 @@ build_left_annot <- function( col = anno_cols_list ) } - return(left_annot) } @@ -518,6 +517,7 @@ make_clone_palette <- function(clone_ids) { #' state 11 is really 11+, so we replace 11s with 11+ for the plot in the #' @param scale_y bool. Default FALSE. Scale the y size of the saved image accoring #' to the number of cells in the heatmap +#' @param cell_height, int. Default = 10 Heigh in pixels per cell if scale_y is True #' legend. #' @export plot_state_hm <- function( @@ -526,7 +526,7 @@ plot_state_hm <- function( phylogeny = NULL, file_name = NULL, anno_df = NULL, # optional, can also specify columns in the dataframe - anno_colors_list = list(), # for custom colors of annotations + anno_colors_list = list(), # for custom colors of annotations. Can also specify custom breaks in the cmap anno_columns = NULL, clone_column = NULL, clones_df = NULL, # optional, can also specify columns in the dataframe @@ -542,6 +542,8 @@ plot_state_hm <- function( legend_11plus = FALSE, color_tree_clones = FALSE, scale_y = FALSE, + cell_height = 10, + default_png_height = 1600 ...) { check_args() @@ -643,10 +645,9 @@ plot_state_hm <- function( if (scale_y) { message("Scaling Image Size by number of cells") ncells <- length(unique(states_df$cell_id)) - message(ncells) - png_height <- ncells*15 + png_height <- 200 + ncells*cell_height } else { - png_height <- 1600 + png_height <- default_png_height } output_hm_image( From ca27d7ad95897ba150cd5665514f50879142ede9 Mon Sep 17 00:00:00 2001 From: Alex Adrian-Hamazaki Date: Fri, 9 Jan 2026 12:06:46 -0800 Subject: [PATCH 3/3] bugfix(plot_state_hm): Fix missing coma --- R/heatmap_plot.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/heatmap_plot.R b/R/heatmap_plot.R index 1cc56c6..bd0447c 100644 --- a/R/heatmap_plot.R +++ b/R/heatmap_plot.R @@ -141,7 +141,6 @@ generate_state_hm <- function( output_hm_image <- function( hm, file_name = NULL, png_height = 1600, png_width = 2800, png_res = 144) { - print(png_height) if (!is.null(file_name)) { # open a file to dump it to grDevices::png( @@ -515,10 +514,12 @@ make_clone_palette <- function(clone_ids) { #' in the heatmap. Will default to the name of the column being plotted. #' @param legend_11plus bool. Default FALSE. For HMMCopy state values, #' state 11 is really 11+, so we replace 11s with 11+ for the plot in the +#' #' legend. #' @param scale_y bool. Default FALSE. Scale the y size of the saved image accoring #' to the number of cells in the heatmap #' @param cell_height, int. Default = 10 Heigh in pixels per cell if scale_y is True -#' legend. +#' @param default_png_height, int: Default = 1600. If scale_y not used, height +#' of final png #' @export plot_state_hm <- function( states_df, @@ -543,7 +544,7 @@ plot_state_hm <- function( color_tree_clones = FALSE, scale_y = FALSE, cell_height = 10, - default_png_height = 1600 + default_png_height = 1600, ...) { check_args()