Diff of /docs/spotanalysis.Rmd [000000] .. [413088]

Switch to unified view

a b/docs/spotanalysis.Rmd
1
---
2
title: "Cell/Spot Analysis"
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
# Xenium Data Analysis
39
40
VoltRon is an end-to-end spatial omic analysis package which also supports investigating spatial points in single cell resolution. VoltRon includes essential built-in functions capable of **filtering**, **processing** and **clustering** as well as **visualizing** spatial datasets with a goal of cell type discovery and annotation. 
41
42
In this use case, we analyse readouts of the experiments conducted on example tissue sections analysed by the [Xenium In Situ](https://www.10xgenomics.com/platforms/xenium) platform. Two tissue sections of 5 $\mu$m tickness are derived from a single formalin-fixed, paraffin-embedded (FFPE) breast cancer tissue block. More information on the spatial datasets and the study can be also be found on the [BioArxiv preprint](https://www.biorxiv.org/content/10.1101/2022.10.06.510405v1).
43
 
44
You can import these readouts from the [10x Genomics website](https://www.10xgenomics.com/products/xenium-in-situ/preview-dataset-human-breast) (specifically, import **In Situ Replicate 1/2**). Alternatively, you can **download a zipped collection of Xenium readouts** from [here](https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/SpatialDataAlignment/Xenium_vs_Visium/10X_Xenium_Visium.zip). 
45
46
<br>
47
48
## Building VoltRon objects
49
50
VoltRon includes built-in functions for converting readouts of Xenium experiments into VoltRon objects. The **importXenium** function locates all readout documents under the output folder of the Xenium experiment, and forms a VoltRon object. We will import both Xenium replicates separately, and merge them after some image manipulation.
51
52
```{r eval = FALSE, class.source="watch-out"}
53
library(VoltRon)
54
Xen_R1 <- importXenium("Xenium_R1/outs", sample_name = "XeniumR1", import_molecules = TRUE)
55
Xen_R2 <- importXenium("Xenium_R2/outs", sample_name = "XeniumR2", import_molecules = TRUE)
56
```
57
58
Before moving on to the downstream analysis of the imaging-based data, we can inspect both Xenium images. We use the **vrImages** function to call and visualize reference images of all VoltRon objects. Observe that the DAPI image of the second Xenium replicate is dim, hence we might need to increase the brightness.  
59
60
```{r eval = FALSE, class.source="watch-out"}
61
vrImages(Xen_R1)
62
vrImages(Xen_R2)
63
```
64
65
<table>
66
<tbody>
67
  <tr style = "vertical-align: center">
68
  <td style = "width:50%; vertical-align: center"> <img src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/xeniumr1.png" class="center"></td>
69
  <td style = "width:50%; vertical-align: center"> <img src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/xeniumr2.png" class="center"></td>
70
  </tr>
71
</tbody>
72
</table>
73
74
<br>
75
76
We can adjust the brightness of the second Xenium replicate using the **modulateImage** function where we can change the brightness and saturation of the reference image of this VoltRon object. This functionality is optional for VoltRon objects and should be used when images require further adjustments. 
77
78
```{r eval = FALSE, class.source="watch-out"}
79
Xen_R2 <- modulateImage(Xen_R2, brightness = 800)
80
vrImages(Xen_R2)
81
```
82
83
<img width="40%" height="40%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/xeniumr2_new.png" class="center">
84
85
<br>
86
87
Once both VoltRon objects are created and images are well-tuned, we can merge these two into a single VoltRon object. 
88
89
```{r eval = FALSE, class.source="watch-out"}
90
Xen_list <- list(Xen_R1, Xen_R2)
91
Xen_data <- merge(Xen_list[[1]], Xen_list[-1])
92
```
93
94
```
95
VoltRon Object 
96
XeniumR1: 
97
  Layers: Section1 
98
XeniumR2: 
99
  Layers: Section1 
100
Assays: Xenium(Main) 
101
```
102
103
<br>
104
105
## Spatial Visualization
106
107
With **vrSpatialPlot**, we can visualize Xenium experiments in both cellular and subcellular context. Since we have not yet started analyzing raw counts of cells, we can first visualize some transcripts of interest. We first visualize mRNAs of ACTA2, a marker for smooth muscle cell actin, and TCF7, an early exhausted t cell marker. 
108
We can interactively select a subset of interest within the tissue section and visualize the localization of these transcripts. Here we subset a ductal carcinoma niche, and visualize visualize mRNAs of **(i)** ACTA2, a marker for smooth muscle cell actin, and **(ii)** TCF7, an early exhausted t cell marker.
109
110
```{r eval = FALSE, class.source="watch-out"}
111
Xen_R1_subsetinfo <- subset(Xen_R1, interactive = TRUE)
112
Xen_R1_subset <- Xen_R1_subsetinfo$subsets[[1]]
113
vrSpatialPlot(Xen_R1_subset, assay = "Xenium_mol", group.by = "gene",
114
              group.id = c("ACTA2", "KRT15", "TACSTD2", "CEACAM6"), pt.size = 0.2, legend.pt.size = 5)
115
```
116
117
<img width="70%" height="70%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_transcripts_visualize.png" class="center">
118
119
We can also visualize count data of cells in the Xenium replicates. The behaviour of **vrSpatialFeaturePlot** (and most plotting functions in VoltRon) depend on the number of assays associated with the assay type (e.g. Xenium is both cell and subcellular type). Here, we have two assays, and we visualize two features, hence the resulting plot would include four panels. Prior to spatial visualization, we can normalize the counts to correct for count depth of cells by **(i)** dividing counts with total counts in each cell, **(ii)** multiply with some constant (default: 10000), and followed by **(iii)** log transformation of the counts.  
120
121
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
122
Xen_data <- normalizeData(Xen_data, sizefactor = 1000)
123
vrSpatialFeaturePlot(Xen_data, features = c("ACTA2", "TCF7"), alpha = 1, pt.size = 0.7)
124
```
125
126
<img width="90%" height="90%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatialfeature_xenium.png" class="center">
127
128
## Processing and Embedding
129
130
Some number of cells in both Xenium replicates might have extremely low counts. Although cells are detected at these locations, the low total counts of cells would make it challenging for phenotyping and clustering these cells. Hence, we remove such cells from the VoltRon objects.
131
132
```{r eval = FALSE, class.source="watch-out"}
133
Xen_data <- subset(Xen_data, Count > 5)
134
```
135
136
VoltRon is capable of reducing dimensionality of datasets using both PCA and UMAP which we gonna use to build profile-specific neighborhood graphs and partition the data into cell types. 
137
138
```{r eval = FALSE, class.source="watch-out"}
139
Xen_data <- getPCA(Xen_data, dims = 20)
140
Xen_data <- getUMAP(Xen_data, dims = 1:20)
141
```
142
143
We can also visualize the normalized expression of these features on embedding spaces (e.g. UMAP) using **vrEmbeddingFeaturePlot** function. 
144
145
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
146
vrEmbeddingFeaturePlot(Xen_data, features = c("LRRC15", "TCF7"), embedding = "umap", 
147
                       pt.size = 0.4)
148
```
149
150
<img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_featureplot_xenium.png" class="center">
151
152
<br>
153
154
## Clustering
155
156
Next, we build neighborhood graphs with the **shared nearest neighbors (SNN)** of cells which are constructed from dimensionally reduced gene expression profiles. The function **getProfileNeighbors** also has an option of building **k-nearest neighbors (kNN)** graphs. 
157
158
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
159
Xen_data <- getProfileNeighbors(Xen_data, dims = 1:20, method = "SNN")
160
vrGraphNames(Xen_data)
161
```
162
163
```
164
[1] "SNN"
165
```
166
167
We can later conduct a clustering of cells using the **leiden's method** from the igraph package, which is utilized with the **getClusters** function.
168
169
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
170
Xen_data <- getClusters(Xen_data, resolution = 1.0, label = "Clusters", graph = "SNN")
171
```
172
173
Now we can label each cell with the associated clustering index and take a look at the clustering accuracy on the embedding space, and we can also visualize these clusters on a spatial context. 
174
175
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
176
vrEmbeddingPlot(Xen_data, group.by = "Clusters", embedding = "umap", 
177
                pt.size = 0.4, label = TRUE)
178
```
179
180
<img width="60%" height="60%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_embedplot_xenium.png" class="center">
181
182
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
183
vrSpatialPlot(Xen_data, group.by = "Clusters", pt.size = 0.18, background.color = "black")
184
```
185
186
<img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatial_xenium.png" class="center">
187
188
<br>
189
190
## Annotation
191
192
We can annotate each of these clusters according to their positive markers across 313 features. One can use the **FindAllMarkers** from the [Seurat](https://satijalab.org/seurat/) package to pinpoint these markers by first utilizing the **as.Seurat** function first on the Xenium assays of the VoltRon object. 
193
194
For more information on conversion to other packages, please visit the [Converting VoltRon Objects](conversion.html).
195
196
Let us create a new metadata feature from the **Clusters** column, called **CellType**, we can insert this new metadata column directly to the object.
197
198
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
199
clusters <- factor(Xen_data$Clusters, levels = sort(unique(Xen_data$Clusters)))
200
levels(clusters) <- c("DCIS_1", 
201
                      "DCIS_2", 
202
                      "CD4_TCells",
203
                      "Adipocytes",
204
                      "PLD4+_LILRA4+_CD4+_Cells",
205
                      "ACTA2_myoepithelial",
206
                      "IT_2",
207
                      "Macrophages",
208
                      "MastCells",
209
                      "Bcells",
210
                      "StromalCells",
211
                      "CD8_TCells",
212
                      "CD8_TCells",
213
                      "EndothelialCells",
214
                      "StromalCells",
215
                      "MyelomaCells",
216
                      "IT_1",
217
                      "IT_2",
218
                      "ACTA2_myoepithelial",
219
                      "DCIS_2",
220
                      "IT_3",
221
                      "KRT15_myoepithelial")
222
Xen_data$CellType <- as.character(clusters)
223
```
224
225
**vrSpatialPlot** function can visualize multiple types of metadata columns, and users can change the location of the legends as well.
226
227
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
228
vrSpatialPlot(Xen_data, group.by = "CellType", pt.size = 0.13, background.color = "black", 
229
              legend.loc = "top", n.tile = 500)
230
```
231
232
<img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatial_xenium_annotated.png" class="center">
233
234
<br>
235
236
# Visium Data Analysis
237
238
Spot-based spatial transcriptomic assays capture spatially-resolved gene expression profiles that are somewhat closer to single cell resolution. However, each spot still include a few number of cells that are likely from a combination of cell types within the tissue of origin. VoltRon analyzes spot level spatial data sets and even allows selecting a highly variable subset of features to cluster spots into meaningful groups of in situ spots for detecting niches of interests
239
240
## Import ST Data
241
242
For this tutorial we will analyze spot-based transcriptomic assays from Mouse Brain generated by the [Visium](https://www.10xgenomics.com/products/spatial-gene-expression) instrument. 
243
244
You can find and download readouts of all four Visium sections [here](https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Cellanalysis/Visium/MouseBrainSerialSections.zip). The **Mouse Brain Serial Section 1** datasets can be downloaded from [here](https://www.10xgenomics.com/resources/datasets?menu%5Bproducts.name%5D=Spatial%20Gene%20Expression&query=&page=1&configure%5BhitsPerPage%5D=50&configure%5BmaxValuesPerFacet%5D=1000) (specifically, please filter for **Species=Mouse**, **AnatomicalEntity=brain**, **Chemistry=v1** and **PipelineVersion=v1.1.0**).
245
246
We will now import each of four samples separately and merge them into one VoltRon object. There are four sections in total given two serial anterior and serial posterior sections, hence we have **two tissue blocks each having two layers**. 
247
248
```{r eval = FALSE, class.source="watch-out"}
249
library(VoltRon)
250
Ant_Sec1 <- importVisium("Sagittal_Anterior/Section1/", sample_name = "Anterior1")
251
Pos_Sec1 <- importVisium("Sagittal_Posterior/Section1/", sample_name = "Posterior1")
252
253
# merge datasets
254
MBrain_Sec <- merge(Ant_Sec1, Pos_Sec1, samples = c("Anterior", "Posterior"))
255
MBrain_Sec
256
```
257
258
```
259
VoltRon Object 
260
Anterior: 
261
  Layers: Section1 
262
Posterior: 
263
  Layers: Section1
264
Assays: Visium(Main) 
265
```
266
267
VoltRon maps metadata features on the spatial images, multiple features can be provided for all assays/layers associated with the main assay (Visium). 
268
269
```{r eval = FALSE, class.source="watch-out"}
270
vrSpatialFeaturePlot(MBrain_Sec, features = "Count", crop = TRUE, alpha = 1, ncol = 2)
271
```
272
273
<img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_firstplot.png" class="center">
274
275
<br>
276
277
## Feature Selection
278
279
VoltRon captures the nearly full transcriptome of the Visium data which then can be filtered from a list of features ranked by their variance and importance. We use the **variance stabilization transformation (vst)** on each individual assay using the **getFeatures** function and combine these ranked list to capture features important for all assay of the Visium data later with **getVariableFeatures** function.
280
281
```{r eval = FALSE, class.source="watch-out"}
282
head(vrFeatures(MBrain_Sec))
283
```
284
285
```
286
[1] "Xkr4"    "Gm1992"  "Gm19938" "Gm37381" "Rp1"     "Sox17"  
287
```
288
289
```{r eval = FALSE, class.source="watch-out"}
290
length(vrFeatures(MBrain_Sec))
291
```
292
293
```
294
[1] 33502
295
```
296
297
```{r eval = FALSE, class.source="watch-out"}
298
MBrain_Sec <- normalizeData(MBrain_Sec)
299
MBrain_Sec <- getFeatures(MBrain_Sec, n = 3000)
300
head(vrFeatureData(MBrain_Sec))
301
```
302
303
```
304
                mean          var    adj_var  rank
305
Xkr4    0.0248608534 0.0249941807 0.02800216 14114
306
Gm1992  0.0000000000 0.0000000000 0.00000000     0
307
Gm19938 0.0285714286 0.0322197476 0.03224908 13889
308
Gm37381 0.0000000000 0.0000000000 0.00000000     0
309
Rp1     0.0003710575 0.0003710575 0.00000000     0
310
Sox17   0.1907235622 0.2219629135 0.23715920 10304
311
```
312
313
```{r eval = FALSE, class.source="watch-out"}
314
selected_features <- getVariableFeatures(MBrain_Sec)
315
head(selected_features, 20)
316
```
317
318
```
319
[1] "Bc1"     "mt-Co1"  "mt-Co3"  "mt-Atp6" "mt-Co2"  "mt-Cytb" "mt-Nd4"  "mt-Nd1"  "mt-Nd2"  
320
[2] "Fth1"    "Hbb-bs"  "Cst3"    "Gapdh"   "Tmsb4x"  "Mbp"     "Rplp1"   "Ttr"     "Ppia"    
321
[3] "Ckb"     "mt-Nd3" 
322
```
323
324
## Embedding
325
326
Now we can learn and visualize PCA and UMAP embeddings on this smaller number of selected features
327
328
```{r eval = FALSE, class.source="watch-out"}
329
MBrain_Sec <- getPCA(MBrain_Sec, features = selected_features, dims = 30)
330
MBrain_Sec <- getUMAP(MBrain_Sec, dims = 1:30)
331
vrEmbeddingPlot(MBrain_Sec, embedding = "umap")
332
```
333
334
<img width="65%" height="65%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_umap.png" class="center">
335
336
<br>
337
338
## Clustering
339
340
```{r eval = FALSE, class.source="watch-out"}
341
MBrain_Sec <- getProfileNeighbors(MBrain_Sec, dims = 1:30, k = 10, method = "SNN")
342
vrGraphNames(MBrain_Sec)
343
```
344
345
```
346
[1] "SNN"
347
```
348
349
```{r eval = FALSE, class.source="watch-out"}
350
MBrain_Sec <- getClusters(MBrain_Sec, resolution = 0.5, label = "Clusters", graph = "SNN")
351
vrEmbeddingPlot(MBrain_Sec, embedding = "umap", group.by = "Clusters")
352
```
353
354
<img width="65%" height="65%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_umap_clusters.png" class="center">
355
356
<br>
357
358
```{r eval = FALSE, class.source="watch-out"}
359
vrSpatialPlot(MBrain_Sec, group.by = "Clusters")
360
```
361
362
<img width="65%" height="65%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_visium_spatial_clusters1.png" class="center">
363
364
<br>
365
366
# MELC Data Analysis
367
368
VoltRon also provides support for imaging based proteomics assays. In this next use case, we analyze cells characterized by **multi-epitope ligand cartography (MELC)** with a panel of 44 parameters. We use the already segmented cells on which expression of **43 protein features** (excluding DAPI) were mapped to these cells. 
369
370
We use the segmented cells over microscopy images collected from **control** and **COVID-19** lung tissues of donors categorized based on disease durations (**control**, **acute**, **chronic** and **prolonged**). Each image is associated with one of few field of views (FOVs) from a single tissue section of a donor. See [GSE190732](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE190732) for more information. You can download the **IFdata.csv** file and the folder with the **DAPI** images [here](https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Cellanalysis/MELC/GSE190732.zip). 
371
372
We import the **protein intensities**, **metadata** and **coordinates** associated with segmented cells across FOVs of samples.
373
374
```{r eval = FALSE, class.source="watch-out"}
375
library(VoltRon)
376
IFdata <- read.csv("IFdata.csv")
377
data <- IFdata[,c(2:43)]
378
metadata <- IFdata[,c("disease_state", "object_id", "cluster", "Clusters",
379
                      "SourceID", "Sample", "FOV", "Section")]
380
coordinates <- as.matrix(IFdata[,c("posX","posY")], rownames.force = TRUE)
381
```
382
383
<br>
384
385
## Importing MELC data
386
387
Before analyzing MELC assays across FOVs, we should **build a VoltRon object** for each individual FOV/Section by using the **formVoltron** function. We then merge these sections to respective tissue blocks by defining their samples of origins. We can also define **assay names**, **assay types** and **sample (i.e. block) names** of these objects. 
388
389
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
390
library(dplyr)
391
library(magick)
392
vr_list <- list()
393
sample_metadata <- metadata %>% select(Sample, FOV, Section) %>% distinct()
394
for(i in 1:nrow(sample_metadata)){
395
  vrassay <- sample_metadata[i,]
396
  cells <- rownames(metadata)[metadata$Section == vrassay$Section]
397
  image <- image_read(paste0("DAPI/", vrassay$Sample, "/DAPI_", vrassay$FOV, ".tif"))
398
  vr_list[[vrassay$Section]] <- formVoltRon(data = t(data[cells,]), 
399
                                            metadata = metadata[cells,],
400
                                            image = image, 
401
                                            coords = coordinates[cells,],
402
                                            main.assay = "MELC", 
403
                                            assay.type = "cell",
404
                                            sample_name = vrassay$Section)
405
}
406
```
407
408
Before moving forward with merging FOVs, we should **flip coordinates** of cells and perhaps also then **resize** these images. The main reason for this coordinate flipping is that the y-axis of most digital images are of the opposite direction to the commonly used coordinate spaces. 
409
410
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
411
for(i in 1:nrow(sample_metadata)){
412
  vrassay <- sample_metadata[i,]
413
  vr_list[[vrassay$Section]] <- flipCoordinates(vr_list[[vrassay$Section]])
414
  vr_list[[vrassay$Section]] <- resizeImage(vr_list[[vrassay$Section]], size = 600)
415
}
416
```
417
418
Finally, we merge these assays into one VoltRon object. The **samples** arguement in the merge function determines which assays are layers of a single tissue sample/block.
419
420
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
421
vr_merged <- merge(vr_list[[1]], vr_list[-1], samples = sample_metadata$Sample)
422
vr_merged 
423
```
424
425
```
426
VoltRon Object 
427
control_case_3: 
428
  Layers: Section1 Section2 
429
control_case_2: 
430
  Layers: Section1 Section2 
431
control_case_1: 
432
  Layers: Section1 Section2 Section3 
433
acute_case_3: 
434
  Layers: Section1 Section2 
435
acute_case_1: 
436
  Layers: Section1 Section2 
437
... 
438
There are 13 samples in total 
439
Assays: MELC(Main) 
440
```
441
442
<br>
443
444
The prolonged case 4 has two fields of views (FOVs). By subsetting on the sample of a prolonged case, we can visualize only these two sections, and visualize the protein expression of CD31 and Pancytokeratin which are markers of endothelial and epithelial cells.
445
446
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
447
vr_subset <- subset(vr_merged, samples = "prolonged_case_4")
448
g1 <- vrSpatialFeaturePlot(vr_subset, features = c("CD31", "Pancytokeratin"), alpha = 1, 
449
                           pt.size = 0.7, background.color = "black")
450
```
451
452
<img width="90%" height="90%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_spatialfeature.png" class="center">
453
454
<br>
455
456
## Dimensionality Reduction
457
458
We can utilize dimensional reduction of the available protein markers using the getPCA and getUMAP functions, but now with relatively lower numbers of principal components which are enough to capture the information across 44 features.
459
460
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
461
vr_merged <- getPCA(vr_merged, dims = 10)
462
vr_merged <- getUMAP(vr_merged, dims = 1:10)
463
vrEmbeddingFeaturePlot(vr_merged, features = c("CD31", "Pancytokeratin"), embedding = "umap")
464
```
465
466
<img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_embedding.png" class="center">
467
468
<br>
469
470
## Clustering
471
472
Now we can visualize the clusters across these sections and perhaps also check for clusters that may reside in only specific disease conditions. 
473
474
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
475
# SNN graph and clusters
476
vr_merged <- getProfileNeighbors(vr_merged, dims = 1:10, k = 10, method = "SNN")
477
vrGraphNames(vr_merged)
478
```
479
480
```
481
[1] "SNN"
482
```
483
484
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
485
vr_merged <- getClusters(vr_merged, resolution = 0.8, label = "MELC_Clusters", graph = "SNN")
486
487
# install patchwork package
488
if (!requireNamespace("patchwork", quietly = TRUE))
489
  install.packages("patchwork")
490
library(patchwork)
491
492
# visualize conditions and clusters
493
vr_merged$Condition <- gsub("_[0-9]$", "", vr_merged$Sample)
494
g1 <- vrEmbeddingPlot(vr_merged, group.by = c("Condition"), embedding = "umap")
495
g2 <- vrEmbeddingPlot(vr_merged, group.by = c("MELC_Clusters"), embedding = "umap", 
496
                      label = TRUE)
497
g1 | g2
498
```
499
500
<img width="100%" height="100%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_embeddingclusters.png" class="center">
501
502
<br>
503
504
## Visualization of Markers
505
506
VoltRon provides both violin plots (**vrViolinPlot**) and heatmaps (**vrHeatmapPlot**) to further investigate the enrichment of markers across newly clustered datasets. **Note:** the vrHeatmapPlot function would require you to have the **ComplexHeatmap** package in your namespace. 
507
508
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
509
# install patchwork package
510
if (!requireNamespace("ComplexHeatmap", quietly = TRUE))
511
  BiocManager::install("ComplexHeatmap")
512
library(ComplexHeatmap)
513
514
# Visualize Markers
515
vrHeatmapPlot(vr_merged, features = vrFeatures(vr_merged), 
516
              group.by = "MELC_Clusters", show_row_names = TRUE)
517
```
518
519
<img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_heatmapclusters.png" class="center">
520
521
<br>
522
523
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
524
vrViolinPlot(vr_merged, features = c("CD3", "SMA", "Pancytokeratin", "CCR2"), 
525
             group.by = "MELC_Clusters", ncol = 2)
526
```
527
528
<img width="80%" height="80%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_violinclusters.png" class="center">
529
530
<br>
531
532
## Neighborhood Analysis
533
534
We use the **vrNeighbourhoodEnrichment** function to detect cell type pairs that co occur within each others' neighborhoods. First, we establish **spatial neighborhood graphs** that determine the neighbors of each cell on tissue sections. 
535
536
[Delaunay tesselations](https://en.wikipedia.org/wiki/Delaunay_triangulation) or graphs are commonly used to determine neighbors of spatial entities. The function **getSpatialNeighbors** builds a delaunay graph of all assays of a certain type and detects neighbors of cells in a VoltRon object.
537
538
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
539
vr_merged <- getSpatialNeighbors(vr_merged, method = "delaunay")
540
```
541
542
The graph **delaunay**, which we will use for spatially-aware neightborhood analysis, is now the second graph available in the VoltRon object along with **SNN**.
543
544
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
545
vrGraphNames(vr_merged)
546
```
547
548
```
549
[1] "SNN"      "delaunay"
550
```
551
552
Once neighbors are founds, we can apply a **permutation test** that compares the number of cell type occurances with an expected number of these occurances under multiple permutations of labels in the tissue (fixed coordinates but cells are randomly labelled). A similar approach is used to by several spatial analysis frameworks and packages ([Schapiro et. al 2017](https://www.nature.com/articles/nmeth.4391), [Palla et. al 2022](https://www.nature.com/articles/s41592-021-01358-2)).
553
554
Here, we will use the original cell type labels annotated by [Mothes et. al 2023](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9922044/).
555
556
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
557
neighborhood_results <- vrNeighbourhoodEnrichment(vr_merged, group.by = "Clusters")
558
```
559
560
The neighborhood analysis provides the results of:
561
562
* the **association** tests (whether cell types are within each other's neighborhood)
563
* the **segregation** tests (whether cell types are clustered separately) 
564
565
between all cell type pairs across each layers and assay. 
566
567
The number of each cell in a pair in each section is reported to assess the impact of the results of the test (i.e. low number of abundance in one cell type may indicate low impact).
568
569
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
570
head(neighborhood_results)
571
```
572
573
<div><pre><code style="font-size: 10px;">          from_value     to_value   p_assoc   p_segreg p_assoc_adj p_segreg_adj n_from n_to AssayID Assay    Layer         Sample
574
Assay1.1 CD163+ macs  CD163+ macs 0.0000000 1.00000000      0.0000   1.00000000     41   41  Assay1  MELC Section1 control_case_3
575
Assay1.2 CD163+ macs CD4+ T cells 0.9380000 0.03300000      0.9980   0.09762866     41   48  Assay1  MELC Section1 control_case_3
576
Assay1.3 CD163+ macs  CD8+ Tcells 0.8779011 0.04339051      0.9980   0.09762866     41   11  Assay1  MELC Section1 control_case_3
577
Assay1.4 CD163+ macs     NK cells 0.8190000 0.08700000      0.9980   0.15660000     41   15  Assay1  MELC Section1 control_case_3
578
Assay1.5 CD163+ macs   endothelia 0.1230000 0.85100000      0.5535   0.95737500     41  139  Assay1  MELC Section1 control_case_3
579
Assay1.6 CD163+ macs    epithelia 0.9320000 0.03600000      0.9980   0.09762866     41   39  Assay1  MELC Section1 control_case_3</code></pre></div>
580
581
<br>
582
583
```{r eval = FALSE, class.source="watch-out", fig.align='center'}
584
vrNeighbourhoodEnrichmentPlot(neighborhood_results, assay = "Assay1", type = "assoc")
585
```
586
587
<img width="70%" height="70%" src="https://bimsbstatic.mdc-berlin.de/landthaler/VoltRon/Package/images/cellspot_neighenrichment.png" class="center">