summing integer RLE
1
0
Entering edit mode
gen ▴ 30
@gen-7383
Last seen 8.9 years ago
United States

Hi,

Say you have something like this RleListexample

RleList of length 4
$seq1 integer-Rle of length 1575 with 42 runs Lengths: 982 1 1 2 3 2 2 1 1 1 ... 1 1 1 2 1 1 3 1 531 Values : 0 2 3 6 8 10 12 13 15 17 ... 12 11 10 8 7 5 4 2 0$seq2
integer-Rle of length 1584 with 1 run
Lengths: 1584
Values :    0

$seq1 integer-Rle of length 1575 with 42 runs Lengths: 982 1 1 2 3 2 2 1 1 1 ... 1 1 1 2 1 1 3 1 531 Values : 0 2 3 6 8 10 12 13 15 17 ... 12 11 10 8 7 5 4 2 0$seq2
integer-Rle of length 1584 with 1 run
Lengths: 1584
Values :    0

How would you add or average the values of only the seq1 RLEs into one single RLE object?

When I try sum(RleListexample) it collapses everything into one number. When I try RleListexample\$seq1 it doesn't provide me with the two RLEs in the list it just provides me with one.

rle list irange grangeslist • 1.8k views
1
Entering edit mode
Chris Seidel ▴ 80
@chris-seidel-5840
Last seen 2.8 years ago
United States

Your Rle object has the same name for more than one element. Since this doesn't provide specificity, if you want to sum a particular element, you might refer to it specifically (i.e. not by name):

sum(RleListexample[[1]])

Or if you want to sum all the elements named "seq1" you might create a boolean index:

sum(RleListexample[names(RleListexample) == "seq1"])

0
Entering edit mode

Hi, thanks but the answer collapses the RLE into one number. I need to find the average RLE in an RLElist. IE for two sets of coverage data. Combine them into one set and then average it out for mean coverage.

thanks

1
Entering edit mode

Maybe you are looking for something like (RleListexample[1:2] + RleListexample[3:4]) / 2 ? As Chris suggested, it's probably more usual to think of averaging two separate objects

library(GenomicAlignments)
cvg1 = coverage(BamFile("first.bam"))
cvg2 = coverage(BamFile("second.bam"))
avecvg = (cvg1 + cvg2) / 2

0
Entering edit mode

cool it works for individual RLEs. I might need to do something with lists though.