cadnano.util module

beginSuperMacro(model_object, desc=None)

SuperMacros can be used to nest multiple command lists.

Normally execCommandList macros all the commands in a list. In some cases, multiple command lists need to be executed separately because of dependency issues. (e.g. in part.autoStaple, strands must be completely 1. created and 2. split before 3. xover installation.)

clamp(x, min_x, max_x)

Returns the complement of the sequence in seqStr.

doCmd(model_object, command, use_undostack)

Helper for pushing onto the undostack


Ends a SuperMacro. Should be called after beginSuperMacro.

execCommandList(model_object, commands, desc=None, use_undostack=True)

This is a wrapper for performing QUndoCommands, meant to ensure uniform handling of the undoStack and macro descriptions.

When using the undoStack, commands are pushed onto self.undoStack() as part of a macro with description desc. Otherwise, command redo methods are called directly.

finalizeCommands(model_object, commands, desc=None)

Used to enable interaction with the model but not push commands to the undostack. In practice:

  1. Call a bunch of commands and don’t push them to the undostack AKA:
  2. call finalizeCommands() to push the cummulative change to the stack

This assumes that the UndoCommands provided this function respresent a transition from the initial state to the final state


UndoCommands need to implement specialUndo (e.g. just call normal undo.)


When called when self is a QGraphicsItem, iterates through self’s childItems(), placing a red rectangle (a sibling of self) around each item in sequence (press return to move between items). Since the index of each child item is displayed as it is highlighted, one can use findChild() to quickly get a reference to one of self’s children. At each step, one can type a command letter before hitting return. The command will apply to the current child. Command Letter: Action: <return> Advance to next child s<return> Show current child S<return> Show current child, hide siblings h<return> Hide current child r<return> return current child

init_logging(args=None, logdir=None)

Set up standard logging system based on parameters in args, e.g. loglevel and testing.


Returns True if platform is detected as Linux, otherwise False


Returns True if platform is detected as Darwin, otherwise False


Returns True if platform is detected as Windows, otherwise False


Returns string containing name of the calling method.

nearest(a, l)

Gets rid of non-letters in a string.

overlap(x, y, a, b)

Finds the overlap of (x, y) and (a, b). Assumes an overlap exists, i.e. y >= a and b >= x.

parse_args(argv=None, gui=None)

Uses argparse to process commandline arguments.

Returns:NameSpace object. This can easily be converted to a regular dict through – argns.__dict__
This also presents a nice command line help to the user, exposed with –help flag:
python –help

If gui is set to “qt”, then the parser will use parse_known_args. Unlike parse_args(), parse_known_args() will not cause abort by show the help message and exit, if it finds any unrecognized command-line arguments.

Alternatively, you can initialize your app via:
app = QApplication(sys.argv) parse_args(app.arguments())

QApplication.arguments() returns a list of arguments with all Qt arguments stripped away. Qt command line args include:

-style=<style> -stylesheet=<stylesheet> -widgetcount -reverse -qmljsdebugger -session=<session>

Returns the reverse complement of the sequence in seqStr.


Returns a stack trace n frames deep


Returns a list of plugin paths that have yet to be loaded but are in the top level of one of the search directories specified in pluginDirs