5.1.35. subtract


../../_images/subtract-glyph.png

bedtools subtract searches for features in B that overlap A. 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.

5.1.35.1. Usage and option summary

Usage:

bedtools subtract [OPTIONS] -a <BED/GFF/VCF> -b <BED/GFF/VCF>

(or):

subtractBed [OPTIONS] -a <BED/GFF/VCF> -b <BED/GFF/VCF>
Option Description
-f Minimum overlap required as a fraction of A. Default is 1E-9 (i.e. 1bp).
-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.
-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.
-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.
-N Same as -A except when used with -f, the amount is the sum of all features (not any single feature).

5.1.35.2. Default behavior

By default, bedtools subtracts removes each overlapping interval in B from A. If a feature in B completely overlaps a feature in A, the A feature is removed.

$ cat A.bed
chr1  10   20
chr1  100  200

$ cat B.bed
chr1  0    30
chr1  180  300

$ bedtools subtract -a A.bed -b B.bed
chr1  100  180

5.1.35.3. -f Requiring a minimal overlap fraction before subtracting

This option behaves the same as the -f option for bedtools intersect. In this case, subtract will only subtract an overlap with B if it covers at least the fraction of A defined by -f. If an overlap is found, but it does not meet the overlap fraction, the original A feature is reported without subtraction.

$ cat A.bed
chr1  100  200

$ cat B.bed
chr1  180  300

$ bedtools subtract -a A.bed -b B.bed -f 0.10
chr1  100  180

$ bedtools subtract -a A.bed -b B.bed -f 0.80
chr1  100  200

5.1.35.4. -s Enforcing same “strandedness”

This option behaves the same as the -s option for bedtools intersect while scanning for features in B that should be subtracted from A.

$ cat A.bed
chr1  100  200    a1  1   +

$ cat B.bed
chr1  80   120    b1  1   +
chr1  180  300    b2  1   -

$ bedtools subtract -a A.bed -b B.bed -s
chr1  120  200    a1  1   +

5.1.35.5. -S Enforcing opposite “strandedness”

This option behaves the same as the -s option for bedtools intersect while scanning for features in B that should be subtracted from A.

$ cat A.bed
chr1  100  200    a1  1   +

$ cat B.bed
chr1  80   120    b1  1   +
chr1  180  300    b2  1   -

$ bedtools subtract -a A.bed -b B.bed -S
chr1  100  180    a1  1   +

5.1.35.6. -A Remove features with any overlap

Unlike the default behavior, the -A option will completely remove a feature from A if it has even 1bp of overlap with a feature in B.

$ cat A.bed
chr1  100  200

$ cat B.bed
chr1  180  300

$ bedtools subtract -a A.bed -b B.bed
chr1  100  180

$ bedtools subtract -a A.bed -b B.bed -A
comments powered by Disqus

Edit and improve this document!

This file can be edited directly through the Web. Anyone can update and fix errors in this document with few clicks -- no downloads needed.

  1. Go to 5.1.35. subtract on GitHub.
  2. Edit files using GitHub's text editor in your web browser (see the 'Edit' tab on the top right of the file)
  3. Fill in the Commit message text box at the bottom of the page describing why you made the changes. Press the Propose file change button next to it when done.
  4. Then click Send a pull request.
  5. Your changes are now queued for review under the project's Pull requests tab on GitHub!

For an introduction to the documentation format please see the reST primer.