I have a Run length encoded vector representing some value at every position on the genome, in order. As a toy example suppose I had just one chromosome of length 10, then I would have a vector looking like
library(GenomicRanges) set.seed(1) toyData = Rle(sample(1:3,10,replace=TRUE))
I would like to coerce this into a GRanges object. The best I can come up with is
gr = GRanges('toyChr',IRanges(start(toyData)-1, width=runLength(toyData)), toyData = runValue(toyData))
which works, but is quite slow. Is there a faster way to construct the same object?