Shrink elements of a bedtools file
2
0
Entering edit mode
9.4 years ago

Is there a way to shrink elements in a bed file? `bedtools {slop,flank}` are all about increasing, but I can't find a function in bedtools that will shrink a region. In particular, I'm interested in taking intron files and strand-specifically removing 400bp from one end.

Thanks!

bedtools • 2.6k views
ADD COMMENT
3
Entering edit mode
9.4 years ago
 awk -vX=400 '{OFS="\t";S=$2+X; E=$3-X; if(S<=E) {$2=S;$3=E;print;}}' input.bed
ADD COMMENT
0
Entering edit mode
9.4 years ago

This can easily be done per edge and per strand with awk and BEDOPS bedops --range.

To shrink forward-stranded introns from the "left" edge:

$ awk '$6=="+"' introns.bed | bedops --everything --range 400:0 - > left_shrunken_forward_introns.bed

To shrink forward-stranded elements from the "right" edge:

$ awk '$6=="+"' introns.bed | bedops --everything --range 0:-400 - > right_shrunken_forward_introns.bed

To shrink reverse-stranded introns from the "left" edge:

$ awk '$6=="-"' introns.bed | bedops --everything --range 400:0 - > left_shrunken_reverse_introns.bed

And, finally, from the "right" edge:

$ awk '$6=="-"' introns.bed | bedops --everything --range 0:-400 - > right_shrunken_reverse_introns.bed
ADD COMMENT

Login before adding your answer.

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