Low-level operationsΒΆ

We can use the BedTool.as_intervalfile() method to return an IntervalFile instance. This class provides low-level support to the BEDTools C++ API.

The method IntervalFile.all_hits() takes a single Interval as the query and returns a list of all features in the IntervalFile that intersect:

>>> a = pybedtools.example_bedtool('a.bed')
>>> ivf = a.as_intervalfile()
>>> query = a[2]
>>> ivf.all_hits(query)
[Interval(chr1:100-200), Interval(chr1:150-500)]

Similarly, we can just return if there were any hits, a much faster operation:

>>> ivf.any_hits(query)

Or count how many hits:

>>> ivf.count_hits(query)

See the docstrings for IntervalFile.all_hits(), IntervalFile.any_hits(), and IntervalFile.count_hits() for more, including stranded hits and restricting hits to a specific overlap.


These methods are now available as BedTool methods, BedTool.all_hits(), BedTool.any_hits(), and BedTool.count_hits()