How To Melt A Bed File (With Bedops?)
2
1
Entering edit mode
11.2 years ago
Irsan ★ 7.8k

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.5k views
ADD COMMENT
6
Entering edit mode
11.2 years ago

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...

ADD COMMENT
0
Entering edit mode

This one is also clean, thanks!

ADD REPLY
4
Entering edit mode
11.2 years ago

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
ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1495 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6