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