forked from Danko-Lab/proseq2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergeBigWigs.bsh
93 lines (78 loc) · 2.07 KB
/
mergeBigWigs.bsh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/bash
#
#CHINFO=/fs/cbsudanko/storage/data/hg19/hg19.chromInfo
function show_help {
echo "bash mergeBigWigs.bsh --chrom-info=PATH out.bigWig input_bigWig1 input_bigWig2 [ input_bigWig3 ...]"
echo " "
echo "-c, "
echo "--chrom-info=PATH Location of the chromInfo table."
echo ""
echo "options:"
echo " "
echo "To get help:"
echo "-h,"
echo "--help show this brief help menu."
echo " "
echo " "
exit 0
}
bwFiles=()
while test $# -gt 0; do
case "$1" in
-h|--help)
show_help
exit 0
;;
--chrom-info*)
export CHINFO=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-c)
shift
if test $# -gt 0; then
export CHINFO=$1
else
echo "No chromInfo table is specified."
exit 1
fi
shift
;;
*)
bwFiles+=($1)
shift
;;
esac
done
if [ ${#bwFiles[@]} -eq 0 ]
then
show_help
exit 0
fi
if [ ${#bwFiles[@]} -lt 3 ]
then
echo "Error: Input files less than 2"
exit 1
fi
if [ "$CHINFO" = "" ]
then
echo "Error: No chromInfo table is specified."
exit 1
fi
#get the final file name
mergeBw=${bwFiles[0]}
echo "Output bigWig: $mergeBw"
#remove the first element
unset bwFiles[0]
echo "Input bigWigs: ${bwFiles[*]}"
for tool in bedtools bedGraphToBigWig bigWigToBedGraph
do command -v ${tool} >/dev/null 2>&1 || { echo >&2 ${tool}" is required. Please make sure you can call the bioinformatics tools from your current working directoryb. Aborting."; exit 1; }
done
WORKDIR=`mktemp -d`
for i in ${bwFiles[*]}
do
bigWigToBedGraph $i $WORKDIR/$(basename $i).bedGraph
done
bedtools unionbedg -i `ls ${WORKDIR}/*.bedGraph` | awk 'BEGIN{OFS="\t"} {sum=0; for (i=4; i<=NF; i++) { sum+= $i } print $1,$2,$3, sum}' > ${WORKDIR}/all.bed
bedGraphToBigWig ${WORKDIR}/all.bed $CHINFO $mergeBw
#echo $WORKDIR
rm -rf $WORKDIR