# HG changeset patch
# User ross lazarus ross.lazarus@gmail.com
# Date 1338381394 -36000
# Node ID fda8032fe9894590430c4986550a078c1ded1da9
Initial checkin of dynamic script runner. Goal is to add code to generate a new toolshed entry once the script works correctly
diff -r 000000000000 -r fda8032fe989 images/dynamicScriptTool.png
Binary file images/dynamicScriptTool.png has changed
diff -r 000000000000 -r fda8032fe989 rgDynamicScriptWrapper.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rgDynamicScriptWrapper.py Wed May 30 22:36:34 2012 +1000
@@ -0,0 +1,253 @@
+# rgDynamicScriptWrapper.py
+# derived from
+# rgBaseScriptWrapper.py
+# to run some user supplied code
+# extremely dangerous
+# trusted users only - private site only
+# a list in the xml is searched - only users in the list can run this tool.
+#
+# copyright ross lazarus (ross.lazarus@gmail.com) May 2012
+#
+# all rights reserved
+# Licensed under the LGPL for your pleasure
+# Derived from rgDGE.py in May 2012
+# generalized to run required interpreter
+# to make your own tools based on a given script and interpreter such as perl or python
+# clone this and the corresponding xml wrapper
+# replace the parameters/inputs/outputs and the configfile contents with your script
+# Use the $foo syntax to place your parameter values inside the script to assign them - at run time, the script will be used as a template
+# and returned as part of the output to the user - with the right values for all the parameters.
+# Note that this assumes you want all the outputs arranged as a single Html file output
+# after this generic script runner runs your script with the specified interpreter,
+# it will collect all output files into the specified output_html, making thumbnails for all the pdfs it finds and making links for all the other files.
+
+import sys
+import shutil
+import subprocess
+import os
+import time
+import tempfile
+import optparse
+
+progname = os.path.split(sys.argv[0])[1]
+myversion = 'V000.1 May 2012'
+verbose = False
+debug = False
+
+# characters that are allowed but need to be escaped
+# also a test sandboxing of any R system commands
+# ultimately futile - we need to generate a new tool
+# which will have no new security problems!
+mapped_chars = { '>' :'__gt__',
+ '<' :'__lt__',
+ "'" :'__sq__',
+ '"' :'__dq__',
+ '{' :'__oc__',
+ '}' :'__cc__',
+ '@' : '__at__',
+ '\n' : '__cn__',
+ '\r' : '__cr__',
+ '\t' : '__tc__',
+ '#' : '__pd__',
+ '[' :'__ob__',
+ ']' :'__cb__',
+ '\t' : 'Xt',
+ 'systemCallsAreNotAllowed' : 'system'
+ }
+
+galhtmlprefix = """
+
+
+
\n')
+ html.append(galhtmlattr % (progname,timenow()))
+ html.append(galhtmlpostfix)
+ htmlf = file(self.opts.output_html,'w')
+ htmlf.write('\n'.join(html))
+ htmlf.write('\n')
+ htmlf.close()
+ return retval
+
+
+def main():
+ u = """
+ This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
+ rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
+
+ """
+ permitted_users = ['rlazarus@bakeridi.edu.au','akaspi@bakeridi.edu.au','mziemann@bakeridi.edu.edu']
+ op = optparse.OptionParser()
+ a = op.add_option
+ a('--script_path',default=None)
+ a('--tool_name',default=None)
+ a('--interpreter',default=None)
+ a('--output_dir',default=None)
+ a('--output_html',default=None)
+ a('--input_tab',default='NONE')
+ a('--output_tab',default='NONE')
+ a('--user_email',default=None)
+ a('--bad_user',default=None)
+ opts, args = op.parse_args()
+ assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin' % opts.bad_user
+ assert opts.tool_name,'## Dynamic script wrapper expects a tool name - eg --tool_name=DESeq'
+ assert opts.interpreter,'## Dynamic script wrapper expects an interpreter - eg --interpreter=Rscript'
+ assert os.path.isfile(opts.script_path),'## Dynamic script wrapper expects a script path - eg --script_path=foo.R'
+ if opts.output_dir:
+ try:
+ os.makedirs(opts.output_dir)
+ except:
+ pass
+ r = ScriptRunner(opts)
+ retcode = r.run()
+ if retcode:
+ sys.exit(retcode) # indicate failure to job runner
+
+
+if __name__ == "__main__":
+ main()
+
+
diff -r 000000000000 -r fda8032fe989 rgDynamicScriptWrapper.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rgDynamicScriptWrapper.xml Wed May 30 22:36:34 2012 +1000
@@ -0,0 +1,94 @@
+
+ DIY scripting
+
+#if ( $__user_email__ not in ['rlazarus@bakeridi.edu.au','mziemann@bakeridi.edu.au','akaspi@bakeridi.edu.au'] ):
+ rgDynamicScriptWrapper.py --bad_user $__user_email__
+ #else:
+ rgDynamicScriptWrapper.py --script_path "$runme" --interpreter "$interpreter"
+ --tool_name "$tool_name" --input_tab "$input1" --user_email "${__user_email__}"
+ #if $makeHTML.value=="yes":
+ --output_dir "$html_file.files_path" --output_html "$html_file"
+ #end if
+ #if $makeTAB.value=="yes":
+ --output_tab "$tab_file"
+ #end if
+#end if
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ makeTAB=="yes"
+
+
+ makeHTML=="yes"
+
+
+
+
+${dynScript}
+
+
+
+**What it does**
+This tool enables a user to paste and submit an arbitrary R/python/perl script to run in Galaxy.
+This is (extremely) insecure.
+
+**Restrictions**
+This tool will ONLY work if your user id has been added to the local copy's list of permitted users.
+Ask your friendly Galaxy administrator to edit this tool's source for you if you need this.
+
+**Note to system administrators**
+Under no circumstances should you allow any user to use this tool unless you really, really trust them to do
+no harm.
+
+**Use on public servers**
+is STRONGLY discouraged for obvious reasons
+
+**Scripting conventions**
+The pasted script will be executed.
+It will get the path to the (optional) input tabular data file path or NONE if you do not select one
+as the first command line parameter
+
+The script must write it's output as tab delimited text to the path found as the second command line parameter
+Note that if an optional HTML output is selected, all the output files spewed by your script will be nicely presented as links to the user.
+Any pdf images will automagically be converted to show thumbnails in that output.
+This can be handy for complex scripts creating lots of output.
+
+**Simple Rscript example**
+
+A simple "filter" that takes an input file, does something and writes the results to a new tabular file might look like this::
+
+ ourargs = commandArgs(TRUE)
+ inf = ourargs[1]
+ outf = ourargs[2]
+ inp = read.table(inf,head=F,row.names=NULL,sep='\t')
+ inp[,5] = runif ( nrow(inp) )
+ write.table(inp,outf, quote=FALSE, sep="\t",row.names=F,col.names=F)
+
+
+
+
+
+
+