Applications of BEDOPS > bedops

bedops merge peaks function (bedops -m)



I'm quite unfamiliar with bedops and interval operations in general, i was trying out the bedops functions on standard bed files and got confused about the --merge option output.
From the documentation it says: Merge (-m, –merge)

The --merge operation flattens all overlapping and adjoining elements into contiguous regions:
So i was thinking that if I use 2 bed files, all intervals that appear in only one file, that is, have no overlap, would be left out.
However, when i look at the result, i see those non-overlapping intervals as in the original file, and for the overlapping ones, the full extension that covers both, as expected.

I probably missed some description on this, could you comment a bit?
And could you give some ideas on how to get only the overlapping intervals between sets, extended to the full peak range?

Thanks in advance,

For the second of your questions, perhaps try:
bedops -e -1 file1.bed file2.bed > g1
bedops -e -1 file2.bed file1.bed > g2
bedops -m g1 g2 > answer2.bed

It's a good point on the technical wording of how --merge (-m) works.  We will update the documentation.

I accidentally deleted my response. I can't remember what I typed, but I think the following is a bit cleaner (one command instead of two).

Here's a way to get all "overlapping-only" elements with a one-liner:

$ bedops --merge elements.bed \
    | bedmap --count --echo-map --delim '\t' - elements.bed \
    | awk '$1>1' - \
    | cut -f2- - \
    | tr ';' '\n' \
    | sort-bed - \
    > overlapping-only.bed

In addition to doing it all without intermediate files, another nice thing about this approach is that this preserves ID and other fields in elements.bed. I think my previous approach may have stripped this information.

If you want the merged regions from these, just add another bedops --merge step at the end:

$ bedops --merge elements.bed \
    | bedmap --count --echo-map --delim '\t' - elements.bed \
    | awk '$1>1' - \
    | cut -f2- - \
    | tr ';' '\n' \
    | sort-bed - \
    | bedops --merge - \
    > overlapping-only-and-merged.bed

To get the set of elements that do not merge (those that are "disjoint"), you can use either of the above results:

$ bedops --not-element-of -1 elements.bed overlapping-only.bed > disjoint.bed

The description for bedops --merge has been updated in upcoming release, v2p5p0


[0] Message Index

Go to full version