Skip to content

Instantly share code, notes, and snippets.

@arnavm
Created July 10, 2020 21:40
Show Gist options
  • Save arnavm/8556b53adf386e47efb880e4ef218f32 to your computer and use it in GitHub Desktop.
Save arnavm/8556b53adf386e47efb880e4ef218f32 to your computer and use it in GitHub Desktop.
One-liner to rescale BED features to a constant-width intervals
# Nifty one-liner for rescaling BED features (new size designated by s)
# Solution from https://www.biostars.org/p/241744/#241748
alias rescaleBed="awk -F '\t' '{X=s; mid=(int(\$2)+int(\$3))/2;printf(\"%s\t%d\t%d\n\",\$1,(mid-X<0?0:mid-X),mid+X);}'"
# Example usage to get centered, 200 bp intervals: rescaleBed s=100 test.bed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment