closest-bed
Quick Start
- Command:
closestBed -a <A> -b <B> [options] - Local executable:
/home/vimalinx/miniforge3/envs/bio/bin/closestBed - Full reference: See
references/help.md
When To Use This Tool
- Find the nearest genomic feature in B for every feature in A.
- Report unsigned distance with
-dor signed upstream/downstream distance with-D. - Ignore overlaps and search only for nearby non-touching features with
-io. - Limit to same-strand or opposite-strand neighbors with
-s/-S. - Resolve ties or return multiple nearest hits with
-t,-k, and-mdb.
Common Patterns
# 1) Find the nearest gene for each peak with distance
closestBed \
-a peaks.bed \
-b genes.bed \
-d
# 2) Report upstream/downstream signed distance relative to A strand
closestBed \
-a peaks.bed \
-b genes.bed \
-D a \
-io
# 3) Keep the two closest same-strand hits and break ties by file order
closestBed \
-a exons.bed \
-b transcripts.bed \
-s \
-k 2 \
-t first
Recommended Workflow
- Decide whether overlapping features should count as closest; if not, add
-io. - Choose
-dfor absolute distance or-D ref|a|bif signed orientation matters biologically. - Apply
-s/-S,-iu/-id, or-fu/-fdonly after you are sure the strand and orientation model is the one you want. - Inspect cases with
none/-1output because they mean no candidate in B exists on the same chromosome.
Guardrails
-iu,-id,-fu, and-fdrequire-Dand inherit its upstream/downstream orientation rules.- Ties are reported by default; if you need one record only, set
-t firstor-t last. - With multiple B files,
-mdb eachand-mdb allproduce meaningfully different semantics. - Chromosome naming mismatches can make valid neighbors disappear silently into
none/-1results. - Prefer
-hfor help; some--help/--versioninvocations on these wrappers produce extra errors.