Hi Leandro,

Leandro Hermida wrote, On 04/29/2011 06:17 AM:
> But I have one complication I guess.  My tool is already running a Python 
> code file to dynamically create a drop-down menu using the dynamic_options 
> attribute a la:
> 
> <param type="select" dynamic_options="my_options()">
> ...
> <code file="my_options.py"/>
> 
> In this function my_options I would need the tool dir path.  How would I be 
> able to combine what you did with this?  Which function runs at the right 
> time before my_options() is executed is it exec_before_process?
>  

This just gets messier and messier :)

The following hack will get you the tool's path inside the "dynamic option" 
code, but it is SO ugly, I would highly recommend against it.
A better way would be to add some code to "./galaxy/lib/parameters/basic.py" 
inside "get_options()" to add the 'tool' object to the "other_values" object, 
so that custom code functions would be able to access it (or something similar 
and as clean).

That being said, here goes:

=========  dynamic_options_path.xml  ==================
<tool id="cshl_dynamic_optinos_path_test" name="dynamic_options_path" 
description="" >
<command>echo '$input1' &gt; '$output'</command>
        <inputs>
                <param name="input1" type="text" value="10" label="Dummy"/>
                <param name="mylist" type="select" label="Dynamic Options"
                        
dynamic_options="get_my_options(code_ref=get_my_options)" display="radio" />
        </inputs>
        <code file="dynamic_options_code.py" />
        <outputs>
                <data name="output" format="txt" />
        </outputs>
</tool>
===========================


====== dynamic_options_code.py ==============
import os
import os.path
import sys

def get_my_options(code_ref):
        root_dir=os.getcwd()
        sys.stderr.write("Galaxy root dir = %s\n" % ( root_dir ) )
        sys.stderr.write("Custom code file = %s\n" % ( 
code_ref.__code__.co_filename) )
        tool_path = root_dir + '/' + os.path.dirname( 
code_ref.__code__.co_filename)
        sys.stderr.write("tool path = %s\n" % ( tool_path ) )
        res = [('Hello','World',False),]
        return res
==========================

The output (STDERR) when viewing the tool's form is:
Galaxy root dir = /home/gordon/projects/galaxy_dev
Custom code file = ./tools/cshl_tests/dynamic_options_code.py
tool path = /home/gordon/projects/galaxy_dev/./tools/cshl_tests



The trick is that the dynamic function itself ("get_my_options()") is a valid 
object (which is luckily accessible from inside the code), and python keeps 
track of the file that contained the function.

Good luck (and don't try this at home :) ),
 -gordon
___________________________________________________________
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/

Reply via email to