Question: GRanges get hits from (only) antisense strand with findOverlaps().
0
gravatar for svenbioinf
3.3 years ago by
svenbioinf0
svenbioinf0 wrote:

Hello guys,

Given a GRanges object with 3 ranges on the "+" strand and 2 on the "-" strand:

gr1 <- GRanges(c(1,1,1,1,1),strand=Rle(c("+","+","+","-","-"),c(1,1,1,1,1)), IRanges(c(1,2,10,1,1), c(8,7,15,5,5)),mcols=data.frame(id=c("T1","T3","T5","T6","T7")))

> gr1
GRanges object with 5 ranges and 1 metadata column:
      seqnames    ranges strand | mcols.id
         <Rle> <IRanges>  <Rle> | <factor>
  [1]        1  [ 1,  8]      + |       T1
  [2]        1  [ 2,  7]      + |       T3
  [3]        1  [10, 15]      + |       T5
  [4]        1  [ 1,  5]      - |       T6
  [5]        1  [ 1,  5]      - |       T7

I would like to get all hits on the antisense strand for each range. That means for all ranges on the "+" strand hits from the "-" and for all ranges on "-" the "+" hits.
NO hits on the same strand! FindOverlaps() (like below) gives me all hits from everywhere. How can I change this?

> hitsI=findOverlaps(gr1,drop.self=T,ignore.strand=T) #ignore.strand=T
> hitsI

> hitsI=findOverlaps(gr1,drop.self=T,ignore.strand=T) #ignore.strand=T
> hitsI
SelfHits object with 12 hits and 0 metadata columns:
       queryHits subjectHits
       <integer>   <integer>
   [1]         1           4
   [2]         1           5
   [3]         1           2
   [4]         2           1
   [5]         2           4
   ...       ...         ...
   [8]         4           5
   [9]         4           2
  [10]         5           1
  [11]         5           4
  [12]         5           2

 

What i would like to have:

queryHits subjectHits
       <integer>   <integer>
   [1]         1           4
   [2]         1           5
  
   [5]         2           4
   ...       ...         ...
 
   [9]         4           2
  [10]         5           1

  [12]         5           2

 

Any help would be greatly appreciated!

ADD COMMENTlink modified 3.3 years ago by li lilingdu450 • written 3.3 years ago by svenbioinf0
Answer: GRanges get hits from (only) antisense strand with findOverlaps().
2
gravatar for li lilingdu
3.3 years ago by
li lilingdu450
li lilingdu450 wrote:
gr1 <- GRanges(c(1,1,1,1,1),strand=Rle(c("+","+","+","-","-"),c(1,1,1,1,1)), IRanges(c(1,2,10,1,1), c(8,7,15,5,5)),mcols=data.frame(id=c("T1","T3","T5","T6","T7"))) 

hitsI=findOverlaps(gr1,drop.self=T,ignore.strand=T)

 

##just filter

hitsI[strand(gr1[from(hitsI)])!=strand(gr1[to(hitsI)]),]

 

 

 

 

 

 

ADD COMMENTlink modified 3.3 years ago • written 3.3 years ago by li lilingdu450

This is so good! Nice and simple. Thanks a lot, Li Lilingdu!

ADD REPLYlink written 3.3 years ago by svenbioinf0
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: 342 users visited in the last hour