Skip to content

Instantly share code, notes, and snippets.

@jurgjn
Forked from taoliu/bdg2bw
Last active August 1, 2019 16:20
Show Gist options
  • Save jurgjn/1582d1f014164c70e25a091002c76e7a to your computer and use it in GitHub Desktop.
Save jurgjn/1582d1f014164c70e25a091002c76e7a to your computer and use it in GitHub Desktop.
bedGraph to bigWig
#!/bin/bash
# check commands: slopBed, bedGraphToBigWig and bedClip
which bedtools &>/dev/null || { echo "bedtools not found! Download bedTools: <http://code.google.com/p/bedtools/>"; exit 1; }
which bedGraphToBigWig &>/dev/null || { echo "bedGraphToBigWig not found! Download: <http://hgdownload.cse.ucsc.edu/admin/exe/>"; exit 1; }
which bedClip &>/dev/null || { echo "bedClip not found! Download: <http://hgdownload.cse.ucsc.edu/admin/exe/>"; exit 1; }
# end of checking
if [ $# -lt 2 ];then
echo "Need 2 parameters! <bedgraph> <chrom info>"
exit
fi
F=$1
G=$2
bedtools slop -i ${F} -g ${G} -b 0 | bedClip stdin ${G} ${F}.clip
LC_COLLATE=C sort -k1,1 -k2,2n --temporary-directory=./ ${F}.clip > ${F}.sort.clip
bedGraphToBigWig ${F}.sort.clip ${G} ${F/bdg/bw}
rm -f ${F}.clip ${F}.sort.clip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment