| 1 |
.. _cluster: |
| 2 |
|
| 3 |
############### |
| 4 |
*cluster* |
| 5 |
############### |
| 6 |
|
| 7 |
| |
| 8 |
|
| 9 |
.. image:: ../images/tool-glyphs/cluster-glyph.png |
| 10 |
:width: 600pt |
| 11 |
| |
| 12 |
|
| 13 |
|
| 14 |
Similar to :doc:`../tools/merge`, ``cluster`` report each set of overlapping or |
| 15 |
"book-ended" features in an interval file. In contrast to ``merge``, |
| 16 |
``cluster`` does not flatten the cluster of intervals into a new meta-interval; |
| 17 |
instead, it assigns an unique cluster ID to each record in each cluster. This |
| 18 |
is useful for having fine control over how sets of overlapping intervals in |
| 19 |
a single interval file are combined. |
| 20 |
|
| 21 |
.. note:: |
| 22 |
|
| 23 |
``bedtools cluster`` requires that you presort your data by chromosome and |
| 24 |
then by start position (e.g., ``sort -k1,1 -k2,2n in.bed > in.sorted.bed`` |
| 25 |
for BED files). |
| 26 |
|
| 27 |
.. seealso:: |
| 28 |
|
| 29 |
:doc:`../tools/merge` |
| 30 |
|
| 31 |
|
| 32 |
========================================================================== |
| 33 |
Usage and option summary |
| 34 |
========================================================================== |
| 35 |
**Usage**: |
| 36 |
:: |
| 37 |
|
| 38 |
bedtools cluster [OPTIONS] -i <BED/GFF/VCF> |
| 39 |
|
| 40 |
**(or)**: |
| 41 |
:: |
| 42 |
|
| 43 |
clusterBed [OPTIONS] -i <BED/GFF/VCF> |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
=========================== =============================================================================================================================================================================================================== |
| 48 |
Option Description |
| 49 |
=========================== =============================================================================================================================================================================================================== |
| 50 |
**-s** Force strandedness. That is, only cluster features that are the same strand. *By default, this is disabled*. |
| 51 |
**-d** Maximum distance between features allowed for features to be clustered. *Default is 0. That is, overlapping and/or book-ended features are clustered*. |
| 52 |
=========================== =============================================================================================================================================================================================================== |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
========================================================================== |
| 59 |
Default behavior |
| 60 |
========================================================================== |
| 61 |
By default, ``bedtools cluster`` collects overlapping (by at least 1 bp) and/or |
| 62 |
bookended intervals into distinct clusters. In the example below, the 4th |
| 63 |
column is the cluster ID. |
| 64 |
|
| 65 |
.. code-block:: bash |
| 66 |
|
| 67 |
$ cat A.bed |
| 68 |
chr1 100 200 |
| 69 |
chr1 180 250 |
| 70 |
chr1 250 500 |
| 71 |
chr1 501 1000 |
| 72 |
|
| 73 |
$ bedtools cluster -i A.bed |
| 74 |
chr1 100 200 1 |
| 75 |
chr1 180 250 1 |
| 76 |
chr1 250 500 1 |
| 77 |
chr1 501 1000 2 |
| 78 |
|
| 79 |
|
| 80 |
========================================================================== |
| 81 |
``-s`` Enforcing "strandedness" |
| 82 |
========================================================================== |
| 83 |
The ``-s`` option will only cluster intervals that are overlapping/bookended |
| 84 |
*and* are on the same strand. |
| 85 |
|
| 86 |
.. code-block:: bash |
| 87 |
|
| 88 |
$ cat A.bed |
| 89 |
chr1 100 200 a1 1 + |
| 90 |
chr1 180 250 a2 2 + |
| 91 |
chr1 250 500 a3 3 - |
| 92 |
chr1 501 1000 a4 4 + |
| 93 |
|
| 94 |
$ bedtools cluster -i A.bed -s |
| 95 |
chr1 100 200 a1 1 + 1 |
| 96 |
chr1 180 250 a2 2 + 1 |
| 97 |
chr1 501 1000 a4 4 + 2 |
| 98 |
chr1 250 500 a3 3 - 3 |
| 99 |
|
| 100 |
|
| 101 |
========================================================================== |
| 102 |
``-d`` Controlling how close two features must be in order to cluster |
| 103 |
========================================================================== |
| 104 |
By default, only overlapping or book-ended features are combined into a new |
| 105 |
feature. However, one can force ``cluster`` to combine more distant features |
| 106 |
with the ``-d`` option. For example, were one to set ``-d`` to 1000, any |
| 107 |
features that overlap or are within 1000 base pairs of one another will be |
| 108 |
clustered. |
| 109 |
|
| 110 |
.. code-block:: bash |
| 111 |
|
| 112 |
$ cat A.bed |
| 113 |
chr1 100 200 |
| 114 |
chr1 501 1000 |
| 115 |
|
| 116 |
$ bedtools cluster -i A.bed |
| 117 |
chr1 100 200 1 |
| 118 |
chr1 501 1000 2 |
| 119 |
|
| 120 |
$ bedtools cluster -i A.bed -d 1000 |
| 121 |
chr1 100 200 1 |
| 122 |
chr1 501 1000 1 |
| 123 |
|