From 2b9e4f0f4910232edf799ff11ce56799b2ecccbe Mon Sep 17 00:00:00 2001 From: Virginia Turati Date: Sun, 7 Mar 2021 14:50:13 -0500 Subject: [PATCH] Add option to stack children clones --- R/EvoFreq_funcs.R | 5 +++-- R/idx_funcs.R | 13 ++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R/EvoFreq_funcs.R b/R/EvoFreq_funcs.R index 216f700..7ca80c7 100644 --- a/R/EvoFreq_funcs.R +++ b/R/EvoFreq_funcs.R @@ -22,6 +22,7 @@ #'@param tm_frac Value between 0 and 1 that determines where the maximum growth rate is in the inferred origin sizes. Lower values result in earlier maximum growth #'@param rescale_after_thresholding Boolean determining if frequencies should be rescaled after thresholding, so that frequencies are based on what was above the threshold. #'@param shuffle_colors Boolean determining if colors should be shuffled before being assigned to each clone. Only applies when fill_value = NULL +#'@param stacked Boolean determining if subclones should be stacked or sister branches should be separated by their parent clone. #'@return Formatted dataframe called a "freq_frame" containing the information needed to plot the frequency dynamics over time. #' #'@examples @@ -93,7 +94,7 @@ #'default_cmap_evo_p <- plot_evofreq(freq_frame_default_color) #'} #'@export -get_evofreq <- function(size_df, clones, parents, fill_value=NULL, fill_range = NULL, time_pts=NULL, clone_cmap=NULL, threshold=0.01, scale_by_sizes_at_time = FALSE, data_type="size", interpolation_steps = 20, interp_method = "monoH.FC", fill_gaps_in_size = FALSE, test_links=TRUE, add_origin=FALSE, tm_frac=0.6, rescale_after_thresholding=FALSE, shuffle_colors=FALSE){ +get_evofreq <- function(size_df, clones, parents, fill_value=NULL, fill_range = NULL, time_pts=NULL, clone_cmap=NULL, threshold=0.01, scale_by_sizes_at_time = FALSE, data_type="size", interpolation_steps = 20, interp_method = "monoH.FC", fill_gaps_in_size = FALSE, test_links=TRUE, add_origin=FALSE, tm_frac=0.6, rescale_after_thresholding=FALSE, shuffle_colors=FALSE, stacked=FALSE){ # # ## FOR TESTING ### # data("example.easy.wide.with.attributes") # ### Split dataframe into clone info and size info using fact timepoint column names can be converted to numeric values @@ -170,7 +171,7 @@ get_evofreq <- function(size_df, clones, parents, fill_value=NULL, fill_range = cat("\n") print("Getting Plot Positions") time_pts <- colnames(freq_mat) - plot_pos_df <- get_pos(clones, parents, freq_mat, as.numeric(time_pts)) + plot_pos_df <- get_pos(clones, parents, freq_mat, as.numeric(time_pts), stacked) if(interpolation_steps > 0){ diff --git a/R/idx_funcs.R b/R/idx_funcs.R index 6c72426..9d90d7d 100644 --- a/R/idx_funcs.R +++ b/R/idx_funcs.R @@ -54,7 +54,7 @@ get_ancestor_idx_evo_freq <- function(clone_id, clone_list, parent_list){ return(ancestral_idx) } -get_pos <- function(clones, parents, mut_mat, og_time_pts=NULL){ +get_pos <- function(clones, parents, mut_mat, og_time_pts=NULL, stacked=FALSE){ ### FOR TESTING ### # parents <- parents # clones <- clones @@ -145,7 +145,11 @@ get_pos <- function(clones, parents, mut_mat, og_time_pts=NULL){ } # n_children <- length(children_idx)### NOTE WAS HERE # n_children <- length(children_idx) - spacing <- (parent_area - total_child_area)/(n_children+1) + if(stacked){ + spacing <- (parent_area - total_child_area)/2 + } else { + spacing <- (parent_area - total_child_area)/(n_children+1) + } # spacing[spacing < 0] <- min(spacing[spacing >= 0]) ###TODO DOES THIS WORK? ### Get bottom of parent's polygon @@ -185,7 +189,10 @@ get_pos <- function(clones, parents, mut_mat, og_time_pts=NULL){ bottom <- loc loc <- loc + child_size top <- loc - loc <- loc + spacing + + if(!stacked){ + loc <- loc + spacing + } # if(any(is.na(bottom))){ # print(paste("bottom positions are NA for clone", clone_id))