galaxy.util package

Utility functions used systemwide.


Supplied URL may be null, if not ensure http:// or https:// etc… is stripped off.


File is binary if it contains a null-byte by default (e.g. behavior of grep, etc.). This may fail for utf-16 files, but so would ASCII encoding. >>> is_binary( string.printable ) False >>> is_binary( b’xcex94’ ) False >>> is_binary( b’x00’ ) True


This method returns True if value is a UUID, otherwise False. >>> is_uuid( “123e4567-e89b-12d3-a456-426655440000” ) True >>> is_uuid( “0x3242340298902834” ) False

>>> directory_hash_id( 100 )
>>> directory_hash_id( "90000" )
>>> directory_hash_id("777777777")
['000', '777', '777']
>>> directory_hash_id("135ee48a-4f51-470c-ae2f-ce8bd78799e6")
['1', '3', '5']
galaxy.util.get_charset_from_http_headers(headers, default=None)[source]

This wrapper will serialize access to ‘func’ to a single thread. Use it as a decorator.

galaxy.util.iter_start_of_line(fh, chunk_size=None)[source]

Iterate over fh and call readline(chunk_size)

galaxy.util.file_reader(fp, chunk_size=65536)[source]

This generator yields the open fileobject in chunks (default 64k). Closes the file at the end


Generates an unique id

>>> ids = [ unique_id() for i in range(1000) ]
>>> len(set(ids))
galaxy.util.parse_xml(fname, strip_whitespace=True, remove_comments=True)[source]

Returns a parsed xml tree

galaxy.util.parse_xml_string(xml_string, strip_whitespace=True)[source]
galaxy.util.xml_to_string(elem, pretty=False)[source]

Returns a string from an xml tree.

galaxy.util.xml_element_compare(elem1, elem2)[source]
galaxy.util.xml_element_list_compare(elem_list1, elem_list2)[source]
galaxy.util.pretty_print_xml(elem, level=0)[source]
galaxy.util.get_file_size(value, default=None)[source]
galaxy.util.shrink_stream_by_size(value, size, join_by=b'..', left_larger=True, beginning_on_size_error=False, end_on_size_error=False)[source]

Shrinks bytes read from value to size.

value needs to implement tell/seek, so files need to be opened in binary mode. Returns unicode text with invalid characters replaced.

galaxy.util.shrink_string_by_size(value, size, join_by='..', left_larger=True, beginning_on_size_error=False, end_on_size_error=False)[source]
galaxy.util.pretty_print_time_interval(time=False, precise=False, utc=False)[source]

Get a datetime object or a int() Epoch timestamp and return a pretty string like ‘an hour ago’, ‘Yesterday’, ‘3 months ago’, ‘just now’, etc credit:

galaxy.util.pretty_print_json(json_data, is_json_string=False)[source]
galaxy.util.restore_text(text, character_map={'\t': '__tc__', '\n': '__cn__', '\r': '__cr__', '"': '__dq__', '#': '__pd__', "'": '__sq__', '<': '__lt__', '>': '__gt__', '@': '__at__', '[': '__ob__', ']': '__cb__', '{': '__oc__', '}': '__cc__'})[source]

Restores sanitized text

galaxy.util.sanitize_text(text, valid_characters={'Z', 'I', '0', '^', 'V', 'P', 'h', 'v', 'w', 'Q', '1', '*', 'b', '3', 'F', 'u', 'x', 'n', 'O', '+', '.', 'e', 'W', 's', 'H', 'X', '=', 'c', 'k', 'o', '6', 'G', 'Y', '-', 'N', 'K', 't', 'r', 'T', '9', 'A', 'C', 'D', 'E', ' ', '(', 'S', 'p', 'd', '!', 'm', 'q', 'U', 'R', '2', ')', 'M', 'a', '5', ', ', 'g', 'z', 'f', 'J', '4', '7', 'i', 'L', '_', 'y', 'l', '8', ':', 'B', '?', 'j', '/'}, character_map={'\t': '__tc__', '\n': '__cn__', '\r': '__cr__', '"': '__dq__', '#': '__pd__', "'": '__sq__', '<': '__lt__', '>': '__gt__', '@': '__at__', '[': '__ob__', ']': '__cb__', '{': '__oc__', '}': '__cc__'}, invalid_character='X')[source]

Restricts the characters that are allowed in text; accepts both strings and lists of strings; non-string entities will be cast to strings.

galaxy.util.sanitize_lists_to_string(values, valid_characters={'Z', 'I', '0', '^', 'V', 'P', 'h', 'v', 'w', 'Q', '1', '*', 'b', '3', 'F', 'u', 'x', 'n', 'O', '+', '.', 'e', 'W', 's', 'H', 'X', '=', 'c', 'k', 'o', '6', 'G', 'Y', '-', 'N', 'K', 't', 'r', 'T', '9', 'A', 'C', 'D', 'E', ' ', '(', 'S', 'p', 'd', '!', 'm', 'q', 'U', 'R', '2', ')', 'M', 'a', '5', ', ', 'g', 'z', 'f', 'J', '4', '7', 'i', 'L', '_', 'y', 'l', '8', ':', 'B', '?', 'j', '/'}, character_map={'\t': '__tc__', '\n': '__cn__', '\r': '__cr__', '"': '__dq__', '#': '__pd__', "'": '__sq__', '<': '__lt__', '>': '__gt__', '@': '__at__', '[': '__ob__', ']': '__cb__', '{': '__oc__', '}': '__cc__'}, invalid_character='X')[source]
galaxy.util.sanitize_param(value, valid_characters={'Z', 'I', '0', '^', 'V', 'P', 'h', 'v', 'w', 'Q', '1', '*', 'b', '3', 'F', 'u', 'x', 'n', 'O', '+', '.', 'e', 'W', 's', 'H', 'X', '=', 'c', 'k', 'o', '6', 'G', 'Y', '-', 'N', 'K', 't', 'r', 'T', '9', 'A', 'C', 'D', 'E', ' ', '(', 'S', 'p', 'd', '!', 'm', 'q', 'U', 'R', '2', ')', 'M', 'a', '5', ', ', 'g', 'z', 'f', 'J', '4', '7', 'i', 'L', '_', 'y', 'l', '8', ':', 'B', '?', 'j', '/'}, character_map={'\t': '__tc__', '\n': '__cn__', '\r': '__cr__', '"': '__dq__', '#': '__pd__', "'": '__sq__', '<': '__lt__', '>': '__gt__', '@': '__at__', '[': '__ob__', ']': '__cb__', '{': '__oc__', '}': '__cc__'}, invalid_character='X')[source]

Clean incoming parameters (strings or lists)

galaxy.util.sanitize_for_filename(text, default=None)[source]

Restricts the characters that are allowed in a filename portion; Returns default value or a unique id string if result is not a valid name. Method is overly aggressive to minimize possible complications, but a maximum length is not considered.

galaxy.util.find_instance_nested(item, instances, match_key=None)[source]

Recursively find instances from lists, dicts, tuples.

instances should be a tuple of valid instances If match_key is given the key must match for an instance to be added to the list of found instances.


Masks out passwords from connection urls like the database connection in galaxy.ini

>>> mask_password_from_url( 'sqlite+postgresql://user:password@localhost/' )
>>> mask_password_from_url( 'amqp://user:amqp@localhost' )
>>> mask_password_from_url( 'amqp://localhost')

General method to convert a string (i.e. object name) to a URL-ready slug.

>>> ready_name_for_url( "My Cool Object" )
>>> ready_name_for_url( "!My Cool Object!" )
>>> ready_name_for_url( "Hello₩◎ґʟⅾ" )
galaxy.util.in_directory(file, directory, local_path_module=<module 'posixpath' from '/var/jenkins/workspace/galaxy-sphinx-by-branch/PYTHON/System-CPython-2.7/TARGET_GIT_BRANCH/master/.venv/lib/python3.7/'>)[source]

Return true, if the common prefix of both is equal to directory e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b. This function isn’t used exclusively for security checks, but if it is used for such checks it is assumed that directory is a “trusted” path - supplied by Galaxy or by the admin and file is something generated by a tool, configuration, external web server, or user supplied input.

local_path_module is used by Pulsar to check Windows paths while running on a POSIX-like system.

>>> base_dir = tempfile.mkdtemp()
>>> safe_dir = os.path.join(base_dir, "user")
>>> os.mkdir(safe_dir)
>>> good_file = os.path.join(safe_dir, "1")
>>> with open(good_file, "w") as f: _ = f.write("hello")
>>> in_directory(good_file, safe_dir)
>>> in_directory("/other/file/is/here.txt", safe_dir)
>>> unsafe_link = os.path.join(safe_dir, "2")
>>> os.symlink("/other/file/bad.fasta", unsafe_link)
>>> in_directory(unsafe_link, safe_dir)
galaxy.util.merge_sorted_iterables(operator, *iterables)[source]
>>> operator = lambda x: x
>>> list( merge_sorted_iterables( operator, [1,2,3], [4,5] ) )
[1, 2, 3, 4, 5]
>>> list( merge_sorted_iterables( operator, [4, 5], [1,2,3] ) )
[1, 2, 3, 4, 5]
>>> list( merge_sorted_iterables( operator, [1, 4, 5], [2], [3] ) )
[1, 2, 3, 4, 5]
class galaxy.util.Params(params, sanitize=True)[source]

Bases: object

Stores and ‘sanitizes’ parameters. Alphanumeric characters and the non-alphanumeric ones that are deemed safe are let to pass through (see L{valid_chars}). Some non-safe characters are escaped to safe forms for example C{>} becomes C{__lt__} (see L{mapped_chars}). All other characters are replaced with C{X}.

Operates on string or list values only (HTTP parameters).

>>> values = { 'status':'on', 'symbols':[  'alpha', '<>', '$rm&#!' ]  }
>>> par = Params(values)
>>> par.status
>>> par.value == None      # missing attributes return None
>>> par.get('price', 0)
>>> par.symbols            # replaces unknown symbols with X
['alpha', '__lt____gt__', 'XrmX__pd__!']
>>> sorted(par.flatten())  # flattening to a list
[('status', 'on'), ('symbols', 'XrmX__pd__!'), ('symbols', '__lt____gt__'), ('symbols', 'alpha')]
NEVER_SANITIZE = ['file_data', 'url_paste', 'URL', 'filesystem_paths']
__init__(params, sanitize=True)[source]

Creates a tuple list from a dict with a tuple/value pair for every value that is a list

get(key, default)[source]
galaxy.util.rst_to_html(s, error=False)[source]

Convert a blob of reStructuredText to HTML

galaxy.util.xml_text(root, name=None)[source]

Returns the text inside an element


Code shared between jobs and workflows for reading resource parameter configuration files.

TODO: Allow YAML in addition to XML.

Returns True, None or False based on the argument:
True if passed True, ‘True’, ‘Yes’, or ‘On’ None if passed None or ‘None’ False otherwise

Note: string comparison is case-insensitive so lowecase versions of those function equivalently.

galaxy.util.listify(item, do_strip=False)[source]

Make a single item a single item list.

If item is a string, it is split on comma (,) characters to produce the list. Optionally, if do_strip is true, any extra whitespace around the split items is stripped.

If item is a list it is returned unchanged. If item is a tuple, it is converted to a list and returned. If item evaluates to False, an empty list is returned.

  • item (object) – object to make a list from
  • do_strip (bool) – strip whitespaces from around split items, if set to True
Return type:



The input as a list

galaxy.util.roundify(amount, sfs=2)[source]

Take a number in string form and truncate to ‘sfs’ significant figures.

galaxy.util.unicodify(value, encoding='utf-8', error='replace', strip_null=False)[source]

Returns a Unicode string or None.

>>> assert unicodify(None) is None
>>> assert unicodify('simple string') == u'simple string'
>>> assert unicodify(3) == u'3'
>>> assert unicodify(bytearray([115, 116, 114, 196, 169, 195, 177, 103])) == u'strĩñg'
>>> assert unicodify(Exception(u'strĩñg')) == u'strĩñg'
>>> assert unicodify('cómplǐcḁtëd strĩñg') == u'cómplǐcḁtëd strĩñg'
>>> s = u'cómplǐcḁtëd strĩñg'; assert unicodify(s) == s
>>> s = u'lâtín strìñg'; assert unicodify(s.encode('latin-1'), 'latin-1') == s
>>> s = u'lâtín strìñg'; assert unicodify(s.encode('latin-1')) == u'l�t�n str��g'
>>> s = u'lâtín strìñg'; assert unicodify(s.encode('latin-1'), error='ignore') == u'ltn strg'
galaxy.util.smart_str(s, encoding='utf-8', strings_only=False, errors='strict')[source]

Returns a bytestring version of ‘s’, encoded as specified in ‘encoding’.

If strings_only is True, don’t convert (some) non-string-like objects.

Adapted from an older, simpler version of django.utils.encoding.smart_str.

>>> assert smart_str(None) == b'None'
>>> assert smart_str(None, strings_only=True) is None
>>> assert smart_str(3) == b'3'
>>> assert smart_str(3, strings_only=True) == 3
>>> s = b'a bytes string'; assert smart_str(s) == s
>>> s = bytearray(b'a bytes string'); assert smart_str(s) == s
>>> assert smart_str(u'a simple unicode string') == b'a simple unicode string'
>>> assert smart_str(u'à strange ünicode ڃtring') == b'\xc3\xa0 strange \xc3\xbcnicode \xda\x83tring'
>>> assert smart_str(b'\xc3\xa0n \xc3\xabncoded utf-8 string', encoding='latin-1') == b'\xe0n \xebncoded utf-8 string'
>>> assert smart_str(bytearray(b'\xc3\xa0n \xc3\xabncoded utf-8 string'), encoding='latin-1') == b'\xe0n \xebncoded utf-8 string'

Strip unicode control characters from a string.


Recursively strips control characters from lists, dicts, tuples.

galaxy.util.clean_multiline_string(multiline_string, sep='\n')[source]

Dedent, split, remove first and last empty lines, rejoin.

class galaxy.util.ParamsWithSpecs(specs=None, params=None)[source]

Bases: collections.defaultdict

__init__(specs=None, params=None)[source]
galaxy.util.compare_urls(url1, url2, compare_scheme=True, compare_hostname=True, compare_path=True)[source]

Read build names from file

galaxy.util.read_build_sites(filename, check_builds=True)[source]

read db names to ucsc mappings from file, this file should probably be merged with the one above

galaxy.util.mkstemp_ln(src, prefix='mkstemp_ln_')[source]

From tempfile._mkstemp_inner, generate a hard link in the same dir with a random name. Created so we can persist the underlying file of a NamedTemporaryFile upon its closure.

galaxy.util.umask_fix_perms(path, umask, unmasked_perms, gid=None)[source]

umask-friendly permissions fixing


Trimming python doc strings. Taken from:


Returns a readably formatted string with the size

>>> nice_size(100)
'100 bytes'
>>> nice_size(10000)
'9.8 KB'
>>> nice_size(1000000)
'976.6 KB'
>>> nice_size(100000000)
'95.4 MB'

Returns a number of bytes (as integer) if given a reasonably formatted string with the size

>>> size_to_bytes('1024')
>>> size_to_bytes('1.0')
>>> size_to_bytes('10 bytes')
>>> size_to_bytes('4k')
>>> size_to_bytes('2.2 TB')
>>> size_to_bytes('.01 TB')
>>> size_to_bytes('1.b')
>>> size_to_bytes('1.2E2k')
galaxy.util.send_mail(frm, to, subject, body, config, html=None)[source]

Sends an email.

  • frm (str) – from address
  • to (str) – to address
  • subject (str) – Subject line
  • body (str) – Body text (should be plain text)
  • config (object) – Galaxy configuration object
  • html (str) – Alternative HTML representation of the body content. If provided will convert the message to a MIMEMultipart. (Default ‘None’)
galaxy.util.move_merge(source, target)[source]
galaxy.util.safe_str_cmp(a, b)[source]

safely compare two strings in a timing-attack-resistant manner

galaxy.util.config_directories_from_setting(directories_setting, galaxy_root='/var/jenkins/workspace/galaxy-sphinx-by-branch/PYTHON/System-CPython-2.7/TARGET_GIT_BRANCH/master/lib/galaxy/util/../../..')[source]

Parse the directories_setting into a list of relative or absolute filesystem paths that will be searched to discover plugins.

  • galaxy_root (string) – the root path of this galaxy installation
  • directories_setting (string (default: None)) – the filesystem path (or paths) to search for plugins. Can be CSV string of paths. Will be treated as absolute if a path starts with ‘/’, relative otherwise.
Return type:

list of strings


list of filesystem paths

galaxy.util.parse_int(value, min_val=None, max_val=None, default=None, allow_none=False)[source]

Parse string s into a float but throw a ValueError if the string is in the otherwise acceptable format d+ed+ (e.g. 40000000000000e5.)

This can be passed into json.loads to prevent a hex string in the above format from being incorrectly parsed as a float in scientific notation.

>>> parse_non_hex_float( '123.4' )
>>> parse_non_hex_float( '2.45e+3' )
>>> parse_non_hex_float( '2.45e-3' )
>>> parse_non_hex_float( '40000000000000e5' )
Traceback (most recent call last):
ValueError: could not convert string to float: 40000000000000e5
galaxy.util.build_url(base_url, port=80, scheme='http', pathspec=None, params=None, doseq=False)[source]
galaxy.util.url_get(base_url, auth=None, pathspec=None, params=None, max_retries=5, backoff_factor=1)[source]

Make contact with the uri provided and return any contents.

galaxy.util.download_to_file(url, dest_file_path, timeout=30, chunk_size=1048576)[source]

Download a URL to a file in chunks.

class galaxy.util.classproperty(f)[source]

Bases: object

class galaxy.util.ExecutionTimer[source]

Bases: object

class galaxy.util.StructuredExecutionTimer(timer_id, template, **tags)[source]

Bases: object

__init__(timer_id, template, **tags)[source]


galaxy.util.aliaspickler module

class galaxy.util.aliaspickler.AliasUnpickler(aliases, *args, **kw)[source]

Bases: _pickle.Unpickler

__init__(aliases, *args, **kw)[source]
find_class(module, name)[source]
class galaxy.util.aliaspickler.AliasPickleModule(aliases)[source]

Bases: object

dump(obj, fileobj, protocol=0)[source]
dumps(obj, protocol=0)[source]

galaxy.util.bunch module

class galaxy.util.bunch.Bunch(**kwds)[source]

Bases: object

Often we want to just collect a bunch of stuff together, naming each item of the bunch; a dictionary’s OK for that, but a small do-nothing class is even handier, and prettier to use.

get(key, default=None)[source]

galaxy.util.bytesize module

class galaxy.util.bytesize.ByteSize(value)[source]

Bases: object

Convert multiples of bytes to various units.


Represents a quantity of bytes.

value may be an integer, in which case it is assumed to be bytes. If value is a string, it is parsed as bytes if no suffix (Mi, M, Gi, G …) is found.

>>> values = [128974848, '129e6', '129M', '123Mi' ]
>>> [ByteSize(v).to_unit('M') for v in values]
['128M', '129M', '129M', '128M']
to_unit(unit=None, as_string=True)[source]

unit must be None or one of Ki,Mi,Gi,Ti,Pi,Ei,K,M,G,T,P.


galaxy.util.checkers module

galaxy.util.checkers.check_html(name, file_path=True)[source]

Returns True if the file/string contains HTML code.

galaxy.util.checkers.check_binary(name, file_path=True)[source]
galaxy.util.checkers.check_gzip(file_path, check_content=True)[source]
galaxy.util.checkers.check_bz2(file_path, check_content=True)[source]
galaxy.util.checkers.check_zip(file_path, check_content=True, files=1)[source]

Simple wrapper around image_type to yield a True/False verdict

galaxy.util.commands module

Generic I/O and shell processing code used by Galaxy tool dependencies.

galaxy.util.commands.redirecting_io(sys=<module 'sys' (built-in)>)[source]

Predicate to determine if we are redicting stdout in process.

galaxy.util.commands.redirect_aware_commmunicate(p, sys=<module 'sys' (built-in)>)[source]

Variant of process.communicate that works with in process I/O redirection., env=None, **kwds)[source]

Run shell commands with shell_process and wait.

galaxy.util.commands.shell_process(cmds, env=None, **kwds)[source]

A high-level method wrapping subprocess.Popen.

Handles details such as environment extension and in process I/O redirection.

galaxy.util.commands.execute(cmds, input=None)[source]

Execute commands and throw an exception on a non-zero exit. if input is not None then the string is sent to the process’ stdin.

Return the standard output if the commands are successful

galaxy.util.commands.argv_to_str(command_argv, quote=True)[source]

Convert an argv command list to a string for shell subprocess.

If None appears in the command list it is simply excluded.

Arguments are quoted with shlex_quote. That said, this method is not meant to be used in security critical paths of code and should not be used to sanitize code.

galaxy.util.commands.download_command(url, to='-')[source]

Build a command line to download a URL.

By default the URL will be downloaded to standard output but a specific file can be specified with the to argument.

exception galaxy.util.commands.CommandLineException(command, stdout, stderr, returncode)[source]

Bases: Exception

An exception indicating a non-zero command-line exit.

__init__(command, stdout, stderr, returncode)[source]

Construct a CommandLineException from command and standard I/O.


galaxy.util.compression_utils module

galaxy.util.compression_utils.get_fileobj(filename, mode='r', compressed_formats=None)[source]

Returns a fileobj. If the file is compressed, return an appropriate file reader. In text mode, always use ‘utf-8’ encoding.

  • filename – path to file that should be opened
  • mode – mode to pass to opener
  • compressed_formats – list of allowed compressed file formats among ‘bz2’, ‘gzip’ and ‘zip’. If left to None, all 3 formats are allowed
galaxy.util.compression_utils.get_fileobj_raw(filename, mode='r', compressed_formats=None)[source]
galaxy.util.compression_utils.file_iter(fname, sep=None)[source]

This generator iterates over a file and yields its lines splitted via the C{sep} parameter. Skips empty lines and lines starting with the C{#} character.

>>> lines = [ line for line in file_iter(__file__) ]
>>> len(lines) !=  0
class galaxy.util.compression_utils.CompressedFile(file_path, mode='r')[source]

Bases: object

static can_decompress(file_path)[source]
__init__(file_path, mode='r')[source]

Get the common prefix directory for all the files in the archive, if any.

Returns ‘’ if the archive contains multiple files and/or directories at the root of the archive.


Determine the path to which the archive should be extracted.

open_tar(filepath, mode)[source]
open_zip(filepath, mode)[source]

This function is a bit pedantic and not functionally necessary. It checks whether there is no file pointing outside of the extraction, because ZipFile.extractall() has some potential security holes. See python zipfile documentation for more details.

galaxy.util.dbkeys module

Functionality for dealing with dbkeys.

class galaxy.util.dbkeys.GenomeBuilds(app, data_table_name='__dbkeys__', load_old_style=True)[source]

Bases: object

default_value = '?'
default_name = 'unspecified (?)'
__init__(app, data_table_name='__dbkeys__', load_old_style=True)[source]
get_chrom_info(dbkey, trans=None, custom_build_hack_get_len_from_fasta_conversion=True)[source]

galaxy.util.dictifiable module

galaxy.util.dictifiable.dict_for(obj, **kwds)[source]
class galaxy.util.dictifiable.Dictifiable[source]

Bases: object

Mixin that enables objects to be converted to dictionaries. This is useful when for sharing objects across boundaries, such as the API, tool scripts, and JavaScript code.

to_dict(view='collection', value_mapper=None)[source]

Return item dictionary.

galaxy.util.expressions module

Expression evaluation support.

For the moment this depends on python’s eval. In the future it should be replaced with a “safe” parser.

class galaxy.util.expressions.ExpressionContext(dict, parent=None)[source]


__init__(dict, parent=None)[source]

Create a new expression context that looks for values in the container object ‘dict’, and falls back to ‘parent’

galaxy.util.facts module

Return various facts for string formatting.

class galaxy.util.facts.Facts(config=None, **kwargs)[source]


A dict-like object that evaluates values at access time.

__init__(config=None, **kwargs)[source]
galaxy.util.facts.get_facts(config=None, **kwargs)[source]

galaxy.util.filelock module

Code obtained from

See full license at:

exception galaxy.util.filelock.FileLockException[source]

Bases: Exception

class galaxy.util.filelock.FileLock(file_name, timeout=10, delay=0.05)[source]

Bases: object

A file locking mechanism that has context-manager support so you can use it in a with statement. This should be relatively cross compatible as it doesn’t rely on msvcrt or fcntl for the locking.

__init__(file_name, timeout=10, delay=0.05)[source]

Prepare the file locker. Specify the file to lock and optionally the maximum timeout and the delay between each attempt to lock.


Acquire the lock, if possible. If the lock is in use, it check again every wait seconds. It does this until it either gets the lock or exceeds timeout number of seconds, in which case it throws an exception.


Get rid of the lock by deleting the lockfile. When working in a with statement, this gets automatically called at the end.

galaxy.util.form_builder module

Classes for generating HTML forms

class galaxy.util.form_builder.BaseField(name, value=None, label=None, **kwds)[source]

Bases: object

__init__(name, value=None, label=None, **kwds)[source]
class galaxy.util.form_builder.TextField(name, value=None, label=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

A standard text input box.

class galaxy.util.form_builder.PasswordField(name, value=None, label=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

A password input box. text appears as “**

class galaxy.util.form_builder.TextArea(name, value=None, label=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

A standard text area box.

class galaxy.util.form_builder.CheckboxField(name, value=None, label=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

A checkbox (boolean input)

static is_checked(value)[source]
class galaxy.util.form_builder.SelectField(name, multiple=None, display=None, field_id=None, value=None, selectlist=None, refresh_on_change=False, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

A select field.

__init__(name, multiple=None, display=None, field_id=None, value=None, selectlist=None, refresh_on_change=False, **kwds)[source]
add_option(text, value, selected=False)[source]
class galaxy.util.form_builder.AddressField(name, user=None, value=None, security=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

static fields()[source]
__init__(name, user=None, value=None, security=None, **kwds)[source]
class galaxy.util.form_builder.WorkflowField(name, user=None, value=None, security=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

__init__(name, user=None, value=None, security=None, **kwds)[source]
class galaxy.util.form_builder.WorkflowMappingField(name, user=None, value=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

__init__(name, user=None, value=None, **kwds)[source]
class galaxy.util.form_builder.HistoryField(name, user=None, value=None, security=None, **kwds)[source]

Bases: galaxy.util.form_builder.BaseField

__init__(name, user=None, value=None, security=None, **kwds)[source]

Get unittest suite for this module

galaxy.util.getargspec module


galaxy.util.hash_util module

Utility functions for bi-directional Python version compatibility. Python 2.5 introduced hashlib which replaced sha in Python 2.4 and previous versions.


Returns a sha1 hash object; optionally initialized with a string


Returns a sha1 hash object; optionally initialized with a string


Returns a md5 hash object; optionally initialized with a string


Returns the hexdigest of the sha1 hash of the argument text_type.

galaxy.util.hash_util.hmac_new(key, value)[source]

galaxy.util.heartbeat module


Get a dictionary of all ‘Thread’ objects created via the threading module keyed by thread_id. Note that not all interpreter threads have a thread objects, only the main thread and any created via the ‘threading’ module. Threads created via the low level ‘thread’ module will not be in the returned dictionary.

HACK: This mucks with the internals of the threading module since that
module does not expose any way to match ‘Thread’ objects with intepreter thread identifiers (though it should).
class galaxy.util.heartbeat.Heartbeat(config, name='Heartbeat Thread', period=20, fname='heartbeat.log')[source]

Bases: threading.Thread

Thread that periodically dumps the state of all threads to a file

__init__(config, name='Heartbeat Thread', period=20, fname='heartbeat.log')[source]

Returns True if the given stack-frame represents a known sleeper function (at least in python 2.5)


Scans a given backtrace stack frames, returns a single quadraple of [filename, line, function-name, text] of the single, deepest, most interesting frame.

Interesting being:

inside the galaxy source code ("/lib/galaxy"),
prefreably not an egg.
dump_signal_handler(signum, frame)[source]

galaxy.util.image_util module

Provides utilities for working with image files.

galaxy.util.image_util.check_image_type(filename, types)[source]

galaxy.util.inflection module

class galaxy.util.inflection.Inflector[source]

Bases: object

Inflector for pluralizing and singularizing English nouns.

NONCHANGING_WORDS = {'rice', 'species', 'sheep', 'series', 'money', 'information', 'equipment', 'sms'}
IRREGULAR_WORDS = {'child': 'children', 'man': 'men', 'move': 'moves', 'octopus': 'octopi', 'person': 'people', 'sex': 'sexes'}
PLURALIZE_RULES = (('(?i)(quiz)$', '\\1zes'), ('(?i)^(ox)$', '\\1en'), ('(?i)([m|l])ouse$', '\\1ice'), ('(?i)(matr|vert|ind)ix|ex$', '\\1ices'), ('(?i)(x|ch|ss|sh)$', '\\1es'), ('(?i)([^aeiouy]|qu)ies$', '\\1y'), ('(?i)([^aeiouy]|qu)y$', '\\1ies'), ('(?i)(hive)$', '\\1s'), ('(?i)(?:([^f])fe|([lr])f)$', '\\1\\2ves'), ('(?i)sis$', 'ses'), ('(?i)([ti])um$', '\\1a'), ('(?i)(buffal|tomat)o$', '\\1oes'), ('(?i)(bu)s$', '\\1ses'), ('(?i)(alias|status|virus)', '\\1es'), ('(?i)(ax|test)is$', '\\1es'), ('(?i)s$', 's'), ('(?i)$', 's'))
SINGULARIZE_RULES = (('(?i)(quiz)zes$', '\\1'), ('(?i)(matr)ices$', '\\1ix'), ('(?i)(vert|ind)ices$', '\\1ex'), ('(?i)^(ox)en', '\\1'), ('(?i)(alias|status|virus)es$', '\\1'), ('(?i)(cris|ax|test)es$', '\\1is'), ('(?i)(shoe)s$', '\\1'), ('(?i)(o)es$', '\\1'), ('(?i)(bus)es$', '\\1'), ('(?i)([m|l])ice$', '\\1ouse'), ('(?i)(x|ch|ss|sh)es$', '\\1'), ('(?i)(m)ovies$', '\\1ovie'), ('(?i)(s)eries$', '\\1eries'), ('(?i)([^aeiouy]|qu)ies$', '\\1y'), ('(?i)([lr])ves$', '\\1f'), ('(?i)(tive)s$', '\\1'), ('(?i)(hive)s$', '\\1'), ('(?i)([^f])ves$', '\\1fe'), ('(?i)(^analy)ses$', '\\1sis'), ('(?i)((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$', '\\1\\2sis'), ('(?i)([ti])a$', '\\1um'), ('(?i)(n)ews$', '\\1ews'), ('(?i)s$', ''))

Pluralizes nouns.


Singularizes nouns.

cond_plural(number_of_records, word)[source]

Returns the plural form of a word if first parameter is greater than 1

galaxy.util.json module

galaxy.util.json.safe_dumps(*args, **kwargs)[source]

This is a wrapper around dumps that encodes Infinity and NaN values. It’s a fairly rare case (which will be low in request volume). Basically, we tell json.dumps to blow up if it encounters Infinity/NaN, and we ‘fix’ it before re-encoding.

galaxy.util.json.validate_jsonrpc_request(request, regular_methods, notification_methods)[source]
galaxy.util.json.validate_jsonrpc_response(response, id=None)[source]
galaxy.util.json.jsonrpc_request(method, params=None, id=None, jsonrpc='2.0')[source]
galaxy.util.json.jsonrpc_response(request=None, id=None, result=None, error=None, jsonrpc='2.0')[source]

galaxy.util.jstree module

class galaxy.util.jstree.Path(path, id, options)

Bases: tuple


Alias for field number 1


Alias for field number 2


Alias for field number 0

class galaxy.util.jstree.Node(path, oid, **kwargs)[source]

Bases: dictobj.DictionaryObject

Copyright 2012 “Grim Apps”

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Helper class written by William Grim - grimwm Original repo: Code adjusted according to the idea of Frank Blechschmidt - FraBle Thank you! ******************** This class exists as a helper to the JSTree. Its “jsonData” method can generate sub-tree JSON without putting the logic directly into the JSTree.

This data structure is only semi-immutable. The JSTree uses a directly iterative (i.e. no stack is managed) builder pattern to construct a tree out of paths. Therefore, the children are not known in advance, and we have to keep the children attribute mutable.

__init__(path, oid, **kwargs)[source]

kwargs allows users to pass arbitrary information into a Node that will later be output in jsonData(). It allows for more advanced configuration than the default path handling that JSTree currently allows. For example, users may want to pass “attr” or some other valid jsTree options.

>>> node = Node('a', None)
>>> assert node._items == {'text': 'a', 'children': dictobj.MutableDictionaryObject({})}
>>> assert node.jsonData() == {'text': 'a'}
>>> node = Node('a', 1)
>>> assert node._items == {'text': 'a', 'children': dictobj.MutableDictionaryObject({}), 'li_attr': dictobj.DictionaryObject({'id': 1}), 'id': 1}
>>> assert node.jsonData() == {'text': 'a', 'id': 1, 'li_attr': {'id': 1}}
>>> node = Node('a', 5, icon="folder", state = {'opened': True})
>>> assert node._items == {'text': 'a', 'id': 5, 'state': dictobj.DictionaryObject({'opened': True}), 'children': dictobj.MutableDictionaryObject({}), 'li_attr': dictobj.DictionaryObject({'id': 5}), 'icon': 'folder'}
>>> assert node.jsonData() == {'text': 'a', 'state': {'opened': True}, 'id': 5, 'li_attr': {'id': 5}, 'icon': 'folder'}
class galaxy.util.jstree.JSTree(paths, **kwargs)[source]

Bases: dictobj.DictionaryObject

An immutable dictionary-like object that converts a list of “paths” into a tree structure suitable for jQuery’s jsTree.

__init__(paths, **kwargs)[source]

Take a list of paths and put them into a tree. Paths with the same prefix should be at the same level in the tree.

kwargs may be standard jsTree options used at all levels in the tree. These will be outputted in the JSON.

pretty(root=None, depth=0, spacing=2)[source]

Create a “pretty print” represenation of the tree with customized indentation at each level of the tree.


Returns a copy of the internal tree in a JSON-friendly format, ready for consumption by jsTree. The data is represented as a list of dictionaries, each of which are our internal nodes.

galaxy.util.lazy_process module

class galaxy.util.lazy_process.LazyProcess(command_and_args)[source]

Bases: object

Abstraction describing a command line launching a service - probably as needed as functionality is accessed in Galaxy.

class galaxy.util.lazy_process.NoOpLazyProcess[source]

Bases: object

LazyProcess abstraction meant to describe potentially optional services, in those cases where one is not configured or valid, this class can be used in place of LazyProcess.


galaxy.util.monitors module

class galaxy.util.monitors.Monitors[source]

Bases: object


galaxy.util.object_wrapper module

Classes for wrapping Objects and Sanitizing string output.

galaxy.util.object_wrapper.coerce(x, y)[source]
galaxy.util.object_wrapper.cmp(x, y)[source]
galaxy.util.object_wrapper.sanitize_lists_to_string(values, valid_characters={'Z', 'I', '0', '^', 'V', 'P', 'h', 'v', 'w', 'Q', '1', '*', 'b', '3', 'F', 'u', 'x', 'n', 'O', '+', '.', 'e', 'W', 's', 'H', 'X', '=', 'c', 'k', 'o', '6', 'G', 'Y', '-', 'N', '@', 'K', 't', 'r', 'T', '9', 'A', 'C', 'D', 'E', ' ', '(', 'S', 'p', 'd', '!', 'm', 'q', 'U', 'R', '2', ')', 'M', 'a', '5', ', ', 'g', 'z', 'f', 'J', '4', '7', 'i', 'L', '_', 'y', 'l', '8', ':', 'B', '?', 'j', '/'}, character_map={'\t': '__tc__', '\n': '__cn__', '\r': '__cr__', '"': '__dq__', '#': '__pd__', "'": '__sq__', '<': '__lt__', '>': '__gt__', '[': '__ob__', ']': '__cb__', '{': '__oc__', '}': '__cc__'}, invalid_character='X')[source]
galaxy.util.object_wrapper.wrap_with_safe_string(value, no_wrap_classes=None)[source]

Recursively wrap values that should be wrapped.

class galaxy.util.object_wrapper.SafeStringWrapper(value, safe_string_wrapper_function=<function wrap_with_safe_string>)[source]

Bases: object

Class that wraps and sanitizes any provided value’s attributes that will attempt to be cast into a string.

Attempts to mimic behavior of original class, including operands.

To ensure proper handling of e.g. subclass checks, the wrap_with_safe_string() method should be used.

This wrapping occurs in a recursive/parasitic fashion, as all called attributes of the originally wrapped object will also be wrapped and sanitized, unless the attribute is of a type found in __DONT_SANITIZE_TYPES__ + __DONT_WRAP_TYPES__, where e.g. ~(strings will still be sanitized, but not wrapped), and e.g. integers will have neither.

__init__(value, safe_string_wrapper_function=<function wrap_with_safe_string>)[source]
class galaxy.util.object_wrapper.CallableSafeStringWrapper(value, safe_string_wrapper_function=<function wrap_with_safe_string>)[source]

Bases: galaxy.util.object_wrapper.SafeStringWrapper


galaxy.util.odict module

Ordered dictionary implementation with insert functionality.

This is only used in one specific place in the codebase:

Whenever possible the stdlib collections.OrderedDict should be used instead of this custom implementation.

class galaxy.util.odict.odict(dict=None)[source]

Bases: collections.UserDict

This dictionary class extends UserDict to record the order in which items are added. Calling keys(), values(), items(), etc. will return results in this order.

setdefault(key, failobj=None)[source]
insert(index, key, item)[source]

galaxy.util.oset module

Ordered set implementation from

class galaxy.util.oset.OrderedSet(iterable=None)[source]



galaxy.util.permutations module

There is some shared logic between matching/multiplying inputs in workflows and tools. This module is meant to capture some general permutation logic that can be applicable for both cases but will only be used in the newer tools case first.

Maybe this doesn’t make sense and maybe much of this stuff could be replaced with itertools product and permutations. These are open questions.

exception galaxy.util.permutations.InputMatchedException(err_msg=None, type='info', **extra_error_info)[source]

Bases: galaxy.exceptions.MessageException

Indicates problem matching inputs while building up inputs permutations.

galaxy.util.permutations.expand_multi_inputs(inputs, classifier, key_filter=None)[source]

galaxy.util.plugin_config module

class galaxy.util.plugin_config.PluginConfigSource(type, source)

Bases: tuple


Alias for field number 1


Alias for field number 0

galaxy.util.plugin_config.plugins_dict(module, plugin_type_identifier)[source]

Walk through all classes in submodules of module and find ones labelled with specified plugin_type_identifier and throw in a dictionary to allow constructions from plugins by these types later on.

galaxy.util.plugin_config.load_plugins(plugins_dict, plugin_source, extra_kwds=None, plugin_type_keys=('type', ))[source]
galaxy.util.plugin_config.plugin_source_from_dict(as_dict)[source] module

Module used to blend ini, environment, and explicit dictionary properties to determine application configuration. Some hard coded defaults for Galaxy but this should be reusable by tool shed and pulsar as well., exts=None, dirs=None, include_samples=False)[source]

Locate a config file in multiple directories, with multiple extensions.

>>> from shutil import rmtree
>>> from tempfile import mkdtemp
>>> def touch(d, f):
...     open(os.path.join(d, f), 'w').close()
>>> def _find_config_file(*args, **kwargs):
...     return find_config_file(*args, **kwargs).replace(d, '')
>>> d = mkdtemp()
>>> d1 = os.path.join(d, 'd1')
>>> d2 = os.path.join(d, 'd2')
>>> os.makedirs(d1)
>>> os.makedirs(d2)
>>> touch(d1, 'foo.ini')
>>> touch(d1, '')
>>> touch(d1, 'baz.ini.sample')
>>> touch(d2, 'foo.yaml')
>>> touch(d2, 'baz.yml')
>>> _find_config_file('foo', dirs=(d1, d2))
>>> _find_config_file('baz', dirs=(d1, d2))
>>> _find_config_file('baz', dirs=(d1, d2), include_samples=True)
>>> _find_config_file('baz', dirs=(d1,), include_samples=True)
>>> _find_config_file('foo', dirs=(d2, d1))
>>> find_config_file('quux', dirs=(d,))
>>> _find_config_file('foo', exts=('bar', 'ini'), dirs=(d1,))
>>> rmtree(d), ini_file=None, ini_section=None, config_file=None, config_section=None, config_prefix='GALAXY_CONFIG_')[source]
class, *args, **kw)[source]

Bases: configparser.ConfigParser

__init__(filename, *args, **kw)[source]
read_file(f, source=None)

Like read() but the argument must be a file-like object.

The `f’ argument must be iterable, returning one line at a time. Optional second argument is the `source’ specifying the name of the file being read. If not given, it is taken from If `f’ has no `name’ attribute, `<???>’ is used.


Return the defaults, with their values interpolated (with the defaults dict itself)

Mainly to support defaults using values such as %(here)s

class InterpolateWrapper(original)[source]

Bases: object

before_get(parser, section, option, value, defaults)[source][source]

galaxy.util.renamed_temporary_file module

Safely write file to temporary file and then move file into place.

class galaxy.util.renamed_temporary_file.RenamedTemporaryFile(final_path, **kwargs)[source]

Bases: object

A temporary file object which will be renamed to the specified path on exit.

__init__(final_path, **kwargs)[source]
>>> dir = tempfile.mkdtemp()
>>> with RenamedTemporaryFile(os.path.join(dir, 'test.txt'), mode="w") as out:
...     _ = out.write('bla')

galaxy.util.rules_dsl module

galaxy.util.rules_dsl.apply_regex(regex, target, data, replacement=None, group_count=None)[source]
class galaxy.util.rules_dsl.BaseRuleDefinition[source]

Bases: object


Short string describing type of rule (plugin class) to use.


Validate dictified rule definition of this type.

apply(rule, data, sources)[source]

Apply validated, dictified rule definition to supplied data.

class galaxy.util.rules_dsl.AddColumnMetadataRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_metadata'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddColumnGroupTagValueRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_group_tag_value'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddColumnConcatenateRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_concatenate'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddColumnBasenameRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_basename'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddColumnRegexRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_regex'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddColumnRownumRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_rownum'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddColumnValueRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_value'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddColumnSubstrRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_column_substr'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.RemoveColumnsRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'remove_columns'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddFilterRegexRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_filter_regex'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddFilterCountRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_filter_count'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddFilterEmptyRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_filter_empty'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddFilterMatchesRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_filter_matches'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.AddFilterCompareRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'add_filter_compare'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.SortRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'sort'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.SwapColumnsRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'swap_columns'
apply(rule, data, sources)[source]
class galaxy.util.rules_dsl.SplitColumnsRuleDefinition[source]

Bases: galaxy.util.rules_dsl.BaseRuleDefinition

rule_type = 'split_columns'
apply(rule, data, sources)[source]
galaxy.util.rules_dsl.flat_map(f, items)[source]
class galaxy.util.rules_dsl.RuleSet(rule_set_as_dict)[source]

Bases: object

apply(data, sources)[source]

alias of galaxy.util.rules_dsl.SplitColumnsRuleDefinition

galaxy.util.sanitize_html module

HTML Sanitizer (lists of acceptable_* ripped from feedparser)

galaxy.util.sanitize_html.sanitize_html(htmlSource, allow_data_urls=False)[source]

galaxy.util.script module

Utilities for Galaxy scripts

galaxy.util.script.main_factory(description=None, actions=None, arguments=None, default_action=None)[source]

Entry point for conversion process.

galaxy.util.script.app_properties_from_args(args, legacy_config_override=None, app=None)[source]
galaxy.util.script.config_file_from_args(args, legacy_config_override=None, app=None)[source]

galaxy.util.simplegraph module

Fencepost-simple graph structure implementation.

class galaxy.util.simplegraph.SimpleGraphNode(index, **data)[source]

Bases: object

Node representation.

__init__(index, **data)[source]
  • index (int) – index of this node in some parent list
  • data ((variadic dictionary)) – any extra data that needs to be saved
class galaxy.util.simplegraph.SimpleGraphEdge(source_index, target_index, **data)[source]

Bases: object

Edge representation.

__init__(source_index, target_index, **data)[source]
  • source_index (int) – index of the edge’s source node in some parent list
  • target_index (int) – index of the edge’s target node in some parent list
  • data ((variadic dictionary)) – any extra data that needs to be saved
class galaxy.util.simplegraph.SimpleGraph(nodes=None, edges=None)[source]

Bases: object

Each node is unique (by id) and stores its own index in the node list/odict. Each edge is represented as two indeces into the node list/odict. Both nodes and edges allow storing extra information if needed.

multiple edges between two nodes self referential edges (an edge from a node to itself)

These graphs are not specifically directed but since source and targets on the edges are listed - it could easily be used that way.

__init__(nodes=None, edges=None)[source]
add_node(node_id, **data)[source]

Adds a new node only if it doesn’t already exist. :param node_id: some unique identifier :type node_id: (hashable) :param data: any extra data that needs to be saved :type data: (variadic dictionary) :returns: the new node

add_edge(source_id, target_id, **data)[source]

Adds a new node only if it doesn’t already exist. :param source_id: the id of the source node :type source_id: (hashable) :param target_id: the id of the target node :type target_id: (hashable) :param data: any extra data that needs to be saved for the edge :type data: (variadic dictionary) :returns: the new node

..note: that, although this will create new nodes if necessary, there’s no way to pass data to them - so if you need to assoc. more data with the nodes, use add_node first.

Returns a generator that yields node dictionaries in the form:
{ ‘id’: <the nodes unique id>, ‘data’: <any additional node data> }

Returns a generator that yields node dictionaries in the form:

    'source': <the index of the source node in the graph's node list>,
    'target': <the index of the target node in the graph's node list>,
    'data'  : <any additional edge data>

Returns a dictionary of the form:

{ 'nodes': <a list of node dictionaries>, 'edges': <a list of node dictionaries> }

galaxy.util.sleeper module

class galaxy.util.sleeper.Sleeper[source]

Bases: object

Provides a ‘sleep’ method that sleeps for a number of seconds unless the notify method is called (from a different thread).


galaxy.util.sockets module


galaxy.util.specs module


galaxy.util.sqlite module


galaxy.util.streamball module

A simple wrapper for writing tarballs as a stream.

class galaxy.util.streamball.StreamBall(mode, members=None)[source]

Bases: object

__init__(mode, members=None)[source]
add(file, relpath, check_file=False)[source]
stream(environ, start_response)[source]
class galaxy.util.streamball.ZipBall(tmpf, tmpd)[source]

Bases: object

__init__(tmpf, tmpd)[source]
stream(environ, start_response)[source]
galaxy.util.streamball.stream_archive(trans, path, upstream_gzip=False)[source]

galaxy.util.submodules module

galaxy.util.submodules.import_submodules(module, ordered=True, recursive=False)[source]

Import all submodules of a module

  • module (str | module) – module (package name or actual module)
  • ordered (bool) – Whether to order the returned modules. The default is True, and modules are returned in reverse order to allow hierarchical overrides i.e.,,
  • recursive (bool) – Recursively returns all subpackages
Return type:


galaxy.util.template module

Entry point for the usage of Cheetah templating within Galaxy.

class galaxy.util.template.FixedModuleCodeCompiler(source=None, file=None, moduleName='DynamicallyCompiledCheetahTemplate', mainClassName=None, mainMethodName=None, baseclassName=None, extraImportStatements=None, settings=None)[source]

Bases: Cheetah.Compiler.ModuleCompiler

module_code = None
galaxy.util.template.fill_template(template_text, context=None, retry=10, compiler_class=<class 'Cheetah.Compiler.ModuleCompiler'>, first_exception=None, futurized=False, python_template_version='3', **kwargs)[source]

Fill a cheetah template out for specified context.

If template_text is None, an exception will be thrown, if context is None (the default) - keyword arguments to this function will be used as the context.


galaxy.util.tool_version module


Removes version from toolshed-derived tool_id(=guid).

galaxy.util.topsort module

Topological sort.

From Tim Peters, see:

topsort takes a list of pairs, where each pair (x, y) is taken to mean that x <= y wrt some abstract partial ordering. The return value is a list, representing a total ordering that respects all the input constraints. E.g.,

topsort( [(1,2), (3,3)] )

Valid topological sorts would be any of (but nothing other than)

[3, 1, 2] [1, 3, 2] [1, 2, 3]

… however this variant ensures that ‘key’ order (first element of tuple) is preserved so the following will be result returned:

[1, 3, 2]

because those are the permutations of the input elements that respect the “1 precedes 2” and “3 precedes 3” input constraints. Note that a constraint of the form (x, x) is really just a trick to make sure x appears somewhere in the output list.

If there’s a cycle in the constraints, say

topsort( [(1,2), (2,1)] )

then CycleError is raised, and the exception object supports many methods to help analyze and break the cycles. This requires a good deal more code than topsort itself!

exception galaxy.util.topsort.CycleError(sofar, numpreds, succs)[source]

Bases: Exception

__init__(sofar, numpreds, succs)[source]

galaxy.util.ucsc module

Utilities for dealing with UCSC data.

exception galaxy.util.ucsc.UCSCLimitException[source]

Bases: Exception

class galaxy.util.ucsc.UCSCOutWrapper(other)[source]

Bases: object

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


galaxy.util.validation module

Module for validation of incoming inputs.

TODO: Refactor BaseController references to similar methods to use this module.

galaxy.util.validation.validate_and_sanitize_basestring(key, val)[source]
galaxy.util.validation.validate_and_sanitize_basestring_list(key, val)[source]
galaxy.util.validation.validate_boolean(key, val)[source]

galaxy.util.watcher module

galaxy.util.watcher.get_observer_class(config_name, config_value, default, monitor_what_str)[source]
galaxy.util.watcher.get_watcher(config, config_name, default='False', monitor_what_str=None, watcher_class=None, event_handler_class=None, **kwargs)[source]
class galaxy.util.watcher.BaseWatcher(observer_class, even_handler_class, **kwargs)[source]

Bases: object

__init__(observer_class, even_handler_class, **kwargs)[source]
monitor(dir_path, recursive=False)[source]
class galaxy.util.watcher.Watcher(observer_class, event_handler_class, **kwargs)[source]

Bases: galaxy.util.watcher.BaseWatcher

__init__(observer_class, event_handler_class, **kwargs)[source]
watch_file(file_path, callback=None)[source]
watch_directory(dir_path, callback=None, recursive=False, ignore_extensions=None, require_extensions=None)[source]
class galaxy.util.watcher.EventHandler(watcher)[source]


class galaxy.util.watcher.NullWatcher[source]

Bases: object

watch_file(*args, **kwargs)[source]
watch_directory(*args, **kwargs)[source]

galaxy.util.web_compat module

Work around for gross circular dependency between galaxy.util and galaxy.web_stack.

Provide a function that will delay to forking in a uwsgi environment but run immediately otherwise.

galaxy.util.xml_macros module


Load XML documentation from file system and preprocesses XML macros.

Return the XML representation of the expanded tree and paths to referenced files that were imported (macros).


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


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


galaxy.util.yaml_util module

class galaxy.util.yaml_util.OrderedLoader(stream)[source]

Bases: yaml.loader.SafeLoader

galaxy.util.yaml_util.ordered_load(stream, merge_duplicate_keys=False)[source]

Parse the first YAML document in a stream and produce the corresponding Python object, using OrderedDicts instead of dicts.

If merge_duplicate_keys is True, merge the values of duplicate mapping keys into a list, as the uWSGI “dumb” YAML parser would do. Otherwise, following YAML 1.2 specification which says that “each key is unique in the association”, raise a ConstructionError exception.

galaxy.util.yaml_util.ordered_dump(data, stream=None, Dumper=<class 'yaml.dumper.Dumper'>, **kwds)[source]