Reference Code backup Executable files
Returns the depth and breadth of coverage of features from B on the intervals in A.
bedtools coverage [OPTIONS] -a <bed/gff/vcf> -b <bed/gff/vcf>
This tool is part of the bedtools
suite and it has an alias known as coverageBed
.
The bedtools coverage
tool computes both the depth and breadth of coverage of features in file B on the features in file A. For example, bedtools coverage can compute the coverage of sequence alignments (file B) across 1 kilobase (arbitrary) windows (file A) tiling a genome of interest. One advantage that bedtools coverage offers is that it not only counts the number of features that overlap an interval in file A, it also computes the fraction of bases in the interval in A that were overlapped by one or more features. Thus, bedtools coverage also computes the breadth of coverage observed for each interval in A.
After each interval in A, bedtools coverage
will report:
Below are the number of features in B ($N=…$) overlapping A and fraction of bases in A with coverage.
Chromosome ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ BED FILE A *************** *************** ****** ************** BED File B ^^^^ ^^^^ ^^ ^^^^^^^^^ ^^^ ^^ ^^^^ ^^^^^^^^ ^^^^^ ^^^^^ ^^ Result [ N=3, 10/15 ] [ N=1, 2/15 ] [N=1,6/6] [N=6, 12/14 ]
samtools view -b <BAM> | bedtools intersect-abam stdin
-b genes.bed
-f 0.90
and -r, you require that B overlap at least 90% of A and that A also overlaps at least 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.sort -k1,1 -k2,2n
for BED files) input. When using -sorted, memory usage remains low even for very large files.-sorted
option.Use the -s option if one wants to only count coverage if features in A are on the same strand as the feature / window in A. This is especially useful for RNA-seq experiments.
For example (note the difference in coverage with and without -s:
$ cat A.bed chr1 0 100 b1 1 + chr1 100 200 b2 1 - chr2 0 100 b3 1 + $ cat B.bed chr1 10 20 a1 1 - chr1 20 30 a2 1 - chr1 30 40 a3 1 - chr1 100 200 a4 1 + $ bedtools coverage-a A.bed
-b B.bed
chr1 0 100 b1 1 + 3 30 100 0.3000000 chr1 100 200 b2 1 - 1 100 100 1.0000000 chr2 0 100 b3 1 + 0 0 100 0.0000000 $ bedtools coverage-a A.bed
-b B.bed
-s chr1 0 100 b1 1 + 0 0 100 0.0000000 chr1 100 200 b2 1 - 0 0 100 0.0000000 chr2 0 100 b3 1 + 0 0 100 0.0000000
One should use the -hist option to create, for each interval in A, a histogram of coverage of the features in B across A. In this case, each entire feature in A will be reported, followed by the depth of coverage, the number of bases at that depth, the size of the feature, and the fraction covered. After all of the features in A have been reported, a histogram summarizing the coverage among all features in A will be reported.
$ cat A.bed chr1 0 100 b1 1 + chr1 100 200 b2 1 - chr2 0 100 b3 1 + $ cat B.bed chr1 10 20 a1 1 - chr1 20 30 a2 1 - chr1 30 40 a3 1 - chr1 100 200 a4 1 + $ bedtools coverage-a A.bed
-b B.bed
-hist chr1 0 100 b1 1 + 0 70 100 0.7000000 chr1 0 100 b1 1 + 1 30 100 0.3000000 chr1 100 200 b2 1 - 1 100 100 1.0000000 chr2 0 100 b3 1 + 0 100 100 1.0000000 all 0 170 300 0.5666667 all 1 130 300 0.4333333
One should use the -d option to create, for each interval in A, a detailed list of coverage at each of the positions across each A interval. The output will consist of a line for each one-based position in each A feature, followed by the coverage detected at that position.
$ cat A.bed chr1 0 10 $ cat B.bed chr1 0 5 chr1 3 8 chr1 4 8 chr1 5 9 $ bedtools coverage-a A.bed
-b B.bed
-d chr1 0 10 B 1 1 chr1 0 10 B 2 1 chr1 0 10 B 3 1 chr1 0 10 B 4 2 chr1 0 10 B 5 3 chr1 0 10 B 6 3 chr1 0 10 B 7 3 chr1 0 10 B 8 3 chr1 0 10 B 9 1 chr1 0 10 B 10 0