-
Notifications
You must be signed in to change notification settings - Fork 0
/
Motif analysis with Signac
452 lines (188 loc) · 7.25 KB
/
Motif analysis with Signac
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
title: "Motif analysis with Signac"
date: 'Compiled: `r format(Sys.Date(), "%B %d, %Y")`'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
In this analysis, we will perform DNA sequence motif analysis in Signac. We will
explore two complementary options for performing motif analysis: one by finding
overrepresented motifs in a set of differentially accessible peaks, one method
performing differential motif activity analysis between groups of cells.
In this demonstration we use data from the adult mouse brain. See our
[vignette](mouse_brain_vignette.html) for the code used to generate this object,
and links to the raw data. First, load the required packages and the
pre-computed Seurat object:
```{r message=FALSE, warning=FALSE}
library(Signac)
library(Seurat)
library(JASPAR2020)
library(TFBSTools)
library(BSgenome.Mmusculus.UCSC.mm10)
library(patchwork)
set.seed(1234)
```
```{r message=FALSE, warning=FALSE}
mouse_brain <- readRDS("../vignette_data/adult_mouse_brain.rds")
mouse_brain
```
```{r message=FALSE, warning=FALSE}
p1 <- DimPlot(mouse_brain, label = TRUE, pt.size = 0.1) + NoLegend()
p1
```
## The Motif class
To facilitate motif analysis in Signac, we have create the `Motif` class to
store all the required information, including a list of position weight matrices
(PWMs) or position frequency matrices (PFMs) and a motif occurrence matrix.
Here, we construct a `Motif` object and add it to our mouse brain dataset. A
motif object can be added to any Seurat assay using the `SetAssayData()`
function. See the [object interaction vignette](data_structures.html) for
more information.
```{r message=FALSE, warning=FALSE}
# Get a list of motif position frequency matrices from the JASPAR database
pfm <- getMatrixSet(
x = JASPAR2020,
opts = list(species = 9606, all_versions = FALSE)
)
# Scan the DNA sequence of each peak for the presence of each motif
motif.matrix <- CreateMotifMatrix(
features = granges(mouse_brain),
pwm = pfm,
genome = 'mm10',
use.counts = FALSE
)
# Create a new Mofif object to store the results
motif <- CreateMotifObject(
data = motif.matrix,
pwm = pfm
)
# Add the Motif object to the assay
mouse_brain <- SetAssayData(
object = mouse_brain,
assay = 'peaks',
slot = 'motifs',
new.data = motif
)
mouse_brain[["peaks"]]
```
In order to test for overrepresented motifs, we also need to compute some
sequence characteristics of the peaks, such as GC content, sequence length, and
dinucleotide frequency. The `RegionStats()` function computes this information
for us and stores the results in the feature metadata in the Seurat object.
```{r message=FALSE, warning=FALSE}
mouse_brain <- RegionStats(object = mouse_brain, genome = BSgenome.Mmusculus.UCSC.mm10)
```
## Finding overrepresented motifs
To identify potentially important cell-type-specific regulatory sequences, we
can search for DNA motifs that are overrepresented in a set of peaks that are
differentially accessible between cell types.
Here, we find differentially accessible peaks between Pvalb and Sst inhibitory
interneurons. We then perform a hypergeometric test to test the probability of
observing the motif at the given frequency by chance, comparing with a
background set of peaks matched for GC content.
```{r message=FALSE, warning=FALSE}
da_peaks <- FindMarkers(
object = mouse_brain,
ident.1 = 'Pvalb',
ident.2 = 'Sst',
only.pos = TRUE,
test.use = 'LR',
latent.vars = 'nCount_peaks'
)
# get top differentially accessible peaks
top.da.peak <- rownames(da_peaks[da_peaks$p_val < 0.005, ])
```
<details>
<summary>**Optional: choosing a set of background peaks**</summary>
Matching the set of background peaks is essential when finding enriched DNA
sequence motifs. By default, we choose a set of peaks matched for GC content,
but it can be sometimes be beneficial to further restrict the background peaks
to those that are accessible in the groups of cells compared when finding
differentially accessible peaks.
The `AccessiblePeaks()` function can be used to find a set of peaks that are
open in a subset of cells. We can use this function to first restrict the set
of possible background peaks to those peaks that were open in the set of cells
compared in `FindMarkers()`, and then create a GC-content-matched set of peaks
from this larger set using `MatchRegionStats()`.
```{r}
# find peaks open in Pvalb or Sst cells
open.peaks <- AccessiblePeaks(mouse_brain, idents = c("Pvalb", "Sst"))
# match the overall GC content in the peak set
peaks.matched <- MatchRegionStats(
meta.feature = GetAssayData(mouse_brain, assay = "peaks", slot = "meta.features")[open.peaks, ],
regions = top.da.peak,
n = 50000
)
```
`peaks.matched` can then be used as the background peak set by setting
`background=peaks.matched` in `FindMotifs()`.
</details>
```{r}
# test enrichment
enriched.motifs <- FindMotifs(
object = mouse_brain,
features = top.da.peak
)
```
```{r}
knitr::kable(head(enriched.motifs))
```
We can also plot the position weight matrices for the motifs, so we can
visualize the different motif sequences.
```{r}
MotifPlot(
object = mouse_brain,
motifs = head(rownames(enriched.motifs))
)
```
We and others have previously shown that Mef-family motifs, particularly
*Mef2c*, are enriched in Pvalb-specific peaks in scATAC-seq data
(https://doi.org/10.1016/j.cell.2019.05.031; https://doi.org/10.1101/615179),
and further shown that *Mef2c* is required for the development of Pvalb
interneurons (https://www.nature.com/articles/nature25999). Here our results are
consistent with these findings, and we observe a strong enrichment of Mef-family
motifs in the top results from `FindMotifs()`.
## Computing motif activities
We can also compute a per-cell motif activity score by running
[chromVAR](https://greenleaflab.github.io/chromVAR/index.html). This allows us
to visualize motif activities per cell, and also provides an alternative method
of identifying differentially-active motifs between cell types.
ChromVAR identifies motifs associated with variability in chromatin
accessibility between cells. See the chromVAR
[paper](https://www.nature.com/articles/nmeth.4401) for a complete description
of the method.
```{r message=FALSE, warning=FALSE, fig.width=12}
mouse_brain <- RunChromVAR(
object = mouse_brain,
genome = BSgenome.Mmusculus.UCSC.mm10
)
DefaultAssay(mouse_brain) <- 'chromvar'
# look at the activity of Mef2c
p2 <- FeaturePlot(
object = mouse_brain,
features = "MA0497.1",
min.cutoff = 'q10',
max.cutoff = 'q90',
pt.size = 0.1
)
p1 + p2
```
We can also directly test for differential activity scores between cell types.
This tends to give similar results as performing an enrichment test on
differentially accessible peaks between the cell types (shown above).
```{r message=FALSE, warning=FALSE}
differential.activity <- FindMarkers(
object = mouse_brain,
ident.1 = 'Pvalb',
ident.2 = 'Sst',
only.pos = TRUE,
test.use = 'LR',
latent.vars = 'nCount_peaks'
)
MotifPlot(
object = mouse_brain,
motifs = head(rownames(differential.activity)),
assay = 'peaks'
)
```
##################################