This is a test version of Biostars. For the public version, visit https://www.biostars.org.
merge overlaps and remove non overlap genomic windows

hi everyone

I have two bed files, How can I create a file from the two mentioned files that merges the overlaps and deletes the rest of the windows

for example

A.bed
Ch1 200 250
Ch1 260 300
Ch1 310 400
Ch1 480 500

B
Ch1 150 220
Ch1 311 420
Ch1 501 600
Ch1 601 650

desired output
Ch1 150 250
Ch1 310 420
Ch1 480 600
bed intersection overlap

1 answer

have two bed files

these are not bed files. A chromosome is missing in chromosome 1

How can I create a file from the two mentioned files that merges the overlaps and deletes the rest of the windows

once there is a chromosome, use 'bedtools intersect -v'

-v  Only report those entries in A that have _no overlaps_ with B.
    - Similar to "grep -v" (an homage).

sorry i edited my example. But your answer is exactly the opposite of what I want

But your answer is exactly the opposite of what I want

oh I see. but i don't understand the logic why:

"Ch1 200 250" and "Ch1 150 220" would return "Ch1 150 250" ?

Overlap of "Ch1 200 250" and "Ch1 150 220" is "Ch1 200 220", but I want to combine windows that have overlap. Thus, my goal is to combine these two windows and create "Ch1 150 250". I'm also going to skip windows that don't have overlaps.

English is not my native language and I may not be able to explain myself properly

Log in to answer this question.