I am trying to merge two bed files (more in future) to one. my bed files are something like : .
I need to merge them in a way to have the shared chromosome location.
Is there a way to do that ?
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
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.
In my opinion, the easiest way to merge bed files is to use bedtools merge
.
To merge multiple BED files into one, you need to do the following:
bedtools merge
only accepts one input BED)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