diff --git a/lib/galaxy/tool_util/xsd/galaxy.xsd b/lib/galaxy/tool_util/xsd/galaxy.xsd
index d2b51ea99670..f30904d1a487 100644
--- a/lib/galaxy/tool_util/xsd/galaxy.xsd
+++ b/lib/galaxy/tool_util/xsd/galaxy.xsd
@@ -4124,8 +4124,9 @@ Currently the following filters are defined:
* ``data_meta`` populate or filter options based on the metadata of another input parameter specified by ``ref``. If a ``column`` is given options are filtered for which the entry in this column ``column`` is equal to metadata of the input parameter specified by ``ref``.
If no ``column`` is given the metadata value of the referenced input is added to the options list (in this case the corresponding ``options`` tag must not have the ``from_data_table`` or ``from_dataset`` attributes).
In both cases the desired metadata is selected by ``key``.
+* ``data_table`` remove values according to the entries of a data table. Remove options where the value in ``column`` appears in the data table ``table_name`` in column ``table_column``. Setting ``keep`` will to ``true`` will keep only entries also appearing in the data table.
-The ``static_value`` and ``regexp`` filters can be inverted by setting ``keep`` to true.
+The ``static_value``, ``regexp``, and ``data_table`` filters can be inverted by setting ``keep`` to true.
* ``add_value``: add an option with a given ``name`` and ``value`` to the options. By default the new option is appended, with ``index`` the insertion position can be specified.
* ``remove_value``: remove a value from the options. Either specified explicitly with ``value``, the value of another input specifified with ``ref``, or the metatdata ``key`` of another input ``meta_ref``.
@@ -4287,7 +4288,7 @@ only used if ``multiple`` is set to ``true``.]]>
If ``true``, keep columns matching the
value, if ``false`` discard columns matching the value. Used when ``type`` is
-either ``static_value``, ``regexp`` or ``param_value``.
+either ``static_value``, ``regexp``, ``param_value`` or ``data_table``.
@@ -4319,6 +4320,18 @@ added to the end of the list.
from the list.
+
+
+ Only used when ``type`` is
+``data_table``. The name of the data table to use.
+
+
+
+
+ Only used when ``type`` is
+``data_table``. The column of the data table to use (0 based index or column name).
+
+
@@ -6192,6 +6205,7 @@ and ``bibtex`` are the only supported options.
+
diff --git a/lib/galaxy/tools/parameters/dynamic_options.py b/lib/galaxy/tools/parameters/dynamic_options.py
index 759457f4a6a8..93a16da94d40 100644
--- a/lib/galaxy/tools/parameters/dynamic_options.py
+++ b/lib/galaxy/tools/parameters/dynamic_options.py
@@ -499,6 +499,59 @@ def filter_options(self, options, trans, other_values):
return sorted(options, key=lambda x: x[self.column])
+class DataTableFilter(Filter):
+ """
+ Filters a list of options by entries present in a data table, i.e.
+ option[column] needs to be in the specified data table column
+
+ Type: data_table
+
+ Required Attributes:
+
+ - column: column in options to compare with
+ - table_name: data table to use
+ - data_table_column: data table column to use
+
+ Optional Attributes:
+
+ - keep: Keep options where option[column] is in the data table column (True)
+ Discard columns matching value (False)
+
+ """
+ def __init__(self, d_option, elem):
+ Filter.__init__(self, d_option, elem)
+ self.table_name = elem.get("table_name", None)
+ assert self.table_name is not None, "Required 'table_name' attribute missing from filter"
+ column = elem.get("column", None)
+ assert column is not None, "Required 'column' attribute missing from filter"
+ self.column = d_option.column_spec_to_index(column)
+ self.data_table_column = elem.get("data_table_column", None)
+ assert self.data_table_column is not None, "Required 'data_table_column' attribute missing from filter"
+ self.keep = string_as_bool(elem.get("keep", 'True'))
+
+ def filter_options(self, options, trans, other_values):
+ # get column from data table, by index or column name
+ entries = None
+ try:
+ entries = set([f[int(self.data_table_column)] for f in trans.app.tool_data_tables[self.table_name].get_fields()])
+ except TypeError:
+ pass
+ try:
+ entries = set([f[self.data_table_column] for f in trans.app.tool_data_tables[self.table_name].get_named_fields_list()])
+ except KeyError:
+ pass
+ if entries is None:
+ log.error(f"could not get data from column {self.data_table_column} from data_table {self.table_name}")
+ return options
+
+ rval = []
+ for o in options:
+ log.error(f"o {o}")
+ if self.keep == (o[self.column] in entries):
+ rval.append(o)
+ return rval
+
+
filter_types = dict(data_meta=DataMetaFilter,
param_value=ParamValueFilter,
static_value=StaticValueFilter,
@@ -508,7 +561,8 @@ def filter_options(self, options, trans, other_values):
attribute_value_splitter=AttributeValueSplitterFilter,
add_value=AdditionalValueFilter,
remove_value=RemoveValueFilter,
- sort_by=SortByColumnFilter)
+ sort_by=SortByColumnFilter,
+ data_table=DataTableFilter)
class DynamicOptions:
@@ -557,10 +611,12 @@ def load_from_parameter(from_parameter, transform_lines=None):
data_file = data_file.strip()
if not os.path.isabs(data_file):
full_path = os.path.join(self.tool_param.tool.app.config.tool_data_path, data_file)
+ log.error(f"full_path {full_path}")
if os.path.exists(full_path):
self.index_file = data_file
with open(full_path) as fh:
self.file_fields = self.parse_file_fields(fh)
+ log.error(f"exists file_fields {self.file_fields}")
else:
self.missing_index_file = data_file
elif dataset_file is not None:
diff --git a/test/functional/tool-data/test_file.tsv b/test/functional/tool-data/test_file.tsv
new file mode 100644
index 000000000000..22722e11bbae
--- /dev/null
+++ b/test/functional/tool-data/test_file.tsv
@@ -0,0 +1,2 @@
+hg19_value hg19 hg19_name hg19_path
+absent_value absent absent_name absent_path
diff --git a/test/functional/tools/filter_data_table.xml b/test/functional/tools/filter_data_table.xml
new file mode 100644
index 000000000000..6b7709a3fc69
--- /dev/null
+++ b/test/functional/tools/filter_data_table.xml
@@ -0,0 +1,45 @@
+
+ Filter on datatable entries
+ '$output'
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml
index bcf4de8167ae..074d4e2a515b 100644
--- a/test/functional/tools/samples_tool_conf.xml
+++ b/test/functional/tools/samples_tool_conf.xml
@@ -53,6 +53,7 @@
+