Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend range in both directions

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
like image 281
Ludo Avatar asked Dec 09 '22 00:12

Ludo


1 Answers

GRanges supports operators such as - and +

gr + 10 

will do the trick.

like image 62
crazyhottommy Avatar answered Dec 10 '22 14:12

crazyhottommy