Mercurial > repos > kellrott > synapse_interface
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 2:a104cc98359c | 3:93c4d2fad9af |
|---|---|
| 1 <tool id="synapse_download" name="Synapse Download" version="1.0"> | 1 <tool id="synapse_download" name="Synapse Download" version="2.0.0"> |
| 2 <description>Download Synapse Entity</description> | 2 <description>Download Synapse Entity</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 #if str( $pass ) != '': | |
| 8 -p "$pass" | |
| 9 #end if | |
| 10 -s $synid | |
| 11 $data_type | |
| 12 -o $outfile | |
| 13 </command> | |
| 14 <inputs> | 4 <inputs> |
| 15 <param name="user" type="text" size="90" label="Username"/> | 5 <param name="user" type="text" size="90" label="Username"/> |
| 16 <param name="pass" type="text" size="90" label="Password"/> | 6 <param name="pass" type="text" size="90" label="Password"/> |
| 17 <param name="synid" type="text" label="Synapse ID"/> | 7 <param name="synid" type="text" label="Synapse ID"/> |
| 18 <param name="data_type" type="select" label="Data Type"> | 8 <param name="data_type" type="select" label="Data Type"> |
| 19 <option value="-e">Affy Eset</option> | 9 <option value="e">Affy Eset</option> |
| 20 <option value="-a">Attachment</option> | 10 <option value="a">Attachment</option> |
| 21 </param> | 11 </param> |
| 22 </inputs> | 12 </inputs> |
| 23 <outputs> | 13 <outputs> |
| 24 <data format="txt" name="outfile" label="${synid}" /> | 14 <data format="txt" name="outfile" label="${synid}" /> |
| 25 </outputs> | 15 </outputs> |
| 26 <configfiles> | 16 <configfiles> |
| 27 <configfile name="script_file"><![CDATA[#!/usr/bin/env python | 17 <configfile name="script_file"><![CDATA[#!/usr/bin/env python |
| 28 rcode = """ | 18 rcode = """ |
| 29 library('getopt'); | |
| 30 library(affy) | 19 library(affy) |
| 31 require(synapseClient) | 20 require(synapseClient) |
| 32 | 21 |
| 33 opt = getopt(c( | 22 galaxyClean <- function(x) { |
| 34 'user', 'u', 2, "character", | 23 y = gsub("__gt__", ">", x); |
| 35 'pass', 'p', 2, "character", | 24 y = gsub("__lt__", "<", y ); |
| 36 'outfile', 'o', 2, "character", | 25 y = gsub("__sq__", "'", y); |
| 37 'synid', 's', 2, "character", | 26 y = gsub("__dq__", "\\"",y); |
| 38 'eset', 'e', 0, "logical", | 27 y = gsub("__ob__", "[", y); |
| 39 'attach', 'a', 0, "logical" | 28 y = gsub("__cb__", "]", y); |
| 40 )); | 29 y = gsub("__oc__", "{", y); |
| 41 | 30 y = gsub("__cc__", "}", y); |
| 42 if ( !is.null(opt\$user) && !is.null(opt\$pass)) { | 31 y = gsub("__at__", "@", y); |
| 43 synapseLogin(username=user, password=pass) | 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); | |
| 44 } | 38 } |
| 45 | 39 |
| 46 ent <- loadEntity(opt\$synid); | 40 if (nchar("$user") && nchar("$pass")) { |
| 41 synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass")) | |
| 42 } | |
| 47 | 43 |
| 48 if (!is.null(opt\$eset)) { | 44 |
| 45 cat("Loading...") | |
| 46 ent <- loadEntity("$synid"); | |
| 47 cat("Done\n") | |
| 48 | |
| 49 if ("e" == "$data_type") { | |
| 49 eset <- exprs(ent\$objects\$eset); | 50 eset <- exprs(ent\$objects\$eset); |
| 50 write(paste(c("PROBE", colnames(eset)), collapse="\\t"), file=opt\$outfile) | 51 write(paste(c("PROBE", colnames(eset)), collapse="\\t"), file="$outfile") |
| 51 write.table(eset, opt\$outfile, col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE); | 52 write.table(eset, "$outfile", col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE); |
| 52 } | 53 } |
| 53 if (!is.null(opt\$attach)) { | 54 if ("a" == "$data_type") { |
| 54 fpath <- file.path(ent\$cacheDir, ent\$files[[1]]); | 55 fpath <- file.path(ent\$cacheDir, ent\$files[[1]]); |
| 55 file.copy(fpath, opt\$outfile, overwrite=T); | 56 file.copy(fpath, "$outfile", overwrite=T); |
| 56 } | 57 } |
| 57 | 58 |
| 58 """ | 59 """ |
| 59 | 60 |
| 60 import tempfile | 61 import tempfile |
| 64 | 65 |
| 65 h, path = tempfile.mkstemp() | 66 h, path = tempfile.mkstemp() |
| 66 os.write(h,rcode) | 67 os.write(h,rcode) |
| 67 os.close(h) | 68 os.close(h) |
| 68 | 69 |
| 69 print subprocess.check_output( ["Rscript", path] + sys.argv[1:], stderr=subprocess.STDOUT ) | 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) | |
| 70 os.unlink(path) | 75 os.unlink(path) |
| 71 | |
| 72 ]]></configfile> | 76 ]]></configfile> |
| 73 </configfiles> | 77 </configfiles> |
| 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> | |
| 74 </tool> | 92 </tool> |
