Expanding Genomic Coordinates Using Bedtools
5
0
Entering edit mode
5.7 years ago
gtasource ▴ 60

I have the following bed file

chr1    18551   18579   
chr1    18559   18583   
chr1    18966   18991   
chr1    18966   18991   
chr1    18966   18993   

I want to expand the coordinates to generate a new file that lists every single coordinate individually. For example:

chr1 18551 18552
chr1 18552 18553
...
chr1 18578 18579

I want it to do this for every single bed coordinate, and put all if it in a single file. Any help? I've played around with Bedtools slop, but it wasn't doing exactly what I needed.

bed bedtools • 1.9k views
ADD COMMENT
1
Entering edit mode
5.7 years ago

You could --merge and --chop intervals from one to N sorted BED files into single-base intervals with BEDOPS bedops and a Unix pipe:

$ bedops --merge A.bed ... N.bed | bedops --chop 1 - > answer.bed

The merge step merges overlapping intervals before chopping. This removes duplicates.

If you instead want duplicate single-base intervals where there are overlaps, just replace the merge operation with a union operation:

$ bedops --everything A.bed ... N.bed | bedops --chop 1 - > answer.bed
ADD COMMENT
1
Entering edit mode
5.7 years ago
bedtools makewindows -b in.bed -w 1
ADD COMMENT
0
Entering edit mode
5.7 years ago
 awk  '{S=int($2);E=int($3);while(S<E) {printf("%s\t%d\t%s\n",$1,S,S+1);S++}}'   in.bed
ADD COMMENT
0
Entering edit mode
5.7 years ago
import sys 
with open(sys.argv[1],"r")as bed: 
        for line in bed: 
                #cor=line.strip("\n").split("   ") 
                cor=line.strip("\n").split("\t") 
                for i in range(int(cor[1]),int(cor[2])): 
                        print(cor[0],i,i+1,sep="\t")

Save this script as biostars.py and run python biostars.py input.bed .

ADD COMMENT
0
Entering edit mode
5.7 years ago
venu 7.1k

There are many working solutions. But as you mentioned bedtools, here is how you do it

cat file.bed | windowMaker -b - -w 1
ADD COMMENT

Login before adding your answer.

Traffic: 2734 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