-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse neuroblastoma scATAC-seq
744 lines (314 loc) · 12.9 KB
/
mouse neuroblastoma scATAC-seq
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
title: "Analyzing adult mouse brain scATAC-seq"
output: html_document
date: 'Compiled: `r format(Sys.Date(), "%B %d, %Y")`'
```{r init, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
#For this tutorial, we will be analyzing a single-cell ATAC-seq dataset of adult
mouse brain cells provided by 10x Genomics. The following files are used in this
vignette, all available through the 10x Genomics website:
* The [Raw data](http://cf.10xgenomics.com/samples/cell-atac/1.1.0/atac_v1_adult_brain_fresh_5k/atac_v1_adult_brain_fresh_5k_filtered_peak_bc_matrix.h5)
* The [Metadata](http://cf.10xgenomics.com/samples/cell-atac/1.1.0/atac_v1_adult_brain_fresh_5k/atac_v1_adult_brain_fresh_5k_singlecell.csv)
* The [fragments file](http://cf.10xgenomics.com/samples/cell-atac/1.1.0/atac_v1_adult_brain_fresh_5k/atac_v1_adult_brain_fresh_5k_fragments.tsv.gz)
* The fragments file [index](http://cf.10xgenomics.com/samples/cell-atac/1.1.0/atac_v1_adult_brain_fresh_5k/atac_v1_adult_brain_fresh_5k_fragments.tsv.gz.tbi)
This vignette echoes the commands run in the introductory Signac vignette on
[human PBMC](https://satijalab.org/signac/articles/pbmc_vignette.html). We
provide the same analysis in a different system to demonstrate performance and
applicability to other tissue types, and to provide an example from another
species.
First load in Signac, Seurat, and some other packages we will be using for
analyzing mouse data.
```{r setup, message=FALSE}
library(Signac)
library(Seurat)
library(GenomeInfoDb)
library(EnsDb.Mmusculus.v79)
library(ggplot2)
library(patchwork)
set.seed(1234)
```
## Pre-processing workflow
```{r}
counts <- Read10X_h5("/home/stuartt/github/chrom/vignette_data/atac_v1_adult_brain_fresh_5k_filtered_peak_bc_matrix.h5")
metadata <- read.csv(
file = "/home/stuartt/github/chrom/vignette_data/atac_v1_adult_brain_fresh_5k_singlecell.csv",
header = TRUE,
row.names = 1
)
brain_assay <- CreateChromatinAssay(
counts = counts,
sep = c(":", "-"),
genome = "mm10",
fragments = '/home/stuartt/github/chrom/vignette_data/atac_v1_adult_brain_fresh_5k_fragments.tsv.gz',
min.cells = 1
)
brain <- CreateSeuratObject(
counts = brain_assay,
assay = 'peaks',
project = 'ATAC',
meta.data = metadata
)
```
We can also add gene annotations to the `brain` object for the mouse genome.
This will allow downstream functions to pull the gene annotation information
directly from the object.
```{r message=FALSE, warning=FALSE}
# extract gene annotations from EnsDb
annotations <- GetGRangesFromEnsDb(ensdb = EnsDb.Mmusculus.v79)
# change to UCSC style since the data was mapped to hg19
seqlevelsStyle(annotations) <- 'UCSC'
genome(annotations) <- "mm10"
# add the gene information to the object
Annotation(brain) <- annotations
```
## Computing QC Metrics
Next we compute some useful per-cell QC metrics.
```{r message=FALSE, warning=FALSE}
brain <- NucleosomeSignal(object = brain)
```
We can look at the fragment length periodicity for all the cells, and group by
cells with high or low nucleosomal signal strength. You can see that cells which
are outliers for the mononucleosomal/ nucleosome-free ratio have different
banding patterns. The remaining cells exhibit a pattern that is typical for a
successful ATAC-seq experiment.
```{r message=FALSE, warning=FALSE}
brain$nucleosome_group <- ifelse(brain$nucleosome_signal > 4, 'NS > 4', 'NS < 4')
FragmentHistogram(object = brain, group.by = 'nucleosome_group', region = 'chr1-1-10000000')
```
The enrichment of Tn5 integration events at transcriptional start sites (TSSs)
can also be an important quality control metric to assess the targeting of Tn5
in ATAC-seq experiments. The ENCODE consortium defined a TSS enrichment score as
the number of Tn5 integration site around the TSS normalized to the number of
Tn5 integration sites in flanking regions. See the ENCODE documentation for more
information about the TSS enrichment score
(https://www.encodeproject.org/data-standards/terms/). We can calculate the TSS
enrichment score for each cell using the `TSSEnrichment()` function in Signac.
```{r message=FALSE, warning=FALSE}
brain <- TSSEnrichment(brain, fast = FALSE)
```
```{r message=FALSE, warning=FALSE}
brain$high.tss <- ifelse(brain$TSS.enrichment > 2, 'High', 'Low')
TSSPlot(brain, group.by = 'high.tss') + NoLegend()
```
```{r message=FALSE, warning=FALSE, fig.width=12, fig.height=6}
brain$pct_reads_in_peaks <- brain$peak_region_fragments / brain$passed_filters * 100
brain$blacklist_ratio <- brain$blacklist_region_fragments / brain$peak_region_fragments
VlnPlot(
object = brain,
features = c('pct_reads_in_peaks', 'peak_region_fragments',
'TSS.enrichment', 'blacklist_ratio', 'nucleosome_signal'),
pt.size = 0.1,
ncol = 5
)
```
We remove cells that are outliers for these QC metrics.
```{r}
brain <- subset(
x = brain,
subset = peak_region_fragments > 3000 &
peak_region_fragments < 100000 &
pct_reads_in_peaks > 40 &
blacklist_ratio < 0.025 &
nucleosome_signal < 4 &
TSS.enrichment > 2
)
brain
```
## Normalization and linear dimensional reduction
```{r message=FALSE, warning=FALSE}
brain <- RunTFIDF(brain)
brain <- FindTopFeatures(brain, min.cutoff = 'q0')
brain <- RunSVD(object = brain)
```
The first LSI component often captures sequencing depth (technical variation)
rather than biological variation. If this is the case, the component should be
removed from downstream analysis. We can assess the correlation between each LSI
component and sequencing depth using the `DepthCor()` function:
```{r}
DepthCor(brain)
```
Here we see there is a very strong correlation between the first LSI component
and the total number of counts for the cell, so we will perform downstream steps
without this component.
## Non-linear dimension reduction and clustering
Now that the cells are embedded in a low-dimensional space, we can use methods
commonly applied for the analysis of scRNA-seq data to perform graph-based
clustering, and non-linear dimension reduction for visualization. The functions
`RunUMAP()`, `FindNeighbors()`, and `FindClusters()` all come from the Seurat
package.
```{r message=FALSE, warning=FALSE}
brain <- RunUMAP(
object = brain,
reduction = 'lsi',
dims = 2:30
)
brain <- FindNeighbors(
object = brain,
reduction = 'lsi',
dims = 2:30
)
brain <- FindClusters(
object = brain,
algorithm = 3,
resolution = 1.2,
verbose = FALSE
)
DimPlot(object = brain, label = TRUE) + NoLegend()
```
## Create a gene activity matrix
```{r, message=FALSE, warning=FALSE}
# compute gene activities
gene.activities <- GeneActivity(brain)
# add the gene activity matrix to the Seurat object as a new assay
brain[['RNA']] <- CreateAssayObject(counts = gene.activities)
brain <- NormalizeData(
object = brain,
assay = 'RNA',
normalization.method = 'LogNormalize',
scale.factor = median(brain$nCount_RNA)
)
```
```{r, fig.width=12, fig.height=10}
DefaultAssay(brain) <- 'RNA'
FeaturePlot(
object = brain,
features = c('Sst','Pvalb',"Gad2","Neurod6","Rorb","Syt6"),
pt.size = 0.1,
max.cutoff = 'q95',
ncol = 3
)
```
## Integrating with scRNA-seq data
To help interpret the scATAC-seq data, we can classify cells based on an
scRNA-seq experiment from the same biological system (the adult mouse brain).
We utilize methods for cross-modality integration and label transfer, described
[here](https://doi.org/10.1016/j.cell.2019.05.031), with a more in-depth
tutorial [here](https://satijalab.org/seurat/v3.0/atacseq_integration_vignette.html).
You can download the raw data for this experiment from the Allen Institute
[website](http://celltypes.brain-map.org/api/v2/well_known_file_download/694413985),
and view the code used to construct this object on
[GitHub](https://github.com/satijalab/Integration2019/blob/master/preprocessing_scripts/allen_brain.R).
Alternatively, you can download the pre-processed Seurat object
[here](https://www.dropbox.com/s/kqsy9tvsklbu7c4/allen_brain.rds?dl=0).
```{r warning=FALSE, message=FALSE}
# Load the pre-processed scRNA-seq data
allen_rna <- readRDS("/home/stuartt/github/chrom/vignette_data/allen_brain.rds")
allen_rna <- FindVariableFeatures(
object = allen_rna,
nfeatures = 5000
)
transfer.anchors <- FindTransferAnchors(
reference = allen_rna,
query = brain,
reduction = 'cca',
dims = 1:40
)
predicted.labels <- TransferData(
anchorset = transfer.anchors,
refdata = allen_rna$subclass,
weight.reduction = brain[['lsi']],
dims = 2:30
)
brain <- AddMetaData(object = brain, metadata = predicted.labels)
```
```{r fig.width=12}
plot1 <- DimPlot(allen_rna, group.by = 'subclass', label = TRUE, repel = TRUE) + NoLegend() + ggtitle('scRNA-seq')
plot2 <- DimPlot(brain, group.by = 'predicted.id', label = TRUE, repel = TRUE) + NoLegend() + ggtitle('scATAC-seq')
plot1 + plot2
```
<details>
<summary>**Why did we change default parameters?**</summary>
We changed default parameters for `FindIntegrationAnchors()` and
`FindVariableFeatures()` (including more features and dimensions). You can run
the analysis both ways, and observe very similar results. However, when using
default parameters we mislabel cluster 11 cells as Vip-interneurons, when they
are in fact a Meis2 expressing CGE-derived interneuron population recently
described by [us](https://www.nature.com/articles/nature25999) and
[others](https://www.nature.com/articles/ncomms14219). The reason is that this
subset is exceptionally rare in the scRNA-seq data (0.3%), and so the genes
define this subset (for example, *Meis2*) were too lowly expressed to be
selected in the initial set of variable features. We therefore need more genes
and dimensions to facilitate cross-modality mapping. Interestingly, this subset
is 10-fold more abundant in the scATAC-seq data compared to the scRNA-seq data
(see [this paper](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0209648)
for possible explanations.)
</details>
You can see that the RNA-based classifications are entirely consistent with the
UMAP visualization, computed only on the ATAC-seq data. We can now easily
annotate our scATAC-seq derived clusters (alternately, we could use the RNA
classifications themselves). We note three small clusters (13, 20, 21) which
represent subdivisions of the scRNA-seq labels. Try transferring the cluster
label (which shows finer distinctions) from the allen scRNA-seq dataset,
to annotate them!
```{r}
# replace each label with its most likely prediction
for(i in levels(brain)) {
cells_to_reid <- WhichCells(brain, idents = i)
newid <- names(sort(table(brain$predicted.id[cells_to_reid]),decreasing=TRUE))[1]
Idents(brain, cells = cells_to_reid) <- newid
}
```
## Find differentially accessible peaks between clusters
Here, we find differentially accessible regions between excitatory neurons in
different layers of the cortex.
```{r message=TRUE, warning=FALSE}
#switch back to working with peaks instead of gene activities
DefaultAssay(brain) <- 'peaks'
da_peaks <- FindMarkers(
object = brain,
ident.1 = c("L2/3 IT"),
ident.2 = c("L4", "L5 IT", "L6 IT"),
min.pct = 0.4,
test.use = 'LR',
latent.vars = 'peak_region_fragments'
)
head(da_peaks)
```
```{r fig.width=12}
plot1 <- VlnPlot(
object = brain,
features = rownames(da_peaks)[1],
pt.size = 0.1,
idents = c("L4","L5 IT","L2/3 IT")
)
plot2 <- FeaturePlot(
object = brain,
features = rownames(da_peaks)[1],
pt.size = 0.1,
max.cutoff = 'q95'
)
plot1 | plot2
```
```{r, warning=FALSE, message=FALSE}
open_l23 <- rownames(da_peaks[da_peaks$avg_logFC > 0.25, ])
open_l456 <- rownames(da_peaks[da_peaks$avg_logFC < -0.25, ])
closest_l23 <- ClosestFeature(brain, open_l23)
closest_l456 <- ClosestFeature(brain, open_l456)
head(closest_l23)
```
```{r, warning=FALSE, message=FALSE}
head(closest_l456)
```
## Plotting genomic regions
We can also create coverage plots grouped by cluster, cell type, or any other
metadata stored in the obect for any genomic region using the `CoveragePlot()`
function. These represent pseudo-bulk accessibility tracks, where signal from
all cells within a group have been averaged together to visualize the DNA
accessibility in a region.
```{r message=FALSE, warning=FALSE, out.width='90%', fig.height=10}
# set plotting order
levels(brain) <- c("L2/3 IT","L4","L5 IT","L5 PT","L6 CT", "L6 IT","NP","Sst","Pvalb","Vip","Lamp5","Meis2","Oligo","Astro","Endo","VLMC","Macrophage")
CoveragePlot(
object = brain,
region = c("Neurod6", "Gad2"),
extend.upstream = 1000,
extend.downstream = 1000,
ncol = 1
)
```
```{r message=FALSE, warning=FALSE, echo=FALSE}
saveRDS(object = brain, file = "../vignette_data/adult_mouse_brain.rds")
```
<details>
<summary>**Session Info**</summary>
```{r}
sessionInfo()