Can bedtools subtract support multiple files?
1
0
Entering edit mode
5.1 years ago
msimmer92 ▴ 300

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 • 2.8k views
ADD COMMENT
2
Entering edit mode
5.1 years ago
h.mon 35k

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 COMMENT
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 2633 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