cadnano.strandset.strandset module

class StrandSet(is_fwd, id_num, part, initial_size)

Bases: cadnano.cnobject.CNObject

StrandSet is a container class for Strands, and provides the several publicly accessible methods for editing strands, including operations for creation, destruction, resizing, splitting, and merging strands.

Views may also query StrandSet for information that is useful in determining if edits can be made, such as the bounds of empty space in which a strand can be created or resized.

Internally StrandSet uses redundant heap and a list data structures to track Strands objects, with the list of length of a virtual helix looking like:

strand_array = [strandA, strandA, strandA, ..., None, strandB, strandB, ...]

Where every index strandA spans has a reference to strandA and strand_heap:

strand_heap = [strandA, strandB, strandC, ...]

is merely a sorted list from low index to high index of strand objects

Parameters:
  • is_fwd (bool) – is this a forward or reverse StrandSet?
  • id_num (int) – ID number of the virtual helix this is on
  • part (Part) – Part object this is a child of
  • initial_size (int) – initial_size to allocate
complementStrandSet()

Returns the complementary strandset. Used for insertions and sequence application.

Returns:StrandSet – the complementary StrandSet
createDeserializedStrand(base_idx_low, base_idx_high, color, use_undostack=False)

Passes a strand to AddStrandCommand that was read in from file input. Omits the step of checking _couldStrandInsertAtLastIndex, since we assume that deserialized strands will not cause collisions.

createStrand(base_idx_low, base_idx_high, color=None, use_undostack=True)

Assumes a strand is being created at a valid set of indices.

Parameters:
  • base_idx_low (int) – low index of strand
  • base_idx_high (int) – high index of strand
  • color (str, optional) – default=True
  • use_undostack (bool, optional) – default=True
Returns:

int – 0 if successful, -1 otherwise

destroy()

Destroy this object

document()

Get model Document

Returns:Document – the Document
dump(xover_list)

Serialize a StrandSet, and append to a xover_list of xovers adding a xover if the 3 prime end of it is founds TODO update this to support strand properties

Parameters:xover_list (list) – A list to append xovers to
Returns:list of tuple – indices low and high of each strand in the StrandSet
getBoundsOfEmptyRegionContaining(base_idx)

Return the bounds of the empty region containing base index <base_idx>.

Parameters:base_idx (int) – the index of interest
Returns:tuple

of int of form:

(low_idx, high_idx)
getNeighbors(strand)

Given a Strand in this StrandSet find it’s internal neighbors

Parameters:strand (Strand) –
Returns:tuple – (low neighbor, high neighbor) of types Strand or None
getOverlappingStrands(idx_low, idx_high)

Gets Strand list that overlap the given range.

Parameters:
  • idx_low (int) – low index of overlap region
  • idx_high (int) – high index of overlap region
Returns:

list of Strand – all Strand objects in range

getStrand(base_idx)

Returns the Strand that overlaps with base_idx

Parameters:base_idx (int) –
Returns:StrandStrand at base_idx if it exists
getStrandIndex(strand)

Get the index of strand if it exists

Returns:tuple – (bool, int)
Raises:ValueError
hasStrandAt(idx_low, idx_high)

Check if set has a strand on the interval given

Parameters:
  • idx_low (int) – low index
  • idx_high (int) – high index
Returns:

bool – True if strandset has a strand in the region between idx_low and idx_high (both included). False otherwise

idNum()

Get the associated virtual helix ID number

Returns:int – virtual helix ID number
indexOfRightmostNonemptyBase()

Returns the high base_idx of the last strand, or 0.

isForward()

Is the set 5’ to 3’ (forward) or is it 3’ to 5’ (reverse)

Returns:bool – True if is forward, False otherwise
isReverse()
isStrandInSet(strand)
length()

length of the StrandSet and therefore also the associated virtual helix in bases

Returns:int – length of the set
mergeStrands(priority_strand, other_strand, use_undostack=True)

Merge the priority_strand and other_strand into a single new strand. The oligo of priority should be propagated to the other and all of its connections.

Parameters:
  • priority_strand (Strand) – priority strand
  • other_strand (Strand) – other strand
  • use_undostack (bool, optional) – default=True
oligoStrandRemover(strand, cmds, solo=True)

Used for removing all Strand`s from an :class:`Oligo

Parameters:
  • strand (Strand) – a strand to remove
  • cmds (list) – a list of UndoCommand objects to append to
  • solo (bool, optional) – to pass on to RemoveStrandCommand,
  • default=True
part()

Get model Part

Returns:Part – the Part
removeAllStrands(use_undostack=True)

Remove all Strand objects in the set

Parameters:use_undostack (bool, optional) – default=True
removeStrand(strand, use_undostack=True, solo=True)

Remove a Strand from the set

Parameters:
  • strand (Strand) – the Strand to remove
  • use_undostack (bool, optional) – default=True
  • solo (bool, optional) – solo is an argument to enable
  • signals emiting from the command in the case the command (limiting) –
  • instantiated part of a larger command, default=True (is) –
resize(delta_low, delta_high)

Resize this StrandSet. Pad each end when growing otherwise don’t do anything

Parameters:
  • delta_low (int) – amount to resize the low index end
  • delta_high (int) – amount to resize the high index end
simpleCopy(part)

Create an empty copy (no strands) of this strandset with the only a new virtual_helix_group parent

TODO: consider renaming this method

Parameters:part (Part) – part to copy this into
splitStrand(strand, base_idx, update_sequence=True, use_undostack=True)

Break strand into two strands. Reapply sequence by default.

Parameters:
  • strand (Strand) – the Strand
  • base_idx (int) – the index
  • update_sequence (bool, optional) – whether to emit signal, default=True
  • use_undostack (bool, optional) – default=True
Returns:

bool – True if successful, False otherwise

strandCanBeSplit(strand, base_idx)

Make sure the base index is within the strand Don’t split right next to a 3Prime end Don’t split on endpoint (AKA a crossover)

Parameters:
  • strand (Strand) – the Strand
  • base_idx (int) – the index to split at
Returns:

bool – True if can be split, False otherwise

strandCount()

Getter for the number of Strands in the set

Returns:int – the number of Strands in the set
strandFilter()

Get the filter type for this set

Returns:str – ‘forward’ if is_fwd else ‘reverse’
strandType()

Store the enum of strand type

Returns:intStrandType.FWD if is forward, otherwise StrandType.REV
strands()

Get raw reference to the strand_heap of this StrandSet

Returns:list – the list of strands
strandsCanBeMerged(strandA, strandB)

Only checks that the strands are of the same StrandSet and that the end points differ by 1. DOES NOT check if the Strands overlap, that should be handled by addStrand

Returns:tuple – empty tuple if the strands can’t be merged if the strands can be merged it returns the strand with the lower index in the form:
(strand_low, strand_high)
strandsetStrandAddedSignal = <cadnano.cnproxy.DummySignal object>

pyqtSignal(QObject, QObject) – strandset, strand