| 1 |
.. _jaccard: |
| 2 |
|
| 3 |
############### |
| 4 |
*jaccard* |
| 5 |
############### |
| 6 |
|
| 7 |
| |
| 8 |
|
| 9 |
.. image:: ../images/tool-glyphs/jaccard-glyph.png |
| 10 |
:width: 600pt |
| 11 |
|
| 12 |
Whereas the bedtools ``intersect`` tool enumerates each an every intersection between two sets of genomic |
| 13 |
intervals, one often needs a single statistic reflecting the *similarity* of the two sets based on the |
| 14 |
intersections between them. The Jaccard statistic is used in set theory to represent the ratio of the |
| 15 |
intersection of two sets to the union of the two sets. Similarly, Favorov et al [1] reported the use |
| 16 |
of the Jaccard statistic for genome intervals: specifically, it measures the ratio of the number of |
| 17 |
intersecting base pairs between two sets to the number of base pairs in the union of the two sets. |
| 18 |
The bedtools jaccard tool implements this statistic, yet modifies the statistic such that the length of the |
| 19 |
intersection is subtracted from the length of the union. As a result, the final statistic ranges from 0.0 |
| 20 |
to 1.0, where 0.0 represents no overlap and 1.0 represent complete overlap. |
| 21 |
|
| 22 |
.. code:: |
| 23 |
|
| 24 |
[1] Exploring Massive, Genome Scale Datasets with the GenometriCorr Package. |
| 25 |
Favorov A, Mularoni L, Cope LM, Medvedeva Y, Mironov AA, et al. (2012) |
| 26 |
PLoS Comput Biol 8(5): e1002529. doi:10.1371/journal.pcbi.1002529 |
| 27 |
|
| 28 |
|
| 29 |
.. note:: |
| 30 |
|
| 31 |
The ``jaccard`` tool requires that your data is pre-sorted by chromosome and |
| 32 |
then by start position (e.g., ``sort -k1,1 -k2,2n in.bed > in.sorted.bed`` |
| 33 |
for BED files). |
| 34 |
|
| 35 |
.. seealso:: |
| 36 |
|
| 37 |
:doc:`../tools/reldist` |
| 38 |
:doc:`../tools/intersect` |
| 39 |
|
| 40 |
|
| 41 |
=============================== |
| 42 |
Usage and option summary |
| 43 |
=============================== |
| 44 |
**Usage**: |
| 45 |
:: |
| 46 |
|
| 47 |
bedtools jaccard [OPTIONS] -a <BED/GFF/VCF> -b <BED/GFF/VCF> |
| 48 |
|
| 49 |
|
| 50 |
=========================== ========================================================================================================================================================= |
| 51 |
Option Description |
| 52 |
=========================== ========================================================================================================================================================= |
| 53 |
**-a** BED/GFF/VCF file A. Each feature in A is compared to B in search of overlaps. Use "stdin" if passing A with a UNIX pipe. |
| 54 |
**-b** BED/GFF/VCF file B. Use "stdin" if passing B with a UNIX pipe. |
| 55 |
**-f** Minimum overlap required as a fraction of A. Default is 1E-9 (i.e. 1bp). |
| 56 |
**-F** Minimum overlap required as a fraction of B. Default is 1E-9 (i.e., 1bp). |
| 57 |
**-r** Require that the fraction of overlap be reciprocal for A and B. In other words, if -f is 0.90 and -r is used, this requires that B overlap at least 90% of A and that A also overlaps at least 90% of B. |
| 58 |
**-e** Require that the minimum fraction be satisfied for A _OR_ B. In other words, if -e is used with -f 0.90 and -F 0.10 this requires that either 90% of A is covered OR 10% of B is covered. Without -e, both fractions would have to be satisfied.**-s** Force "strandedness". That is, only report hits in B that overlap A on the same strand. By default, overlaps are reported without respect to strand. |
| 59 |
**-S** Require different strandedness. That is, only report hits in B that overlap A on the _opposite_ strand. By default, overlaps are reported without respect to strand. |
| 60 |
**-split** Treat "split" BAM (i.e., having an "N" CIGAR operation) or BED12 entries as distinct BED intervals. |
| 61 |
=========================== ========================================================================================================================================================= |
| 62 |
|
| 63 |
|
| 64 |
=============================== |
| 65 |
Default behavior |
| 66 |
=============================== |
| 67 |
By default, ``bedtools jaccard`` reports the length of the intersection, the length of the union (minus the intersection), |
| 68 |
the final Jaccard statistic reflecting the similarity of the two sets, as well as the number of intersections. |
| 69 |
|
| 70 |
.. code-block:: bash |
| 71 |
|
| 72 |
$ cat a.bed |
| 73 |
chr1 10 20 |
| 74 |
chr1 30 40 |
| 75 |
|
| 76 |
$ cat b.bed |
| 77 |
chr1 15 20 |
| 78 |
|
| 79 |
$ bedtools jaccard -a a.bed -b b.bed |
| 80 |
intersection union jaccard n_intersections |
| 81 |
5 20 0.25 1 |
| 82 |
|
| 83 |
============================================ |
| 84 |
Controlling which intersections are included |
| 85 |
============================================ |
| 86 |
One can also control which intersections are included in the statistic by requiring a certain fraction of overlap |
| 87 |
with respect to the features in A (via the ``-f`` parameter) or also by requiring that the fraction of overlap is |
| 88 |
reciprocal (``-r``) in A and B. |
| 89 |
|
| 90 |
.. code-block:: bash |
| 91 |
|
| 92 |
$ cat a.bed |
| 93 |
chr1 10 20 |
| 94 |
chr1 30 40 |
| 95 |
|
| 96 |
$ cat b.bed |
| 97 |
chr1 15 20 |
| 98 |
|
| 99 |
Require 10% overlap with respect to the intervals in A: |
| 100 |
|
| 101 |
.. code-block:: bash |
| 102 |
|
| 103 |
$ bedtools jaccard -a a.bed -b b.bed -f 0.1 |
| 104 |
intersection union jaccard n_intersections |
| 105 |
5 20 0.25 1 |
| 106 |
|
| 107 |
Require 60% overlap with respect to the intervals in A: |
| 108 |
|
| 109 |
.. code-block:: bash |
| 110 |
|
| 111 |
$ bedtools jaccard -a a.bed -b b.bed -f 0.6 |
| 112 |
intersection union jaccard n_intersections |
| 113 |
0 25 0.25 0 |
| 114 |
|