LTLA / InteractionSet

Clone of the Bioconductor repository for the InteractionSet package, see https://bioconductor.org/packages/devel/bioc/html/InteractionSet.html for the official development version.
2 stars 0 forks source link

GInteraction object anchor1 and anchor2 overlap with a set of regions #3

Closed gtrichard closed 6 years ago

gtrichard commented 6 years ago

Dear InteractionSet developers,

I recently started to use InteractionSet and it is an awesome R package, many thanks for the hard work.

I have one, perhaps naive, question about the overlap methods since I did not find such a case in the documentation of InteractionSet.

Given a GInteraction object gi and a GRanges object regions, I would like to only keep the gi anchors1 and anchors2 that overlap with the regions.

As I understood, when using subsetByOverlaps(gi, regions), I will get the anchors1 overlapping with regions (with whatever anchors2) and the anchors2 overlapping with regions (with whatever anchors1), but not the exclusive cases where anchors1 AND anchors2 are both overlapping with regions, and this is what I am trying to achieve.

I tried

subset1<-subsetByOverlaps(gi, regions, regions="first")
subset2<-subsetByOverlaps(gi, regions, regions="second")
final<-subsetByOverlaps(subset1, subset2)

But I don't get why there is a difference between:

final1<-subsetByOverlaps(subset1, subset2)
final2<-subsetByOverlaps(subset2, subset1)

And I'm not sure this is the right way to achieve what I want.

Do you have any suggestion to achieve it?

Many thanks, Gautier

LTLA commented 6 years ago

If you want to find overlaps to the same region, do:

dummy <- GInteractions(seq_along(regions), seq_along(regions), regions)
final <- subsetByOverlaps(gi, dummy)

If you want to find overlaps between gi and any two elements of regions, use linkOverlaps.

Your proposed approach uses regions=, which doesn't correspond to any argument that I recall. The closest is use.region=.

gtrichard commented 6 years ago

dummy <- GInteractions(seq_along(regions), seq_along(regions), regions) final <- subsetByOverlaps(gi, dummy)

Did the trick it seems, thank you very much @LTLA for the quick and precise answer!

For regions=, yes I got it wrong while typing my question here, I meant use.region= as you suggested.