tools Package

tools Package

Classes encapsulating galaxy tools and tool configuration.

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.BadValue(value)[source]

Bases: object

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.DataManagerTool(config_file, root, app, guid=None, data_manager_id=None, **kwds)[source]

Bases: galaxy.tools.OutputParameterJSONTool

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.

default_tool_action

alias of DataManagerToolAction

exec_after_process(app, inp_data, out_data, param_dict, job=None, **kwds)[source]
get_default_history_by_trans(trans, create=False)[source]
tool_type = 'manage_data'
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.

default_tool_action

alias of DataSourceToolAction

exec_before_job(app, inp_data, out_data, param_dict=None)[source]
parse_inputs(tool_source)[source]
tool_type = 'data_source'
class galaxy.tools.DefaultToolState[source]

Bases: object

Keeps track of the state of a users interaction with a tool between requests. The default tool state keeps track of the current page (for multipage “wizard” tools) and the values of all

copy()[source]

WARNING! Makes a shallow copy, SHOULD rework to have it make a deep copy.

decode(value, tool, app, secure=True)[source]

Restore the state from a string

encode(tool, app, secure=True)[source]

Convert the data to a string

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.GenomeIndexTool(config_file, tool_source, app, guid=None, repository_id=None, allow_code_files=True)[source]

Bases: galaxy.tools.Tool

tool_type = 'index_genome'
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'
exception galaxy.tools.InterruptedUpload[source]

Bases: exceptions.Exception

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

exec_before_job(app, inp_data, out_data, param_dict=None)[source]
tool_type = 'output_parameter_json'
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.

exec_after_process(app, inp_data, out_data, param_dict, job=None)[source]
job_failed(job_wrapper, message, exception=False)[source]
requires_setting_metadata = False
tool_type = 'set_metadata'
class galaxy.tools.SetParamAction(name, output_name)[source]

Set parameter action.

static parse(elt)[source]

Parse action from element.

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

Bases: object, galaxy.model.item_attrs.Dictifiable

Represents a computational tool that can be executed through Galaxy.

allow_user_access(user, attempting_access=True)[source]
Returns:bool – Whether the user is allowed to access the tool.
build_dependency_shell_commands()[source]

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

build_redirect_url_params(param_dict)[source]

Substitute parameter values into self.redirect_url_params

call_hook(hook_name, *args, **kwargs)[source]

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

check_and_update_param_values(values, trans, update_values=True, allow_workflow_parameters=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.

check_and_update_param_values_helper(inputs, values, trans, messages, context=None, prefix='', update_values=True, allow_workflow_parameters=False)[source]

Recursive helper for check_and_update_param_values_helper

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.

collect_child_datasets(output, job_working_directory)[source]

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

collect_dynamic_collections(output, **kwds)[source]

Find files corresponding to dynamically structured collections.

collect_primary_datasets(output, job_working_directory, input_ext)[source]

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

default_template = 'tool_form.mako'
default_tool_action

alias of DefaultToolAction

dict_collection_visible_keys = ('id', 'name', 'version', 'description')
exec_after_process(app, inp_data, out_data, param_dict, job=None)[source]
exec_before_job(app, inp_data, out_data, param_dict={})[source]
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.

fill_in_new_state(trans, inputs, state, context=None, history=None)[source]

Fill in a tool state dictionary with default values for all parameters in the dictionary inputs. Grouping elements are filled in recursively.

find_fieldstorage(x)[source]
find_output_def(name)[source]
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).

get_hook(name)[source]

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

get_job_destination(job_params=None)[source]
Returns:galaxy.jobs.JobDestination – The destination definition and runner parameters.
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_panel_section()[source]
get_param(key)[source]

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

get_param_html_map(trans, page=0, other_values={})[source]

Return a dictionary containing the HTML representation of each parameter. This is used for rendering display elements. It is currently not compatible with grouping constructs.

NOTE: This should be considered deprecated, it is only used for tools
with display elements. These should be eliminated.
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.

handle_input(trans, incoming, history=None, old_errors=None, process_state='update', source='html')[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).

process_state can be either ‘update’ (to incrementally build up the state over several calls - one repeat per handle for instance) or ‘populate’ force a complete build of the state and submission all at once (like from API). May want an incremental version of the API also at some point, that is why this is not just called for_api.

handle_interrupted(trans, inputs)[source]

Upon handling inputs, if it appears that we have received an incomplete form, do some cleanup or anything else deemed necessary. Currently this is only likely during file uploads, but this method could be generalized and a method standardized for handling other tools.

handle_job_failure_exception(e)[source]

Called by job.fail when an exception is generated to allow generation of a better error message (returning None yields the default behavior)

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

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

handle_unvalidated_param_values(input_values, app)[source]

Find any instances of UnvalidatedValue within input_values and validate them (by calling ToolParameter.from_html and ToolParameter.validate).

handle_unvalidated_param_values_helper(inputs, input_values, app, context=None, prefix='')[source]

Recursive helper for handle_unvalidated_param_values

help
help_by_page
installed_tool_dependencies
job_failed(job_wrapper, message, exception=False)[source]

Called when a job has failed

new_state(trans, all_pages=False, history=None)[source]

Create a new DefaultToolState for this tool. It will be initialized with default values for inputs.

Only inputs on the first page will be initialized unless all_pages is True, in which case all inputs regardless of page are initialized.

params_from_strings(params, app, ignore_errors=False)[source]
params_to_strings(params, app)[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.

parse(tool_source, guid=None)[source]

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

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_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_input_page(page_source, enctypes)[source]

Parse a page of inputs. This basically just calls ‘parse_input_elem’, but it also deals with possible ‘display’ elements which are supported only at the top/page level (not in groups).

parse_inputs(tool_source)[source]

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

parse_outputs(tool_source)[source]

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

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.

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
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).

populate_state(trans, inputs, state, incoming, history=None, source='html', prefix='', context=None)[source]
populate_tool_shed_info()[source]
produces_collections
requires_setting_metadata = True
sa_session

Returns a SQLAlchemy session

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

Returns dict of tool.

to_json(trans, kwd={}, is_workflow=False)[source]

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

tool_shed_repository
tool_type = 'default'
tool_version

Return a ToolVersion if one exists for our id

tool_versions
update_state(trans, inputs, state, incoming, source='html', prefix='', context=None, update_only=False, old_errors={}, item_callback=None)[source]

Update the tool state in state using the user input in incoming. This is designed to be called recursively: inputs contains the set of inputs being processed, and prefix specifies a prefix to add to the name of each input to extract its value from incoming.

If update_only is True, values that are not in incoming will not be modified. In this case old_errors can be provided, and any errors for parameters which were not updated will be preserved.

visit_inputs(value, 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 )

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

Bases: galaxy.tools.toolbox.base.AbstractToolBox

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

create_tool(config_file, repository_id=None, guid=None, **kwds)[source]
handle_datatypes_changed()[source]

Refresh upload tools when new datatypes are added.

tools_by_id
exception galaxy.tools.ToolNotFoundException[source]

Bases: exceptions.Exception

class galaxy.tools.ToolOutput(name, format=None, format_source=None, metadata_source=None, parent=None, label=None, filters=None, actions=None, hidden=False, implicit=False)[source]

Bases: galaxy.tools.ToolOutputBase

Represents an output datasets produced by a tool. For backward compatibility this behaves as if it were the tuple:

(format, metadata_source, parent)
dict_collection_visible_keys = ('name', 'format', 'label', 'hidden')
class galaxy.tools.ToolOutputBase(name, label=None, filters=None, hidden=False)[source]

Bases: object, galaxy.model.item_attrs.Dictifiable

class galaxy.tools.ToolOutputCollection(name, structure, label=None, filters=None, hidden=False, default_format='data', default_format_source=None, default_metadata_source=None, inherit_format=False, inherit_metadata=False)[source]

Bases: galaxy.tools.ToolOutputBase

Represents a HistoryDatasetCollectionAssociation of output datasets produced by a tool. <outputs>

<dataset_collection type=”list” label=”${tool.name} on ${on_string} fasta”>
<discover_datasets pattern=”__name__” ext=”fasta” visible=”True” directory=”outputFiles” />

</dataset_collection> <dataset_collection type=”paired” label=”${tool.name} on ${on_string} paired reads”>

<data name=”forward” format=”fastqsanger” /> <data name=”reverse” format=”fastqsanger”/>

</dataset_collection>

<outputs>

dataset_collectors
dynamic_structure
known_outputs(inputs, type_registry)[source]
class galaxy.tools.ToolOutputCollectionPart(output_collection_def, element_identifier, output_def)[source]

Bases: object

effective_output_name
static is_named_collection_part_name(name)[source]
static split_output_name(name)[source]
class galaxy.tools.ToolOutputCollectionStructure(collection_type, structured_like, dataset_collectors)[source]

Bases: object

class galaxy.tools.TracksterConfig(actions)[source]

Trackster configuration encapsulation.

static parse(root)[source]
galaxy.tools.check_param_from_incoming(trans, state, input, incoming, key, context, source)[source]

Unlike “update” state, this preserves default if no incoming value found. This lets API user specify just a subset of params and allow defaults to be used when available.

galaxy.tools.get_incoming_value(incoming, key, default)[source]

Fetch value from incoming dict directly or check special nginx upload created variants of this key.

galaxy.tools.json_fix(val)[source]
galaxy.tools.tool_class

alias of DataDestinationTool

exception_handling Module

Exceptions and handlers for tools.

FIXME: These are used by tool scripts, not the framework, and should not live
in this package.
exception galaxy.tools.exception_handling.UCSCLimitException[source]

Bases: exceptions.Exception

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

next()[source]
readline()[source]

test Module

class galaxy.tools.test.ParamContext(name, index=None, parent_context=None)[source]

Bases: object

extract_value(raw_inputs)[source]
for_state()[source]
param_names()[source]
class galaxy.tools.test.RootParamContext[source]

Bases: object

for_state()[source]
get_index()[source]
param_names()[source]
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)

test_data()[source]

Iterator over metadata representing the required files for upload.

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

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

galaxy.tools.test.require_file(name, value, extra, required_files)[source]
galaxy.tools.test.test_data_iter(required_files)[source]