Repository 'tool_factory_2'
hg clone https://toolshed.g2.bx.psu.edu/repos/fubar/tool_factory_2

Changeset 28:ad564ab3cf7b (2020-07-31)
Previous changeset 27:c4e3cf28545f (2020-07-31) Next changeset 29:6db39cbc3242 (2020-08-07)
Commit message:
Uploaded
added:
toolfactory/LICENSE
toolfactory/README.md
toolfactory/images/dynamicScriptTool.png
toolfactory/rgToolFactory2.py
toolfactory/rgToolFactory2.xml
toolfactory/test-data/infile.tabular
toolfactory/test-data/reverseargp2.toolshed.gz
toolfactory/test-data/reverseargp2_test1_output.xls
toolfactory/test-data/runme.py
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/LICENSE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/toolfactory/LICENSE Fri Jul 31 23:00:31 2020 -0400
b
b"@@ -0,0 +1,504 @@\n+GNU LESSER GENERAL PUBLIC LICENSE\n+                       Version 2.1, February 1999\n+\n+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n+ Everyone is permitted to copy and distribute verbatim copies\n+ of this license document, but changing it is not allowed.\n+\n+(This is the first released version of the Lesser GPL.  It also counts\n+ as the successor of the GNU Library Public License, version 2, hence\n+ the version number 2.1.)\n+\n+                            Preamble\n+\n+  The licenses for most software are designed to take away your\n+freedom to share and change it.  By contrast, the GNU General Public\n+Licenses are intended to guarantee your freedom to share and change\n+free software--to make sure the software is free for all its users.\n+\n+  This license, the Lesser General Public License, applies to some\n+specially designated software packages--typically libraries--of the\n+Free Software Foundation and other authors who decide to use it.  You\n+can use it too, but we suggest you first think carefully about whether\n+this license or the ordinary General Public License is the better\n+strategy to use in any particular case, based on the explanations below.\n+\n+  When we speak of free software, we are referring to freedom of use,\n+not price.  Our General Public Licenses are designed to make sure that\n+you have the freedom to distribute copies of free software (and charge\n+for this service if you wish); that you receive source code or can get\n+it if you want it; that you can change the software and use pieces of\n+it in new free programs; and that you are informed that you can do\n+these things.\n+\n+  To protect your rights, we need to make restrictions that forbid\n+distributors to deny you these rights or to ask you to surrender these\n+rights.  These restrictions translate to certain responsibilities for\n+you if you distribute copies of the library or if you modify it.\n+\n+  For example, if you distribute copies of the library, whether gratis\n+or for a fee, you must give the recipients all the rights that we gave\n+you.  You must make sure that they, too, receive or can get the source\n+code.  If you link other code with the library, you must provide\n+complete object files to the recipients, so that they can relink them\n+with the library after making changes to the library and recompiling\n+it.  And you must show them these terms so they know their rights.\n+\n+  We protect your rights with a two-step method: (1) we copyright the\n+library, and (2) we offer you this license, which gives you legal\n+permission to copy, distribute and/or modify the library.\n+\n+  To protect each distributor, we want to make it very clear that\n+there is no warranty for the free library.  Also, if the library is\n+modified by someone else and passed on, the recipients should know\n+that what they have is not the original version, so that the original\n+author's reputation will not be affected by problems that might be\n+introduced by others.\n+\n+  Finally, software patents pose a constant threat to the existence of\n+any free program.  We wish to make sure that a company cannot\n+effectively restrict the users of a free program by obtaining a\n+restrictive license from a patent holder.  Therefore, we insist that\n+any patent license obtained for a version of the library must be\n+consistent with the full freedom of use specified in this license.\n+\n+  Most GNU software, including some libraries, is covered by the\n+ordinary GNU General Public License.  This license, the GNU Lesser\n+General Public License, applies to certain designated libraries, and\n+is quite different from the ordinary General Public License.  We use\n+this license for certain libraries in order to permit linking those\n+libraries into non-free programs.\n+\n+  When a program is linked with a library, whether statically or using\n+a shared library, the combination of the two is legally speaking a\n+combined work, a derivative "..b'oes not specify a\n+license version number, you may choose any version ever published by\n+the Free Software Foundation.\n+\n+  14. If you wish to incorporate parts of the Library into other free\n+programs whose distribution conditions are incompatible with these,\n+write to the author to ask for permission.  For software which is\n+copyrighted by the Free Software Foundation, write to the Free\n+Software Foundation; we sometimes make exceptions for this.  Our\n+decision will be guided by the two goals of preserving the free status\n+of all derivatives of our free software and of promoting the sharing\n+and reuse of software generally.\n+\n+                            NO WARRANTY\n+\n+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\n+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\n+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\n+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY\n+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\n+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\n+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\n+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n+\n+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\n+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\n+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\n+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\n+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\n+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\n+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\n+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\n+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\n+DAMAGES.\n+\n+                     END OF TERMS AND CONDITIONS\n+\n+           How to Apply These Terms to Your New Libraries\n+\n+  If you develop a new library, and you want it to be of the greatest\n+possible use to the public, we recommend making it free software that\n+everyone can redistribute and change.  You can do so by permitting\n+redistribution under these terms (or, alternatively, under the terms of the\n+ordinary General Public License).\n+\n+  To apply these terms, attach the following notices to the library.  It is\n+safest to attach them to the start of each source file to most effectively\n+convey the exclusion of warranty; and each file should have at least the\n+"copyright" line and a pointer to where the full notice is found.\n+\n+    {description}\n+    Copyright (C) {year} {fullname}\n+\n+    This library is free software; you can redistribute it and/or\n+    modify it under the terms of the GNU Lesser General Public\n+    License as published by the Free Software Foundation; either\n+    version 2.1 of the License, or (at your option) any later version.\n+\n+    This library is distributed in the hope that it will be useful,\n+    but WITHOUT ANY WARRANTY; without even the implied warranty of\n+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+    Lesser General Public License for more details.\n+\n+    You should have received a copy of the GNU Lesser General Public\n+    License along with this library; if not, write to the Free Software\n+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301\n+    USA\n+\n+Also add information on how to contact you by electronic and paper mail.\n+\n+You should also get your employer (if you work as a programmer) or your\n+school, if any, to sign a "copyright disclaimer" for the library, if\n+necessary.  Here is a sample; alter the names:\n+\n+  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n+  library `Frob\' (a library for tweaking knobs) written by James Random\n+  Hacker.\n+\n+  {signature of Ty Coon}, 1 April 1990\n+  Ty Coon, President of Vice\n+\n+That\'s all there is to it!\n'
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/README.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/toolfactory/README.md Fri Jul 31 23:00:31 2020 -0400
b
@@ -0,0 +1,166 @@
+*WARNING before you start*
+
+ Install this tool on a private Galaxy ONLY
+ Please NEVER on a public or production instance

+Updated august 2014 by John Chilton adding citation support
+
+Updated august 8 2014 to fix bugs reported by Marius van den Beek
+
+Please cite the resource at
+http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573?ijkey=lczQh1sWrMwdYWJ&keytype=ref
+if you use this tool in your published work.
+
+**Short Story**
+
+This is an unusual Galaxy tool capable of generating new Galaxy tools.
+It works by exposing *unrestricted* and therefore extremely dangerous scripting
+to all designated administrators of the host Galaxy server, allowing them to
+run scripts in R, python, sh and perl over multiple selected input data sets,
+writing a single new data set as output.
+
+*You have a working r/python/perl/bash script or any executable with positional or argparse style parameters*
+
+It can be turned into an ordinary Galaxy tool in minutes, using a Galaxy tool.
+
+
+**Automated generation of new Galaxy tools for installation into any Galaxy**
+
+A test is generated using small sample test data inputs and parameter settings you supply.
+Once the test case outputs have been produced, they can be used to build a
+new Galaxy tool. The supplied script or executable is baked as a requirement
+into a new, ordinary Galaxy tool, fully workflow compatible out of the box.
+Generated tools are installed via a tool shed by an administrator
+and work exactly like all other Galaxy tools for your users.
+
+**More Detail**
+
+To use the ToolFactory, you should have prepared a script to paste into a
+text box, or have a package in mind and a small test input example ready to select from your history
+to test your new script.
+
+```planemo test rgToolFactory2.xml --galaxy_root ~/galaxy --test_data ~/galaxy/tools/tool_makers/toolfactory/test-data``` works for me
+
+There is an example in each scripting language on the Tool Factory form. You
+can just cut and paste these to try it out - remember to select the right
+interpreter please. You'll also need to create a small test data set using
+the Galaxy history add new data tool.
+
+If the script fails somehow, use the "redo" button on the tool output in
+your history to recreate the form complete with broken script. Fix the bug
+and execute again. Rinse, wash, repeat.
+
+Once the script runs sucessfully, a new Galaxy tool that runs your script
+can be generated. Select the "generate" option and supply some help text and
+names. The new tool will be generated in the form of a new Galaxy datatype
+*toolshed.gz* - as the name suggests, it's an archive ready to upload to a
+Galaxy ToolShed as a new tool repository.
+
+Once it's in a ToolShed, it can be installed into any local Galaxy server
+from the server administrative interface.
+
+Once the new tool is installed, local users can run it - each time, the script
+that was supplied when it was built will be executed with the input chosen
+from the user's history. In other words, the tools you generate with the
+ToolFactory run just like any other Galaxy tool,but run your script every time.
+
+Tool factory tools are perfect for workflow components. One input, one output,
+no variables.
+
+*To fully and safely exploit the awesome power* of this tool,
+Galaxy and the ToolShed, you should be a developer installing this
+tool on a private/personal/scratch local instance where you are an
+admin_user. Then, if you break it, you get to keep all the pieces see
+https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
+
+**Installation**
+This is a Galaxy tool. You can install it most conveniently using the
+administrative "Search and browse tool sheds" link. Find the Galaxy Main
+toolshed at https://toolshed.g2.bx.psu.edu/ and search for the toolfactory
+repository. Open it and review the code and select the option to install it.
+
+If you can't get the tool that way, the xml and py files here need to be
+copied into a new tools
+subdirectory such as tools/toolfactory Your tool_conf.xml needs a new entry
+pointing to the xml
+file - something like::
+
+  <section name="Tool building tools" id="toolbuilders">
+    <tool file="toolfactory/rgToolFactory.xml"/>
+  </section>
+
+If not already there,
+please add:
+<datatype extension="toolshed.gz" type="galaxy.datatypes.binary:Binary"
+mimetype="multipart/x-gzip" subclass="True" />
+to your local data_types_conf.xml.
+
+
+**Restricted execution**
+
+The tool factory tool itself will then be usable ONLY by admin users -
+people with IDs in admin_users in universe_wsgi.ini **Yes, that's right. ONLY
+admin_users can run this tool** Think about it for a moment. If allowed to
+run any arbitrary script on your Galaxy server, the only thing that would
+impede a miscreant bent on destroying all your Galaxy data would probably
+be lack of appropriate technical skills.
+
+**What it does** 
+
+This is a tool factory for simple scripts in python, R and
+perl currently. Functional tests are automatically generated. How cool is that.
+
+LIMITED to simple scripts that read one input from the history. Optionally can
+write one new history dataset, and optionally collect any number of outputs
+into links on an autogenerated HTML index page for the user to navigate -
+useful if the script writes images and output files - pdf outputs are shown
+as thumbnails and R's bloated pdf's are shrunk with ghostscript so that and
+imagemagik need to be available.
+
+Generated tools can be edited and enhanced like any Galaxy tool, so start
+small and build up since a generated script gets you a serious leg up to a
+more complex one.
+
+**What you do**
+
+You paste and run your script, you fix the syntax errors and
+eventually it runs. You can use the redo button and edit the script before
+trying to rerun it as you debug - it works pretty well.
+
+Once the script works on some test data, you can generate a toolshed compatible
+gzip file containing your script ready to run as an ordinary Galaxy tool in
+a repository on your local toolshed. That means safe and largely automated
+installation in any production Galaxy configured to use your toolshed.
+
+**Generated tool Security**
+
+Once you install a generated tool, it's just
+another tool - assuming the script is safe. They just run normally and their
+user cannot do anything unusually insecure but please, practice safe toolshed.
+Read the code before you install any tool. Especially this one - it is really scary.
+
+**Send Code**
+
+Patches and suggestions welcome as bitbucket issues please?
+
+**Attribution**
+
+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
+
+http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573?ijkey=lczQh1sWrMwdYWJ&keytype=ref
+
+**Licensing**
+
+Copyright Ross Lazarus 2010
+ross lazarus at g mail period com
+
+All rights reserved.
+
+Licensed under the LGPL
+
+**Obligatory screenshot**
+
+http://bitbucket.org/fubar/galaxytoolmaker/src/fda8032fe989/images/dynamicScriptTool.png
+
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/images/dynamicScriptTool.png
b
Binary file toolfactory/images/dynamicScriptTool.png has changed
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/rgToolFactory2.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/toolfactory/rgToolFactory2.py Fri Jul 31 23:00:31 2020 -0400
[
b'@@ -0,0 +1,502 @@\n+# rgToolFactory.py\n+# see https://github.com/fubar2/toolfactory\n+#\n+# copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012\n+#\n+# all rights reserved\n+# Licensed under the LGPL\n+# suggestions for improvement and bug fixes welcome at https://github.com/fubar2/toolfactory\n+#\n+# July 2020: BCC was fun and I feel like rip van winkle after 5 years.\n+# Decided to\n+# 1. Fix the toolfactory so it works - done for simplest case\n+# 2. Fix planemo so the toolfactory function works\n+# 3. Rewrite bits using galaxyxml functions where that makes sense - done\n+#\n+# removed all the old complications including making the new tool use this same script\n+# galaxyxml now generates the tool xml https://github.com/hexylena/galaxyxml\n+# No support for automatic HTML file creation from arbitrary outputs\n+# TODO: add option to run that code as a post execution hook\n+# TODO: add additional history input parameters - currently only one\n+\n+import sys\n+import subprocess\n+import shutil\n+import os\n+import time\n+import tempfile\n+import argparse\n+import tarfile\n+import re\n+import galaxyxml.tool as gxt\n+import galaxyxml.tool.parameters as gxtp\n+import logging\n+\n+\n+progname = os.path.split(sys.argv[0])[1]\n+myversion = \'V2.1 July 2020\'\n+verbose = True\n+debug = True\n+toolFactoryURL = \'https://github.com/fubar2/toolfactory\'\n+ourdelim = \'~~~\'\n+\n+\n+def timenow():\n+    """return current time as a string\n+    """\n+    return time.strftime(\'%d/%m/%Y %H:%M:%S\', time.localtime(time.time()))\n+\n+\n+def quote_non_numeric(s):\n+    """return a prequoted string for non-numerics\n+    useful for perl and Rscript parameter passing?\n+    """\n+    try:\n+        _ = float(s)\n+        return s\n+    except ValueError:\n+        return \'"%s"\' % s\n+\n+\n+html_escape_table = {\n+    "&": "&amp;",\n+    ">": "&gt;",\n+    "<": "&lt;",\n+    "$": r"\\$"\n+}\n+\n+\n+def html_escape(text):\n+    """Produce entities within text."""\n+    return "".join(html_escape_table.get(c, c) for c in text)\n+\n+\n+def html_unescape(text):\n+    """Revert entities within text. Multiple character targets so use replace"""\n+    t = text.replace(\'&amp;\', \'&\')\n+    t = t.replace(\'&gt;\', \'>\')\n+    t = t.replace(\'&lt;\', \'<\')\n+    t = t.replace(\'\\\\$\', \'$\')\n+    return t\n+\n+\n+def parse_citations(citations_text):\n+    """\n+    """\n+    citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]\n+    citation_tuples = []\n+    for citation in citations:\n+        if citation.startswith("doi"):\n+            citation_tuples.append(("doi", citation[len("doi"):].strip()))\n+        else:\n+            citation_tuples.append(\n+                ("bibtex", citation[len("bibtex"):].strip()))\n+    return citation_tuples\n+\n+\n+class ScriptRunner:\n+    """Wrapper for an arbitrary script\n+    uses galaxyxml\n+\n+    """\n+\n+    def __init__(self, args=None):\n+        """\n+        prepare command line cl for running the tool here\n+        and prepare elements needed for galaxyxml tool generation\n+        """\n+        lastclredirect = None\n+        self.cl = []\n+        aCL = self.cl.append\n+        if args.output_dir:  # simplify for the tool tarball\n+            os.chdir(args.output_dir)\n+        self.args = args\n+        # a sanitizer now does this but..\n+        self.tool_name = re.sub(\'[^a-zA-Z0-9_]+\', \'\', args.tool_name)\n+        self.tool_id = self.tool_name\n+        self.xmlfile = \'%s.xml\' % self.tool_name\n+        if self.args.interpreter_name == "Executable":  # binary - no need\n+            aCL(self.args.exe_package)  # this little CL will just run\n+        else:  # a script has been provided\n+            rx = open(self.args.script_path, \'r\').readlines()\n+            # remove pesky dos line endings if needed\n+            rx = [x.rstrip() for x in rx]\n+            self.script = \'\\n\'.join(rx)\n+            fhandle, self.sfile = tempfile.mkstemp(\n+                prefix=self.tool_name, suffix=".%s" % (args.interpreter_name))\n+            # use self.sfile as script source for Popen\n+            tscript = '..b' shell=False, stdout=sto,\n+                               stderr=ste, cwd=self.args.output_dir)\n+            sto.close()\n+            ste.close()\n+            tmp_stderr = open(self.elog, \'rb\')\n+            err = \'\'\n+            buffsize = 1048576\n+            try:\n+                while True:\n+                    err += str(tmp_stderr.read(buffsize))\n+                    if not err or len(err) % buffsize != 0:\n+                        break\n+            except OverflowError:\n+                pass\n+            tmp_stderr.close()\n+            retval = p.returncode\n+        else:  # work around special case of simple scripts that take stdin and write to stdout\n+            sti = open(self.infile_paths[0], \'rb\')\n+            sto = open(self.args.output_tab, \'wb\')\n+            # must use shell to redirect\n+            p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti)\n+            retval = p.returncode\n+            sto.close()\n+            sti.close()\n+        if self.args.output_dir:\n+            if p.returncode != 0 and err:  # problem\n+                sys.stderr.write(err)\n+        logging.debug(\'run done\')\n+        return retval\n+\n+\n+def main():\n+    """\n+    This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:\n+    <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"\n+    </command>\n+    """\n+    parser = argparse.ArgumentParser()\n+    a = parser.add_argument\n+    a(\'--script_path\', default=\'\')\n+    a(\'--tool_name\', default=None)\n+    a(\'--interpreter_name\', default=None)\n+    a(\'--interpreter_version\', default=None)\n+    a(\'--exe_package\', default=None)\n+    a(\'--exe_package_version\', default=None)\n+    a(\'--output_dir\', default=\'./\')\n+    a(\'--input_files\', default=[], action="append")\n+    a("--input_formats", default="tabular")\n+    a(\'--output_tab\', default=None)\n+    a(\'--output_format\', default=\'tabular\')\n+    a(\'--output_cl\', default=None)\n+    a(\'--user_email\', default=\'Unknown\')\n+    a(\'--bad_user\', default=None)\n+    a(\'--make_Tool\', default=None)\n+    a(\'--help_text\', default=None)\n+    a(\'--tool_desc\', default=None)\n+    a(\'--new_tool\', default=None)\n+    a(\'--tool_version\', default=None)\n+    a(\'--include_dependencies\', default=None)\n+    a(\'--citations\', default=None)\n+    a(\'--additional_parameters\', dest=\'additional_parameters\',\n+      action=\'append\', default=[])\n+    a(\'--edit_additional_parameters\', action="store_true", default=False)\n+    a(\'--parampass\', default="positional")\n+    args = parser.parse_args()\n+    assert not args.bad_user, \'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file\' % (\n+        args.bad_user, args.bad_user)\n+    assert args.tool_name, \'## Tool Factory expects a tool name - eg --tool_name=DESeq\'\n+    assert (args.interpreter_name or args.exe_package), \'## Tool Factory wrapper expects an interpreter - eg --interpreter_name=Rscript or an executable package findable by the dependency management package\'\n+    assert args.exe_package or (len(args.script_path) > 0 and os.path.isfile(\n+        args.script_path)), \'## Tool Factory wrapper expects a script path - eg --script_path=foo.R if no executable\'\n+    if args.output_dir:\n+        try:\n+            os.makedirs(args.output_dir)\n+        except BaseException:\n+            pass\n+    args.input_files = [x.replace(\'"\', \'\').replace("\'", \'\')\n+                        for x in args.input_files]\n+    # remove quotes we need to deal with spaces in CL params\n+    for i, x in enumerate(args.additional_parameters):\n+        args.additional_parameters[i] = args.additional_parameters[i].replace(\n+            \'"\', \'\')\n+    r = ScriptRunner(args)\n+    if args.make_Tool:\n+        retcode = r.makeTooltar()\n+    else:\n+        retcode = r.run()\n+    if retcode:\n+        sys.exit(retcode)  # indicate failure to job runner\n+\n+\n+if __name__ == "__main__":\n+    main()\n'
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/rgToolFactory2.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/toolfactory/rgToolFactory2.xml Fri Jul 31 23:00:31 2020 -0400
[
b'@@ -0,0 +1,449 @@\n+<tool id="rgTF2" name="toolfactory" version="2.00">\n+  <description>Scripts into tools</description>\n+  <macros>\n+     <xml name="addpar">\n+        <param name="edit_params" type="select" display="radio" label="Add all additional parameters to the generated tool form so they are user editable?" \n+             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">\n+            <option value="yes">Yes, allow user to edit all additional parameters on the generated tool form</option>\n+            <option value="no" selected="true">No - use the fixed values for all additional parameters - no user editing</option>\n+        </param>\n+        <repeat name="additional_history_inputs" title="Additional Current history data files to pass in to the script - Use the \'+\' button to add as many as needed"\n+             help="Each of these will become a history item selector as input for users of the new tool you are making">\n+            <param name="input_files" type="data" format="data" label="Select an input file from your history" optional="true" size="120" multiple="false"\n+               help=""/>\n+            <param name="input_formats" type="select" multiple="true" label="Select the datatype(s) that your tool/script accepts as input"\n+              help="If your datatype is not listed here, it has to be added in galaxy\'s datatypes_conf.xml" value="tabular">\n+               <options from_parameter="tool.app.datatypes_registry.upload_file_formats">\n+                <column name="value" index="0"/>\n+               </options>\n+            </param>\n+            <param name="param_label" type="text" value="" label="This will become the user prompt for the form so please make it informative" size="60" \n+             help="Note that \'~~~\' is an internal delimiter so must not appear in this text field - please work around this technical limitation" >\n+            <sanitizer invalid_char="">\n+              <valid initial="string.printable"> <remove value=\'~~~\'/> </valid>\n+              <mapping initial="none"/>\n+            </sanitizer>\n+            </param>\n+            <param name="param_help" type="text" value="parameter_help" label="This will become help text on the form."\n+             help="Note that three consecutive ~ cannot be used in this text field - please work around this technical limitation" size="60">\n+            <sanitizer invalid_char="">\n+              <valid initial="string.printable"> <remove value=\'~~~\'/> </valid>\n+              <mapping initial="none"/>\n+            </sanitizer>\n+            </param>\n+            <param name="CL" type="text" size="60" label="Positional: ordinal integer. Argparse: argument name."\n+              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="">          \n+            </param>\n+        </repeat>\n+        <repeat name="additional_parameters" title="Pass additional parameters to the script"\n+             help="See examples below to see how these can be parsed by scripts in the various languages">\n+          <param name="param_name" type="text" value="parameter_name" label="Choose the name for this parameter" size="60">\n+            <sanitizer invalid_char="">\n+              <valid initial="string.letters,string.digits"/>\n+              <mapping initial="none"/> \n+            </sanitizer>\n+          </param>\n+          <param name="param_type" type="select" label="Select the type for this parameter">\n+            <option value="text" selected="true">text</option>\n+            <option value="integer">integer</option>\n+            <option value="float">float</option>\n+          </param>\n+          <param name="param_value" type="text" value="parameter_value" label="Enter this parameter\'s default value" size="60"\n+            help="Note th'..b'e=\'output1\' file=\'reverseargp2_test1_output.xls\' compare=\'diff\' lines_diff = \'10\'/>\n+    <output name=\'new_tool\' file="reverseargp2.toolshed.gz" compare="sim_size" delta="600" />\n+</test>\n+</tests>\n+<help>\n+    \n+.. class:: warningmark\n+\n+**Details and attribution** \n+(see GTF_)\n+\n+**Local Admins ONLY** \n+Only users whose IDs found in the local admin_user configuration setting in universe_wsgi.ini can run this tool.\n+\n+**If you find a bug** \n+Please raise an issue at the bitbucket repository GTFI_\n+\n+**What it does** \n+This tool optionally generates normal workflow compatible first class Galaxy tools\n+\n+Generated tools can run existing binary packages that become requirements, existing scripts, or new scripts pasted into this tool form.\n+Pasted scripts are written so they are part of the new tool and cannot be adjusted by the downstream user.\n+Binary packages are managed by the dependency subsystem - conda usually, so anything in bioconda or conda_forge is available for example.\n+\n+Any number of parameters can be built into the new tool form for passing in to the script or executable at runtime.\n+These can be editable by the downstream user or baked in.\n+\n+When you run this tool, your executable or script and supplied parameter values will be run to produce a canonical\n+set of outputs - these are used to construct a test for the new tool.\n+\n+If tool generation is required, a new tarball compatible with any Galaxy toolshed is created.\n+It can be unpacked in your galaxy/tools directory and manually added to tool_conf.xml, or\n+installed into any toolshed from where it can be installed into your Galaxy.\n+\n+\n+.. class:: warningmark\n+\n+**Note to system administrators** \n+This tool offers *NO* built in protection against malicious scripts. It should only be installed on private/personnal Galaxy instances.\n+Admin_users will have the power to do anything they want as the Galaxy user if you install this tool.\n+\n+.. class:: warningmark\n+\n+**Use on public servers**  is STRONGLY discouraged for obvious reasons\n+\n+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.\n+We recommend that you follow the good code hygiene practices associated with safe toolshed practices.\n+\n+Here\'s a sample python script that can be cut and pasted into the tool form, suitable for positional parameter passing:\n+\n+::\n+\n+    # reverse order of text by row\n+    import sys\n+    inp = sys.argv[1]\n+    outp = sys.argv[2]\n+    i = open(inp,\'r\').readlines()\n+    o = open(outp,\'w\')\n+    for row in i:\n+      rs = row.rstrip()\n+      rs = list(rs)\n+      rs.reverse()\n+      o.write(\'\'.join(rs))\n+      o.write(\'\\n\')\n+    o.close()\n+\n+With argparse style parameters:\n+    \n+::\n+\n+    # reverse order of text by row\n+    import argparse\n+    parser = argparse.ArgumentParser()\n+    a = parser.add_argument\n+    a(\'--infile\',default=\'\')\n+    a(\'--outfile\',default=None)\n+    args = parser.parse_args()\n+    inp = args.infile\n+    outp = args.outfile\n+    i = open(inp,\'r\').readlines()\n+    o = open(outp,\'w\')\n+    for row in i:\n+      rs = row.rstrip()\n+      rs = list(rs)\n+      rs.reverse()\n+      o.write(\'\'.join(rs))\n+      o.write(\'\\n\')\n+    o.close()\n+     \n+\n+Paper_ :\n+\n+Creating re-usable tools from scripts: The Galaxy Tool Factory\n+Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team\n+Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573\n+\n+**Licensing** \n+\n+Copyright Ross Lazarus (ross period lazarus at gmail period com) May 2012\n+All rights reserved.\n+Licensed under the LGPL_\n+\n+.. _LGPL: http://www.gnu.org/copyleft/lesser.html\n+.. _GTF:  https://bitbucket.org/fubar/galaxytoolfactory\n+.. _GTFI:  https://bitbucket.org/fubar/galaxytoolfactory/issues\n+.. _Paper: http://bioinformatics.oxfordjournals.org/cgi/reprint/bts573\n+\n+\n+</help>\n+<citations>\n+    <citation type="doi">10.1093/bioinformatics/bts573</citation>\n+</citations>\n+</tool>\n+\n+\n'
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/test-data/infile.tabular
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/toolfactory/test-data/infile.tabular Fri Jul 31 23:00:31 2020 -0400
b
@@ -0,0 +1,7 @@
+0.1
+0.00001
+0.2
+0.3
+0.004
+0.5
+0.000000002
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/test-data/reverseargp2.toolshed.gz
b
Binary file toolfactory/test-data/reverseargp2.toolshed.gz has changed
b
diff -r c4e3cf28545f -r ad564ab3cf7b toolfactory/test-data/runme.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/toolfactory/test-data/runme.py Fri Jul 31 23:00:31 2020 -0400
b
@@ -0,0 +1,19 @@
+# reverse order of columns in a tabular file
+import argparse
+parser = argparse.ArgumentParser()
+a = parser.add_argument
+a('--infile',default='')
+a('--outfile',default=None)
+a('--prefix',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('%s:%s' % (args.prefix,''.join(rs)))
+ o.write('\n')
+o.close()