91
bedops / Re: bedops merge peaks function (bedops -m)
« Last post by AlexReynolds 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
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