view rgToolFactory.xml @ 23:6146509c9c2d

mostly working again
author ross lazarus ross.lazarus@gmail.com
date Tue, 05 Jun 2012 23:25:35 +1000
parents c23e53f768ed
children 8289ebc513ab
line wrap: on
line source

<tool id="rgTF" name="Tool Factory" version="0.05">
  <description>Makes scripts into tools</description>
  <command interpreter="python">
#if ( $__user_email__ not in ['yourID@email','ross.lazarus@gmail.com'] ):
     rgToolFactory.py --bad_user $__user_email__
  #else:
    rgToolFactory.py --script_path "$runme" --interpreter "$interpreter" 
     --tool_name "$tool_name"  
    #if $make_TAB.value=="yes":
       --output_tab "$tab_file"
    #end if
    #if $makeMode.make_Tool=="yes":
      --make_Tool "$makeMode.make_Tool"
      --help_text "$helpme"
      --tool_desc "tool_desc"
      --new_tool "$new_tool"
    #end if
    #if $make_HTML.value=="yes":
      --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"
    #end if
    #if $input1 != 'None':
       --input_tab "$input1"
    #end if
#end if 
  </command>
  <inputs>
    <param name="input1"  type="data"  label="Select an input file from your history" optional="true"
       help="Most scripts will need an input - your script MUST be ready for 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">
        <sanitizer>
            <valid initial="string.letters,string.digits">
                <mapping initial="none"/>
            </valid>
        </sanitizer>
    </param>
    <conditional name="makeMode">
        <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>
        <option value="" selected="true">Not yet, it's still broken</option>
        </param>
        <when value = "yes">
            <param name="tool_desc" type="text" width="120" value="" help="Supply a brief tool description for the Galaxy tool menu entry (optional - appears after the tool name)" />
            <param name="help_text" type="text" area="true" size="8x80" width="120" value="**What it Does**" help="Supply the brief user documentation to appear on the new tool form as reStructured text" >           
                <sanitizer>
                    <valid initial="string.printable">
                    </valid>
                    <mapping initial="none"/>
                </sanitizer>
            </param>
        </when>
        <when value = "">

        </when>
    </conditional> 
    <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. Turn off for simple tools so they just create one output">
        <option value="yes" selected="true">Yes</option>
        <option value="">No</option>
    </param>


    <param name="make_TAB" type="select" label="Create a new (default tabular) history output" 
         help="This is useful if your script creates a single new tabular file you want to appear in the history after the tool executes">
        <option value="yes" selected="true">Make a new history output file</option>
        <option value="">No new history output file. Will use an HTML file</option>
    </param>
    <param name="out_format" type="select" label="Galaxy datatype for your tool's output file" help="You may need to edit the xml to extend this list">
    <option value="tabular" selected="true">Tabular</option>
    <option value="interval">Interval</option>
    <option value="gz">gz</option>
    <option value="text">text</option>
    </param>
    <param name="interpreter" type="select" label="Select the interpreter for your code. This must be available on the path of the execution host">
        <option value="Rscript" selected="true">Rscript</option>
        <option value="python">python</option>
        <option value="perl (ugh)">perl</option>
    </param>   
    <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>
         <mapping initial="none"/>
      </sanitizer>
     </param>
  </inputs>
  <outputs>
    <data format="tabular" name="tab_file" label="${tool_name}.${out_format}">
        <filter>make_TAB=="yes"</filter>
        <change_format>
            <when input="out_format" value="interval"  format="interval" />
            <when input="out_format" value="gz" format="gz" />
            <when input="out_format" value="text"  format="text"  />
         </change_format>
    </data>
    <data format="html" name="html_file" label="${tool_name}.html">
        <filter>make_HTML == "yes"</filter>
    </data>
    <data format="toolshed.gz" name="new_tool" label="${tool_name}.toolshed.gz">
        <filter>makeMode['make_Tool'] == "yes"</filter>
    </data>
  </outputs>
<configfiles>
<configfile name="runme">
${dynScript}
</configfile>

<configfile name="helpme">
#if $makeMode.make_Tool == "yes":
${makeMode.help_text}
#end if
</configfile>
</configfiles>
<help>
**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.

**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** 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.

.. class:: warningmark

**Use on public servers**  is STRONGLY discouraged for obvious reasons

**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::

 # 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)::

 # 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>