changeset 4:0a872e59164c

Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
author Lance Parsons <lparsons@princeton.edu>
date Wed, 25 May 2011 19:33:40 -0400
parents 7ed26fc9fa8a
children 1dada50cca8a
files cutadapt.xml discard_stderr_wrapper.sh
diffstat 2 files changed, 42 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cutadapt.xml	Wed May 25 18:54:09 2011 -0400
+++ b/cutadapt.xml	Wed May 25 19:33:40 2011 -0400
@@ -4,7 +4,7 @@
 		<requirement type="python-module">cutadapt</requirement>
 	</requirements>
 
-	<command>cutadapt 
+	<command interpreter="sh">discard_stderr_wrapper.sh cutadapt
 		#if $input.extension.startswith( "fastq"):
 		--format=fastq
 		#else
@@ -30,7 +30,7 @@
 		#end if
 		'$input'
 		--output='$output' 
-		2> $report
+		> $report
 	</command>
 	<inputs>
 		<param format="fastqsanger, fasta" name="input" type="data" optional="false" label="Fastq file to trim" length="100"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/discard_stderr_wrapper.sh	Wed May 25 19:33:40 2011 -0400
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# STDERR wrapper - discards STDERR if command execution was OK.
+
+#
+# This script executes a given command line,
+# while saving the STDERR in a temporary file.
+#
+# When the command is completed, it checks to see if the exit code was zero.
+# if so - the command is assumed to have succeeded - the STDERR file is discarded.
+# if not - the command is assumed to have failed, and the STDERR file is dumped to the real STDERR
+#
+#
+# Use this wrapper for tools which insist on writting stuff to STDERR
+# even if they succeeded - which throws galaxy off balance.
+#
+#
+# Copyright 2009 (C) by Assaf Gordon
+# This file is distributed under the BSD license.
+#
+# Modified by Lance Parsons (2011)
+# Echo STDERR to STDOUT if return code was 0
+
+TMPFILE=$(mktemp -t tmp.XXXXXXXXXX) || exit 1
+#CWD=`pwd`
+#DIRECTORY=$(cd `dirname $0` && pwd)
+#cd $DIRECTORY
+"$@" 2> $TMPFILE
+
+EXITCODE=$?
+# Exitcode != 0 ?
+if [ "$EXITCODE" -ne "0" ]; then
+	cat $TMPFILE >&2
+else
+#	echo "Testing STDOUT"
+	cat $TMPFILE >&1
+fi
+rm $TMPFILE
+cd $CWD
+exit $EXITCODE