Examples

Assembly

Simulating DNA assembly between SeqRecords without a protocol.

Gibson Assembly with primer generation

"""Example of Gibson cloning fragments together via PCR."""

import os

from Bio.SeqIO import parse
from synbio.assembly import gibson

insert = next(parse(os.path.join("..", "data", "gibson", "pdsred2.fa"), "fasta"))
backbone = next(parse(os.path.join("..", "data", "gibson", "pDusk.fa"), "fasta"))

# assembled the SeqRecords together, creating primers for each SeqRecord so that
# after PCR they will anneal to one another
fragments = [insert, backbone]
plasmid, primer_pairs = gibson(fragments)

# inspect the plasmids that will be created
for fragment, primers in zip(fragments, primer_pairs):
    print("PCR", fragment.id, "with FWD", primers.fwd, "and REV", primers.rev)

Cloning via restriction digest and ligation

"""Example of cloning together SeqRecords after digestion with enzymes."""

import os

# 'synbio' uses the enzymes provided in Bio.Restriction
from Bio.Restriction import NotI, BamHI
from Bio.SeqIO import parse
from synbio.assembly import clone

# insert has "DsRed2" between NotI and BamHI
insert = next(parse(os.path.join("..", "data", "cloning", "pdsred2.gb"), "genbank"))

# backbone has "KanR" resistance between BamHI and NotI
backbone = next(parse(os.path.join("..", "data", "cloning", "pdusk.gb"), "genbank"))

# simulate a digestion and ligation between the backbone and the insert via NotI and BamHI
# keep only the plasmids that have both the DsRed2 and KanR features
plasmids = clone([insert, backbone], [NotI, BamHI], include=["DsRed2", "KanR"])

# inspect the plasmids that will be created
for plasmid in plasmids:
    print(plasmid.id, f"{len(plasmid)}bp", plasmid.description)

Protocols

Executing a DNA assembly while accumulating a Protocol object for writing protocol instructions, plate layouts, DNA files (gb, fa) and protocol inputs.

Gibson Assembly of a plasmid library

"""Example of a Gibson Assembly for a library of plasmids."""

import os

from Bio.SeqIO import parse

from synbio.designs import PlasmidLibrary
from synbio.protocols import Gibson

# read in the SeqRecords from files
insert1 = next(parse(os.path.join("..", "data", "gibson", "BBa_K1085023.fa"), "fasta"))
insert2 = next(parse(os.path.join("..", "data", "gibson", "BBa_K1649003.fa"), "fasta"))
backbone = next(parse(os.path.join("..", "data", "gibson", "pSB1C3.fa"), "fasta"))

# concatenate the insert to the backbone
design = PlasmidLibrary([[insert1, backbone], [insert2, backbone]])

# create a protocol using Gibson as the sole composite step and run
# filter on KanR in a backbone
protocol = Gibson(design=design)

# export the composite plasmid
protocol.to_fasta("plasmid.fasta")

# export plate layouts
protocol.to_csv("plates.csv")

# export human readable protocol
protocol.to_txt("protocol.txt")

Gibson Assembly of a single plasmid

"""Example of a Gibson Assembly with two fragments."""

import os

from Bio.SeqIO import parse

from synbio.designs import Plasmid
from synbio.protocols import Gibson

# read in the SeqRecords from files
insert = next(parse(os.path.join("..", "data", "gibson", "BBa_K1085023.fa"), "fasta"))
backbone = next(parse(os.path.join("..", "data", "gibson", "pSB1C3.fa"), "fasta"))

# concatenate the insert to the backbone
design = Plasmid([insert, backbone])

# create a protocol using Gibson as the sole composite step and run
# filter on KanR in a backbone
protocol = Gibson(design=design)

# export the composite plasmid
protocol.to_fasta("plasmid.fasta")

# export plate layouts
protocol.to_csv("plates.csv")

# export human readable protocol
protocol.to_txt("protocol.txt")

Golden Gate Assembly of a single plasmid

"""Example of a Golden Gate Assembly from a single list of SeqRecords into a plasmid.

The SeqRecords are combined into new plasmid SeqRecords:
all new combinations of SeqRecords. An error is thrown if no new plasmids are possible.
"""

import os

from Bio.SeqIO import parse

from synbio.designs import Plasmid
from synbio.protocols import GoldenGate


def read(filename):
    """read a SeqRecord from a file from a Genbank in the "goldengate" dir"""

    filename = os.path.join("..", "data", "goldengate", filename)
    return next(parse(filename, "genbank"))


# read in each SeqRecord: a promoter, RBS, CDS, terminator and backbone
design = Plasmid(
    read(r)
    for r in [
        "J23100_AB.gb",
        "B0032m_BC.gb",
        "C0012m_CD.gb",
        "B0015_DE.gb",
        "DVK_AE.gb",
    ]
)

# create a protocol using GoldenGate as the sole composite step and run
# filter on KanR in a backbone
protocol = GoldenGate(name="Golden Gate Plasmid", design=design, min_count=5)

# export the composite plasmid
protocol.to_fasta("plasmid.fasta")

# export plate layouts
protocol.to_csv("plates.csv")

# export human readable protocol
protocol.to_txt("protocol.txt")

Combinatorial Golden Gate Assembly: all valid plasmid combinations

"""Example of a Combinatorial Golden Gate assembly with steps and output."""

import os

from Bio.SeqIO import parse

from synbio.designs import Combinatorial
from synbio.protocols import GoldenGate


def read_all_records():
    """Gather all SeqRecords from "goldengate" dir in examples."""

    data_dir = os.path.join("..", "data", "goldengate")
    records = []
    for file in os.listdir(data_dir):
        if file.endswith(".gb"):
            records.extend(parse(os.path.join(data_dir, file), "genbank"))
    return records


# create a combinatorial library design from multiple "bins"
design = Combinatorial(read_all_records())

# create a protocol using Golden Gate as the sole composite step and run
protocol = GoldenGate(
    name="Combinatorial Golden Gate", design=design, include=["KanR"], min_count=5
)

# export all the output plasmids to a multi-FASTA
protocol.to_fasta("composite_parts.fasta")

# export plate layouts
protocol.to_csv("plate_layouts.csv")

# export human protocol
protocol.to_txt("protocol.txt")

# export a hamilton picklist
protocol.to_picklists("robotic_picklist.gwl", platform="tecan")

Combinatorial Golden Gate Assembly with bins: all plasmid combinations between bins

"""Example of a CombinatorialBins MoClo assembly with steps and output.

All possible assemblies from combinations of all SeqRecords across
multiple bins are tested and those that will successfully linearize
are combined into composite plasmids.
"""

import os

from Bio.SeqIO import parse

from synbio.designs import CombinatorialBins
from synbio.protocols import GoldenGate


def read_all_records():
    """Gather all SeqRecords from "goldengate" dir in examples."""

    data_dir = os.path.join("..", "data", "goldengate")
    records = []
    for file in os.listdir(data_dir):
        if file.endswith(".gb"):
            records.extend(parse(os.path.join(data_dir, file), "genbank"))
    return records


# create a combinatorial library design from multiple "bins"
design = CombinatorialBins()
gg_records = read_all_records()
for type in ["promoter", "RBS", "CDS", "terminator", "KanR"]:
    record_bin = [r for r in gg_records if any(f.type == type for f in r.features)]
    design.append(record_bin)  # add a new cominatorial bin

# create a protocol using GoldenGate as the sole composite step and run
# filter on plasmids with a KanR feature in the backbone and at least 5 consituent SeqRecords
protocol = GoldenGate(
    name="CombinatorialBins Golden Gate", design=design, include=["KanR"], min_count=5
)

# export all the output plasmids to a multi-FASTA
protocol.to_fasta("plasmids.fasta")

# export plate layouts
protocol.to_csv("plates.csv")

# export protocol
protocol.to_txt("protocol.txt")

# because this is a larger assembly, make robotic instructions
protocol.to_picklists("robotic_picklist.gwl", platform="tecan")

Annotation

Annotating a SeqRecord with a curated SeqFeature database

"""Example of annotating a Bio.SeqRecord with common plasmid Bio.SeqFeatures."""

from Bio.SeqIO import parse
from synbio.features import annotate

record = next(parse("plasmid.fa", "fasta"))
record_with_features = annotate(record, identity=0.96)