Skip to content

Other Models

SgffNotes

File-level metadata (block 6). Inherits from SgffModel.

python
from sgffp import SgffNotes

BLOCK_IDS: (6,)

Properties

PropertyTypeDescription
dataDictRaw notes dict
descriptionstrFile description (settable)
createdstr | NoneCreation timestamp
last_modifiedstr | NoneLast modification timestamp

Methods

MethodDescription
get(key, default=None)Get value by key
set(key, value)Set value and sync
remove(key) → boolRemove key and sync

Example

python
sgff.notes.description = "My plasmid"
sgff.notes.set("Type", "Synthetic")
print(sgff.notes.created)         # "2024-01-15.12:00:00"
sgff.notes.remove("CustomMapLabel")

SgffProperties

Sequence properties (block 8). Inherits from SgffModel.

python
from sgffp import SgffProperties

BLOCK_IDS: (8,)

Properties

PropertyTypeDescription
dataDictRaw properties dict

Methods

MethodDescription
get(key, default=None)Get value by key
set(key, value)Set value and sync

Example

python
props = sgff.properties
print(props.get("UpstreamModification"))  # "Unmodified"
props.set("UpstreamStickiness", "4")

SgffAlignmentList

Alignable sequences (block 17). Inherits from SgffListModel[SgffAlignment].

python
from sgffp import SgffAlignmentList, SgffAlignment

BLOCK_IDS: (17,)

Provides standard list operations: add(), remove(), clear(), indexing, iteration.

SgffAlignment

Single alignable sequence.

FieldTypeDefaultDescription
namestr""Sequence name
sequencestr""Sequence string
extrasDict{}Unmodeled attributes

Methods: from_dict(data), to_dict().


SgffTraceList

Chromatogram traces (block 16 containers). Inherits from SgffListModel[SgffTrace].

python
from sgffp import SgffTraceList

BLOCK_IDS: (16,)

Loads traces from block 16 containers — each container wraps a block 18 ZTR trace with optional block 8 properties. Block 18 never appears at the top level.

Provides standard list operations: add(), remove(), clear(), indexing, iteration.

SgffTrace

Single sequence trace (Sanger chromatogram).

python
from sgffp import SgffTrace
FieldTypeDefaultDescription
basesstr""Base calls
positionsList[int][]Base-to-sample positions
confidenceList[int][]Confidence scores per base
samplesSgffTraceSamples | NoneNoneACGT channel intensities
clipSgffTraceClip | NoneNoneQuality clip boundaries
textDict[str, str]{}Metadata key-value pairs
commentsList[str][]Comment strings

Properties

PropertyTypeDescription
sequencestrAlias for bases
lengthintNumber of bases
sample_countintNumber of sample points

Methods

MethodDescription
get_metadata(key, default="")Get metadata value
get_confidence_at(index) → int | NoneConfidence at base index
get_position_at(index) → int | NoneSample position at base index
from_dict(data)Create from parsed dict
to_dict()Serialize to dict

SgffTraceClip

Quality clip boundaries.

FieldTypeDefaultDescription
leftint0Left clip position
rightint0Right clip position

SgffTraceSamples

Trace sample intensities for each channel.

FieldTypeDefaultDescription
aList[int][]Adenine channel
cList[int][]Cytosine channel
gList[int][]Guanine channel
tList[int][]Thymine channel
PropertyDescription
lengthNumber of sample points

Example

python
for trace in sgff.traces:
    print(f"{trace.length} bases, {trace.sample_count} samples")
    if trace.clip:
        print(f"  clip: {trace.clip.left}..{trace.clip.right}")
    if trace.samples:
        print(f"  A channel: {trace.samples.a[:5]}...")

SgffAttachmentList

File attachments (block 23). Inherits from SgffListModel[SgffAttachment].

python
from sgffp import SgffAttachmentList, SgffAttachment

BLOCK_IDS: (23,)

Provides standard list operations: add(), remove(), clear(), indexing, iteration. Additional lookup methods: get_by_name(name), get_by_id(file_id).

SgffAttachment

Single file attachment embedded in a SnapGene file.

FieldTypeDefaultDescription
idint0File ID (auto-assigned on add)
namestr""Filename
databytesb""Raw file content
sizeint0File size in bytes
mtimestr""Modification timestamp
compressiblestr"0"Whether SnapGene may compress
extrasDict{}Unmodeled manifest attributes

Methods: from_blocks(file_block, manifest_entry), to_manifest_dict(), to_file_block().

Example

python
for att in sgff.attachments:
    print(f"[{att.id}] {att.name}: {att.size} bytes")

sgff.add_attachment("gel.jpg", open("gel.jpg", "rb").read())
att = sgff.attachments.get_by_name("gel.jpg")

SgffTraceAlignment

Trace alignment data (block 27). Inherits from SgffModel. Contains BGZF-compressed BAM data — alignments of sequencing traces against the reference sequence.

python
from sgffp import SgffTraceAlignment, SgffBamRecord, SgffBamReference

BLOCK_IDS: (27,)

PropertyTypeDescription
headerstrSAM header text
referencesList[SgffBamReference]Reference sequences
recordsList[SgffBamRecord]Alignment records
record_countintNumber of alignment records
reference_countintNumber of reference sequences

SgffBamReference

FieldTypeDefaultDescription
namestr""Reference name
lengthint0Reference length in bp

SgffBamRecord

FieldTypeDefaultDescription
read_namestr""Read/trace name (matches block 17 Sequence/@ID)
flagint0SAM flag bits
ref_idint0Reference sequence index
posint00-based mapping position
mapqint255Mapping quality
cigarstr""CIGAR string (e.g. 3S154M6S)
sequencestr""Read sequence
qualityList[int][]Per-base quality scores

Properties: is_unmapped, is_reverse, length.

Example

python
if sgff.has_trace_alignment:
    ta = sgff.trace_alignment
    print(f"SAM header: {ta.header}")
    for ref in ta.references:
        print(f"  Reference: {ref.name} ({ref.length} bp)")
    for rec in ta.records:
        strand = "reverse" if rec.is_reverse else "forward"
        print(f"  {rec.read_name}: {strand}, CIGAR={rec.cigar}, {rec.length}bp")

Released under the MIT License.