-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbdgToBw
executable file
·56 lines (42 loc) · 1.5 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /bin/bash
# Vivek Rai
# Parker Lab
# vivekrai@umich.edu
#
# April 20, 2019
set -eo pipefail
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; }
[[ $# -ne 3 ]] && echo "Usage: <PROG> [bdg-file] [chrom-sizes] [bw-file]" \
&& echo "Converts Bedgraph file to Bigwig." \
&& echo "Optionally set TMPDIR for a different scratch directory." \
&& exit 1
say() {
echo "$@" 2> /dev/stderr
}
# Wolverine and falcon specific; default to directory of input Bedgraph file
if [[ -z $TMPDIR ]]; then
case $(hostname) in
wolverine | falcon)
TMPDIR="/localscratch"
;;
*)
TMPDIR=$(dirname "$1")
;;
esac
fi
# more sanity checks
[[ ! -f "$1" ]] && say "$1 not found. Exiting!" && exit 1
[[ ! -f "$2" ]] && say "$2 not found. Exiting!" && exit 1
base=$(basename "$1")
say "Converting $base, TMPDIR=$TMPDIR"
say "Clipping and sorting bedgraph.."
bedtools slop -i "$1" -g "$2" -b 0 \
| bedClip stdin "$2" stdout \
| LC_ALL=C sort -k1,1 -k2,2n > "$TMPDIR/$base.sorted.bdg"
say "Converting to bigwig.."
bedGraphToBigWig "$TMPDIR/$base.sorted.bdg" "$2" "$3"
say "Cleanup.."
unlink "$TMPDIR/$base.sorted.bdg"
say "Done."