Mercurial > repos > fubar > brokenandnotdeletablebyowneroradmin
changeset 12:d12728e33c3d
Changed to deliver a gz file - requires a new datatypes_conf.xml entry:
<datatype extension="gz" type="galaxy.datatypes.binary:Binary" mimetype="multipart/x-gzip" subclass="True" />
There's some wierd shit going on with filter values and such but it now all appears to be working ok
author | ross lazarus ross.lazarus@gmail.com |
---|---|
date | Sun, 03 Jun 2012 15:39:20 +1000 |
parents | a0a5d0757e39 |
children | 7725e4ab27e1 |
files | rgToolFactory.py rgToolFactory.xml |
diffstat | 2 files changed, 90 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/rgToolFactory.py Sat Jun 02 22:49:40 2012 +1000 +++ b/rgToolFactory.py Sun Jun 03 15:39:20 2012 +1000 @@ -67,28 +67,25 @@ self.pyfile = self.myname # crude but efficient - the cruft won't hurt much self.xmlfile = '%s.xml' % self.toolname self.sfile = '%s.%s' % (self.toolname,opts.interpreter) - if opts.output_dir or self.opts.make_Tool: # may not want these complexities + if opts.output_dir: # may not want these complexities self.tlog = os.path.join(opts.output_dir,"%s_runner.log" % self.toolname) artifactpath = os.path.join(opts.output_dir,'%s_run.script' % self.toolname) artifact = open(artifactpath,'w') artifact.write(self.script) artifact.write('\n') artifact.close() + if opts.make_Tool: # need this code and the user script for the tarball localscript = open(self.sfile,'w') localscript.write(self.script) localscript.close() shutil.copyfile(self.myname,'%s.py' % self.toolname) # for tool and for user - localpy = open('%s.py' % self.toolname,'w') - localpy.write(open(self.myname,'r').read()) self.cl = [] self.html = [] a = self.cl.append a(opts.interpreter) a('-') # use stdin - if opts.input_tab: - a(opts.input_tab) - if opts.output_tab: - a(opts.output_tab) + a(opts.input_tab) + a(opts.output_tab) self.outFormats = 'tabular' # TODO make this an option at tool generation time self.inputFormats = 'tabular' # TODO make this an option at tool generation time @@ -134,7 +131,7 @@ xdict['tooldesc'] = '' xdict['command_outputs'] = '' xdict['outputs'] = '' - if self.opts.input_tab: + if self.opts.input_tab <> 'None': xdict['command_inputs'] = '--input_tab "$input1"' xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/>' % self.inputFormats else: @@ -148,7 +145,7 @@ if self.opts.make_HTML: xdict['command_outputs'] += '--output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"' xdict['outputs'] += '<data format="html" name="html_file" label="${job_name}.html"/>\n' - if self.opts.output_tab: + if self.opts.output_tab <> 'None': xdict['command_outputs'] += '--output_tab "$tab_file"' xdict['outputs'] += '<data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats xdict['command'] = newCommand % xdict @@ -172,15 +169,16 @@ self.makeXML() tdir = self.toolname os.mkdir(tdir) - if self.opts.input_tab: # we may have test data? + if self.opts.input_tab <> 'None': # we may have test data? testdir = os.path.join(tdir,'test-data') os.mkdir(testdir) # make tests directory shutil.copyfile(self.opts.input_tab,os.path.join(testdir,'test1_in.tab')) - if self.opts.output_tab: + if self.opts.output_tab <> 'None': shutil.copyfile(self.opts.output_tab,os.path.join(testdir,'test1_out.tab')) if self.opts.make_HTML: shutil.copyfile(self.opts.output_html,os.path.join(testdir,'test1_out.html')) - shutil.copyfile(self.opts.tlog,os.path.join(testdir,'test1_out.log')) + if self.opts.output_dir: + shutil.copyfile(self.tlog,os.path.join(testdir,'test1_out.log')) shutil.copyfile(self.xmlfile,os.path.join(tdir,self.xmlfile)) shutil.copyfile(self.pyfile,os.path.join(tdir,'%s.py' % self.toolname)) shutil.copyfile(self.sfile,os.path.join(tdir,self.sfile)) @@ -188,8 +186,8 @@ tar = tarfile.open(tarpath, "w:gz") tar.add(tdir,arcname=self.toolname) tar.close() + shutil.copy(tarpath,self.opts.new_tool) shutil.rmtree(tdir) - self.makeHtml() # call this to return the new gzip inside the autogenerated html file ## TODO: replace with optional direct upload to local toolshed? return retval @@ -294,7 +292,7 @@ def run(self): """ """ - if self.opts.output_dir or self.opts.make_Tool: + if self.opts.output_dir: sto = open(self.tlog,'w') p = subprocess.Popen(' '.join(self.cl),shell=True,stdout=sto,stderr=sto,stdin=subprocess.PIPE,cwd=self.opts.output_dir) else: @@ -302,8 +300,9 @@ p.stdin.write(self.script) p.stdin.close() retval = p.wait() - if self.opts.make_HTML or self.opts.make_Tool: + if self.opts.output_dir: sto.close() + if self.opts.make_HTML: self.makeHtml() return retval @@ -321,14 +320,15 @@ 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('--input_tab',default="None") + a('--output_tab',default="None") a('--user_email',default=None) a('--bad_user',default=None) a('--make_Tool',default=None) a('--make_HTML',default=None) a('--help_text',default=None) a('--tool_desc',default=None) + a('--new_tool',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,'## Tool Factory expects a tool name - eg --tool_name=DESeq'
--- a/rgToolFactory.xml Sat Jun 02 22:49:40 2012 +1000 +++ b/rgToolFactory.xml Sun Jun 03 15:39:20 2012 +1000 @@ -6,29 +6,36 @@ #else: rgToolFactory.py --script_path "$runme" --interpreter "$interpreter" --tool_name "$tool_name" - #if $make_HTML.value=="yes" or $factory.make_Tool=="yes": + #if $make_TAB.value=="yes": + --output_tab "$tab_file" + #end if + #if $factory.make_Tool=="yes": + --make_Tool "$factory.make_Tool" + --help_text "$helpme" + --tool_desc "$factory.tool_desc" + --new_tool "$new_tool" + #end if + #if $make_HTML.value=="yes": --output_dir "$html_file.files_path" --output_html "$html_file" #end if #if $input1 != 'None': --input_tab "$input1" #end if #if $make_HTML.value=="yes": - --make_HTML "yes" - #end if - #if $make_TAB.value=="yes": - --output_tab "$tab_file" - #end if - #if $factory.make_Tool=="yes": - --make_Tool "$factory.make_Tool" - --help_text "$helpme" - --tool_desc "$factory.tool_desc" + --make_HTML "yes" #end if #end if </command> <inputs> <param name="input1" type="data" label="Select an optional input file from your history" optional="true" help="Your script probably needs an input - but if not, this can be left unassigned. Note that your script MUST be able to parse whatever format you choose!"/> - <param name="tool_name" type="text" value="My dynamic script" size="80" label="Title for job outputs" help="Supply a meaningful name here to remind you what the outputs contain"/> + <param name="tool_name" type="text" value="My dynamic script" size="80" label="Title for job outputs" help="Supply a meaningful name here to remind you what the outputs contain"> + <sanitizer> + <valid initial="string.letters,string.digits"> + <mapping initial="none"/> + </valid> + </sanitizer> + </param> <conditional name="factory"> <param name="make_Tool" type="select" label="Create a tar.gz file ready for local toolshed entry" help="Ready to deploy securely!"> <option value="yes">Yes</option> @@ -45,8 +52,8 @@ </param> </when> </conditional> - <param name="make_HTML" type="select" label="Create an HTML output with all script outputs collected together, with thumbnails of new PDF images, the script and a run log file" - help="This is useful for presenting complex outputs and is not needed if your script doesn't create anything other than a single tabular output"> + <param name="make_HTML" type="select" label="Create an HTML report with links to all output files and thumbnail links to PDF images" + help="Recommended for presenting complex outputs in an accessible manner"> <option value="yes">Yes</option> <option value="" selected="true">No</option> </param> @@ -60,8 +67,8 @@ <option value="python">python</option> <option value="perl (ugh)">perl</option> </param> - <param name="dynScript" label="Your Script Goes Here" type="text" value="" area="True" size="8x80" width="80" - help="CL parameters: input tabular file path (if selected) and optional output (if selected). Script must deal with these and write output (if any) to the right one"> + <param name="dynScript" label="Cut and paste the script to be executed here" type="text" value="" area="True" size="8x80" width="80" + help="Script must deal with two command line parameters: Path to input tabular file path (or 'None' if none selected) and path to output tabular history file (or 'None')."> <sanitizer> <valid initial="string.printable"> </valid> @@ -71,10 +78,13 @@ </inputs> <outputs> <data format="tabular" name="tab_file" label="${tool_name}.xls"> - <filter> make_TAB=="yes" </filter> + <filter>make_TAB == "yes"</filter> </data> <data format="html" name="html_file" label="${tool_name}.html"> - <filter>make_HTML=="yes" or factory.make_Tool=="yes"</filter> + <filter>make_HTML == "yes"</filter> + </data> + <data format="gz" name="new_tool" label="${tool_name}_tool.gz"> + <filter>factory['make_Tool'] == "yes"</filter> </data> </outputs> <configfiles> @@ -89,41 +99,39 @@ </configfile> </configfiles> <help> -**What it does** -This tool enables a user to paste and submit an arbitrary R/python/perl script to run in Galaxy. +**What it does** This tool enables a user to paste and submit an arbitrary R/python/perl script to Galaxy. + +**Input options** This version is limited to simple transformation or reporting requiring only a single input file selected from the history. -**Restrictions** -This tool will ONLY work if your user id has been added to the local copy's list of permitted users. -It should only ever be used on a private, personal Galaxy instance and you should edit this tool's source so your local login -is authorised to use it - *it will not run otherwise* +**Output options** Optional script outputs include one single new history tabular file, or for scripts that create multiple outputs, +a new HTML report linking all the files and images created by the script can be automatically generated. + +**Tool Generation option** Once the script is working with test data, this tool will optionally generate a new Galaxy tool in a gzip file +ready to upload to your local toolshed for sharing and installation. + +**Permission to to use this tool** must be explicitly granted by an administrator adding approved Galaxy user IDs to the local tool XML list of permitted users. *It will not run otherwise* .. class:: warningmark -**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. This tool (extremely) insecure and is only recommended for private/personnal Galaxy instances. +**Note to system administrators** This tool offers *NO* built in protection against malicious scripts and should only be installed on private/personnal Galaxy instances. +Under no circumstances should you allow any user to use this tool unless you really, really trust them with the power to do what they want as the Galaxy user. -Once you get the script working on some test data, you can generate a complete ready to run -Galaxy tool by setting the "Make tool" option to Yes. The resulting tarball will be ready to install -It will run just as securely as any other normal Galaxy tool - unlike this one used to generate it. +The tools generated by this tool will run just as securely as any other normal installed Galaxy tool but like any other new tools, should always be checked carefully before installation. .. class:: warningmark **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. +**Scripting conventions** The pasted script will be executed with the path to the (optional) input tabular data file path or NONE if you do not select one, and the path to the optional +output file or None if none is wanted, as the first and second command line parameters. The script must deal appropriately with these - see Rscript examples below. +Note that if an optional HTML output is selected, all the output files created by the script will be nicely presented as links, with pdf images linked as thumbnails in that output. This can be handy for complex scripts creating lots of output. -**Simple Rscript example** +**Simple examples** -A simple "filter" that takes an input file, does something and writes the results to a new tabular file might look like this:: +A simple Rscript "filter" showing how the command line parameters can be handled, takes an input file, does something (transpose in this case) and writes the results to a new tabular file:: + # transpose a tabular input file and write as a tabular output file ourargs = commandArgs(TRUE) inf = ourargs[1] outf = ourargs[2] @@ -131,19 +139,41 @@ outp = t(inp) write.table(outp,outf, quote=FALSE, sep="\t",row.names=F,col.names=F) -A more complex example takes no input file but generates a random heatmap pdf - you must make sure the option to create an HTML output file is +A more complex Rscript example takes no input file but generates a random heatmap pdf - you must make sure the option to create an HTML output file is turned on for this to work. The heatmap will be presented as a thumbnail linked to the pdf in the resulting HTML page:: + # note this script takes NO input or output because it generates random data foo = data.frame(a=runif(100),b=runif(100),c=runif(100),d=runif(100),e=runif(100),f=runif(100)) bar = as.matrix(foo) pdf( "heattest.pdf" ) heatmap(bar,main='Random Heatmap') dev.off() -**Attribution** -Copyright ross lazarus (ross.lazarus at gmail stop com) May 2012 -All rights reserved -Licensed under the LGPL for your pleasure +A Python example that reverses each row of a tabular file (you'll need to remove the leading spaces for this to work if cut and pasted into the script box):: + + # reverse order of columns in a tabular file + import sys + inp = sys.argv[1] + outp = sys.argv[2] + i = open(inp,'r') + o = open(outp,'w') + for row in i: + rs = row.rstrip().split('\t') + rs.reverse() + o.write('\t'.join(rs)) + o.write('\n') + i.close() + o.close() + + +**Attribution** Copyright Ross Lazarus (ross period lazarus at gmail period com) May 2012 + +All rights reserved. + +Licensed under the LGPL_ + +.. _LGPL: http://www.gnu.org/copyleft/lesser.html + </help> </tool>