I am trying to merge two bed files (more in future) to one. my bed files are something like : result of macs pea calling.

I need to merge them in a way to have the shared chromosome location.

Is there a way to do that ?


2 Answers 2


In my opinion, the easiest way to merge bed files is to use bedtools merge.

  1. Convert each of your Excel spreadsheets to tab-delimited text files (how-to).
  2. Install and run Cygwin, if using Windows. If you are using OS X, open up the Terminal app.
  3. Install the BEDOPS toolkit to get sorting and set operation tools (if you're not averse to using them).
  4. Strip out the Microsoft line endings, strip the header, and sort each of the N files:

    $ tr -d '\r' < fileN.tsv | tail -n+2 - | sort-bed - > fileN.bed
  5. Merge the files:

    $ bedops --merge file1.bed file2.bed ... fileN.bed > answer.bed

The file answer.bed will contain all merged regions from files file1.bed through fileN.bed. Merging will be done on intervals for each unique chromosome name.

  • 1
    $\begingroup$ Thanks that worked $\endgroup$
    – Mariam
    Commented Apr 4, 2020 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.