BEDOPS bedmap
is an option, e.g.:
$ bedmap --echo --echo-map reference.bed map.bed > answer.bed
The file answer.bed
will contain all elements from reference.bed
on each line, with any elements from map.bed
that overlap elements from reference.bed
.
You can add options to change delimiters or overlap criteria, as well as apply signal or ID mapping operations, etc.
The BEDOPS documentation has more detail:
http://bedops.readthedocs.io/en/latest/content/reference/statistics/bedmap.html
Note: Someone has suggested using bedops --intersect
. This answer is not correct, as --intersect
calculates new genomic regions where there are overlaps in the genomic intervals in two or more sets, i.e. an intersection.
If you want to map or find associations between two sets, use bedmap
to retrieve those associations (or use bedops --element-of
, if you do not need to preserve per-element associations, but simply want to see what elements in one set overlap those in another set).
Take a look at bedtools intersect. Equivalent option in BEDOPS.