Galaxy Tool Utilities

26.0.0 · active · verified Fri Apr 17

galaxy-tool-util provides core utilities for parsing, managing, and validating Galaxy tool definitions and tool dependencies. It is an essential component for understanding and extending the Galaxy bioinformatics platform. The library is part of the larger Galaxy project and is released in lock-step with major Galaxy versions, typically every few months.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a Galaxy tool XML definition using `get_tool_source`. It creates a simple XML file, parses it, and prints basic metadata. Note that full linting (`lint_tool_xml`) often requires a more complete Galaxy environment or specific mock objects for its various checks.

import os
from galaxy.tool_util.parser import get_tool_source
from galaxy.tool_util.linters import lint_tool_xml

# Create a dummy tool XML file for demonstration
tool_xml_content = """
<tool id="test_tool" name="Test Tool" version="1.0.0">
    <description>A simple test tool</description>
    <command>echo "Hello World"</command>
    <inputs>
        <param name="input_text" type="text" label="Input text"/>
    </inputs>
    <outputs>
        <data name="output_file" format="txt" label="Output Text File"/>
    </outputs>
    <tests>
        <test>
            <param name="input_text" value="test"/>
            <output name="output_file" ftype="txt" value="Hello World" compare="re"/>
        </test>
    </tests>
</tool>
"""

tool_path = "dummy_tool.xml"
with open(tool_path, "w") as f:
    f.write(tool_xml_content)

# 1. Parse the tool XML
try:
    tool_source = get_tool_source(tool_path)
    print(f"Successfully parsed tool: {tool_source.parse_id()} (version {tool_source.parse_version()})")

    # 2. Linter (basic validation)
    # The lint_tool_xml function typically requires a tool_shed_repository mock for full functionality
    # For a simple local file, we can run it with minimal context.
    # In a real Galaxy environment, this would be part of a larger object.
    print("Running linter...")
    lint_problems = []
    # The linter expects an XML root element, not a path directly.
    # For this quickstart, we'll demonstrate using a basic parse.
    from xml.etree import ElementTree
    root = ElementTree.parse(tool_path).getroot()

    # lint_tool_xml needs a ToolSource object, not just the root.
    # For a basic lint, you often need the full Galaxy context or specific mocks.
    # This example focuses on parsing.
    print("Basic parsing complete. Full linting requires more context.")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists(tool_path):
        os.remove(tool_path)

view raw JSON →