changeset 18:494b5cd02238

bash script
author youngkim
date Wed, 30 Mar 2016 13:39:05 -0400
parents 161866cee2a2
children caed0168f704
files BAMqc.sh ezBAMQC.sh
diffstat 2 files changed, 122 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/BAMqc.sh	Wed Mar 30 13:28:47 2016 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-#!/bin/sh
-
-### Galaxy Wrapper for BAMqc ###
-
-alignment_files=""
-refgene=""
-attrID=""
-rRNA=""
-outputHTML=""
-stranded=""
-mapq="30"
-lowBound="-250"
-upperBound="250"
-stepSize="5"
-labels=""
-cores="1"
-
-ARGS=$(getopt -o "r:f:R:o:s:p:q:" -- "$@")
-
-if [ $? -ne 0 ]; then
-    echo "Invalid command-line parameters. Do not use this script outside of Galaxy" >&2
-    exit 1
-fi
-
-eval set -- "$ARGS"
-
-while [ $# -gt 0 ]; do
-  case "$1" in
-      -r)
-	  refgene="$2"
-	  shift 2
-	  ;;
-      -f)
-	  attrID="$2"	
-	  shift 2
-	  ;;
-      -R)
-	  rRNA="$2"
-	  shift 2
-	  ;;
-      -o)
-	  outputHTML=$2
-	  shift 2
-	  ;;
-      -s)
-	  stranded=$2
-	  shift 2
-	  ;;
-      -q)
-	  mapq=$2
-	  shift 2
-	  ;;
-
-      -p)
-	  cores=$2
-	  shift 2
-	  ;;
-      --)
-	  shift
-	  break
-	  ;;
-  esac
-done
-
-if [ "$cores" -gt 10 ];then
-    cores="10"
-fi
-
-outputDir=`echo $outputHTML | sed 's/\.dat$/_files/'`
-if [ ! -d "$outputDir" ]; then
-    mkdir $outputDir
-fi
-
-touch bamqc.log
-
-while [ "$#" -ne 0 ];
-do
-  FILE="$1"
-  LABEL=`echo $2 | sed 's/ /-/g; s/\[//; s/\]//;'`
-  shift 2
-  QNAME_SORTED=`samtools view -H ${FILE} | grep "SO:queryname"`
-  if [ $? -ne 0 ]; then
-      BASE=`basename ${FILE} \.dat`
-      echo "Sorting BAM file (${LABEL}." >>samtools.log
-      samtools sort -@ 5 -n ${FILE} ${BASE} 2>>samtools.log
-      if [ $? -ne 0 ]; then
-	  echo "Error with samtools sorting for BAM file (${LABEL})." >&2
-	  cat samtools.log >&2
-	  exit 1
-      fi
-      echo "BAM file (${LABEL}) was re-sorted by query name." >>bamqc.log
-      FILELIST="$FILELIST ${BASE}.bam"
-  else
-      FILELIST="$FILELIST $FILE"
-  fi
-  LABELLIST="$LABELLIST $LABEL"
-done
-
-CMD="ezBAMQC -i $FILELIST -l $LABELLIST -f $attrID -r $refgene -o Galaxy_BAMqc_output --stranded $stranded -q $mapq --rRNA $rRNA -t $cores"
-
-echo "BAMqc command: $CMD" >> bamqc.log
-echo >> bamqc.log
-
-$CMD 2>> bamqc.log
-
-if [ $? -ne 0 ]; then
-    echo "BAMqc ran with errors" >&2
-    cat bamqc.log >&2
-    exit 1
-fi
-
-sed -i "s/\.\.\/Galaxy_BAMqc_output\///g;" Galaxy_BAMqc_output/bamqc_output.html
-
-cp -r Galaxy_BAMqc_output/data "$outputDir"
-cp -r Galaxy_BAMqc_output/figs "$outputDir"
-cp Galaxy_BAMqc_output/bamqc_output.html "$outputHTML"
-
-if [ $? -ne 0 ]; then
-    echo "Copying BAMqc results failed" >&2
-fi
-
-echo "BAMqc results copied to $outputDir" >>bamqc.log
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ezBAMQC.sh	Wed Mar 30 13:39:05 2016 -0400
@@ -0,0 +1,122 @@
+#!/bin/sh
+
+### Galaxy Wrapper for ezBAMQC ###
+
+alignment_files=""
+refgene=""
+attrID=""
+rRNA=""
+outputHTML=""
+stranded=""
+mapq="30"
+lowBound="-250"
+upperBound="250"
+stepSize="5"
+labels=""
+cores="1"
+
+ARGS=$(getopt -o "r:f:R:o:s:p:q:" -- "$@")
+
+if [ $? -ne 0 ]; then
+    echo "Invalid command-line parameters. Do not use this script outside of Galaxy" >&2
+    exit 1
+fi
+
+eval set -- "$ARGS"
+
+while [ $# -gt 0 ]; do
+  case "$1" in
+      -r)
+	  refgene="$2"
+	  shift 2
+	  ;;
+      -f)
+	  attrID="$2"	
+	  shift 2
+	  ;;
+      -R)
+	  rRNA="$2"
+	  shift 2
+	  ;;
+      -o)
+	  outputHTML=$2
+	  shift 2
+	  ;;
+      -s)
+	  stranded=$2
+	  shift 2
+	  ;;
+      -q)
+	  mapq=$2
+	  shift 2
+	  ;;
+
+      -p)
+	  cores=$2
+	  shift 2
+	  ;;
+      --)
+	  shift
+	  break
+	  ;;
+  esac
+done
+
+if [ "$cores" -gt 10 ];then
+    cores="10"
+fi
+
+outputDir=`echo $outputHTML | sed 's/\.dat$/_files/'`
+if [ ! -d "$outputDir" ]; then
+    mkdir $outputDir
+fi
+
+touch ezbamqc.log
+
+while [ "$#" -ne 0 ];
+do
+  FILE="$1"
+  LABEL=`echo $2 | sed 's/ /-/g; s/\[//; s/\]//;'`
+  shift 2
+  QNAME_SORTED=`samtools view -H ${FILE} | grep "SO:queryname"`
+  if [ $? -ne 0 ]; then
+      BASE=`basename ${FILE} \.dat`
+      echo "Sorting BAM file (${LABEL}." >>samtools.log
+      samtools sort -@ 5 -n ${FILE} ${BASE} 2>>samtools.log
+      if [ $? -ne 0 ]; then
+	  echo "Error with samtools sorting for BAM file (${LABEL})." >&2
+	  cat samtools.log >&2
+	  exit 1
+      fi
+      echo "BAM file (${LABEL}) was re-sorted by query name." >>ezbamqc.log
+      FILELIST="$FILELIST ${BASE}.bam"
+  else
+      FILELIST="$FILELIST $FILE"
+  fi
+  LABELLIST="$LABELLIST $LABEL"
+done
+
+CMD="ezBAMQC -i $FILELIST -l $LABELLIST -f $attrID -r $refgene -o Galaxy_ezBAMQC_output --stranded $stranded -q $mapq --rRNA $rRNA -t $cores"
+
+echo "ezBAMQC command: $CMD" >> ezbamqc.log
+echo >> ezbamqc.log
+
+$CMD 2>> ezbamqc.log
+
+if [ $? -ne 0 ]; then
+    echo "ezBAMQC ran with errors" >&2
+    cat ezbamqc.log >&2
+    exit 1
+fi
+
+sed -i "s/\.\.\/Galaxy_ezBAMQC_output\///g;" Galaxy_ezBAMQC_output/bamqc_output.html
+
+cp -r Galaxy_ezBAMQC_output/data "$outputDir"
+cp -r Galaxy_ezBAMQC_output/figs "$outputDir"
+cp Galaxy_ezBAMQC_output/bamqc_output.html "$outputHTML"
+
+if [ $? -ne 0 ]; then
+    echo "Copying ezBAMQC results failed" >&2
+fi
+
+echo "ezBAMQC results copied to $outputDir" >>ezbamqc.log