Warning
This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.
Source code for galaxy.tool_util.biotools.interface
import re
from typing import (
Any,
)
TERM_PATTERN = re.compile(r"https?://edamontology.org/(.*)")
[docs]
class ParsedBiotoolsEntry:
"""Provide XML wrapper relevant entities from a bio.tool entry - topics and operations."""
biotoolsID: str
edam_topics: list[str]
edam_operations: list[str]
[docs]
class BiotoolsEntry:
"""Parse the RAW entries of interest for Galaxy from a bio.tools entry."""
biotoolsID: str
topic: list[dict]
function: list[dict]
[docs]
@staticmethod
def from_json(from_json: dict[str, Any]) -> "BiotoolsEntry":
entry = BiotoolsEntry()
entry.biotoolsID = from_json["biotoolsID"]
entry.topic = from_json.get("topic", [])
entry.function = from_json.get("function", [])
return entry
@property
def edam_info(self) -> ParsedBiotoolsEntry:
parsed = ParsedBiotoolsEntry()
parsed.biotoolsID = self.biotoolsID
parsed.edam_topics = list(set(simplify_edam_dicts(self.topic)))
operations = []
for function in self.function:
if "operation" in function:
operations.extend(simplify_edam_dicts(function["operation"]))
parsed.edam_operations = list(set(operations))
return parsed
[docs]
def simplify_edam_dicts(a_list: list[dict[str, str]]):
terms = []
for term in map(simplify_edam_dict, a_list):
if term:
terms.append(term)
return terms
[docs]
def simplify_edam_dict(as_dict: dict[str, str]) -> str | None:
uri = as_dict["uri"]
if match := TERM_PATTERN.match(uri):
return match.group(1)
else:
# TODO: log problem...
return None