$npx -y skills add GPTomics/bioSkills --skill consensus-peaksetBuild a differential-ready consensus peakset from per-replicate ATAC-seq peaks using iterative overlap removal, fixed-width re-centering, and majority-rule overlap. Use when generating a stable peak coordinate system for downstream differential accessibility, ML feature engineeri
| 1 | ## Version Compatibility |
| 2 | |
| 3 | Reference examples tested with: bedtools 2.31+, samtools 1.19+, BEDOPS 2.4.41+, GenomicRanges 1.54+, DiffBind 3.12+, Subread 2.0.2+ (featureCounts; `--countReadPairs` requires >= 2.0.2), pybedtools 0.10+. |
| 4 | |
| 5 | Before using code patterns, verify installed versions match. If versions differ: |
| 6 | - Python: `pip show <package>` then `help(module.function)` to check signatures |
| 7 | - R: `packageVersion('<pkg>')` then `?function_name` to verify parameters |
| 8 | - CLI: `<tool> --version` then `<tool> --help` to confirm flags |
| 9 | |
| 10 | If code throws unexpected errors, introspect the installed package and adapt rather than retrying. |
| 11 | |
| 12 | # Consensus Peakset Construction |
| 13 | |
| 14 | **"Build a single peakset to count reads against for all my samples"** -> Combine per-replicate or per-condition peak calls into a non-redundant, fixed-width set of regions. The strategy chosen drives FDR calibration, peak-width fairness, and reproducibility downstream. |
| 15 | |
| 16 | - CLI: `bedtools merge` (simple union) and `bedtools multiinter` (per-sample membership columns emitted by default) |
| 17 | - CLI: Corces 2018 iterative overlap removal (custom shell) |
| 18 | - R: `DiffBind::dba.count(summits=250)` (built-in fixed-width) |
| 19 | - Python: `pybedtools` for programmatic merging |
| 20 | |
| 21 | The peakset choice is rarely default-correct. Wrong width or wrong overlap rule propagates to every downstream analysis (differential, motif, footprint, ML). |
| 22 | |
| 23 | ## Why a Consensus Peakset Matters |
| 24 | |
| 25 | ATAC peaks vary in width across replicates: same regulatory element might be called 200 bp in rep1 and 800 bp in rep2 because of stochastic Tn5 cuts at edges. Counting reads in different-width intervals confounds peak width with biological signal. A fixed-width consensus avoids this. |
| 26 | |
| 27 | For ENCODE-style differential analysis: ALL samples must be counted against the SAME peak coordinates; otherwise the count matrix is non-rectangular and statistical models are misspecified. |
| 28 | |
| 29 | ## Strategy Taxonomy |
| 30 | |
| 31 | | Strategy | Implementation | Width | When to use | Fails when | |
| 32 | |----------|---------------|-------|-------------|------------| |
| 33 | | Naive union | `bedtools merge` of all peaks | Variable, tends wide | Quick exploratory; never for differential | Width inflation drives spurious differential | |
| 34 | | Naive intersection | `bedtools multiinter` requiring all samples | Variable | High-stringency reproducibility | Loses real condition-specific peaks | |
| 35 | | Majority-rule overlap | `multiinter` requiring >= n/2 samples | Variable | Balance; DiffBind default with `minOverlap` | Width still varies; counts are width-biased | |
| 36 | | Iterative overlap removal (Corces 2018) | Sort by significance, greedily keep non-overlapping at fixed width | 501 bp fixed | ML features; cross-study comparison; modern ATAC standard | Loses sub-501bp resolution; overweights high-significance peaks | |
| 37 | | Summit-centered fixed width (DiffBind) | `dba.count(summits=250)` re-centers all peaks on summit +/- 250 bp | 501 bp fixed | Matches the Corces 501 bp convention (note: `dba.count` default is `summits=200` -> 401 bp); integrates with replicate counts | Requires summit info (MACS narrowPeak); broad peaks lose width info | |
| 38 | | IDR-filtered union | Union of IDR-passed peaks across rep pairs | Variable | ENCODE pipeline-compliant; reproducibility-aware | Requires running IDR per pair; computationally heavier | |
| 39 | | Per-condition union, then global union | Each group consensus separately, then merge | Variable | Different cell types / strong condition shift | Same width issues as naive union | |
| 40 | | Width-controlled extension | Extend each peak to median width centered on midpoint | User-set | Quick fixed-width without summit info | Midpoint != summit; can shift biology | |
| 41 | |
| 42 | Methodology evolves; verify against current ENCODE 4 ATAC standards (encodeproject.org/atac-seq) and the Corces 2018 iterative overlap algorithm before locking pipelines. |
| 43 | |
| 44 | ## Iterative Overlap Removal (Corces 2018) |
| 45 | |
| 46 | This is the modern standard for fixed-width consensus peaksets used in cross-study comparison and machine-learning feature matrices. |
| 47 | |
| 48 | **Algorithm:** |
| 49 | 1. Pool all peaks from all samples; re-center each on its summit; extend +/- 250 bp -> 501 bp fixed-width peaks. |
| 50 | 2. Sort by significance (narrowPeak column 7, signalValue, descending). |
| 51 | 3. Walk down the sorted list. Keep each peak if it does not overlap any previously kept peak. Drop if overlap. |
| 52 | 4. Output the kept peaks as the consensus. |
| 53 | |
| 54 | **Goal:** Produce a non-overlapping, fixed-width peakset weighted toward strongest evidence. |