RapidMACS is a C++ narrow peak caller. In the published paired-end benchmarks, it produced byte-identical peak and summit files and ran 3.5–51× faster than MACS3 v3.0.3, depending on the assay, input format, and thread count.
Those benchmarks used RapidMACS v1.0.1. MACS3 v3.1.0, released since, is multithreaded and much faster than v3.0.3. RapidMACS v1.1 streams coordinate-sorted input without sorting it or keeping an entry per fragment; measurements of it against MACS3 v3.1.0 will be published with the revised paper.
RapidMACS calls narrow peaks, with or without a matched input or IgG control,
from fragment, BAMPE, BEDPE, or single-end BED input. It ships both as a
standalone rapidmacs executable that replaces macs3 callpeak, and as a
static library with no Python or Cython runtime, so an aligner can call peaks
in-process on fragments it already holds.
Identical means literally identical: the same bytes, not the same peaks within a tolerance. Anything computed from a RapidMACS peak or summit file returns exactly what it would have returned from the MACS3 file, because it is handed the same file.
One difference from MACS3 is known, and it comes from a bug in MACS3. On fragment files with more than about 8.4 million fragments within 10 kb of one position, MACS3 v3.0.3 and v3.1.0 lose the local background for the rest of that chromosome, and RapidMACS does not. The v1.1.0 release notes describe it, and it is reported to the MACS3 project as issue 834.
RapidMACS implements one of MACS3's fourteen subcommands. It is not a replacement for MACS3.
- Implemented: narrow
callpeakon paired-end fragment, BAMPE, and BEDPE input, and on single-end BED with--nomodel; treatment-only or matched control;--nolambda;--call-summits. - Not implemented: broad peak calling, which is a separate algorithm with its own pair of cutoffs and region-linking pass; single-end fragment-size model building; every other subcommand.
BAMPE, BEDPE, and fragment tables give both ends of each fragment. A
single-end read identifies one fragment end. In model-based single-end
calling, MACS3 first estimates the fragment length. Applying that estimate
to earlier reads requires saving their positions or reading them again.
RapidMACS accepts single-end BED with a fixed extension length (--nomodel
and --extsize).
On coordinate-sorted BAMPE input, the v1.1 peak caller builds pileup and background counts as it reads the alignments. It stores runs of constant signal and reuses scores for recurring treatment and background values.
RapidMACS needs a C++11 compiler with OpenMP, htslib, and zlib.
# Debian / Ubuntu
sudo apt-get install build-essential libhts-dev zlib1g-dev
# macOS (Homebrew). Apple's clang has no OpenMP runtime, so libomp supplies it.
brew install libomp htslibgit submodule update --init --recursive # first time only
make # lib/librapidmacs.a + bin/rapidmacsOn macOS the Makefile finds libomp and htslib through brew --prefix. To
build with Homebrew GCC instead of Apple's clang, install gcc and run
make CXX=g++-15 with the version Homebrew installed. Without Homebrew, set
OPENMP_CXXFLAGS, OPENMP_LDFLAGS, and HTSLIB_PREFIX on the make command
line. The container below needs none of this and runs on Apple silicon.
The build links against system htslib by default. To build and link the pinned submodule copy instead:
(cd third_party/htslib && autoreconf -i && ./configure && make)
make HTSLIB_DIR=third_party/htslib-f FRAG accepts five-column Cell Ranger / Chromap barcoded fragments
(chrom,start,end,barcode,count) and seven-column Chromap bulk fragment BED
(chrom,start,end,N,mapq,strand,count), reading the duplicate count from
column 5 or 7 according to the detected schema. As in MACS3, FRAG duplicate
counts are already collapsed, so an explicit non-all --keep-dup warns and
is overridden to all.
# Single-cell or bulk ATAC from a fragments file, no control.
bin/rapidmacs --preset shiftTAG -f FRAG -t fragments.tsv.gz -g hs \
-n atac -p 1e-5 --bdgpeakcall-min-len 200 --bdgpeakcall-max-gap 30 \
--macs3-frag-narrowpeak out/atac.narrowPeak \
--macs3-frag-summits out/atac.summits.bed
# ChIP-seq: the chip preset requires a control.
bin/rapidmacs --preset chip -t ctcf.bam -c input.bam \
-n ctcf --out-prefix out/ctcf
# CUT&RUN: matched IgG is optional.
bin/rapidmacs --preset cutrun -t ctcf_cutrun.bam -c igg.bam \
-n ctcf_cutrun --out-prefix out/ctcf_cutrun
# Standard BEDPE (six mate columns).
bin/rapidmacs -f BEDPE -t fragments.bedpe -q 0.05 \
-n bedpe --out-prefix out/bedpe--peak-caller-threads N processes chromosomes concurrently. Presets are
applied first and then overridden by any explicit flag, so place --preset
before per-flag overrides.
For streaming peak calls, --peak-score-mode auto counts each distinct
normalized (treatment, background) pair across the genome. It selects the
capped memo when the count fits the 4,193,280-key budget and every partition
fits one worker’s share. The worker sizes its khash from the partition’s exact
count. Larger inputs use checkpoint tasks within chromosomes. Both modes
compute each distinct score pair once. To override the choice, pass
--peak-score-mode pairs or --peak-score-mode capped-memo. The call reports
the count, selected mode and budget on stderr.
As a library, the entry point is
RunMacs3FragPeakPipelineFromSortedIterator, which pulls fragments one at a
time through the FragmentIterator interface in
include/rapidmacs/fragments.h, so they can come
from a file or straight out of an array the host already holds.
Every narrowPeak and summit field matches MACS3 v3.0.3 — intervals, peak names, summit offsets and coordinates, signal values, p-scores and q-scores — and the full-file MD5 sums agree. This holds across single-cell ATAC-seq, bulk ATAC-seq, ChIP-seq, and CUT&RUN, on fragment and BAMPE input, with and without a control.
Summit BED scores follow MACS3's selected score column: p-score for -p,
q-score for -q.
Two low-level details had to be matched exactly and are worth knowing about.
The summit tie-break. MACS3's internal pos_array, the array iterated to
find the median-tied summit, is per-event rather than per-distinct-value. When
a fragment endpoint lands inside a plateau without changing the running pileup
— one fragment ending where another starts, net Δ of zero — MACS3 still emits
an entry. The bedGraph writer collapses those adjacent same-value runs, so an
exported .bdg agrees either way, but the median is taken over more
sub-pieces than a collapsed track exposes.
src/macs3_pos_array.cc reproduces this directly and
is on by default. --no-macs3-frag-summit-parity takes a lower-memory
shortcut that diverges on roughly 2% of summits (max ~222 bp at PBMC scale);
BED3, bedGraph, and score columns are unaffected.
Score-table arithmetic. The callpeak path retains MACS3's float32 lambda for Poisson scoring and uses its float32 p/q-table arithmetic. Five-decimal rounding is confined to diagnostic bedGraph output.
A public dataset, the exact command to run it on, and the output you should get. This is the quickest end-to-end check that a build works.
Test data. The 10x Genomics Cell Ranger ARC PBMC 3k ATAC fragments,
53,015,732 rows, 537,308,082 bytes,
SHA-256 0189df1de4894f10f48ffb905da4966cefc2466dc5fdd76ee2905244dd5a8dd7:
curl -fLO https://cf.10xgenomics.com/samples/cell-arc/2.0.0/pbmc_unsorted_3k/pbmc_unsorted_3k_atac_fragments.tsv.gzInput. A fragments TSV, plain or gzipped, exactly as Cell Ranger ARC and
Chromap write it: chrom, start, end, barcode, count. The seven-column
Chromap bulk form is also accepted; the schema is detected automatically.
Run.
make -j
bin/rapidmacs --preset shiftTAG -f FRAG \
-t pbmc_unsorted_3k_atac_fragments.tsv.gz \
-g hs -n atac -p 1e-5 \
--bdgpeakcall-min-len 200 --bdgpeakcall-max-gap 30 \
--peak-caller-threads 8 \
--macs3-frag-narrowpeak atac.narrowPeak \
--macs3-frag-summits atac.summits.bedOutput. Two files. atac.narrowPeak is ENCODE narrowPeak: chromosome,
start, end, peak name, score, strand, signal, p-score, q-score, summit offset.
atac.summits.bed is BED5, one row per summit. Expect 50,003 peaks and
these exact checksums, which are also what MACS3 v3.0.3 produces from the same
input:
$ wc -l < atac.narrowPeak
50003
$ md5sum atac.narrowPeak atac.summits.bed
2c0de7c506514b0afef1e4339c386c9f atac.narrowPeak
c3805d1d3744ed78e3d589a523ad0b09 atac.summits.bed
Runtime is about 20 s at 8 threads on the reference host. If the checksums differ, please open an issue rather than working around it.
More worked examples, including ChIP-seq with a control and calling peaks from your own C++ program, are in docs/walkthroughs.md.
docker build -t rapidmacs .
docker run --rm -v "$PWD:/data" rapidmacs \
--preset shiftTAG -f FRAG -t /data/fragments.tsv.gz -g hs -n atac \
-p 1e-5 --bdgpeakcall-min-len 200 --bdgpeakcall-max-gap 30 \
--macs3-frag-narrowpeak /data/atac.narrowPeak \
--macs3-frag-summits /data/atac.summits.bedThe default image is about 89 MB and contains only the binary and its runtime
libraries; rapidmacs is the entrypoint, so arguments pass straight through.
It links Debian's htslib rather than the pinned submodule, which affects BAM
reading only and not peak output.
Prebuilt multi-arch images (amd64 and arm64) are on Docker Hub as
biodepot/rapidmacs, so nothing has to be built:
docker run --rm -v "$PWD:/data" biodepot/rapidmacs \
--preset shiftTAG -f FRAG -t /data/fragments.tsv.gz -g hs -n atac \
-p 1e-5 --bdgpeakcall-min-len 200 --bdgpeakcall-max-gap 30 \
--macs3-frag-narrowpeak /data/atac.narrowPeak \
--macs3-frag-summits /data/atac.summits.bedEach tagged release also carries per-architecture tarballs of the binary, static library, and headers on its GitHub release page.
--target reproduce builds a larger image that also carries released MACS3
v3.0.3 and the paper/ scripts, so the published comparison can be run inside
the container:
docker build -t rapidmacs:reproduce --target reproduce .
docker run --rm -it -v "$PWD:/data" rapidmacs:reproduce
# $MACS3 and $RAPIDMACS are set; paper/scripts is on diskpaper/scripts/run_10x_pbmc_example.sh reproduces the single-cell ATAC row of
Table 1 from a public dataset. It downloads the 10x Cell Ranger ARC PBMC 3k
ATAC fragments, verifies the file against the SHA-256 the paper used, calls
peaks with released MACS3 3.0.3 and with RapidMACS at 1, 4, and 24 threads, and
exits non-zero unless every output file carries the published narrowPeak and
summits MD5 sums:
make -j
paper/scripts/setup_macs3_reference.sh VARIANT=released
MACS3=.macs3-reference/macs3-3.0.3-venv/bin/macs3 \
paper/scripts/run_10x_pbmc_example.shExpect roughly 25 minutes, nearly all of it the one MACS3 run. On the reference
host this configuration is 747.55 s for MACS3 against 58.93, 24.44, and 16.35 s
for RapidMACS v1.0.1, all four producing 50,003 identical peaks. SKIP_MACS3=1 times
RapidMACS alone against the published checksums; WARMUPS=1 REPEATS=3
reproduces the paper's protocol rather than the single timed run the example
defaults to.
paper/README.md covers the complete six-configuration matrix and both MACS3 reference builds. paper/results/ holds every recorded measurement: medians, all three repetitions with per-run output checksums, stage profiles, and the SHA-256 of each MACS3 executable and input.
The three tools that most often re-call peaks on data a pipeline has already
produced were checked against their exact command lines: Signac, ArchR (BED,
--nolambda --call-summits), and SCENIC+/pycisTopic (BEDPE, likewise). All
three default to macs2 and can be pointed at macs3; against the MACS3
v3.0.3 commands, RapidMACS reproduces the narrowPeak and summit files byte for
byte — 12,923 and 9,181 rows respectively on the full PBMC 100K workflow input.
Commands and checksums are in
paper/WORKFLOW-COMPATIBILITY.md.
The BED compatibility path also covers chromosome strands containing a single
tag under duplicate removal, and writes the summit score selected by
--pvalue or --qvalue. Small original-MACS3 3.0.3 goldens exercise both modes
with --keep-dup 1, 2, and all; see CHANGELOG.md for the
v1.0.1 corrections.
FRAG count caps (--frag-pileup-max-count N, equivalent to MACS3
--max-count N) apply to pileups, background totals, and summit placement.
Regression goldens cover caps 1, 2, and 5 as well as uncapped input.
Because the files are identical, the substitution can be made part-way through an established analysis without putting earlier comparisons in question.
make test # unit + ATAC + ChIP-seq + CUT&RUN smokes
make test-unit # C++ unit tests
make test-singleton-parity # BED singleton strands, P/q modes and keep-dup
make test-frag-max-count # FRAG caps 1/2/5 and uncapped original-MACS3 goldens
make test-macs3-frag-100k # FRAG golden
make test-chipseq # public ENCODE BAMPE treatment/input fixture
make test-cutrun # public GEO BAMPE CTCF/IgG fixtureTests that need a fragments file take one from $DATA_DIR (default ./data)
or from an explicit override:
FIXTURE_FRAGS=/path/to/fragments.tsv.gz make test-macs3-frag-100k-
CHANGELOG.md — version history and correctness fixes.
-
docs/RELEASE_NOTES_v1.1.1.md — macOS build, container instructions, and how RapidMACS relates to MACS3.
-
docs/RELEASE_NOTES_v1.1.0.md — streaming of coordinate-sorted input, the library changes, and a known difference from MACS3 on very deep fragment files.
-
docs/RELEASE_NOTES_v1.0.2.md — singleton BED strands, P-mode summit scores, and capped FRAG counts.
-
docs/RELEASE_NOTES_v1.0.1.md — correctness fixes in the v1.0.1 patch release.
-
docs/walkthroughs.md — five worked examples, from a first run to embedding the library.
-
docs/cli.md — complete
rapidmacscommand-line reference. -
docs/api.md — library API: the fragment interface, the parameter struct, and the four entry points.
-
docs/methodology.md — implemented algorithms, parity criteria, and the benchmark protocol.
-
paper/ — everything behind the published results: reproduction scripts, both MACS3 reference builds, and the recorded measurements.
-
NOTICE — third-party attributions.
include/rapidmacs/ public headers
src/ library implementation
cli/ standalone CLI
tests/ unit tests and parity smokes
docs/ CLI reference, API reference, walkthroughs, methodology
paper/
scripts/ every script behind a published number
results/ every recorded measurement
Dockerfile slim runtime image; --target reproduce adds MACS3 3.0.3
RapidMACS is an independent implementation of narrow peak calling as
macs3 callpeak performs it. It contains no MACS3 code, in original or
translated form.
How it was developed. We designed RapidMACS from MACS3's published descriptions of the algorithm and checked every stage by comparing peak and summit files byte for byte with MACS3 v3.0.3. We chose that route for engineering reasons: a design planned on its own terms is not shaped by the structure of the existing code, and we can maintain it because we planned it. It was not a legal precaution. MACS3 is released under the BSD 3-Clause license, which permits reading, using and modifying its source.
Where we consulted MACS3's source. Byte-identical output depends on details that the published descriptions and the output files do not settle. For those we read, and in places instrumented, MACS3 v3.0.3. They include how it breaks ties between summit positions and the 32-bit arithmetic of its score tables. For v1.1 we also read MACS3 v3.1.0 for two details: the arithmetic by which it scales a matched control, and how it divides a peak into pieces before taking the summit from the middle one.
Wherever a part of RapidMACS reproduces the behaviour of a particular MACS3 routine, a comment in our source names that routine. These are the routines named:
| MACS3 module | Named in RapidMACS comments | RapidMACS files |
|---|---|---|
Signal/CallPeakUnit |
CallerFromAlignments, __cal_pvalue_qvalue_table, __chrom_pair_treat_ctrl, __close_peak_with_subpeaks, __close_peak_wo_subpeaks, apply_multiple_cutoffs, get_pscore |
include/rapidmacs/bdgpeakcall.h, include/rapidmacs/macs3_frag_workspace.h, include/rapidmacs/macs3_pos_array.h, include/rapidmacs/peak_io.h, src/bam_stream_peaks.cc, src/bdgpeakcall.cc, src/macs3_frag_sweep.cc, src/macs3_frag_workspace.cc, src/peak_io.cc |
Signal/PeakDetect |
__call_peaks_wo_control, the control-scaling arithmetic of PeakDetect |
include/rapidmacs/peak_io.h, src/macs3_control_scales.h, src/macs3_frag_workspace.cc |
Signal/PairedEndTrack |
PETrackI.finalize, pileup_a_chromosome, pileup_a_chromosome_c, PETrackII, filter_dup |
include/rapidmacs/peak_io.h, src/macs3_bed_callpeak.cc, src/macs3_frag_sweep.cc, src/macs3_frag_workspace.cc, src/peak_io.cc |
Signal/Pileup, Signal/PileupV2 |
quick_pileup, se_all_in_one_pileup, over_two_pv_array, pileup_PV |
include/rapidmacs/macs3_pos_array.h, src/macs3_frag_workspace.cc, src/macs3_pos_array.cc, src/peak_io.cc |
Signal/BedGraph |
bedGraphTrackI.call_peaks, bedGraphTrackI.add_loc, make_ScoreTrackII_for_macs |
include/rapidmacs/bdgpeakcall.h, include/rapidmacs/peak_io.h, src/bdgpeakcall.cc, src/peak_io.cc |
IO/PeakIO |
filter_fc |
include/rapidmacs/macs3_frag_peak_pipeline.h |
IO/Parser |
bampe_pe_binary_parse, BAMPEParser, BEDPEParser |
cli/rapidmacs.cc, src/fragment_input.cc |
RapidMACS is distributed under the MIT license — see LICENSE.
How RapidMACS relates to MACS3, and where we consulted MACS3's source, is set out in Relationship to MACS3 above.
MACS was originally developed in X. Shirley Liu's group and has been maintained and extended since by Tao Liu and the MACS3 contributors. This project would not have been possible without that work, or without its release under a permissive open-source license: being able to read and run the reference implementation is what made byte-level parity achievable.