how does coverage() works
2
0
Entering edit mode
@likeeatingpizza-10790
Last seen 7.8 years ago

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...

biostrings coverage rle iranges • 2.3k views
0
Entering edit mode

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

4
Entering edit mode
@martin-morgan-1513
Last seen 16 days ago
United States

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!

2
Entering edit mode
@michael-lawrence-3846
Last seen 2.2 years ago
United States

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))