
Introduction to shiny.gosling
intro.Rmd
library(shiny.gosling)
library(shiny)
library(sessioninfo)
Introduction to shiny.gosling
This package is an R shiny implementation of the Gosling.js library. Gosling js is a highly expressive library based on a Grammar for scalable and interactive Genomics Data visualization. This library is build upon the React wrapper of the Gosling.js. Which is powered by Shiny.React. Thus most of the Charts can be directly build using this package.
Let’s start with an example. For that let’s read a csv file which has some Genomic data with chromosome start stop indicators. This dataset is directly picked from github here. You can read more about the dataset by going to there website here. In short GEMINI (Genome MINIng) is a flexible framework for exploring genetic variation in the context of the wealth of genome annotations available for the human genome.
gemini_github_path <- "https://raw.githubusercontent.com/sehilyi/gemini-datasets/master/data/UCSC.HG38.Human.CytoBandIdeogram.csv" # nolint
cancer_data <- "https://s3.amazonaws.com/gosling-lang.org/data/cancer/cnv.PD35930a.csv"
cancer_rearranged_data <- "https://s3.amazonaws.com/gosling-lang.org/data/cancer/cnv.PD35930a.csv"
cistrome_data <- "https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec"
In shiny.gosling we can basically create tracks from data and then
create view from tracks. To understand how to build a plot let’s
understand 3 basic principles of gosling.js
-
Track
contains data, layout, height, width and all aesthetics etc… - One or more Track combine together create a
View
- One or more views combine together create a
Plot
.
This is how a plot is created in Gosling. Let’s visit this one by one.
Let’s start by creating a track. Let’s define the first track and add
more properties to the track. With shiny.gosling
you can be
specific about the colors and ranges and channel.
Let’s build the layers for the plot. So we can build multiple tracks
to represent the genome. add_single_track
function
constructs a single track from the inputs.
single_track <- add_single_track(
id = "track1",
data = track_data(
url = cistrome_data,
type = "multivec",
row = "sample",
column = "position",
value = "peak",
categories = c("sample 1", "sample 2", "sample 3", "sample 4"),
binSize = 4,
),
mark = "rect",
x = visual_channel_x(field = "start", type = "genomic", axis = "top"),
xe = visual_channel_x(field = "end", type = "genomic"),
row = visual_channel_row(
field = "sample",
type = "nominal",
legend = TRUE
),
color = visual_channel_color(
field = "peak",
type = "quantitative",
legend = TRUE
),
tooltip = visual_channel_tooltips(
visual_channel_tooltip(field = "start", type = "genomic", alt = "Start Position"),
visual_channel_tooltip(field = "end", type = "genomic", alt = "End Position"),
visual_channel_tooltip(
field = "peak",
type = "quantitative",
alt = "Value",
format = "0.2"
)
),
width = 600,
height = 130
)
now let’s create a final view for the
single_composed_track <- compose_view(
tracks = single_track
)
single_composed_views <- arrange_views(
title = "Single Track",
subtitle = "This is the simplest single track visualization with a linear layout",
layout = "circular",
views = single_composed_track,
xDomain = list(
chromosome = "chr1",
interval = c(1, 3000500)
)
)
We can then even add more tracks to it. So let’s create a few more tracks just to make a better and more beautiful graph.
session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.2.3 (2023-03-15)
#> os Ubuntu 22.04.2 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz UTC
#> date 2023-04-20
#> pandoc 2.19.2 @ /usr/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> bslib 0.4.2 2022-12-16 [1] RSPM
#> cachem 1.0.7 2023-02-24 [1] RSPM
#> cli 3.6.1 2023-03-23 [1] RSPM
#> desc 1.4.2 2022-09-08 [1] RSPM
#> digest 0.6.31 2022-12-11 [1] RSPM
#> ellipsis 0.3.2 2021-04-29 [1] RSPM
#> evaluate 0.20 2023-01-17 [1] RSPM
#> fastmap 1.1.1 2023-02-24 [1] RSPM
#> fs 1.6.1 2023-02-06 [1] RSPM
#> glue 1.6.2 2022-02-24 [1] RSPM
#> htmltools 0.5.5 2023-03-23 [1] RSPM
#> httpuv 1.6.9 2023-02-14 [1] RSPM
#> jquerylib 0.1.4 2021-04-26 [1] RSPM
#> jsonlite 1.8.4 2022-12-06 [1] RSPM
#> knitr 1.42 2023-01-25 [1] RSPM
#> later 1.3.0 2021-08-18 [1] RSPM
#> lifecycle 1.0.3 2022-10-07 [1] RSPM
#> magrittr 2.0.3 2022-03-30 [1] RSPM
#> memoise 2.0.1 2021-11-26 [1] RSPM
#> mime 0.12 2021-09-28 [1] RSPM
#> pkgdown 2.0.7 2022-12-14 [1] any (@2.0.7)
#> promises 1.2.0.1 2021-02-11 [1] RSPM
#> purrr 1.0.1 2023-01-10 [1] RSPM
#> R6 2.5.1 2021-08-19 [1] RSPM
#> ragg 1.2.5 2023-01-12 [1] RSPM
#> Rcpp 1.0.10 2023-01-22 [1] RSPM
#> rlang 1.1.0 2023-03-14 [1] RSPM
#> rmarkdown 2.21 2023-03-26 [1] RSPM
#> rprojroot 2.0.3 2022-04-02 [1] RSPM
#> sass 0.4.5 2023-01-24 [1] RSPM
#> sessioninfo * 1.2.2 2021-12-06 [1] RSPM
#> shiny * 1.7.4 2022-12-15 [1] RSPM
#> shiny.gosling * 0.99.1 2023-04-20 [1] local
#> shiny.react 0.3.0 2022-12-25 [1] RSPM
#> stringi 1.7.12 2023-01-11 [1] RSPM
#> stringr 1.5.0 2022-12-02 [1] RSPM
#> systemfonts 1.0.4 2022-02-11 [1] RSPM
#> textshaping 0.3.6 2021-10-13 [1] RSPM
#> vctrs 0.6.1 2023-03-22 [1] RSPM
#> xfun 0.38 2023-03-24 [1] RSPM
#> xtable 1.8-4 2019-04-21 [1] RSPM
#> yaml 2.3.7 2023-01-23 [1] RSPM
#>
#> [1] /home/runner/work/_temp/Library
#> [2] /opt/R/4.2.3/lib/R/site-library
#> [3] /opt/R/4.2.3/lib/R/library
#>
#> ──────────────────────────────────────────────────────────────────────────────