diff synapse_create.xml @ 0:83173eca36b7

Uploaded
author kellrott
date Tue, 24 Jul 2012 17:33:11 -0400
parents
children 93c4d2fad9af
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/synapse_create.xml	Tue Jul 24 17:33:11 2012 -0400
@@ -0,0 +1,92 @@
+<tool id="synapse_create" name="Synapse Create" version="1.0">
+	<description>Create Synapse</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="name" type="text" size="90" label="Name"/>		
+		<param name="attachment" type="data" optional="true" label="Attachment"/>
+		<param name="attachment_name" type="text" size="90" optional="true" label="Attachment Name"/>
+		<param name="etype" type="select" label="Entity Type">
+			<option value="Project">Project</option>
+			<option value="Study">Study</option>
+			<option value="Data">Data</option>			
+		</param>
+		<repeat name="properties" title="Properties">
+			<param name="name" type="text" size="90" label="Name"/>
+			<param name="value" type="text" size="90" label="Value">
+				<sanitizer>
+					<valid initial="string.printable">
+						<remove value="&quot;"/>
+					</valid>
+					<mapping initial="none">
+						<add source="&quot;" target="\&quot;"/>
+					</mapping>
+				</sanitizer>
+			</param>		
+		</repeat>
+		
+		<repeat name="annotations" title="Annotations">
+			<param name="name" type="text" size="90" label="Name"/>
+			<param name="value" type="text" size="90" label="Value"/>		
+		</repeat>
+		
+	</inputs>
+	<outputs>
+		<data format="txt" name="outfile" />
+	</outputs>
+	<configfiles>
+        	<configfile name="script_file"><![CDATA[#!/usr/bin/env python
+rcode="""
+require(synapseClient)
+
+if (nchar("$user") > 0 && nchar("$pass") > 0) {
+	synapseLogin(username="$user", password="$pass")
+}
+
+ent <- ${etype}( list(name="${name}") )
+
+#for $a in $annotations:
+annotValue(ent, "${a.name}") <- "${a.value}"
+#end for
+
+#for a in $properties:
+propertyValue(ent, "${a.name}") <- "${a.value}"
+#end for
+
+ent <- createEntity(ent)
+
+#if $attachment != 'None' 
+#if $attachment_name == '':
+ent <- addFile(ent, "${attachment}")
+#else
+ent <- addFile(ent, "${attachment}", "${attachment_name}")
+#end if
+#end if
+
+ent <- storeEntity(ent)
+
+write(properties(ent)\$id, file="${outfile}");
+
+"""
+
+
+import tempfile
+import os
+import sys
+import subprocess
+
+h, path = tempfile.mkstemp()
+os.write(h,rcode)
+os.close(h)
+
+proc = subprocess.Popen( ["Rscript", path] + sys.argv[1:], stderr=subprocess.PIPE, stdout=subprocess.PIPE )
+(stdoutdata, stderrdata) = proc.communicate()
+if proc.returncode:
+	sys.stderr.write(stderrdata)
+sys.stdout.write(stdoutdata)
+os.unlink(path)
+
+]]></configfile>
+	</configfiles>
+</tool>