In this tutorial, 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 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:

mouse_brain <- readRDS("../vignette_data/adult_mouse_brain.rds")
mouse_brain
## An object of class Seurat 
## 179010 features across 3512 samples within 2 assays 
## Active assay: peaks (157203 features, 157203 variable features)
##  1 other assay present: RNA
##  2 dimensional reductions calculated: lsi, umap
p1 <- DimPlot(mouse_brain, label = TRUE, pt.size = 0.1) + NoLegend()
p1

Adding motif information to the Seurat object

To add the DNA sequence motif information required for motif analyses, we can run the AddMotifs() function:

# Get a list of motif position frequency matrices from the JASPAR database
pfm <- getMatrixSet(
  x = JASPAR2020,
  opts = list(collection = "CORE", tax_group = 'vertebrates', all_versions = FALSE)
)

# add motif information
mouse_brain <- AddMotifs(
  object = mouse_brain,
  genome = BSgenome.Mmusculus.UCSC.mm10,
  pfm = pfm
)

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, the AddMotifs() function construct a Motif object and adds it to our mouse brain dataset, along with other information such as the base composition of each peak. A motif object can be added to any Seurat assay using the SetAssayData() function. See the object interaction vignette for more information.

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. For sparse data (such as scATAC-seq), we find it is often necessary to lower the min.pct threshold in FindMarkers() from the default (0.1, which was designed for scRNA-seq data).

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.

da_peaks <- FindMarkers(
  object = mouse_brain,
  ident.1 = 'Pvalb',
  ident.2 = 'Sst',
  only.pos = TRUE,
  test.use = 'LR',
  min.pct = 0.05,
  latent.vars = 'nCount_peaks'
)

# get top differentially accessible peaks
top.da.peak <- rownames(da_peaks[da_peaks$p_val < 0.005, ])

Optional: choosing a set of background peaks

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().

# 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
meta.feature <- GetAssayData(mouse_brain, assay = "peaks", slot = "meta.features")
peaks.matched <- MatchRegionStats(
  meta.feature = meta.feature[open.peaks, ],
  query.feature = meta.feature[top.da.peak, ],
  n = 50000
)
## Matching GC.percent distribution

peaks.matched can then be used as the background peak set by setting background=peaks.matched in FindMotifs().

# test enrichment
enriched.motifs <- FindMotifs(
  object = mouse_brain,
  features = top.da.peak
)
## Selecting background regions to match input sequence characteristics
## Matching GC.percent distribution
## Testing motif enrichment in 2082 regions
motif observed background percent.observed percent.background fold.enrichment pvalue motif.name
MA0497.1 MA0497.1 837 9229 40.20173 23.0725 1.742409 0 MEF2C
MA1151.1 MA1151.1 411 3210 19.74063 8.0250 2.459892 0 RORC
MA0773.1 MA0773.1 568 5518 27.28146 13.7950 1.977634 0 MEF2D
MA1150.1 MA1150.1 381 3059 18.29971 7.6475 2.392901 0 RORB
MA0660.1 MA0660.1 484 4461 23.24688 11.1525 2.084454 0 MEF2B
MA0052.4 MA0052.4 781 8939 37.51201 22.3475 1.678577 0 MEF2A

We can also plot the position weight matrices for the motifs, so we can visualize the different motif sequences.

MotifPlot(
  object = mouse_brain,
  motifs = head(rownames(enriched.motifs))
)
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.

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. 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 for a complete description of the method.

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).

When performing differential testing on the chromVAR z-score, we can set mean.fxn=rowMeans and fc.name="avg_diff" in the FindMarkers() function so that the fold-change calculation computes the average difference in z-score between the groups.

differential.activity <- FindMarkers(
  object = mouse_brain,
  ident.1 = 'Pvalb',
  ident.2 = 'Sst',
  only.pos = TRUE,
  mean.fxn = rowMeans,
  fc.name = "avg_diff"
)

MotifPlot(
  object = mouse_brain,
  motifs = head(rownames(differential.activity)),
  assay = 'peaks'
)

Session Info

## R version 4.1.0 (2021-05-18)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.2 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] patchwork_1.1.1                    BSgenome.Mmusculus.UCSC.mm10_1.4.0
##  [3] BSgenome_1.60.0                    rtracklayer_1.52.1                
##  [5] Biostrings_2.60.2                  XVector_0.32.0                    
##  [7] GenomicRanges_1.44.0               GenomeInfoDb_1.28.4               
##  [9] IRanges_2.26.0                     S4Vectors_0.30.0                  
## [11] BiocGenerics_0.38.0                TFBSTools_1.30.0                  
## [13] JASPAR2020_0.99.10                 SeuratObject_4.0.2                
## [15] Seurat_4.0.4                       Signac_1.4.0                      
## 
## loaded via a namespace (and not attached):
##   [1] rappdirs_0.3.3              SnowballC_0.7.0            
##   [3] scattermore_0.7             GGally_2.1.2               
##   [5] R.methodsS3_1.8.1           ragg_1.1.3                 
##   [7] nabor_0.5.0                 tidyr_1.1.3                
##   [9] ggplot2_3.3.5               bit64_4.0.5                
##  [11] knitr_1.34                  irlba_2.3.3                
##  [13] DelayedArray_0.18.0         R.utils_2.10.1             
##  [15] data.table_1.14.0           rpart_4.1-15               
##  [17] KEGGREST_1.32.0             RCurl_1.98-1.5             
##  [19] AnnotationFilter_1.16.0     generics_0.1.0             
##  [21] GenomicFeatures_1.44.2      cowplot_1.1.1              
##  [23] RSQLite_2.2.8               RANN_2.6.1                 
##  [25] chromVAR_1.14.0             future_1.22.1              
##  [27] bit_4.0.4                   tzdb_0.1.2                 
##  [29] spatstat.data_2.1-0         xml2_1.3.2                 
##  [31] httpuv_1.6.3                SummarizedExperiment_1.22.0
##  [33] assertthat_0.2.1            DirichletMultinomial_1.34.0
##  [35] xfun_0.26                   hms_1.1.0                  
##  [37] jquerylib_0.1.4             evaluate_0.14              
##  [39] promises_1.2.0.1            fansi_0.5.0                
##  [41] restfulr_0.0.13             progress_1.2.2             
##  [43] caTools_1.18.2              dbplyr_2.1.1               
##  [45] igraph_1.2.6                DBI_1.1.1                  
##  [47] htmlwidgets_1.5.4           sparsesvd_0.2              
##  [49] reshape_0.8.8               spatstat.geom_2.2-2        
##  [51] purrr_0.3.4                 ellipsis_0.3.2             
##  [53] dplyr_1.0.7                 backports_1.2.1            
##  [55] annotate_1.70.0             biomaRt_2.48.3             
##  [57] deldir_0.2-10               MatrixGenerics_1.4.3       
##  [59] vctrs_0.3.8                 Biobase_2.52.0             
##  [61] ensembldb_2.16.4            ROCR_1.0-11                
##  [63] abind_1.4-5                 cachem_1.0.6               
##  [65] ggforce_0.3.3               checkmate_2.0.0            
##  [67] sctransform_0.3.2           GenomicAlignments_1.28.0   
##  [69] prettyunits_1.1.1           goftest_1.2-2              
##  [71] cluster_2.1.2               lazyeval_0.2.2             
##  [73] seqLogo_1.58.0              crayon_1.4.1               
##  [75] labeling_0.4.2              slam_0.1-48                
##  [77] pkgconfig_2.0.3             tweenr_1.0.2               
##  [79] nlme_3.1-152                ProtGenerics_1.24.0        
##  [81] nnet_7.3-16                 rlang_0.4.11               
##  [83] globals_0.14.0              lifecycle_1.0.0            
##  [85] miniUI_0.1.1.1              filelock_1.0.2             
##  [87] BiocFileCache_2.0.0         dichromat_2.0-0            
##  [89] rprojroot_2.0.2             polyclip_1.10-0            
##  [91] matrixStats_0.61.0          lmtest_0.9-38              
##  [93] graph_1.70.0                ggseqlogo_0.1              
##  [95] Matrix_1.3-4                zoo_1.8-9                  
##  [97] base64enc_0.1-3             ggridges_0.5.3             
##  [99] png_0.1-7                   viridisLite_0.4.0          
## [101] rjson_0.2.20                bitops_1.0-7               
## [103] R.oo_1.24.0                 KernSmooth_2.23-20         
## [105] blob_1.2.2                  stringr_1.4.0              
## [107] parallelly_1.28.1           readr_2.0.1                
## [109] jpeg_0.1-9                  CNEr_1.28.0                
## [111] scales_1.1.1                memoise_2.0.0              
## [113] magrittr_2.0.1              plyr_1.8.6                 
## [115] ica_1.0-2                   zlibbioc_1.38.0            
## [117] compiler_4.1.0              BiocIO_1.2.0               
## [119] RColorBrewer_1.1-2          fitdistrplus_1.1-5         
## [121] Rsamtools_2.8.0             listenv_0.8.0              
## [123] pbapply_1.5-0               htmlTable_2.2.1            
## [125] Formula_1.2-4               mgcv_1.8-36                
## [127] MASS_7.3-54                 tidyselect_1.1.1           
## [129] stringi_1.7.4               textshaping_0.3.5          
## [131] highr_0.9                   yaml_2.2.1                 
## [133] latticeExtra_0.6-29         ggrepel_0.9.1              
## [135] grid_4.1.0                  sass_0.4.0                 
## [137] VariantAnnotation_1.38.0    fastmatch_1.1-3            
## [139] tools_4.1.0                 future.apply_1.8.1         
## [141] rstudioapi_0.13             TFMPvalue_0.0.8            
## [143] lsa_0.73.2                  foreign_0.8-81             
## [145] gridExtra_2.3               farver_2.1.0               
## [147] Rtsne_0.15                  digest_0.6.27              
## [149] BiocManager_1.30.16         shiny_1.6.0                
## [151] pracma_2.3.3                qlcMatrix_0.9.7            
## [153] motifmatchr_1.14.0          Rcpp_1.0.7                 
## [155] later_1.3.0                 RcppAnnoy_0.0.19           
## [157] OrganismDbi_1.34.0          httr_1.4.2                 
## [159] AnnotationDbi_1.54.1        ggbio_1.40.0               
## [161] biovizBase_1.40.0           colorspace_2.0-2           
## [163] XML_3.99-0.8                fs_1.5.0                   
## [165] tensor_1.5                  reticulate_1.22            
## [167] splines_4.1.0               uwot_0.1.10                
## [169] RBGL_1.68.0                 RcppRoll_0.3.0             
## [171] spatstat.utils_2.2-0        pkgdown_1.6.1.9001         
## [173] plotly_4.9.4.1              systemfonts_1.0.2          
## [175] xtable_1.8-4                jsonlite_1.7.2             
## [177] poweRlaw_0.70.6             R6_2.5.1                   
## [179] Hmisc_4.5-0                 pillar_1.6.2               
## [181] htmltools_0.5.2             mime_0.11                  
## [183] glue_1.4.2                  fastmap_1.1.0              
## [185] DT_0.19                     BiocParallel_1.26.2        
## [187] codetools_0.2-18            utf8_1.2.2                 
## [189] lattice_0.20-44             bslib_0.3.0                
## [191] spatstat.sparse_2.0-0       tibble_3.1.4               
## [193] curl_4.3.2                  leiden_0.3.9               
## [195] gtools_3.9.2                GO.db_3.13.0               
## [197] limma_3.48.3                survival_3.2-11            
## [199] docopt_0.7.1                rmarkdown_2.11             
## [201] desc_1.3.0                  munsell_0.5.0              
## [203] GenomeInfoDbData_1.2.6      reshape2_1.4.4             
## [205] gtable_0.3.0                spatstat.core_2.3-0