Author Topic: bedops merge peaks function (bedops -m)  (Read 5560 times)

Bedopsi

  • Newbie
  • *
  • Posts: 1
bedops merge peaks function (bedops -m)
« on: September 04, 2014, 07:45:42 AM »
Hello,

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:
6.1.1.3.8. 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,
Mafalda.

sjn

  • Administrator
  • Jr. Member
  • *****
  • Posts: 72
Re: bedops merge peaks function (bedops -m)
« Reply #1 on: September 12, 2014, 05:55:58 PM »
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.
Thanks.
Shane
« Last Edit: September 18, 2014, 06:08:03 AM by sjn »

AlexReynolds

  • Administrator
  • Jr. Member
  • *****
  • Posts: 72
Re: bedops merge peaks function (bedops -m)
« Reply #2 on: September 14, 2014, 01:02:01 PM »
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
« Last Edit: September 14, 2014, 10:09:23 PM by AlexReynolds »

sjn

  • Administrator
  • Jr. Member
  • *****
  • Posts: 72
Re: bedops merge peaks function (bedops -m)
« Reply #3 on: September 18, 2014, 06:38:17 AM »
The description for bedops --merge has been updated in upcoming release, v2p5p0