Mercurial > repos > kellrott > synapse_interface
diff 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 |
line wrap: on
line diff
--- a/synapse_download.xml Tue Jul 24 17:34:37 2012 -0400 +++ b/synapse_download.xml Wed Oct 24 23:31:13 2012 -0700 @@ -1,23 +1,13 @@ -<tool id="synapse_download" name="Synapse Download" version="1.0"> +<tool id="synapse_download" name="Synapse Download" version="2.0.0"> <description>Download Synapse Entity</description> - <command interpreter="python">$script_file -#if str( $user ) != '': - -u "$user" -#end if -#if str( $pass ) != '': - -p "$pass" -#end if --s $synid -$data_type --o $outfile - </command> + <command interpreter="python">$script_file</command> <inputs> <param name="user" type="text" size="90" label="Username"/> <param name="pass" type="text" size="90" label="Password"/> <param name="synid" type="text" label="Synapse ID"/> <param name="data_type" type="select" label="Data Type"> - <option value="-e">Affy Eset</option> - <option value="-a">Attachment</option> + <option value="e">Affy Eset</option> + <option value="a">Attachment</option> </param> </inputs> <outputs> @@ -26,33 +16,44 @@ <configfiles> <configfile name="script_file"><![CDATA[#!/usr/bin/env python rcode = """ -library('getopt'); library(affy) require(synapseClient) -opt = getopt(c( - 'user', 'u', 2, "character", - 'pass', 'p', 2, "character", - 'outfile', 'o', 2, "character", - 'synid', 's', 2, "character", - 'eset', 'e', 0, "logical", - 'attach', 'a', 0, "logical" -)); - -if ( !is.null(opt\$user) && !is.null(opt\$pass)) { - synapseLogin(username=user, password=pass) +galaxyClean <- function(x) { +y = gsub("__gt__", ">", x); +y = gsub("__lt__", "<", y ); +y = gsub("__sq__", "'", y); +y = gsub("__dq__", "\\"",y); +y = gsub("__ob__", "[", y); +y = gsub("__cb__", "]", y); +y = gsub("__oc__", "{", y); +y = gsub("__cc__", "}", y); +y = gsub("__at__", "@", y); +y = gsub("__cn__", "\\n", y); +y = gsub("__cr__", "\\r", y); +y = gsub("__tc__", "\\t", y); +y = gsub("__pd__", "#", y); +y = gsub("__at__", "@", y); +return(y); } -ent <- loadEntity(opt\$synid); +if (nchar("$user") && nchar("$pass")) { + synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass")) +} + -if (!is.null(opt\$eset)) { +cat("Loading...") +ent <- loadEntity("$synid"); +cat("Done\n") + +if ("e" == "$data_type") { eset <- exprs(ent\$objects\$eset); - write(paste(c("PROBE", colnames(eset)), collapse="\\t"), file=opt\$outfile) - write.table(eset, opt\$outfile, col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE); + write(paste(c("PROBE", colnames(eset)), collapse="\\t"), file="$outfile") + write.table(eset, "$outfile", col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE); } -if (!is.null(opt\$attach)) { +if ("a" == "$data_type") { fpath <- file.path(ent\$cacheDir, ent\$files[[1]]); - file.copy(fpath, opt\$outfile, overwrite=T); + file.copy(fpath, "$outfile", overwrite=T); } """ @@ -66,9 +67,26 @@ os.write(h,rcode) os.close(h) -print subprocess.check_output( ["Rscript", path] + sys.argv[1:], stderr=subprocess.STDOUT ) +cmd_args = ["R", "CMD", "BATCH", path ] +proc = subprocess.Popen(cmd_args, stderr=subprocess.PIPE) +stdout, stderr = proc.communicate() +if proc.poll() != 0: + sys.stderr.write(stderr) os.unlink(path) - ]]></configfile> </configfiles> -</tool> + <help> + +This tool current supports two types of data from Synapse: Affy eset data and attachment files. +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 +save the first attached file as the output. + +Install R SynapseClient:: + + source('http://depot.sagebase.org/CRAN.R') + pkgInstall("synapseClient") + +`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>`_ + + </help> +</tool> \ No newline at end of file