Skip to content

Commit

Permalink
Merge pull request #85 from selkamand/17-on-click-copy-sample-id-to-c…
Browse files Browse the repository at this point in the history
…lipboard

feat: added copy argument and ability to copy values to clipboard on …
  • Loading branch information
selkamand authored Feb 6, 2024
2 parents ead5e71 + d2464b9 commit dd1a270
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Description: Generate oncoplots from tabular mutational data.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Imports:
assertions (>= 0.0.0.9000),
assertthat,
Expand All @@ -40,7 +40,7 @@ Suggests:
vdiffr
VignetteBuilder: knitr
Config/testthat/edition: 3
Remotes:
Remotes:
selkamand/mutationtypes,
selkamand/gg1d,
selkamand/assertions
Expand Down
21 changes: 18 additions & 3 deletions R/oncoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ utils::globalVariables(c("Gene", "MutationType", "Pathway", "Sample", "Tooltip",
#' @param topn how many of the top genes to visualise. Ignored if `genes_to_include` is supplied (number)
#' @param show_sample_ids show sample_ids_on_x_axis (flag)
#' @param .data data for oncoplot. A data.frame with 1 row per mutation in your cohort. Must contain columns describing gene_symbols and sample_identifiers (data.frame)
#' @param copy value to copy to clipboard when an oncoplot tile is clicked (string).
#' @param genes_to_include specific genes to include in the oncoplot (character)
#' @param genes_to_ignore names of the genes that should be ignored (character)
#' @param return_extra_genes_if_tied instead of strictly returning `topn` genes,
Expand Down Expand Up @@ -109,9 +110,7 @@ ggoncoplot <- function(.data,
col_tooltip = col_samples, topn = 10, return_extra_genes_if_tied = FALSE,
palette = NULL,
metadata_palette = NULL,
# metadata_colours_default = c("#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F","#E5C494"),
# metadata_colours_default_logical = c(`TRUE` = "#648fff", `FALSE` = "#dc267f"),
# metadata_colours_missing = "grey90",
copy = c('sample', 'gene', 'tooltip', 'mutation_type', 'nothing'),
metadata = NULL,
col_samples_metadata = col_samples,
cols_to_plot_metadata = NULL,
Expand Down Expand Up @@ -220,6 +219,8 @@ ggoncoplot <- function(.data,
assertions::assert_no_missing(.data[[col_genes]])
assertions::assert_excludes(.data[[col_genes]], illegal = "", msg = "{.strong Gene} column cannot contain zero-length strings") # Asserts no empty string

# Argument matching
copy <- rlang::arg_match(copy)

# Configuration -----------------------------------------------------------
# Properties we might want to tinker with, but not expose to user
Expand Down Expand Up @@ -337,6 +338,7 @@ ggoncoplot <- function(.data,
fontsize_ylab = fontsize_ylab,
fontsize_genes = fontsize_genes,
fontsize_samples = fontsize_samples,
copy = copy,
tile_height = tile_height,
tile_width = tile_width,
colour_backround = colour_backround,
Expand Down Expand Up @@ -640,6 +642,7 @@ ggoncoplot_plot <- function(.data,
fontsize_samples = 10,
tile_height = 1,
tile_width = 1,
copy = c('sample', 'gene', 'tooltip', 'mutation_type', 'nothing'),
colour_backround = "grey90",
colour_mutation_type_unspecified = "grey10",
fontsize_pathway = 16,
Expand All @@ -655,6 +658,7 @@ ggoncoplot_plot <- function(.data,
margin_l = 0.3,
margin_unit = "cm"
) {
copy <- rlang::arg_match(copy)
check_valid_dataframe_column(.data, c("Gene", "Sample", "MutationType", "Tooltip"))

# Invert gene factor levels
Expand All @@ -665,6 +669,16 @@ ggoncoplot_plot <- function(.data,
# Get coords of non-mutated tiles we're going to want to render in grey later
non_mutated_tiles_df <- get_nonmutated_tiles(.data)

# Figure out which colum name to copy on click
copy_column <- dplyr::case_match(
copy,
"sample" ~ "Sample",
"gene" ~ "Gene",
"tooltip" ~ "Tooltip",
"mutation_type" ~ "MutationType",
.default = NA_character_
)

# Create ggplot
gg <- ggplot2::ggplot(
data = .data,
Expand All @@ -682,6 +696,7 @@ ggoncoplot_plot <- function(.data,
ggplot2::aes(
tooltip = Tooltip,
data_id = Sample,
onclick = if (copy == "nothing") NULL else paste0('navigator.clipboard.writeText("',.data[[copy_column]],'")'),
height = {{tile_height}},
width = {{tile_width}}
)
Expand Down
3 changes: 3 additions & 0 deletions man/ggoncoplot.Rd

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

3 changes: 3 additions & 0 deletions man/ggoncoplot_plot.Rd

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

17 changes: 17 additions & 0 deletions vignettes/quick_start.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,23 @@ ggoncoplot(
```


## Customising Interactivity

### Copy on Click

By default, clicking a tile of the oncoplot will copy the sample ID to clipboard. This can be customised using the `copy` argument. For example you can choose to copy the tooltip or gene instead.

```{r}
ggoncoplot(
gbm_df,
col_genes = "Hugo_Symbol",
col_samples = "Tumor_Sample_Barcode",
col_mutation_type = "Variant_Classification",
copy = 'gene' # see ?ggoncoplot for other valid values
)
```


## Static Plots

```{r}
Expand Down

0 comments on commit dd1a270

Please sign in to comment.