### Navigation

- index
- modules |
- next |
- previous |
- SamSifter 0.5.4 documentation »
- SamSifter API documentation »
- samsifter package »

# samsifter.models package

Models of entities involved in SamSifter workflows.

This package includes classes modeling entities such as

- tools/filters
- parameters for these tools
- lists and trees of tools
- entire workflows

that are used as data models for the SamSifter GUI.

## filter module

Abstraction of filters and other tools usable in POSIX pipelines.

class `FilterItem`(text=None, desc=None, icon=':/view-filter.png')

  Bases: `PyQt4.QtGui.QStandardItem`

  Representation of filter tool in item-based views.

  This class can abstract any tool that takes line-based input from STDIN, logs messages to STDERR and writes output to STDOUT. It is used to represent this tool in item-based views by means of an icon and descriptive text.

  Each item has a list of parameters as well as input and output requirements in terms file format, sort order and compression.

  `ICON_ANALYZER` = ':/x-office-spreadsheet.png'
  `ICON_CONVERTER` = ':/applications-other.png'
  `ICON_FILTER` = ':/view-filter.png'
  `ICON_SORTER` = ':/view-sort-ascending.png'
  `add_parameter`(parameter)

    Append parameter to list of parameters.

    Parameters: | parameter (FilterParameter) – Parameter to be added to this filter.

  `clone`()

    Creates new instance with identical settings.

    Returns: | Exact clone of this filter item.
    Return type: | FilterItem

  `commandline`(basenames=False)

    Prints full bash command line for filter with all parameters.

    Parameters: | basenames (bool) – Shorten file paths to filename only, defaults to False.
    Returns: | Command to execute filter with all parameters.
    Return type: | str

  `get_description`()
  `get_icon_path`()
  `get_input_compression`()
  `get_input_format`()
  `get_input_sorting`()
  `get_output_compression`()
  `get_output_format`()
  `get_output_sorting`()
  `get_parameters`()
  `is_valid`()
  `make_widget`()

    Creates a FilterWidget visualizing all parameters of this filter.

    Returns: | Qt4 widget visualizing all parameters of this filter.
    Return type: | FilterWidget

  `set_command`(command)
  `set_description`(desc)
  `set_icon_path`(icon_path)
  `set_input_compression`(compression)
  `set_input_format`(fileformat)
  `set_input_sorting`(sorting)
  `set_output_compression`(compression)
  `set_output_format`(fileformat)
  `set_output_sorting`(sorting)
  `set_valid`(boolean)

## filter_model module

Filter models for trees and lists.

Implementations of the standard Qt4 item-based models for trees (2 dimensions) and lists (1 dimension).

Warning

Drag&Drop is not fully implemented due to restrictions on the binary encoding of C++ objects using Python’s `pickle`. Pickling support is required to encode filter items to MIME on initiation of a drag event as well as to decode an item from MIME at the end of a drop event. However this would require the implementation of (de)serialization methods for the entire hierarchy of PyQt-wrapped C++ classes that are used in this project and currently don’t support `pickle`.

Thus, I have decided to simply override the double-click behaviour on filter items to emulate the drag&drop action with a similarly intuitive click&clone action. See `samsifter.models.filter.FilterItem.clone()` and `samsifter.samsifter.MainWindow.init_ui()` for details.

class `FilterListModel`(parent=None)

  Bases: `PyQt4.QtCore.QAbstractListModel`

  One-dimensional list model for filter items.

  Represents data as a simple non-hierarchical sequence of items.

  `__repr__`()

    String representation of model for debugging.

  `data`(index, role=0)

    Supplies item data to views and delegates.

    Generally, models only need to supply data for Qt.DisplayRole and any application-specific Qt.AccessibleTextRole, and Qt.AccessibleDescriptionRole. See the Qt.ItemDataRole enum documentation for information about the types associated with each role.

    Implements abstract Qt4 base method.

    Parameters: | index (QModelIndex) – Model index of requested content item. role (int) – Qt item data role, defaults to DisplayRole.
    Returns: | any – Depending on model data and requested role. None – If index is invalid.

  `flags`(index)

    Provides view with Qt flags for item at given index.

    Must return an appropriate combination of flags for each item. In particular, the value returned by this function must include Qt::ItemIsEditable in addition to the values applied to items in a read-only model.

    Used by other components to obtain information about each item provided by the model. In many models, the combination of flags should include Qt::ItemIsEnabled and Qt::ItemIsSelectable.

    Implements abstract Qt4 method.

    Parameters: | index (QModelIndex) – Model index of requested item.
    Returns: | Combination of bit flags for item properties.
    Return type: | int

  `index`(row, col=0, parent=<PyQt4.QtCore.QModelIndex object at 0x7f384a752898>)

    Returns the index of the specified model item.

    Implements abstract Qt4 base method.

    Parameters: | row (int) – Model row. col (int, optional) – Model column, defaults to 0 (list only has one column). parent (QModelIndex, optional) – Model index of parent item, defaults to invalid QModelIndex.
    Returns: | Model index of specified item (invalid if non-existant).
    Return type: | QModelIndex

  `insertItem`(item, row=None)

    Insert filter item at specified position or append at end.

    Implements abstract Qt4 base method.

    Parameters: | item (FilterItem) – Item to be inserted. row (int, optional) – Target row, defaults to None resulting in insertion at the end.
    Returns: | True on success.
    Return type: | bool

  `item_changed`
  `iterate_items`()

    Provides a lazy iterator over all filter items.

    Yields: | FilterItem – The next filter item in the model.

  `removeAll`(parent=<PyQt4.QtCore.QModelIndex object at 0x7f384a7529e8>)

    Remove all rows.

    Implements abstract Qt4 base method.

    Parameters: | parent (QModelIndex, optional) – Parent of the item to be removed, defaults to invalid index.
    Returns: | True on success.
    Return type: | bool

  `removeRow`(row, parent=<PyQt4.QtCore.QModelIndex object at 0x7f384a752978>)

    Remove a single row.

    Implements abstract Qt4 base method.

    Parameters: | row (int) – Start row of the range to be removed. parent (QModelIndex, optional) – Parent of the item to be removed, defaults to invalid index.
    Returns: | True on success, False on valid index or invalid row number.
    Return type: | bool

  `removeRows`(row, count, parent=<PyQt4.QtCore.QModelIndex object at 0x7f384a752828>)

    Remove several rows at once.

    Used to remove rows and the items of data they contain from all types of model. Implementations must call beginRemoveRows() before inserting new columns into any underlying data structures, and call endRemoveRows() immediately afterwards.

    Implements abstract Qt4 base method.

    Parameters: | row (int) – Start row of the range to be removed. count (int) – Number of rows to be removed including the start row. parent (QModelIndex, optional) – Parent of the item to be removed, defaults to invalid index.
    Returns: | True on success, False on valid index or invalid row number.
    Return type: | bool

  `rowCount`(parent=<PyQt4.QtCore.QModelIndex object at 0x7f384a752a58>)

    Provides the number of rows of data exposed by the model.

    Implements abstract Qt4 base method.

    Returns: | Number of items (= rows) in model.
    Return type: | int

  `supportedDragActions`()

    Drag actions supported by the model.

    Used to return a combination of drop actions, indicating the types of drag and drop operations that the model accepts.

    Overrides Qt4 base method.

    Returns: | Combination of Qt drag actions (bit flags).
    Return type: | int

  `supportedDropActions`()

    Drop actions supported by the model.

    Used to return a combination of drop actions, indicating the types of drop operations that the model accepts.

    Overrides Qt4 base method.

    Returns: | Combination of Qt drop actions (bit flags).
    Return type: | int

  `takeItem`(row=None)

    Retrieves item and remove corresponding row.

    Implements abstract Qt4 base method.

    Parameters: | row (int, optional) – Target row, defaults to None resulting in deletion from the end.
    Returns: | None – If given row is smaller or larger than model. FilterItem – Requested filter item.

class `FilterTreeModel`(parent=None)

  Bases: `PyQt4.QtGui.QStandardItemModel`

  Item-based two-dimensional model for filter items.

  Can represent hierarchical and sequential data by implementing the QAbstractItemModel.

  `iterate_items`()

    Provides a lazy iterator over all filter items.

    Yields: | FilterItem – Next filter item in model.

  `supportedDragActions`()

    Drag actions supported by the model.

    Used to return a combination of drop actions, indicating the types of drag and drop operations that the model accepts.

    Overrides Qt4 base method.

    Returns: | Qt drag action.
    Return type: | int

## parameter module

Different types of command line parameters.

class `FilterFilepath`(text, desc, cli_name, default, extensions=['csv'], readable=True, writable=False, value=None, required=False, active=False)

  Bases: `samsifter.models.parameter.FilterParameter`

  Parameter setting filepath for input or output file.

  Extends parameter base class with a list of supported file extensions and requirements for read and write access.

  `__repr__`()

    Representation of this parameter for debugging.

    Extends base method with additional attributes.

  `cli`(basenames=False)

    Representation of this parameter on command line interface.

    Overrides base method to handle option for shortened filepaths.

    Parameters: | basenames (bool, optional) – Shorten file paths to filename only, defaults to False.
    Returns: | Full command line argument for this parameter with optionally shortened filenames.
    Return type: | str

  `clone`()

    Create new instance with identical settings.

    Returns: | An exact copy of this instance.
    Return type: | FilterParameter

  `get_extensions`()
  `set_extensions`(extensions)
  `set_value`(value)

    Set parameter value.

    Overrides base method to active parameter only when value has changed.

class `FilterParameter`(text, desc, cli_name, default, value=None, required=False, active=False)

  Bases: `builtins.object`

  Abstraction of a general command line argument for standalone filters.

  Serves as base class for thresholds and filepath arguments.

  `__repr__`()

    Representation of this parameter for debugging.

  `__str__`()

    String representation of this parameter.

  `cli`(basenames=False)

    Representation of this parameter on command line interface.

  `clone`()

    Create new instance with identical settings.

    Returns: | Exact clone of this parameter.
    Return type: | FilterParameter

  `get_cli_name`()
  `get_default`()
  `get_description`()
  `get_form_text`()

    Representation of this parameter in form layouts.

  `get_value`()
  `is_active`()
  `is_required`()
  `set_active`(active=True)

    Activate parameter to force showing it on the commandline.

  `set_cli_name`(cli_name)
  `set_default`(default)
  `set_description`(desc)
  `set_required`(required=True)
  `set_value`(value)

class `FilterSwitch`(text, desc, cli_name, default, options=[True, False], value=None, required=False, active=False)

  Bases: `samsifter.models.parameter.FilterParameter`

  Command line switch for a list of exclusive options.

  Extends base class with a list of selectable options. Defaults to a simple binary switch between True and False.

  `__repr__`()

    Representation of this parameter for debugging.

    Extends base method with additional attributes.

  `cli`(basenames=False)

    Representation of this parameter on command line interface.

    Overrides base method to handle unset values.

  `clone`()

    Create new instance with identical settings.

    Returns: | An exact copy of this instance.
    Return type: | FilterSwitch

  `get_option`(index)

    Get specific option out of the available options.

    Parameters: | index (int) – Index of option in list of options.
    Returns: | Desired option (or None on invalid index)
    Return type: | str

  `get_options`()
  `set_options`(options)
  `set_value`(value)

    Set parameter value.

    Overrides base method to active parameter only when value has changed.

class `FilterThreshold`(text, desc, cli_name, default=5.0, minimum=0.0, maximum=100.0, precision=2, unit=None, value=None, required=False, active=False)

  Bases: `samsifter.models.parameter.FilterParameter`

  Abstraction of a numerical command line parameter used as treshold.

  Extends filter parameter by minimum and maximum of permitted value range with variable precision and optional unit.

  `__repr__`()

    Representation of this parameter for debugging.

    Extends base method with additional attributes.

  `cli`(basenames=False)

    Representation of this parameter on command line interface.

    Overrides base method to handle unset values.

  `clone`()

    Create new instance with identical settings.

    Returns: | Exact clone of this parameter.
    Return type: | FilterThreshold

  `get_form_text`()

    Representation of this parameter in form layouts.

    Overrides base method and provides additional information on unit.

  `get_maximum`()
  `get_minimum`()
  `get_precision`()
  `get_unit`()
  `set_maximum`(maximum)
  `set_minimum`(minimum)
  `set_precision`(precision)
  `set_unit`(unit)
  `set_value`(value)

    Set value of parameter.

    Overriding base class to consider value precision.

## workflow module

Abstraction of workflows with input, tool pipeline and output.

class `Workflow`(parent=None)

  Bases: `PyQt4.QtCore.QObject`

  Container object for workflow related data.

  Takes care of serialization and validation using specialized objects.

  `__repr__`()

    Representation of workflow for debugging purposes.

  `__str__`()

    String representation of workflow.

    Returns: | Hyphenated multiline commandline to run workflow.
    Return type: | str

  `changed`
  `clear`()

    Empties the workflow from all filenames and filter steps.

  `commandline`(hyphenated=False, multiline=False, batch=False, basenames=False)

    Creates Bash-compatible commandline for entire workflow.

    Parameters: | hyphenated (bool, optional) – Enable hyphenation of entire commandline for use within variables evaluated by eval command; defaults to False. multiline (bool, optional) – Break long lines after each individual step of the workflow to improve readability; defaults to False. batch (bool, optional) – Enable use of variables that can be evaluated within code blocks like for loops or functions; defaults to False. basenames (bool, optional) – Shorten file paths to filename only; defaults to False.
    Returns: | Commandline to be run in Bash or subprocess.
    Return type: | str

  static `formats`()

    Lists supported file formats for saving and loading.

    Returns: | List of file extensions with leading asterisk, eg. `*.ssx`.
    Return type: | list of str

  `getModel`()
  `get_filename`()
  `get_in_filename`()
  `get_out_filename`()
  `get_run_compile_stats`()
  `get_run_sam2rma`()
  `infile_is_valid`()
  `input_changed`
  `is_dirty`()
  `is_valid`()
  `list_changed`
  `load`(filename)

    Load from file using XML deserialization.

    Parameters: | filename (str, optional) – Readable path to existing workflow file.
    Returns: | bool – True if successful, otherwise False. str – Error or success message.

  `on_change`(item)

    Handle change of workflow model.

  `on_insert`(mdlidx, start, end)

    Handle insertion of items into workflow model.

  `on_remove`(mdlidx, start, end)

    Handle removal of items from workflow model.

  `outfile_is_valid`()
  `output_changed`
  `save`(filename=None)

    Saves file and picks filetype depending on extension.

    Note

    Currently redundant as only XML output is supported since binary output was dropped.

    Parameters: | filename (str, optional) – Writable path of new workflow file.
    Returns: | bool – True if successful, otherwise False. str – Error or success message.

  `save_xml`()

    Save to file using XML serialization.

    Returns: | bool – True if successful, otherwise False. str – Error or success message.

  `set_dirty`(dirty=True)
  `set_filename`(filename)
  `set_in_filename`(filename)
  `set_infile_valid`(valid=True)
  `set_out_filename`(filename)
  `set_outfile_valid`(valid=True)
  `set_run_compile_stats`(button_state)
  `set_run_sam2rma`(button_state)
  `set_valid`(valid=True)
  `to_bash`(filename, bash_options=<samsifter.gui.dialogs.BashOptions object at 0x7f384a4219e8>, rma_options=<samsifter.gui.dialogs.RmaOptions object at 0x7f384a421a58>)

    Write Bash script with optional batch processing capability.

    The batch variants take filenames as arguments while the standard call processes only the explicitly set input file.

    Parameters: | filename (str) – Writable path of new bash script. bash_options (BashOptions, optional) – Bash options object, defaults to new instance. rma_options (RmaOptions, optional) – SAM2RMA options object, defaults to new instance.

  `to_xml_string`()

    Represent workflow as XML tree.

    Returns: | Pretty XML string representing entire workflow structure.
    Return type: | str

  `validity_changed`

### Navigation

- index
- modules |
- next |
- previous |
- SamSifter 0.5.4 documentation »
- SamSifter API documentation »
- samsifter package »