Differential analysis and motif interaction analysis

Introduction

In this vignette, we explore methods to identify synergies (or antagonisms) between TFs. As a example dataset, we use a subset of an ATAC-seq dataset of A549 cells upon ligand-based activation of the glucocorticoid receptor (GCR), encoded by the NR3C1 gene.

First, we load the package and the dataset:

library(betterChromVAR)
library(SummarizedExperiment)
data("NR3C1example", package="betterChromVAR")
peakSE
## class: RangedSummarizedExperiment 
## dim: 19143 6 
## metadata(0):
## assays(1): counts
## rownames(19143): chr1:778656-778955 chr1:827313-827612 ...
##   chr3:198092453-198092752 chr3:198143733-198144032
## rowData names(3): name score bias
## colnames(6): CTRL1.bam CTRL2.bam ... NR3C1_2.bam NR3C1_3.bam
## colData names(2): depth group
motifMatches
## class: RangedSummarizedExperiment 
## dim: 19143 29 
## metadata(0):
## assays(1): motifMatches
## rownames(19143): chr1:778656-778955 chr1:827313-827612 ...
##   chr3:198092453-198092752 chr3:198143733-198144032
## rowData names(3): name score bias
## colnames(29): ARNT CEBPG ... TYY1 ZN133
## colData names(1): name

The peakSE object contains ATAC peaks counts for each 6 samples, while the motifMatches object indicates which peak matches which of a selection of 29 motifs. For discussion about how exactly to generate those kinds of input, see the betterChromVAR package.

Deviation-based methods

Motif deviations, as for instance computed by the betterChromVAR package, quantify the relative accessibility of given DNA motifs across samples/cells. These motif scores are then use to inference the relative activity of the corresponding TFs, and can then be used for differential analysis across conditions. If you are not familiar with motif deviations, it is recommended that you read up on it, for instance the documentation of the chromVAR and/or betterChromVAR packages.

Standard differential motif accessibility using betterChromVAR

First, we illustrate the effect of the treatment of GCR motif accessibility by computing standard motif deviations, followed by differential testing with fitDeviations(), a wrapper around limma that moderates the variance according to the number of motif matches 1:

dev <- betterChromVAR(peakSE, motifMatches)
dev
## class: SummarizedExperiment 
## dim: 29 6 
## metadata(0):
## assays(2): deviations z
## rownames(29): ARNT CEBPG ... TYY1 ZN133
## rowData names(9): name N ... var.pval var.adjPval
## colnames(6): CTRL1.bam CTRL2.bam ... NR3C1_2.bam NR3C1_3.bam
## colData names(2): depth group
fit <- fitDeviations(dev, design=~group)
DAA <- as.data.frame(limma::topTable(fit, coef=2))
DAA
##               logFC       AveExpr         t      P.Value    adj.P.Val         B
## GCR    0.0031509256 -1.039545e-04 12.803448 5.831167e-09 1.691039e-07  7.606556
## MCR    0.0028847231 -9.310033e-05 11.874942 1.497669e-08 2.171621e-07  6.599524
## GATA6  0.0004114021 -1.761540e-05  3.234830 6.203538e-03 5.996753e-02 -6.960836
## RUNX1  0.0002982595 -9.442367e-06  2.460723 2.794476e-02 2.025995e-01 -8.437284
## FOXA3  0.0002977574 -5.862598e-06  2.293394 3.835893e-02 2.224818e-01 -8.738740
## CTCFL -0.0002040309  9.652794e-06 -2.168217 4.844654e-02 2.341583e-01 -8.958089
## SRF   -0.0003057863  2.866207e-06 -1.960873 7.074622e-02 2.930915e-01 -9.307709
## GATA1  0.0002364160 -1.305049e-05  1.698395 1.122298e-01 3.523158e-01 -9.721003
## SOX12  0.0002881680 -1.278130e-05  1.682412 1.153417e-01 3.523158e-01 -9.744966
## SOX2   0.0002365773 -1.049314e-05  1.651921 1.214882e-01 3.523158e-01 -9.790268

The results show GCR as the most differentially-accessible motif between the conditions, as expected, closely followed by the mineralocorticoid receptor (MCR), which has a motif very similar to GCR. We could also look at the pattern across samples for top motifs (e.g. using sechm).

Note that the DAA table reports a logFC, because that is what limma outputs, however these cannot be interpreted as fold-changes, and rather represent differences between the conditions.

Testing for motif interactions

Having identified GCR as the main motif differentially-accessible across conditions, we now want to know whether these differences are particularly at sites that have both GCR and some other motif (or the opposite, particularly at sites that do not harbor the other motif). Computationally speaking, we want to test whether the deviation differences at intersecting sites (i.e.  sites that harbor both motifs) are significantly larger (or smaller) than at sites harboring either motif.

To this end, we first compute deviations for the GCR sites, split according to whether they also harbor each of the other motifs (both), or not (baitOnly), as well as for the sites that have the other motif but no GCR motif (partnerOnly):

idev <- getInteractionsDeviations(peakSE, motifMatches, bait="GCR", minCount=10)
table(rowData(idev)$set)
## 
##        bait        both    baitOnly partnerOnly 
##           1          21          21          21

Next, we test for a significant interaction with respect to the bait motif. For each partner motif, the interaction score is the difference between the deviation at sites with both motifs, and the sum of the deviations at sites with each of the motifs alone (i.e. what would be expected if the two motifs acted independently and additively, thereby taking into account the response of the partner’s own sites). We then test how this score differs between groups:

res <- discoverMotifInteractions(idev, "group")
head(res)
##     contrast motif overlap.N overlap.percentOfBait overlap.jaccard
## 1 NR3C1-CTRL   THA        22                  4.84      0.01815182
## 2 NR3C1-CTRL  JUND        66                 14.51      0.02373247
## 3 NR3C1-CTRL CTCFL        63                 13.85      0.01498216
## 4 NR3C1-CTRL ZN133        19                  4.18      0.01954733
## 5 NR3C1-CTRL  SOX2        19                  4.18      0.01744720
## 6 NR3C1-CTRL RUNX1        27                  5.93      0.01815736
##   overlap.log2Enr   difference         t      P.Value    adj.P.Val
## 1       0.2487587  0.004873025 10.676170 1.068217e-05 0.0002243256
## 2       0.2151990  0.004107921  9.329923 2.677814e-05 0.0002811705
## 3      -0.5246243 -0.003800442 -8.362367 5.580567e-05 0.0003906397
## 4       0.5766449  0.004264001  6.964555 1.845011e-04 0.0009686310
## 5       0.2917949  0.005897191  6.406861 3.134624e-04 0.0013165421
## 6       0.1012072  0.004373580  5.493676 8.065444e-04 0.0028229055
##       diff.both diff.baitOnly diff.partnerOnly
## 1  0.0076339735   0.002831117    -3.660818e-05
## 2  0.0059543907   0.002162167    -2.735861e-04
## 3 -0.0002822017   0.003708910    -2.023842e-04
## 4  0.0071108030   0.002895023    -2.792411e-05
## 5  0.0084893442   0.002731238    -1.090546e-04
## 6  0.0071109959   0.002760364     9.946019e-05

We could plot these results in a kind of volcano plot:

library(ggplot2)
ggplot(res, aes(difference, -log10(adj.P.Val), size=overlap.N, label=motif)) + 
  geom_text() + theme_bw()

The difference column indicate by how much the response in the intersection (e.g. in sites that have both the bait and its interacting motif) differs from what is expected from the response in sites that have only one of the two motifs, and the columns diff.baitOnly, diff.partnerOnly and diff.both give the response in each set of sites. For example, since we established earlier that the treatment increases accessibility of GCR sites, and the difference in the interaction with CTCFL is negative, we can conclude that CTCFL appears to prevent GCR from having a positive impact. In contrast, sites that have the JUND motif (in addition to GCR) appear to increase in accessibility more than those that do not, in line with the known interaction between GCR and JUN/FOS family members.

Note that the p-values are meant to be used for ranking candidates rather than as calibrated error rates – they are far from calibrated (see below). Moreover, since the classes of sites are aggregated, the p-values indicate reflect the reproducibility across replicates, rather than the generalization across sites. For a test that accounts for the variability across sites and produces more calibrated p-values, see the last part of this vignette.

Investigating motif interactions through distance decay patterns

Next, we will explore a bit more in depth those candidate interactions by investigating their dependence on the distance between the two motifs. To this end, the exploreMotifInteraction function will produce deviations for the sites harboring only GCR, only the candidate partner, or both at given distance intervals of each other.

Computing this requires the motifs themselves and the genome sequence, e.g. 2 :

library(BSgenome.Hsapiens.UCSC.hg38)

# we precompute the betterChromVAR background to save computing time in case
# we check many interactions:
bg <- computeBackgrounds(peakSE, getBackgroundBins(peakSE))

# `motifs` is a list of motifs (e.g. a PFMatrixList, as provided in the example
# data); we look at two potential partners of GCR:
didevs <- lapply(c(JUND="JUND", CTCFL="CTCFL"), \(mo){
  exploreMotifInteraction(peakSE, motifs[c("GCR", mo)], bg = bg,
                          genome=BSgenome.Hsapiens.UCSC.hg38)
})

or each partner, we have deviations for different subsets of sites, which we melt into a data.frame for plotting:

dd <- do.call(rbind, lapply(names(didevs), \(mo){
  didev <- didevs[[mo]]
  d <- data.frame(feature=rep(row.names(didev), ncol(didev)),
                  group=rep(didev$group, each=nrow(didev)),
                  norm=as.vector(SummarizedExperiment::assay(didev, "norm")))
  d$feature <- factor(d$feature, row.names(didev))
  d$query <- mo
  d
}))
ggplot(dd, aes(feature, norm)) + geom_hline(yintercept=0, linetype="dashed") + 
  geom_boxplot(aes(fill=group)) + facet_wrap(~query, scale="free") + 
  theme_bw() + labs(x="Site type", y="Adjusted z-scores") + 
  theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5))

On the left of the first panel, we see the change in deviation upon ligand-based GCR activation (i.e. NR3C1 group vs CTRL) in sites harboring the GCR motif (independently of JUND status). Beside it, we see the same in sites harboring the JUND motif (independently of whether they also harbor a GCR motif), which show no difference between conditions. Next, we see GCR sites that are negative for JUND (which show a smaller impact that GCR sites more generally), followed by JUND sites negative for GCR (i.e. sites in which the other motif is neither present nor within the maximum distance). Finally, we see sites harboring both motifs, at difference ranges of distance from each other. The exact distances represent quantiles (so that each distance bin is equally populated) up to a maximum distance specified by the user.

We see that when sites have GCR and JUND motifs very close to each other, the difference in deviation is larger (i.e. the effect of GCR activation on accessibility is stronger), and that this decays with distance, as we would expect of a bona fide interaction. If the interaction is a physical interaction between the TFs, we would expect this to decay rapidly, otherwise it can decay more slowly.

In contrast, the putative interaction (antagonism) with CTCFL shows an inconsistent distance pattern: CTCFL appears to suppress the effect of GCR activation both when close or distant to the GCR motif, but not in the middle bin of 220-299bp. This makes the putative interaction less likely to be a direct physical interaction, but does not exclude an indirect interaction.



Peak-level analysis

The analyses above use the sets of sites as the unit of observation: the deviation of a set is computed in each sample, and compared across samples. The p-values therefore reflect how reproducibly a set of (fixed) sites differs between conditions, but not whether this generalizes across sites: a set of sites that is not special in any way will still have some reproducible difference between conditions, simply because the sites respond differently from one another. An alternative is to use the peaks themselves as the unit of inference. This is what the peakLevelMotifTests and peakLevelMotifInteractions functions do: the differential accessibility (log2-fold-change) of each peak is first estimated, and these are then modeled as a function of the presence of the motif(s) while adjusting for the peak’s accessibility and bias. The approach is related in spirit to motif activity response analysis (MARA, implemented in ISMARA), which models the signal of regulatory regions as a function of the motifs they harbor (Balwierz et al. 2014), but differs in that motifs are here tested separately rather than jointly (for step-wise joint testing, see the stepwisePeakLevelMotifTests() function).

peakLevelMotifInteractions runs the differential analysis of the peaks itself, while peakLevelMotifTests takes as input the results of a peak-level differential analysis provided by the user, along with the SummarizedExperiment it was run on. Both methods regress the peaks’ logFC on the presence of (one or combinations of) motif(s), as well as non-linear technical covariates. In both cases, each peak is weighted by the inverse of its logFC variance (reflecting how robust the logFC is across samples), plus a between-peak variance (taking the heterogeneity across sites harboring a motif into account). Finally, the variance is inflated to account for the correlation between peaks, as done by camera() in the limma package.

Note that the peak-level functions are considerably slower than the deviation- based ones, so consider using multithreading. Moreover, make sure to filter out low-count peaks (e.g. using edgeR::filterByExpr) before using these methods.

Peak-level differential motif accessibility

For each motif, peakLevelMotifTests tests whether the peaks harboring the motif change more (or less) between conditions than comparable peaks that do not harbor it. We first run a differential accessibility analysis of the peaks (here using limma-voom, but this could be any other method), and then provide its results to the function, along with the design matrix used to estimate the correlation between peaks:

design <- model.matrix(~group, data=as.data.frame(colData(peakSE)))
y <- limma::voom(assay(peakSE), design)
## voomLmFit is now recommended over voom
dea <- limma::topTable(limma::eBayes(limma::lmFit(y, design)), coef=2, number=Inf, sort.by="none")
pk <- peakLevelMotifTests(peakSE, dea, motifMatches, design=design, 
                          minCount=10)
head(pk[,c("motif","N","difference","P.Value","adj.P.Val")])
##   motif    N  difference      P.Value    adj.P.Val
## 1   GCR  455  0.24069132 1.763575e-14 5.114367e-13
## 2   MCR  573  0.21944830 5.785950e-11 8.389628e-10
## 3 GATA6 1579  0.03694015 9.842316e-03 9.514239e-02
## 4 CTCFL 3813 -0.03186819 2.550716e-02 1.770627e-01
## 5  FLI1 3429 -0.01444826 3.052804e-02 1.770627e-01
## 6 RUNX1 1059  0.01994942 9.470512e-02 4.159752e-01

Once more, the results indicate a strong response of the glucocorticoid receptor (GCR) and the highly similar MCR motif, as expected.

Peak-level motif interactions

Similarly, peakLevelMotifInteractions models the log-fold-change of the peaks as a function of the presence of the bait motif, of the partner motif, and of their interaction:

res2 <- peakLevelMotifInteractions(peakSE, motifMatches, bait="GCR", 
                                   group="group", minCount=10)
## voomLmFit is now recommended over voom
head(res2[,c("motif","overlap.N","difference","se","P.Value","adj.P.Val",
             "partner.diff")])
##   motif overlap.N difference         se      P.Value    adj.P.Val partner.diff
## 1 CTCFL        63 -0.3166131 0.06304951 4.608758e-06 9.678392e-05 -0.028258982
## 2  SOX2        19  0.5076490 0.15825383 4.877949e-03 5.121846e-02 -0.004486679
## 3  JUND        66  0.2296264 0.10245330 2.842950e-02 1.990065e-01 -0.016581051
## 4 SOX12        19 -0.1709758 0.12437459 1.861025e-01 5.956088e-01  0.040902642
## 5 RUNX1        27  0.2077556 0.15405819 1.891111e-01 5.956088e-01  0.011824572
## 6 FOXA3        30  0.1761408 0.13612351 2.058838e-01 5.956088e-01  0.020331625

In the above, difference is the interaction coefficient (on the log2 scale), and partner.diff is the effect of the treatment at sites with only the partner’s motif.

Comparison of the deviation-based and peak-level approaches

Differential motif accessibility

We first compare the motif-level statistics obtained from the deviations (using fitDeviations) to those of the peak-level approach:

fit <- fitDeviations(dev, design)
tt <- limma::topTable(fit, coef=2, number=Inf, sort.by="none")
cmp1 <- merge(data.frame(motif=row.names(tt), t.deviations=tt$t, 
                         FDR.deviations=tt$adj.P.Val),
              data.frame(pk[,c("motif","N","t","adj.P.Val")]), by="motif")
colnames(cmp1)[5:6] <- c("t.peaks", "FDR.peaks")
ggplot(cmp1, aes(t.deviations, t.peaks, label=motif)) + 
  geom_hline(yintercept=0, linetype="dashed") + 
  geom_vline(xintercept=0, linetype="dashed") +
  geom_point(aes(size=N), alpha=0.5) + geom_text(check_overlap=TRUE, vjust=-1) +
  theme_bw() + labs(x="t-value (deviations)", y="t-value (peak-level)")

The two approaches are in close agreement.

Motif interactions

A similar comparison for the two types of motif interactions analyses (both using GCR as a bait) :

cmp2 <- merge(res[,c("motif","overlap.N","t","adj.P.Val")], 
              res2[,c("motif","t","adj.P.Val")], by="motif",
              suffixes=c(".sample",".peak"))
ggplot(cmp2, aes(t.sample, t.peak, label=motif)) + 
  geom_hline(yintercept=0, linetype="dashed") + 
  geom_vline(xintercept=0, linetype="dashed") +
  geom_point(aes(size=overlap.N), alpha=0.5) + 
  geom_text(check_overlap=TRUE, vjust=-1) + theme_bw() + 
  labs(x="t-value (sample-level)", y="t-value (peak-level)")

Again the statistics are fairly strongly correlated. However, the deviation-based approach is much more liberal: it identifies 9 motifs at an FDR<0.05, versus 1 for the peak-level one (1 in common). This is to be expected, since the deviation-based approach aggregates partially overlapping sites, whereas the peak-level one takes into account the heterogeneity of the signal across sites of a motif. Of the known interactors, JUND shows a strong signal in the sample-level analysis, but only a nominal one at the peak-level (P=0.028). (Note that this example is a small dataset with few samples and a limited number of peaks.)

Behavior on random motifs

To illustrate the difference in calibration, we repeat the analyses with random sets of peaks, which should not have any specific response nor interaction with GCR. The following shows the proportion of these random motifs that are nominally significant (P<0.05) with each approach:

set.seed(1234)
nr <- nrow(peakSE)
rnd <- sapply(round(exp(runif(100, 6, 9))), function(n){
  x <- logical(nr)
  x[sample.int(nr, n)] <- TRUE
  x
})
colnames(rnd) <- paste0("random", seq_len(ncol(rnd)))
rnd <- cbind(GCR=as.vector(assay(motifMatches)[,"GCR"]), rnd)

ridev <- getInteractionsDeviations(peakSE, rnd, bait="GCR")
rres <- discoverMotifInteractions(ridev, "group")
rres2 <- peakLevelMotifInteractions(peakSE, rnd, bait="GCR", group="group")
## voomLmFit is now recommended over voom
data.frame(approach=c("deviations", "peak-level"),
           `% p<0.05`=c(sum(rres$P.Value<0.05),
                                 sum(rres2$P.Value<0.05)), check.names=FALSE)
##     approach % p<0.05
## 1 deviations       39
## 2 peak-level        1

Because these motifs have no true interaction with GCR, the proportion should be around 5%. The deviation-based approach is therefore clearly too liberal, while the peak-level approach is roughly calibrated. For these reasons, we recommend using the peak-level approach to identify interactions, and use the deviation-based approach only via exploreMotifInteraction() to investigate the dependence on distance.

References

Balwierz, Piotr J, Mikhail Pachkov, Phil Arnold, Andreas J Gruber, Mihaela Zavolan, and Erik van Nimwegen. 2014. “ISMARA: Automated Modeling of Genomic Signals as a Democracy of Regulatory Motifs.” Genome Research 24 (5): 869–84. https://doi.org/10.1101/gr.169508.113.

Session info

## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 26.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.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       
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] ggplot2_4.0.4               betterChromVAR_2.1.0       
##  [3] SummarizedExperiment_1.43.0 Biobase_2.73.2             
##  [5] GenomicRanges_1.67.0        Seqinfo_1.3.2              
##  [7] IRanges_2.47.5              S4Vectors_0.51.10          
##  [9] BiocGenerics_0.59.13        generics_0.1.4             
## [11] MatrixGenerics_1.25.0       matrixStats_1.5.0          
## [13] BiocStyle_2.41.0           
## 
## loaded via a namespace (and not attached):
##  [1] sass_0.5.0                SparseArray_1.13.5       
##  [3] lattice_0.23-1            digest_0.6.39            
##  [5] RColorBrewer_1.1-3        evaluate_1.0.5           
##  [7] sparseMatrixStats_1.25.0  grid_4.6.2               
##  [9] fastmap_1.2.0             jsonlite_2.0.0           
## [11] Matrix_1.7-6              limma_3.99.5             
## [13] BiocManager_1.30.27       scales_1.4.0             
## [15] Biostrings_2.81.9         codetools_0.2-20         
## [17] jquerylib_0.1.4           abind_1.4-8              
## [19] cli_3.6.6                 rlang_1.3.0              
## [21] crayon_1.5.3              XVector_0.53.0           
## [23] BiocNeighbors_2.7.3       splines_4.6.2            
## [25] withr_3.0.3               cachem_1.1.0             
## [27] DelayedArray_0.39.8       yaml_2.3.12              
## [29] otel_0.3.0                S4Arrays_1.13.3          
## [31] tools_4.6.2               parallel_4.6.2           
## [33] BiocParallel_1.47.0       vctrs_0.7.3              
## [35] buildtools_1.0.0          R6_2.6.1                 
## [37] lifecycle_1.0.5           gtable_0.3.6             
## [39] bslib_0.12.0              glue_1.8.1               
## [41] Rcpp_1.1.2                statmod_1.5.2            
## [43] xfun_0.62                 sys_3.4.3                
## [45] knitr_1.52                farver_2.1.2             
## [47] htmltools_0.5.9           labeling_0.4.3           
## [49] rmarkdown_2.32            maketools_1.3.2          
## [51] DelayedMatrixStats_1.35.0 compiler_4.6.2           
## [53] S7_1.0.0

  1. If you are not familiar with such differential testing, see the limma documentation.↩︎

  2. To avoid having the genome as a dependency, the precomputed didevs are included in the example data.↩︎