-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
109 lines (76 loc) · 3.26 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(collapse = TRUE)
```
**Here be dragons** 🐉
# g(r)osling
<!-- badges: start -->
<!-- badges: end -->
The goal of **g(r)osling** is to help you build interactive genomics visualizations with
[Gosling](https://github.com/gosling-lang/gosling.js). This package uses
[reticulate](https://rstudio.github.io/reticulate/) to provide an interface
to the [Gos](https://github.com/gosling-lang/gos) Python package.
## Example
```{r, eval = FALSE}
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()
```
![Gosling visualization](https://user-images.githubusercontent.com/24403730/180341226-a9ac36b4-47cb-40d8-bfd2-a2e6f18c153f.png)
## Installation
You can install the development version of gosling like so:
``` r
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](https://rstudio.github.io/reticulate/articles/python_packages.html)
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`:
```r
reticulate::use_condaenv("r-reticulate")
```
The `use_condaenv()` function is called to provide a hint to reticulate on which Python environment to use.
## Local Data
Gos [transparently serves](https://gosling-lang.github.io/gos/user_guide/local_data.html)
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`](https://github.com/rstudio/reticulate/issues/515#issuecomment-1196609327),
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.
```{r load_loop, eval = FALSE}
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()
```
![Gosling visualization using local file](https://user-images.githubusercontent.com/24403730/181269342-9e8d1246-d227-4850-b1ae-66f747654369.png)