mergeBed will do the trick, but bear in mind that it requires that the input file be sorted by chromosome, then by start position. Since AB.bed probably won't be like that by default, try cat A.bed B.bed | sort -k1,1 -k2,2n | mergeBed > AB.bed instead.
Hello, I have 2 bedfiles that share some common features let's call the first file A.bed (bigger file) and the second B.bed (smaller file). I would like to have a new bed file that includes everything in B.bed in the A.bed file. I don't need the intersect, I more like need the merge option I checked bedtools's manual... couldn't find an answer for merging 2 bedfiles. Can someone help?
Thanks in advance
3 answers
You can use -
cat A.bed B.bed > AB.bed
mergeBed -i AB.bed
Yes you are right. For new version, we have to sort the file before merging.
use
bedops --merge a.bed b.bed > merged.bed
the requirements are that both bed files are sorted, which is easy and smart to do, as it makes all downstream analyses more efficient. The output is already sorted, so you only need to do this once for initial, unsorted files.
sort-bed A.bed > a.bed && sort-bed B.bed > b.bed
the suite offers the fastest execution times and least memory overhead. You can use any number of any size inputs at once.
but how will it deal with the overlapping sequences?
It won't, it just concatenates the files (i.e., it copies one onto the end of the other). You may want mergeBed, as suggested above, instead, depending on what you mean by merge.
I assumed you wanted to preserve all features as originally, but you can merge them with mergeBed as suggested if that's your goal.
Log in to answer this question.
did you try mergeBed ? http://code.google.com/p/bedtools/wiki/Usage#mergeBed