How to bin a GRanges to small bins
1
0
Entering edit mode
tangming2005 ▴ 190
@tangming2005-6754
Last seen 5 months ago
United States

Hi there,

Is there a way to bin a GRanges object to small bins?

gr<- GRanges(seqname="chr1", ranges=IRanges(start=c(600,1000),width=1), strand="+")
> gr
GRanges object with 2 ranges and 0 metadata columns:
      seqnames       ranges strand
         <Rle>    <IRanges>  <Rle>
  [1]     chr1 [ 600,  600]      +
  [2]     chr1 [1000, 1000]      +
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

 

I want to extend each point to 200 bp width and bin each interval to 20 * 10bp bin. In the end I want:

seqnames       ranges strand
         <Rle>    <IRanges>  <Rle>
  [1]     chr1 [ 500,  510]      +
  [2]     chr1 [ 510,  520]      +
  [3]     chr1 [ 520,  530]      +

.............

  [11]  chr1 [600, 610]      +

  [12]  chr1 [620, 630]     +

........

[20]  chr1 [690, 700]

  .....

         chr1[1090, 1100] +

 

I can do something like:

start(gr) + seq (-100, 90, length.out=20)

and then reconstruct a GRanges object. I want to know if there is an easier way to do it.

Thanks very much!

Ming

 

 

 

GenomicRanges • 4.2k views
ADD COMMENT
1
Entering edit mode
@michael-lawrence-3846
Last seen 2.4 years ago
United States

Maybe you are looking for the tile() function:

tile(gr + 100, width=10)

 

ADD COMMENT
0
Entering edit mode

Thanks Michael! This saves me a lot!  There are just too many functions I am not aware of...

ADD REPLY
0
Entering edit mode

Yea, it took me like 10 minutes to remember that one. And I wrote it. No chance I would have found it otherwise.

ADD REPLY
0
Entering edit mode

methods(class="GRanges") provides some hints, of which tile is the 117th, so maybe not no chance.

ADD REPLY

Login before adding your answer.

Traffic: 576 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6