Leandro Hermida wrote, On 04/28/2011 08:55 AM: > Hi galaxy developers, > > Just want to double-check, there is no way to import some kind of galaxy tool > context info into python code you are running for a tool?
Nothing is impossible... just depends on how messy you want to get :) for me, the following works: === python_path.xml === <tool id="cshl_python_path_test" name="pythonpath" description="" > <command>echo '$input1' > '$output'</command> <inputs> <param name="input1" type="text" value="10" label="Dummy"/> </inputs> <code file="python_path_code.py" /> <outputs> <data name="output" format="txt" /> </outputs> </tool> ====== ==== python_path_code.py ===== from os import path import sys def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr): tool_path = path.abspath(tool.tool_dir); sys.stderr.write("!!!!! path = %s\n" % (tool_path)) ======================== When the tool runs, the following line is printed to STDERR: ====== !!!!! path = /home/gordon/projects/galaxy_dev/tools/cshl_tests ====== Help this helps, -gordon > > best, > leandro > > On Fri, Apr 15, 2011 at 8:03 PM, Leandro Hermida <soft...@leandrohermida.com > <mailto:soft...@leandrohermida.com>> wrote: > > On Fri, Apr 15, 2011 at 7:27 PM, Peter Cock <p.j.a.c...@googlemail.com > <mailto:p.j.a.c...@googlemail.com>> wrote: > > On Thu, Apr 14, 2011 at 2:56 PM, Leandro Hermida > <soft...@leandrohermida.com <mailto:soft...@leandrohermida.com>> > wrote: > > On Thu, Apr 14, 2011 at 3:17 PM, Peter Cock > <p.j.a.c...@googlemail.com <mailto:p.j.a.c...@googlemail.com>> > > wrote: > >> > >> For standard Python tools in Galaxy, I'm using > >> os.path.split(sys.argv) > >> to get the path, which on reflection probably should be written as > >> os.path.dirname(sys.argv) as you suggest. > >> > >> What do __file__ and sys.argv give you? The simplest way to > debug > >> this is to add a print statement, since Galaxy will show the > stdout. > >> > > > > Hi Peter, > > > > __file__ throws an error: global name '__file__' is not defined > > I guess the script is being loaded as a string, and run with eval(...) > or something like that. It would also explain why sys.argv would > be one of the Galaxy script files. > > > os.path.abspath(os.path.dirname(sys.argv)) gives me > > /path/to/galaxy/scripts directory which is two levels up from what > the tool > > directory I want for example /path/to/galaxy/tools/mytool > > So combine that with ../tools/mytool/ and you're done? OK, you have > to know the name of the folder your tool *should* be in... so not a > perfect solution. > > > Thanks Peter, yes that's the same idea I did as a quick fix.... also > don't like the fact that my tool directory is hard-coded but oh well. There > must be a way within Python in Galaxy importing something from Galaxy that > has the current tool directory path, it would seem that Galaxy needs to know > this and would store it anyway? > > best, > Leandro > > ___________________________________________________________ Please keep all replies on the list by using "reply all" in your mail client. To manage your subscriptions to this and other Galaxy lists, please use the interface at: http://lists.bx.psu.edu/