CLI tool
arq5x/bedtools2 avatar
arq5x/bedtools2

bedtools2: set arithmetic for genomic interval files

bedtools - the swiss army knife for genome arithmetic

1,055 stars304 forksCMIT

At a glance

What is it?
bedtools2 is a C suite of small commands that intersect, merge, count and complement genomic intervals in BAM, BED, GFF/GTF and VCF. It scales well on sorted input, and the README admits that the unsorted R-Tree path could not complete on 100 million alignments.
Who is it for?
bedtools2 suits people who already work in interval files and want one task per command rather than a framework, and it suits pipelines where sorted BED input is the normal case. It is the wrong tool for unsorted data at scale, where the R-Tree path is documented as unable to finish on 100 million alignments, and for anyone who wants a single command that answers a complex overlap question without composing several steps.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 135 days ago.
What is it written in?
Mainly C, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

Genome arithmetic across BAM, BED, GFF and VCF

bedtools2 is a set of C programs for set operations on genomic intervals. The README frames each command as deliberately narrow: intersect two interval files, merge them, count them, complement them, shuffle them. What makes the suite practical is that the same operations read and write BAM, BED, GFF/GTF and VCF, so a coordinate file produced by one step can be handed to the next without conversion. The people who benefit are those who already have alignment and annotation files and need an answer about overlap: how many reads fall inside a set of exons, which regions are covered by at least one feature, what the complement of an annotation looks like. The intended usage model is composition on a UNIX command line, and the documentation states that quite sophisticated analyses come from combining several operations that each do a simple job.

Sorted input decides which algorithm runs

Performance here is not one number, it depends on whether the input is sorted. The documentation states that as of version 2.18 the suite is substantially more scalable because of changes to the algorithm used for datasets pre-sorted by chromosome and start position. Speed and memory scale well on sorted data and poorly on unsorted data, where an R-Tree is used instead. The README also notes that the current version of bedtools intersect is as fast as, or slightly faster than, the bedmap command from the bedops package, which relies on a similar algorithm for sorted data. That comparison is only meaningful because the README explains the bedmap --ec option was used for it, since bedtools enforces similar error checking. Two practical consequences follow. Sort your intervals before running, and expect a different cost profile if you skip that step.

Getting bedtools2 onto your machine

The README names two places to get the software, both of them web pages rather than package recipes.

bash
https://github.com/arq5x/bedtools2/releases/latest

There is no package-manager entry, container image or install script named in the README, so anyone shipping bedtools2 inside their own environment has to make those choices without guidance. For a source build, the root Makefile declares the compiler, the flags and the libraries, and it keeps objects and binaries in separate directories.

makefile
CXX     = g++

BT_CPPFLAGS = -DDEBUG -D_DEBUG -D_FILE_OFFSET_BITS=64 -DWITH_HTS_CB_API $(INCLUDES)
BT_CXXFLAGS = -g -Wall -O2
BT_LIBS    = -lz -lm -lbz2 -llzma -lpthread

prefix ?= /usr/local

Those lines show a g++ toolchain, a separate debug flag set, a release set with optimisation enabled, and links against zlib, bzip2, lzma and pthreads, with /usr/local as the default prefix. Per-command flag documentation lives at bedtools.readthedocs.org, and a first real use means picking a subcommand and reading its options there.

One source directory per subcommand

The top-level entries give the shape of the project: .github/, .gitignore, LICENSE, Makefile, README.md, data/, docs/, genomes/, scripts/, src/, test/, tutorial/. Under src/ sits one directory per command, and the Makefile enumerates them as build subdirectories.

makefile
$(SRC_DIR)/intersectFile
$(SRC_DIR)/mergeFile
$(SRC_DIR)/complementFile

The wider list covers conversion at both ends of the pipeline, from bamToBed and bamToFastq through bedToBam and bedpeToBam, then interval logic such as clusterBed, complementFile, coverageFile, flankBed, mergeFile, multiIntersectBed, and sequence work in fastaFromBed and maskFastaFromBed. There are also statistical commands, fisher and jaccard, and grouping utilities such as groupBy and getOverlap. The practical consequence for a new user is that the command name usually matches a directory name, so tracing a flag back to source does not require much guessing.

The unsorted path has a completion ceiling

The clearest failure mode is written into the README itself: bedtools could not complete when using 100 million alignments and the R-Tree algorithm used for unsorted data. That is a completion failure, not a slowdown, and it means the unsorted branch has a scale limit the sorted branch does not share. The second limitation is structural. Each tool is designed to do a relatively simple task, so answering how many reads fall within exons takes a sequence of invocations rather than one, and every step has to agree on sort order and file format. The third is thin onboarding: the README offers no worked command line with real inputs and no sample data walkthrough, so a first run is an exercise in reading the online manual. Test data does exist in the repository under data/ and test/, but the README does not walk through either.

bedmap and pybedtools approach the same problem differently

The comparison the README itself makes is with bedmap from the bedops package, which uses a similar algorithm for sorted data and enforces its own error checking through the --ec option. The difference in approach is scope: bedtools covers the whole path from BAM conversion through interval logic to sequence extraction inside one release with one Makefile. For Python work, the README points to pybedtools as a library for manipulating genomic datasets and annotations, with its own citation. Choosing between the two is a question of where your script boundary sits. The command line keeps each step inspectable and pipeable, and the library keeps state inside one process instead of writing intermediate files.

Commits continue past the newest tag, and the licence is MIT

The repository is not archived, and the last push was on 2026-06-10. The tagged releases tell a different story: v2.30.0 appeared on 2021-01-23, v2.31.0 on 2023-04-28 and v2.31.1 on 2023-11-07. Commits have landed well after the newest tag, so a build from the default branch is not the same artifact as the latest release, and the README points at the releases page for the current version. The project is released under the MIT licence, with the LICENSE file at the repository root, which is the permissive option with no copyleft condition attached to downstream use. The README also asks that research work cite the 2010 Bioinformatics paper by Quinlan and Hall, and the pybedtools paper if that library is used.

Editorial conclusion

bedtools2 suits people who already work in interval files and want one task per command rather than a framework, and it suits pipelines where sorted BED input is the normal case. It is the wrong tool for unsorted data at scale, where the R-Tree path is documented as unable to finish on 100 million alignments, and for anyone who wants a single command that answers a complex overlap question without composing several steps. Before adopting it, check two things: whether the tagged release you would pin is v2.31.1 from 2023-11-07 while the last push was on 2026-06-10, and whether your inputs are sorted by chromosome and start position, because that decision picks the algorithm and the cost profile you get.

Frequently asked questions

How do I install bedtools2?

The README names no package-manager recipe and no container image, it points at the downloadable release page. For a source build it ships a root Makefile that compiles with g++ and links zlib, bzip2, lzma and pthreads, installing under /usr/local by default.

Why is bedtools intersect slow on my BED file?

The documentation states that speed and memory scale well only for data pre-sorted by chromosome and start position, while unsorted data goes through an R-Tree. The README notes that bedtools could not complete on 100 million alignments using that unsorted algorithm.

How does bedtools intersect compare with bedmap?

The README states that bedtools intersect is as fast as or slightly faster than bedmap from the bedops package, which uses a similar algorithm for sorted data. The comparison used the bedmap --ec option because bedtools enforces similar error checking.

Is bedtools2 still maintained and what licence does it use?

The repository is not archived and the last push was on 2026-06-10, though the newest tagged release, v2.31.1, dates from 2023-11-07. It is released under the MIT licence, with the LICENSE file in the repository root.

Official sources

  1. arq5x/bedtools2 on GitHub
  2. Issues
  3. License: MIT
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/arq5x-bedtools2.svg)](https://hysenlabs.com/projects/arq5x-bedtools2)

Was this useful?