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.
Abstract base class for executable commands. Several members and function have to be overriden to provide all information needed by the egglib script.
This member must be overriden. One-line summary.
Flag indicating whether full error messages should be returned.
This member must be overriden. Full description.
This member must be overriden. List of flag, each given as a tuple of two strings: (label, description).
Processes arguments; returns a (fargs, kwargs) tuple. Don’t change anything of the instance (i.e. don’t set anything). Don’t check anything.
Flag indicating whether information should be displayed in the standard output stream (if quiet is True, information is not displayed).
Execute commands. fargs are flag arguments and kwargs are keyword arguments.
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.
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".