Skip to content

Commit

Permalink
Move edam data out of registry and into (web) app
Browse files Browse the repository at this point in the history
It's only used in API responses and the tool panels.
We surely don't want to load edam data when loading the registry while
setting metadata.
  • Loading branch information
mvdbeek committed Dec 11, 2023
1 parent ddc4045 commit c429262
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
17 changes: 17 additions & 0 deletions lib/galaxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
from galaxy.tool_util.deps import containers
from galaxy.tool_util.deps.dependencies import AppInfo
from galaxy.tool_util.deps.views import DependencyResolversView
from galaxy.tool_util.edam_util import (
EdamDictType,
load_edam_tree,
)
from galaxy.tool_util.verify.test_data import TestDataResolver
from galaxy.tools.biotools import get_galaxy_biotools_metadata_source
from galaxy.tools.cache import ToolCache
Expand Down Expand Up @@ -688,6 +692,19 @@ def __init__(self, **kwargs) -> None:
self.tool_shed_repository_cache = self._register_singleton(ToolShedRepositoryCache)
# Watch various config files for immediate reload
self.watchers = self._register_singleton(ConfigWatchers)
if self.is_webapp:
# Load edam data
edam_ontology_path = self.config.edam_toolbox_ontology_path
self.edam = self._register_singleton(
EdamDictType,
load_edam_tree(
None if not edam_ontology_path or not os.path.exists(edam_ontology_path) else edam_ontology_path,
"format_",
"data_",
"operation_",
"topic_",
),
)
self._configure_toolbox()
# Load Data Manager
self.data_managers = self._register_singleton(DataManagers) # type: ignore[type-abstract]
Expand Down
12 changes: 0 additions & 12 deletions lib/galaxy/datatypes/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,9 @@ class ConfigurationError(Exception):

class Registry:
def __init__(self, config=None):
edam_ontology_path = config.get("edam_toolbox_ontology_path", None) if config is not None else None
edam = {}
if edam_ontology_path:
edam = load_edam_tree(
None if not edam_ontology_path or not os.path.exists(edam_ontology_path) else edam_ontology_path,
"format_",
"data_",
"operation_",
"topic_",
)

self.log = logging.getLogger(__name__)
self.log.addHandler(logging.NullHandler())
self.config = config
self.edam = edam
self.datatypes_by_extension = {}
self.datatypes_by_suffix_inferences = {}
self.mimetypes_by_extension = {}
Expand Down
13 changes: 7 additions & 6 deletions lib/galaxy/managers/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from galaxy.datatypes.data import Data
from galaxy.datatypes.registry import Registry
from galaxy.tool_util.edam_util import EdamDictType


def view_index(
Expand Down Expand Up @@ -90,10 +91,10 @@ def view_converters(datatypes_registry: Registry) -> DatatypeConverterList:
return parse_obj_as(DatatypeConverterList, converters)


def _get_edam_details(datatypes_registry: Registry, edam_ids: Dict[str, str]) -> Dict[str, Dict]:
def _get_edam_details(edam: EdamDictType, edam_ids: Dict[str, str]) -> Dict[str, Dict]:
details_dict = {}
for format, edam_iri in edam_ids.items():
edam_details = datatypes_registry.edam.get(edam_iri, {})
edam_details = edam.get(edam_iri, {})

details_dict[format] = {
"prefix_IRI": edam_iri,
Expand All @@ -105,19 +106,19 @@ def _get_edam_details(datatypes_registry: Registry, edam_ids: Dict[str, str]) ->


def view_edam_formats(
datatypes_registry: Registry, detailed: Optional[bool] = False
edam: EdamDictType, datatypes_registry: Registry, detailed: Optional[bool] = False
) -> Union[Dict[str, str], Dict[str, Dict[str, str]]]:
if detailed:
return _get_edam_details(datatypes_registry, datatypes_registry.edam_formats)
return _get_edam_details(edam, datatypes_registry.edam_formats)
else:
return datatypes_registry.edam_formats


def view_edam_data(
datatypes_registry: Registry, detailed: Optional[bool] = False
edam: EdamDictType, datatypes_registry: Registry, detailed: Optional[bool] = False
) -> Union[Dict[str, str], Dict[str, Dict[str, str]]]:
if detailed:
return _get_edam_details(datatypes_registry, datatypes_registry.edam_data)
return _get_edam_details(edam, datatypes_registry.edam_data)
else:
return datatypes_registry.edam_data

Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/tool_util/edam_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
ROOT_OPERATION = "operation_0004"
ROOT_TOPIC = "topic_0003"

EdamDictType = Dict[str, Dict[str, str]]

def load_edam_tree(path: Optional[str] = None, *included_terms: str):

def load_edam_tree(path: Optional[str] = None, *included_terms: str) -> EdamDictType:
if path is not None:
assert os.path.exists(path), f"Failed to load EDAM tabular data at [{path}] path does not exist."
handle = open(path)
Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/tool_util/toolbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def __init__(
self._tool_tag_manager = self.tool_tag_manager()
self._init_tools_from_configs(config_filenames)

if not self.app.is_webapp:
return

if self.app.name == "galaxy" and self._integrated_tool_panel_config_has_contents:
self._load_tool_panel()

Expand Down Expand Up @@ -223,7 +226,7 @@ def to_model(self) -> ToolPanelViewModel:

for edam_view in listify(self.app.config.edam_panel_views):
mode = EdamPanelMode[edam_view]
tool_panel_views_list.append(EdamToolPanelView(self.app.datatypes_registry.edam, mode=mode))
tool_panel_views_list.append(EdamToolPanelView(self.app.edam, mode=mode))

if view_sources is not None:
for definition in view_sources.get_definitions():
Expand All @@ -233,7 +236,7 @@ def to_model(self) -> ToolPanelViewModel:
for tool_panel_view in tool_panel_views_list:
self._tool_panel_views[tool_panel_view.to_model().id] = tool_panel_view

if self.app.name == "galaxy":
if self.app.name == "galaxy" and self.app.is_webapp:
self._load_tool_panel_views()
if save_integrated_tool_panel:
self._save_integrated_tool_panel()
Expand Down
10 changes: 6 additions & 4 deletions lib/galaxy/webapps/galaxy/api/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
view_mapping,
view_sniffers,
)
from galaxy.tool_util.edam_util import EdamDictType
from . import (
depends,
Router,
Expand Down Expand Up @@ -57,6 +58,7 @@
@router.cbv
class FastAPIDatatypes:
datatypes_registry: Registry = depends(Registry)
edam: EdamDictType = depends(EdamDictType)

@router.get(
"/api/datatypes",
Expand Down Expand Up @@ -123,7 +125,7 @@ async def converters(self) -> DatatypeConverterList:
)
async def edam_formats(self) -> Dict[str, str]:
"""Gets a map of datatypes and their corresponding EDAM formats."""
return cast(Dict[str, str], view_edam_formats(self.datatypes_registry))
return cast(Dict[str, str], view_edam_formats(self.edam, self.datatypes_registry))

@router.get(
"/api/datatypes/edam_formats/detailed",
Expand All @@ -134,7 +136,7 @@ async def edam_formats(self) -> Dict[str, str]:
async def edam_formats_detailed(self):
"""Gets a map of datatypes and their corresponding EDAM formats.
EDAM formats contain the EDAM iri, label, and definition."""
return view_edam_formats(self.datatypes_registry, True)
return view_edam_formats(self.edam, self.datatypes_registry, True)

@router.get(
"/api/datatypes/edam_data",
Expand All @@ -143,7 +145,7 @@ async def edam_formats_detailed(self):
)
async def edam_data(self) -> Dict[str, str]:
"""Gets a map of datatypes and their corresponding EDAM data."""
return cast(Dict[str, str], view_edam_data(self.datatypes_registry))
return cast(Dict[str, str], view_edam_data(self.edam, self.datatypes_registry))

@router.get(
"/api/datatypes/edam_data/detailed",
Expand All @@ -154,4 +156,4 @@ async def edam_data(self) -> Dict[str, str]:
async def edam_data_detailed(self):
"""Gets a map of datatypes and their corresponding EDAM data.
EDAM data contains the EDAM iri, label, and definition."""
return view_edam_data(self.datatypes_registry, True)
return view_edam_data(self.edam, self.datatypes_registry, True)

0 comments on commit c429262

Please sign in to comment.