I'm using bedops to intersect bed and bedgraph files and want to keep information in both files. Currently bedops only outputs the information on the first file that it is fed.
bedops --element-of $bed $bdg > $overlapped.bed
File A: BED
chr1 1000 2000 region_1
chr1 2000 3000 region_2
File B: BDG
chr1 1000 1500 100
chr1 2000 3000 200
Wanted output:
chr1 1000 2000 region_1 chr1 1000 1500 100
chr1 2000-3000 region_2 chr1 2000 3000 200
Any ideas?
Sure, use
bedmap
, instead:--echo
operator prints out each element in set A.--echo-map
operator prints any elements in set B ("map set") that overlap set A's element, by one or more bases.--delim '\t'
operator separates set A elements and any overlapping elements by a tab character.The
bedmap
tool maps or reports associations between sets of elements, based on how they overlap.You can report the associations directly as elements, as shown above with
--echo-map
, or you can even report attributes or summaries of the associations, like statistical or score-based calculations (mean, median, etc.) using other operators (*).The documentation shows examples of this for various BED inputs.
(*) Note: For score calculations, Bedgraph needs to be converted to BED5, but that's easy to do:
If you're just looking at mapped elements, you don't need to convert Bedgraph to BED.
Answered everything, even anticipated the question about the scoring calculations I was going to have after running it. Thanks Alex!
You're welcome! If BEDOPS is useful to you, please consider adding a star to our Github page. This helps us gauge interest and make future updates more easily available.
anyone know how to do this in perl?...just by chance this is very like something i need.
You could use
system()
: