Question: How to bin a GRanges to small bins
0
gravatar for tangming2005
3.8 years ago by
tangming2005150
United States
tangming2005150 wrote:

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 • 2.0k views
ADD COMMENTlink modified 3.8 years ago by Michael Lawrence11k • written 3.8 years ago by tangming2005150
Answer: How to bin a GRanges to small bins
1
gravatar for Michael Lawrence
3.8 years ago by
United States
Michael Lawrence11k wrote:

Maybe you are looking for the tile() function:

tile(gr + 100, width=10)

 

ADD COMMENTlink written 3.8 years ago by Michael Lawrence11k

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

ADD REPLYlink written 3.8 years ago by tangming2005150

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

ADD REPLYlink written 3.8 years ago by Michael Lawrence11k

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

ADD REPLYlink written 3.8 years ago by Martin Morgan ♦♦ 24k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 341 users visited in the last hour