Skip to content

Commit

Permalink
Download edam ontology if not present
Browse files Browse the repository at this point in the history
and beta edam tool panel enabled.
  • Loading branch information
hexylena authored and mvdbeek committed Oct 30, 2020
1 parent 25af8b0 commit 87bc18d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
14 changes: 12 additions & 2 deletions doc/source/admin/galaxy_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3198,8 +3198,18 @@
:Description:
Sets the path to EDAM ontology file.
The value of this option will be resolved with respect to
<config_dir>.
:Default: ``EDAM_1.23.tsv``
<data_dir>.
:Default: ``EDAM.tsv``
:Type: str


~~~~~~~~~~~~~~~~~~~~~~~~~~
``beta_edam_ontology_url``
~~~~~~~~~~~~~~~~~~~~~~~~~~

:Description:
Sets the url to the EDAM ontology file.
:Default: ``http://edamontology.org/EDAM.tsv``
:Type: str


Expand Down
7 changes: 5 additions & 2 deletions lib/galaxy/config/sample/galaxy.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -1595,8 +1595,11 @@ galaxy:

# Sets the path to EDAM ontology file.
# The value of this option will be resolved with respect to
# <config_dir>.
#beta_edam_toolbox_ontology_path: EDAM_1.23.tsv
# <data_dir>.
#beta_edam_toolbox_ontology_path: EDAM.tsv

# Sets the url to the EDAM ontology file.
#beta_edam_ontology_url: http://edamontology.org/EDAM.tsv

# Default format for the export of workflows. Possible values are 'ga'
# or 'format2'.
Expand Down
35 changes: 25 additions & 10 deletions lib/galaxy/tools/toolbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from galaxy.tool_util.loader_directory import looks_like_a_tool
from galaxy.util import (
download_to_file,
etree,
ExecutionTimer,
listify,
Expand All @@ -32,6 +33,7 @@
)
from galaxy.util.bunch import Bunch
from galaxy.util.dictifiable import Dictifiable
from galaxy.util.renamed_temporary_file import RenamedTemporaryFile
from .filters import FilterFactory
from .integrated_panel import ManagesIntegratedToolPanelMixin
from .lineages import LineageMap
Expand Down Expand Up @@ -110,16 +112,7 @@ def __init__(self, config_filenames, tool_root_dir, app, save_integrated_tool_pa
self._filter_factory = FilterFactory(self)
self._tool_tag_manager = tool_tag_manager(app)
self._init_tools_from_configs(config_filenames)

if self.app.config.enable_beta_edam_toolbox:
with open(self.app.config.beta_edam_toolbox_ontology_path, 'r') as handle:
self.edam = {}
for idx, line in enumerate(handle.readlines()):
fields = line.split('\t')
if not fields[0].startswith('http://edamontology.org/'):
continue
term_id = fields[0][len('http://edamontology.org/'):]
self.edam[term_id] = fields[1] # preferred label
self.edam = self._load_edam_terms()

if self.app.name == 'galaxy' and self._integrated_tool_panel_config_has_contents:
# Load self._tool_panel based on the order in self._integrated_tool_panel.
Expand All @@ -139,6 +132,28 @@ def create_dynamic_tool(self, dynamic_tool):
def can_load_config_file(self, config_filename):
return True

def _load_edam_terms(self):
edam = {}
if self.app.config.enable_beta_edam_toolbox:
path_exists = os.path.exists(self.app.config.beta_edam_toolbox_ontology_path)
if not path_exists:
try:
with RenamedTemporaryFile(self.app.config.beta_edam_toolbox_ontology_path) as out:
download_to_file(self.app.config.beta_edam_ontology_url, out.name)
path_exists = True
except Exception:
log.exception()

if path_exists:
with open(self.app.config.beta_edam_toolbox_ontology_path, 'r') as handle:
for line in handle.readlines():
fields = line.split('\t')
if not fields[0].startswith('http://edamontology.org/'):
continue
term_id = fields[0][len('http://edamontology.org/'):]
edam[term_id] = fields[1] # preferred label
return edam

def _init_tools_from_configs(self, config_filenames):
""" Read through all tool config files and initialize tools in each
with init_tools_from_config below.
Expand Down
11 changes: 9 additions & 2 deletions lib/galaxy/webapps/galaxy/config_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2333,12 +2333,19 @@ mapping:
beta_edam_toolbox_ontology_path:
type: str
default: EDAM_1.23.tsv
path_resolves_to: config_dir
default: EDAM.tsv
path_resolves_to: data_dir
required: false
desc: |
Sets the path to EDAM ontology file.
beta_edam_ontology_url:
type: str
default: http://edamontology.org/EDAM.tsv
required: false
desc: |
Sets the url to the EDAM ontology file.
default_workflow_export_format:
type: str
default: ga
Expand Down
1 change: 1 addition & 0 deletions test/unit/config/test_config_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def _load_paths(self):
'datatypes_config_file': self._in_sample_dir('datatypes_conf.xml.sample'),
'dependency_resolvers_config_file': self._in_config_dir('dependency_resolvers_conf.xml'),
'dynamic_proxy_session_map': self._in_data_dir('session_map.sqlite'),
'beta_edam_toolbox_ontology_path' : self._in_data_dir('EDAM.tsv'),
'error_report_file': self._in_config_dir('error_report.yml'),
'file_path': self._in_data_dir('objects'),
'file_sources_config_file': self._in_config_dir('file_sources_conf.yml'),
Expand Down

0 comments on commit 87bc18d

Please sign in to comment.