| name | bio-chipseq-differential-binding |
| description | Differential binding analysis using DiffBind. Compare ChIP-seq peaks between conditions with statistical rigor. Requires replicate samples. Outputs differentially bound regions with fold changes and p-values. Use when comparing ChIP-seq binding between conditions. |
| tool_type | r |
| primary_tool | DiffBind |
Version Compatibility
Reference examples tested with: DESeq2 1.42+, edgeR 4.0+
Before using code patterns, verify installed versions match. If versions differ:
- R:
packageVersion('<pkg>') then ?function_name to verify parameters
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
Differential Binding with DiffBind
"Compare ChIP-seq binding between conditions" → Identify genomic regions with statistically significant differences in transcription factor or histone mark occupancy between experimental groups.
- R:
DiffBind::dba() → dba.count() → dba.contrast() → dba.analyze()
Create Sample Sheet
Goal: Define the experimental design linking BAM files, peak files, and sample metadata for DiffBind.
Approach: Build a data frame (or CSV) with required columns mapping each sample to its files and conditions.
samples <- data.frame(
SampleID = c('ctrl_1', 'ctrl_2', 'treat_1', 'treat_2'),
Tissue = c('cell', 'cell', 'cell', 'cell'),
Factor = c('H3K4me3', 'H3K4me3', 'H3K4me3', 'H3K4me3'),
Condition = c('control', 'control', 'treatment', 'treatment'),
Replicate = c(1, 2, 1, 2),
bamReads = c('ctrl1.bam', 'ctrl2.bam', 'treat1.bam', 'treat2.bam'),
Peaks = c('ctrl1_peaks.narrowPeak', 'ctrl2_peaks.narrowPeak',
'treat1_peaks.narrowPeak', 'treat2_peaks.narrowPeak'),
PeakCaller = c('macs', 'macs', 'macs', 'macs')
)
write.csv(samples, 'samples.csv', row.names = FALSE)
Load Data
Goal: Initialize a DiffBind object from the sample sheet containing all samples and peaks.
Approach: Read the sample sheet CSV into a DBA object that identifies overlapping peaks across samples.
library(DiffBind)
dba_obj <- dba(sampleSheet = 'samples.csv')
dba_obj
Count Reads in Peaks
Goal: Quantify read coverage at consensus peak regions across all samples.
Approach: Count reads in summit-centered windows using dba.count, creating a count matrix for statistical testing.
dba_obj <- dba.count(dba_obj)
dba_obj <- dba.count(
dba_obj,
summits = 250,
minOverlap = 2
)
Normalize Data
Goal: Apply normalization to account for library size and composition differences between samples.
Approach: Use dba.normalize which applies DESeq2/edgeR normalization factors to the count matrix.
dba_obj <- dba.normalize(dba_obj)
dba.normalize(dba_obj, bRetrieve = TRUE)
Set Up Contrast
Goal: Define the comparison between experimental conditions for differential testing.
Approach: Specify a design formula or category-based contrast that tells DiffBind which groups to compare.
dba_obj <- dba.contrast(dba_obj, design = '~ Condition')
dba_obj <- dba.contrast(dba_obj, categories = DBA_CONDITION)
Run Differential Analysis
Goal: Identify peaks with statistically significant binding differences between conditions.
Approach: Apply DESeq2 or edgeR negative binomial models to the normalized count matrix.
dba_obj <- dba.analyze(dba_obj, method = DBA_DESEQ2)
dba_obj <- dba.analyze(dba_obj, method = DBA_EDGER)
View Results
Goal: Retrieve and inspect differentially bound regions with fold changes and significance values.
Approach: Extract results as a GRanges object with dba.report, sorted by significance.
dba.show(dba_obj, bContrasts = TRUE)
db_results <- dba.report(dba_obj)
db_results
Filter Results
Goal: Subset differential peaks by significance and fold-change thresholds.
Approach: Apply FDR and fold-change cutoffs to dba.report output.
db_sig <- dba.report(dba_obj, th = 0.05, fold = 2)
db_all <- dba.report(dba_obj, th = 1)
Export Results
results_df <- as.data.frame(dba.report(dba_obj, th = 1))
write.csv(results_df, 'differential_binding.csv', row.names = FALSE)
library(rtracklayer)
export(db_sig, 'diff_peaks.bed', format = 'BED')
Visualization
dba.plotPCA(dba_obj, DBA_CONDITION, label = DBA_ID)
dba.plotHeatmap(dba_obj)
dba.plotMA(dba_obj)
dba.plotVolcano(dba_obj)
dba.plotHeatmap(dba_obj, contrast = 1, correlations = FALSE)
Venn Diagram of Peaks
dba.plotVenn(dba_obj, dba_obj$masks$control)
dba.plotVenn(dba_obj, dba_obj$masks$treatment)
Profile Plots
profiles <- dba.plotProfile(dba_obj)
Get Consensus Peaks
consensus <- dba.peakset(dba_obj, bRetrieve = TRUE)
export(consensus, 'consensus_peaks.bed', format = 'BED')
Multi-Factor Design
dba_obj <- dba.contrast(dba_obj, design = '~ Batch + Condition')
dba_obj <- dba.analyze(dba_obj)
DiffBind 3.0 Notes
DiffBind 3.0+ introduced significant changes:
dba.normalize() is now required before analysis
- Default
summits=250 recenters peaks (was FALSE in older versions)
- Use design formulas instead of group1/group2 for contrasts
- Blacklist filtering is applied by default
Sample Sheet Columns
| Column | Required | Description |
|---|
| SampleID | Yes | Unique identifier |
| Tissue | No | Tissue/cell type |
| Factor | No | ChIP target |
| Condition | Yes | Experimental condition |
| Treatment | No | Additional grouping |
| Replicate | Yes | Replicate number |
| bamReads | Yes | Path to BAM file |
| Peaks | Yes | Path to peak file |
| PeakCaller | Yes | macs, bed, narrow |
| bamControl | No | Path to input BAM |
Key Functions
| Function | Purpose |
|---|
| dba | Create DBA object |
| dba.count | Count reads in peaks |
| dba.normalize | Normalize counts |
| dba.contrast | Set up comparison |
| dba.analyze | Run differential analysis |
| dba.report | Get results |
| dba.plotPCA | PCA visualization |
| dba.plotMA | MA plot |
| dba.plotHeatmap | Heatmap |
Related Skills
- peak-calling - Generate input peak files
- peak-annotation - Annotate differential peaks
- differential-expression - Compare with RNA-seq
- pathway-analysis - Functional enrichment