Question: how does coverage() works
0
gravatar for likeeatingpizza
3.5 years ago by
likeeatingpizza0 wrote:

I'm learning Bioconductor but can't seem to understand how Biostrings::coverage() works.

During the class I was taught that coverage "counts, for each integer, how many ranges overlap the integer.".

Another definition I found in the documentation of the IRanges package (coverage methods) is "For each position in the space underlying a set of ranges, counts the number of ranges that cover it."

So if I have the following IRanges
> ir <- IRanges(start = c(2,6), width = 2)

and compute the coverage
> coverage(ir)

I would expect to get back an Rle where as Values I have all the integer that a covered by the IRanges (meaning 2 3 6 7) and as Lengths I have the number of times those integer are "covered" by the ranges in the IRanges. In this example this would mean

integer-Rle of length 4 with 4 runs
  Lengths: 1 1 1 1
  Values : 2 3 6 7

Except that the returned Rle is something entirely different:

> coverage(ir)
integer-Rle of length 7 with 4 runs

  Lengths: 1 2 2 2
  Values : 0 1 0 1

> as.numeric(coverage(ir))
[1] 0 1 1 0 0 1 1

Can someone explain me why are there 0s an 1s as Values when neither of this two integer is actually part of the input IRanges? And why do they repeat? I simply can't understand how this Rle is representing the inputted IRanges...

coverage biostrings iranges rle • 604 views
ADD COMMENTlink modified 3.5 years ago • written 3.5 years ago by likeeatingpizza0

 Now I get it, it's not about counting the number of times each integer is covered in the IRanges, but the number of IRanges that cover each integer. Now it makes sense, thank you both

ADD REPLYlink written 3.5 years ago by likeeatingpizza0
Answer: how does coverage() works
4
gravatar for Martin Morgan
3.5 years ago by
Martin Morgan ♦♦ 24k
United States
Martin Morgan ♦♦ 24k wrote:

It's like eating pizza. Take a pizza and cut it into seven pieces. Arrange the pieces in a row, and place the numbers 1 through 7 over pieces 1 through 7.

Position          1 2 3 4 5 6 7
How many pieces?  1 1 1 1 1 1 1

Now eat pieces 1, 4 and 5. Create a vector that counts the number of pieces of pizza over number 1, 2, 3, 4, 5, 6, and 7.

Position          1 2 3 4 5 6 7
How many pieces?  0 1 1 0 0 1 1

 If I've done my eating right, I've got 0, 1, 1, 0, 0, 1, and 1 pieces of pizza covering the numbers 1 through 7, respectively. I could summarize that vector as

Length: 1 2 2 2
Value:  0 1 0 1

Which is to say there was 1 position with 0 pieces of pizza, then 2 positions each with 1 piece of pizza, followed by 2 positions with 0 pieces of pizza, and finally 2 positions each with 1 piece of pizza.

Hope that helps. Time for dinner!

ADD COMMENTlink modified 3.5 years ago • written 3.5 years ago by Martin Morgan ♦♦ 24k
Answer: how does coverage() works
2
gravatar for Michael Lawrence
3.5 years ago by
United States
Michael Lawrence11k wrote:

If you have an Rle cov then cov[i] represents the number of ranges overlapping position i. The Rle is a run-length encoding, which is equivalent to the integer vector generated by rep(runValue(cov), runLength(cov))

ADD COMMENTlink written 3.5 years ago by Michael Lawrence11k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 182 users visited in the last hour