This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Melt A Bed File (With Bedops?)

Consider the following bed entries

chr1    10    13
chr2    100   103

Is it possible to melt this 2-record bed file to a bed where each entry covers only 1 base with bedops or bedtools?

Desired output:

chr1    10    11
chr1    11    12
chr1    12    13
chr2    100    101
chr2    101    102
chr2    102    103
bed

2 answers

The bedtools makewindows command can do this (and other useful "stuff") as well:

bedtools makewindows -b test.bed -w 1
chr1    10    11
chr1    11    12
chr1    12    13
chr2    100    101
chr2    101    102
chr2    102    103

That said, you can't deny general utility of the nice awk approach that Alex describes - easy to adjust...

This one is also clean, thanks!

Not with BEDOPS, but you can run your BED file through awk:

$ awk ' \
    { \
         regionChromosome = $1; \
         regionStart = $2; \
         regionStop = $3; \
         for (baseStart = regionStart; baseStart < regionStop; baseStart++) { \
             baseStop = baseStart + 1; \
             print regionChromosome"\t"baseStart"\t"baseStop; \
         } \
    }' regions.bed > bases.bed

Didn't realize it can be that simple with awk, thanks so much Alex!

Log in to answer this question.