Using findOverlaps to find only partial overlaps
1
0
Entering edit mode
d r ▴ 150
@d-r-5459
Last seen 6.7 years ago
Israel

I have 2 GRanges objects (gr1,gr2). I want to find partial overlaps between them, that is I want to find which ranges in gr2 overlap the i th range in gr1 but are not entirely contained in it (its fine if gr1[i] is entirely contained in some of those gr2 ranges).

I thought I can use findOverlaps once with type='any' and once with type='within',

something along these lines:

overlapsAny<-as.data.frame(findOverlaps(query=gr2,subject=gr1,type='any'))

overlapsFull<-as.data.frame(findOverlaps(query=gr2,subject=gr1,type='within'))

overlapsAny$Combination<-apply(overlapsAny,1,function(row) paste(row$queryHits,row$subjectHits,sep='.'))

overlapsFull$combination<-apply(overlapsFull,1,function(row) paste(row$queryHits,row$subjectHits,sep='.'))

partial<-!(which(overlapsAny$Combination%in%overlapsFull$combination)

Is there a less convoluted way to do this (such as directly intersecting hits objects somehow)?

 

Thanks in adavnce

Dolev Rahat

findoverlaps genomicranges • 1.8k views
ADD COMMENT
1
Entering edit mode
@michael-lawrence-3846
Last seen 3.0 years ago
United States

You should avoid coercing the Hits objects to data.frames, because that discards the semantics and all conveniences gained from them. 

Just do something like:

anyHits <- findOverlaps(gr2, gr1)
withinHits <- findOverlaps(gr2, gr1, type="within")
setdiff(anyHits, withinHits)

These classes exist to make your life easier, not harder. The obvious thing usually works.

 
ADD COMMENT

Login before adding your answer.

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