Reference Code backup Executable files
Removes the portion(s) of intervals (in bed file A) that is overlapped by another feature(s) (defined in bed file B).
bedtools subtract [OPTIONS] -a <BED/GFF/VCF> -b <BED/GFF/VCF>
This tool is part of the bedtools
suite and it's also known as subtractBed
.
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.
-f 0.90
and -r are used, this requires that B overlap 90% of A and A also overlaps 90% of B. -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.-k1,1 -k2,2n
) input.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
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
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 +
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 +
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