You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/Session_3_imaging_assays.Rmd
+48-30Lines changed: 48 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: "Imaging assays (tidy)"
3
3
author:
4
4
- Stefano Mangiola, South Australian immunoGENomics Cancer Institute^[<[email protected]>], Walter and Eliza Hall Institute^[<mangiola.s at wehi.edu.au>]
5
-
- Malvica Kharbanda, South Australian immunoGENomics Cancer Institute^[<[email protected]>]
5
+
- Malvika Kharbanda, South Australian immunoGENomics Cancer Institute^[<[email protected]>]
This [data package](https://bioconductor.org/packages/release/data/experiment/html/SubcellularSpatialData.html) contains annotated datasets localized at the sub-cellular level from the STOmics, Xenium, and CosMx platforms, as analyzed in the publication by [Bhuva et al., 2025](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-024-03241-7). It includes raw transcript detections and provides functions to convert these into `SpatialExperiment` objects.
77
77
78
+
The data in this workshop we will be analyzing is the Xenium Mouse Brain dataset. The dataset has 3 serial sections of fresh frozen mouse brain. Raw transcript level data is provided with region annotations for each detection.
79
+
80
+
The data is stored in the `ExperimentHub` package, and can be downloaded using the following queries:
We can appreciate how, even subsampling the data 1 in 500, we still have a vast amount of data to visualise.
130
+
This dataset have been annotated for regions. Here we plot the regions in the sample. We can appreciate how, even subsampling the data 1 in 500, we still have a vast amount of data to visualise.
124
131
125
132
```{r, fig.width=7, fig.height=8}
126
133
tx_small |>
@@ -132,36 +139,36 @@ tx_small |>
132
139
theme(legend.position = "none")
133
140
```
134
141
135
-
This dataset have been annotated for regions. Let's have a look how many regions have been annotated
142
+
Let's have a look how many regions have been annotated
136
143
137
144
```{r}
138
145
tx_small |>
139
146
distinct(region)
140
147
```
141
148
142
-
From this large dataset, we select a small reagion for illustrative purposes
149
+
From this large dataset, we select a small reagion for illustrative purposes.
143
150
144
151
```{r, eval=FALSE}
145
152
tx_small_region =
146
153
tx |>
147
154
filter(x |> between(3700, 4200), y |> between(5000, 5500))
148
155
```
149
156
150
-
Load the pre-saved data
157
+
If you do not have tx loaded from before, load the pre-saved data:
The R package MoleculeExperiment includes functions to create and manipulate objects from the newly introduced MoleculeExperiment class, designed for analyzing molecule-based spatial transcriptomics data from platforms such as Xenium by 10X, CosMx SMI by Nanostring, and Merscope by Vizgen, among others.
167
+
The R package MoleculeExperiment includes functions to create and manipulate objects from the newly introduced MoleculeExperiment class, designed for analysing molecule-based spatial transcriptomics data from platforms such as Xenium by 10X, CosMx SMI by Nanostring, and Merscope by Vizgen, among others.
161
168
162
-
Although in this session we will not use `MoleculeExperiment` class, because of the lack of segmentation boundary information (we rather have cell identifiers), we briefly introduce this package because as an important part of Bioconductor.
169
+
`MoleculeExperiment` class uses cell boundary information instead of cell identifiers. And thus we won't use `MoleculeExperiment` directly. However, as it is an important part of bioconductor we briefly introduce this package.
163
170
164
-
We show how we would import our table of probe location into a `MoleculeExperiment`. At the end of the Session, for knowledge, we will navigate the example code given in the [vignette material](https://www.bioconductor.org/packages/release/bioc/vignettes/MoleculeExperiment/inst/doc/MoleculeExperiment.html).
171
+
We show how we would import our table of probe location into a `MoleculeExperiment`. For this section, we will go through the example code given in the [vignette material](https://www.bioconductor.org/packages/release/bioc/vignettes/MoleculeExperiment/inst/doc/MoleculeExperiment.html).
In this object, besides the single molecule location, we have cell segmentation boundaries. We can use these boudaries to understand subcellular localisation of molecules and to aggregate molecules in cells.
183
+
In this object, besides the single molecule location, we have cell segmentation boundaries. We can use these boundaries to understand subcellular localisation of molecules and to aggregate molecules in cells.
177
184
178
185
```{r, fig.width=7, fig.height=8}
179
186
ggplot_me() +
@@ -186,7 +193,7 @@ ggplot_me() +
186
193
)
187
194
```
188
195
189
-
In this object we don't only have the cell segmentation but the nucleous segmentation as well.
196
+
In this object we don't only have the cell segmentation but the nucleus segmentation as well.
190
197
191
198
```{r, fig.width=7, fig.height=8}
192
199
boundaries(me, "nucleus") = readBoundaries(
@@ -224,7 +231,7 @@ rm(me)
224
231
gc()
225
232
```
226
233
227
-
We can organise our large data frame containing single molecules into a more efficient `MoleculeExperiment`.
234
+
`MoleculeExperiment` also has functions such as `dataframeToMEList()` and then `MoleculeExperiment()` where we can organise our large data frame containing single molecules into a more efficient `MoleculeExperiment` object.
228
235
229
236
```{r}
230
237
library(MoleculeExperiment)
@@ -269,7 +276,7 @@ gc()
269
276
270
277
#### A preview of a zoomed in section of the tissue
271
278
272
-
Now let's try to visualise just a small section. You can appreciate, coloured by cell, single molecules. You cqn also appreciate the difference in density between regions. An aspect to note, is that not all probes are withiin cells. This depends on the segmentation process.
279
+
Now let's try to visualise just a small section, `tx_small_region`, that we downloaded earlier. You can appreciate, single molecules are coloured by cell. You can also appreciate the difference in density between regions. An aspect to note, is that not all probes are within cells. This depends on the segmentation process.
We want to understand how much data we are discarding, that does not have a cell identity.
316
317
317
318
- Using base R grammar calculate what is the ratio of outside-cell vs within-cell, probes
318
319
- Reproduce the same calculation with `tidyverse`
320
+
- Calculate the percentage of probes are within the cytoplasm but outside the nucleus
319
321
320
322
:::
321
323
324
+
```{r}
325
+
rm(tx_small_region)
326
+
gc()
327
+
```
328
+
322
329
### 3. Aggregation and analysis
323
330
324
331
We will convert our cell by gene count to a `SpatialExperiment`. This object stores a cell by gene matrix with relative XY coordinates.
325
332
326
-
`SubcellularSpatialData` has a utility function that aggregated the single molecules in cells, where these cell ID have been identified with segmentation.
333
+
`SubcellularSpatialData`package has a utility function that aggregated the single molecules in cells, where these cell ID have been identified with segmentation.
327
334
328
335
329
336
```{r, eval=FALSE}
330
337
tx_spe = SubcellularSpatialData::tx2spe(tx)
331
338
332
339
tx_spe = tx_spe |> mutate(in_tissue = TRUE)
333
340
```
334
-
335
-
```{r, echo=FALSE}
341
+
If you do not have tx loaded from before, load the pre-saved data converted to `SpatialExperiment`:
@@ -351,7 +358,7 @@ Let have a look to the `SpatialExperiment`.
351
358
tx_spe
352
359
```
353
360
354
-
A trivial edit to work with `ggspavis.`
361
+
Here we introduce the `ggspavis` package to visualize spatial transcriptomics data. This package requires a column called `in_tissue` to be present in the `SpatialExperiment` object. Here we edit our data include this column.
355
362
356
363
```{r}
357
364
tx_spe = tx_spe |> mutate(in_tissue = TRUE)
@@ -379,7 +386,6 @@ We normalise the `SpatialExperiment` using `scater`.
379
386
```{r}
380
387
tx_spe =
381
388
tx_spe |>
382
-
383
389
# Scaling and tranformation
384
390
scater::logNormCounts()
385
391
```
@@ -479,7 +485,7 @@ tx_spe_sample_1 =
479
485
tx_spe_sample_1 |> select(.cell, clusters)
480
486
```
481
487
482
-
As we have done before, we caculate UMAPs for visualisation purposes.
488
+
As we have done before, we caclculate UMAPs for visualisation purposes.
483
489
484
490
::: {.note}
485
491
This step takes long time.
@@ -519,7 +525,7 @@ In the previous sections we have seen how to do gene marker selection for sequen
519
525
:::
520
526
521
527
522
-
Too understand whether the cell clusters explain morphology as opposed to merely cell identity, we can color cells according to annotated region. As we can see we have a lot of regions. We have more regions that cell clusters.
528
+
To understand whether the cell clusters explain morphology as opposed to merely cell identity, we can color cells according to annotated region. As we can see we have a lot of regions. We have more regions that cell clusters.
523
529
524
530
```{r, fig.width=7, fig.height=8}
525
531
@@ -572,7 +578,7 @@ Algorithm:
572
578
573
579
- Cell-level annotations provided by users are used to construct a cell annotation matrix
574
580
575
-
- Identify cellular neighborhoods uses the SoftMax function, enhanced by a "shape" parameter that governs the "influence radious". This measures probability of a cell type to be found in a neighbour.
581
+
- Identify cellular neighborhoods uses the SoftMax function, enhanced by a "shape" parameter that governs the "influence radius". This measures probability of a cell type to be found in a neighbour.
576
582
577
583
- The K-means clustering algorithm finds recurring neighbours
578
584
@@ -610,9 +616,17 @@ hoods[1:2, 1:10]
610
616
611
617
We plot randomly plot 50 cells to see the output of neighborhood scanning using plotHoodMat. In this plot, each value represent the probability of the each cell (each row) located in each cell type neighborhood. The rowSums of the probability maxtrix will always be 1.
We can then merge the neighborhood results with the `SpatialExperiment` object using `mergeHoodSpe` so that we can conduct more neighborhood-related analysis.
0 commit comments