sfftkrw.core package

Parser module

parser.py

sfftkrw.core.parser.add_args(parser, the_arg)

Convenience function to add the_arg to the parser.

This relies on the argument being structured as a dictionary with the keys args for positional arguments and kwargs for the keyword arguments. The value of doing this is that arguments that are reused in several parsers can be referred to by a variable instead of being redefined.

Usage:

>>> my_arg = {'arg': ['-x'], 'kwargs': {'help': 'help'}}
>>> this_parser = argparse.ArgumentParser()
>>> add_args(this_parser, my_arg)
Parameters:
  • parser (argparse.ArgumentParser) – the parser to be modified
  • the_arg (dict) – the argument specified as a dict with keys args and kwargs
Returns:

a modified parser object

Return type:

argparse.ArgumentParser

sfftkrw.core.parser.parse_args(_args, use_shlex=False)

Parse and check command-line arguments.

This function does all the heavy lifting in ensuring that commandline arguments are properly formatted and checked for sanity.

In this way command handlers (defined in sfftk/sff.py e.g. handle_convert(...)) assume correct argument values and can concentrate on functionality.

Parameters:
  • _args (list or str or unicode) – list of arguments (use_shlex=False); string of arguments (use_shlex=True)
  • use_shlex (bool) – treat _args as a string instead for parsing using shlex lib
Returns:

parsed arguments

Return type:

argparse.Namespace

Printing utilities

Miscellaneous utilities

utils.py

A collection of helpful utilities

sfftkrw.core.utils.get_path(D, path)

Get a path from a dictionary

Parameters:
  • D (dict) – a dictionary
  • path (list) – an iterable of hashables
Returns:

the item at the path from the dictionary

sfftkrw.core.utils.get_unique_id()

Return an ID that will be unique over the current segmentation

Returns:unique_id
Return type:int
sfftkrw.core.utils.get_version(fn)

Gets the version from the EMDB-SFF file

Parameters:fn (bytes or unicode) – name of EMDB-SFF file
Returns:the version
Return type:unicode
sfftkrw.core.utils.rgba_to_hex(rgba, channels=3)

Convert RGB(A) iterable to a hex string (e.g. #aabbcc(dd)

Parameters:
  • rgba (list or tuple) – an iterable with normalised (values in the closed interval [0-1]) colour channel values
  • channels (int) – the number of channels (3 or 4); default 3
Returns:

a hex string

Return type:

str