Skip to content
Prev 14667 / 21307 Next

[Bioc-devel] Merging GInteraction/GenomicInteractions ranges

Hi Luke,

If I understand correctly what you want to do, you can use `findOverlaps()`
to create a new GInteractions object from a set of expanded ranges and the
original interactions.

anchor.one <- GRanges(c("chr1", "chr1", "chr1", "chr1"),
                     IRanges(c(10, 20, 30, 20), width=5))
anchor.two <- GRanges(c("chr1", "chr1", "chr1", "chr2"),
                     IRanges(c(100, 200, 200, 50), width=5))
interaction_counts <- sample(1:10, 4)
test <- GInteractions(anchor1 = anchor.one,
                      anchor2 = anchor.two,
                      counts=interaction_counts)

wider_ranges <- reduce(resize(regions(test), fix = "center", width = 10))

first_ol <- findOverlaps(test, wider_ranges, use.region = "first")
second_ol <- findOverlaps(test, wider_ranges, use.region = "second")

new_gi <- GInteractions(anchor1 = subjectHits(first_ol),
                        anchor2 = subjectHits(second_ol),
                        regions = wider_ranges,
                        counts = test$counts)

This will give you a GInteractions object that's the same length as your
original object. You said you already had a way of summing the counts for
each group of interactions, but you could also incorporate that here. I
would do it with dplyr, but I'm sure there's alternatives that introduce
fewer dependencies...

new_gi_info_df <- data.frame(anchor1 = subjectHits(first_ol),
                             anchor2 = subjectHits(second_ol),
                             counts = test$counts) %>%
  dplyr::group_by(anchor1, anchor2) %>%
  dplyr::summarise(counts = sum(counts))

best wishes,
Liz
On Tue, Feb 19, 2019 at 6:15 PM Luke Klein <lklei001 at ucr.edu> wrote: