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 ?
Bioinformatics Stack Exchange is a question and answer site for researchers, developers, students, teachers, and end users interested in bioinformatics. It only takes a minute to sign up.
Sign up to join this communityIn my opinion, the easiest way to merge bed files is to use bedtools merge
.
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.