From 0ae3705acd099623b77dd1b3a2b97cb988c83740 Mon Sep 17 00:00:00 2001 From: Peter van Heusden Date: Mon, 1 Aug 2022 13:35:46 +0200 Subject: [PATCH 1/2] Allow sort order for sort_by to be reversed --- lib/galaxy/tool_util/xsd/galaxy.xsd | 13 ++++++++++--- lib/galaxy/tools/parameters/dynamic_options.py | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/tool_util/xsd/galaxy.xsd b/lib/galaxy/tool_util/xsd/galaxy.xsd index b1705fae412..5938d93e7c7 100644 --- a/lib/galaxy/tool_util/xsd/galaxy.xsd +++ b/lib/galaxy/tool_util/xsd/galaxy.xsd @@ -4666,10 +4666,10 @@ In both cases the desired metadata is selected by ``key``. The ``static_value`` and ``regexp`` 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``. +* ``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 specified with ``ref``, or the metadata ``key`` of another input ``meta_ref``. * ``unique_value``: remove options that have duplicate entries in the given ``column``. -* ``sort_by``: sort options by the entries of a given ``column``. +* ``sort_by``: sort options by the entries of a given ``column``. If ``reverse_sort_order`` is set to ``true``, reverse sort order from ascending to descending. * ``multiple_splitter``: split the entries of the specified ``column``(s) in the referenced file using a ``separator``. Thereby the number of columns is increased. ### Examples @@ -4858,6 +4858,13 @@ added to the end of the list. from the list. + + + Used when ``type`` is ``sort_by``, if set to + ``true`` it will reverse the sort order from ascending to descending. Default + is ``false``. + + diff --git a/lib/galaxy/tools/parameters/dynamic_options.py b/lib/galaxy/tools/parameters/dynamic_options.py index af9fbd2f1f0..1e6a54ff576 100644 --- a/lib/galaxy/tools/parameters/dynamic_options.py +++ b/lib/galaxy/tools/parameters/dynamic_options.py @@ -516,9 +516,10 @@ class SortByColumnFilter(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.reverse = elem.get("reverse_sort_order", False) def filter_options(self, options, trans, other_values): - return sorted(options, key=lambda x: x[self.column]) + return sorted(options, key=lambda x: x[self.column], reverse=self.reverse) filter_types = dict( From 5fa81610e8502968f5e369cca6b05742fc575769 Mon Sep 17 00:00:00 2001 From: Peter van Heusden Date: Mon, 1 Aug 2022 14:17:19 +0200 Subject: [PATCH 2/2] Correctly use string_as_bool for sort_by reverse_sort_order --- lib/galaxy/tools/parameters/dynamic_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/tools/parameters/dynamic_options.py b/lib/galaxy/tools/parameters/dynamic_options.py index 1e6a54ff576..b677f0cdae8 100644 --- a/lib/galaxy/tools/parameters/dynamic_options.py +++ b/lib/galaxy/tools/parameters/dynamic_options.py @@ -516,7 +516,7 @@ class SortByColumnFilter(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.reverse = elem.get("reverse_sort_order", False) + self.reverse = string_as_bool(elem.get("reverse_sort_order", "False")) def filter_options(self, options, trans, other_values): return sorted(options, key=lambda x: x[self.column], reverse=self.reverse)