Previous changeset 8:9d58cc32a12d (2015-01-12) Next changeset 10:8de2b7571d98 (2015-01-15) |
Commit message:
Uploaded |
modified:
rgToolFactory2.py rgToolFactory2.xml test-data/tf2_test.html test-data/tf2_test.toolshed.gz |
added:
getlocalrpackages.py |
b |
diff -r 9d58cc32a12d -r ce5ec1d989fd getlocalrpackages.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getlocalrpackages.py Wed Jan 14 19:17:11 2015 -0500 |
[ |
@@ -0,0 +1,31 @@ +import os +import subprocess + +def find_packages(prefix="package_r_"): + """ + """ + #locate env.sh | grep -i package_r_ + #/data/extended/galaxyJune14_2014/tool_dependency/readline/6.2/devteam/package_r_2_15_0/8ab0d08a3da1/env.sh + #/data/home/rlazarus/galaxy/tool_dependency_dir/R_3_1_1/3.1.1/fubar/package_r_3_1_1/5f1b8d22140a/env.sh + #/data/home/rlazarus/galaxy/tool_dependency_dir/R_3_1_1/3.1.1/fubar/package_r_3_1_1/d9964efbfbe3/env.sh + #/data/home/rlazarus/galtest/tool_dependency_dir/R_3_1_1/3.1.1/fubar/package_r_3_1_1/63cdb9b2234c/env.sh + eprefix = prefix + if prefix.find('/') <> -1: + eprefix = prefix.replace('/','\/') # for grep + cl = ['locate env.sh | grep -i %s' % eprefix,] + p = subprocess.Popen(cl, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) + out, err = p.communicate() + fpaths = out.split('\n') + fpaths = [x for x in fpaths if len(x) > 1] + fver = [x.split(os.path.sep)[-4:-1] for x in fpaths] + # >>> foo.split(os.path.sep)[-4:-1] + # ['fubar', 'package_r_3_1_1', '63cdb9b2234c'] + res = [['%s rev %s owner %s' % (x[1],x[2],x[0]),fpaths[i],False] for i,x in enumerate(fver)] + res.insert(0,['Use default (system) interpreter','system',False]) + if len(res) > 1: + res[1][2] = True # selected if more than one + # return a triplet - user_sees,value,selected - all unselected if False + return res + +if __name__ == "__main__": + print find_packages() |
b |
diff -r 9d58cc32a12d -r ce5ec1d989fd rgToolFactory2.py --- a/rgToolFactory2.py Mon Jan 12 05:27:52 2015 -0500 +++ b/rgToolFactory2.py Wed Jan 14 19:17:11 2015 -0500 |
[ |
@@ -172,7 +172,20 @@ citation_tuples.append( ("bibtex", citation[len("bibtex"):].strip() ) ) return citation_tuples - +def shell_source(script): + """need a way to source a Galaxy tool interpreter env.sh so we can use that dependency + package + see http://pythonwise.blogspot.fr/2010/04/sourcing-shell-script.html + Sometime you want to emulate the action of "source" in bash, + settings some environment variables. Here is a way to do it. + Note that we have to finesse the automagic exports using nulls as newlines for env""" + pipe = subprocess.Popen("env -i ; . %s ; env -0" % script, stdout=subprocess.PIPE, shell=True) + output = pipe.communicate()[0] + outl = output.split('\0') + outl = [x for x in outl if len(x.split("=")) == 2] + newenv = dict((line.split("=", 1) for line in outl)) + os.environ.update(newenv) + class ScriptRunner: """class is a wrapper for an arbitrary script """ @@ -218,10 +231,7 @@ self.test1Inputs = [] # now a list a = self.cl.append a(opts.interpreter) - if self.treatbashSpecial and opts.interpreter in ['bash','sh']: - a(self.sfile) - else: - a('-') # stdin + a(self.sfile) # if multiple inputs - positional or need to distinguish them with cl params if opts.input_tab: tests = [] @@ -391,7 +401,8 @@ %(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 +</tool>""" +# needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto newCommand=""" %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" @@ -433,8 +444,8 @@ xdict['additionalInputs'] = '' if self.opts.additional_parameters: if self.opts.edit_additional_parameters: # add to new tool form with default value set to original value - xdict['additionalInputs'] = '\n'.join(['<param name="%s" value="%s" label="%s" help="%s" type="%s"/>' % (x.split(',')[0],html_escape(x.split(',')[1]),html_escape(x.split(',')[2]), - html_escape(x.split(',')[3]), x.split(',')[4]) for x in self.opts.additional_parameters]) + xdict['additionalInputs'] = '\n'.join(['<param name="%s" value="%s" label="%s" help="%s" type="%s"/>' % \ + (x.split(',')[0],html_escape(x.split(',')[1]),html_escape(x.split(',')[2]),html_escape(x.split(',')[3]), x.split(',')[4]) for x in self.opts.additional_parameters]) xdict['additionalParams'] = '\n'.join(['<param name="%s" value="%s" />' % (x.split(',')[0],html_escape(x.split(',')[1])) for x in self.opts.additional_parameters]) xdict['requirements'] = '' if self.opts.make_HTML: @@ -774,10 +785,13 @@ self.html = html + def run(self): """ scripts must be small enough not to fill the pipe! """ + if self.opts.envshpath <> 'system': + shell_source(self.opts.envshpath) if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']: retval = self.runBash() else: @@ -786,11 +800,9 @@ sto = open(self.tlog,'w') sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl)) sto.flush() - p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir) + p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,cwd=self.opts.output_dir) else: - p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE) - p.stdin.write(self.script) - p.stdin.close() + p = subprocess.Popen(self.cl,shell=False) retval = p.wait() if self.opts.output_dir: sto.close() @@ -851,6 +863,7 @@ a('--citations',default=None) a('--additional_parameters', dest='additional_parameters', action='append', default=[]) a('--edit_additional_parameters', action="store_true", default=False) + a('--envshpath',default="system") opts, args = op.parse_args() 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) assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' |
b |
diff -r 9d58cc32a12d -r ce5ec1d989fd rgToolFactory2.xml --- a/rgToolFactory2.xml Mon Jan 12 05:27:52 2015 -0500 +++ b/rgToolFactory2.xml Wed Jan 14 19:17:11 2015 -0500 |
b |
@@ -1,15 +1,17 @@ -<tool id="rgTF2" name="Tool Factory Two" version="1.15"> +<tool id="rgTF2" name="Tool Factory Two" version="1.16"> <description>Scripts into tools</description> <requirements> <requirement type="package" version="9.10">ghostscript</requirement> <requirement type="package" version="1.3.20">graphicsmagick</requirement> </requirements> + <code file="getlocalrpackages.py"/> <command interpreter="python"> #if ( $__user_email__ not in $__admin_users__ ): rgToolFactory2.py --bad_user $__user_email__ #else: - rgToolFactory2.py --script_path "$runme" --interpreter "$interpreter" + rgToolFactory2.py --script_path "$runme" --interpreter "$interp.interpreter" --tool_name "$tool_name" --user_email "$__user_email__" --citations "$citeme" + --envshpath "$interp.envpath" #if $make_TAB.value=="yes": --output_tab "$output1" @@ -96,7 +98,7 @@ </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." /> + 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" @@ -135,6 +137,7 @@ <column name="value" index="0"/> </options> </param> + <conditional name="interp"> <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> @@ -142,6 +145,19 @@ <option value="bash">bash</option> <option value="sh">sh</option> </param> + <when value="Rscript"> + <param name="envpath" type="select" label="Interpreter to use" dynamic_options="find_packages(prefix='package_r_')" + help = "Select the R interpreter to use when running this code - should show all installed tool shed package_r_..." /> + </when> + <when value="python"> + <param name="envpath" type="select" label="Interpreter to use" dynamic_options="find_packages(prefix='package_python_')" + help = "Select the python dependency to use when running this code - should show all installed tool shed package_python_..." /> + </when> + <when value="perl"> + <param name="envpath" type="select" label="Interpreter to use" dynamic_options="find_packages(prefix='package_perl_')" + help = "Select the Perl interpreter to use when running this code - should show all installed tool shed package_perl_..." /> + </when> + </conditional> <param name="edit_params" type="select" label="Add all 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> @@ -244,6 +260,7 @@ <param name="output_format" value="tabular" /> <param name="input_formats" value="tabular" /> <param name="interpreter" value='python' /> + <param name="envpath" value='system' /> <param name="runme" value="tf2_test_runme.py"/> <output name='output1' file='tf2_test_out.xls' compare='diff' lines_diff = '10'/> <output name='html_file' file="tf2_test.html" compare='diff' lines_diff = '10'/> @@ -418,7 +435,7 @@ </help> <citations> - <citation type="doi">doi: 10.1093/bioinformatics/bts573</citation> + <citation type="doi">10.1093/bioinformatics/bts573</citation> </citations> </tool> |
b |
diff -r 9d58cc32a12d -r ce5ec1d989fd test-data/tf2_test.html --- a/test-data/tf2_test.html Mon Jan 12 05:27:52 2015 -0500 +++ b/test-data/tf2_test.html Wed Jan 14 19:17:11 2015 -0500 |
b |
@@ -8,18 +8,18 @@ <body> <div class="toolFormBody"> -<div class="infomessage">Galaxy Tool "tf2_test" run at 02/01/2015 11:50:01</div><br/> +<div class="infomessage">Galaxy Tool "tf2_test" run at 15/01/2015 11:06:33</div><br/> <div class="toolFormTitle">tf2 log output</div> tf2_test_error.log is empty<br/> <div class="toolFormTitle">Other log output</div> -/tmp/tmpsyPOyw/job_working_directory/000/2/dataset_3_files/tf2_test_runner.log is empty<br/> +/tmp/tmp5bLHi4/job_working_directory/000/2/dataset_3_files/tf2_test_runner.log is empty<br/> <div class="toolFormTitle">All output files available for downloading</div> <div><table class="colored" cellpadding="3" cellspacing="3"><tr><th>Output File Name (click to view)</th><th>Size</th></tr> <tr><td><a href="tf2_test.python">tf2_test.python</a></td><td>0 B</td></tr> <tr class="odd_row"><td><a href="tf2_test_error.log">tf2_test_error.log</a></td><td>0 B</td></tr> -<tr><td><a href="tf2_test_runner.log">tf2_test_runner.log</a></td><td>177 B</td></tr> +<tr><td><a href="tf2_test_runner.log">tf2_test_runner.log</a></td><td>216 B</td></tr> </table></div><br/> </div></body></html> |
b |
diff -r 9d58cc32a12d -r ce5ec1d989fd test-data/tf2_test.toolshed.gz |
b |
Binary file test-data/tf2_test.toolshed.gz has changed |