Keep original range by using flank() on a GRanges object.
1
0
Entering edit mode
svenbioinf • 0
@svenbioinf-11239
Last seen 2.1 years ago
Münster

Is there an easy way to obtain the flank range and the flanked range in one GRanges object after calling flank()?

See the following example:

> gr1 <- GRanges(c(1,1),strand=Rle(c("+","-"),c(1,1)), IRanges(c(30,120), c(70,170)),mcols=data.frame(id=c("T1","T3")))
> gr1
GRanges object with 2 ranges and 1 metadata column:
      seqnames     ranges strand | mcols.id
         <Rle>  <IRanges>  <Rle> | <factor>
  [1]        1 [ 30,  70]      + |       T1
  [2]        1 [120, 170]      - |       T3
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
flank(gr1, 10) 

> flank(gr1, 10)
GRanges object with 2 ranges and 1 metadata column:
      seqnames     ranges strand | mcols.id
         <Rle>  <IRanges>  <Rle> | <factor>
  [1]        1 [ 20,  29]      + |       T1
  [2]        1 [171, 180]      - |       T3
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

What I would like to get is:

> gr1
GRanges object with 2 ranges and 1 metadata column:
      seqnames     ranges strand | mcols.id
         <Rle>  <IRanges>  <Rle> | <factor>
  [1]        1 [ 20,  70]      + |       T1
  [2]        1 [120, 180]      - |       T3
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

Any hint on this is greatly appreciated!

 

granges flank • 1.5k views
ADD COMMENT
3
Entering edit mode
@valerie-obenchain-4275
Last seen 2.3 years ago
United States

Try resize():

> resize(gr1, width=width(gr1) + 10, fix="end")
GRanges object with 2 ranges and 1 metadata column:
      seqnames     ranges strand | mcols.id
         <Rle>  <IRanges>  <Rle> | <factor>
  [1]        1 [ 20,  70]      + |       T1
  [2]        1 [120, 180]      - |       T3
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

Valerie

ADD COMMENT
0
Entering edit mode

Thank you so much Valerie, that is quite smart (-:

ADD REPLY

Login before adding your answer.

Traffic: 836 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