diff synapse_query.xml @ 3:93c4d2fad9af

Fixing bugs and bad code
author Kyle Ellrott <kellrott@gmail.com>
date Wed, 24 Oct 2012 23:31:13 -0700
parents a104cc98359c
children
line wrap: on
line diff
--- a/synapse_query.xml	Tue Jul 24 17:34:37 2012 -0400
+++ b/synapse_query.xml	Wed Oct 24 23:31:13 2012 -0700
@@ -1,19 +1,12 @@
 <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>
+	<command interpreter="python">$script_file</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">
+		<param name="query" type="text" area="True" size="5x35" label="Query"/>
+		
+		<!--
 			<sanitizer>
 				<valid initial="string.printable">
 					<remove value="&quot;"/>
@@ -22,32 +15,47 @@
 					<add source="&quot;" target="&apos;"/>
 				</mapping>
 			</sanitizer>
-		</param>		
+		</param>
+		-->		
 	</inputs>
 	<outputs>
-		<data format="txt" name="outfile" />
+		<data format="tabular" 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)
+galaxyClean <- function(x) { 
+y = gsub("__gt__", ">", x);
+y = gsub("__lt__", "<", y );
+y = gsub("__sq__", "'", y);
+y = gsub("__dq__", "\\"",y);
+y = gsub("__ob__", "[", y);
+y = gsub("__cb__", "]", y);
+y = gsub("__oc__", "{", y);
+y = gsub("__cc__", "}", y);
+y = gsub("__at__", "@", y);
+y = gsub("__cn__", "\\n", y);
+y = gsub("__cr__", "\\r", y);
+y = gsub("__tc__", "\\t", y);
+y = gsub("__pd__", "#", y);
+y = gsub("__at__", "@", y);
+return(y);
 }
 
+if (nchar("$user") && nchar("$pass")) {
+	synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass"))
+}
+
+
+
+query <- galaxyClean("${query}");
+cat(query)
+
 query.out <- synapseQuery(query);
-write.table(query.out, quote=F, file=opt\$outfile, row.name=F, sep="\\t")
+write.table(query.out, quote=F, file="$outfile", row.name=F, sep="\\t")
 
 """
 import tempfile
@@ -55,18 +63,32 @@
 import sys
 import subprocess
 
-h, path = tempfile.mkstemp()
+h, path = tempfile.mkstemp(dir="/tmp")
 os.write(h,rcode)
 os.close(h)
 
-proc = subprocess.Popen( ["Rscript", path] + sys.argv[1:], stderr=subprocess.PIPE, stdout=subprocess.PIPE )
+proc = subprocess.Popen( ["Rscript", path], 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>
+		<help>
+
+Install R SynapseClient::
+
+    source('http://depot.sagebase.org/CRAN.R')
+    pkgInstall("synapseClient")
+
+`To setup auto login (so you don't have to type in your password) &lt;https://sagebionetworks.jira.com/wiki/display/SYNR/How+to+configure+automatic+login&gt;`_ 
+
+Example Query:
+
+select * from entity where parentId=="syn300013"
+
+	</help>
+
+</tool>
\ No newline at end of file