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