# NOT RUN {
library(dplyr)
x1 <- tibble(id1 = 1:4,
chromosome = c("chr1", "chr1", "chr2", "chr2"),
start = c(100, 200, 300, 400),
end = c(150, 250, 350, 450))
x2 <- tibble(id2 = 1:4,
chromosome = c("chr1", "chr2", "chr2", "chr1"),
start = c(140, 210, 400, 300),
end = c(160, 240, 415, 320))
if (requireNamespace("IRanges", quietly = TRUE)) {
# note that the the third and fourth items don't join (even though
# 300-350 and 300-320 overlap) since the chromosomes are different:
genome_inner_join(x1, x2, by = c("chromosome", "start", "end"))
# other functions:
genome_full_join(x1, x2, by = c("chromosome", "start", "end"))
genome_left_join(x1, x2, by = c("chromosome", "start", "end"))
genome_right_join(x1, x2, by = c("chromosome", "start", "end"))
genome_semi_join(x1, x2, by = c("chromosome", "start", "end"))
genome_anti_join(x1, x2, by = c("chromosome", "start", "end"))
}
# }
Run the code above in your browser using DataLab