Question: How To Melt A Bed File (With Bedops?)
1
gravatar for Irsan
5.8 years ago by
Irsan6.9k
Amsterdam
Irsan6.9k wrote:

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 • 1.5k views
ADD COMMENTlink modified 5.8 years ago by Aaronquinlan11k • written 5.8 years ago by Irsan6.9k
6
gravatar for Aaronquinlan
5.8 years ago by
Aaronquinlan11k
United States
Aaronquinlan11k wrote:

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 COMMENTlink written 5.8 years ago by Aaronquinlan11k

This one is also clean, thanks!

ADD REPLYlink written 5.8 years ago by Irsan6.9k
4
gravatar for Alex Reynolds
5.8 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

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 COMMENTlink modified 5.8 years ago • written 5.8 years ago by Alex Reynolds28k

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

ADD REPLYlink written 5.8 years ago by Irsan6.9k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1441 users visited in the last hour