pybedtools.bedtool.BedTool.overlap

BedTool.overlap(*args, **kwargs)[source]

Wraps bedtools overlap.

Example usage:

>>> a = pybedtools.example_bedtool('a.bed')
>>> b = pybedtools.example_bedtool('b.bed')
>>> c = a.window(b, w=10).overlap(cols=[2,3,8,9])
>>> print(c) 
chr1    100     200     feature2        0       +       chr1    155     200     feature5        0       -       45
chr1    150     500     feature3        0       -       chr1    155     200     feature5        0       -       45
chr1    900     950     feature4        0       +       chr1    800     901     feature6        0       +       1

For convenience, the file or stream this BedTool points to is implicitly passed as the -i argument to getOverlap

Original BEDTools help::

Tool:    bedtools overlap (aka getOverlap)
Version: v2.31.1
Summary: Computes the amount of overlap (positive values)
         or distance (negative values) between genome features
         and reports the result at the end of the same line.

Options: 
        -i      Input file. Use "stdin" for pipes.

        -cols   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

Example: 
        $ bedtools window -a A.bed -b B.bed -w 10
        chr1 10  20  A   chr1    15  25  B
        chr1 10  20  C   chr1    25  35  D

        $ bedtools window -a A.bed -b B.bed -w 10 | bedtools overlap -i stdin -cols 2,3,6,7
        chr1 10  20  A   chr1    15  25  B   5
        chr1 10  20  C   chr1    25  35  D   -5