changeset 1:7a60e992bfb0

Uploaded
author kellrott
date Tue, 24 Jul 2012 17:34:14 -0400
parents 83173eca36b7
children a104cc98359c
files synapse_download.xml
diffstat 1 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/synapse_download.xml	Tue Jul 24 17:34:14 2012 -0400
@@ -0,0 +1,74 @@
+<tool id="synapse_download" name="Synapse Download" version="1.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>
+	<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('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)
+}
+
+ent <- loadEntity(opt\$synid);
+
+if (!is.null(opt\$eset)) {
+	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);
+}
+if (!is.null(opt\$attach)) {
+	fpath <- file.path(ent\$cacheDir, ent\$files[[1]]);
+	file.copy(fpath, opt\$outfile, overwrite=T);
+}
+
+"""
+
+import tempfile
+import os
+import sys
+import subprocess
+
+h, path = tempfile.mkstemp()
+os.write(h,rcode)
+os.close(h)
+
+print subprocess.check_output( ["Rscript", path] + sys.argv[1:], stderr=subprocess.STDOUT )
+os.unlink(path)
+
+]]></configfile>
+	</configfiles>
+</tool>