<p>Feel free to @ me in deepTools questions, since I'm the primary developer.</p>

<p>For a given bin, the count assigned to it is the number of reads overlapping it, regardless of whether they overlap by 1 or 10 bases. So a read overlapping only partially and one overlapping completely are treated the same.</p>

<p>Since your bigWig file is in units of "alignments" (i.e., it's not 1x normalized), the resulting profile will also be in units of "alignments" (i.e., profiles and heatmaps are in whatever units the input files are in).</p>

<p>Upstream/downstream regions and unscaled regions are also 10 base bins. Note that these are then the average of the per-base value, since the bins here may not perfectly correspond to the bins in the bigWig files. The line in the profile plot is indeed the average (by default, you can choose median, max, min, etc.) of the underlying regions for each bin.</p>

<p>Regarding the scaled section in the middle, the the number of genomic bases per bin is changed such that the region will have <code>"length"/(regionBodyLength/binSize)</code> bases each. As above, the per-base value is then averaged (or whatever you specify) to derive the per-bin value. The <code>length</code> here is decreased if you have unscaled regions, since otherwise bases would get counted twice.</p>

CC BY-SA 3.0
2017-06-12T11:45:08.583Z
When you write "the average of the per-base value" you mean that if a region 10 bp bin overlaps with 3 bp from genomic bin `i` (having `m` reads) and 7 bp from genomic bin `i+1` (having `n` reads), then the value for this region bin will be `(3*m + 7*n) / 10`?
bli
CC BY-SA 3.0
2017-06-12T11:46:08.347Z
Correct, the average will be weighted by the amount of overlap exactly as you showed.
Devon Ryan
CC BY-SA 3.0
2017-06-09T17:04:19.710Z
2017-06-09T17:04:19.710Z
Devon Ryan
<p>I start with a sorted and indexed bam file ("mapped.bam") representing the mapping of small reads on a reference genome, and a bed file ("genes.bed") containing the coordinates of a set of features of interest (let's say they are genes), for which I want to compute an average profile using programs from <a href="http://deeptools.readthedocs.io/en/latest/content/list_of_tools.html" rel="noreferrer">deeptools</a>. <strong>I would like to understand the steps involved to be sure of what the vertical axis of the final profile represents.</strong></p>

<h3>First step: making a bigwig file</h3>

<p>I create a bigwig file ("mapped.bw") from the bam file using <code>bamCoverage</code> as follows:</p>

<pre><code>bamCoverage -b mapped.bam -bs 10 -of=bigwig -o mapped.bw
</code></pre>

<p>The help of <code>bamCoverage</code> says:</p>

<blockquote>
  <p>The coverage is calculated as the number of reads per bin, where bins are short consecutive counting windows of a defined size.</p>
</blockquote>

<p>In my case, the bins are 10 bp long. My reads are longer than that.</p>

<p>For a given bin, a given read can:</p>

<ol>
<li><p>completely overlap the bin</p></li>
<li><p>overlap the bin on n bp, n &lt; 10</p></li>
<li><p>not overlap the bin at all</p></li>
</ol>

<p>Please correct me if I'm wrong: My guess it that the read is counted as 1 in cases 1. and 2., and 0 otherwise, and I also suppose that a read can be counted for several successive bins if it is long enough.</p>

<h3>Second step: averaging over genes and plotting</h3>

<p>I compute a "meta profile matrix" ("mapped_on_genes.gz") using <code>computeMatrix scale-regions</code> as follows:</p>

<pre><code>computeMatrix scale-regions \
    -S mapped.bw \
    -R genes.bed \
    --upstream 300 \
    --unscaled5prime 500 \
    --regionBodyLength 2000 \
    --unscaled3prime 500 \
    --downstream 300 \
    -out mapped_on_genes.gz
</code></pre>

<p>(There is a <code>-bs</code> parameter which default value is 10 according to the help of the command.)</p>

<p>I use this to plot a profile using <code>plotProfile</code>:</p>

<pre><code>plotProfile -m mapped_on_genes.gz \
    -out mapped_on_genes_meta_profile.pdf
</code></pre>

<p>I obtain a profile in with values on the y axis. In what units are these values?</p>

<p>My guess is the following:</p>

<p>For the upstream (300 bp) and internal 5-prime (500 bp), since the bin size was the same in <code>bamCoverage</code> and <code>computeMatrix</code>, each point on the x axis probably represents a 10 bp window, and its y coordinate is the average over the regions present in the bed file of the corresponding bins in the bigwig file, so it is an average number of reads overlapping a 10 bp bin.</p>

<p>Same thing at the 3-prime and downstream side.</p>

<p>For the central 100 bp portion, before averaging over regions some shrinking or spreading of the bins must have been performed, I guess by averaging between neighbouring bins. So the final unit is still a <strong>number of reads overlapping a 10 bp bin</strong>.</p>

<p>And if I use larger bins, I should end up with proportionally higher values.</p>

<p><strong>Am I correct?</strong></p>

<hts><deeptools><bigwig>
What unit do I get on the y-axis of a metagene profile plot?
# What unit do I get on the y-axis of a metagene profile plot?

(Asked by: username_0 on 2017-06-09)

I start with a sorted and indexed bam file ("mapped.bam") representing the mapping of small reads on a reference genome, and a bed file ("genes.bed") containing the coordinates of a set of features of interest (let's say they are genes), for which I want to compute an average profile using programs from deeptools. I would like to understand the steps involved to be sure of what the vertical axis of the final profile represents.
First step: making a bigwig file
I create a bigwig file ("mapped.bw") from the bam file using bamCoverage as follows:
bamCoverage -b mapped.bam -bs 10 -of=bigwig -o mapped.bw

The help of bamCoverage says:

The coverage is calculated as the number of reads per bin, where bins are short consecutive counting windows of a defined size.

In my case, the bins are 10 bp long. My reads are longer than that.
For a given bin, a given read can:

completely overlap the bin
overlap the bin on n bp, n < 10
not overlap the bin at all

Please correct me if I'm wrong: My guess it that the read is counted as 1 in cases 1. and 2., and 0 otherwise, and I also suppose that a read can be counted for several successive bins if it is long enough.
Second step: averaging over genes and plotting
I compute a "meta profile matrix" ("mapped_on_genes.gz") using computeMatrix scale-regions as follows:
computeMatrix scale-regions \
    -S mapped.bw \
    -R genes.bed \
    --upstream 300 \
    --unscaled5prime 500 \
    --regionBodyLength 2000 \
    --unscaled3prime 500 \
    --downstream 300 \
    -out mapped_on_genes.gz

(There is a -bs parameter which default value is 10 according to the help of the command.)
I use this to plot a profile using plotProfile:
plotProfile -m mapped_on_genes.gz \
    -out mapped_on_genes_meta_profile.pdf

I obtain a profile in with values on the y axis. In what units are these values?
My guess is the following:
For the upstream (300 bp) and internal 5-prime (500 bp), since the bin size was the same in bamCoverage and computeMatrix, each point on the x axis probably represents a 10 bp window, and its y coordinate is the average over the regions present in the bed file of the corresponding bins in the bigwig file, so it is an average number of reads overlapping a 10 bp bin.
Same thing at the 3-prime and downstream side.
For the central 100 bp portion, before averaging over regions some shrinking or spreading of the bins must have been performed, I guess by averaging between neighbouring bins. So the final unit is still a number of reads overlapping a 10 bp bin.
And if I use larger bins, I should end up with proportionally higher values.
Am I correct?

**Tags:** hts, deeptools, bigwig

---

## 1 answers

### Answer by username_1 on 2017-06-09. Score: 4 | Accepted answer

Feel free to @ me in deepTools questions, since I'm the primary developer.

For a given bin, the count assigned to it is the number of reads overlapping it, regardless of whether they overlap by 1 or 10 bases. So a read overlapping only partially and one overlapping completely are treated the same.

Since your bigWig file is in units of "alignments" (i.e., it's not 1x normalized), the resulting profile will also be in units of "alignments" (i.e., profiles and heatmaps are in whatever units the input files are in).

Upstream/downstream regions and unscaled regions are also 10 base bins. Note that these are then the average of the per-base value, since the bins here may not perfectly correspond to the bins in the bigWig files. The line in the profile plot is indeed the average (by default, you can choose median, max, min, etc.) of the underlying regions for each bin.

Regarding the scaled section in the middle, the the number of genomic bases per bin is changed such that the region will have `"length"/(regionBodyLength/binSize)` bases each. As above, the per-base value is then averaged (or whatever you specify) to derive the per-bin value. The `length` here is decreased if you have unscaled regions, since otherwise bases would get counted twice.

> **Comments:**
> **username_0**: When you write "the average of the per-base value" you mean that if a region 10 bp bin overlaps with 3 bp from genomic bin `i` (having `m` reads) and 7 bp from genomic bin `i+1` (having `n` reads), then the value for this region bin will be `(3*m + 7*n) / 10`?  
> **username_1**: Correct, the average will be weighted by the amount of overlap exactly as you showed.  

---

