I have a GRanges object and I would like to extend all ranges eg 1kb on both sides, so each range will become 2kb longer. It is strange but I couldn't manage to do this using the inter-range-methods
of GenomicRanges or IRanges. One way that would produce the desired result is to use resize twice, to first extend the 5' and then the 3'. But this of course is extremely awkward. Isn't there a more direct way of doing this? Please advice
gr <- GRanges(c('chr1','chr1'), IRanges(start=c(20, 120), width=10), strand='+')
gr <- resize(gr, fix='start', width=width(gr)+10)
gr <- resize(gr, fix='end', width=width(gr)+10)
gr
GRanges supports operators such as - and +
gr + 10
will do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With