Does Bedops Have A Command Similar To The Bedtools Makewindows?
2
5
Entering edit mode
9.6 years ago
Irsan ★ 7.6k

With bedtools you can make genomic windows from a genome file or a bed file

input.bed

chr1    1000000 1500000
chr3    500000  900000


[prompt]$bedtools makewindows -b input.bed -w 250000 chr1 1000000 1250000 chr1 1250000 1500000 chr3 500000 750000 chr3 750000 900000  Does the bedops suite provide a similar way to create genomic windows? bedtools • 5.8k views ADD COMMENT 4 Entering edit mode Does it matter? The two tools complement each other pretty well. Why not just use the windows created by bedtools with bedops? ADD REPLY 0 Entering edit mode hi aaronquinlan, i am trying to minimize the amount of dependencies of our pipelines. but it seems like we will continue to use both ADD REPLY 4 Entering edit mode 9.6 years ago sjneph ▴ 690 Hi Isran, Here is a pretty straightforward script that breaks up regions into fixed-sized chunks, using a standard awk 'program'. I put it inside of a simple c-shell script. You wouldn't have to do that though. If you name this script, say, as windowed-chunks, then you'd invoke as: [prompt]$ ./windowed-chunks 250000 input.bed


#!/bin/csh -ef
if ( $#argv != 2 ) then printf "Expect a window size and an input BED file!\n" exit -1 endif awk -v winsize=$1 \
'{ \
i = $2; \ while ( i <$3 ) { \
j = i+winsize; \
if ( j > $3 ) { j =$3; } \
print $1"\t"i"\t"j; \ i = j; \ } \ }'$2

exit 0


You could embed this awk statement into a bash or sh script instead if you wanted, or even a simpler awk script (this would allow you to get rid of all of the '\' characters I used). If you wanted to make this script a bit more robust, you could add checks that the window size given isn't a negative number or string, and other little things like that. If you have questions regarding BEDOPS, feel free to join the forum at http://bedops.uwencode.org/forum/ - we'd be happy to help.

0
Entering edit mode

Hi sjneph, thanks for your reply. Did not realize it could be that easy. I can extend your code so that it also allows for windows with a step size. And I will have a look at the bedops forum, last time I checked it did not look very active so that's why I asked here :-)

1
Entering edit mode

You bet. The forum has been very quiet for a while now. We monitor it regularly, but there is very little activity as you pointed out. I'd like to see that change. I guess I'll float around out here too. This is my first post, so I'm happy it was helpful.

3
Entering edit mode
7.6 years ago

Version 2.4.3 of the bedops tool now offers --chop and --stagger functions to melt input regions into non-overlapping, adjacent or overlapping windows.

For instance, given input.bed:

chr1    1000000 1500000
chr3    500000  900000


You can use --chop 250000 to get the desired adjacent windows:

$bedops --chop 250000 input.bed chr1 1000000 1250000 chr1 1250000 1500000 chr3 500000 750000 chr3 750000 900000  Use of --stagger will step the window from the initial start position by the specified amount, keeping within bounds. Here's an example that makes overlapping windows: $ bedops --chop 250000 --stagger 100000 input.bed
chr1    1000000    1250000
chr1    1100000    1350000
chr1    1200000    1450000
chr1    1300000    1500000
chr1    1400000    1500000
chr3    500000    750000
chr3    600000    850000
chr3    700000    900000
chr3    800000    900000


The stagger value can be larger than the chop to create non-overlapping windows, where all output elements fall within the bounds of the input elements:

\$ bedops --chop 50000 --stagger 100000 input.bed
chr1    1000000    1050000
chr1    1100000    1150000
chr1    1200000    1250000
chr1    1300000    1350000
chr1    1400000    1450000
chr3    500000    550000
chr3    600000    650000
chr3    700000    750000
chr3    800000    850000