Question: Can bedtools subtract support multiple files?
gravatar for msimmer92
9 weeks ago by
msimmer92180 wrote:

I have four BED files with data from different conditions (let's say A B C and D). I want to make a file (using bedtools subtract) that have those regions specific to A. Since bedtools subtract works pairwise, I should do (manual example):

bedtools subtract -a A.bed –b B.bed > temp1.bed 
bedtools subtract -a temp1.bed –b C.bed > temp2.bed
bedtools subtract -a temp2.bed –b D.bed > only_A.bed

By any chance bedtools has a way of doing it for multiple files? such as

bedtools subtract -a A.bed –b B.bed C.bed D.bed > only_A.bed

On its manual entry is not very clear, but they have done it for other tools such as intersect. Thank you !

bedtools • 146 views
ADD COMMENTlink modified 9 weeks ago • written 9 weeks ago by msimmer92180
gravatar for h.mon
9 weeks ago by
h.mon25k wrote:

To avoid intermediary files, you can chain the commands with pipes:

bedtools subtract -a A.bed -b B.bed \
  | bedtools subtract -a stdin -b C.bed \
  | bedtools subtract -a stdin -b D.bed > only_A.bed

Two notes:

1) I believe you meant bedtools subtract -a temp2.bed –b D.bed > only_A.bed at you third command, correct?

2) be careful with hyphens (used to indicate command-line parameters) and paragraph marks. Your command-lines above correctly use hyphens for -a, but incorrectly use paragraph dash for –b.

edit: I don't know if bedtools subtract -b accepts multiple files (I think it doesn't), but you can easily check for yourself: just try it and compare the results with the output of the multiple commands with intermediary files.

ADD COMMENTlink modified 9 weeks ago • written 9 weeks ago by h.mon25k

Thank you for your answer! Yes, I had a typo in temp2.bed, I just edited it. The hyphen and paragraph dash thing might be because I wrote this on a Word document where I keep record of what I do and then copied from there and pasted it here.. sometimes when you copy and paste stuff to programs such as Word some of these things change automatically, but I use hyphens for the parameters. I did not notice they appeared different when I posted this.. And yes, I can try it myself but I figured to write here in case there's someone that did it before and has some important observations about it. I will do it now.

ADD REPLYlink written 9 weeks ago by msimmer92180
Please log in to add an answer.


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