Skip to content

Instantly share code, notes, and snippets.

@mikelove
Created August 3, 2023 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikelove/b855d493656438c0de64901d44b3eafc to your computer and use it in GitHub Desktop.
Save mikelove/b855d493656438c0de64901d44b3eafc to your computer and use it in GitHub Desktop.
join_overlap_* but with distance as a metadata column
library(plyranges)
x <- data.frame(seqnames=1,
start=sample(1000,10,FALSE),
width=1, id=1:10) %>%
as_granges()
y <- data.frame(seqnames=1,
start=sample(1000,10,FALSE),
width=1, id=letters[1:10]) %>%
as_granges()
x %>%
join_overlap_inner(y, maxgap=100)
y2 <- y %>%
mutate(y_start = start)
x %>%
join_overlap_inner(y2, maxgap=100) %>%
mutate(distance = abs(start - y_start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment