<p>The order of <code>-a</code> and <code>-b</code> switched at some point. You want:</p>

<pre><code>bedtools coverage -a All_peaks.bed -b file.bam &gt; file.cov.txt
</code></pre>

<p>For reference, this is the end of the help output in version 2.25:</p>

<pre><code>Default Output:  
     After each entry in A, reports: 
       1) The number of features in B that overlapped the A interval.
       2) The number of bases in A that had non-zero coverage.
       3) The length of the entry in A.
       4) The fraction of bases in A that had non-zero coverage.
</code></pre>

<p>And this is the equivalent output from version 2.19:</p>

<pre><code>Default Output:  
     After each entry in B, reports: 
       1) The number of features in A that overlapped the B interval.
       2) The number of bases in B that had non-zero coverage.
       3) The length of the entry in B.
       4) The fraction of bases in B that had non-zero coverage.
</code></pre>

<p><strong>Update</strong>: The change in behavior happened in version 2.24:</p>

<blockquote>
  <p>We have changed the behavior of the coverage tool such that it is consistent with the other tools. Specifically, coverage is now
  computed for the intervals in the A file based on the overlaps with the B file, rather than vice versa.</p>
</blockquote>

CC BY-SA 3.0
2017-08-17T13:32:11.627Z
Thanks Devon! I wasn't aware of the 'switch'. Switching -a and -b solves indeed my problem!
benn
CC BY-SA 3.0
2017-08-17T13:21:05.450Z
2017-08-17T13:21:05.450Z
Devon Ryan
<p>I recently installed Ubuntu 16.04 (because I was still using 12.04). But it seems my bedtools scripts don't work properly anymore. I can't figure out how to use the new bedtools for my old ways. What I want to do is get the number of reads from a bam file, per interval from a bed file. It was very simple with my old version of Ubuntu and bedtools:</p>

<pre><code>bedtools coverage -abam file.bam -b All_peaks.bed &gt; file.cov.txt
</code></pre>

<p>But this doesn't seem to work anymore. I used to get small files as results (~3MB), but now huge files are created (~4GB) including read names??</p>

<p>I am using bedtools v2.25 now.</p>

<sam><bedtools>
How to count reads in bam per bed interval with bedtools
# How to count reads in bam per bed interval with bedtools

(Asked by: username_0 on 2017-08-17)

I recently installed Ubuntu 16.04 (because I was still using 12.04). But it seems my bedtools scripts don't work properly anymore. I can't figure out how to use the new bedtools for my old ways. What I want to do is get the number of reads from a bam file, per interval from a bed file. It was very simple with my old version of Ubuntu and bedtools:
bedtools coverage -abam file.bam -b All_peaks.bed > file.cov.txt

But this doesn't seem to work anymore. I used to get small files as results (~3MB), but now huge files are created (~4GB) including read names??
I am using bedtools v2.25 now.

**Tags:** sam, bedtools

---

## 1 answers

### Answer by username_1 on 2017-08-17. Score: 10 | Accepted answer

The order of -a and -b switched at some point. You want:
bedtools coverage -a All_peaks.bed -b file.bam > file.cov.txt

For reference, this is the end of the help output in version 2.25:
Default Output:  
     After each entry in A, reports: 
       1) The number of features in B that overlapped the A interval.
       2) The number of bases in A that had non-zero coverage.
       3) The length of the entry in A.
       4) The fraction of bases in A that had non-zero coverage.

And this is the equivalent output from version 2.19:
Default Output:  
     After each entry in B, reports: 
       1) The number of features in A that overlapped the B interval.
       2) The number of bases in B that had non-zero coverage.
       3) The length of the entry in B.
       4) The fraction of bases in B that had non-zero coverage.

Update: The change in behavior happened in version 2.24:

We have changed the behavior of the coverage tool such that it is consistent with the other tools. Specifically, coverage is now
  computed for the intervals in the A file based on the overlaps with the B file, rather than vice versa.

> **Comments:**
> **username_0**: Thanks Devon! I wasn't aware of the 'switch'. Switching -a and -b solves indeed my problem!  

---

