Mercurial > repos > kellrott > synapse_interface
view 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 source
<tool id="synapse_download" name="Synapse Download" version="2.0.0"> <description>Download Synapse Entity</description> <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> </param> </inputs> <outputs> <data format="txt" name="outfile" label="${synid}" /> </outputs> <configfiles> <configfile name="script_file"><![CDATA[#!/usr/bin/env python rcode = """ library(affy) require(synapseClient) 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); } if (nchar("$user") && nchar("$pass")) { synapseLogin(username=galaxyClean("$user"), password=galaxyClean("$pass")) } 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="$outfile") write.table(eset, "$outfile", col.names=FALSE, sep="\\t", quote=FALSE, append=TRUE); } if ("a" == "$data_type") { fpath <- file.path(ent\$cacheDir, ent\$files[[1]]); file.copy(fpath, "$outfile", overwrite=T); } """ import tempfile import os import sys import subprocess h, path = tempfile.mkstemp() os.write(h,rcode) os.close(h) 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> <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>