comparison 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
comparison
equal deleted inserted replaced
2:a104cc98359c 3:93c4d2fad9af
1 <tool id="synapse_query" name="Synapse Query" version="1.0"> 1 <tool id="synapse_query" name="Synapse Query" version="1.0">
2 <description>Query Synapse</description> 2 <description>Query Synapse</description>
3 <command interpreter="python">$script_file 3 <command interpreter="python">$script_file</command>
4 #if str( $user ) != '':
5 -u "$user"
6 #end if
7
8 #if str( $pass ) != '':
9 -p "$pass"
10 #end if
11 -o $outfile
12 </command>
13 <inputs> 4 <inputs>
14 <param name="user" type="text" size="90" label="Username"/> 5 <param name="user" type="text" size="90" label="Username"/>
15 <param name="pass" type="text" size="90" label="Password"/> 6 <param name="pass" type="text" size="90" label="Password"/>
16 <param name="query" type="text" area="True" size="5x35" label="Query"> 7 <param name="query" type="text" area="True" size="5x35" label="Query"/>
8
9 <!--
17 <sanitizer> 10 <sanitizer>
18 <valid initial="string.printable"> 11 <valid initial="string.printable">
19 <remove value="&quot;"/> 12 <remove value="&quot;"/>
20 </valid> 13 </valid>
21 <mapping initial="none"> 14 <mapping initial="none">
22 <add source="&quot;" target="&apos;"/> 15 <add source="&quot;" target="&apos;"/>
23 </mapping> 16 </mapping>
24 </sanitizer> 17 </sanitizer>
25 </param> 18 </param>
19 -->
26 </inputs> 20 </inputs>
27 <outputs> 21 <outputs>
28 <data format="txt" name="outfile" /> 22 <data format="tabular" name="outfile" />
29 </outputs> 23 </outputs>
30 <configfiles> 24 <configfiles>
31 <configfile name="script_file"><![CDATA[#!/usr/bin/env python 25 <configfile name="script_file"><![CDATA[#!/usr/bin/env python
32 rcode=""" 26 rcode="""
33 library('getopt');
34 library(affy) 27 library(affy)
35 require(synapseClient) 28 require(synapseClient)
36 29
37 opt = getopt(c( 30 galaxyClean <- function(x) {
38 'user', 'u', 2, "character", 31 y = gsub("__gt__", ">", x);
39 'pass', 'p', 2, "character", 32 y = gsub("__lt__", "<", y );
40 'outfile', 'o', 2, "character" 33 y = gsub("__sq__", "'", y);
41 )); 34 y = gsub("__dq__", "\\"",y);
42 35 y = gsub("__ob__", "[", y);
43 query <- "${query}"; 36 y = gsub("__cb__", "]", y);
44 cat(query) 37 y = gsub("__oc__", "{", y);
45 if ( !is.null(opt\$user) && !is.null(opt\$pass)) { 38 y = gsub("__cc__", "}", y);
46 synapseLogin(username=user, password=pass) 39 y = gsub("__at__", "@", y);
40 y = gsub("__cn__", "\\n", y);
41 y = gsub("__cr__", "\\r", y);
42 y = gsub("__tc__", "\\t", y);
43 y = gsub("__pd__", "#", y);
44 y = gsub("__at__", "@", y);
45 return(y);
47 } 46 }
48 47
48 if (nchar("$user") && nchar("$pass")) {
49 synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass"))
50 }
51
52
53
54 query <- galaxyClean("${query}");
55 cat(query)
56
49 query.out <- synapseQuery(query); 57 query.out <- synapseQuery(query);
50 write.table(query.out, quote=F, file=opt\$outfile, row.name=F, sep="\\t") 58 write.table(query.out, quote=F, file="$outfile", row.name=F, sep="\\t")
51 59
52 """ 60 """
53 import tempfile 61 import tempfile
54 import os 62 import os
55 import sys 63 import sys
56 import subprocess 64 import subprocess
57 65
58 h, path = tempfile.mkstemp() 66 h, path = tempfile.mkstemp(dir="/tmp")
59 os.write(h,rcode) 67 os.write(h,rcode)
60 os.close(h) 68 os.close(h)
61 69
62 proc = subprocess.Popen( ["Rscript", path] + sys.argv[1:], stderr=subprocess.PIPE, stdout=subprocess.PIPE ) 70 proc = subprocess.Popen( ["Rscript", path], stderr=subprocess.PIPE, stdout=subprocess.PIPE )
63 (stdoutdata, stderrdata) = proc.communicate() 71 (stdoutdata, stderrdata) = proc.communicate()
64 if proc.returncode: 72 if proc.returncode:
65 sys.stderr.write(stderrdata) 73 sys.stderr.write(stderrdata)
66 sys.stdout.write(stdoutdata) 74 sys.stdout.write(stdoutdata)
67 os.unlink(path) 75 os.unlink(path)
68 76
69
70 ]]></configfile> 77 ]]></configfile>
71 </configfiles> 78 </configfiles>
79 <help>
80
81 Install R SynapseClient::
82
83 source('http://depot.sagebase.org/CRAN.R')
84 pkgInstall("synapseClient")
85
86 `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;`_
87
88 Example Query:
89
90 select * from entity where parentId=="syn300013"
91
92 </help>
93
72 </tool> 94 </tool>