From 49b541205106c9385ac6c5e9ec7943ff4e9db397 Mon Sep 17 00:00:00 2001
From: Holger Brandl <holgerbrandl@gmail.com>
Date: Thu, 3 Sep 2015 14:49:22 +0200
Subject: [PATCH] added bigwig helper

---
 dge_workflow/dge_utils.sh | 40 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/dge_workflow/dge_utils.sh b/dge_workflow/dge_utils.sh
index 887b69c..32d6a76 100755
--- a/dge_workflow/dge_utils.sh
+++ b/dge_workflow/dge_utils.sh
@@ -201,6 +201,46 @@ mailme "$project: bamcorrelate done in $(pwd)"
 export -f dge_bam_correlate
 
 
+dge_bigwig(){
+
+usage="Usage: dge_bigwig <genome_fai> [<bam_file>]+"
+
+
+if [ $# -lt 2 ]; then
+    echo ${usage} >&2 ; return;
+fi
+
+#bamFiles=$(find . -name "*.bam" | grep -v unmapped |  xargs echo)
+genomeFai=$1
+bamFiles="${@:2}"
+
+if [ ! -f "${genomeFai}" ]; then
+    echo "could not find fai index $1! ${usage}" >&2 ; return;
+fi
+
+## add bigwig to PATH
+export PATH=~/bin:${PATH}
+
+if [ -z "$(which wigToBigWig 2>/dev/null)" ]; then
+    echo "could not find wigToBigWig in PATH! ${usage}" >&2 ; #return;
+fi
+
+## create big wig files
+for bamFile in $bamFiles; do
+    sample=$(basename $bamFile .bam)
+    echo "converting $bamFile to bigwig format"
+    mysub "${project}__bw__${sample}" "genomeCoverageBed -bg -ibam $bamFile  -g ${genomeFai} |  wigToBigWig -clip stdin ${genomeFai} ${sample}.bw" -q short | joblist .bigwig
+done
+
+wait4jobs .bigwig
+
+}
+export -f dge_bigwig
+
+## http://stackoverflow.com/questions/6916856/can-bash-show-a-functions-definition
+#type dge_bigwig
+
+
 ## Merge technical replicatews
 dge_merge_treps(){
 
-- 
GitLab