Last active
July 12, 2016 10:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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