EggLib
EggLib version 2.1 is archived.

Previous topic

fitmodel

Next topic

test

This Page

Utils module

Executable tools. This module defines the classes Option and BaseCommand that allow to develop automatically executable commands. A utilitary script egglib will load this module at runtime and let the user run any of this commands as if they were independent programs.

class egglib.utils.BaseCommand

Abstract base class for executable commands. Several members and function have to be overriden to provide all information needed by the egglib script.

brief = ''

This member must be overriden. One-line summary.

debug

Flag indicating whether full error messages should be returned.

description = ''

This member must be overriden. Full description.

flags = []

This member must be overriden. List of flag, each given as a tuple of two strings: (label, description).

options = []

This member must be overriden. List of Option instances.

process_cmdline_arguments(arguments)

Processes arguments; returns a (fargs, kwargs) tuple. Don’t change anything of the instance (i.e. don’t set anything). Don’t check anything.

quiet

Flag indicating whether information should be displayed in the standard output stream (if quiet is True, information is not displayed).

run(*fargs, **kwargs)

Execute commands. fargs are flag arguments and kwargs are keyword arguments.

class egglib.utils.Option(name, doc, convert=<type 'str'>, default=None, requirements=[])

Defines the type, default value and requirements of all program options (except flags that are dealt with otherwise).

name is the name of the option, doc must be a string providing documentation. convert should be a function taking a string and returning a value of the appropriate type (can also be classes such as int, float or lambda expressions, providing that they take a string and process it the appropriate way), default is the default value (None means that the option must be specified) and requirements is a list of requirements, each of them under the form of a function taking a possible option value and returning True is the option is valid.

egglib.utils.execute(*fargs, **fkwargs)

Execute utils commands. This functions takes arguments to specify the command name and its options. There must be at least one positional argument: the first positional argument gives the function name and other (optional) positional arguments give the command flags to be activated. The keyword arguments give the command options. Flag, option names but also option values should be string (option values will be converted automatically). In case options are of a simple type (int, float), they can be passed as such. But options that are described as a string presenting a list of values separated by commas CANNOT be passed as a list using the function. If there is no argument whatsoever, arguments will be read from sys.argv. In this case, the first argument will be ignored; the second argument must be the command name; and keyword arguments must be passed under the form key=value where key is the option name.

For example, running the command:

egglib ungap input=file1.fas output=file2.fas threshold=0.5 triplets

is the equivalent of calling the function:

>>> egglib.utils.execute('ungap', 'triplets', input='file1.fas', output='file2.fas', threshold=0.5)

where threshold can also take the string "0.5".

Hosted by  Get seqlib at SourceForge.net. Fast, secure and Free Open Source software downloads