Hi Sigrid,
I have copied my response to your inquiry to the bedtools mailing list in case others have wondered the same thing.
In short, no there is no single command that will do this for _all_ types of BED files. The unionCoverageBed tool can be used to do this for sorted BEDGRAPH files that have non-overlapping intervals. For example, the following illustrates an example if your interval files are non-overlapping (if not, you could first use mergeBed -n on each file):
chr1 1000 1500 10
chr1 2000 2100 20
chr1 900 1600 60
chr1 1700 2050 50
chr1 1980 2070 80
chr1 2090 2100 20
chr1 900 1000 0 60 0
chr1 1000 1500 10 60 0
chr1 1500 1600 0 60 0
chr1 1700 1980 0 50 0
chr1 1980 2000 0 50 80
chr1 2000 2050 20 50 80
chr1 2050 2070 20 0 80
chr1 2070 2090 20 0 0
chr1 2090 2100 20 0 20
Now, I have been thinking about a general solution for multiple BED files with potentially overlapping intervals, but don't yet have a solution I feel is worth sharing. The only other current option in BEDTools is to either create a large piped command such as:
$ intersectBed -a 1.bed -b 2.bed | intersectBed -a - -b 3.bed | intersectBed -a - -b 4.bed {ETC.]
Alternatively, if you use Python, the pybedtools library has a nice approach for this, where the "+" operator is overloaded to do interval intersection:
from pybedtools import BedTool
file1 = BedTool("1.bed")
file2 = BedTool("2.bed")
file3 = BedTool("3.bed")
file4 = BedTool("4.bed")
common_intervals = (file1 + file2 + file3 + file4)
I hope this provides some potential options.
Best,
On Oct 25, 2011, at 1:20 AM, Sigrid Laure ROUAM wrote:
Hello,
I am currently using bedtools and am really satisfied with it. It is a great tool.
I was wondering if it is possible to intersect more than 2 files at a time. For example I would like to know what are the common regions in 70 different file.
Thank you.
Best Regards,
--
Sigrid Rouam, PhD
Post Doctoral Fellow
Computational and Mathematical Biology 4
Genome Institute of Singapore
+65 6808 8195