Skip to content
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
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
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 May 24, 2024
f3dcd5a
minor labels
lee-t May 28, 2024
b4c4136
Merge branch 'mtmorgan:devel' into vis_shinygosling
lee-t May 28, 2024
1886cb4
update suggests w/shiny.gosling, fix runtime and library calls, updat…
lee-t May 29, 2024
b6a7358
update b_vis vignette. take screenshots for presentation
lee-t Jun 20, 2024
224e5f2
fix knitting error: seperating track objects
lee-t Jun 20, 2024
2aba65e
wrap lolipop plotting in function "plot_shinygosling" examples and ot…
lee-t Jul 29, 2024
7fa6954
Merge branch 'devel' into vis_shinygosling
nturaga Jul 29, 2024
123c788
Remove z_scratch.Rmd after consulting with Tram and Tyronne
nturaga Jul 29, 2024
4bac60a
Remove .Rproj
nturaga Jul 29, 2024
75428d2
Remove d_clinvar.R, fix DESCRIPTION
nturaga Jul 29, 2024
ea6f464
Remove .gosling repo
nturaga Jul 29, 2024
1790d52
revert changes to ignores
nturaga Jul 29, 2024
236aa27
Remove .RData
nturaga Jul 29, 2024
9e9170a
Fixes
nturaga Jul 29, 2024
424fe6b
checks for directory .gosling
tram-nguyen-n Jul 29, 2024
4eefe87
modify function; change colormap, change example, fix categories
lee-t Jul 29, 2024
70ca8d6
edit vignettes; remove gosling.shiny vis from intro, add to alphafold
lee-t Jul 29, 2024
a4a6785
add contributors to DESCRIPTION
lee-t Jul 29, 2024
94837cf
whitespace DESCRIPTION
lee-t Jul 29, 2024
7f44587
no `gosling` R package
lee-t Aug 2, 2024
64e4de0
fixes for example
lee-t Aug 2, 2024
6dfd4b2
rename as_granges->gr, get_range - > g; fix GRanges accesssors in zoo…
lee-t Aug 6, 2024
bbc4def
add validation for input types
lee-t Aug 6, 2024
b9b7388
use cache for gosling dir
lee-t Aug 6, 2024
af48390
add tooltips to lolipop plot
lee-t Aug 6, 2024
96fa7f5
'plot_type' selects between bars and lolipop plots
lee-t Aug 6, 2024
e6137b2
replace tabs with spaces (on Windows-1252)
lee-t Aug 7, 2024
b4a28bb
text and example changes to alphafold.Rmd; fix spelling of 'lollipop'
lee-t Aug 7, 2024
c265cf2
remove runtime from intro
lee-t Aug 7, 2024
00c57a7
sync help page for plot_shinygosling.rd
lee-t Aug 7, 2024
0c66dc9
fixing vignettes, trying to pass R CMD check
lee-t Aug 7, 2024
963a9ff
imports and cache creation reverted
lee-t Aug 7, 2024
008b5d6
reverting importFrom, cache order
lee-t Aug 7, 2024
e32322f
found the missing visual channel imports.
lee-t Aug 7, 2024
48a0558
some message suppression and link fixes
lee-t Aug 21, 2024
916e254
some cosmetics to the gosling section
lgeistlinger Aug 21, 2024
a24edaa
Rename plot_shinygosling to match function. Edit documentation wordin…
lee-t Sep 17, 2024
73f173d
change function indentation and input granges name
lee-t Sep 19, 2024
57cbc97
combine assertions into one `stopifnot()`, `plot_type` is already che…
lee-t Sep 19, 2024
c9e9088
change to use `identical()`
lee-t Sep 19, 2024
c65a351
format example
lee-t Sep 19, 2024
b0b5a45
reformat DESCRIPTION
lee-t Sep 19, 2024
aa46568
change @details
lee-t Sep 19, 2024
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
78 changes: 42 additions & 36 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,70 @@ Package: AlphaMissenseR
Title: Accessing AlphaMissense Data Resources in R
Version: 1.1.5
Authors@R:
c(person(
c(person(
"Martin", "Morgan", role = c("aut", "cre"),
Copy link
Owner

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved e6137b2

Copy link
Owner

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.

Copy link
Author

@lee-t lee-t Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email = "mtmorgan.xyz@gmail.com",
comment = c(ORCID = "0000-0002-5874-8148")
), person(
), person(
"Tram", "Nguyen",
role = "aut"
), person(
), person(
"Tyrone", "Lee",
role = "ctb"
), person(
"Nitesh", "Turaga",
role = "ctb"
), person(
"Chan Zuckerberg Initiative DAF CZF2019-002443",
role = "fnd"
), person(
), person(
"NIH NCI ITCR U24CA180996",
role = "fnd"
), person(
), person(
"NIH NCI IOTN U24CA232979",
role = "fnd"
), person(
), person(
"NIH NCI ARTNet U24CA274159",
role = "fnd"
))
))
Description:
The AlphaMissense publication
<https://www.science.org/doi/epdf/10.1126/science.adg7492>
outlines how a variant of AlphaFold / DeepMind was used to predict
missense variant pathogenicity. Supporting data on Zenodo
<https://zenodo.org/record/10813168> include, for instance, 71M
variants across hg19 and hg38 genome builds. The 'AlphaMissenseR'
package allows ready access to the data, downloading individual
files to DuckDB databases for exploration and integration into *R*
and *Bioconductor* workflows.
The AlphaMissense publication
<https://www.science.org/doi/epdf/10.1126/science.adg7492>
outlines how a variant of AlphaFold / DeepMind was used to predict
missense variant pathogenicity. Supporting data on Zenodo
<https://zenodo.org/record/10813168> include, for instance, 71M
variants across hg19 and hg38 genome builds. The 'AlphaMissenseR'
package allows ready access to the data, downloading individual
files to DuckDB databases for exploration and integration into *R*
and *Bioconductor* workflows.
License: Artistic-2.0
URL: https://mtmorgan.github.io/AlphaMissenseR/
BugReports: https://github.com/mtmorgan/AlphaMissenseR/issues
Depends:
R (>= 4.3.0),
dplyr
R (>= 4.3.0),
dplyr
Imports:
rjsoncons (>= 1.0.1), DBI, duckdb (>= 0.9.1), rlang,
curl, BiocFileCache, spdl, memoise, BiocBaseUtils,
utils, stats, methods, whisker, ggplot2
rjsoncons (>= 1.0.1), DBI, duckdb (>= 0.9.1), rlang,
curl, BiocFileCache, spdl, memoise, BiocBaseUtils,
utils, stats, methods, whisker, ggplot2
Suggests:
BiocManager,
BiocGenerics,
GenomicRanges,
GenomeInfoDb,
AnnotationHub,
ensembldb,
httr,
tidyr,
r3dmol, bio3d, shiny,
colorspace,
knitr,
rmarkdown,
testthat (>= 3.0.0)
BiocManager,
BiocGenerics,
GenomicRanges,
GenomeInfoDb,
AnnotationHub,
ensembldb,
httr,
tidyr,
r3dmol, bio3d, shiny, shiny.gosling,
colorspace,
knitr,
rmarkdown,
testthat (>= 3.0.0)
biocViews: SNP, Annotation, FunctionalGenomics, StructuralPrediction,
Transcriptomics, VariantAnnotation, GenePrediction, ImmunoOncology
Transcriptomics, VariantAnnotation, GenePrediction, ImmunoOncology
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
VignetteBuilder: knitr
Config/testthat/edition: 3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(db_disconnect_all)
export(db_range_join)
export(db_tables)
export(db_temporary_table)
export(plot_granges)
export(to_GPos)
importFrom(BiocBaseUtils,isCharacter)
importFrom(BiocBaseUtils,isScalarCharacter)
Expand Down
222 changes: 222 additions & 0 deletions R/plot_granges.R
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)
}
Loading