changeset 13:7725e4ab27e1

Adding tests - problem to find the script - needs a fixed string somewhere. Updated readme
author ross lazarus ross.lazarus@gmail.com
date Sun, 03 Jun 2012 22:25:46 +1000
parents d12728e33c3d
children 6f36c696afa5
files README.txt rgToolFactory.py
diffstat 2 files changed, 121 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/README.txt	Sun Jun 03 15:39:20 2012 +1000
+++ b/README.txt	Sun Jun 03 22:25:46 2012 +1000
@@ -1,10 +1,10 @@
-= WARNING before you start = This tool should only ever be installed on a private Galaxy instance - NEVER use it on a public 
+**WARNING before you start** This tool should only ever be installed on a private Galaxy instance - Please NEVER use it on a public 
 Galaxy because the risks are too awful to contemplate let alone manage. You have been warned.
 
-== Motivation == Simple transformation, filtering or reporting scripts get written, run and lost every day in most busy labs 
+**Motivation** Simple transformation, filtering or reporting scripts get written, run and lost every day in most busy labs 
 - even ours where Galaxy is in use. This 'dark script matter' is pervasive and generally not reproducible.
 
-== Benefits == For our group, this allows Galaxy to fill that important dark script gap - all those "small" bioinformatics 
+**Benefits** For our group, this allows Galaxy to fill that important dark script gap - all those "small" bioinformatics 
 tasks. Once a user has a working R (or python or perl) script that does something Galaxy cannot currently do (eg transpose a 
 tabular file) and takes parameters the way Galaxy supplies them (see example below), they:
 
@@ -23,29 +23,78 @@
 
 7. Ask the local admin to check the new tool to confirm it's not evil and install it in the local production galaxy
 
+**What it does** This tool enables a user to paste and submit an arbitrary R/python/perl script to Galaxy. 
 New mantra: Galaxy can efficiently soak up all your lab's dark script matter and make it reproducible and shareable.
 
-== Proof of concept ==
+
+**Input options** This version is limited to simple transformation or reporting requiring only a single input file selected from the history.
+
+**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*
 
-=== Obligatory screenshot ===
-[[http://bitbucket.org/fubar/galaxytoolmaker/src/fda8032fe989/images/dynamicScriptTool.png|proof of concept screengrab]]
+**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.
+
+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.
+
+**Use on public servers**  is STRONGLY discouraged for obvious reasons
 
-=== Sample Rscript ===
-As a working example, this trivial Rscript transposes a tabular file:
+**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 examples**
+
+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::
 
-{{{
-  ourargs = commandArgs(TRUE)
-  inf = ourargs[1]
-  outf = ourargs[2]
-  inp = read.table(inf,head=F,row.names=NULL,sep='\t')
-  outp = t(inp)
-  write.table(outp,outf, quote=FALSE, sep="\t",row.names=F,col.names=F)
-}}}
+ # transpose a tabular input file and write as a tabular output file
+ ourargs = commandArgs(TRUE)
+ inf = ourargs[1]
+ outf = ourargs[2]
+ inp = read.table(inf,head=F,row.names=NULL,sep='\t')
+ outp = t(inp)
+ write.table(outp,outf, quote=FALSE, sep="\t",row.names=F,col.names=F)
+
+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()
+
+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)::
 
-== Licensing ==
-All project artefacts are copyright Ross Lazarus (ross period lazarus at gmail period com) 2012
+ # 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.
-You may accept a license from me under the LGPL if you want to use this code for any reason.
-Please see http://www.gnu.org/licenses/lgpl.html for details
+
+Licensed under the LGPL_
 
 
+**Obligatory screenshot**
+http://bitbucket.org/fubar/galaxytoolmaker/src/fda8032fe989/images/dynamicScriptTool.png
+
--- a/rgToolFactory.py	Sun Jun 03 15:39:20 2012 +1000
+++ b/rgToolFactory.py	Sun Jun 03 22:25:46 2012 +1000
@@ -93,7 +93,52 @@
     def makeXML(self):
         """
         Create a Galaxy xml tool wrapper for the new script as a string to write out
-        fixme - use templating or something less fugly than this
+        fixme - use templating or something less fugly than this.
+        Here's an example of what we produce
+
+        <tool id="reverse" name="reverse" version="0.01">
+            <description>a tabular file</description>
+            <command interpreter="python">
+            reverse.py --script_path "$runMe" --interpreter "python" 
+            --tool_name "reverse" --input_tab "$input1" --output_tab "$tab_file" 
+            </command>
+            <inputs>
+            <param name="input1"  type="data" format="tabular" label="Select a suitable input file from your history"/><param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="reverse"/>
+
+            </inputs>
+            <outputs>
+            <data format="tabular" name="tab_file" label="${job_name}"/>
+
+            </outputs>
+            <help>
+            
+**What it Does**
+
+Reverse the columns in a tabular file
+
+            </help>
+            <configfiles>
+            <configfile name="runMe">
+            
+# 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()
+ 
+
+            </configfile>
+            </configfiles>
+            </tool>
+        
         """    
         newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="0.01">
             %(tooldesc)s
@@ -112,13 +157,18 @@
             %(script)s
             </configfile>
             </configfiles>
+            %(tooltests)s
             </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
                
         newCommand="""<command interpreter="python">
             %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" 
             --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s 
             </command>""" # may NOT be an input or htmlout
-            
+        tooltests = """<tests><test>
+        <param name="input1" value="%s" ftype="%s"/>
+        <param name="job_name" value="test1"/>
+        <param name="runMe" value="$runMe"/>
+        </test><tests>"""
         xdict = {}
         xdict['script'] = self.script # configfile is least painful way to embed script to avoid external dependencies
         if self.opts.help_text: