1

when working with bedtools intersect , there are many options that you could use like setting minimum overlap as percentage of file A or B , or whether to write original A or B entries. I was wondering if there is a package in R that does the same

I would appreciate your answer

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
pegahT
  • 59
  • 1
  • 8
  • http://bioconductor.org/packages/release/bioc/html/GenomicRanges.html .. you have to be more specific about what you wanna do – StupidWolf Nov 27 '20 at 20:44

2 Answers2

1

There is the 'valr' package, that allows you to execute some of the basic bedtools commands in R.

https://rnabioco.github.io/valr/

But I don't think it yet supports the percentage overlap -f option of bedtools unfortunately

You can code it yourself though:

library(tidyverse)
library(valr)
A <- tibble(chrom='chr1', start=100, end=900)
B <- tibble(chrom='chr1', start=700, end=1000) %>% 
       dplyr::mutate(width=end-start)
bed_intersect(A,B) %>% 
       dplyr::mutate(percent_overlap = .overlap / width.y) %>%
       dplyr::filter(percent_overlap >= 0.5
0

The bioconductor package GenomicRanges has a function to find overlaps: findOverlaps() and intersect() and you can set an option minoverlap More info here.

You can also read bedFiles into GRanges using rtracklayer

Jabber1
  • 69
  • 5