Question: Using findOverlaps to find only partial overlaps
0
gravatar for d r
4.3 years ago by
d r150
Israel
d r150 wrote:

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

genomicranges findoverlaps • 633 views
ADD COMMENTlink modified 4.3 years ago by Michael Lawrence11k • written 4.3 years ago by d r150
Answer: Using findOverlaps to find only partial overlaps
1
gravatar for Michael Lawrence
4.3 years ago by
United States
Michael Lawrence11k wrote:

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 COMMENTlink written 4.3 years ago by Michael Lawrence11k
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: 249 users visited in the last hour