Repository navigation
Plasmid Engineering & Restriction Workbench
The BioLabCalc v0.4.0 plasmid engineering suite introduces comprehensive, offline-first synthetic biology capabilities for designing expression constructs, simulating enzymatic restriction digestion, and visualizing circular plasmids in an interactive, responsive Elm Architecture (TEA) workbench.
- Overview & Architectural Philosophy
- Biological Sequence Storage & Catalog (
biolabcalc.sequence_store) - Circular Plasmid Representation & GenBank I/O (
biolabcalc.plasmid) - In-Silico Restriction Digestion & Virtual Gels (
biolabcalc.restriction_engine) - Automated Expression Plasmid Engineering (
biolabcalc.plasmid_engineering) - The Elm Architecture (TEA) State Runtime (
biolabcalc.tea_runtime) - Interactive HTML5/SVG Plasmid Workbench (
biolabcalc.interactive_plasmid) - Command-Line Interface (CLI) Usage
- Python API Code Examples
Molecular cloning workflows require exact sequence manipulation, circular coordinate tracking, and restriction fragment verification. BioLabCalc v0.4.0 implements these operations following strict biochemical conventions:
-
Strict Immutability: Every domain entity (
SequenceRecord,PlasmidRecord,PlasmidFeature,DigestionPrediction,EngineeredPlasmidResult) is implemented as an immutable@dataclass(frozen=True)with tuple collections. -
1-Based Inclusive Coordinates: All sequence positions adhere to GenBank and SnapGene standard 1-based indexing (
$1 \le \text{pos} \le L$ ). -
Origin-Spanning Circular Features: In a circular plasmid of length
$L$ , features crossing the origin have$\text{start} > \text{end}$ . Feature length is calculated as:$$\text{Length} = (L - \text{start} + 1) + \text{end}$$ -
Exact Overhang Phosphodiester Tracking: Cleavage offsets for top-strand (
$5' \to 3'$ ) and bottom-strand ($3' \to 5'$ ) phosphodiesters are tracked independently. Cohesive overhang sequences are dynamically extracted from the cleaved DNA sequence itself, essential for degenerate IUPAC enzymes (e.g., SfiI) and Type IIS enzymes (e.g., BsaI, BsmBI, SapI). -
Deterministic State Transitions: The Elm Architecture (
Model,Msg,update,view,Cmd) guarantees reproducible state management and reversible time-travel history without side effects.
Module: biolabcalc.sequence_store
-
SequenceAnnotation: Feature name, feature type (e.g.,promoter,CDS,tag), 1-based coordinates[start .. end], strand ($+1$ or$-1$ ), and optional notes. -
SequenceRecord: Unique ID, name, sequence string, sequence type (dna,rna,protein), topology (linear,circular,dsdna), automatic SHA-256 checksum (first 16 hex characters), sequence length, GC percentage, and exact biophysical molecular weight in Daltons.
BioLabCalc includes a default catalog of verified public-domain reference sequences:
-
T7_PROMOTER(20 bp): Bacteriophage T7 RNA Polymerase Promoter (-17 to +3) -
SP6_PROMOTER(23 bp): Bacteriophage SP6 RNA Polymerase Promoter -
T3_PROMOTER(20 bp): Bacteriophage T3 RNA Polymerase Promoter -
GLUK2_EXON1_AMPLICON(120 bp): Diagnostic PCR amplicon for human GRIK2 exon 1 -
GLUA1_LBD_CDS(753 bp): Ligand-binding domain (S1S2) coding sequence of human GRIA1 -
AB9SR_APTAMER(79 nt): High-affinity synthetic RNA aptamer -
EGFP_CDS(720 bp): Enhanced Green Fluorescent Protein reporter gene -
HIS6_TEV_TAG(39 bp): Hexahistidine affinity tag fused to a TEV protease cleavage site -
KANR_CDS(816 bp): Kanamycin / neomycin resistance gene (aphA-3) -
AMPR_CDS(861 bp): Ampicillin resistance gene (beta-lactamase, bla)
-
save_sequence(record, filepath=None): Atomically persists sequences to~/.biolabcalc/sequences.json. -
get_sequence(id_or_name, filepath=None): Retrieves record by identifier or display name. -
import_fasta(text_or_path, seq_type="dna"): Parses standard single or multi-record FASTA files into immutableSequenceRecordobjects. -
export_fasta(records, filepath=None): Serializes records into standard FASTA format with 70-character line wrapping.
Module: biolabcalc.plasmid
-
PlasmidFeature: Represents annotations on circular DNA. Supports forward strand ($+1$ ) and reverse strand ($-1$ ), customizable hex display colors, and circular origin wrapping. -
PlasmidRecord: Represents the complete circular plasmid. Calculates GC content, double-stranded molecular weight (using standard$650\text{ Da/bp}$ or base-exact composition), and feature distributions.
-
extract_subsequence(plasmid, start, end, strand=1): Extracts linear subsequence across 1-based coordinates. Correctly handles circular wrap when$\text{start} > \text{end}$ by concatenating segment$[\text{start} \dots L]$ with$[1 \dots \text{end}]$ . -
rotate_origin(plasmid, new_origin_1based): Rotates the physical base 1 coordinate of the circular plasmid to any arbitrary index. Recalculates all feature start and end coordinates with modulo-$L$ invariance. -
insert_subsequence(plasmid, index_1based, insert_seq, replace_end_1based=None): Inserts or replaces DNA fragments, adjusting all downstream feature coordinates and expanding origin-spanning features. -
find_orfs(plasmid_or_seq, min_aa=50, circular=True): Discovers open reading frames across all 6 reading frames, tracking ORFs that cross the circular origin boundary.
-
pUC19(2,686 bp): Complete sequence with annotated ColE1/pUC origin, beta-lactamase (AmpR), lac promoter, and multiple cloning site (MCS). -
pET-28a(+): Bacterial T7 expression cassette with N-terminal 6xHis-Thrombin-T7 tag, MCS, and C-terminal 6xHis tag. -
pcDNA3.1(+): Mammalian expression cassette with human cytomegalovirus (CMV) promoter, BGH polyadenylation signal, and f1 origin. -
pGoldenGate-Dest: Synthetic destination vector with flanking outward-facing BsaI sites for Golden Gate Type IIS assembly.
-
parse_genbank(gb_text_or_path): Full parser extractingLOCUS,DEFINITION,ACCESSION,ORIGIN, andFEATUREStable into a nativePlasmidRecord. -
export_genbank(plasmid, filepath=None): Exports complete GenBank-compliant flatfiles, with origin-spanning features formatted asjoin(start..L, 1..end).
Module: biolabcalc.restriction_engine
Restriction enzymes cleave top and bottom strands at distinct phosphodiester offsets relative to their recognition sequence:
-
Type II Palindromic Enzymes: E.g., EcoRI recognizes
G^AATTC(cleavage top = 1, bottom = 5), leaving a$5'$ cohesive overhangAATT. SmaI recognizesCCC^GGG(cleavage top = 3, bottom = 3), leaving blunt ends. -
Type IIS Asymmetric Enzymes: E.g., BsaI recognizes
GGTCTC(N1/N5), cleaving outside its recognition site (cut top = 7, bottom = 11) to yield an arbitrary 4-bp sticky overhang.
-
simulate_restriction_digest(plasmid, enzymes, complete=True): Simulates complete single, double, or multiplex digestion setups.- Generates
DigestionPredictioncontaining fragment lengths, start/end coordinates, and exact 5' and 3' terminal overhang sequences. - Calculates fragment molecular weights and relative stoichiometric abundance.
- Accounts for circular plasmid linearization (1 cut site = 1 linear fragment of length
$L$ ) and multiple cut sites ($N$ cut sites =$N$ fragments whose lengths sum to$L$ ).
- Generates
-
digest_matches_gel(predicted_bands, observed_bands, tolerance_bp=50): Compares predicted in-silico fragments with wet-lab experimental agarose gel bands, scoring migration consistency.
-
generate_virtual_gel_ascii(prediction, ladder_key="dna_1kb_plus"): Generates high-resolution terminal ASCII diagrams simulating agarose gel band migration and relative fluorescence intensity. -
render_virtual_gel_svg(predictions_by_lane, ladder_key="dna_1kb_plus"): Generates publication-quality scalable vector graphics (SVG) virtual gel representations with calibrated log-linear band dispersion.
Module: biolabcalc.plasmid_engineering
Automates the complete design of expression plasmids for protein production or mammalian transfection:
- Directional Restriction-Ligation: Inserts target CDS between two compatible unique restriction sites in the MCS (e.g., BamHI + XhoI in pET-28a).
- Gibson / Isothermal Assembly: Inserts target fragment with 25β40 bp vector homology overhangs for exonuclease-polymerase-ligase assembly.
- Golden Gate Assembly (Type IIS): Inserts target CDS into destination vectors using BsaI, BsmBI, or PaqCI, with customizable 4-bp overhangs.
Ensures the target open reading frame stays strictly in-frame with N-terminal affinity tags (e.g., 6xHis, TEV, FLAG):
- Calculates translation frame offset:
$$\Delta_{\text{frame}} = (\text{insertion_index} - \text{tag_frame_origin}) \pmod 3$$ - Automatically introduces non-disruptive padding nucleotides (e.g.,
GCorA) into PCR primer overhangs when$\Delta_{\text{frame}} \ne 0$ .
If an insert contains internal recognition sites for cloning enzymes (e.g., an internal BsaI site in Golden Gate assembly), domesticate_restriction_sites introduces synonymous codon mutations:
- Identifies conflicting motifs on both sense and antisense strands.
- Substitutes rare or motif-causing codons with preferred synonymous host codons (E. coli or human) without changing the translated amino acid sequence.
Before outputting any engineered construct, the engine executes a comprehensive 7-point quality audit:
- In-Frame Verification: Confirms insertion maintains continuous reading frame from initiator ATG through stop codon.
- Start Codon Integrity: Verifies presence of canonical initiator codon.
- Stop Codon Integrity: Verifies termination codon (TAA, TAG, TGA).
- Premature Termination Check: Verifies zero internal in-frame stop codons.
- RBS / Kozak Alignment: Confirms Shine-Dalgarno or Kozak spacing is optimal (5β9 nt to ATG).
- Origin of Replication Intact: Confirms ColE1/pUC/f1 origin is completely unaltered.
- Selection Marker Intact: Confirms antibiotic resistance CDS is functional.
Module: biolabcalc.tea_runtime
The Elm Architecture (TEA) provides a purely functional state engine for interactive workbench applications:
+-----------------------+
| |
| User Action |
| |
+-----------+-----------+
|
v
+-----------------------+
| |
| Msg (Union) |
| |
+-----------+-----------+
|
v
+--------------+ +-----------------------+
| | | |
| Old Model +------>+ update(msg, model) +------> (New Model, Cmd)
| | | |
+--------------+ +-----------+-----------+
|
v
+-----------------------+
| |
| view(model) |
| |
+-----------+-----------+
|
v
+-----------------------+
| Markdown / SVG / |
| Interactive HTML |
+-----------------------+
-
BioLabModel: Immutable snapshot containing loaded plasmid, selected restriction enzymes, active digestion prediction, engineered vector result, and time-travel history. -
MsgHierarchy:LoadPlasmidMsg(plasmid_id, custom_plasmid)SelectEnzymesMsg(enzyme_names)RunDigestMsg()InsertGeneMsg(gene_name, insert_seq, mode, enzyme_5prime, enzyme_3prime, tag)RotateOriginMsg(new_origin)-
UndoMsg()andRedoMsg()
-
update(msg, model) -> Tuple[BioLabModel, Cmd]: Pure state transition function returning new model and external command. -
view(model) -> str: Pure renderer generating structured Markdown and SVG visualization.
Module: biolabcalc.interactive_plasmid
Generates zero-dependency standalone HTML5/SVG web applications:
- Circular Plasmid Map: Scalable vector graphics (SVG) with color-coded feature arcs, directional gene arrows, restriction site ticks, and origin marker.
- Virtual Gel Lane Simulation: Live simulated agarose gel lane calibrated against standard 1 kb Plus DNA ladders.
- Dynamic Tooltips & Inspection: Hover over any feature or restriction site to inspect coordinates, amino acid translation, and cleavage overhang details.
-
Export Capabilities: Download engineered plasmid maps as SVG, GenBank flatfiles (
.gb), or FASTA files directly from the browser.
BioLabCalc v0.4.0 exposes unified subcommands for all plasmid and restriction capabilities:
# List all pre-seeded and custom sequences
biolabcalc sequence --list
# Inspect a sequence by ID
biolabcalc sequence --get EGFP_CDS
# Import a sequence from a FASTA file
biolabcalc sequence --import-fasta my_insert.fasta --type dna# List standard plasmid catalog
biolabcalc plasmid --list
# Inspect pUC19 features and restriction sites
biolabcalc plasmid --get pUC19 --info
# Export plasmid to GenBank format
biolabcalc plasmid --get pET-28a(+) --export-gb pet28a.gb
# Import custom plasmid from GenBank file
biolabcalc plasmid --import-gb my_vector.gb# Digest pUC19 with EcoRI and HindIII
biolabcalc digest --plasmid pUC19 --enzymes EcoRI HindIII
# Display ASCII virtual agarose gel
biolabcalc digest --plasmid pUC19 --enzymes EcoRI BamHI --simulate-gel# Directional cloning of EGFP into pET-28a(+) via BamHI and XhoI
biolabcalc engineer-plasmid \
--vector "pET-28a(+)" \
--insert-seq "ATGGTGAGCAAGGGCGAGGAGCTG..." \
--gene-name "EGFP" \
--mode restriction_ligation \
--e5 BamHI \
--e3 XhoI \
--tag "6xHis"
# Output engineered GenBank file directly
biolabcalc engineer-plasmid \
--vector "pET-28a(+)" \
--insert-seq "ATGGTGAGCAAGGGCGAGGAGCTG..." \
--output-gb "pET28a-EGFP.gb"# Export standalone HTML5/SVG workbench for pUC19
biolabcalc plasmid-workbench --plasmid pUC19 --output pUC19_workbench.html
# Launch workbench in local browser
biolabcalc plasmid-workbench --plasmid "pET-28a(+)" --open-browserfrom biolabcalc.plasmid import get_plasmid
from biolabcalc.restriction_engine import simulate_restriction_digest, generate_virtual_gel_ascii
# Load pUC19 from catalog
puc19 = get_plasmid("pUC19")
# Simulate double digestion with EcoRI and PstI
prediction = simulate_restriction_digest(puc19, ["EcoRI", "PstI"])
print(f"Fragments generated: {prediction.fragment_count}")
for frag in prediction.fragments:
print(f" - Length: {frag.length_bp} bp | Coordinates: {frag.start}..{frag.end}")
# Print terminal ASCII virtual gel
print(generate_virtual_gel_ascii(prediction))from biolabcalc.plasmid_engineering import engineer_plasmid
from biolabcalc.sequence_store import get_sequence
# Retrieve EGFP coding sequence
egfp = get_sequence("EGFP_CDS")
# Assemble into pET-28a(+) with frame synchronization
result = engineer_plasmid(
vector="pET-28a(+)",
insert_seq=egfp.sequence,
gene_name="EGFP",
mode="restriction_ligation",
enzyme_5prime="BamHI",
enzyme_3prime="XhoI",
auto_domesticate=True,
)
print(f"Cloning Mode: {result.mode}")
print(f"Reading Frame Synchronized: {result.in_frame}")
print(f"Forward Primer: {result.forward_primer_full_seq}")
print(f"Reverse Primer: {result.reverse_primer_full_seq}")
print(f"Predicted Yield: {result.predicted_expression_yield_mg_l:.1f} mg/L culture")from biolabcalc.tea_runtime import init, update, LoadPlasmidMsg, RunDigestMsg, view
# Initialize TEA runtime model
model, cmd = init("pUC19")
# Update model with digestion message
model, cmd = update(RunDigestMsg(), model)
# Render Markdown view of current state
print(view(model))BioLabCalc Documentation Wiki | Licensed under the MIT License | GitHub Repository Research Use Only (RUO). Not intended for clinical or diagnostic procedures.
- Core Calculators & Stoichiometry
- Solution Prep & Spectroscopy
- Buffers & Precipitation
- Protein Quantification & Assays
- Fluorophores & Dye Labeling
- Molecular Cloning & Assembly
- Plasmid Engineering & Workbench
- PCR Kinetics & Primer Design
- In Vitro Transcription (IVT)
- Western Blotting Suite
- Bacterial Growth & Kinetics
- ELN System Architecture
- SOP & Protocol Management
- Instrument Data Parsers
- Inventory & Freezer LIMS
- Local RAG Knowledge Engine
- GxP Compliance & Audit Trails