<p>If one assumes that repeat elements of a given type (e.g., LINEs) don't overlap each other, then the following will work:</p>

<ol>
<li>Split your BED file by repeat element, such that you have a LINE.bed, SINE.bed, etc.</li>
<li>Convert those to bedGraph (e.g., <code>awk 'BEGIN{OFS="\t"}{print <span class="math-container">$1,$</span>2,$3,"1.0"}' LINE.bed &gt; LINE.bedGraph</code>).</li>
<li>Use UCSC tools to convert those bedGraph files to BigWig.</li>
<li>Install deepTools and run <code>computeMatrix reference-point -b 2500 -a 20 -S LINE.bigWig SINE.bigWig LTR.bigWig -R Regions_Of_Interest.BED -o foo.mat.gz</code></li>
<li>Make a profile plot with plotProfile (<code>plotProfile -m foo.mat.gz -o foo.png --perGroup</code>)</li>
</ol>

<p>If you do have overlapping regions you'll need to first make a disjoint set of intervals (you can use bedops for this), find the coverage of them (e.g., <code>bedtools coverage</code>) and then continue on with that.</p>

CC BY-SA 4.0
2019-01-31T12:13:16.543Z
I still have to try it, but this might just work. I will mark it as answer unless something goes wrong. I would use `scale-regions` instead of `reference-point` since I'm interested in the whole region length.
Siddharth
CC BY-SA 4.0
2019-01-30T07:42:45.817Z
2019-01-30T07:42:45.817Z
Devon Ryan
<p>There is a reasonably nice looking tutorial on metaplots in R here: <a href="https://rpubs.com/achitsaz/94710" rel="nofollow noreferrer">https://rpubs.com/achitsaz/94710</a></p>

CC BY-SA 4.0
2019-01-29T13:43:23.850Z
Thanks for answering this, usually we'd like to have the answer self-contained. Perhaps you could improve the question by including the relevant packages/code from that website into your answer.
llrs
CC BY-SA 4.0
2019-01-29T11:00:55.103Z
2019-01-29T11:00:55.103Z
Jay Moore
<p>I'm trying to plot "meta" coverage of annotation: i.e. features (eg. gene class) over certain regions. It is similar to read coverage plots over gene body, except my input is two bed files (both in BED6 format) - (A) one containing the regions for which the meta plot is needed, and another being the list of genes or any feature whose coverage over the regions in (A) is needed. </p>

<p>Is there any package or tool which can create such plots (my domain is limited to python but I can try to work with R) ?</p>

<p>Something akin to this but for whole gene body<a href="https://genomebiology.biomedcentral.com/articles/10.1186/gb-2012-13-11-r107" rel="nofollow noreferrer">[1]</a>:
<a href="https://i.sstatic.net/X2buW.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/X2buW.jpg" alt="enter image description here"></a></p>

<p>[<a href="https://genomebiology.biomedcentral.com/articles/10.1186/gb-2012-13-11-r107" rel="nofollow noreferrer">1</a>]- Kelley, D, Rinn, J (2012). Transposable elements reveal a stem cell-specific class of long noncoding RNAs. Genome Biol., 13, 11:R107.</p>

<p>Edit: The BED file containing list of regions looks like this:</p>

<pre><code>chr3    39218734    40053659    region1 0.92426187419769    +
chr4    140163762   140453127   region2 0.896103896103896   -
chr7    40549151    41205036    region3 0.986072423398329   +
chr8    81291743    81963246    region4 0.94184168012924    -
chr9    12284032    12539789    region5 0.95539033457249    -
</code></pre>

<p>And the bed file containing features to be plotted looks like this:</p>

<pre><code>chr3    39218100    40053200    LINE    1   +
chr4    140163962   140453027   LINE 1  -
chr7    40549002    41204999    SINE 1  +
chr8    81291143    81963846    LTR 1   -
chr9    12284332    12539720    LTR 1   -
</code></pre>

CC BY-SA 4.0
2019-01-28T13:28:19.617Z
I am not familiar with this field, so I would like to know the terms I should avoid/are not good enough. What kind of keywords have you searched?
llrs
CC BY-SA 4.0
2019-01-28T13:53:38.293Z
@llrs, I'm not exactly sure what you mean by "terms I should avoid/are not good enough." - but I believe coverage plots are one class of visualisation which are more similar to binned histograms in general. Except a google search would yield in methods related to plotting coverage of transcripts or reads acquired from sequencing experiments [keywords: coverage plots, bedfiles, metaplots]. The key difference here is that I'm interested in scaled coverage over whole gene body (TSS-TES) instead of positions relative to TSS - similar to deeptools plotProfile.
Siddharth
<python><software-recommendation><visualization><coverage>
Plotting coverage of annotation over collection of region
# Plotting coverage of annotation over collection of region

(Asked by: username_0 on 2019-01-28)

I'm trying to plot "meta" coverage of annotation: i.e. features (eg. gene class) over certain regions. It is similar to read coverage plots over gene body, except my input is two bed files (both in BED6 format) - (A) one containing the regions for which the meta plot is needed, and another being the list of genes or any feature whose coverage over the regions in (A) is needed. 
Is there any package or tool which can create such plots (my domain is limited to python but I can try to work with R) ?
Something akin to this but for whole gene body[1]:

[1]- Kelley, D, Rinn, J (2012). Transposable elements reveal a stem cell-specific class of long noncoding RNAs. Genome Biol., 13, 11:R107.
Edit: The BED file containing list of regions looks like this:
chr3    39218734    40053659    region1 0.92426187419769    +
chr4    140163762   140453127   region2 0.896103896103896   -
chr7    40549151    41205036    region3 0.986072423398329   +
chr8    81291743    81963246    region4 0.94184168012924    -
chr9    12284032    12539789    region5 0.95539033457249    -

And the bed file containing features to be plotted looks like this:
chr3    39218100    40053200    LINE    1   +
chr4    140163962   140453027   LINE 1  -
chr7    40549002    41204999    SINE 1  +
chr8    81291143    81963846    LTR 1   -
chr9    12284332    12539720    LTR 1   -

**Tags:** python, software-recommendation, visualization, coverage
> **Comments:**
> **username_1**: I am not familiar with this field, so I would like to know the terms I should avoid/are not good enough. What kind of keywords have you searched?  
> **username_0**: @llrs, I'm not exactly sure what you mean by "terms I should avoid/are not good enough." - but I believe coverage plots are one class of visualisation which are more similar to binned histograms in general. Except a google search would yield in methods related to plotting coverage of transcripts or reads acquired from sequencing experiments [keywords: coverage plots, bedfiles, metaplots]. The key difference here is that I'm interested in scaled coverage over whole gene body (TSS-TES) instead of positions relative to TSS - similar to deeptools plotProfile.  

---

## 2 answers

### Answer by username_2 on 2019-01-30. Score: 3 | Accepted answer

If one assumes that repeat elements of a given type (e.g., LINEs) don't overlap each other, then the following will work:

1. Split your BED file by repeat element, such that you have a LINE.bed, SINE.bed, etc.
2. Convert those to bedGraph (e.g., `awk 'BEGIN{OFS="\t"}{print $1,$2,$3,"1.0"}' LINE.bed > LINE.bedGraph`).
3. Use UCSC tools to convert those bedGraph files to BigWig.
4. Install deepTools and run `computeMatrix reference-point -b 2500 -a 20 -S LINE.bigWig SINE.bigWig LTR.bigWig -R Regions_Of_Interest.BED -o foo.mat.gz`
5. Make a profile plot with plotProfile (`plotProfile -m foo.mat.gz -o foo.png --perGroup`)

If you do have overlapping regions you'll need to first make a disjoint set of intervals (you can use bedops for this), find the coverage of them (e.g., `bedtools coverage`) and then continue on with that.

> **Comments:**
> **username_0**: I still have to try it, but this might just work. I will mark it as answer unless something goes wrong. I would use `scale-regions` instead of `reference-point` since I'm interested in the whole region length.  

---

### Answer by username_3 on 2019-01-29. Score: 0

There is a reasonably nice looking tutorial on metaplots in R here: <https://rpubs.com/achitsaz/94710>

> **Comments:**
> **username_1**: Thanks for answering this, usually we'd like to have the answer self-contained. Perhaps you could improve the question by including the relevant packages/code from that website into your answer.  

---

