From af612e93424fb57decd2d19aaa2e5478901fea99 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Tue, 26 Mar 2024 09:40:15 +0100 Subject: [PATCH] add linting for valid EDAM terms --- lib/galaxy/tool_util/linters/general.py | 12 ++++++++++ test/unit/tool_util/test_tool_linters.py | 28 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/linters/general.py b/lib/galaxy/tool_util/linters/general.py index 10fe98e9000f..eb3a98fd3b82 100644 --- a/lib/galaxy/tool_util/linters/general.py +++ b/lib/galaxy/tool_util/linters/general.py @@ -9,6 +9,7 @@ from packaging.version import Version from galaxy.tool_util.biotools.source import ApiBiotoolsMetadataSource +from galaxy.tool_util.edam_util import load_edam_tree from galaxy.tool_util.lint import Linter from galaxy.tool_util.version import ( LegacyVersion, @@ -241,3 +242,14 @@ def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): metadata_source = ApiBiotoolsMetadataSource() if not metadata_source.get_biotools_metadata(xref["value"]): lint_ctx.warn(f'No entry {xref["value"]} in bio.tools.', linter=cls.name(), node=tool_node) + + +class EDAMTermsValid(Linter): + @classmethod + def lint(cls, tool_source: "ToolSource", lint_ctx: "LintContext"): + _, tool_node = _tool_xml_and_root(tool_source) + edam = load_edam_tree(None, "operation_", "topic_") + terms = tool_source.parse_edam_operations() + tool_source.parse_edam_topics() + for term in terms: + if term not in edam: + lint_ctx.warn(f"No entry '{term}' in EDAM.", linter=cls.name(), node=tool_node) diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index e51c0e75d7f3..57285e5dd2df 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -128,6 +128,19 @@ """ +GENERAL_VALID_EDAM = """ + + + topic_2269 + topic_000 + + + operation_3434 + operation_000 + + +""" + # test tool xml for help linter HELP_MULTIPLE = """ @@ -1102,6 +1115,19 @@ def test_general_valid_biotools(lint_ctx): assert not lint_ctx.error_messages +def test_general_valid_edam(lint_ctx): + tool_source = get_xml_tool_source(GENERAL_VALID_EDAM) + run_lint_module(lint_ctx, general, tool_source) + assert "No entry 'operation_000' in EDAM." in lint_ctx.warn_messages + assert "No entry 'topic_000' in EDAM." in lint_ctx.warn_messages + assert not lint_ctx.info_messages + assert len(lint_ctx.valid_messages) == 4 + assert len(lint_ctx.warn_messages) == 2 + # accept 2 xsd errors due to malformed topic/operation ID + # which should make sure that the id never becomes valid + assert len(lint_ctx.error_messages) == 2 + + def test_help_multiple(lint_ctx): tool_source = get_xml_tool_source(HELP_MULTIPLE) run_lint_module(lint_ctx, help, tool_source) @@ -2099,7 +2125,7 @@ def test_xml_comments_are_ignored(lint_ctx: LintContext): def test_list_linters(): linter_names = Linter.list_listers() # make sure to add/remove a test for new/removed linters if this number changes - assert len(linter_names) == 131 + assert len(linter_names) == 132 assert "Linter" not in linter_names # make sure that linters from all modules are available for prefix in [