<p>You are looking for <code>bedtools genomecov</code>, specifically <a href="https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html#d-reporting-per-base-genome-coverage" rel="nofollow noreferrer"><code>-d</code></a> option. See <a href="https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html" rel="nofollow noreferrer">https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html</a> , for example:</p>

<pre><code>bedtools genomecov -i A.bed -g my.genome -d
</code></pre>

<hr>

<p>I recommend not reinventing the wheel: use <code>bedtools</code> instead of reimplementing the same functionality in Perl.</p>

CC BY-SA 4.0
2020-01-28T14:21:11.230Z
thanks, but bedtools doesn't work in this case as there is no header info.
Gene_of_Thrones
CC BY-SA 4.0
2020-01-28T14:25:52.557Z
Can you add it from another bam file using samtools? Or add a fake header?
Timur Shtatland
CC BY-SA 4.0
2020-02-10T13:14:16.093Z
i did add a header from a different sample to calculate the coverage... just wondering if we can do it using awk.
Gene_of_Thrones
CC BY-SA 4.0
2020-01-27T17:39:13.583Z
2020-01-27T17:39:13.583Z
Timur Shtatland
<p>I have a RNA aligned file without any header info. 
I need to calculate the coverage of each mapped base for per chromosome. Is it possible to do it with perl ? </p>

<pre><code>NS500377:28:H16A7BGXX:2:21205:16038:7658        99      chr2   3000482 255     46M     =       3000502 56      GTCCTACAGTGTGCATTTCTCGTTTTCCACGTTTCT    AAAA)FFFFFFFFFAFFFFFFFFFFF.F.FFFFFAF    XA:i:2  MD:Z:21T4T7T1   NM:i:3
NS500377:28:H16A7BGXX:3:11503:24953:10427       99      chr2   3000482 255     50M     =       3000513 71      GTCCTACAGTGTGCATTTCTCATTTTTCAAGTTTTTCAGT        AAAAAFFFFFFFFFFFFAFFFFFF7AAFFFFFFFFFFFFF
        XA:i:1  MD:Z:21T7C10    NM:i:2
NS500377:28:H16A7BGXX:3:12404:23929:9392        163     chr2   3000482 255     49M     =       3000483 40      GTCCTACAGTGTGCATTTCCCTTTTTTCACGTTTTTTAG AAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF XA:i:1  MD:Z:19T16C2    NM:i:2
NS500377:28:H16A7BGXX:3:12404:23929:9392        83      chr2   3000483 255     49M     =       3000482 -40     TCCTACAGTGTGCATTTCCCTTTTTTCACGTTTTTTAGT AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF XA:i:2  MD:Z:18T16C3    NM:i:2
NS500377:28:H16A7BGXX:3:21606:15675:1639        83      chr2   3000483 255     50M     =       3000480 -43     TCTTACAGTGTGCATTTCTCTTTTTTCACGTTTTTCAGTG        AFFFFFFFFFAFFFFFFFFFFFFFFFFFFFFFFFFAAAAA
        XA:i:0  MD:Z:2C37       NM:i:1
NS500377:28:H16A7BGXX:4:12605:18505:11088       83      chr2   3000486 255     50M     =       3000481 -45     TACAATGTGCATTTCTCTTTTTTCACGTTTTTCAGTATTT        FFFFFFFAFFF)FFFFFFFFF&lt;FFFF&lt;AFFFFFFFAA&lt;AA
        XA:i:1  MD:Z:4G31G3     NM:i:2
NS500377:28:H16A7BGXX:2:13303:20634:12085       99      chr2   3000487 255     49M     =       3000521 73      ACAGTGTACATTTCTCATTTTTCACGTTTTTCAGTGTTA AAAAAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF. XA:i:2  MD:Z:7G8T21T0   NM:i:3
</code></pre>

<rna><coverage><awk>
how to calculate coverage of each base of mapped reads?
# how to calculate coverage of each base of mapped reads?

(Asked by: username_0 on 2020-01-27)

I have a RNA aligned file without any header info. 
I need to calculate the coverage of each mapped base for per chromosome. Is it possible to do it with perl ? 
NS500377:28:H16A7BGXX:2:21205:16038:7658        99      chr2   3000482 255     46M     =       3000502 56      GTCCTACAGTGTGCATTTCTCGTTTTCCACGTTTCT    AAAA)FFFFFFFFFAFFFFFFFFFFF.F.FFFFFAF    XA:i:2  MD:Z:21T4T7T1   NM:i:3
NS500377:28:H16A7BGXX:3:11503:24953:10427       99      chr2   3000482 255     50M     =       3000513 71      GTCCTACAGTGTGCATTTCTCATTTTTCAAGTTTTTCAGT        AAAAAFFFFFFFFFFFFAFFFFFF7AAFFFFFFFFFFFFF
        XA:i:1  MD:Z:21T7C10    NM:i:2
NS500377:28:H16A7BGXX:3:12404:23929:9392        163     chr2   3000482 255     49M     =       3000483 40      GTCCTACAGTGTGCATTTCCCTTTTTTCACGTTTTTTAG AAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF XA:i:1  MD:Z:19T16C2    NM:i:2
NS500377:28:H16A7BGXX:3:12404:23929:9392        83      chr2   3000483 255     49M     =       3000482 -40     TCCTACAGTGTGCATTTCCCTTTTTTCACGTTTTTTAGT AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF XA:i:2  MD:Z:18T16C3    NM:i:2
NS500377:28:H16A7BGXX:3:21606:15675:1639        83      chr2   3000483 255     50M     =       3000480 -43     TCTTACAGTGTGCATTTCTCTTTTTTCACGTTTTTCAGTG        AFFFFFFFFFAFFFFFFFFFFFFFFFFFFFFFFFFAAAAA
        XA:i:0  MD:Z:2C37       NM:i:1
NS500377:28:H16A7BGXX:4:12605:18505:11088       83      chr2   3000486 255     50M     =       3000481 -45     TACAATGTGCATTTCTCTTTTTTCACGTTTTTCAGTATTT        FFFFFFFAFFF)FFFFFFFFF

**Tags:** rna, coverage, awk

---

## 1 answers

### Answer by username_1 on 2020-01-27. Score: 1

You are looking for bedtools genomecov, specifically -d option. See https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html , for example:
bedtools genomecov -i A.bed -g my.genome -d


I recommend not reinventing the wheel: use bedtools instead of reimplementing the same functionality in Perl.

> **Comments:**
> **username_0**: thanks, but bedtools doesn't work in this case as there is no header info.  
> **username_1**: Can you add it from another bam file using samtools? Or add a fake header?  
> **username_0**: i did add a header from a different sample to calculate the coverage... just wondering if we can do it using awk.  

---

