bedtools
Quick Start
- Command:
bedtools <subcommand> [options] - Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/bedtools - Version: 2.31.1
- Full reference: See
references/help.mdfor complete subcommand list and options
When To Use This Tool
- Perform interval arithmetic on BED/BAM/BEDGRAPH/GFF-like genomic coordinates.
- This is the default tool for overlap, merge, coverage, complement, and FASTA extraction tasks.
- Use it whenever the job is fundamentally about genomic intervals rather than alignments or variants.
- Choose the subcommand first;
bedtoolsis a toolbox, not one operation.
Common Patterns
# 1) Intersect peaks with genes
bedtools intersect -a peaks.bed -b genes.bed > peaks_in_genes.bed
# 2) Merge overlapping intervals
bedtools merge -i intervals.sorted.bed > intervals.merged.bed
# 3) Compute coverage of intervals by alignments
bedtools coverage -a targets.bed -b sample.sorted.bam > targets.coverage.tsv
# 4) Extract sequences from a reference FASTA
bedtools getfasta -fi genome.fa -bed regions.bed -fo regions.fa
Recommended Workflow
- Make sure coordinate systems, chromosome names, and genome assembly all match.
- Sort interval inputs whenever the subcommand expects sorted data.
- Pick the specific subcommand that matches the biological question.
- Validate output shape and coordinate sanity before chaining into another tool.
Guardrails
- BEDTools assumes interval semantics are correct; mixed assemblies or
chrnaming mismatches will silently distort results. - Many operations behave best or only correctly with sorted input.
- Some interval-manipulation subcommands need a genome file for chromosome lengths.
- Always check subcommand-specific help, because required flags differ substantially across subcommands.