Here be dragons 🐉
The goal of g(r)osling is to help you build interactive genomics visualizations with Gosling. This package uses reticulate to provide an interface to the Gos Python package.
library(gosling)
data <- gos$bigwig(
url = "https://s3.amazonaws.com/gosling-lang.org/data/ExcitatoryNeurons-insertions_bin100_RIPnorm.bw",
column = "position",
value = "peak"
)
track <- gos$Track(data, height = 100)$mark_point()$encode(
x = gos$X("position:G"),
y = gos$Y("peak:Q")
)
track$view()
You can install the development version of gosling like so:
devtools::install_github("gosling-lang/grosling")
Because of Python, there may be some additional installation steps.
1.) Python must be installed on your system. We recommend conda
.
2.) Create a conda environment called "r-reticulate"
. It is
recommended
to use this environment name for all packages that use reticulate.
3.) Install Gos into your "r-reticulate"
environment using
gosling::install_gosling()
.
You may wish to add a line like this to the .First()
function in your
.Rprofile
:
reticulate::use_condaenv("r-reticulate")
The use_condaenv()
function is called to provide a hint to reticulate
on which Python environment to use.
Gos transparently serves local and in-memory datasets for the Gosling client via a background data server. This feature is enabled automatically whenever a local file path is detected (rather than a URL).
Due to a temporary limitation with
reticulate
,
some additional setup is required to enable this feature in
grosling. Hopefully this will be resolved in reticulate
soon, but
the current workaround is shown below.
library(gosling)
### Setup reticulate to continually yield R <> Python. You only need to run this *once*.
local({
reticulate::py_run_string("from time import sleep")
py_yield_and_register_next_yield <- function() {
reticulate::py_eval("sleep(0.001)")
later::later(py_yield_and_register_next_yield, .001)
invisible()
}
later::later(py_yield_and_register_next_yield)
})
###
file <- "./ExcitatoryNeurons-insertions_bin100_RIPnorm.bw" # local file
data <- gos$bigwig(file, column = "position", value = "peak")
track <- gos$Track(data, height = 100, width = 750)$mark_bar()$encode(
x = gos$X("position:G"),
y = gos$Y("peak:Q"),
color = gos$Color("peak:Q")
)
track$view()