Skip to content

Commit

Permalink
add linting for valid EDAM terms
Browse files Browse the repository at this point in the history
  • Loading branch information
bernt-matthias committed Mar 26, 2024
1 parent 53e0ac5 commit af612e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/galaxy/tool_util/linters/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
28 changes: 27 additions & 1 deletion test/unit/tool_util/test_tool_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
</tool>
"""

GENERAL_VALID_EDAM = """
<tool name="valid name" id="valid_id" version="1.0+galaxy1" profile="23.0">
<edam_topics>
<edam_topic>topic_2269</edam_topic>
<edam_topic>topic_000</edam_topic>
</edam_topics>
<edam_operations>
<edam_operation>operation_3434</edam_operation>
<edam_operation>operation_000</edam_operation>
</edam_operations>
</tool>
"""

# test tool xml for help linter
HELP_MULTIPLE = """
<tool id="id" name="name">
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 [
Expand Down

0 comments on commit af612e9

Please sign in to comment.