Skip to content

History ​

SgffHistory ​

History model: tree (block 7), snapshots (block 11), and content blobs (block 30). Block 29 modifiers are accessed via sgff.blocks[29].

python
from sgffp import SgffHistory

BLOCK_IDS: (7, 11, 29, 30)

Tree Access (Block 7) ​

MemberDescription
tree → SgffHistoryTree | NoneHistory tree structure (settable)
get_tree_node(node_id) → SgffHistoryTreeNode | NoneGet tree node by ID
walk_tree() → Iterator[SgffHistoryTreeNode]Iterate all tree nodes depth-first

Node Access (Block 11) ​

MemberDescription
nodes → Dict[int, SgffHistoryNode]Sequence snapshots indexed by node_index
get_node(index) → SgffHistoryNode | NoneGet snapshot by index
get_sequence_at(index) → str | NoneGet sequence at a history node
add_node(node) → intAdd snapshot and sync
remove_node(index) → boolRemove snapshot and sync
update_node(index, **kwargs) → boolUpdate snapshot attributes

Tree Modification ​

MethodDescription
record_operation(blocks, new_seq, operation, name="", **kwargs)Snapshot current state and create new root
snapshot_current_state(blocks) → SgffHistoryNodeCreate block 11 entry from main blocks
update_for_new_sequence(new_seq)Update root node's seqLen without recording
next_id() → intNext available tree node ID
clear()Remove all history (blocks 7, 11, 29, 30)

Dunder Methods ​

MethodDescription
len(history)Number of block 11 nodes
iter(history)Iterate over SgffHistoryNode values

SgffHistoryTree ​

Tree structure parsed from block 7.

python
from sgffp import SgffHistoryTree
MemberDescription
root → SgffHistoryTreeNode | NoneRoot node (current state)
nodes → Dict[int, SgffHistoryTreeNode]All nodes indexed by ID
get(node_id) → SgffHistoryTreeNode | NoneLookup by ID
walk(from_node=None) → IteratorPre-order traversal (parent first)
walk_reverse(from_node=None) → IteratorPost-order traversal (children first, chronological)
ancestors(node_id) → List[SgffHistoryTreeNode]Chain from node to root
to_dict() → DictSerialize to dict
from_dict(data) → SgffHistoryTreeCreate from parsed dict
len(tree)Total node count
iter(tree)Pre-order walk

SgffHistoryTreeNode ​

Single node in the history tree (block 7).

python
from sgffp import SgffHistoryTreeNode

Fields ​

FieldTypeDescription
idintUnique node ID
namestrSequence filename
typestr"DNA", "RNA", or "Protein"
seq_lenintSequence length
strandednessstr"single" or "double"
circularboolCircular topology
operationstrOperation that created this state
upstream_modificationstre.g., "Unmodified"
downstream_modificationstre.g., "Unmodified"
resurrectableboolUser can restore this state

Nested Data ​

FieldTypeDescription
oligosList[SgffHistoryOligo]Primers used in operation
parametersDict[str, str]Key-value parameters
input_summariesList[SgffInputSummary]Range/enzyme selections
primersDict | NonePrimer binding data
history_colorsDict | NoneStrand coloring
featuresList[Dict]Feature snapshots

Tree Structure ​

FieldTypeDescription
childrenList[SgffHistoryTreeNode]Child nodes
parentSgffHistoryTreeNode | NoneParent node
extrasDictUnmodeled attributes

Properties ​

PropertyDescription
input_summaryFirst SgffInputSummary (or None)

Methods: from_dict(data, parent=None), to_dict().


SgffHistoryNode ​

Sequence snapshot stored in block 11.

python
from sgffp import SgffHistoryNode

Fields ​

FieldTypeDefaultDescription
indexintNode index (links to tree node ID)
sequencestr""Sequence at this history point
sequence_typeint00=DNA, 1=compressed, 21=protein, 32=RNA
lengthint0Sequence length
contentSgffHistoryNodeContent | NoneNoneNested content (features, etc.)
writer_stampint30Opaque writer-side byte for compressed-DNA snapshots (preserved for round-trip; SnapGene's parser ignores it)
tree_nodeSgffHistoryTreeNode | NoneNoneLinked tree node

Model Accessors ​

Shortcuts to content models (delegate to content):

PropertyType
featuresSgffFeatureList
primersSgffPrimerList
notesSgffNotes
propertiesSgffProperties
tracesSgffTraceList

Methods: from_dict(data), to_dict().


SgffHistoryNodeContent ​

Content snapshot with model accessors. Wraps a blocks dict.

python
from sgffp import SgffHistoryNodeContent
MemberDescription
blocks → Dict[int, List]Raw blocks dict
block_types → List[int]Block types present
exists → boolAny content present
featuresSgffFeatureList
primersSgffPrimerList
notesSgffNotes
propertiesSgffProperties
alignmentsSgffAlignmentList
tracesSgffTraceList
has_features, has_primers, has_notes, has_properties, has_alignments, has_tracesExistence checks

SgffHistoryOligo ​

Primer/oligo used in a cloning operation.

python
from sgffp import SgffHistoryOligo
FieldTypeDefault
namestr
sequencestr
phosphorylatedboolFalse

Methods: from_dict(data), to_dict().


SgffInputSummary ​

Describes range/selection for an operation.

python
from sgffp import SgffInputSummary
FieldTypeDefaultDescription
manipulationstre.g., "select", "insert", "digest"
val1intStart position
val2intEnd position
enzymesList[tuple][][(name, site_count), ...]
extrasDict{}Unmodeled attributes
PropertyDescription
enzyme_names → List[str]List of enzyme names

Methods: from_dict(data), to_dict().


HistoryOperation ​

String enum of known operation types.

python
from sgffp import HistoryOperation

Values by Category ​

Base:

EnumValue
INVALID"invalid"

Create:

EnumValue
MAKE_DNA"makeDna"
MAKE_RNA"makeRna"
MAKE_PROTEIN"makeProtein"

Cloning:

EnumValue
AMPLIFY"amplifyFragment"
INSERT"insertFragment"
INSERT_MULTI"insertFragments"
DIGEST"digest"
LIGATE"ligateFragments"
GATEWAY_LR"gatewayLRCloning"
GATEWAY_BP"gatewayBPCloning"
GIBSON"gibsonAssembly"
GOLDEN_GATE"goldenGateAssembly"
RESTRICTION_CLONE"restrictionCloning"
TA_CLONE"taCloning"
TOPO_CLONE"topoCloning"
IN_FUSION"inFusionCloning"

Edit:

EnumValue
REPLACE"replace"
FLIP"flip"
NEW_FROM_SELECTION"newFileFromSelection"
MUTAGENESIS"primerDirectedMutagenesis"

Metadata:

EnumValue
CHANGE_METHYLATION"changeMethylation"
CHANGE_PHOSPHORYLATION"changePhosphorylation"
CHANGE_STRANDEDNESS"changeStrandedness"
CHANGE_TOPOLOGY"changeTopology"

Unknown operation strings are handled gracefully via _missing_().


SgffOps ​

Operations API for recording history. See the History & Operations guide for usage examples.

All methods return SgffObject for chaining. Access via sgff.ops.

Methods ​

Metadata: change_methylation(**kw), change_phosphorylation(**kw), change_strandedness(**kw), change_topology(**kw)

Create: make_dna(seq, *, topology=, strandedness=, **kw), make_rna(seq, *, topology=, **kw), make_protein(seq, **kw)

Edit: replace(seq, **kw), insert_fragment(seq, **kw), insert_fragments(seq, **kw), flip(seq, **kw), new_from_selection(seq, **kw), mutagenesis(seq, **kw)

Cloning: amplify(seq, **kw), digest(seq, **kw), ligate(seq, **kw), gateway_lr(seq, **kw), gateway_bp(seq, **kw), gibson(seq, **kw), golden_gate(seq, **kw), restriction_clone(seq, **kw), ta_clone(seq, **kw), topo_clone(seq, **kw), in_fusion(seq, **kw)

Generic: custom(operation, new_seq, **kw)

Bulk: build_from_spec(nodes, final_sequence) → SgffObject

Edit node: edit_node(node_id, **kwargs) → SgffObject

Released under the MIT License.