This is a test version of Biostars. For the public version, visit https://www.biostars.org.
obtain non-overlapping regions within the file

Hi

I have a file like this

chr1 1 100
chr1 1 50
chr1 55 70
chr1 75 100
chr1 101 200

I want to obtain all non-overlapping regions into separate file. So my output will look like this

chr1 1 100
chr1 101 200

Is there any way to do this please let me know

non-overlapping bedtools

This was already answered here

2 answers

With BEDOPS bedops and sort-bed:

$ sort-bed input.bed | bedops --merge - > answer.bed

Sorting is required to deal with matches in the second (start position) column. Make sure your input BED file is tab-delimited.

...Since you tag bedtools, this should do:

sort -k1,1 -k2,2n in.bed | mergeBed > merged.bed

Log in to answer this question.