2
|
1 <tool id="synapse_query" name="Synapse Query" version="1.0">
|
|
2 <description>Query Synapse</description>
|
3
|
3 <command interpreter="python">$script_file</command>
|
2
|
4 <inputs>
|
|
5 <param name="user" type="text" size="90" label="Username"/>
|
|
6 <param name="pass" type="text" size="90" label="Password"/>
|
3
|
7 <param name="query" type="text" area="True" size="5x35" label="Query"/>
|
|
8
|
|
9 <!--
|
2
|
10 <sanitizer>
|
|
11 <valid initial="string.printable">
|
|
12 <remove value="""/>
|
|
13 </valid>
|
|
14 <mapping initial="none">
|
|
15 <add source=""" target="'"/>
|
|
16 </mapping>
|
|
17 </sanitizer>
|
3
|
18 </param>
|
|
19 -->
|
2
|
20 </inputs>
|
|
21 <outputs>
|
3
|
22 <data format="tabular" name="outfile" />
|
2
|
23 </outputs>
|
|
24 <configfiles>
|
|
25 <configfile name="script_file"><![CDATA[#!/usr/bin/env python
|
|
26 rcode="""
|
|
27 library(affy)
|
|
28 require(synapseClient)
|
|
29
|
3
|
30 galaxyClean <- function(x) {
|
|
31 y = gsub("__gt__", ">", x);
|
|
32 y = gsub("__lt__", "<", y );
|
|
33 y = gsub("__sq__", "'", y);
|
|
34 y = gsub("__dq__", "\\"",y);
|
|
35 y = gsub("__ob__", "[", y);
|
|
36 y = gsub("__cb__", "]", y);
|
|
37 y = gsub("__oc__", "{", y);
|
|
38 y = gsub("__cc__", "}", y);
|
|
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);
|
2
|
46 }
|
|
47
|
3
|
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
|
2
|
57 query.out <- synapseQuery(query);
|
3
|
58 write.table(query.out, quote=F, file="$outfile", row.name=F, sep="\\t")
|
2
|
59
|
|
60 """
|
|
61 import tempfile
|
|
62 import os
|
|
63 import sys
|
|
64 import subprocess
|
|
65
|
3
|
66 h, path = tempfile.mkstemp(dir="/tmp")
|
2
|
67 os.write(h,rcode)
|
|
68 os.close(h)
|
|
69
|
3
|
70 proc = subprocess.Popen( ["Rscript", path], stderr=subprocess.PIPE, stdout=subprocess.PIPE )
|
2
|
71 (stdoutdata, stderrdata) = proc.communicate()
|
|
72 if proc.returncode:
|
|
73 sys.stderr.write(stderrdata)
|
|
74 sys.stdout.write(stdoutdata)
|
|
75 os.unlink(path)
|
|
76
|
|
77 ]]></configfile>
|
|
78 </configfiles>
|
3
|
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) <https://sagebionetworks.jira.com/wiki/display/SYNR/How+to+configure+automatic+login>`_
|
|
87
|
|
88 Example Query:
|
|
89
|
|
90 select * from entity where parentId=="syn300013"
|
|
91
|
|
92 </help>
|
|
93
|
|
94 </tool> |