From 817b97553ffe7f9edb66c6c6a468bfafe4e4afe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9r=C3=A9nice=20Batut?= Date: Thu, 22 Feb 2024 15:48:44 +0100 Subject: [PATCH] Add script to generate from tool table a YAML to install the tool --- bin/generate_tool_install_yaml.py | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 bin/generate_tool_install_yaml.py diff --git a/bin/generate_tool_install_yaml.py b/bin/generate_tool_install_yaml.py new file mode 100644 index 00000000..5edabad1 --- /dev/null +++ b/bin/generate_tool_install_yaml.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +import argparse + +import pandas as pd +import yaml + +COLUMNS = { + "Galaxy tool ids": "name", + "Galaxy wrapper owner": "owner", + "EDAM operation": "tool_panel_section_label", +} + + +def generate_install_yaml( + tsv_path: str, + output_path: str, +) -> None: + df = pd.read_csv(tsv_path, sep="\t").assign(Expand=lambda df: "").fillna("") + if "To keep" in df.columns: + df["To keep"] = df["To keep"].replace("", False) + df = df.query("`To keep`") + df = df.loc[:, COLUMNS.keys()].reindex(columns=COLUMNS.keys()).rename(columns=COLUMNS) + df["name"] = df["name"].str.split(", ") + df = df.explode("name") + print(df) + + tool_dict = { + "install_tool_dependencies": True, + "install_repository_dependencies": True, + "install_resolver_dependencies": True, + "tools": df.to_dict("records"), + } + + with open(output_path, "w") as output: + yaml.dump(tool_dict, output, default_flow_style=False) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Generate the YAML to install the tools on a Galaxy server \ + from TSV file" + ) + parser.add_argument( + "--table", + "-ta", + required=True, + help="Path to TSV file with tools", + ) + parser.add_argument( + "--output", + "-out", + required=True, + help="Path to YAML output", + ) + + args = parser.parse_args() + generate_install_yaml(args.table, args.output)