Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions R/EvoFreq_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down
13 changes: 10 additions & 3 deletions R/idx_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down