Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add select parameter with options from remote resources #17087

Merged
merged 10 commits into from
Feb 14, 2024
Prev Previous commit
Next Next commit
Add test cases against usegalaxy.org's genomes api
mvdbeek committed Feb 12, 2024

Verified

This commit was signed with the committer’s verified signature.
mvdbeek Marius van den Beek
commit d96dc3dfa562ec408a62763fde0b27f8b496562d
12 changes: 9 additions & 3 deletions lib/galaxy/tools/parameters/dynamic_options.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
import re
from io import StringIO

import requests

from galaxy.model import (
DatasetCollectionElement,
HistoryDatasetAssociation,
@@ -781,11 +783,15 @@ def to_triple(values):
return [str(values[0]), str(values[1]), bool(values[2])]

if self.from_url:
import requests

context = User.user_template_environment(trans.user)
url = fill_template(self.from_url, context)
data = requests.get(url).json()
try:
response = requests.get(url)
response.raise_for_status()
except Exception as e:
log.warning("Fetching from url '%s' failed: %s", url, str(e))
return []
data = response.json()

if self.from_url_postprocess:
data = do_eval(
36 changes: 28 additions & 8 deletions test/functional/tools/select_from_url.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
<tool id="select_from_url" name="select_from_url" version="0.1.0" profile="23.1">
<command>
echo '$url_param_value' > '$the_value'
</command>
<command><![CDATA[
echo '$url_param_value' > '$param_value' &&
echo '$url_param_value_postprocessed' > '$param_value_postprocessed'
]]></command>
<inputs>
<param name="url_param_value" type="select">
<options from_url="http://localhost:8000/data">
<options from_url="https://usegalaxy.org/api/genomes">
mvdbeek marked this conversation as resolved.
Show resolved Hide resolved
</options>
</param>
<!--
<param name="url_param_value_templated" type="select">
<options from_url="http://localhost:8000/data?user=$__user_id__">
</options>
</param>
<param name="url_param_value_templated_and_postprocessed" type="select">
<options from_url="http://localhost:8000/data_paginated?user=$__user_id__">
-->
<param name="url_param_value_postprocessed" type="select">
<options from_url="https://usegalaxy.org/api/genomes/dm6">
<postprocess_expression><![CDATA[
$( inputs.map((v) => [`name: ${v[0]}`, `value: ${v[1]}`]) )
$( Object.values(inputs.chrom_info).map((v) => [v.chrom, v.len]) )
]]></postprocess_expression>
</options>
</param>
</inputs>
<outputs>
<data format="txt" name="the_value"></data>
<data format="txt" label="url param value" name="param_value"></data>
<data format="txt" label="url param value postprocessed" name="param_value_postprocessed"></data>
</outputs>
<tests>
<test>
<param name="url_param_value" value="dm6" />
<param name="url_param_value_postprocessed" value="chr2L" />
<output name="param_value">
<assert_contents>
<has_text text="dm6"></has_text>
</assert_contents>
</output>
<output name="param_value_postprocessed">
<assert_contents>
<has_text text="23513712"></has_text>
</assert_contents>
</output>
</test>
</tests>
</tool>