view synapse_create.xml @ 3:93c4d2fad9af

Fixing bugs and bad code
author Kyle Ellrott <kellrott@gmail.com>
date Wed, 24 Oct 2012 23:31:13 -0700
parents 83173eca36b7
children
line wrap: on
line source

<tool id="synapse_create" name="Synapse Create" version="2.0.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="select" size="90" label="Name">
				<option value="name">Name</option>
				<option value="parentId">ParentID</option>
				<option value="description">Description</option>
				<option value="species">Species</option>
				<option value="numSamples">Number of Samples</option>
				<option value="disease">Disease</option>
				<option value="tissueType">Tissue Type</option>
			</param>
			<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">
				<sanitizer>
					<valid initial="string.printable">
						<remove value="&quot;"/>
					</valid>
					<mapping initial="none">
						<add source="&quot;" target="\&quot;"/>
					</mapping>
				</sanitizer>
			</param>		
		</repeat>
		
	</inputs>
	<outputs>
		<data format="txt" name="outfile" />
	</outputs>
	<configfiles>
        	<configfile name="script_file"><![CDATA[#!/usr/bin/env python
rcode="""
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"))
}


ent <- ${etype}( list(name=galaxyClean("${name}")) )

#for $a in $annotations:
annotValue(ent, galaxyClean("${a.name}")) <- galaxyClean("${a.value}")
#end for

#for a in $properties:
propertyValue(ent, galaxyClean("${a.name}")) <- galaxyClean("${a.value}")
#end for

ent <- createEntity(ent)

#if $attachment != 'None' 
#if $attachment_name == '':
ent <- addFile(ent, galaxyClean("${attachment}"))
#else
ent <- addFile(ent, galaxyClean("${attachment}"), galaxyClean("${attachment_name}"))
#end if
#end if

ent <- storeEntity(ent)

write(properties(ent)\$id, file=galaxyClean("${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>
		<help>

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) &lt;https://sagebionetworks.jira.com/wiki/display/SYNR/How+to+configure+automatic+login&gt;`_ 

	</help>

</tool>