Answers.Body: <p>If you prefer to have a more concise report than a per-base one, <a href="https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html" rel="nofollow noreferrer">bedtools genomecov</a> could be a better choice.</p>
  <p>Its <code>-bga</code> option allows you to report consecutive bases that have the same coverage as a range in a single line.</p>
  <p>In your case, you could achieve this (unfortunately they only offer the strandedness option for a specified strand) by running the following command:</p>
  <pre><code>bedtools genomecov -bga -ibam aln.bam -g chr1.bed -strand + &gt; coverage.perposition_chr1.tsv
  </code></pre>
  <p>Output will look like:</p>
  <pre><code>chr1  554304  554309  5
  chr1  554309  554313  6
  chr1  554313  554314  1
  chr1  554315  554316  6
  chr1  554316  554317  5
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-17T01:05:42.210Z
Answers.LastActivityDate: 2022-11-17T01:05:42.210Z
Answers.UserDisplayName: Siyuan Feng
Body: <p>I am using bedtools coverage to compute the sequencing depth at every positions of a chromosome but it didn't work as I expected.
  Instead it reported 0 coverage at every positions.</p>
  <p>This is how I did it :</p>
  <p>I made a <code>chr1.bed</code> bedfile :</p>
  <pre><code>chr start   end 
  1   1   158534110
  </code></pre>
  <p>I ran this command  :</p>
  <pre><code>coverageBed -a -d chr1.bed -b aln.bam -s &gt; coverage.perposition_chr1.tsv
  </code></pre>
  <p>However I don't find any position in the output that is actually covered :</p>
  <pre><code>chr start end 1-pos depth
  1   1   158534110   1   0
  1   1   158534110   2   0
  1   1   158534110   3   0
  1   1   158534110   4   0
  1   1   158534110   5   0
  1   1   158534110   6   0
  1   1   158534110   7   0
  1   1   158534110   8   0
  (...)
  1   1   158534110   158534109   0
  
  </code></pre>
  <p>I must do something wrong because I already computed depth at specific pattern positions using the same <code>aln.bam</code> and it was working fine...</p>
  <p><strong>Suggestions and tries :</strong></p>
  <ul>
  <li>Swapping <code>-a</code> &amp; <code>-d</code> parameters produces the same results</li>
  <li>Adding a strand column to the bedfile still gives 0 coverage.</li>
  </ul>
  <p><code>chr1.bed</code></p>
  <pre><code>1       1       158534110       .       0       +
  1       1       158534110       .       0       -
  </code></pre>
  <p><code>output</code></p>
  <pre><code>
  1       1       158534110       .       0       +       1       0
  1       1       158534110       .       0       +       2       0
  (...)
  1       1       158534110       .       0       -       158534108       0
  1       1       158534110       .       0       -       158534109       0
  <span class="math-container">```</span>
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-12T17:18:51.477Z
Comments.Text: In your .bam file (and the original reference you used) are the chromosomes called '1' '2'; etc, or 'Chr1', 'Chr2' etc?  Also, you could try swapping the -a and -d - maybe the -a needs to be immediately before the .bed file.
Comments.UserDisplayName: Jay Moore
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-12T17:21:16.343Z
Comments.Text: @JonathanMoore I bet you're right. The `-a` expects a string, so that would take `-d` as the value for `-a`. Probably worth an answer already.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-12T17:42:22.263Z
Comments.Text: @JonathanMoore Yes this is the right chromosome name. I tried swipping parameters and it did produce the same file. @terdon wouldn't I expect an error If it indeed took `-d` as the `-a` value ? It is not fitting the right format
Comments.UserDisplayName: Paul Endymion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-12T22:52:28.040Z
Comments.Text: Consider posting 1-2 alignments in `sam` format, which you would expect to give non-zero coverage as the minimum reproducible example. What is the bedtools version? What happens if you drop `-s`?
Comments.UserDisplayName: Timur Shtatland
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-13T09:53:45.790Z
Comments.Text: @TimurShtatland Dammit that was it, the bam went blank at some point in my testing. I should have suspected that. It works now. My bad and thanks all for the suggestions..
Comments.UserDisplayName: Paul Endymion
Tags: <phylogenetics><bedtools><coverage>
Title: bedtools coverage - Report the depth at each position in each A feature
ThreadText: # bedtools coverage - Report the depth at each position in each A feature
  
  (Asked by: username_0 on 2019-11-12)
  
  I am using bedtools coverage to compute the sequencing depth at every positions of a chromosome but it didn't work as I expected.
  Instead it reported 0 coverage at every positions.
  
  This is how I did it :
  
  I made a `chr1.bed` bedfile :
  
  ```
  chr start   end 
  1   1   158534110
  
  ```
  
  I ran this command :
  
  ```
  coverageBed -a -d chr1.bed -b aln.bam -s > coverage.perposition_chr1.tsv
  
  ```
  
  However I don't find any position in the output that is actually covered :
  
  ```
  chr start end 1-pos depth
  1   1   158534110   1   0
  1   1   158534110   2   0
  1   1   158534110   3   0
  1   1   158534110   4   0
  1   1   158534110   5   0
  1   1   158534110   6   0
  1   1   158534110   7   0
  1   1   158534110   8   0
  (...)
  1   1   158534110   158534109   0
  
  ```
  
  I must do something wrong because I already computed depth at specific pattern positions using the same `aln.bam` and it was working fine...
  
  **Suggestions and tries :**
  
  * Swapping `-a` & `-d` parameters produces the same results
  * Adding a strand column to the bedfile still gives 0 coverage.
  
  `chr1.bed`
  
  ```
  1       1       158534110       .       0       +
  1       1       158534110       .       0       -
  
  ```
  
  `output`
  
  ```
  
  1       1       158534110       .       0       +       1       0
  1       1       158534110       .       0       +       2       0
  (...)
  1       1       158534110       .       0       -       158534108       0
  1       1       158534110       .       0       -       158534109       0
  ```
  
  ```
  
  **Tags:** phylogenetics, bedtools, coverage
  
  > **Comments:**
  > **username_1**: In your .bam file (and the original reference you used) are the chromosomes called '1' '2'; etc, or 'Chr1', 'Chr2' etc?  Also, you could try swapping the -a and -d - maybe the -a needs to be immediately before the .bed file.  
  > **username_2**: @JonathanMoore I bet you're right. The `-a` expects a string, so that would take `-d` as the value for `-a`. Probably worth an answer already.  
  > **username_0**: @JonathanMoore Yes this is the right chromosome name. I tried swipping parameters and it did produce the same file. @username_2 wouldn't I expect an error If it indeed took `-d` as the `-a` value ? It is not fitting the right format  
  > **username_3**: Consider posting 1-2 alignments in `sam` format, which you would expect to give non-zero coverage as the minimum reproducible example. What is the bedtools version? What happens if you drop `-s`?  
  > **username_0**: @username_3 Dammit that was it, the bam went blank at some point in my testing. I should have suspected that. It works now. My bad and thanks all for the suggestions..  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2022-11-17. Score: 2
  
  If you prefer to have a more concise report than a per-base one, [bedtools genomecov](https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html) could be a better choice.
  
  Its `-bga` option allows you to report consecutive bases that have the same coverage as a range in a single line.
  
  In your case, you could achieve this (unfortunately they only offer the strandedness option for a specified strand) by running the following command:
  
  ```
  bedtools genomecov -bga -ibam aln.bam -g chr1.bed -strand + > coverage.perposition_chr1.tsv
  
  ```
  
  Output will look like:
  
  ```
  chr1  554304  554309  5
  chr1  554309  554313  6
  chr1  554313  554314  1
  chr1  554315  554316  6
  chr1  554316  554317  5
  
  ```
  
  
  ---
  
  