Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ codebook
codeword
codewords
colData
colocalize
colorectal
colour
ComplexHeatmap
Expand Down Expand Up @@ -304,6 +305,7 @@ Menyhárt
mer
merchantability
MERFISH
MERSCOPE
mesenchymal
mesoderm
metacell
Expand Down Expand Up @@ -344,6 +346,7 @@ myocytes
myoepithelial
myofibroblast
myogenesis
NanoString
natively
NCI
nd
Expand Down Expand Up @@ -494,6 +497,7 @@ Srivastava
SRP
SRR
StackOverflow
STARmap
StatQuest
Stoeckius
str
Expand Down Expand Up @@ -566,6 +570,7 @@ versicolor
virginica
Visium
vitro
Vizgen
VST
Wattenberg
WCSS
Expand Down
51 changes: 49 additions & 2 deletions module-cheatsheets/spatial-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ If you have a different version of R or other R packages, the documentation may
- [`SpotSweeper`](#spotsweeper)
- [`Banksy`](#banksy)
- [`spacexr`](#spacexr)
- [`SpatialExperimentIO`](#spatialexperimentio)
- [`hoodscanR`](#hoodscanr)
- [`scuttle`, `scran`, and `scater`](#scuttle-scran-and-scater)
- [`bluster`](#bluster)
- [`patchwork`](#patchwork)
- [`pals`](#pals)
- [`pheatmap`](#pheatmap)
- [`purrr`](#purrr)
- [`ComplexHeatmap`](#complexheatmap)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -125,6 +128,40 @@ Read the [`spacexr` package documentation](https://www.bioconductor.org/packages

<div style="page-break-after: always;"></div>

### `SpatialExperimentIO`

<!-- TODO: This package has not yet made it to rdrr -->
Read the [`SpatialExperimentIO` package documentation](https://www.bioconductor.org/packages/release/bioc/html/SpatialExperimentIO.html) and a [vignette on its usage](https://www.bioconductor.org/packages/release/bioc/vignettes/SpatialExperimentIO/inst/doc/SpatialExperimentIO.html).

This package provides reader functions for imaging-based spatial transcriptomics platforms, including Xenium (10x Genomics), CosMx (NanoString), MERSCOPE (Vizgen), and STARmap PLUS.


| Library/Package | Piece of Code | What it's called | What it does |
|----------------------|----------------------------|--------------------------------------------|--------------------------------------------------------------|
| `SpatialExperimentIO` | [`readXeniumSXE()`](https://www.bioconductor.org/packages/release/bioc/vignettes/SpatialExperimentIO/inst/doc/SpatialExperimentIO.html#xenium) | Read Xenium into a Spatial Experiment | Loads an unzipped 10x Genomics Xenium output bundle directory into a `SpatialExperiment` object |

<div style="page-break-after: always;"></div>

### `hoodscanR`

<!-- TODO: This package has not yet made it to rdrr -->
Read the [`hoodscanR` package documentation](https://www.bioconductor.org/packages/release/bioc/html/hoodscanR.html) and a [vignette on its usage](https://www.bioconductor.org/packages/release/bioc/vignettes/hoodscanR/inst/doc/Quick_start.html).

Note that the functions in this package are generally run in sequence, where the output of one function is the input to the next.


| Library/Package | Piece of Code | What it's called | What it does |
|----------------------|----------------------------|--------------------------------------------|--------------------------------------------------------------|
| `hoodscanR` | [`findNearCells()`](https://davislaboratory.github.io/hoodscanR/reference/findNearCells.html) | Find the k-the nearest cells for each | Find the `k` nearest cells to each cell in a `SpatialExperiment` object, returning a list with a matrix of distances and a matrix of the annotations (e.g., cell types) of those neighboring cells |
| `hoodscanR` | [`scanHoods()`](https://davislaboratory.github.io/hoodscanR/reference/scanHoods.html) | Scan cellular neighborhoods | Apply a modified softmax algorithm to the distance matrix from `hoodscanR::findNearCells()` to calculate the probability that each cell is associated with each of its nearest neighboring cells |
| `hoodscanR` | [`mergeByGroup()`](https://davislaboratory.github.io/hoodscanR/reference/mergeByGroup.html) | Merge probability matrix based on annotations | Collapse the probability matrix from `hoodscanR::scanHoods()` by annotation, so that each column is a group (e.g., a cell type) rather than an individual neighboring cell |
| `hoodscanR` | [`mergeHoodSpe()`](https://davislaboratory.github.io/hoodscanR/reference/mergeHoodSpe.html) | Merge probability matrix into Spatial Experiment object | Add the merged probability matrix into the `colData` of a `SpatialExperiment` object |
| `hoodscanR` | [`calcMetrics()`](https://davislaboratory.github.io/hoodscanR/reference/calcMetrics.html) | Calculate metrics for probability matrix | Calculate the entropy and perplexity of the probability matrix for each cell, which summarize how mixed or how distinct that cell's neighborhood is, and store them in `colData` |
| `hoodscanR` | [`plotColocal()`](https://davislaboratory.github.io/hoodscanR/reference/plotColocal.html) | Plot heatmap for neighborhood analysis | Plot a heatmap of the Pearson correlations between cells' neighborhood probability distributions to show which groups tend to colocalize |
| `hoodscanR` | [`clustByHood()`](https://davislaboratory.github.io/hoodscanR/reference/clustByHood.html) | Cluster the probability matrix with K-means | Perform k-means clustering on the probability matrix to assign each cell to a neighborhood cluster |
| `hoodscanR` | [`plotProbDist()`](https://davislaboratory.github.io/hoodscanR/reference/plotProbDist.html) | Plot probability distribution | Plot the distribution of neighborhood probabilities, optionally split by a grouping variable such as the neighborhood clusters from `hoodscanR::clustByHood()` |

<div style="page-break-after: always;"></div>

### `scuttle`, `scran`, and `scater`

Expand All @@ -141,14 +178,14 @@ Read the [`scater` package documentation](https://rdrr.io/bioc/scater/), and a [
| `scuttle`| [`addPerCellQC()`](https://rdrr.io/bioc/scuttle/man/addPerCellQC.html)| Add per cell quality control | For a `SingleCellExperiment` object, calculate and add quality control per cell and store in `colData` |
| `scuttle` | [`computeLibraryFactors()`](https://rdrr.io/bioc/scuttle/man/librarySizeFactors.html) | Compute Library Factors | Returns a numeric vector of computed size factors for each spot (or cell) stored in a `SpatialExperiment` (or `SingleCellExperiment`) object. The size factor is computed as the library size of each spot/cell after scaling them to have a mean of 1 across all spots/cells |
| `scuttle`| [`logNormCounts()`](https://rdrr.io/bioc/scuttle/man/logNormCounts.html)| Normalize log counts | Returns the `SpatialExperiment` (or `SingleCellExperiment`) object with normalized expression values for each spot (cell), using the size factors stored in the object |
| `scuttle`| [`isOutlier()`](https://rdrr.io/bioc/scuttle/man/isOutlier.html)| Identify outliers | Convenience function to determine which values in a numeric vector are outliers based on the median absolute deviation (MAD) |
| `scran`| [`getTopHVGs()`](https://rdrr.io/bioc/scran/man/getTopHVGs.html)| Get top highly variable genes | Identify variable genes in a `SingleCellExperiment` object, based on variance |
| `scran`| [`modelGeneVar()`](https://rdrr.io/bioc/scran/man/modelGeneVar.html)| model per gene variance | Model the per gene variance of a `SingleCellExperiment` object |
| `scran`| [`clusterCells()`](https://rdrr.io/github/MarioniLab/scran/man/clusterCells.html)| Cluster cells | Perform clustering on an SCE object using the `bluster` package |
| `scater`| [`runPCA()`](https://rdrr.io/bioc/scater/man/runPCA.html)| Run PCA | Calculates principal components analysis on a `SingleCellExperiment` object, returning an SCE object with a PCA reduced dimension |
| `scater`| [`runUMAP()`](https://rdrr.io/bioc/scater/man/runUMAP.html)| Run UMAP | Calculates uniform manifold approximate projection on a `SingleCellExperiment` object, returning an SCE object with a UMAP reduced dimension |
| `scater`| [`plotUMAP()`](https://rdrr.io/bioc/scater/man/plot_reddim.html)| Plot UMAP | Plot the "UMAP"-named reduced dimension slot from a `SingleCellExperiment` object |


<div style="page-break-after: always;"></div>


Expand Down Expand Up @@ -216,4 +253,14 @@ Read the [`purrr` package documentation](https://purrr.tidyverse.org/) and a [vi
|----------------|--------------|-----------------|--------------|
| `purrr`| [`map()`](https://purrr.tidyverse.org/reference/map.html)| map | Apply a function across each element of list; return a list |
| `purrr`| [`imap()`](https://purrr.tidyverse.org/reference/imap.html)| imap | Apply a function across each element of list and its index/names; return a list |
| `purrr`| [`reduce()`](https://purrr.tidyverse.org/reference/reduce.html)| Reduce | Reduce a list to a single value by repeatedly applying a given function. Can also be used to iteratively modify a single object. |
| `purrr`| [`reduce()`](https://purrr.tidyverse.org/reference/reduce.html)| Reduce | Reduce a list to a single value by repeatedly applying a given function. Can also be used to iteratively modify a single object. |


### `ComplexHeatmap`

Read the [`ComplexHeatmap` package documentation](https://rdrr.io/bioc/ComplexHeatmap/) and the [`ComplexHeatmap` Complete Reference e-book](https://jokergoo.github.io/ComplexHeatmap-reference/book/).


| Library/Package | Piece of Code | What it's called | What it does |
|----------------------|--------------------|---------------------|---------------|
| `ComplexHeatmap`| [`Heatmap()`](https://rdrr.io/bioc/ComplexHeatmap/man/Heatmap.html)| Heatmap | Create a clustered heatmap from a matrix, with options to split, annotate, and combine it with other heatmaps |
Binary file modified module-cheatsheets/spatial-cheatsheet.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions spatial/05-xenium_processing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ output:

- Read Xenium data into R
- Calculate quality control measures on imaging spatial transcriptomic data
- Remove likely low-quality spots with `SpaceTrooper()`
- Remove likely low-quality spots
- Normalize spatial expression data

## Introduction
Expand Down Expand Up @@ -398,7 +398,7 @@ p1 + p2
```

To flag these cells, we summarize each cell by its counts-per-area ratio and look for cells that sit far below the bulk of the distribution.
Specifically, we use `scater::isOutlier()` to flag cells whose ratio falls more than three median absolute deviations (MADs) below the median.
Specifically, we use `scuttle::isOutlier()` to flag cells whose ratio falls more than three median absolute deviations (MADs) below the median.

* The MAD is a robust measure of spread and is less sensitive to extreme values than the standard deviation.
* We will use the common cutoff of 3 * MAD.
Expand All @@ -412,7 +412,7 @@ count_area_ratio <- spe$total_counts / spe$cell_area

# flag cells that are outliers on the low side
# (3 median absolute deviations below the median, on the log2 scale since the metric is a ratio)
outliers <- scater::isOutlier(count_area_ratio, log = TRUE, type = "lower", nmads = 3)
outliers <- scuttle::isOutlier(count_area_ratio, log = TRUE, type = "lower", nmads = 3)

# print the structure which tells us where to find the identified threshold
str(outliers)
Expand Down
Loading