Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OliPelz/8737ad979a1453a1ec357e581cecffd8 to your computer and use it in GitHub Desktop.
Save OliPelz/8737ad979a1453a1ec357e581cecffd8 to your computer and use it in GitHub Desktop.
How to pass dynamic values such as username to a galaxy tool using dynamic_options
Tried a lot of different approaches to pass the username or user id to a galaxy tool configuration, nothing seemed to work,
e.g. the __user_id__ or user_name could not be passed to a function referenced by dynamic_options, e.g.:
<param name="mytool" type="select" dynamic_options="mystuff(userid=__user_id__)" />
or
<param name="mytool" type="select" dynamic_options="mystuff(username=__user_name__)" />
did not work, neither other approaches such as username='$__user_name__' or ${__user_name__} or '${__user_name__}'
it seems that the reserved variables from this document here cannot be accessed by a dynamic_options method:
https://wiki.galaxyproject.org/Admin/Tools/ToolConfigSyntax?action=show&redirect=Admin%2FTools%2FTool+Config+Syntax#A.3Ccode.3E_tag_set
The only solution or working approach is to submit the __trans__ dictionary, which is accessible in the referencing
dynamics_option function.
Because this feature is not well documented, here is some example code to get you started.
<tool id="my-ftp-downloader" name="Tool to upload ftp stuff to a specific dir" version="0.0.1">
<description>download all files from official a public server</description>
<command><![CDATA[
## bash command to be executed
## comments with double hash
/software/galaxy_ftp_uploader/uploader.py "$ftp_dynamic_upload_dir"
]]>
</command>
<stdio>
<exit_code range="1:" />
<exit_code range=":-1" />
</stdio>
<inputs>
<param name="ftp_dynamic_upload_dir" type="select" label="FTP upload dir" dynamic_options="generate_ftp_download_dir( trans=__trans__ )"/>
</inputs>
<outputs>
</outputs>
<help>
<![CDATA[
This tool does whatever it can.
]]>
</help>
<options refresh="True"/>
<code file="my_ftp_uploader.py" />
</tool>
#!/usr/bin/env python
import time
# needs to return a list of (Name, Value, Bool)
def generate_ftp_download_dir(trans = None):
if trans:
username = trans.user.username
unix_timestamp = str(int(time.time()))
upload_path = "galaxy_" + username + "_" + unix_timestamp
return_obj = []
return_obj.append( (upload_path, upload_path, True) )
return return_obj
return []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment