For example I have 3 bed files:
window.bed:
chr1 0 1000
chr1 1000 2000
lp1.bed:
chr1 20 50
chr1 30 40
chr1 1500 1900
lp2.bed:
chr1 68 786
chr1 899 987
How can I create this output:
chr1 0 1000 2 2
chr1 1000 2000 1 0
In this output columns 1, 2, 3 are the standard bed format cols, of the chromosome, start, and end of the features taken from window.bed above. Column 4 is the number of intersections between window.bed and lp1.bed per feature in window.bed. For example, the first element in column 4 is '2' because there are two intersections between window.bed and lp1.bed. Column 5 is the same but for the number of intersections between window.bed and lp2.bed for each feature in window.bed.
In the case that a feature is a subset of another feature in either lp1.bed, or lp2.bed, they should be counted as two intersections. For example, the second feature of lp1.bed is a subset of the first feature. This is reflected in the first element of column 4 of the output.
I suspect that it is doable with bedtools intersect, but I cannot work out the syntax.