annotate synapse_download.xml @ 3:93c4d2fad9af

Fixing bugs and bad code
author Kyle Ellrott <kellrott@gmail.com>
date Wed, 24 Oct 2012 23:31:13 -0700
parents 7a60e992bfb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
1 <tool id="synapse_download" name="Synapse Download" version="2.0.0">
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
2 <description>Download Synapse Entity</description>
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
3 <command interpreter="python">$script_file</command>
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
4 <inputs>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
5 <param name="user" type="text" size="90" label="Username"/>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
6 <param name="pass" type="text" size="90" label="Password"/>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
7 <param name="synid" type="text" label="Synapse ID"/>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
8 <param name="data_type" type="select" label="Data Type">
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
9 <option value="e">Affy Eset</option>
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
10 <option value="a">Attachment</option>
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
11 </param>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
12 </inputs>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
13 <outputs>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
14 <data format="txt" name="outfile" label="${synid}" />
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
15 </outputs>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
16 <configfiles>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
17 <configfile name="script_file"><![CDATA[#!/usr/bin/env python
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
18 rcode = """
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
19 library(affy)
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
20 require(synapseClient)
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
21
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
22 galaxyClean <- function(x) {
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
23 y = gsub("__gt__", ">", x);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
24 y = gsub("__lt__", "<", y );
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
25 y = gsub("__sq__", "'", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
26 y = gsub("__dq__", "\\"",y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
27 y = gsub("__ob__", "[", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
28 y = gsub("__cb__", "]", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
29 y = gsub("__oc__", "{", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
30 y = gsub("__cc__", "}", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
31 y = gsub("__at__", "@", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
32 y = gsub("__cn__", "\\n", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
33 y = gsub("__cr__", "\\r", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
34 y = gsub("__tc__", "\\t", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
35 y = gsub("__pd__", "#", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
36 y = gsub("__at__", "@", y);
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
37 return(y);
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
38 }
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
39
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
40 if (nchar("$user") && nchar("$pass")) {
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
41 synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass"))
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
42 }
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
43
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
44
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
45 cat("Loading...")
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
46 ent <- loadEntity("$synid");
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
47 cat("Done\n")
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
48
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
49 if ("e" == "$data_type") {
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
50 eset <- exprs(ent\$objects\$eset);
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
51 write(paste(c("PROBE", colnames(eset)), collapse="\\t"), file="$outfile")
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
52 write.table(eset, "$outfile", col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE);
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
53 }
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
54 if ("a" == "$data_type") {
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
55 fpath <- file.path(ent\$cacheDir, ent\$files[[1]]);
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
56 file.copy(fpath, "$outfile", overwrite=T);
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
57 }
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
58
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
59 """
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
60
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
61 import tempfile
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
62 import os
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
63 import sys
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
64 import subprocess
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
65
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
66 h, path = tempfile.mkstemp()
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
67 os.write(h,rcode)
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
68 os.close(h)
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
69
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
70 cmd_args = ["R", "CMD", "BATCH", path ]
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
71 proc = subprocess.Popen(cmd_args, stderr=subprocess.PIPE)
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
72 stdout, stderr = proc.communicate()
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
73 if proc.poll() != 0:
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
74 sys.stderr.write(stderr)
1
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
75 os.unlink(path)
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
76 ]]></configfile>
7a60e992bfb0 Uploaded
kellrott
parents:
diff changeset
77 </configfiles>
3
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
78 <help>
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
79
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
80 This tool current supports two types of data from Synapse: Affy eset data and attachment files.
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
81 For Affy eset data, it will attempt to turn the eset into a table and write a tab separated file. For attachment files, it will
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
82 save the first attached file as the output.
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
83
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
84 Install R SynapseClient::
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
85
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
86 source('http://depot.sagebase.org/CRAN.R')
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
87 pkgInstall("synapseClient")
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
88
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
89 `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: 1
diff changeset
90
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
91 </help>
93c4d2fad9af Fixing bugs and bad code
Kyle Ellrott <kellrott@gmail.com>
parents: 1
diff changeset
92 </tool>