Skip to content

Commit

Permalink
remove 'allmuts' and mutation regex columns from ggtree object's data
Browse files Browse the repository at this point in the history
  • Loading branch information
russHyde committed Dec 7, 2022
1 parent a969811 commit be9a225
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 53 deletions.
48 changes: 5 additions & 43 deletions R/plot_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ create_trees <- function(ggtree_data,

tree_list$with_interactivity_data <- append_interactivity_data(
tree_list[["noninteractive"]],
branch_col = branch_col,
sc0 = sc0,
cmuts = cmuts,
mut_regex = mut_regex
branch_col = branch_col
)

genotype <- extract_genotype_data(
Expand Down Expand Up @@ -187,22 +184,17 @@ create_noninteractive_ggtree <- function(ggtree_data,
gtr1.1
}

#' Adds data to a ggtree object to allow mouse-over tooltips etc when presented interactively
#' Adds data to a \code{ggtree} object to allow mouse-over tooltips etc when presented interactively
#'
#' @param ggobj A \code{ggtree} object.
#' @param branch_col Scalar string. The name of a column within \code{ggobj$data} defining the
#' statistic under study here (`logistic_growth_rate`, `clock_outlier`).
#' @inheritParams create_trees
#'
#' @return A ggtree object. The \code{$data} entry has additional entries (\code{mouseover},
#' \code{colour_var}, \code{allmuts}) that are used when presented interactively by
#' \code{ggiraph}.
#' @return A \code{ggtree} object. The \code{$data} entry has additional entries (\code{mouseover},
#' \code{colour_var}) that are used when presented interactively by \code{ggiraph}.

append_interactivity_data <- function(ggobj,
branch_col,
sc0,
cmuts,
mut_regex) {
branch_col) {
# make mouseover info
## standard meta data
ttdfs <- apply(ggobj$data, 1, FUN = function(x) {
Expand All @@ -218,36 +210,6 @@ append_interactivity_data <- function(ggobj,
)
})

ttallmuts <- sapply(match(ggobj$data$cluster_id, sc0$cluster_id), function(isc0) {
if (is.na(isc0)) {
return("")
}
paste(
sep = "\n",
"All mutations:",
gsub(
x = stringr::str_wrap(
paste(
collapse = " ",
sort_mutations(cmuts[[as.character(sc0$node_number[isc0])]]$all)
),
width = 60
),
pattern = " ",
replacement = ", "
),
"\n"
)
}) # end of sapply

ggobj$data$allmuts <- ttallmuts
if (!is.null(mut_regex)) {
for (mre in mut_regex) {
i <- which(grepl(ggobj$data$allmuts, pattern = mre))
ggobj$data[[mre]] <- grepl(ggobj$data$allmuts, pattern = mre)
}
}

ggobj$data$mouseover <- ttdfs
ggobj$data$colour_var <- ggobj$data[[branch_col]]

Expand Down
15 changes: 5 additions & 10 deletions man/append_interactivity_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be9a225

Please sign in to comment.