view toolfactory/rgToolFactory2.xml @ 31:69eed330c91f draft

Uploaded
author fubar
date Fri, 07 Aug 2020 07:55:35 -0400
parents 6f48315c32c1
children 4d578c8c1613
line wrap: on
line source

<tool id="rgTF2" name="toolfactory" version="2.00">
  <description>Scripts into tools</description>
  <macros>
     <xml name="io">
        <repeat name="history_inputs" title="Add a data file from your history to pass in to the script. Use the '+' button as needed"
             help="USE SMALL SAMPLES because these will be used for the new tool's test. The names will become a history item selector as input for users of the new tool you are making">
            <param name="input_files" type="data" format="data" label="Select an input file from your history" optional="true" size="120" multiple="false"
               help=""/>
            <param name="input_formats" type="select" multiple="true" label="Select the datatype(s) that your tool/script accepts as input"
              help="If your datatype is not listed here, it has to be added in galaxy's datatypes_conf.xml" value="tabular">
               <options from_parameter="tool.app.datatypes_registry.upload_file_formats">
                <column name="value" index="0"/>
               </options>
            </param>
            <param name="input_label" type="text" value="" label="This will become the user prompt for the form so please make it informative" size="60" 
             help="Note that '~~~' is an internal delimiter so must not appear in this text field - please work around this technical limitation" >
            <sanitizer invalid_char="">
              <valid initial="string.printable"> <remove value='~~~'/> </valid>
              <mapping initial="none"/>
            </sanitizer>
            </param>
            <param name="input_help" type="text" value="parameter_help" label="This will become help text on the form."
             help="Note that three consecutive ~ cannot be used in this text field - please work around this technical limitation" size="60">
            <sanitizer invalid_char="">
              <valid initial="string.printable"> <remove value='~~~'/> </valid>
              <mapping initial="none"/>
            </sanitizer>
            </param>
            <param name="input_CL" type="text" size="60" label="Positional: ordinal integer. Argparse: argument name."
              help="If you will pass positional parameters, enter the integer ordinal for this parameter. If Argparse style, '--' will be prepended or '-' if single character" value="">          
            </param>
        </repeat>
        <repeat name="history_outputs" title="Add a tool run output file to the user's history from your tool - Use the '+' button to add as many as needed"
             help="The name will become a history item for users of the new tool you are making containing one of it's outputs">
            <param name="history_name" type="text" label="Name for this output to appear in new history" optional="false" size="120" 
               help=""/>
            <param name="history_format" type="select" multiple="false" label="Select the datatype for this output"
              help="If your datatype is not listed here, it has to be added in galaxy's datatypes_conf.xml" value="tabular">
               <options from_parameter="tool.app.datatypes_registry.upload_file_formats">
                <column name="value" index="0"/>
               </options>
            </param>
            <param name="history_CL" type="text" size="60" label="Positional: ordinal integer. Argparse: argument name expected for this output parameter"
              help="If positional parameters, enter the integer ordinal expected for this parameter. If Argparse style, '--' will be prepended or '-' if single character" value="">          
            </param>
        </repeat>
     </xml>
     <xml name="additparam">
        <param name="edit_params" type="select" display="radio" label="Add any additional parameters to the generated tool form so they are user editable?" 
             help="If no (default), users will NOT be able to alter any additional parameters. If yes, these will appear on the tool form as text fields with no validation or sanitizing">
            <option value="yes">Yes, allow user to edit all additional parameters on the generated tool form</option>
            <option value="no" selected="true">No - use the fixed values for all additional parameters - no user editing</option>
        </param>

        <repeat name="additional_parameters" title="Pass additional parameters to the script"
             help="See examples below to see how these can be parsed by scripts in the various languages">
          <param name="param_name" type="text" value="parameter_name" label="Choose the name for this parameter" size="60">
            <sanitizer invalid_char="">
              <valid initial="string.letters,string.digits"/>
              <mapping initial="none"/> 
            </sanitizer>
          </param>
          <param name="param_type" type="select" label="Select the type for this parameter">
            <option value="text" selected="true">text</option>
            <option value="integer">integer</option>
            <option value="float">float</option>
          </param>
          <param name="param_value" type="text" value="" label="Enter this parameter's default value" size="60"
            help="Note that '~~~' is an internal delimiter must not appear in this text field - please work around this technical limitation" >
            <sanitizer invalid_char="">
              <valid initial="string.printable"> <remove value='~~~'/> </valid>
              <mapping initial="none"/>
            </sanitizer>
          </param>
          <param name="param_label" type="text" value="parameter_label" label="Enter this parameter's label for the form" size="60" 
             help="Note that '~~~' is an internal delimiter so must not appear in this text field - please work around this technical limitation" >
            <sanitizer invalid_char="">
              <valid initial="string.printable"> <remove value='~~~'/> </valid>
              <mapping initial="none"/>
            </sanitizer>
          </param>
          <param name="param_help" type="text" value="parameter_help" label="Help for this parameter"
             help="Note that three consecutive ~ cannot be used in this text field - please work around this technical limitation" size="60">
            <sanitizer invalid_char="">
              <valid initial="string.printable"> <remove value='~~~'/> </valid>
              <mapping initial="none"/>
            </sanitizer>
          </param>
          <param name="param_CL" type="text" size="60" label="Positional order (must be integer > 1) or Argument name to be prefixed with '--' or '-' if single letter"
              help="Using positional parameters, enter the integer ordinal for this parameter on the command line. Using Argparse style, '--' will be prepended on the CL" value="">           
          </param>
        </repeat>
     </xml>
     <xml name="builtin_dynpar">
          <param name="interpreter_version" type="text" value="" 
          label="Specific interpreter version to match dependency (Conda) repositories - e.g. for python '3.8.5' Latest if empty"/>
            <param name="exe_package_version" type="text" value=""
              label="Executable package version to match dependency (Conda) repositories - e.g. for bwa='0.7.17'. Latest if empty"/>
          <param name="dynScript" label="Cut and paste the script to be executed here" type="text" value="Script goes here" area="True"  
              help="If there are parameters, either positional or argparse style, the script must parse and use them appropriately">
              <sanitizer>
                 <valid initial="string.printable">
                 </valid>
                 <mapping initial="none"/>
              </sanitizer>
          </param>
    </xml>
    <xml name="dynpar">
          <param name="interpreter_version" type="text" value=""
          label="Specific interpreter version to match dependency (Conda) repositories - e.g. for python '3.8.5' Latest if empty"/>
            <param name="exe_package_version" type="text" value="" 
              label="Executable package version to match dependency (Conda) repositories - e.g. for bwa='0.7.17'. Latest if empty"/>
          <param name="dynScript" label="Cut and paste the script to be executed here" type="text" value="Script goes here" area="True" 
              help="If there are parameters, either positional or argparse style, the script must parse and use them appropriately">
              <sanitizer>
                 <valid initial="string.printable">
                 </valid>
                 <mapping initial="none"/>
              </sanitizer>
          </param>
    </xml>
  </macros>
   <requirements>
      <requirement type="package">python</requirement>
  </requirements>
  <command interpreter="python"><![CDATA[
#import os
#set dev_env = os.environ.get('GALAXY_DEVELOPMENT_ENVIRONMENT', '0') == '1'
#if not $dev_env and ( $__user_email__ not in $__admin_users__ ):
$__tool_directory__/rgToolFactory2.py --bad_user $__user_email__
 #else:
$__tool_directory__/rgToolFactory2.py 
--runmode "$interexe.interpreter"
   #if str($interexe.interpreter)=="Executable" or str($interexe.interpreter)=="system":
--exe_package="$interexe.exe_package" 
    #if str($interexe.exe_package_version) != 'None' :  
--exe_package_version="$interexe.exe_package_version" 
    #end if
   #else:
--interpreter_name="$interexe.interpreter" --script_path "$runme" 
     #if str($interexe.interpreter_version) != 'None':
--interpreter_version="$interexe.interpreter_version"
     #end if
   #end if
--tool_name="$tool_name"  --user_email="$__user_email__" --citations="$citeme"  --parampass="$ppass.parampass"
   #if str($makeMode.make_Tool)=="yes":
--make_Tool="$makeMode.make_Tool"
--tool_desc="$makeMode.tool_desc"
--tool_version="$makeMode.tool_version"
--help_text="$helpme"
--new_tool="$new_tool"
   #end if
   #if $ppass.parampass != '0':
     #if str($ppass.edit_params) == "yes":
--edit_additional_parameters  
     #end if
     #for apar in $ppass.additional_parameters:
--additional_parameters="$apar.param_name~~~$apar.param_value~~~$apar.param_label~~~$apar.param_help~~~$apar.param_type~~~$apar.param_CL"
     #end for
   #end if

     #for $intab in $ppass.history_inputs:
--input_files="$intab.input_files~~~$intab.input_CL~~~$intab.input_formats~~~$intab.input_label~~~$intab.input_help"
     #end for


     #for $otab in $ppass.history_outputs:
--output_files "$otab.history_name~~~$otab.history_format~~~$otab.history_CL"
     #end for
 #end if 
]]></command>
 <configfiles>
  <configfile name="runme">

#if $interexe.interpreter != "Executable" and $interexe.interpreter != "system" :
${interexe.dynScript}
#else:
$tool_name
#end if
 </configfile>
 <configfile name="helpme">
    #if $makeMode.make_Tool == "yes":
${makeMode.help_text}
    #else
$tool_name help goes here
    #end if
 </configfile>
 <configfile name="citeme">
#if $makeMode.make_Tool == "yes":
    #for $citation in $makeMode.citations:
        #if $citation.citation_type.type == "bibtex":
            **ENTRY**bibtex
            ${citation.citation_type.bibtex}
        #else
            **ENTRY**doi
            ${citation.citation_type.doi}
        #end if
    #end for
#end if
 </configfile>
  </configfiles>
  <inputs>

   <param name="tool_name" type="text" value="tool1"   label="New tool ID and title for outputs" size="60"
         help="This will become the toolshed repository name so choose thoughtfully to avoid namespace clashes with other tool writers. lower case, digits and underscores only">
        <sanitizer invalid_char="">
            <valid initial="string.letters,string.digits">
                <add value="_"/>
            </valid>
        </sanitizer>
    </param>    
    <conditional name="interexe">
        <param name="interpreter" type="select" label="For binaries, choose 'Executable'. Otherwise choose the interpreter for your code"
        help = "If executable, the supplied package will become a requirement so must match the tool dependency resolver package name - conda is the default.">
            <option value="Executable" selected="true">An executable binary to be provided and managed by the Conda dependency management subsystem</option>
            <option value="python">python</option>
            <option value="r-base">Rscript</option>
            <option value="perl">perl</option>
            <option value="bash">bash</option>
            <option value="sh">sh</option>
            <option value="system" >A system executable found on the path such as awk/sed</option>
            <option value="specialtestcaseinterpreterpython" >for testing only - do not use me please</option>
        </param>
        <when value="Executable">
            <param name="exe_package" type="text" value="" label="Executable package name in dependency (Conda) repositories - e.g. 'bwa'" size="60" optional="false"/>
            <param name="exe_package_version" type="text" value="" label="Executable package version to match dependency (Conda) repositories - e.g. for bwa='0.7.17'. Latest if empty" size="60"/>
        </when>
        <when value="system">
            <param name="exe_package" type="text" value="" label="System executable to run" size="60" optional="false"/>
            <param name="exe_package_version" type="text" value=""
              label="Executable package version to match dependency (Conda) repositories - e.g. for bwa='0.7.17'. Latest if empty"/>
        </when>
        <when value = "python">
           <expand macro="dynpar" />
        </when>
        <when value = "r-base">
           <expand macro="dynpar" />
        </when>
        <when value = "perl">
           <expand macro="dynpar" />
        </when>
        <when value = "bash">
           <expand macro="builtin_dynpar" />
        </when>
        <when value = "sh">
           <expand macro="builtin_dynpar" />
        </when>
         <when value = "specialtestcaseinterpreterpython">
           <expand macro="builtin_dynpar" />
        </when>
    </conditional>
    <conditional name = "ppass">

        <param name="parampass"  type="select" display="radio" label="Command line parameter passing method to use">
            <option value="argparse" selected="true">Argparse style: on CL in the form of --inputbam="foo.bam" if label below is "inputbam"</option>
            <option value="positional">Positional: on CL in the order defined on this screen -> "... foo.bam bar.idx zot.xls"</option>
            <option value="0">No parameters needed because tool reads selected history file from STDIN and writes to STDOUT for history"</option>
        </param>
        <when value = "argparse">
            <expand macro="io" />
            <expand macro="additparam" />
        </when>
        <when value = "positional">
            <expand macro="io" />
            <expand macro="additparam" />
        </when>
        <when value = "0">
             <expand macro="io"/>
        </when>
    </conditional>    
    <conditional name="makeMode">
        <param name="make_Tool" type="select" display="radio" label="Generate new tool as  a tar.gz file ready to upload to a toolshed repository" 
          help="Generate a toolshed archive - upload to a toolshed from where it can be auto-installed via the Galaxy admin functions" 
          size="60">
        <option value="yes">Generate a Galaxy ToolShed compatible toolshed.gz</option>
        <option value="" selected="true">No. Just run the script please</option>
        </param>
        <when value = "yes">
            <param name="tool_version" label="Tool Version - bump this to warn users trying to redo old analyses" type="text" value="0.01"
            help="If you change your script and regenerate the 'same' tool, you should inform Galaxy (and users) by changing (bumping is traditional) this number"/>
            <param name="tool_desc" label="Tool Description" type="text" value="" size="40" 
             help="Supply a brief tool description for the Galaxy tool menu entry (optional - appears after the tool name)" />
            <param name="help_text" label="Tool form documentation and help text for users" type="text" area="true" 
             size="8x120" value="**What it Does**" 
             help="Supply the brief user documentation to appear on the new tool form as reStructured text - http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html" >           
                <sanitizer>
                    <valid initial="string.printable">
                    </valid>
                    <mapping initial="none"/>
                </sanitizer>
            </param>
            <repeat name="citations" title="Citation">
                <conditional name="citation_type">
                    <param name="type" type="select" display="radio" label="Citation Type">
                        <option value="doi">DOI</option>
                        <option value="bibtex">BibTeX</option>
                    </param>
                    <when value="doi">
                        <param name="doi" label="DOI" type="text" value="" 
                        help="Supply a DOI (e.g. doi: 10.1111/j.1740-9713.2007.00258.x) that should be cited when this tool is used in published research." />
                    </when>
                    <when value="bibtex">
                        <param name="bibtex" label="BibTex" type="text" area="true" size="8x120"
                            help="Supply a BibTex entry that should be cited when this tool is used in published research." value="" >
                            <sanitizer>
                                <valid initial="string.printable">
                                </valid>
                                <mapping initial="none"/>
                            </sanitizer>
                        </param>
                    </when>
                </conditional>
            </repeat>
        </when>
        <when value = "">
        </when>
    </conditional> 
  </inputs>
  <outputs>
    <collection name="ToolFactory_Outputs" type="list" label="Toolfactory ${tool_name} test run outputs" >
       <discover_datasets pattern="__name__" directory="tfout/test-data" format="txt"/>
    </collection>
    <data format="tgz" name="new_tool" label="${tool_name}_toolshed.tgz">
        <filter>makeMode['make_Tool'] == "yes"</filter>
    </data>
  </outputs>
<tests>
<test>
    <param name="input_files" value="input1_sample" />
    <param name="input_CL" value="1" />
    <param name="input_formats" value="txt" />
    <param name="input_label" value="input" />
    <param name="input_help" value="help" />
    <param name="tool_name" value="pyrevpos" />
    <param name="parampass" value="positional" />
    <param name="make_Tool" value="yes" />
    <param name="tool_version" value="0.01" />
    <param name="tool_desc" value="positional reverse" />
    <param name="help_text" value="help text goes here" />
    <param name="interpreter" value="python"/>
    <param name="history_name" value="output2_sample" />
    <param name="history_format" value="txt" />
    <param name="history_CL" value="2" />
    <param name="runme" value="pyrevpos.python"/> 
    <output_collection name="ToolFactory_Outputs" type="list">
        <element name="output2_sample_sample" file="output2_sample" ftype="txt" compare="diff" lines_diff = "10" />
    </output_collection>
    <output name="new_tool" file="toolfactory_pyrevpos_tgz_sample" compare="sim_size" delta="6000" />
</test>
</tests>
<help>

.. class:: warningmark

**Details and attribution** 
(see GTF_)

**Local Admins ONLY** 
Only users whose IDs found in the local admin_user configuration setting in universe_wsgi.ini can run this tool.

**If you find a bug** 
Please raise an issue, or even better, submit a pull request fixing it, on the github repository GTF_

**What it does** 
This tool optionally generates normal workflow compatible first class Galaxy tools

Generated tools can run existing binary packages that become requirements, existing scripts, or new scripts pasted into this tool form.
Pasted scripts are written so they are part of the new tool and cannot be adjusted by the downstream user.
Binary packages are managed by the dependency subsystem - conda usually, so anything in bioconda or conda_forge is available for example.

Any number of parameters can be built into the new tool form for passing in to the script or executable at runtime.
These can be editable by the downstream user or baked in.

When you run this tool, your executable or script and supplied parameter values will be run to produce a canonical
set of outputs - these are used to construct a test for the new tool.

If tool generation is required, a new tarball compatible with any Galaxy toolshed is created.
It can be unpacked in your galaxy/tools directory and manually added to tool_conf.xml, or
installed into any toolshed from where it can be installed into your Galaxy.


.. class:: warningmark

**Note to system administrators** 
This tool offers *NO* built in protection against malicious scripts. It should only be installed on private/personnal Galaxy instances.
Admin_users will have the power to do anything they want as the Galaxy user if you install this tool.

.. class:: warningmark

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

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.
We recommend that you follow the good code hygiene practices associated with safe toolshed practices.

Here's a sample python script that can be cut and pasted into the tool form, suitable for positional parameter passing:

::

    # reverse order of text by row
    import sys
    inp = sys.argv[1]
    outp = sys.argv[2]
    i = open(inp,'r').readlines()
    o = open(outp,'w')
    for row in i:
      rs = row.rstrip()
      rs = list(rs)
      rs.reverse()
      o.write(''.join(rs))
      o.write('\n')
    o.close()

With argparse style parameters:
    
::

    # reverse order of text by row
    import argparse
    parser = argparse.ArgumentParser()
    a = parser.add_argument
    a('--infile',default='')
    a('--outfile',default=None)
    args = parser.parse_args()
    inp = args.infile
    outp = args.outfile
    i = open(inp,'r').readlines()
    o = open(outp,'w')
    for row in i:
      rs = row.rstrip()
      rs = list(rs)
      rs.reverse()
      o.write(''.join(rs))
      o.write('\n')
    o.close()
     

Paper_ :

Creating re-usable tools from scripts: The Galaxy Tool Factory
Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team
Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573

**Licensing** 

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
.. _GTF:  https://github.com/fubar2/toolfactory
.. _Paper: http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573


</help>
<citations>
    <citation type="doi">10.1093/bioinformatics/bts573</citation>
</citations>
</tool>