changeset 2:a104cc98359c

Uploaded
author kellrott
date Tue, 24 Jul 2012 17:34:37 -0400
parents 7a60e992bfb0
children 93c4d2fad9af 2925d82b84fc
files synapse_query.xml
diffstat 1 files changed, 72 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/synapse_query.xml	Tue Jul 24 17:34:37 2012 -0400
@@ -0,0 +1,72 @@
+<tool id="synapse_query" name="Synapse Query" version="1.0">
+	<description>Query Synapse</description>
+	<command interpreter="python">$script_file
+#if str( $user ) != '':
+  -u "$user"
+#end if    
+
+#if str( $pass ) != '':
+  -p "$pass"
+#end if    
+-o $outfile
+	</command>
+	<inputs>
+		<param name="user" type="text" size="90" label="Username"/>
+		<param name="pass" type="text" size="90" label="Password"/>
+		<param name="query" type="text" area="True" size="5x35" label="Query">
+			<sanitizer>
+				<valid initial="string.printable">
+					<remove value="&quot;"/>
+				</valid>
+				<mapping initial="none">
+					<add source="&quot;" target="&apos;"/>
+				</mapping>
+			</sanitizer>
+		</param>		
+	</inputs>
+	<outputs>
+		<data format="txt" name="outfile" />
+	</outputs>
+	<configfiles>
+        	<configfile name="script_file"><![CDATA[#!/usr/bin/env python
+rcode="""
+library('getopt');
+library(affy)
+require(synapseClient)
+
+opt = getopt(c(
+	'user', 'u', 2, "character",
+	'pass', 'p', 2, "character",
+	'outfile', 'o', 2, "character"
+));
+
+query <- "${query}";
+cat(query)
+if ( !is.null(opt\$user) && !is.null(opt\$pass)) {
+	synapseLogin(username=user, password=pass)
+}
+
+query.out <- synapseQuery(query);
+write.table(query.out, quote=F, file=opt\$outfile, row.name=F, sep="\\t")
+
+"""
+import tempfile
+import os
+import sys
+import subprocess
+
+h, path = tempfile.mkstemp()
+os.write(h,rcode)
+os.close(h)
+
+proc = subprocess.Popen( ["Rscript", path] + sys.argv[1:], stderr=subprocess.PIPE, stdout=subprocess.PIPE )
+(stdoutdata, stderrdata) = proc.communicate()
+if proc.returncode:
+	sys.stderr.write(stderrdata)
+sys.stdout.write(stdoutdata)
+os.unlink(path)
+
+
+]]></configfile>
+	</configfiles>
+</tool>