galaxy.tools package

Classes encapsulating galaxy tools and tool configuration.

class galaxy.tools.ToolErrorLog[source]
__init__()[source]
add_error(file, phase, exception)[source]
exception galaxy.tools.ToolInputsNotReadyException[source]

Bases: exceptions.Exception

exception galaxy.tools.ToolNotFoundException[source]

Bases: exceptions.Exception

class galaxy.tools.ToolBox(config_filenames, tool_root_dir, app)[source]

Bases: galaxy.tools.toolbox.base.BaseGalaxyToolBox

A derivative of AbstractToolBox with knowledge about Tool internals - how to construct them, action types, dependency management, etc....

__init__(config_filenames, tool_root_dir, app)[source]
handle_panel_update(section_dict)[source]

Sends a panel update to all threads/processes.

has_reloaded(other_toolbox)[source]
all_requirements
tools_by_id
create_tool(config_file, repository_id=None, guid=None, **kwds)[source]
get_tool_components(tool_id, tool_version=None, get_loaded_tools_by_lineage=False, set_selected=False)[source]

Retrieve all loaded versions of a tool from the toolbox and return a select list enabling selection of a different version, the list of the tool’s loaded versions, and the specified tool.

class galaxy.tools.DefaultToolState[source]

Bases: object

Keeps track of the state of a users interaction with a tool between requests.

__init__()[source]
initialize(trans, tool)[source]

Create a new DefaultToolState for this tool. It will be initialized with default values for inputs. Grouping elements are filled in recursively.

encode(tool, app, nested=False)[source]

Convert the data to a string

decode(values, tool, app)[source]

Restore the state from a string

copy()[source]

Shallow copy of the state

class galaxy.tools.Tool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: object, galaxy.util.dictifiable.Dictifiable

Represents a computational tool that can be executed through Galaxy.

tool_type = 'default'
requires_setting_metadata = True
default_tool_action

alias of DefaultToolAction

dict_collection_visible_keys = ('id', 'name', 'version', 'description', 'labels')
__init__(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Load a tool from the config named by config_file

version_object
sa_session

Returns a SQLAlchemy session

tool_version

Return a ToolVersion if one exists for our id

tool_versions
tool_shed_repository
produces_collections_of_unknown_type
produces_collections_with_unknown_structure
valid_input_states
requires_galaxy_python_environment

Indicates this tool’s runtime requires Galaxy’s Python environment.

get_job_handler(job_params=None)[source]

Get a suitable job handler for this Tool given the provided job_params. If multiple handlers are valid for combination of Tool and job_params (e.g. the defined handler is a handler tag), one will be selected at random.

Parameters:job_params (dict or None) – Any params specific to this job (e.g. the job source)
Returns:str – The id of a job handler for a job run of this Tool
get_job_destination(job_params=None)[source]
Returns:galaxy.jobs.JobDestination – The destination definition and runner parameters.
get_panel_section()[source]
allow_user_access(user, attempting_access=True)[source]
Returns:bool – Whether the user is allowed to access the tool.
parse(tool_source, guid=None)[source]

Read tool configuration from the element root and fill in self.

tests
parse_command(tool_source)[source]
parse_environment_variables(tool_source)[source]
parse_inputs(tool_source)[source]

Parse the “<inputs>” element and create appropriate `ToolParameter`s. This implementation supports multiple pages and grouping constructs.

parse_help(tool_source)[source]

Parse the help text for the tool. Formatted in reStructuredText, but stored as Mako to allow for dynamic image paths. This implementation supports multiple pages.

parse_outputs(tool_source)[source]

Parse <outputs> elements and fill in self.outputs (keyed by name)

parse_stdio(tool_source)[source]

Parse <stdio> element(s) and fill in self.return_codes, self.stderr_rules, and self.stdout_rules. Return codes have a range and an error type (fault or warning). Stderr and stdout rules have a regular expression and an error level (fault or warning).

parse_input_elem(page_source, enctypes, context=None)[source]

Parse a parent element whose children are inputs – these could be groups (repeat, conditional) or param elements. Groups will be parsed recursively.

parse_param_elem(input_source, enctypes, context)[source]

Parse a single “<param>” element and return a ToolParameter instance. Also, if the parameter has a ‘required_enctype’ add it to the set enctypes.

populate_resource_parameters(tool_source)[source]
populate_tool_shed_info()[source]
help
help_by_page
find_output_def(name)[source]
check_workflow_compatible(tool_source)[source]

Determine if a tool can be used in workflows. External tools and the upload tool are currently not supported by workflows.

new_state(trans)[source]

Create a new DefaultToolState for this tool. It will be initialized with default values for inputs. Grouping elements are filled in recursively.

get_param(key)[source]

Returns the parameter named key or None if there is no such parameter.

get_hook(name)[source]

Returns an object from the code file referenced by code_namespace (this will normally be a callable object)

visit_inputs(values, callback)[source]

Call the function callback on each parameter of this tool. Visits grouping parameters recursively and constructs unique prefixes for each nested set of The callback method is then called as:

callback( level_prefix, parameter, parameter_value )

handle_input(trans, incoming, history=None)[source]

Process incoming parameters for this tool from the dict incoming, update the tool state (or create if none existed), and either return to the form or execute the tool (only if ‘execute’ was clicked and there were no errors).

handle_single_execution(trans, rerun_remap_job_id, params, history, mapping_over_collection, execution_cache=None)[source]

Return a pair with whether execution is successful as well as either resulting output data or an error message indicating the problem.

find_fieldstorage(x)[source]
params_with_missing_data_table_entry

Return all parameters that are dynamically generated select lists whose options require an entry not currently in the tool_data_table_conf.xml file.

params_with_missing_index_file

Return all parameters that are dynamically generated select lists whose options refer to a missing .loc file.

get_static_param_values(trans)[source]

Returns a map of parameter names and values if the tool does not require any user input. Will raise an exception if any parameter does require input.

execute(trans, incoming={}, set_output_hid=True, history=None, **kwargs)[source]

Execute the tool using parameter values in incoming. This just dispatches to the ToolAction instance specified by self.tool_action. In general this will create a Job that when run will build the tool’s outputs, e.g. DefaultToolAction.

params_to_strings(params, app)[source]
params_from_strings(params, app, ignore_errors=False)[source]
check_and_update_param_values(values, trans, update_values=True, workflow_building_mode=False)[source]

Check that all parameters have values, and fill in with default values where necessary. This could be called after loading values from a database in case new parameters have been added.

build_dependency_cache(**kwds)[source]
build_dependency_shell_commands(job_directory=None, metadata=False)[source]

Return a list of commands to be run to populate the current environment to include this tools requirements.

installed_tool_dependencies
tool_requirements

Return all requiremens of type package

tool_requirements_status

Return a list of dictionaries for all tool dependencies with their associated status

build_redirect_url_params(param_dict)[source]

Substitute parameter values into self.redirect_url_params

parse_redirect_url(data, param_dict)[source]

Parse the REDIRECT_URL tool param. Tools that send data to an external application via a redirect must include the following 3 tool params:

  1. REDIRECT_URL - the url to which the data is being sent
  2. DATA_URL - the url to which the receiving application will send an http post to retrieve the Galaxy data
  3. GALAXY_URL - the url to which the external application may post data as a response
call_hook(hook_name, *args, **kwargs)[source]

Call the custom code hook function identified by ‘hook_name’ if any, and return the results

exec_before_job(app, inp_data, out_data, param_dict={})[source]
exec_after_process(app, inp_data, out_data, param_dict, job=None)[source]
job_failed(job_wrapper, message, exception=False)[source]

Called when a job has failed

collect_child_datasets(output, job_working_directory)[source]

Look for child dataset files, create HDA and attach to parent.

collect_primary_datasets(output, job_working_directory, input_ext, input_dbkey='?')[source]

Find any additional datasets generated by a tool and attach (for cases where number of outputs is not known in advance).

collect_dynamic_collections(output, **kwds)[source]

Find files corresponding to dynamically structured collections.

to_archive()[source]
to_dict(trans, link_details=False, io_details=False)[source]

Returns dict of tool.

to_json(trans, kwd={}, job=None, workflow_building_mode=False)[source]

Recursively creates a tool dictionary containing repeats, dynamic options and updated states.

get_default_history_by_trans(trans, create=False)[source]
classmethod get_externally_referenced_paths(path)[source]

Return relative paths to externally referenced files by the tool described by file at path. External components should not assume things about the structure of tool xml files (this is the tool’s responsibility).

class galaxy.tools.OutputParameterJSONTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.Tool

Alternate implementation of Tool that provides parameters and other values JSONified within the contents of an output dataset

tool_type = 'output_parameter_json'
exec_before_job(app, inp_data, out_data, param_dict=None)[source]
class galaxy.tools.DataSourceTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.OutputParameterJSONTool

Alternate implementation of Tool for data_source tools – those that allow the user to query and extract data from another web site.

tool_type = 'data_source'
default_tool_action

alias of DataSourceToolAction

parse_inputs(tool_source)[source]
exec_before_job(app, inp_data, out_data, param_dict=None)[source]
class galaxy.tools.AsyncDataSourceTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DataSourceTool

tool_type = 'data_source_async'
class galaxy.tools.DataDestinationTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.Tool

tool_type = 'data_destination'
class galaxy.tools.SetMetadataTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.Tool

Tool implementation for special tool that sets metadata on an existing dataset.

tool_type = 'set_metadata'
requires_setting_metadata = False
exec_after_process(app, inp_data, out_data, param_dict, job=None)[source]
job_failed(job_wrapper, message, exception=False)[source]
class galaxy.tools.ExportHistoryTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.Tool

tool_type = 'export_history'
class galaxy.tools.ImportHistoryTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.Tool

tool_type = 'import_history'
class galaxy.tools.DataManagerTool(config_file, root, app, guid=None, data_manager_id=None, **kwds)[source]

Bases: galaxy.tools.OutputParameterJSONTool

tool_type = 'manage_data'
default_tool_action

alias of DataManagerToolAction

__init__(config_file, root, app, guid=None, data_manager_id=None, **kwds)[source]
exec_after_process(app, inp_data, out_data, param_dict, job=None, **kwds)[source]
get_default_history_by_trans(trans, create=False)[source]
allow_user_access(user, attempting_access=True)[source]
Parameters:
  • user (galaxy.model.User) – model object representing user.
  • attempting_access (bool) – is the user attempting to do something with the the tool (set false for incidental checks like toolbox listing)
Returns:

bool – Whether the user is allowed to access the tool.

Data Manager tools are only accessible to admins.

class galaxy.tools.DatabaseOperationTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.Tool

default_tool_action

alias of ModelOperationToolAction

require_dataset_ok = True
valid_input_states
allow_errored_inputs
check_inputs_ready(input_datasets, input_dataset_collections)[source]
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.UnzipCollectionTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DatabaseOperationTool

tool_type = 'unzip_collection'
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.ZipCollectionTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DatabaseOperationTool

tool_type = 'zip_collection'
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.MergeCollectionTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DatabaseOperationTool

tool_type = 'merge_collection'
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.FilterFailedDatasetsTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DatabaseOperationTool

tool_type = 'filter_failed_datasets_collection'
require_dataset_ok = False
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.FlattenTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DatabaseOperationTool

tool_type = 'flatten_collection'
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.RelabelFromFileTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DatabaseOperationTool

tool_type = 'relabel_from_file'
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.FilterFromFileTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.DatabaseOperationTool

tool_type = 'filter_from_file'
produce_outputs(trans, out_data, output_collections, incoming, history)[source]
class galaxy.tools.TracksterConfig(actions)[source]

Trackster configuration encapsulation.

__init__(actions)[source]
static parse(root)[source]
class galaxy.tools.SetParamAction(name, output_name)[source]

Set parameter action.

__init__(name, output_name)[source]
static parse(elt)[source]

Parse action from element.

class galaxy.tools.BadValue(value)[source]

Bases: object

__init__(value)[source]
exception galaxy.tools.InterruptedUpload[source]

Bases: exceptions.Exception

galaxy.tools.tool_class

alias of DataDestinationTool

Subpackages

Submodules

galaxy.tools.errors module

Functionality for dealing with tool errors.

class galaxy.tools.errors.ErrorReporter(hda, app)[source]

Bases: object

__init__(hda, app)[source]
create_report(user, email='', message='', **kwd)[source]
send_report(user, email=None, message=None, **kwd)[source]
class galaxy.tools.errors.EmailErrorReporter(hda, app)[source]

Bases: galaxy.tools.errors.ErrorReporter

galaxy.tools.evaluation module

class galaxy.tools.evaluation.ToolEvaluator(app, tool, job, local_working_directory)[source]

Bases: object

An abstraction linking together a tool and a job runtime to evaluate tool inputs in an isolated, testable manner.

__init__(app, tool, job, local_working_directory)[source]
set_compute_environment(compute_environment, get_special=None)[source]

Setup the compute environment and established the outline of the param_dict for evaluating command and config cheetah templates.

build_param_dict(incoming, input_datasets, output_datasets, output_collections, output_paths, job_working_directory, input_paths=[])[source]

Build the dictionary of parameters for substituting into the command line. Each value is wrapped in a InputValueWrapper, which allows all the attributes of the value to be used in the template, but when the __str__ method is called it actually calls the to_param_dict_string method of the associated input.

build()[source]

Build runtime description of job to execute, evaluate command and config templates corresponding to this tool with these inputs on this compute environment.

galaxy.tools.exception_handling module

class galaxy.tools.exception_handling.UCSCOutWrapper(other)[source]

Bases: object

File-like object that throws an exception if it encounters the UCSC limit error lines

__init__(other)[source]
next()[source]
readline()[source]
exception galaxy.tools.exception_handling.UCSCLimitException[source]

Bases: exceptions.Exception

galaxy.tools.execute module

Once state information has been calculated, handle actually executing tools from various states, tracking results, and building implicit dataset collections from matched collections.

galaxy.tools.execute.execute(trans, tool, param_combinations, history, rerun_remap_job_id=None, collection_info=None, workflow_invocation_uuid=None)[source]

Execute a tool and return object containing summary (output data, number of failures, etc...).

galaxy.tools.lint module

This modules contains the functions that drive the tool linting framework.

galaxy.tools.lint.lint_tool_source(tool_source, level='all', fail_level='warn', extra_modules=[], skip_types=[])[source]
galaxy.tools.lint.lint_xml(tool_xml, level='all', fail_level='warn', extra_modules=[], skip_types=[])[source]
galaxy.tools.lint.lint_tool_source_with(lint_context, tool_source, extra_modules=[])[source]
galaxy.tools.lint.lint_xml_with(lint_context, tool_xml, extra_modules=[])[source]
class galaxy.tools.lint.LintContext(level, skip_types=[])[source]

Bases: object

__init__(level, skip_types=[])[source]
lint(name, lint_func, lint_target)[source]
valid(message, *args)[source]
info(message, *args)[source]
error(message, *args)[source]
warn(message, *args)[source]
failed(fail_level)[source]

galaxy.tools.loader module

galaxy.tools.loader.load_tool(path)

Loads tool from file system and preprocesses tool macros.

galaxy.tools.loader.raw_tool_xml_tree(path)[source]

Load raw (no macro expansion) tree representation of tool represented at the specified path.

galaxy.tools.loader.imported_macro_paths(root)[source]
galaxy.tools.loader.template_macro_params(root)[source]

Look for template macros and populate param_dict (for cheetah) with these.

galaxy.tools.loader_directory module

Utilities for loading and reasoning about unparsed tools in directories.

galaxy.tools.loader_directory.find_possible_tools_from_path(path, recursive=False, enable_beta_formats=False)[source]

Walk a directory and find potential tool files.

galaxy.tools.loader_directory.load_tool_sources_from_path(path, load_exception_handler=<function load_exception_handler>, recursive=False, register_load_errors=False)[source]

Walk a directory and ToolSource objects.

galaxy.tools.loader_directory.load_tool_elements_from_path(path, load_exception_handler=<function load_exception_handler>, recursive=False, register_load_errors=False)[source]

Walk a directory and load tool XML elements.

galaxy.tools.loader_directory.is_tool_load_error(obj)[source]

Predicate to determine if object loaded for tool is a tool error.

galaxy.tools.loader_directory.looks_like_a_tool_xml(path)[source]

Quick check to see if a file looks like it may be a Galaxy XML tool file.

galaxy.tools.loader_directory.is_a_yaml_with_class(path, classes)[source]

Determine if a file is a valid YAML with a supplied class entry.

galaxy.tools.loader_directory.looks_like_a_tool_yaml(path)[source]

Quick check to see if a file looks like it may be a Galaxy YAML tool file.

galaxy.tools.loader_directory.looks_like_a_cwl_artifact(path, classes=None)[source]

Quick check to see if a file looks like it may be a CWL artifact.

galaxy.tools.loader_directory.looks_like_a_tool_cwl(path)[source]

Quick check to see if a file looks like it may be a CWL tool.

galaxy.tools.test module

galaxy.tools.test.parse_tests(tool, tests_source)[source]

Build ToolTestBuilder objects for each “<test>” elements and return default interactor (if any).

class galaxy.tools.test.ToolTestBuilder(tool, test_dict, i, default_interactor)[source]

Bases: object

Encapsulates information about a tool test, and allows creation of a dynamic TestCase class (the unittest framework is very class oriented, doing dynamic tests in this way allows better integration)

__init__(tool, test_dict, i, default_interactor)[source]
test_data()[source]

Iterator over metadata representing the required files for upload.

galaxy.tools.test.test_data_iter(required_files)[source]
galaxy.tools.test.require_file(name, value, extra, required_files)[source]
class galaxy.tools.test.ParamContext(name, index=None, parent_context=None)[source]

Bases: object

__init__(name, index=None, parent_context=None)[source]
for_state()[source]
param_names()[source]
extract_value(raw_inputs)[source]
class galaxy.tools.test.RootParamContext[source]

Bases: object

__init__()[source]
for_state()[source]
param_names()[source]
get_index()[source]

galaxy.tools.wrappers module

galaxy.tools.wrappers.DEFAULT_PATH_REWRITER(x)[source]
class galaxy.tools.wrappers.ToolParameterValueWrapper[source]

Bases: object

Base class for object that Wraps a Tool Parameter and Value.

get_display_text(quote=True)[source]

Returns a string containing the value that would be displayed to the user in the tool interface. When quote is True (default), the string is escaped for e.g. command-line usage.

class galaxy.tools.wrappers.RawObjectWrapper(obj)[source]

Bases: galaxy.tools.wrappers.ToolParameterValueWrapper

Wraps an object so that __str__ returns module_name:class_name.

__init__(obj)[source]
class galaxy.tools.wrappers.InputValueWrapper(input, value, other_values={})[source]

Bases: galaxy.tools.wrappers.ToolParameterValueWrapper

Wraps an input so that __str__ gives the “param_dict” representation.

__init__(input, value, other_values={})[source]
class galaxy.tools.wrappers.SelectToolParameterWrapper(input, value, other_values={}, path_rewriter=None)[source]

Bases: galaxy.tools.wrappers.ToolParameterValueWrapper

Wraps a SelectTooParameter so that __str__ returns the selected value, but all other attributes are accessible.

class SelectToolParameterFieldWrapper(input, value, other_values, path_rewriter)[source]

Provide access to any field by name or index for this particular value. Only applicable for dynamic_options selects, which have more than simple ‘options’ defined (name, value, selected).

__init__(input, value, other_values, path_rewriter)[source]
SelectToolParameterWrapper.__init__(input, value, other_values={}, path_rewriter=None)[source]
class galaxy.tools.wrappers.DatasetFilenameWrapper(dataset, datatypes_registry=None, tool=None, name=None, dataset_path=None, identifier=None)[source]

Bases: galaxy.tools.wrappers.ToolParameterValueWrapper

Wraps a dataset so that __str__ returns the filename, but all other attributes are accessible.

class MetadataWrapper(metadata)[source]

Wraps a Metadata Collection to return MetadataParameters wrapped according to the metadata spec. Methods implemented to match behavior of a Metadata Collection.

__init__(metadata)[source]
get(key, default=None)[source]
items()[source]
DatasetFilenameWrapper.__init__(dataset, datatypes_registry=None, tool=None, name=None, dataset_path=None, identifier=None)[source]
DatasetFilenameWrapper.element_identifier
DatasetFilenameWrapper.is_collection
DatasetFilenameWrapper.is_of_type(*exts)[source]
class galaxy.tools.wrappers.HasDatasets[source]
paths_as_file(sep='\n')[source]
class galaxy.tools.wrappers.DatasetListWrapper(job_working_directory, datasets, dataset_paths=[], **kwargs)[source]

Bases: list, galaxy.tools.wrappers.ToolParameterValueWrapper, galaxy.tools.wrappers.HasDatasets

__init__(job_working_directory, datasets, dataset_paths=[], **kwargs)[source]
static to_dataset_instances(dataset_instance_sources)[source]
class galaxy.tools.wrappers.DatasetCollectionWrapper(job_working_directory, has_collection, dataset_paths=[], **kwargs)[source]

Bases: galaxy.tools.wrappers.ToolParameterValueWrapper, galaxy.tools.wrappers.HasDatasets

__init__(job_working_directory, has_collection, dataset_paths=[], **kwargs)[source]
keys()[source]
is_collection
is_input_supplied