I have two bed files (let's say B1.bed, B2.bed) to be queried against another file (A.bed).
A.bed
1 1 10
1 30 40
1 80 100
1 110 130
B1.bed
1 1 10 reg1
1 1 10 reg2
1 30 40 reg3
1 30 40 reg4
B2.bed
1 30 40 reg1
1 60 70 reg2
1 80 100 reg3
1 110 130 reg4
I would like to know what would be the way to get an output regions such that the reg1 of B1 and reg1 of B2 both are intersecting a feature in A, and so on for ref2, reg3, reg4.
something like:
if reg of B1 and reg of B2 intersects with A: print
I could use the pybedtools:
https://gist.github.com/gouthamatla/c5a7b9f33b8cb78ba305
output:
True
False # Because reg2 of B2.bed does not intersect with A.bed
True
True
Here I do not see an option that A.intersect could read data as string, hence I have to convert every interval to a bed file before using it, which might be taking very very long time for the script to run on large data sets.
Is there any other way to do it or to optimize my snippet ? For me its more or less sounds like checking if both the fragments are mapped to same regions, using bedtools
P.S: I don't know how to title this question.
No. the regions are given same identifiers in B1 and B2. Check if the reg1 of B1 and reg1 of B2 overlaps with A. It is not necessary that the reg1 of B1 overlaps with reg1 of B2.
Okay, let's try again - I edited my answer above.