Hi, I previously asked about summing RLEs but I'm now curious about extending the concept to summing lists of RLEs of arbitrary lengths. It seems fairly simple but I haven't seen a way to do it outside of loops.

Given something like...

$uc001aaa.3 numeric-Rle of length 249250621 with 5 runs Lengths: 14101 25 219 30 249236246 Values : 0 1 0 1 0 $uc001aac.4 numeric-Rle of length 249250621 with 124 runs Lengths: 14345 30 ... 25 249221232 Values : 0 0.909090909090909 ... 0.909090909090909 0 $uc001aae.4 numeric-Rle of length 249250621 with 29 runs Lengths: 14345 30 1163 13 ... 489 25 249231381 Values : 0 1 0 1 ... 0 1 0

I know you can sum RLEs through result<-c(RLE1,RLE2) ie

integer-Rle of length 249250621 with 69798 runs Lengths: 20000646 25 2330 25 ... 2121 25 199255312 Values : 0 1 0 1 ... 0 1 0 integer-Rle of length 249250621 with 69798 runs Lengths: 20000646 25 2330 25 ... 2121 25 199255312 Values : 0 1 0 1 ... 0 1 0

=

integer-Rle of length 249250621 with 69798 runs Lengths: 20000646 25 2330 25 ... 2121 25 199255312 Values : 0 2 0 2 ... 0 2 0

but I need to do it automatically with an arbitrary length list. Somehow being in a list form seems to prevent operations that would normally work.

reduce('+',RLElist) sum(RLElist)

don't work, and I can't even sum elements of the list as I could RLEs that are not in a list.

thanks

Hi, yeah I want to get a big RLE not a single value. the second option unfortunately seems to give integer overflow errors.

`rror in unlist(RleList(ExampleRLElist)) : error in evaluating the argument 'x' in selecting a method for function 'unlist': Error in .Call2("Rle_constructor", values, lengths, check, 0L, PACKAGE = "S4Vectors") : integer overflow while summing elements in 'lengths'`

What do you think could be a solution? maybe something like runmean?

Integer overflow means you will need to convert to numeric (i.e. floating point) because your sum is larger than the maximum representable integer. Note that you might lose some precision in the result.

Hi, somewhat of a tangent, but if you wanted to shift a numeric RLE unchanged to a certain position or by a certain amount how could you do it?

The closest I can find is shiftApply which I believe lines two RLEs together? But it doesn't seem to work on an RLE in isolation.

Please ask this as a new question. Also make sure to explain what you mean by

shiftinga numeric Rle. What does it mean for example to shift an ordinary numeric vector? Do you mean padding with zeroes? Again, if you know how to do it on an ordinary numeric vector, then you know how to do it on a numeric Rle. For example, padding with 100 zeroes on the left:H.

The length of an Rle object cannot exceed 2^31-1. Unlisting your RleList object would result in an Rle object that exceeds that limit, hence the error. (The error message doesn't help, we should improve it.) Note that this limit is not just for Rle objects but for any vector-like or list-like object that derives from the Vector or List class (e.g. Hits, CharacterList, GRanges, GRangesList, GAlignments, etc...)

H.