Extract exact match from bed files
2
0
Entering edit mode
4.3 years ago

I would like to extract only regions which exactly match another bed

So I have a regions of interest bed which defines regions, I want to extract only exact matches to these regions

cat regions_of_interest.bed
chr8    79611214    79636802    annotated   0   -
chr8    79611214    79616823    abnormal    0   -

Trying with bedops extracts the regions which also have overlap with these regions

bedops -e 1 target.sorted.bed regions_of_interest.bed

Returns

chr8    79611214    79613670    target.sorted.bed   3   +
chr8    79611214    79613823    target.sorted.bed   178 +
chr8    79611214    79615702    target.sorted.bed   3   +
chr8    79611214    79616054    target.sorted.bed   6   +

Bedtools intersect also returns any overlap

bedtools intersect -a target.sorted.bed -b regions_of_interest.bed

chr8    79611214    79613670    target.sorted.bed   3   +
chr8    79611214    79613670    target.sorted.bed   3   +
chr8    79611214    79613823    target.sorted.bed   178 +
chr8    79611214    79613823    target.sorted.bed   178 +
chr8    79611214    79615702    target.sorted.bed   3   +
chr8    79611214    79615702    target.sorted.bed   3   +
chr8    79611214    79616054    target.sorted.bed   6   +
chr8    79611214    79616054    target.sorted.bed   6   +

Ideally the function would work like this

differenttool intersect -a target.sorted.bed -b regions_of_interest.bed

chr8    79611214    79613823    target.sorted.bed   178 +
chr8    79611214    79636802    target.sorted.bed   2996    +
bedtools bedops bed • 1.6k views
ADD COMMENT
2
Entering edit mode
4.3 years ago

The following uses BEDOPS bedmap:

bedmap --echo --exact --skip-unmapped target.sorted.bed regions_of_interest.bed > answer.bed

The file answer.bed contains elements from target.sorted.bed, whose intervals match exactly with intervals from regions_of_interest.bed.

ADD COMMENT
1
Entering edit mode
4.3 years ago
bedtools intersect -f 1 -wa -r -a target.aggregated.bed -b regions_of_interest.bed
ADD COMMENT

Login before adding your answer.

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