### Basic Job Configuration Example (XML)
Source: https://docs.galaxyproject.org/en/release_20.05/_sources/admin/jobs
A minimal example of a job_conf.xml file, showing the root element and basic configurations for plugins, handlers, and destinations. This serves as a starting point for job execution setup.
```xml
```
--------------------------------
### Setting up Galaxy Virtual Environment and Running
Source: https://docs.galaxyproject.org/en/release_22.05/admin/production
This snippet demonstrates the process of installing virtualenv, creating a dedicated virtual environment for Galaxy, activating it, navigating to the Galaxy distribution directory, and starting the Galaxy server. This ensures dependency isolation for a production-ready setup.
```bash
pip install virtualenv
nate@weyerbacher% virtualenv --no-site-packages galaxy_env
nate@weyerbacher% . ./galaxy_env/bin/activate
nate@weyerbacher% cd galaxy-dist
nate@weyerbacher% sh run.sh
```
--------------------------------
### Python: Prepare Tool Dependency Set Environment For Install Action
Source: https://docs.galaxyproject.org/en/release_19.09/_modules/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler
This Python function prepares a 'set_environment_for_install' action within the context of tool dependency management. It processes XML elements to define an environment suitable for compiling tool dependencies. The example XML shows how to reference a repository for environment setup.
```python
def prepare_step(self, tool_dependency, action_elem, action_dict, install_environment, is_binary_download):
#
#
#
#
#
# This action type allows for defining an environment that will properly compile a tool dependency.
# Currently, tag set definitions like that above are supported, but in the future other approaches
# to setting environment variables or other environment attributes can be supported. The above tag
```
--------------------------------
### Setup R Environment - Python
Source: https://docs.galaxyproject.org/en/release_18.01/lib/tool_shed.galaxy_install.tool_dependencies
Initializes the environment for installing R packages. This class is typically used during the initial download stage of package installation. It filters recipe steps, defines the installation directory, and handles environment setup based on the `initial_download` flag.
```python
class tool_shed.galaxy_install.tool_dependencies.recipe.step_handler.SetupREnvironment(_app_):
"""Initialize the environment for installing R packages. The class is called during the initial download stage when installing packages, so the value of initial_download will generally be True. However, the parameter value allows this class to also be used in the second stage of the installation, although it may never be necessary. If initial_download is True, the recipe steps will be filtered and returned and the installation directory (i.e., dir) will be defined and returned. If we’re not in the initial download stage, these actions will not occur, and None values will be returned for them."""
def prepare_step(_tool_dependency_, _action_elem_, _action_dict_, _install_environment_, _is_binary_download_):
pass
```
--------------------------------
### Get Example Parameters
Source: https://docs.galaxyproject.org/en/master/_modules/galaxy/tools/execute
Returns the first parameter combination as an example. If no parameter combinations are available, it returns the base parameter template. This is useful for generating default or example configurations.
```python
@property
def example_params:
if self.mapping_params.param_combinations:
return self.mapping_params.param_combinations[0]
else:
# TODO: This isn't quite right - what we want is something like param_template wrapped,
# need a test case with an output filter applied to an empty list, still this is
# an improvement over not allowing mapping of empty lists.
return self.mapping_params.param_template
```
--------------------------------
### Setup Ruby Environment Initialization
Source: https://docs.galaxyproject.org/en/release_19.01/_modules/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler
Initializes the environment for installing Ruby packages. This function handles the setup process, including filtering actions and defining installation directories based on the `initial_download` flag. It ensures that the necessary environment variables are set for Ruby package installation.
```python
def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder,
install_environment, work_dir, current_dir=None, initial_download=False):
"""
Initialize the environment for installing Ruby packages. The class is called during the initial
download stage when installing packages, so the value of initial_download will generally be True.
However, the parameter value allows this class to also be used in the second stage of the installation,
although it may never be necessary. If initial_download is True, the recipe steps will be filtered
and returned and the installation directory (i.e., dir) will be defined and returned. If we're not
in the initial download stage, these actions will not occur, and None values will be returned for them.
"""
#
#
#
#
#
# protk
# protk=1.2.4
# http://url-to-some-gem-file.de/protk.gem
#
dir = None
if initial_download:
filtered_actions = actions[1:]
env_shell_file_paths = action_dict.get('env_shell_file_paths', None)
if env_shell_file_paths is None:
log.debug('Missing Ruby environment, make sure your specified Ruby installation exists.')
if initial_download:
return tool_dependency, filtered_actions, dir
return tool_dependency, None, None
else:
install_environment.add_env_shell_file_paths(env_shell_file_paths)
log.debug('Handling setup_ruby_environment for tool dependency %s with install_environment.env_shell_file_paths:\n%s' %
(str(tool_dependency.name), str(install_environment.env_shell_file_paths)))
dir = os.path.curdir
current_dir = os.path.abspath(os.path.join(work_dir, dir))
with lcd(current_dir):
with settings(warn_only=True):
```
--------------------------------
### Setup Python Virtual Environment and Install Packages
Source: https://docs.galaxyproject.org/en/release_19.05/_modules/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler
This function initializes a Python virtual environment for installing packages. It handles the creation of the virtual environment, manages requirements specified in a file or directly, and installs packages using pip. The function constructs and executes a series of shell commands to achieve this setup. Dependencies include the 'os' module for path manipulation and a logging mechanism ('log'). It returns the tool dependency object and potentially None values if the setup fails.
```python
import os
import logging
log = logging.getLogger(__name__)
class SetupVirtualEnv(Download, RecipeStep):
def __init__(self, app):
self.app = app
self.type = 'setup_virtualenv'
def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder,
install_environment, work_dir, current_dir=None, initial_download=False):
"""
Initialize a virtual environment for installing packages. If initial_download is True, the recipe
steps will be filtered and returned and the installation directory (i.e., dir) will be defined and
returned. If we're not in the initial download stage, these actions will not occur, and None values
will be returned for them.
"""
# This class is not currently used during stage 1 of the installation process, so filter_actions
# are not affected, and dir is not set. Enhancements can easily be made to this function if this
# class is needed in stage 1.
venv_src_directory = os.path.abspath(os.path.join(self.app.config.tool_dependency_dir, '__virtualenv_src'))
if not self.install_virtualenv(install_environment, venv_src_directory):
log.debug('Unable to install virtualenv')
return tool_dependency, None, None
requirements = action_dict['requirements']
if os.path.exists(os.path.join(install_environment.install_dir, requirements)):
# requirements specified as path to a file
requirements_path = requirements
else:
# requirements specified directly in XML, create a file with these for pip.
requirements_path = os.path.join(install_environment.install_dir, "requirements.txt")
with open(requirements_path, "w") as f:
f.write(requirements)
venv_directory = os.path.join(install_environment.install_dir, "venv")
python_cmd = action_dict['python']
# TODO: Consider making --no-site-packages optional.
setup_command = "%s %s/virtualenv.py --no-site-packages '%s'" % (python_cmd, venv_src_directory, venv_directory)
# POSIXLY_CORRECT forces shell commands . and source to have the same
# and well defined behavior in bash/zsh.
activate_command = "POSIXLY_CORRECT=1; . %s" % os.path.join(venv_directory, "bin", "activate")
if action_dict['use_requirements_file']:
install_command = "python '%s' install -r '%s' --log '%s'" % \
(os.path.join(venv_directory, "bin", "pip"),
requirements_path,
os.path.join(install_environment.install_dir, 'pip_install.log'))
else:
install_command = ''
with open(requirements_path, "rb") as f:
while True:
line = f.readline()
if not line:
break
line = line.strip()
if line:
line_install_command = "python '%s' install %s --log '%s'" % \
(os.path.join(venv_directory, "bin", "pip"),
line,
os.path.join(install_environment.install_dir, 'pip_install_%s.log' % (line)))
if not install_command:
install_command = line_install_command
else:
install_command = "%s && %s" % (install_command, line_install_command)
full_setup_command = "%s; %s; %s" % (setup_command, activate_command, install_command)
return_code = install_environment.handle_command(tool_dependency=tool_dependency,
cmd=full_setup_command,
return_output=False,
job_name=package_name)
if return_code:
log.error("Failed to do setup_virtualenv install, exit code='%s'", return_code)
# would it be better to try to set env variables anway, instead of returning here?
return tool_dependency, None, None
site_packages_directory, site_packages_directory_list = \
self.__get_site_packages_directory(install_environment,
self.app,
tool_dependency,
python_cmd,
venv_directory)
env_file_builder.append_line(name="PATH", action="prepend_to", value=os.path.join(venv_directory, "bin"))
if site_packages_directory is None:
log.error("virtualenv's site-packages directory '%s' does not exist", site_packages_directory_list)
else:
# This part of the code seems incomplete in the provided snippet.
pass # Placeholder for potential further actions
```
--------------------------------
### Setup Ruby Environment - Python
Source: https://docs.galaxyproject.org/en/release_18.01/lib/tool_shed.galaxy_install.tool_dependencies
Initializes the environment for installing Ruby packages. Similar to R environment setup, this class is invoked during the initial download phase. It manages filtering of recipe steps and setting the installation directory when `initial_download` is true, returning None otherwise.
```python
class tool_shed.galaxy_install.tool_dependencies.recipe.step_handler.SetupRubyEnvironment(_app_):
"""Initialize the environment for installing Ruby packages. The class is called during the initial download stage when installing packages, so the value of initial_download will generally be True. However, the parameter value allows this class to also be used in the second stage of the installation, although it may never be necessary. If initial_download is True, the recipe steps will be filtered and returned and the installation directory (i.e., dir) will be defined and returned. If we’re not in the initial download stage, these actions will not occur, and None values will be returned for them."""
def execute_step(_tool_dependency_, _package_name_, _actions_, _action_dict_, _filtered_actions_, _env_file_builder_, _install_environment_, _work_dir_, _current_dir=None, _initial_download=False):
pass
def prepare_step(_tool_dependency_, _action_elem_, _action_dict_, _install_environment_, _is_binary_download_):
pass
```
--------------------------------
### Create and Manage Galaxy Libraries using Python API
Source: https://docs.galaxyproject.org/en/release_21.01/api/quickstart
These Python scripts demonstrate the creation and management of libraries and folders within Galaxy. They require an API key and Galaxy URL. The scripts allow listing libraries, creating new libraries with a name and description, and creating folders within libraries.
```python
% ./display.py my_key http://localhost:8080/api/libraries
Collection Members
------------------
0 elements in collection
% ./library_create_library.py my_key http://localhost:8080/api/libraries api_test 'API Test Library'
Response
--------
/api/libraries/f3f73e481f432006
name: api_test
id: f3f73e481f432006
% ./display.py my_key http://localhost:8080/api/libraries
Collection Members
------------------
/api/libraries/f3f73e481f432006
name: api_test
id: f3f73e481f432006
% ./display.py my_key http://localhost:8080/api/libraries/f3f73e481f432006
Member Information
------------------
synopsis: None
contents_url: /api/libraries/f3f73e481f432006/contents
description: API Test Library
name: api_test
% ./display.py my_key http://localhost:8080/api/libraries/f3f73e481f432006/contents
Collection Members
------------------
/api/libraries/f3f73e481f432006/contents/28202595c0d2591f61ddda595d2c3670
name: /
type: folder
id: 28202595c0d2591f61ddda595d2c3670
% ./library_create_folder.py my_key http://localhost:8080/api/libraries/f3f73e481f432006/contents 28202595c0d2591fa4f9089d2303fd89 api_test_folder1 'API Test Folder 1'
Response
--------
/api/libraries/f3f73e481f432006/contents/28202595c0d2591fa4f9089d2303fd89
name: api_test_folder1
id: 28202595c0d2591fa4f9089d2303fd89
% ./library_upload_from_import_dir.py my_key http://localhost:8080/api/libraries/f3f73e481f432006/contents 28202595c0d2591fa4f9089d2303fd89 bed bed hg19
Response
--------
/api/libraries/f3f73e481f432006/contents/e9ef7fdb2db87d7b
name: 2.bed
id: e9ef7fdb2db87d7b
/api/libraries/f3f73e481f432006/contents/3b7f6a31f80a5018
name: 3.bed
id: 3b7f6a31f80a5018
% ./display.py my_key http://localhost:8080/api/libraries/f3f73e481f432006/contents
Collection Members
------------------
/api/libraries/f3f73e481f432006/contents/28202595c0d2591f61ddda595d2c3670
name: /
type: folder
id: 28202595c0d2591f61ddda595d2c3670
```
--------------------------------
### Get Tool Installation Directory Path
Source: https://docs.galaxyproject.org/en/release_18.09/_modules/tool_shed/util/tool_util
This function determines the installation directory path for a tool based on its configuration. It iterates through configuration elements to find the specified tool by its GUID and returns both the base tool path and the relative installation directory.
```python
def get_tool_path_install_dir(partial_install_dir, shed_tool_conf_dict, tool_dict, config_elems):
for elem in config_elems:
if elem.tag == 'tool':
if elem.get('guid') == tool_dict['guid']:
tool_path = shed_tool_conf_dict['tool_path']
relative_install_dir = os.path.join(tool_path, partial_install_dir)
return tool_path, relative_install_dir
elif elem.tag == 'section':
for section_elem in elem:
if section_elem.tag == 'tool':
if section_elem.get('guid') == tool_dict['guid']:
tool_path = shed_tool_conf_dict['tool_path']
relative_install_dir = os.path.join(tool_path, partial_install_dir)
return tool_path, relative_install_dir
return None, None
```
--------------------------------
### Dockerfile Configuration for HELLO-IE Container
Source: https://docs.galaxyproject.org/en/release_19.05/dev/interactive_environments
This Dockerfile sets up a container to serve directory listings via Nginx. It exposes port 80 and runs a startup script. The `CMD` instruction specifies the entry point for the container.
```dockerfile
# EXTREMELY IMPORTANT! You must expose a SINGLE port on your container.
EXPOSE 80
CMD /startup.sh
```
--------------------------------
### Get List of All Watchers
Source: https://docs.galaxyproject.org/en/release_21.05/_modules/galaxy/config_watchers
Returns a tuple containing all configured watcher objects. This can be used to iterate over and manage the watchers, for example, to start or stop them.
```python
@property
def watchers(self):
return (self.tool_watcher,
self.tool_config_watcher,
self.data_manager_config_watcher,
self.tool_data_watcher,
self.tool_watcher,
self.job_rule_watcher,
self.core_config_watcher,
self.tour_watcher)
```
--------------------------------
### Configure Galaxy for Data Library Example
Source: https://docs.galaxyproject.org/en/release_20.01/api/quickstart
This snippet shows configuration options for the `galaxy.yml` file to enable a Data Library example. It requires setting `admin_users` and `library_import_dir`. After changes, Galaxy needs to be restarted.
```yaml
admin_users: you@example.org
library_import_dir: /path/to/some/directory
```
--------------------------------
### Get Tool GUID from Repository URL and Path (Python)
Source: https://docs.galaxyproject.org/en/release_20.05/_modules/galaxy/tool_shed/galaxy_install/tool_migration_manager
Constructs a tool's Global Unique Identifier (GUID) based on its repository clone URL and installation directory. It optionally prefixes the relative installation directory with the 'tool_path' from the shed configuration dictionary and strips the path from the tool configuration filename. Dependencies include 'os' and 'strip_path'.
```python
def get_guid(self, repository_clone_url, relative_install_dir, tool_config):
if self.shed_config_dict.get('tool_path'):
relative_install_dir = os.path.join(self.shed_config_dict['tool_path'], relative_install_dir)
tool_config_filename = strip_path(tool_config)
```
--------------------------------
### Create Galaxy Library using Python
Source: https://docs.galaxyproject.org/en/release_19.01/_sources/api/quickstart
This script creates a new library within Galaxy. It requires an API key, Galaxy server URL, library name, and a display name. The response includes the ID and URL of the newly created library.
```python
import requests
def create_library(api_key, galaxy_url, name, description):
headers = {"Content-Type": "application/json", "Accept": "application/json"}
url = f"{galaxy_url}/api/libraries"
payload = {
"name": name,
"description": description
}
response = requests.post(url, headers=headers, params={'key': api_key}, json=payload)
response.raise_for_status()
return response.json()
if __name__ == "__main__":
# Example usage:
# Replace 'my_key' with your actual API key
# Replace 'http://localhost:8080' with your Galaxy server URL
api_key = "my_key"
galaxy_url = "http://localhost:8080"
library_name = "api_test"
library_description = "API Test Library"
try:
result = create_library(api_key, galaxy_url, library_name, library_description)
print("Response")
print("--------")
print(f"{result['url']}")
print(f" name: {result['name']}")
print(f" id: {result['id']}")
except requests.exceptions.RequestException as e:
print(f"Error creating library: {e}")
```
--------------------------------
### Display Galaxy Libraries using display.py
Source: https://docs.galaxyproject.org/en/release_18.09/_sources/api/quickstart
This script lists all available libraries within Galaxy. It requires an API key and the Galaxy server URL. The output provides the API path and name for each library found.
```bash
% ./display.py my_key http://localhost:8080/api/libraries
Collection Members
------------------
0 elements in collection
```
```bash
% ./display.py my_key http://localhost:8080/api/libraries
Collection Members
------------------
/api/libraries/f3f73e481f432006
name: api_test
id: f3f73e481f432006
```
--------------------------------
### Get Tool Installation Directory from Configuration
Source: https://docs.galaxyproject.org/en/release_18.01/_modules/tool_shed/util/tool_util
This function extracts the tool path and relative installation directory for a specific tool based on its GUID from the Galaxy tool configuration. It iterates through the configuration elements, checking for 'tool' and 'section' tags.
```python
import os
def get_tool_path_install_dir(partial_install_dir, shed_tool_conf_dict, tool_dict, config_elems):
for elem in config_elems:
if elem.tag == 'tool':
if elem.get('guid') == tool_dict['guid']:
tool_path = shed_tool_conf_dict['tool_path']
relative_install_dir = os.path.join(tool_path, partial_install_dir)
return tool_path, relative_install_dir
elif elem.tag == 'section':
for section_elem in elem:
if section_elem.tag == 'tool':
if section_elem.get('guid') == tool_dict['guid']:
tool_path = shed_tool_conf_dict['tool_path']
relative_install_dir = os.path.join(tool_path, partial_install_dir)
return tool_path, relative_install_dir
return None, None
```
--------------------------------
### Get GUID (Python)
Source: https://docs.galaxyproject.org/en/release_19.09/_modules/tool_shed/galaxy_install/tool_migration_manager
This Python snippet aims to get a GUID (Globally Unique Identifier) based on repository clone URL, relative installation directory, and tool configuration. It modifies the `relative_install_dir` if a `tool_path` is defined in `shed_config_dict` and then walks the directory to find the tool configuration file. Dependencies include `os` and `basic_util` modules. It handles `.hg` directories by excluding them from the walk.
```python
def get_guid(self, repository_clone_url, relative_install_dir, tool_config):
if self.shed_config_dict.get('tool_path'):
relative_install_dir = os.path.join(self.shed_config_dict['tool_path'], relative_install_dir)
tool_config_filename = basic_util.strip_path(tool_config)
for root, dirs, files in os.walk(relative_install_dir):
if root.find('.hg') < 0 and root.find('hgrc') < 0:
if '.hg' in dirs:
dirs.remove('.hg')
```
--------------------------------
### Constructing Installation Script Command Message in Python
Source: https://docs.galaxyproject.org/en/release_19.05/_modules/tool_shed/galaxy_install/migrate/check
This Python code snippet constructs messages that guide the user on how to execute installation scripts, including options for installing tool dependencies. It dynamically includes the latest tool migration script number and provides clear examples of commands to run. This helps users understand the available options for their installation process.
```python
msg += "%s" % output.replace('done', '')
msg += "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n"
msg += "sh ./scripts/migrate_tools/%04d_tools.sh\n" % latest_tool_migration_script_number
msg += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n"
if have_tool_dependencies:
msg += "The tool dependencies listed above will be installed along with the repositories if you add the 'install_dependencies'\n"
msg += "option to the above command like this:\n\n"
msg += "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n"
msg += "sh ./scripts/migrate_tools/%04d_tools.sh install_dependencies\n" % latest_tool_migration_script_number
msg += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n"
msg += "Tool dependencies can be installed after the repositories have been installed as well.\n\n"
```
--------------------------------
### Get Filesource URI Root (Python)
Source: https://docs.galaxyproject.org/en/latest/lib/galaxy.files
Returns the root URI for a browsable filesource, which serves as the starting point for navigation. For example, 'gxfiles://bucket1/' for an S3 bucket.
```python
def get_uri_root() -> str:
"""
Return a prefix for the root (e.g. gxfiles://prefix/).
"""
pass
```
--------------------------------
### Python: Execute Virtual Environment Setup and Package Installation
Source: https://docs.galaxyproject.org/en/release_20.05/_modules/galaxy/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler
This Python code snippet demonstrates the execution of commands to set up a virtual environment and install Python packages. It first ensures virtualenv is installed, then determines the requirements file path. It constructs and executes a command that includes creating the virtual environment, activating it, and installing packages using pip, logging any errors.
```python
venv_src_directory = os.path.abspath(os.path.join(self.app.tool_dependency_dir, '__virtualenv_src'))
if not self.install_virtualenv(install_environment, venv_src_directory):
log.debug('Unable to install virtualenv')
return tool_dependency, None, None
requirements = action_dict['requirements']
if os.path.exists(os.path.join(install_environment.install_dir, requirements)):
requirements_path = requirements
else:
requirements_path = os.path.join(install_environment.install_dir, "requirements.txt")
with open(requirements_path, "w") as f:
f.write(requirements)
venv_directory = os.path.join(install_environment.install_dir, "venv")
python_cmd = action_dict['python']
setup_command = "%s %s/virtualenv.py --no-site-packages '%s'" % (python_cmd, venv_src_directory, venv_directory)
activate_command = "POSIXLY_CORRECT=1; . %s" % os.path.join(venv_directory, "bin", "activate")
if action_dict['use_requirements_file']:
install_command = "python '%s' install -r '%s' --log '%s'" % \
(os.path.join(venv_directory, "bin", "pip"),
requirements_path,
os.path.join(install_environment.install_dir, 'pip_install.log'))
else:
install_command = ''
with open(requirements_path, "rb") as f:
while True:
line = f.readline()
if not line:
break
line = line.strip()
if line:
line_install_command = "python '%s' install %s --log '%s'" % \
(os.path.join(venv_directory, "bin", "pip"),
line,
os.path.join(install_environment.install_dir, 'pip_install_%s.log' % (line)))
if not install_command:
install_command = line_install_command
else:
install_command = "%s && %s" % (install_command, line_install_command)
full_setup_command = "%s; %s; %s" % (setup_command, activate_command, install_command)
return_code = install_environment.handle_command(tool_dependency=tool_dependency,
cmd=full_setup_command,
return_output=False,
job_name=package_name)
if return_code:
log.error("Failed to do setup_virtualenv install, exit code='%s'", return_code)
return tool_dependency, None, None
site_packages_directory, site_packages_directory_list = \
self.__get_site_packages_directory(install_environment,
self.app,
tool_dependency,
python_cmd,
venv_directory)
```
--------------------------------
### Enable and Start Galaxy Service with Systemd
Source: https://docs.galaxyproject.org/en/release_25.0/admin/scaling
Commands to enable the Galaxy systemd service to start on boot and to start the service immediately. This assumes the `galaxy.service` file is correctly placed in the systemd configuration directory.
```bash
# systemctl enable galaxy
# systemctl start galaxy
```
--------------------------------
### Galaxy Tool XML Configuration Example 2
Source: https://docs.galaxyproject.org/en/latest/admin/tool_panel
A more complex example of a Galaxy tool configuration XML file, illustrating tool installation from a ToolShed. It includes attributes like 'tool_path', 'guid', and nested elements detailing the tool's shed, repository, owner, and revision.
```xml
```
--------------------------------
### Create Galaxy Library using Python
Source: https://docs.galaxyproject.org/en/release_19.09/_sources/api/quickstart
This script creates a new library in Galaxy. It requires an API key, the Galaxy server URL, and a name and description for the new library. The response includes the API path to the newly created library.
```python
import requests
import sys
def create_library(api_key, url, name, description):
headers = {"content-type": "application/json"}
payload = {
"name": name,
"description": description
}
r = requests.post(url, headers=headers, params={'key': api_key}, json=payload)
return r.json()
if __name__ == '__main__':
if len(sys.argv) != 5:
print("Usage: ./library_create_library.py ")
sys.exit(1)
api_key = sys.argv[1]
url = sys.argv[2]
name = sys.argv[3]
description = sys.argv[4]
library = create_library(api_key, url, name, description)
print("Response")
print("--------")
print(f"{library['url']}")
print(f" name: {library['name']}")
print(f" id: {library['id']}")
```
--------------------------------
### Setup Virtual Environment - Python
Source: https://docs.galaxyproject.org/en/release_18.01/lib/tool_shed.galaxy_install.tool_dependencies
Initializes a virtual environment for package installations. It filters recipe steps and defines the installation directory when `initial_download` is true. If not in the initial download stage, it returns `None` values for these.
```python
class tool_shed.galaxy_install.tool_dependencies.recipe.step_handler.SetupVirtualEnv(_app_):
"""Initialize a virtual environment for installing packages. If initial_download is True, the recipe steps will be filtered and returned and the installation directory (i.e., dir) will be defined and returned. If we’re not in the initial download stage, these actions will not occur, and None values will be returned for them."""
def execute_step(_tool_dependency_, _package_name_, _actions_, _action_dict_, _filtered_actions_, _env_file_builder_, _install_environment_, _work_dir_, _current_dir=None, _initial_download=False):
pass
def install_virtualenv(_install_environment_, _venv_dir_):
pass
def prepare_step(_tool_dependency_, _action_elem_, _action_dict_, _install_environment_, _is_binary_download_):
pass
```
--------------------------------
### Install and Start Slurm Services
Source: https://docs.galaxyproject.org/en/release_23.2/dev/debugging_galaxy_slurm
This sequence of commands installs the Slurm Workload Manager, starts its core services (slurmd and slurmctld), and installs a utility (mailutils) to prevent Slurm from encountering errors related to missing mail commands. Munge, a message authentication service, is also installed and started, which is often a prerequisite for Slurm authentication.
```bash
sudo apt install -y slurm-wlm slurm-wlm-doc
sudo apt install -y mailutils
sudo apt install munge
sudo service munge start
sudo service slurmd start
sudo service slurmctld start
```
--------------------------------
### Example Conda Resolver Configuration
Source: https://docs.galaxyproject.org/en/release_22.01/admin/dependency_resolvers
This example demonstrates how to configure multiple Conda resolvers. It shows setting administrator-maintained read-only installation first, followed by a Galaxy-maintained writable installation with automatic dependency installation.
```yaml
- type: conda
auto_init: false
auto_install: false
prefix: /hpc/conda
- type: conda
auto_init: true
auto_install: true
prefix: /galaxy/conda
```
--------------------------------
### Python: Setup Virtual Environment Installation
Source: https://docs.galaxyproject.org/en/release_20.09/_modules/galaxy/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler
This Python code defines the `SetupVirtualEnv` class, responsible for creating and managing Python virtual environments. It handles installing packages into the virtual environment, including processing requirements from files or direct input. It also manages the activation of the virtual environment and logs installation progress.
```python
import os
import logging
log = logging.getLogger(__name')
class SetupVirtualEnv(Download, RecipeStep):
def __init__(self, app):
self.app = app
self.type = 'setup_virtualenv'
def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder,
install_environment, work_dir, current_dir=None, initial_download=False):
"""
Initialize a virtual environment for installing packages. If initial_download is True, the recipe
steps will be filtered and returned and the installation directory (i.e., dir) will be defined and
returned. If we're not in the initial download stage, these actions will not occur, and None values
will be returned for them.
"""
# This class is not currently used during stage 1 of the installation process, so filter_actions
# are not affected, and dir is not set. Enhancements can easily be made to this function if this
# class is needed in stage 1.
venv_src_directory = os.path.abspath(os.path.join(self.app.tool_dependency_dir, '__virtualenv_src'))
if not self.install_virtualenv(install_environment, venv_src_directory):
log.debug('Unable to install virtualenv')
return tool_dependency, None, None
requirements = action_dict['requirements']
if os.path.exists(os.path.join(install_environment.install_dir, requirements)):
# requirements specified as path to a file
requirements_path = requirements
else:
# requirements specified directly in XML, create a file with these for pip.
requirements_path = os.path.join(install_environment.install_dir, "requirements.txt")
with open(requirements_path, "w") as f:
f.write(requirements)
venv_directory = os.path.join(install_environment.install_dir, "venv")
python_cmd = action_dict['python']
# TODO: Consider making --no-site-packages optional.
setup_command = "{} {}/virtualenv.py --no-site-packages '{}'".format(python_cmd, venv_src_directory, venv_directory)
# POSIXLY_CORRECT forces shell commands . and source to have the same
# and well defined behavior in bash/zsh.
activate_command = "POSIXLY_CORRECT=1; . %s" % os.path.join(venv_directory, "bin", "activate")
if action_dict['use_requirements_file']:
install_command = "python '%s' install -r '%s' --log '%s'" % \
(os.path.join(venv_directory, "bin", "pip"),
requirements_path,
os.path.join(install_environment.install_dir, 'pip_install.log'))
else:
install_command = ''
with open(requirements_path, "rb") as f:
while True:
line = f.readline()
if not line:
break
line = line.strip()
if line:
line_install_command = "python '%s' install %s --log '%s'" % \
(os.path.join(venv_directory, "bin", "pip"),
line,
os.path.join(install_environment.install_dir, 'pip_install_%s.log' % (line)))
if not install_command:
install_command = line_install_command
else:
install_command = "{} && {}".format(install_command, line_install_command)
full_setup_command = "{}; {}; {}".format(setup_command, activate_command, install_command)
return_code = install_environment.handle_command(tool_dependency=tool_dependency,
cmd=full_setup_command,
return_output=False,
job_name=package_name)
if return_code:
log.error("Failed to do setup_virtualenv install, exit code='%s'", return_code)
# would it be better to try to set env variables anway, instead of returning here?
return tool_dependency, None, None
site_packages_directory, site_packages_directory_list = \
self.__get_site_packages_directory(install_environment,
self.app,
tool_dependency,
python_cmd,
venv_directory)
```
--------------------------------
### Enable and Start Galaxy Service with Systemd
Source: https://docs.galaxyproject.org/en/release_24.2/admin/scaling
These are standard systemd commands used to enable and start a service. Enabling a service ensures it starts automatically on system boot, while starting it initiates the service immediately. The example shown is for the `galaxy.service` unit.
```bash
# systemctl enable galaxy
# systemctl start galaxy
```
--------------------------------
### Get Latest Installable Revision API
Source: https://docs.galaxyproject.org/en/release_19.01/_modules/galaxy/webapps/galaxy/api/tool_shed_repositories
Get the latest installable revision of a specified repository from a specified Tool Shed.
```APIDOC
## POST /api/tool_shed_repositories/get_latest_installable_revision
### Description
Get the latest installable revision of a specified repository from a specified Tool Shed.
### Method
POST
### Endpoint
/api/tool_shed_repositories/get_latest_installable_revision
### Parameters
#### Request Body
- **tool_shed_url** (string) - Required - The base URL of the Tool Shed from which to retrieve the Repository revision.
- **name** (string) - Required - The name of the Repository.
- **owner** (string) - Required - The owner of the Repository.
### Request Example
```json
{
"tool_shed_url": "https://toolshed.g2.bx.psu.edu",
"name": "fastqc",
"owner": "test"
}
```
### Response
#### Success Response (200)
- **status** (string) - The status of the request.
- **message** (string) - A message detailing the latest installable revision or any errors.
#### Response Example
```json
{
"status": "success",
"message": "1.0.3"
}
```
```
--------------------------------
### Setup Virtual Environment for Package Installation
Source: https://docs.galaxyproject.org/en/release_19.09/_modules/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler
Initializes a Python virtual environment and installs packages using pip. It handles requirements specified either as a file path or directly in the configuration. The method supports filtering actions during initial download stages and returns relevant information for environment setup.
```python
class SetupVirtualEnv(Download, RecipeStep):
def __init__(self, app):
self.app = app
self.type = 'setup_virtualenv'
def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder,
install_environment, work_dir, current_dir=None, initial_download=False):
"""
Initialize a virtual environment for installing packages. If initial_download is True, the recipe
steps will be filtered and returned and the installation directory (i.e., dir) will be defined and
returned. If we're not in the initial download stage, these actions will not occur, and None values
will be returned for them.
"""
# This class is not currently used during stage 1 of the installation process, so filter_actions
# are not affected, and dir is not set. Enhancements can easily be made to this function if this
# class is needed in stage 1.
venv_src_directory = os.path.abspath(os.path.join(self.app.tool_dependency_dir, '__virtualenv_src'))
if not self.install_virtualenv(install_environment, venv_src_directory):
log.debug('Unable to install virtualenv')
return tool_dependency, None, None
requirements = action_dict['requirements']
if os.path.exists(os.path.join(install_environment.install_dir, requirements)):
# requirements specified as path to a file
requirements_path = requirements
else:
# requirements specified directly in XML, create a file with these for pip.
requirements_path = os.path.join(install_environment.install_dir, "requirements.txt")
with open(requirements_path, "w") as f:
f.write(requirements)
venv_directory = os.path.join(install_environment.install_dir, "venv")
python_cmd = action_dict['python']
# TODO: Consider making --no-site-packages optional.
setup_command = "%s %s/virtualenv.py --no-site-packages \'%s\'" % (python_cmd, venv_src_directory, venv_directory)
# POSIXLY_CORRECT forces shell commands . and source to have the same
# and well defined behavior in bash/zsh.
activate_command = "POSIXLY_CORRECT=1; . %s" % os.path.join(venv_directory, "bin", "activate")
if action_dict['use_requirements_file']:
install_command = "python \'%s\' install -r \'%s\' --log \'%s\'" % \
(os.path.join(venv_directory, "bin", "pip"),
requirements_path,
os.path.join(install_environment.install_dir, 'pip_install.log'))
else:
install_command = ''
with open(requirements_path, "rb") as f:
while True:
line = f.readline()
if not line:
break
line = line.strip()
if line:
line_install_command = "python \'%s\' install %s --log \'%s\'" % \
(os.path.join(venv_directory, "bin", "pip"),
line,
os.path.join(install_environment.install_dir, 'pip_install_%s.log' % (line)))
if not install_command:
install_command = line_install_command
else:
install_command = "%s && %s" % (install_command, line_install_command)
full_setup_command = "%s; %s; %s" % (setup_command, activate_command, install_command)
return_code = install_environment.handle_command(tool_dependency=tool_dependency,
cmd=full_setup_command,
return_output=False,
job_name=package_name)
if return_code:
log.error("Failed to do setup_virtualenv install, exit code='%s'", return_code)
# would it be better to try to set env variables anway, instead of returning here?
return tool_dependency, None, None
site_packages_directory, site_packages_directory_list =
self.__get_site_packages_directory(install_environment,
self.app,
tool_dependency,
python_cmd,
venv_directory)
env_file_builder.append_line(name="PATH", action="prepend_to", value=os.path.join(venv_directory, "bin"))
if site_packages_directory is None:
log.error("virtualenv's site-packages directory '%s' does not exist", site_packages_directory_list)
else:
```
--------------------------------
### Dockerfile for Helloworld Container
Source: https://docs.galaxyproject.org/en/release_19.01/dev/interactive_environments
This Dockerfile sets up a basic container environment using Alpine Linux. It installs necessary packages like wget, Nginx, and Python, copies custom startup and monitoring scripts, configures Nginx, and sets up a volume for data import. Environment variables are defined to facilitate connectivity with Galaxy.
```dockerfile
FROM alpine
# These environment variables are passed from Galaxy to the container
# and help you enable connectivity to Galaxy from within the container.
# This means your user can import/export data from/to Galaxy.
ENV DEBIAN_FRONTEND=noninteractive \
API_KEY=none \
DEBUG=false \
PROXY_PREFIX=none \
GALAXY_URL=none \
GALAXY_WEB_PORT=10000 \
HISTORY_ID=none \
REMOTE_HOST=none \
DOCKER_PORT=none \
CORS_ORIGIN-none
RUN apk update && \
apk add \
wget procps nginx python py2-pip net-tools nginx git patch
# Our very important scripts. Make sure you've run `chmod +x startup.sh
# monitor_traffic.sh` outside of the container!
ADD ./startup.sh /startup.sh
ADD ./monitor_traffic.sh /monitor_traffic.sh
# /import will be the universal mount-point
# The Galaxy instance can copy in data that needs to be present to the
# container
RUN mkdir -p /import /web/helloworld /run/nginx
# Nginx configuration
COPY ./proxy.conf /proxy.conf
COPY ./index.html /web/helloworld/
RUN chmod ugo+r /web/helloworld/index.html
VOLUME ["/import"]
WORKDIR /import/
```
--------------------------------
### Minimal Galaxy Object Store Template (YAML)
Source: https://docs.galaxyproject.org/en/latest/_sources/admin/data
A basic example of a Galaxy object store template in YAML format. This template defines a simple object store configuration that can be used to get started.
```yaml
object_store_templates:
- name: "My Simple Object Store"
type: "disk"
description: "A simple disk-based object store."
config:
path: "/path/to/my/object_store/${user.username}/${project_name}"
```