Category

Genomic Interval Manipulation


Usage

bedtools overlap -i <in.bed|stdin> -cols <str>


Manual

This tool is part of the bedtools suite, and it's also known as getOverlap.

The overlap tool from bedtools computes the amount of overlap (in the case of positive values) or distance (in the case of negative values) between feature coordinates occurring on the same input line and reports the result at the end of the same line.

Required arguments

  • -i str: Input file. Use stdin for pipes.

  • -cols str: Specify the columns (1-based) for the starts and ends of the features for which you'd like to compute the overlap/distance. The columns must be listed in the following order: start1,end1,start2,end2.

Examples

Assume you have two sets of genomic features and you want to calculate how many base pairs they overlap or how far they are away from each other. In this case, you can use getOverlap to get the numbers.

The input file looks like:

$ head input.bed
chr1  10  20  A  chr1  15  25  B
chr1  10  20  C  chr1  25  35  D

Now let's do the calculation:

$ bedtools overlap -i input.bed -cols 2,3,6,7
chr1  10  20  A  chr1  15  25  B  5   # overlap between A and B
chr1  10  20  C  chr1  25  35  D  -5  # distance between C and D

# you will get the same results if you run getOverlap

$ getOverlap -i input.bed -cols 2,3,6,7
chr1 10 20 A chr1 15 25 B 5
chr1 10 20 C chr1 25 35 D -5

File formats this tool works with
BED

Share your experience or ask a question