Question: How Can I Include One Bed File In Another Bed File ?
0
gravatar for fmfshog
6.2 years ago by
fmfshog0
fmfshog0 wrote:

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 • 2.8k views
ADD COMMENTlink modified 6.2 years ago by sjneph600 • written 6.2 years ago by fmfshog0
1

did you try mergeBed ? http://code.google.com/p/bedtools/wiki/Usage#mergeBed

ADD REPLYlink written 6.2 years ago by Pierre Lindenbaum123k
4
gravatar for Vikas Bansal
6.2 years ago by
Vikas Bansal2.3k
Berlin, Germany
Vikas Bansal2.3k wrote:

You can use -

cat A.bed B.bed > AB.bed

mergeBed -i AB.bed
ADD COMMENTlink written 6.2 years ago by Vikas Bansal2.3k
2

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 REPLYlink written 6.2 years ago by Matt LaFave280

Yes you are right. For new version, we have to sort the file before merging.

ADD REPLYlink written 6.2 years ago by Vikas Bansal2.3k
1
gravatar for sjneph
6.2 years ago by
sjneph600
sjneph600 wrote:

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 COMMENTlink written 6.2 years ago by sjneph600
0
gravatar for André Rendeiro
6.2 years ago by
Vienna, Austria
André Rendeiro50 wrote:

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 COMMENTlink written 6.2 years ago by André Rendeiro50

but how will it deal with the overlapping sequences?

ADD REPLYlink written 6.2 years ago by fmfshog0
2

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 REPLYlink written 6.2 years ago by Devon Ryan92k

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 REPLYlink written 6.2 years ago by André Rendeiro50
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 705 users visited in the last hour