2
$\begingroup$

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 ?

$\endgroup$

3 Answers 3

3
$\begingroup$
  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.

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

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

$\endgroup$
0
$\begingroup$

To merge multiple BED files into one, you need to do the following:

  • concatenate them all (bedtools merge only accepts one input BED)
  • sort the concatenated BED
  • merge the sorted BED with bedtools merge

Here is a simple pipeline to do this

cat a.bed b.bed | sort -k 1,1 -k2,2n | bedtools merge > merged.bed
$\endgroup$

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.