How Can I Include One Bed File In Another Bed File ?
3
0
Entering edit mode
11.3 years ago
fmfshog • 0

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

bedtools merge • 7.2k views
ADD COMMENT
1
Entering edit mode
ADD REPLY
4
Entering edit mode
11.3 years ago
Vikas Bansal ★ 2.4k

You can use -

cat A.bed B.bed > AB.bed

mergeBed -i AB.bed
ADD COMMENT
2
Entering edit mode

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.

ADD REPLY
0
Entering edit mode
ADD REPLY
3
Entering edit mode
11.3 years ago
sjneph ▴ 690

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.

ADD COMMENT
0
Entering edit mode
11.3 years ago

This is classic file-handling, no need to look for a BedTools command, this is enough:

cat A.bed B.bed > C.bed

If your bed files have headers, you can remove them with sed '1d' X.bed.

ADD COMMENT
0
Entering edit mode

but how will it deal with the overlapping sequences?

ADD REPLY
2
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

I assumed you wanted to preserve all features as originally, but you can merge them with mergeBed as suggested if that's your goal.

ADD REPLY

Login before adding your answer.

Traffic: 1794 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6