-
Notifications
You must be signed in to change notification settings - Fork 1
/
bdgTobw
executable file
·33 lines (23 loc) · 1.1 KB
/
bdgTobw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /bin/bash
command -v bedtools &>/dev/null || { echo "bedtools not found! Download bedTools: <http://code.google.com/p/bedtools/>"; exit 1; }
command -v bedGraphToBigWig &>/dev/null || { echo "bedGraphToBigWig not found! Download: <http://hgdownload.cse.ucsc.edu/admin/exe/>"; exit 1; }
command -v bedClip &>/dev/null || { echo "bedClip not found! Download: <http://hgdownload.cse.ucsc.edu/admin/exe/>"; exit 1; }
[[ $# -lt 3 ]] && echo "USAGE: <PROG> [bdg-file] [chrom-sizes] [bw-file] [tmp-dir]" \
&& echo "Converts Bedgraph file to Bigwig." \
&& echo " [tmp-dir]: Set to /dev/shm if not specified" \
&& exit 1
base=$(basename "$1")
tmpdir="$4"
[[ -z "$tmpdir" ]] && tmpdir="/dev/shm"
echo "Using $base."
echo "TMPDIR set to $tmpdir."
echo "Clipping and sorting bedgraph.."
bedtools slop -i "$1" -g "$2" -b 0 \
| bedClip stdin "$2" stdout \
| LC_COLLATE=C sort -k1,1 -k2,2n > "$tmpdir/$base.sorted.bdg"
echo "Converting to bigwig.."
bedGraphToBigWig "$tmpdir/$base.sorted.bdg" "$2" "$3"
echo "Wrote to $3."
echo "Cleanup.."
rm "$tmpdir/$base.sorted.bdg"
echo "Done."