-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add plot_granges
#6
Closed
Closed
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
ffbeac3
add integrated shiny.gosling plot embedded into vignette, first pass
lee-t f3dcd5a
minor labels
lee-t b4c4136
Merge branch 'mtmorgan:devel' into vis_shinygosling
lee-t 1886cb4
update suggests w/shiny.gosling, fix runtime and library calls, updat…
lee-t b6a7358
update b_vis vignette. take screenshots for presentation
lee-t 224e5f2
fix knitting error: seperating track objects
lee-t 2aba65e
wrap lolipop plotting in function "plot_shinygosling" examples and ot…
lee-t 7fa6954
Merge branch 'devel' into vis_shinygosling
nturaga 123c788
Remove z_scratch.Rmd after consulting with Tram and Tyronne
nturaga 4bac60a
Remove .Rproj
nturaga 75428d2
Remove d_clinvar.R, fix DESCRIPTION
nturaga ea6f464
Remove .gosling repo
nturaga 1790d52
revert changes to ignores
nturaga 236aa27
Remove .RData
nturaga 9e9170a
Fixes
nturaga 424fe6b
checks for directory .gosling
tram-nguyen-n 4eefe87
modify function; change colormap, change example, fix categories
lee-t 70ca8d6
edit vignettes; remove gosling.shiny vis from intro, add to alphafold
lee-t a4a6785
add contributors to DESCRIPTION
lee-t 94837cf
whitespace DESCRIPTION
lee-t 7f44587
no `gosling` R package
lee-t 64e4de0
fixes for example
lee-t 6dfd4b2
rename as_granges->gr, get_range - > g; fix GRanges accesssors in zoo…
lee-t bbc4def
add validation for input types
lee-t b9b7388
use cache for gosling dir
lee-t af48390
add tooltips to lolipop plot
lee-t 96fa7f5
'plot_type' selects between bars and lolipop plots
lee-t e6137b2
replace tabs with spaces (on Windows-1252)
lee-t b4a28bb
text and example changes to alphafold.Rmd; fix spelling of 'lollipop'
lee-t c265cf2
remove runtime from intro
lee-t 00c57a7
sync help page for plot_shinygosling.rd
lee-t 0c66dc9
fixing vignettes, trying to pass R CMD check
lee-t 963a9ff
imports and cache creation reverted
lee-t 008b5d6
reverting importFrom, cache order
lee-t e32322f
found the missing visual channel imports.
lee-t 48a0558
some message suppression and link fixes
lee-t 916e254
some cosmetics to the gosling section
lgeistlinger a24edaa
Rename plot_shinygosling to match function. Edit documentation wordin…
lee-t 73f173d
change function indentation and input granges name
lee-t 57cbc97
combine assertions into one `stopifnot()`, `plot_type` is already che…
lee-t c9e9088
change to use `identical()`
lee-t c65a351
format example
lee-t b0b5a45
reformat DESCRIPTION
lee-t aa46568
change @details
lee-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
#' @rdname plot_granges | ||
#' | ||
#' @title Plot a GRanges object using Shiny and Gosling | ||
#' | ||
#' @description This function creates a Shiny app that displays a | ||
#' Gosling plot of a given GRanges object. It visualizes genomic | ||
#' ranges with both rectangle and point representations, and | ||
#' allows for customization of the plot title and subtitle. | ||
|
||
#' @details | ||
#' The function supports 2 types of plots as selected through the `plot_type` | ||
#' argument: (1) a barplot-like view of the pathogenicity score at each position, | ||
#' similar to a sequencing coverage plot, and (2) a lollipop plot focusing on | ||
#' the pathogenicity classification (ambiguous, benign, pathogenic) at each | ||
#' position. It requires that the [`GRanges`] object has the following metadata | ||
#' columns: 'am_class' (effect classification),'am_pathogenicity' | ||
#' (pathogenicity score), 'ALT' (alternative allele) and 'REF' | ||
#' (reference allele). | ||
|
||
#' @param gr A [`GRanges`] object containing the genomic ranges to | ||
#' be plotted. | ||
#' @param title character(1) Title of the plot. Default is | ||
#' "GRanges Plot". | ||
#' @param subtitle character(1) The subtitle of the plot. Default | ||
#' is "Stacked nucleotide example". | ||
#' @param plot_type character(1) Select the type of gosling plot. | ||
#' Default is "bars". | ||
#' - "bars": Stacked bar plot with height based on pathogenicity score, | ||
#' - "lollipop": variation of a bar chart where the bar is replaced with a | ||
#' line and a dot at the end to show mutation variations. | ||
#' | ||
#' @return A `shinyApp` object that, when run, displays the Gosling | ||
#' plot. | ||
#' | ||
#' @note This function requires the `shiny`, `shiny.gosling`, and `GenomicRanges` | ||
#' packages to be installed. | ||
#' | ||
#' @examples | ||
#' if (requireNamespace("GenomicRanges")) { | ||
#' | ||
#' ## Create a sample GRanges object from AlphamissenseR | ||
#' gpos <- | ||
#' am_data("hg38") |> | ||
#' filter(uniprot_id == "Q1W6H9") |> | ||
#' to_GPos() | ||
#' | ||
#' ## Plot the GRanges object | ||
#' plot_granges( | ||
#' gpos, mode = "bar", title = "Q1W6H_track", | ||
#' subtitle = "bar plot example" | ||
#' ) | ||
#'} | ||
#' | ||
#' | ||
#' | ||
#' @export | ||
plot_granges <- | ||
function(gr_input, | ||
title = "GRanges Plot", | ||
subtitle = "Stacked nucleotide example", | ||
plot_type = "bars") | ||
{ | ||
## Validate input | ||
stopifnot( | ||
is(granges, "GRanges"), | ||
isScalarCharacter(title), | ||
isScalarCharacter(subtitle), | ||
isScalarCharacter(plot_type) | ||
) | ||
|
||
## Define categories and color mapping | ||
categories <- c("likely_benign", "ambiguous", "likely_pathogenic") | ||
colormapping <- c("#89d5f5", "gray", "#f56c6c") | ||
|
||
## Turns out gr must be coerced to GRanges(), will look into this later | ||
gr_input <- as(gr_input, "GRanges") | ||
## Get range from GRanges object | ||
r <- range(gr_input) | ||
|
||
# This fixes the bug if .gosling directory does not already exist | ||
if (!dir.exists(".gosling")){ | ||
dir.create(".gosling") | ||
} | ||
|
||
## Prepare track data | ||
track_data <- shiny.gosling::track_data_gr( | ||
gr_input, | ||
chromosomeField = "seqnames", | ||
genomicFields = c("start", "end") | ||
) | ||
|
||
|
||
## trigger the option for bars or lollipop | ||
if (identical(plot_type, "bars")){ | ||
#define single track | ||
track_bar <- shiny.gosling::add_single_track( | ||
width = 800, | ||
height = 180, | ||
data = track_data, | ||
mark = "bar", | ||
x = shiny.gosling::visual_channel_x( | ||
field = "start", type = "genomic", axis = "bottom" | ||
), | ||
xe = shiny.gosling::visual_channel_x(field = "end", type = "genomic"), | ||
y = shiny.gosling::visual_channel_y( | ||
field = "am_pathogenicity", type = "quantitative", axis = "right" | ||
), | ||
color = shiny.gosling::visual_channel_color( | ||
field = "am_pathogenicity", | ||
type = "quantitative" | ||
), | ||
tooltip = shiny.gosling::visual_channel_tooltips( | ||
shiny.gosling::visual_channel_tooltip(field = "REF", type = "nominal", | ||
alt = "Reference"), | ||
shiny.gosling::visual_channel_tooltip(field = "ALT", type = "nominal", | ||
alt = "Alternative / Mutation"), | ||
shiny.gosling::visual_channel_tooltip( | ||
field = "am_pathogenicity", | ||
type = "quantitative", | ||
alt = "AM_Pathogenicity Score", | ||
format = "0.2" | ||
) ), | ||
size = list(value = 5) | ||
) | ||
|
||
composed_view <- shiny.gosling::compose_view( | ||
layout = "linear", | ||
xDomain = list(chromosome = as.character(seqnames(r)), | ||
interval = c(start(r), end(r))), | ||
tracks = track_bar | ||
|
||
) | ||
|
||
## other option | ||
} else if (identical(plot_type, "lollipop")){ | ||
|
||
## Define multi tracks | ||
track_ref <- shiny.gosling::add_single_track( | ||
data = track_data, | ||
mark = "rect", | ||
x = shiny.gosling::visual_channel_x(field = "start", type = "genomic", axis = "top"), | ||
xe = shiny.gosling::visual_channel_x(field = "end", type = "genomic"), | ||
size = list(value = 50), | ||
stroke = "lightgrey", | ||
strokeWidth = list(value = 1), | ||
opacity = list(value = 0.3) | ||
) | ||
|
||
track_alt <- shiny.gosling::add_single_track( | ||
data = track_data, | ||
mark = "point", | ||
x = shiny.gosling::visual_channel_x(field = "start", type = "genomic", axis = "top"), | ||
xe = shiny.gosling::visual_channel_x(field = "end", type = "genomic"), | ||
y = shiny.gosling::visual_channel_y(field = "am_class", type="nominal", | ||
domain= categories, axis = "left",baseline = "ambiguous" ), | ||
text = list(field = "ALT", type = "nominal"), | ||
size = list(value = 5), | ||
tooltip = shiny.gosling::visual_channel_tooltips( | ||
shiny.gosling::visual_channel_tooltip(field = "REF", type = "nominal", | ||
alt = "Reference"), | ||
shiny.gosling::visual_channel_tooltip(field = "ALT", type = "nominal", | ||
alt = "Alternative / Mutation"), | ||
shiny.gosling::visual_channel_tooltip( | ||
field = "am_pathogenicity", | ||
type = "quantitative", | ||
alt = "AM_Pathogenicity Score", | ||
format = "0.2" | ||
) ) | ||
) | ||
|
||
## Compose view | ||
composed_view <- shiny.gosling::compose_view( | ||
width = 800, | ||
height = 180, | ||
multi = TRUE, | ||
layout = "linear", | ||
xDomain = list( | ||
chromosome = as.character(seqnames(r)), | ||
interval = c(start(r), end(r)) | ||
), | ||
alignment = "overlay", | ||
color = shiny.gosling::visual_channel_color( | ||
field = "am_class", | ||
type = "nominal", | ||
domain = categories, | ||
baseline = "ambiguous", | ||
range = colormapping, | ||
legend = TRUE | ||
), | ||
tracks = shiny.gosling::add_multi_tracks(track_ref, track_alt) | ||
) | ||
|
||
} | ||
## trigger check | ||
else { | ||
stop("Invalid plot_type. Use 'bars' or 'lollipop'") | ||
} | ||
## Arrange into view | ||
arranged_view3 <- shiny.gosling::arrange_views( | ||
title = title, | ||
subtitle = subtitle, | ||
views = composed_view | ||
) | ||
|
||
## Create Shiny app | ||
ui <- shiny::fluidPage( | ||
shiny.gosling::use_gosling(clear_files = FALSE), | ||
shiny.gosling::goslingOutput("gosling_plot") | ||
) | ||
|
||
server <- function(input, output, session) { | ||
output$gosling_plot <- shiny.gosling::renderGosling({ | ||
shiny.gosling::gosling( | ||
component_id = "component_3", | ||
arranged_view3 | ||
) | ||
}) | ||
} | ||
|
||
## Return the Shiny app | ||
shiny::shinyApp(ui, server) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 'white space' changes replace spaces with tabs, but tabs are not used in AlphaMissesnseR. In general PRs should contain the essential changes required for the feature being implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved e6137b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry to be a pain but the original indentation was 8 spaces, not 4 and not tab.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b0b5a45