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

Changeset 30:fb3fa6a2874d (2014-08-28)
Previous changeset 29:bff4c9bfabc7 (2014-08-07) Next changeset 31:8e19698d597e (2014-08-28)
Commit message:
Citations added (thanks John!) and a few more output formats for Alistair Chilcott
modified:
README.txt
rgToolFactory.py
rgToolFactory.xml
added:
rgToolFactoryMultIn.py
rgToolFactoryMultIn.xml
b
diff -r bff4c9bfabc7 -r fb3fa6a2874d README.txt
--- a/README.txt Thu Aug 07 22:11:02 2014 -0400
+++ b/README.txt Thu Aug 28 02:22:39 2014 -0400
b
@@ -16,6 +16,15 @@
 freeze the supplied script into a new, ordinary Galaxy tool that runs it over a single input file, 
 working just like any other Galaxy tool for your users. 
 
+If you use the Html output option, please ensure that sanitize_all_html is set to False and 
+uncommented in universe_wsgi.ini - it should show:
+
+# By default, all tool output served as 'text/html' will be sanitized
+sanitize_all_html = False
+
+
+*More Detail*
+
 To use the ToolFactory, you should have prepared a script to paste into a text box,
 and a small test input example ready to select from your history to test your new script.
 There is an example in each scripting language on the Tool Factory form. You can just
@@ -40,31 +49,6 @@
 
 Tool factory tools are perfect for workflow components. One input, one output, no variables.
 
-*Reasons to read further*
-
-If you use Galaxy to support your research;
-
-You and fellow users are sometimes forced to take data out of Galaxy, process it with ugly
-little perl/awk/sed/R... scripts and put it back;
-
-You do this when you can't do some transformation in Galaxy (the 90/10 rule);
-
-You don't have enough developer resources for wrapping dozens of even relatively simple tools;
-
-Your research and your institution would be far better off if those feral scripts were all tucked 
-safely in your local toolshed and Galaxy histories.
-
-*The good news* If it can be trivially scripted, it can be running safely in your
-local Galaxy via your own local toolshed in a few minutes - with functional tests.
-
-
-*Value proposition* The ToolFactory allows Galaxy to efficiently take over most of your lab's 
-dark script matter, making it reproducible in Galaxy and shareable through the ToolShed.
-
-That's what this tool does. You paste a simple script and the tool returns 
-a new, real Galaxy tool, ready to be installed from the local toolshed to local servers.
-Scripts can be wrapped and online literally within minutes.
-
 *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
@@ -72,9 +56,10 @@
 
 ** Installation **
 This is a Galaxy tool. You can install it most conveniently using the administrative "Search and browse tool sheds" link.
-Find the Galaxy Test toolshed (not main) and search for the toolfactory repository.
+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::
@@ -85,11 +70,8 @@
 
 If not already there (I just added it to datatypes_conf.xml.sample), please add:
 <datatype extension="toolshed.gz" type="galaxy.datatypes.binary:Binary" mimetype="multipart/x-gzip" subclass="True" />
-to your local data_types_conf.xml. 
-
-Ensure that html sanitization is set to False and uncommented in universe_wsgi.ini
-
-You'll have to restart the server for the new tool to be available.
+to your local data_types_conf.xml.
+)
 
 Of course, R, python, perl etc are needed on your path if you want to test scripts using those interpreters.
 Adding new ones to this tool code should be easy enough. Please make suggestions as bitbucket issues and code.
@@ -137,18 +119,6 @@
 
 Patches and suggestions welcome as bitbucket issues please? 
 
-long route to June 2012 product
-derived from an integrated script model  
-called rgBaseScriptWrapper.py
-Note to the unwary:
-  This tool allows arbitrary scripting on your Galaxy as the Galaxy user
-  There is nothing stopping a malicious user doing whatever they choose
-  Extremely dangerous!!
-  Totally insecure. So, trusted users only
-
-
-
-
 copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
 
 all rights reserved
b
diff -r bff4c9bfabc7 -r fb3fa6a2874d rgToolFactory.py
--- a/rgToolFactory.py Thu Aug 07 22:11:02 2014 -0400
+++ b/rgToolFactory.py Thu Aug 28 02:22:39 2014 -0400
[
@@ -134,6 +134,19 @@
            stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
 
 
+def parse_citations(citations_text):
+    """
+    """
+    citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
+    citation_tuples = []
+    for citation in citations:
+        if citation.startswith("doi"):
+            citation_tuples.append( ("doi", citation[len("doi"):].strip() ) )
+        else:
+            citation_tuples.append( ("bibtex", citation[len("bibtex"):].strip() ) )
+    return citation_tuples
+
+
 class ScriptRunner:
     """class is a wrapper for an arbitrary script
     """
@@ -264,6 +277,10 @@
 %(help)s
 
 </help>
+<citations>
+    %(citations)s
+    <citation type="doi">10.1093/bioinformatics/bts573</citation>
+</citations>
 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
 
         newCommand="""
@@ -303,7 +320,8 @@
         xdict = {}
         xdict['requirements'] = ''
         if self.opts.make_HTML:
-            xdict['requirements'] = protorequirements
+            if self.opts.include_dependencies == "yes":
+                xdict['requirements'] = protorequirements
         xdict['tool_version'] = self.opts.tool_version
         xdict['test1Input'] = self.test1Input
         xdict['test1HTML'] = self.test1HTML
@@ -323,6 +341,16 @@
             xdict['help'] = ''.join([x for x in helptext])
         else:
             xdict['help'] = 'Please ask the tool author (%s) for help as none was supplied at tool generation\n' % (self.opts.user_email)
+        if self.opts.citations:
+            citationstext = open(self.opts.citations,'r').read()
+            citation_tuples = parse_citations(citationstext)
+            citations_xml = ""
+            for citation_type, citation_content in citation_tuples:
+                citation_xml = """<citation type="%s">%s</citation>""" % (citation_type, html_escape(citation_content))
+                citations_xml += citation_xml
+            xdict['citations'] = citations_xml
+        else:
+            xdict['citations'] = ""
         coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::']
         coda.append('\n')
         coda.append(self.indentedScript)
@@ -671,6 +699,7 @@
     a('--make_Tool',default=None)
     a('--make_HTML',default=None)
     a('--help_text',default=None)
+    a('--citations',default=None)
     a('--tool_desc',default=None)
     a('--new_tool',default=None)
     a('--tool_version',default=None)
b
diff -r bff4c9bfabc7 -r fb3fa6a2874d rgToolFactory.xml
--- a/rgToolFactory.xml Thu Aug 07 22:11:02 2014 -0400
+++ b/rgToolFactory.xml Thu Aug 28 02:22:39 2014 -0400
b
@@ -1,5 +1,5 @@
 <tool id="rgTF" name="Tool Factory" version="1.11">
-  <description>Makes scripts into tools</description>
+  <description>Run a script; make a tool!</description>
    <requirements>
       <requirement type="package" version="9.10">ghostscript</requirement>
       <requirement type="package" version="1.3.18">graphicsmagick</requirement>
@@ -20,8 +20,11 @@
       --new_tool "$new_tool"
       --help_text "$helpme"
       #if $make_HTML.value=="yes":
-      --include_dependencies "${makeMode.include_deps}"
+          #if makeMode.include.deps.value=="yes":
+             --include_dependencies "yes"
+          #end if
       #end if
+      --citations "$citeme"
     #end if
     #if $make_HTML.value=="yes":
       --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"
@@ -66,7 +69,28 @@
                 <option value="">Rely on system ghostscript and graphicsmagick rather than include these as dependencies</option>
                 <option value="yes" selected="true">Include dependencies so target installations will always work if HTML is being generated</option>
             </param>
-
+            <repeat name="citations" title="Citation">
+                <conditional name="citation_type">
+                    <param name="type" type="select" 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. 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>
@@ -86,11 +110,17 @@
     <option value="interval">Interval</option>
     <option value="gz">gz</option>
     <option value="text">text</option>
+    <option value="sam">sam</option>
+    <option value="bam">bam</option>
+    <option value="fastqsanger">fastqsanger</option>
+    <option value="fastq">fastq</option>
+    <option value="fasta">fasta</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">perl</option>
+        <option value="bash">bash</option>
         <option value="sh">sh</option>
     </param>   
     <param name="dynScript" label="Cut and paste the script to be executed here" type="text" value="" area="True" size="8x120"  
@@ -109,6 +139,10 @@
             <when input="out_format" value="interval"  format="interval" />
             <when input="out_format" value="gz" format="gz" />
             <when input="out_format" value="text"  format="text"  />
+            <when input="out_format" value="sam" format="sam" />
+            <when input="out_format" value="bam"  format=bam"  />
+            <when input="out_format" value="fastqsanger" format="fastqsanger" />
+            <when input="out_format" value="fastq"  format=fastq"  />
          </change_format>
     </data>
     <data format="html" name="html_file" label="${tool_name}.html">
@@ -125,6 +159,19 @@
 ${makeMode.help_text}
 #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>
 <help>
     
@@ -310,7 +357,9 @@
 
 
 </help>
-
+<citations>
+    <citation type="doi">10.1093/bioinformatics/bts573</citation>
+</citations>
 </tool>
 
 
b
diff -r bff4c9bfabc7 -r fb3fa6a2874d rgToolFactoryMultIn.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rgToolFactoryMultIn.py Thu Aug 28 02:22:39 2014 -0400
[
b'@@ -0,0 +1,736 @@\n+# rgToolFactoryMultIn.py\n+# see https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home\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://bitbucket.org/fubar/galaxytoolfactory/wiki/Home\n+#\n+# august 2014\n+# Allows arbitrary number of input files\n+# NOTE positional parameters are now passed to script\n+# and output (may be "None") is *before* arbitrary number of inputs\n+#\n+# march 2014\n+# had to remove dependencies because cross toolshed dependencies are not possible - can\'t pre-specify a toolshed url for graphicsmagick and ghostscript\n+# grrrrr - night before a demo\n+# added dependencies to a tool_dependencies.xml if html page generated so generated tool is properly portable\n+#\n+# added ghostscript and graphicsmagick as dependencies \n+# fixed a wierd problem where gs was trying to use the new_files_path from universe (database/tmp) as ./database/tmp\n+# errors ensued\n+#\n+# august 2013\n+# found a problem with GS if $TMP or $TEMP missing - now inject /tmp and warn\n+#\n+# july 2013\n+# added ability to combine images and individual log files into html output\n+# just make sure there\'s a log file foo.log and it will be output\n+# together with all images named like "foo_*.pdf\n+# otherwise old format for html\n+#\n+# January 2013\n+# problem pointed out by Carlos Borroto\n+# added escaping for <>$ - thought I did that ages ago...\n+#\n+# August 11 2012 \n+# changed to use shell=False and cl as a sequence\n+\n+# This is a Galaxy tool factory for simple scripts in python, R or whatever ails ye.\n+# It also serves as the wrapper for the new tool.\n+# \n+# you paste and run your script\n+# Only works for simple scripts that read one input from the history.\n+# Optionally can write one new history dataset,\n+# and optionally collect any number of outputs into links on an autogenerated HTML page.\n+\n+# DO NOT install on a public or important site - please.\n+\n+# installed generated tools are fine if the script is safe.\n+# They just run normally and their user cannot do anything unusually insecure\n+# but please, practice safe toolshed.\n+# Read the fucking code before you install any tool \n+# especially this one\n+\n+# After you get the script working on some test data, you can\n+# optionally generate a toolshed compatible gzip file\n+# containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for\n+# safe and largely automated installation in a production Galaxy.\n+\n+# If you opt for an HTML output, you get all the script outputs arranged\n+# as a single Html history item - all output files are linked, thumbnails for all the pdfs.\n+# Ugly but really inexpensive.\n+# \n+# Patches appreciated please. \n+#\n+#\n+# long route to June 2012 product\n+# Behold the awesome power of Galaxy and the toolshed with the tool factory to bind them\n+# derived from an integrated script model  \n+# called rgBaseScriptWrapper.py\n+# Note to the unwary:\n+#   This tool allows arbitrary scripting on your Galaxy as the Galaxy user\n+#   There is nothing stopping a malicious user doing whatever they choose\n+#   Extremely dangerous!!\n+#   Totally insecure. So, trusted users only\n+#\n+# preferred model is a developer using their throw away workstation instance - ie a private site.\n+# no real risk. The universe_wsgi.ini admin_users string is checked - only admin users are permitted to run this tool.\n+#\n+\n+import sys \n+import shutil \n+import subprocess \n+import os \n+import time \n+import tempfile \n+import optparse\n+import tarfile\n+import re\n+import shutil\n+import math\n+\n+progname = os.path.split(sys.argv[0])[1] \n+myversion = \'V001.1 March 2014\' \n+verbose = False \n+debug = False\n+toolFactoryURL = \'https://bitbucket.org/fubar/galaxytoolfactory\'\n+\n+# if we do html we need these dependencies specified in a tool_dependencies.xml file and referred to in the generated\n+# tool xml\n+toolhtmldepskel = """<?xml version="1.0"'..b'  htmlf = file(self.opts.output_html,\'w\')\n+        htmlf.write(\'\\n\'.join(html))\n+        htmlf.write(\'\\n\')\n+        htmlf.close()\n+        self.html = html\n+\n+\n+    def run(self):\n+        """\n+        scripts must be small enough not to fill the pipe!\n+        """\n+        if self.treatbashSpecial and self.opts.interpreter in [\'bash\',\'sh\']:\n+          retval = self.runBash()\n+        else:\n+            if self.opts.output_dir:\n+                ste = open(self.elog,\'w\')\n+                sto = open(self.tlog,\'w\')\n+                sto.write(\'## Toolfactory generated command line = %s\\n\' % \' \'.join(self.cl))\n+                sto.flush()\n+                p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir)\n+            else:\n+                p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE)\n+            p.stdin.write(self.script)\n+            p.stdin.close()\n+            retval = p.wait()\n+            if self.opts.output_dir:\n+                sto.close()\n+                ste.close()\n+                err = open(self.elog,\'r\').readlines()\n+                if retval <> 0 and err: # problem\n+                    print >> sys.stderr,err\n+            if self.opts.make_HTML:\n+                self.makeHtml()\n+        return retval\n+\n+    def runBash(self):\n+        """\n+        cannot use - for bash so use self.sfile\n+        """\n+        if self.opts.output_dir:\n+            s = \'## Toolfactory generated command line = %s\\n\' % \' \'.join(self.cl)\n+            sto = open(self.tlog,\'w\')\n+            sto.write(s)\n+            sto.flush()\n+            p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,cwd=self.opts.output_dir)\n+        else:\n+            p = subprocess.Popen(self.cl,shell=False)            \n+        retval = p.wait()\n+        if self.opts.output_dir:\n+            sto.close()\n+        if self.opts.make_HTML:\n+            self.makeHtml()\n+        return retval\n+  \n+\n+def main():\n+    u = """\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+    op = optparse.OptionParser()\n+    a = op.add_option\n+    a(\'--script_path\',default=None)\n+    a(\'--tool_name\',default=None)\n+    a(\'--interpreter\',default=None)\n+    a(\'--output_dir\',default=\'./\')\n+    a(\'--output_html\',default=None)\n+    a(\'--input_tab\',default=[], action="append")    \n+    a("--input_formats",default="tabular")\n+    a(\'--output_tab\',default="None")\n+    a(\'--output_format\',default=\'tabular\')\n+    a(\'--user_email\',default=\'Unknown\')\n+    a(\'--bad_user\',default=None)\n+    a(\'--make_Tool\',default=None)\n+    a(\'--make_HTML\',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+    opts, args = op.parse_args()\n+    assert not opts.bad_user,\'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to admin_users in universe_wsgi.ini\' % (opts.bad_user,opts.bad_user)\n+    assert opts.tool_name,\'## Tool Factory expects a tool name - eg --tool_name=DESeq\'\n+    assert opts.interpreter,\'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript\'\n+    assert os.path.isfile(opts.script_path),\'## Tool Factory wrapper expects a script path - eg --script_path=foo.R\'\n+    if opts.output_dir:\n+        try:\n+            os.makedirs(opts.output_dir)\n+        except:\n+            pass\n+    opts.input_tab = [x.replace(\'"\',\'\').replace("\'",\'\') for x in opts.input_tab]\n+    r = ScriptRunner(opts)\n+    if opts.make_Tool:\n+        retcode = r.makeTooltar()\n+    else:\n+        retcode = r.run()\n+    os.unlink(r.sfile)\n+    if retcode:\n+        sys.exit(retcode) # indicate failure to job runner\n+\n+\n+if __name__ == "__main__":\n+    main()\n+\n+\n'
b
diff -r bff4c9bfabc7 -r fb3fa6a2874d rgToolFactoryMultIn.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rgToolFactoryMultIn.xml Thu Aug 28 02:22:39 2014 -0400
[
b'@@ -0,0 +1,343 @@\n+<tool id="rgTFM" name="Tool Factory Multiple Inputs" version="1.12">\n+  <description>Makes scripts into tools</description>\n+   <requirements>\n+      <requirement type="package" version="9.10">ghostscript</requirement>\n+      <requirement type="package" version="1.3.18">graphicsmagick</requirement>\n+  </requirements>\n+  <command interpreter="python">\n+#if ( $__user_email__ not in $__admin_users__ ):\n+     rgToolFactoryMultIn.py --bad_user $__user_email__\n+#else:\n+    rgToolFactoryMultIn.py --script_path "$runme" --interpreter "$interpreter" \n+     --tool_name "$tool_name"  --user_email "$__user_email__"\n+    #if $make_TAB.value=="yes":\n+          --output_tab "$output1"\n+          --output_format "$output_format"\n+    #end if\n+    #if $makeMode.make_Tool=="yes":\n+      --make_Tool "$makeMode.make_Tool"\n+      --tool_desc "$makeMode.tool_desc"\n+      --tool_version "$makeMode.tool_version"\n+      --new_tool "$new_tool"\n+      --help_text "$helpme"\n+      #if $make_HTML.value=="yes":\n+          #if $makeMode.include_deps.value=="yes":\n+             --include_dependencies "yes"\n+          #end if\n+      #end if\n+    #end if\n+    #if $make_HTML.value=="yes":\n+      --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"\n+    #else:\n+       --output_dir "."\n+    #end if\n+    #if $input1 != \'None\':\n+        --input_formats "$input_formats"\n+        #for intab in $input1:\n+          #if $add_names.value == "yes":\n+              --input_tab "$intab,$intab.name"\n+          #else:\n+              --input_tab "$intab"\n+          #end if\n+        #end for\n+        --input_formats = "$input_formats"\n+    #end if\n+#end if \n+  </command>\n+  <inputs>\n+    <param name="input1"  type="data"  label="Select an input file from your history" optional="true" size="120" multiple="true"\n+       help="Use the multiple input widget (above/right of input box) for multiple inputs - your script MUST be ready to parse the command line right - see samples below"/>\n+    <param name="input_formats" type="text" value="tabular" label="Select allowable Galaxy input formats for your inputs passed to your script - default is tabular"\n+         help="Multiple input formats are allowed as a comma separated list (eg \'tabular,txt\'), but your script must be able to deal with whatever is passed in!">\n+        <sanitizer invalid_char="">\n+            <valid initial="string.letters">\n+                <add value=","/>\n+                <add value=" "/>\n+            </valid>\n+        </sanitizer>\n+    </param>\n+    <param name="add_names" type="select" label="Pass input file(s) as path,name - useful if you need the user supplied Galaxy name for your data sets" \n+         help="Your script is responsible for parsing and dealing with these comma separated values!">\n+        <option value="yes">Pass inputs as comma separated path,name values on the script command line</option>\n+        <option value="" selected="true">Pass input parameters as path only - do not include the user supplied name</option>\n+    </param>\n+    <param name="tool_name" type="text" value="My dynamic script"   label="New tool ID and title for outputs" size="60"\n+         help="This will become the toolshed repository name so please choose thoughtfully to avoid namespace clashes with other tool writers">\n+        <sanitizer invalid_char="">\n+            <valid initial="string.letters,string.digits">\n+                <add value="_"/>\n+            </valid>\n+        </sanitizer>\n+    </param>\n+    <conditional name="makeMode">\n+        <param name="make_Tool" type="select" label="Create a tar.gz file ready for local toolshed entry" help="Ready to deploy securely!" size="60">\n+        <option value="yes">Generate a Galaxy ToolShed compatible toolshed.gz</option>\n+        <option value="" selected="true">No. Just run the script please</option>\n+        </param>\n+        <when value = "yes">\n+            <param name="tool_version" label="Tool Version - bump this to warn'..b'justed p value from a column of p values - for this script to be useful, it needs the right column for the input to be specified in the code for the\n+given input file type(s) specified when the tool is generated ::\n+\n+ # use p.adjust - assumes a HEADER row and column 1 - please fix for any real use\n+ column = 1 # adjust if necessary for some other kind of input\n+ ourargs = commandArgs(TRUE)\n+ inf = ourargs[1]\n+ outf = ourargs[2]\n+ inp = read.table(inf,head=T,row.names=NULL,sep=\'\\t\')\n+ p = inp[,column]\n+ q = p.adjust(p,method=\'BH\')\n+ outp = cbind(inp,\'BH Adjusted p-value\'=q)\n+ write.table(outp,outf, quote=FALSE, sep="\\t",row.names=F,col.names=T) \n+\n+\n+A demonstration Rscript example takes no input file but generates some random data based pdf images\n+You must make sure the option to create an HTML output file is\n+turned on for this to work. Images (pdf) are linked via thumbnails and\n+all files have a link on the resulting HTML page::\n+\n+ # note this script takes NO input or output because it generates random data\n+ for (i in 1:10) {\n+    foo = runif(100)\n+    bar = rnorm(100)\n+    bar = foo + 0.05*bar\n+    pdf(paste(\'yet\',i,"anotherplot.pdf",sep=\'_\'))\n+    plot(foo,bar,main=paste("Foo by Bar plot #",i),col="maroon", pch=3,cex=0.6)\n+    dev.off()\n+    foo = data.frame(a=runif(100),b=runif(100),c=runif(100),d=runif(100),e=runif(100),f=runif(100))\n+    bar = as.matrix(foo)\n+    pdf(paste(\'yet\',i,"anotherheatmap.pdf",sep=\'_\'))\n+    heatmap(bar,main=\'Random Heatmap\')\n+    dev.off()\n+ }\n+\n+A slight variation taking an input tabular file from which we read the first number as nreps\n+\n+# note this script takes a single parameter\n+# number of replicates\n+ourargs = commandArgs(TRUE)\n+infname = ourargs[1]\n+nreps = read.table(infname,head=F)\n+nreps = unlist(nreps)[1]\n+nreps = max(c(1,nreps))\n+nreps = min(c(20,nreps))\n+print(paste("Using nreps=",nreps))\n+for (i in 1:nreps) {\n+   foo = runif(100)\n+   bar = rnorm(100)\n+   bar = foo + 0.2*bar\n+   pdf(paste("yet",i,"anotherplot.pdf",sep="_"))\n+   plot(foo,bar,main=paste("Foo by Bar plot ",i),col="maroon", pch=3,cex=0.6)\n+   dev.off()\n+   foo = data.frame(a=runif(100),b=runif(100),c=runif(100),d=runif(100),e=runif(100),f=runif(100))\n+   bar = as.matrix(foo)\n+   pdf(paste("yet",i,"anotherheatmap.pdf",sep="_"))\n+   heatmap(bar,main="Random Heatmap")\n+   dev.off()\n+}\n+\n+A Python example that reverses each row of a tabular file (you\'ll need to remove the leading spaces \n+for this to work if cut and pasted into the script box)::\n+\n+ # reverse order of columns in a tabular file\n+ import sys\n+ inp = sys.argv[1]\n+ outp = sys.argv[2]\n+ i = open(inp,\'r\')\n+ o = open(outp,\'w\')\n+ for row in i:\n+     rs = row.rstrip().split(\'\\t\')\n+     rs.reverse()\n+     o.write(\'\\t\'.join(rs))\n+     o.write(\'\\n\')\n+ i.close()\n+ o.close()\n+ \n+A trivial shell script example to show that it works::\n+\n+ #!/bin/bash\n+ INF=$1\n+ OUTF=$2\n+ cut -c2,4,6,8,10,12 $INF > $OUTF \n+\n+A trivial perl script example to show that even perl works::\n+\n+ #\n+ # change all occurances of a string in a file to another string\n+ #\n+ $oldfile = $ARGV[0];\n+ $newfile = $ARGV[1];\n+ $old = "gene";\n+ $new = "foo";\n+ open(OF, $oldfile);\n+ open(NF, ">$newfile");\n+ # read in each line of the file\n+ while ($line = <OF>) {\n+    $line =~ s/$old/$new/;\n+    print NF $line;\n+ }\n+ close(OF);\n+ close(NF);\n+\n+]]>\n+\n+**Citation**\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+\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?ijkey=lczQh1sWrMwdYWJ&amp;keytype=ref\n+\n+\n+</help>\n+\n+</tool>\n+\n+\n'