-
Notifications
You must be signed in to change notification settings - Fork 84
/
pbmc_multiomic.Rmd
350 lines (277 loc) · 10.2 KB
/
pbmc_multiomic.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
---
title: "Joint RNA and ATAC analysis: 10x multiomic"
date: 'Compiled: `r format(Sys.Date(), "%B %d, %Y")`'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
In this vignette, we'll demonstrate how to jointly analyze a single-cell dataset
measuring both DNA accessibility and gene expression in the same cells using
Signac and Seurat. In this vignette we'll be using a publicly available 10x
Genomic Multiome dataset for human PBMCs.
<details>
<summary>**View data download code**</summary>
You can download the required data by running the following lines in a shell:
```{sh eval=FALSE}
wget https://cf.10xgenomics.com/samples/cell-arc/1.0.0/pbmc_granulocyte_sorted_10k/pbmc_granulocyte_sorted_10k_filtered_feature_bc_matrix.h5
wget https://cf.10xgenomics.com/samples/cell-arc/1.0.0/pbmc_granulocyte_sorted_10k/pbmc_granulocyte_sorted_10k_atac_fragments.tsv.gz
wget https://cf.10xgenomics.com/samples/cell-arc/1.0.0/pbmc_granulocyte_sorted_10k/pbmc_granulocyte_sorted_10k_atac_fragments.tsv.gz.tbi
```
</details>
```{r include=FALSE}
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
if (!requireNamespace("EnsDb.Hsapiens.v86", quietly = TRUE))
BiocManager::install("EnsDb.Hsapiens.v86")
if (!requireNamespace("BSgenome.Hsapiens.UCSC.hg38", quietly = TRUE))
BiocManager::install("BSgenome.Hsapiens.UCSC.hg38")
if (!requireNamespace("remotes", quietly = TRUE))
install.packages("remotes")
if (!requireNamespace("SeuratDisk", quietly = TRUE))
remotes::install_github("mojaveazure/seurat-disk")
if (!requireNamespace("glmGamPoi", quietly = TRUE))
BiocManager::install("glmGamPoi")
```
```{r message=FALSE, warning=FALSE}
library(Signac)
library(Seurat)
library(EnsDb.Hsapiens.v86)
library(BSgenome.Hsapiens.UCSC.hg38)
```
```{r message=FALSE, warning=FALSE}
# load the RNA and ATAC data
counts <- Read10X_h5("../vignette_data/multiomic/pbmc_granulocyte_sorted_10k_filtered_feature_bc_matrix.h5")
fragpath <- "../vignette_data/multiomic/pbmc_granulocyte_sorted_10k_atac_fragments.tsv.gz"
```
```{r message=FALSE, warning=FALSE}
# get gene annotations for hg38
annotation <- GetGRangesFromEnsDb(ensdb = EnsDb.Hsapiens.v86)
seqlevels(annotation) <- paste0('chr', seqlevels(annotation))
# create a Seurat object containing the RNA adata
pbmc <- CreateSeuratObject(
counts = counts$`Gene Expression`,
assay = "RNA"
)
# create ATAC assay and add it to the object
pbmc[["ATAC"]] <- CreateChromatinAssay(
counts = counts$Peaks,
sep = c(":", "-"),
fragments = fragpath,
annotation = annotation
)
```
```{r}
pbmc
```
## Quality control
We can compute per-cell quality control metrics using the DNA accessibility data
and remove cells that are outliers for these metrics, as well as cells with
low or unusually high counts for either the RNA or ATAC assay.
```{r fig.width=18, message=FALSE, warning=FALSE}
DefaultAssay(pbmc) <- "ATAC"
pbmc <- NucleosomeSignal(pbmc)
pbmc <- TSSEnrichment(pbmc)
```
The relationship between variables stored in the object metadata can
be visualized using the `DensityScatter()` function. This can also be used
to quickly find suitable cutoff values for different QC metrics by setting
`quantiles=TRUE`:
```{r}
DensityScatter(pbmc, x = 'nCount_ATAC', y = 'TSS.enrichment', log_x = TRUE, quantiles = TRUE)
```
```{r}
VlnPlot(
object = pbmc,
features = c("nCount_RNA", "nCount_ATAC", "TSS.enrichment", "nucleosome_signal"),
ncol = 4,
pt.size = 0
)
```
```{r}
# filter out low quality cells
pbmc <- subset(
x = pbmc,
subset = nCount_ATAC < 100000 &
nCount_RNA < 25000 &
nCount_ATAC > 1800 &
nCount_RNA > 1000 &
nucleosome_signal < 2 &
TSS.enrichment > 1
)
pbmc
```
<!-- ## Peak calling -->
<!-- The set of peaks identified using Cellranger often merges distinct peaks that are -->
<!-- close together. This can create a problem for certain analyses, particularly motif -->
<!-- enrichment analysis and peak-to-gene linkage. To identify a more accurate set of peaks, -->
<!-- we can call peaks using MACS2 with the `CallPeaks()` function. Here we call peaks -->
<!-- on all cells together, but we could identify peaks for each group of cells separately -->
<!-- by setting the `group.by` parameter, and this can help identify peaks specific to -->
<!-- rare cell populations. -->
<!-- ```{r include=FALSE} -->
<!-- old_path <- Sys.getenv("PATH") -->
<!-- Sys.setenv(PATH = paste(old_path, "/Users/stuartt/mambaforge/bin", sep = ":")) -->
<!-- ``` -->
<!-- ```{r message=FALSE, warning=FALSE} -->
<!-- # call peaks using MACS2 -->
<!-- peaks <- CallPeaks(pbmc) -->
<!-- # remove peaks on nonstandard chromosomes and in genomic blacklist regions -->
<!-- peaks <- keepStandardChromosomes(peaks, pruning.mode = "coarse") -->
<!-- peaks <- subsetByOverlaps(x = peaks, ranges = blacklist_hg38_unified, invert = TRUE) -->
<!-- ``` -->
<!-- ```{r include=FALSE} -->
<!-- gc() -->
<!-- ``` -->
<!-- ```{r message=FALSE, warning=FALSE} -->
<!-- # quantify counts in each peak -->
<!-- macs2_counts <- FeatureMatrix( -->
<!-- fragments = Fragments(pbmc), -->
<!-- features = peaks, -->
<!-- cells = colnames(pbmc) -->
<!-- ) -->
<!-- ``` -->
<!-- ```{r include=FALSE} -->
<!-- gc() -->
<!-- ``` -->
<!-- ```{r} -->
<!-- # create a new assay using the MACS2 peak set and add it to the Seurat object -->
<!-- pbmc[["peaks"]] <- CreateChromatinAssay( -->
<!-- counts = macs2_counts, -->
<!-- fragments = fragpath, -->
<!-- annotation = annotation -->
<!-- ) -->
<!-- ``` -->
## Gene expression data processing
We can normalize the gene expression data using SCTransform, and reduce the dimensionality
using PCA.
```{r results='hide', message=FALSE, warning=FALSE}
DefaultAssay(pbmc) <- "RNA"
pbmc <- SCTransform(pbmc)
pbmc <- RunPCA(pbmc)
```
## DNA accessibility data processing
Here we process the DNA accessibility assay the same way we would process a
scATAC-seq dataset, by performing latent semantic indexing (LSI).
```{r message=FALSE, warning=FALSE}
DefaultAssay(pbmc) <- "ATAC"
pbmc <- FindTopFeatures(pbmc, min.cutoff = 5)
pbmc <- RunTFIDF(pbmc)
pbmc <- RunSVD(pbmc)
```
## Annotating cell types
To annotate cell types in the dataset we can transfer cell labels from an existing
PBMC reference dataset using tools in the Seurat package. See the
Seurat reference mapping [vignette](https://satijalab.org/seurat/v4.0/reference_mapping.html)
for more information.
We'll use an annotated PBMC reference dataset from [Hao et al. (2020)](https://www.biorxiv.org/content/10.1101/2020.10.12.335331v1),
available for download here: https://atlas.fredhutch.org/data/nygc/multimodal/pbmc_multimodal.h5seurat
Note that the SeuratDisk package is required to load the reference dataset.
Installation instructions for SeuratDisk can be found [here](https://github.com/mojaveazure/seurat-disk).
```{r message=FALSE, warning=FALSE}
library(SeuratDisk)
# load PBMC reference
reference <- LoadH5Seurat("../vignette_data/multiomic/pbmc_multimodal.h5seurat", assays = list("SCT" = "counts"), reductions = 'spca')
reference <- UpdateSeuratObject(reference)
DefaultAssay(pbmc) <- "SCT"
# transfer cell type labels from reference to query
transfer_anchors <- FindTransferAnchors(
reference = reference,
query = pbmc,
normalization.method = "SCT",
reference.reduction = "spca",
recompute.residuals = FALSE,
dims = 1:50
)
predictions <- TransferData(
anchorset = transfer_anchors,
refdata = reference$celltype.l2,
weight.reduction = pbmc[['pca']],
dims = 1:50
)
pbmc <- AddMetaData(
object = pbmc,
metadata = predictions
)
# set the cell identities to the cell type predictions
Idents(pbmc) <- "predicted.id"
# remove low-quality predictions
pbmc <- pbmc[, pbmc$prediction.score.max > 0.5]
```
## Joint UMAP visualization
Using the weighted nearest neighbor methods in [Seurat v4](https://www.biorxiv.org/content/10.1101/2020.10.12.335331v1),
we can compute a joint neighbor graph that represent both the gene expression and
DNA accessibility measurements.
```{r message=FALSE, warning=FALSE}
# build a joint neighbor graph using both assays
pbmc <- FindMultiModalNeighbors(
object = pbmc,
reduction.list = list("pca", "lsi"),
dims.list = list(1:50, 2:40),
modality.weight.name = "RNA.weight",
verbose = TRUE
)
# build a joint UMAP visualization
pbmc <- RunUMAP(
object = pbmc,
nn.name = "weighted.nn",
assay = "RNA",
verbose = TRUE
)
DimPlot(pbmc, label = TRUE, repel = TRUE, reduction = "umap") + NoLegend()
```
## Linking peaks to genes
For each gene, we can find the set of peaks that may regulate the gene by by
computing the correlation between gene expression and accessibility at nearby
peaks, and correcting for bias due to GC content, overall accessibility, and
peak size. See the [Signac paper](https://www.biorxiv.org/content/10.1101/2020.11.09.373613v1)
for a full description of the method we use to link peaks to genes.
Running this step on the whole genome can be time consuming, so here we demonstrate
peak-gene links for a subset of genes as an example. The same function can be used
to find links for all genes by omitting the `genes.use` parameter:
```{r message=FALSE, warning=FALSE}
DefaultAssay(pbmc) <- "ATAC"
# first compute the GC content for each peak
pbmc <- RegionStats(pbmc, genome = BSgenome.Hsapiens.UCSC.hg38)
# link peaks to genes
pbmc <- LinkPeaks(
object = pbmc,
peak.assay = "ATAC",
expression.assay = "SCT",
genes.use = c("LYZ", "MS4A1")
)
```
We can visualize these links using the `CoveragePlot()` function, or alternatively
we could use the `CoverageBrowser()` function in an interactive analysis:
```{r fig.height=10, message=FALSE, warning=FALSE}
idents.plot <- c("B naive", "B intermediate", "B memory",
"CD14 Mono", "CD16 Mono", "CD8 TEM", "CD8 Naive")
p1 <- CoveragePlot(
object = pbmc,
region = "MS4A1",
features = "MS4A1",
expression.assay = "SCT",
idents = idents.plot,
extend.upstream = 500,
extend.downstream = 10000
)
p2 <- CoveragePlot(
object = pbmc,
region = "LYZ",
features = "LYZ",
expression.assay = "SCT",
idents = idents.plot,
extend.upstream = 8000,
extend.downstream = 5000
)
patchwork::wrap_plots(p1, p2, ncol = 1)
```
```{r include=FALSE}
saveRDS(object = pbmc, file = "../vignette_data/pbmc_multiomic.rds")
```
<details>
<summary>**Session Info**</summary>
```{r}
sessionInfo()
```
</details>