From 37a672607733fd5dd748c1d833320d38a6a9582c Mon Sep 17 00:00:00 2001 From: Wolfgang Maier Date: Mon, 23 Sep 2024 15:41:35 +0200 Subject: [PATCH 1/3] Rely on get_column_list as only source of truth --- lib/galaxy/tools/parameters/basic.py | 31 +++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 9669b62771e9..31eb54953175 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1507,6 +1507,9 @@ def get_options(self, trans, other_values): Show column labels rather than c1..cn if use_header_names=True """ options: List[Tuple[str, Union[str, Tuple[str, str]], bool]] = [] + column_list = self.get_column_list(trans, other_values) + if not column_list: + return options # if available use column_names metadata for option names # otherwise read first row - assume is a header with tab separated names if self.usecolnames: @@ -1516,29 +1519,23 @@ def get_options(self, trans, other_values): and hasattr(dataset.metadata, "column_names") and dataset.metadata.element_is_set("column_names") ): - column_list = [ - ("%d" % (i + 1), "c%d: %s" % (i + 1, x)) for i, x in enumerate(dataset.metadata.column_names) - ] + try: + options = [("c%s: %s" % (c, dataset.metadata.column_names[int(c) - 1]), c, False) for c in column_list] + except IndexError: + # ignore and rely on fallback + pass else: try: with open(dataset.get_file_name()) as f: head = f.readline() cnames = head.rstrip("\n\r ").split("\t") - column_list = [("%d" % (i + 1), "c%d: %s" % (i + 1, x)) for i, x in enumerate(cnames)] + options = [("c%s: %s" % (c, cnames[int(c) - 1]), c, False) for i in column_list] except Exception: - column_list = self.get_column_list(trans, other_values) - if self.numerical: # If numerical was requested, filter columns based on metadata - if hasattr(dataset, "metadata") and getattr(dataset.metadata, "column_types", None) is not None: - if len(dataset.metadata.column_types) >= len(column_list): - numerics = [i for i, x in enumerate(dataset.metadata.column_types) if x in ["int", "float"]] - column_list = [column_list[i] for i in numerics] - else: - column_list = self.get_column_list(trans, other_values) - for col in column_list: - if isinstance(col, tuple) and len(col) == 2: - options.append((col[1], col[0], False)) - else: - options.append((f"Column: {col}", col, False)) + # ignore and rely on fallback + pass + if not options: + # fallback if no options list could be built so far + options = [(f"Column: {col}", col, False) for col in column_list] return options def get_initial_value(self, trans, other_values): From 724c83f16a533dd85d0cfdc86c239f94e6b88377 Mon Sep 17 00:00:00 2001 From: Wolfgang Maier Date: Tue, 24 Sep 2024 11:27:09 +0200 Subject: [PATCH 2/3] Fix typo --- lib/galaxy/tools/parameters/basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index 31eb54953175..f017f0e69bcf 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1529,7 +1529,7 @@ def get_options(self, trans, other_values): with open(dataset.get_file_name()) as f: head = f.readline() cnames = head.rstrip("\n\r ").split("\t") - options = [("c%s: %s" % (c, cnames[int(c) - 1]), c, False) for i in column_list] + options = [("c%s: %s" % (c, cnames[int(c) - 1]), c, False) for c in column_list] except Exception: # ignore and rely on fallback pass From fb3b7177dd0415312ef35996a4fe0fd8ebcde8d0 Mon Sep 17 00:00:00 2001 From: Wolfgang Maier Date: Tue, 24 Sep 2024 11:46:26 +0200 Subject: [PATCH 3/3] Use format strings to form option values --- lib/galaxy/tools/parameters/basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/tools/parameters/basic.py b/lib/galaxy/tools/parameters/basic.py index f017f0e69bcf..c33183430771 100644 --- a/lib/galaxy/tools/parameters/basic.py +++ b/lib/galaxy/tools/parameters/basic.py @@ -1520,7 +1520,7 @@ def get_options(self, trans, other_values): and dataset.metadata.element_is_set("column_names") ): try: - options = [("c%s: %s" % (c, dataset.metadata.column_names[int(c) - 1]), c, False) for c in column_list] + options = [(f"c{c}: {dataset.metadata.column_names[int(c) - 1]}", c, False) for c in column_list] except IndexError: # ignore and rely on fallback pass @@ -1529,7 +1529,7 @@ def get_options(self, trans, other_values): with open(dataset.get_file_name()) as f: head = f.readline() cnames = head.rstrip("\n\r ").split("\t") - options = [("c%s: %s" % (c, cnames[int(c) - 1]), c, False) for c in column_list] + options = [(f"c{c}: {cnames[int(c) - 1]}", c, False) for c in column_list] except Exception: # ignore and rely on fallback pass