File: topical-low-level-ops.rst

package info (click to toggle)
python-pybedtools 0.10.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,620 kB
  • sloc: python: 10,030; cpp: 899; makefile: 142; sh: 57
file content (48 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
.. include:: includeme.rst

Low-level operations
--------------------

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

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

.. doctest::
    :options: +NORMALIZE_WHITESPACE

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

.. doctest:: 
    :options: +NORMALIZE_WHITESPACE

    >>> ivf.any_hits(query)
    1

Or count how many hits:

.. doctest:: 
    :options: +NORMALIZE_WHITESPACE

    >>> ivf.count_hits(query)
    2

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

.. note::

    These methods are now available as :class:`BedTool` methods,
    :meth:`BedTool.all_hits`, :meth:`BedTool.any_hits`, and
    :meth:`BedTool.count_hits`