| 1 |
.. _subtract: |
| 2 |
|
| 3 |
############### |
| 4 |
*subtract* |
| 5 |
############### |
| 6 |
|
| 7 |
| |
| 8 |
|
| 9 |
.. image:: ../images/tool-glyphs/subtract-glyph.png |
| 10 |
:width: 600pt |
| 11 |
|
| 12 |
| |
| 13 |
|
| 14 |
``bedtools subtract`` bedtools` subtract searches for features in B that overlap A by at least the number of base pairs given by the -f option. If an overlapping feature is found in B, the overlapping portion is removed from A and the remaining portion of A is reported. If a feature in B overlaps all of a feature in A, the A feature will not be reported. If a feature in B does not overlap a feature in A by at least the -f amount, the A feature will be reported in its entirety. |
| 15 |
|
| 16 |
|
| 17 |
=============================== |
| 18 |
Usage and option summary |
| 19 |
=============================== |
| 20 |
**Usage**: |
| 21 |
:: |
| 22 |
|
| 23 |
bedtools subtract [OPTIONS] -a <BED/GFF/VCF> -b <BED/GFF/VCF> |
| 24 |
|
| 25 |
**(or)**: |
| 26 |
:: |
| 27 |
|
| 28 |
subtractBed [OPTIONS] -a <BED/GFF/VCF> -b <BED/GFF/VCF> |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
=========================== =============================================================================================================================================================================================================== |
| 33 |
Option Description |
| 34 |
=========================== =============================================================================================================================================================================================================== |
| 35 |
**-f** Minimum overlap required as a fraction of A. Default is 1E-9 (i.e. 1bp). |
| 36 |
**-F** Minimum overlap required as a fraction of B. Default is 1E-9 (i.e., 1bp). |
| 37 |
**-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. |
| 38 |
**-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. |
| 39 |
**-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. |
| 40 |
**-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. |
| 41 |
**-A** Remove entire feature if any overlap. That is, by default, only subtract the portion of A that overlaps B. Here, if any overlap is found (or ``-f`` amount), the entire feature is removed. |
| 42 |
**-N** Same as -A except when used with -f, the amount is the sum of all features (not any single feature). |
| 43 |
=========================== =============================================================================================================================================================================================================== |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
========================================================================== |
| 48 |
Default behavior |
| 49 |
========================================================================== |
| 50 |
By default, ``bedtools subtracts`` removes each overlapping interval in B |
| 51 |
from A. If a feature in B *completely* overlaps a feature in A, the A feature |
| 52 |
is removed. |
| 53 |
|
| 54 |
.. code-block:: bash |
| 55 |
|
| 56 |
$ cat A.bed |
| 57 |
chr1 10 20 |
| 58 |
chr1 100 200 |
| 59 |
|
| 60 |
$ cat B.bed |
| 61 |
chr1 0 30 |
| 62 |
chr1 180 300 |
| 63 |
|
| 64 |
$ bedtools subtract -a A.bed -b B.bed |
| 65 |
chr1 100 180 |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
========================================================================== |
| 73 |
``-f`` Requiring a minimal overlap fraction before subtracting |
| 74 |
========================================================================== |
| 75 |
This option behaves the same as the ``-f`` option for ``bedtools intersect``. |
| 76 |
In this case, ``subtract`` will only subtract an overlap with B if it covers at |
| 77 |
least the fraction of A defined by ``-f``. If an overlap is found, |
| 78 |
but it does not meet the overlap fraction, the original A feature is |
| 79 |
reported without subtraction. |
| 80 |
|
| 81 |
.. code-block:: bash |
| 82 |
|
| 83 |
$ cat A.bed |
| 84 |
chr1 100 200 |
| 85 |
|
| 86 |
$ cat B.bed |
| 87 |
chr1 180 300 |
| 88 |
|
| 89 |
$ bedtools subtract -a A.bed -b B.bed -f 0.10 |
| 90 |
chr1 100 180 |
| 91 |
|
| 92 |
$ bedtools subtract -a A.bed -b B.bed -f 0.80 |
| 93 |
chr1 100 200 |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
========================================================================== |
| 99 |
``-s`` Enforcing same "strandedness" |
| 100 |
========================================================================== |
| 101 |
This option behaves the same as the ``-s`` option for ``bedtools intersect`` |
| 102 |
while scanning for features in B that should be subtracted from A. |
| 103 |
|
| 104 |
.. code-block:: bash |
| 105 |
|
| 106 |
$ cat A.bed |
| 107 |
chr1 100 200 a1 1 + |
| 108 |
|
| 109 |
$ cat B.bed |
| 110 |
chr1 80 120 b1 1 + |
| 111 |
chr1 180 300 b2 1 - |
| 112 |
|
| 113 |
$ bedtools subtract -a A.bed -b B.bed -s |
| 114 |
chr1 120 200 a1 1 + |
| 115 |
|
| 116 |
|
| 117 |
========================================================================== |
| 118 |
``-S`` Enforcing opposite "strandedness" |
| 119 |
========================================================================== |
| 120 |
This option behaves the same as the ``-s`` option for ``bedtools intersect`` |
| 121 |
while scanning for features in B that should be subtracted from A. |
| 122 |
|
| 123 |
.. code-block:: bash |
| 124 |
|
| 125 |
$ cat A.bed |
| 126 |
chr1 100 200 a1 1 + |
| 127 |
|
| 128 |
$ cat B.bed |
| 129 |
chr1 80 120 b1 1 + |
| 130 |
chr1 180 300 b2 1 - |
| 131 |
|
| 132 |
$ bedtools subtract -a A.bed -b B.bed -S |
| 133 |
chr1 100 180 a1 1 + |
| 134 |
|
| 135 |
|
| 136 |
========================================================================== |
| 137 |
``-A`` Remove features with any overlap |
| 138 |
========================================================================== |
| 139 |
Unlike the default behavior, the ``-A`` option will completely remove |
| 140 |
a feature from A if it has even 1bp of overlap with a feature in B. |
| 141 |
|
| 142 |
.. code-block:: bash |
| 143 |
|
| 144 |
$ cat A.bed |
| 145 |
chr1 100 200 |
| 146 |
|
| 147 |
$ cat B.bed |
| 148 |
chr1 180 300 |
| 149 |
|
| 150 |
$ bedtools subtract -a A.bed -b B.bed |
| 151 |
chr1 100 180 |
| 152 |
|
| 153 |
$ bedtools subtract -a A.bed -b B.bed -A |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|