Skip to content

Instantly share code, notes, and snippets.

@taoliu
Last active March 22, 2024 21:00
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save taoliu/2469050 to your computer and use it in GitHub Desktop.
Save taoliu/2469050 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 ${F}.clip > ${F}.sort.clip
bedGraphToBigWig ${F}.sort.clip ${G} ${F/bdg/bw}
rm -f ${F}.clip ${F}.sort.clip
@hyjforesight
Copy link

@ultrav71
Copy link

ultrav71 commented Jun 3, 2022

@hyjforesight thank you!

@sx998508
Copy link

hey there taoliu. would you mind to help me sloving quisiton when i run script and errors came out like bedgraph file contain Homo sapiens unplaced genomic contig ?

@ShannonTown
Copy link

ShannonTown commented Aug 25, 2022

Hi I have some questions about this script, first, I ran the original script and ran into the error about "Overlapping regions in a BedGraph file", then I made some modifications according to the last post in here and was able to make the bw file. I don't really understand what the codes do....but I was able to make it work.. Do you have further suggestions regarding "Overlapping regions in a BedGraph file"?

In the bw file, I noticed that the "binning" is larger than the original bedgraph, is it possible to keep the original "binning"? It is changed because there's a "bedtool merge" step in the modification (which is to solve the overlapping region error?)?
image

Thank you!

@sx998508
Copy link

sx998508 commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment