|
a |
|
b/docs/interactive.Rmd |
|
|
1 |
--- |
|
|
2 |
title: "Interactive" |
|
|
3 |
output: |
|
|
4 |
html_document: |
|
|
5 |
toc: true |
|
|
6 |
toc_float: |
|
|
7 |
collapsed: false |
|
|
8 |
smooth_scroll: false |
|
|
9 |
--- |
|
|
10 |
|
|
|
11 |
<style> |
|
|
12 |
.title{ |
|
|
13 |
display: none; |
|
|
14 |
} |
|
|
15 |
body { |
|
|
16 |
text-align: justify |
|
|
17 |
} |
|
|
18 |
.center { |
|
|
19 |
display: block; |
|
|
20 |
margin-left: auto; |
|
|
21 |
margin-right: auto; |
|
|
22 |
} |
|
|
23 |
</style> |
|
|
24 |
|
|
|
25 |
```{css, echo=FALSE} |
|
|
26 |
.watch-out { |
|
|
27 |
color: black; |
|
|
28 |
} |
|
|
29 |
``` |
|
|
30 |
|
|
|
31 |
```{r setup, include=FALSE} |
|
|
32 |
# use rmarkdown::render_site(envir = knitr::knit_global()) |
|
|
33 |
knitr::opts_chunk$set(highlight = TRUE, echo = TRUE) |
|
|
34 |
``` |
|
|
35 |
|
|
|
36 |
<br> |
|
|
37 |
|
|
|
38 |
# Interactive Annotation |
|
|
39 |
|
|
|
40 |
**VoltRon** includes interactive applications to select and manually label spatial points by drawing polygons and circles. As an example, we will use a Spot-based spatial transcriptomic assay, specifically the **Mouse Brain Serial Section 1/2** datasets, analyzed in the [Niche Clustering](nicheclustering.html) tutorial. You can find the already analyzed data stored as a VoltRon object [here](https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/NicheClustering/Visium&Visium_data_decon_analyzed.rds) |
|
|
41 |
|
|
|
42 |
```{r class.source="watch-out", eval = FALSE} |
|
|
43 |
MBrain_Sec <- readRDS("Visium&Visium_data_decon_analyzed.rds") |
|
|
44 |
``` |
|
|
45 |
|
|
|
46 |
We can start annotating the spatial assay. By passing arguments used by the **vrSpatialPlot** function to visualize labels (e.g. clusters), we can better select regions within tissue sections for annotation. |
|
|
47 |
|
|
|
48 |
```{r class.source="watch-out", eval = FALSE} |
|
|
49 |
MBrain_Sec <- annotateSpatialData(MBrain_Sec, assay = "Assay1", |
|
|
50 |
group.by = "clusters", label = "annotation") |
|
|
51 |
``` |
|
|
52 |
|
|
|
53 |
<img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/interactive_annotation.png" class="center"> |
|
|
54 |
|
|
|
55 |
<br> |
|
|
56 |
|
|
|
57 |
Here, **annotateSpatialData** function not only labels spots with within regions of interests (ROIs) selected by the user, but also records these regions in ROI assays within the same layer of the annotated Visium assay. The new assay type will be given the name **ROIAnnotations** if otherwise not specified using the **annotation_assay** arguement in the function. |
|
|
58 |
|
|
|
59 |
```{r class.source="watch-out", eval = FALSE} |
|
|
60 |
MBrain_Sec |
|
|
61 |
``` |
|
|
62 |
|
|
|
63 |
``` |
|
|
64 |
VoltRon Object |
|
|
65 |
Anterior: |
|
|
66 |
Layers: Section1 Section2 |
|
|
67 |
Posterior: |
|
|
68 |
Layers: Section1 Section2 |
|
|
69 |
Assays: Visium_decon(Main) Visium ROIAnnotation |
|
|
70 |
``` |
|
|
71 |
|
|
|
72 |
```{r class.source="watch-out", eval = FALSE} |
|
|
73 |
MBrain_Sec@sample.metadata |
|
|
74 |
``` |
|
|
75 |
|
|
|
76 |
``` |
|
|
77 |
> MBrain_Sec@sample.metadata |
|
|
78 |
Assay Layer Sample |
|
|
79 |
Assay1 Visium Section1 Anterior |
|
|
80 |
Assay2 Visium Section2 Anterior |
|
|
81 |
Assay3 Visium Section1 Posterior |
|
|
82 |
Assay4 Visium Section2 Posterior |
|
|
83 |
Assay5 ROIAnnotation Section1 Anterior |
|
|
84 |
``` |
|
|
85 |
|
|
|
86 |
The new annotations are available in the metadata of the spot assay (default assay in this object) and can be visualized if wanted. |
|
|
87 |
|
|
|
88 |
```{r class.source="watch-out", eval = FALSE} |
|
|
89 |
head(Metadata(MBrain_Sec)) |
|
|
90 |
``` |
|
|
91 |
|
|
|
92 |
``` |
|
|
93 |
Count Assay Layer Sample clusters annotation |
|
|
94 |
AAACAAGTATCTCCCA-1_Assay1 1 Visium_decon Section1 Anterior 1 Region 3 |
|
|
95 |
AAACACCAATAACTGC-1_Assay1 1 Visium_decon Section1 Anterior 3 undefined |
|
|
96 |
AAACAGAGCGACTCCT-1_Assay1 1 Visium_decon Section1 Anterior 4 undefined |
|
|
97 |
AAACAGCTTTCAGAAG-1_Assay1 1 Visium_decon Section1 Anterior 5 Region 1 |
|
|
98 |
AAACAGGGTCTATATT-1_Assay1 1 Visium_decon Section1 Anterior 5 Region 1 |
|
|
99 |
AAACATGGTGAGAGGA-1_Assay1 1 Visium_decon Section1 Anterior 3 undefined |
|
|
100 |
``` |
|
|
101 |
|
|
|
102 |
```{r class.source="watch-out", eval = FALSE} |
|
|
103 |
vrSpatialPlot(MBrain_Sec, assay = "Assay1", group.by = "annotation") |
|
|
104 |
``` |
|
|
105 |
|
|
|
106 |
<img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/interactive_annotation_plot.png" class="center"> |
|
|
107 |
|
|
|
108 |
<br> |
|
|
109 |
|
|
|
110 |
You can also overlay the ROI annotations with the clustered spots to visualize multiple assays in the same time. |
|
|
111 |
|
|
|
112 |
```{r class.source="watch-out", eval = FALSE} |
|
|
113 |
library(ggnewscale) |
|
|
114 |
vrSpatialPlot(MBrain_Sec, assay = "Assay1", group.by = "clusters") |> |
|
|
115 |
addSpatialLayer(MBrain_Sec, assay = "Assay5", group.by = "annotation", alpha = 0.7) |
|
|
116 |
``` |
|
|
117 |
|
|
|
118 |
<img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/interactive_annotation_example_overlay_plot.png" class="center"> |
|
|
119 |
|
|
|
120 |
<br> |
|
|
121 |
|
|
|
122 |
# Interactive Visualization |
|
|
123 |
|
|
|
124 |
VoltRon incorporates utilities |
|
|
125 |
|
|
|
126 |
* **(i)** to convert VoltRon objects into other spatial data objects and files that could be used platforms, and |
|
|
127 |
* **(ii)** to incorporate wrapper functions to call methods from package that achieves interactive visualization |
|
|
128 |
|
|
|
129 |
<br> |
|
|
130 |
|
|
|
131 |
## Vitessce |
|
|
132 |
|
|
|
133 |
We will transform VoltRon objects of Xenium data into zarr arrays, and use them for interactive visualization in [Vitessce](http://vitessce.io/). We should first download the vitessceR package which incorporates wrapper function to visualize zarr arrays interactively in R. |
|
|
134 |
|
|
|
135 |
```{r class.source="watch-out", eval = FALSE} |
|
|
136 |
if (!require("devtools", quietly = TRUE)) |
|
|
137 |
install.packages("devtools") |
|
|
138 |
if (!require("vitessceR", quietly = TRUE)) |
|
|
139 |
devtools::install_github("Artur-man/vitessceR") |
|
|
140 |
``` |
|
|
141 |
|
|
|
142 |
We can convert the VoltRon object into an anndata object and save it as a a zarr array using the **as.AnnData** function which will create the array in the specified location. We use the **flip_coordinates=TRUE** argument to flip the coordinates of cells vertically, hence match it with the top to bottom system of the background DAPI image. Also, we can save an OMETIFF file of the DAPI image using **create.ometiff** arguement to be used by vitessceR later. |
|
|
143 |
|
|
|
144 |
```{r class.source="watch-out", eval = FALSE} |
|
|
145 |
xenium_data <- as.AnnData(xenium_data, file = "xenium_data.zarr", assay = "Xenium", |
|
|
146 |
flip_coordinates = TRUE, create.ometiff = TRUE) |
|
|
147 |
``` |
|
|
148 |
|
|
|
149 |
<br> |
|
|
150 |
|
|
|
151 |
We can use the zarr file directly in the **vrSpatialPlot** function to visualize the zarr array interactively in Rstudio viewer. The **reduction** arguement allows the umap of the Xenium data to be visualized alongside with the spatial coordinates of the Xenium cells (thus associated cell segmentations). |
|
|
152 |
|
|
|
153 |
```{r class.source="watch-out", eval = FALSE} |
|
|
154 |
vrSpatialPlot("xenium_data.zarr", group.by = "clusters", reduction = "umap") |
|
|
155 |
``` |
|
|
156 |
|
|
|
157 |
<img width="90%" height="90%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/interactive_vitessce.png" class="center"> |
|
|
158 |
|
|
|
159 |
<br> |
|
|
160 |
|
|
|
161 |
The vitessce application in the viewer pane allows visualizing background DAPI image and segmentations simultaneously while allowing users to zoom in and control the pane for advanced visualization. |
|
|
162 |
|
|
|
163 |
<img width="90%" height="90%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/interactive_vitessce_zoom.png" class="center"> |
|
|
164 |
|
|
|
165 |
<br> |
|
|
166 |
|
|
|
167 |
## TissUUmaps |
|
|
168 |
|
|
|
169 |
To use **TissUUmaps** for interactive investigation of your spatial omic data, we first need to convert the VoltRon object into an anndata object. However, this time we save the anndata object as an h5ad array using again the **as.AnnData** function which will create the array in the specified location. We use the **flip_coordinates=TRUE** argument to flip the coordinates of cells vertically, hence match it with the top to bottom system of the background DAPI image. |
|
|
170 |
|
|
|
171 |
```{r class.source="watch-out", eval = FALSE} |
|
|
172 |
as.AnnData(xenium_data, file = "xenium_data.h5ad", assay = "Xenium", flip_coordinates = TRUE) |
|
|
173 |
``` |
|
|
174 |
|
|
|
175 |
To use **TissUUmaps**, you can follow the instructions [here](https://tissuumaps.github.io/installation/). Once installed and executed, simply drag and drop the h5ad file to the main panel of the application |
|
|
176 |
|
|
|
177 |
<img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/interactive_tissuumaps.png" class="center"> |
|
|
178 |
|
|
|
179 |
<br> |
|
|
180 |
|
|
|
181 |
## VoltRon |
|
|
182 |
|
|
|
183 |
You can also use the built-in Shiny-based interactive visualizers of the VoltRon package by calling **interactive=TRUE**. You can zoom in by drawing a box on the plot and double-clicking in the selected area. |
|
|
184 |
|
|
|
185 |
```{r class.source="watch-out", eval = FALSE} |
|
|
186 |
vrSpatialPlot(xenium_data, group.by = "clusters", plot.segments = TRUE, interactive = TRUE) |
|
|
187 |
``` |
|
|
188 |
|
|
|
189 |
<img width="85%" height="85%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/interactive_voltron.png" class="center"> |
|
|
190 |
|
|
|
191 |
<br> |
|
|
192 |
|