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