Beispiel #1
0
 def setUp(self):
     self.doc = sbol.Document()
     self.assertEqual(self.doc.num_sbol_objects, 0)
     self.uris = []
     self.testees = []
     self.createTestees()
     self.assertEqual(len(self.uris), len(self.testees))
     self.assertEqual(len(self.uris), self.doc.num_sbol_objects)
     self.assertEqual(len(self.uris),
                      sbol.libsbol.getNumSBOLObjects(self.doc.ptr))
def test1():
    sbol.setHomespace('http://sbol_prefix.org')
    doc = sbol.Document()

    pTetR = sbol.ComponentDefinition("test_promoter_1", sbol.BIOPAX_DNA)
    pTetR.roles = sbol.SO_PROMOTER
    doc.addComponentDefinition(pTetR)

    results = doc.write("pysbol_output.xml")
    return results
Beispiel #3
0
 def sbol(self):
     doc = sbol.Document()
     dc = sbol.DNAComponent(doc, "#" + str(self.pk) + "_con")
     dc.display_id = str(self.name)
     dc.description = str(self.description)
     dc.sequence = sbol.DNASequence(doc, "#" + str(self.pk) + "_seq")
     dc.sequence.nucleotides = str(self.sequence())
     fid = [1]
     l = self.length()
     def makeAnnot(f, parent=dc):
         if self.shape == 'c' and f.end > l and parent == dc:
             end = f.end
             f.end = l
             makeAnnot(f, parent)
             f.end = end - l
             f.start = 0
             makeAnnot(f, parent)
             return
         dcf = sbol.DNAComponent(doc, "#dc_" + str(fid[0]))
         dcf.display_id = str(f.type)
         dcf.description = str(";".join(["%s:%s" % (q.name,q.data) for q in f.qualifiers.all()]))
         sa = sbol.SequenceAnnotation(doc, "#sa_" + str(fid[0]))
         sa.subcomponent = dcf
         if f.direction == 'f':
             sa.strand = '+'
         else:
             sa.strand = '-'
         sa.start = f.start + 1 # SBOL 1-based
         sa.end = f.end + 1
         parent.annotations.append(sa)
         fid[0] += 1
         return dcf
     fragments = {}
     fragmentfeats = {}
     for f in self.features(False): # sub-annotations relative to parent
         try:
             if f.gene is not None:
                 if f.type == "fragment":
                     fragments[f.gene] = f
                 else:
                     if f.gene in fragmentfeats:
                         fragmentfeats[f.gene].append(f)
                     else:
                         fragmentfeats[f.gene] = [f]
         except:
             makeAnnot(f)
     for gene, fragment in fragments.iteritems():
         dcf = makeAnnot(fragment)
         dcf.description = str(gene.description)
         if gene in fragmentfeats:
             for f in  fragmentfeats[gene]:
                 makeAnnot(f, dcf)
     return str(doc)
def parseSBOL(inputFile):
    i = 0
    doc = sbol.Document()
    doc.read(inputFile)
    returnList = []
    for a in doc.sequences:
        sequence = SeqObject(idN=a.displayId,
                             name="Sequence " + str(i),
                             sequence=str(a.elements).upper())
        returnList.append(sequence)
        i = i + 1
    return returnList
Beispiel #5
0
def parse(sbol_doc=None, path=None):
    '''Parse SBOL and extract an assembly plan.

    Parameters
    ----------

    sbol_doc
      A PySBOL Document() containing the designs and parts seqs.
      A path to a SBOL .xml file can be provided instead.

    path
      A path to a SBOL .xml file

    Returns
    -------

    (parts_seqs, parts_per_construct, constructs_seqs)
      Assembly plan data:
      - parts_seqs is of the form ``{part_id: 'ATTTGTGTGC...'}``,
      - parts_per_constructs is of the form ``{construct_id: [part_id_1,...]}``
      - constructs_seqs is of the form ``{construct_id: 'ATGCCC...'}``.
    '''
    if path is not None:
        sbol_doc = sbol.Document()
        sbol_doc.read(path)

    parts_seqs = {
        comp_def.displayId: comp_def.sequence.elements.upper()
        for comp_def in sbol_doc.componentDefinitions
        if comp_def.sequence
    }

    parts_per_construct = [
        (comp_def.displayId, [sbol_doc.getComponentDefinition(
            comp.definition).displayId
            for comp in comp_def.components])
        for comp_def in sbol_doc.componentDefinitions
        if _SO_PLASMID in comp_def.roles
    ]

    constructs_seqs = [
        (construct_name, ''.join([parts_seqs[part] for part in parts]))
        for construct_name, parts in parts_per_construct
    ]

    return parts_seqs, \
        OrderedDict(parts_per_construct), \
        OrderedDict(constructs_seqs)
Beispiel #6
0
def scrape_parts(doc, part_files, parts_list, TARGET_DIR='.'):
    # Scrape parts from files
    # doc is the Document to which the scraped parts will be added
    # part_files should be a list of file names without .xml extension
    for pf in part_files:
        print(pf)
        sbol_in = sbol.Document()
        sbol_in.read(TARGET_DIR + '/' + pf + '.xml')
        print("Components in infile", len(sbol_in.components))

        for i_dc, dc in enumerate(sbol_in.components):
            try:
                if dc.uri in parts_list:
                    dc.move(doc)
            except:
                print('error in ', i_dc)
        libsbol.deleteDocument(sbol_in.ptr)
    return doc
def get_assembly_plan_from_sbol(sbol_doc=None, path=None):
    """Extract an assembly plan from sbol

    Parameters
    ----------

    sbol_doc
      A PySBOL Document() containing the designs and parts sequences. A path
      to a SBOL .xml file can be provided instead.

    path
      A path to a SBOL .xml file
    
    Returns
    -------

    (parts_sequences, parts_per_construct, constructs_sequences)
      Assembly plan data:
      - parts_sequences is of the form ``{part_id: "ATTTGTGTGC..."}``,
      - parts_per_constructs is of the form ``{construct_id: [part_id_1,...]}``
      - constructs_sequences is of the form ``{construct_id: "ATGCCC..."}``.
    """
    if path is not None:
        sbol_doc = sbol.Document()
        sbol_doc.read(path)

    parts_sequences = {
        seq.displayId.replace("_sequence", ""): seq.elements.upper()
        for seq in sbol_doc.sequences
    }
    parts_per_construct = [(component.displayId,
                            [c.displayId[:-2] for c in component.components])
                           for component in sbol_doc.componentDefinitions
                           if len(component.components)]

    constructs_sequences = [
        (construct_name, "".join([parts_sequences[part] for part in parts]))
        for construct_name, parts in parts_per_construct
    ]
    parts_per_construct = OrderedDict(parts_per_construct)
    constructs_sequences = OrderedDict(constructs_sequences)
    return (parts_sequences, parts_per_construct, constructs_sequences)
Beispiel #8
0
import matplotlib.pyplot as plt
from matplotlib import gridspec
from matplotlib.patches import Polygon, Ellipse, Wedge, Circle, PathPatch
from matplotlib.path import Path
from matplotlib.lines import Line2D
from matplotlib.patheffects import Stroke
import matplotlib.patches as patches

__author__ = 'Bryan Der <*****@*****.**>, Voigt Lab, MIT\n\
               Thomas Gorochowski <*****@*****.**>, Voigt Lab, MIT'

__license__ = 'MIT'
__version__ = '1.0'

# Test pySBOL interface
doc = sbol.Document()
doc.read('ExampleAlignment.xml')
target = doc.components['http://sys-bio.org/Design']
module = [None] * 3
module[0] = doc.components['http://sys-bio.org/DC1']
module[1] = doc.components['http://sys-bio.org/DC2']
module[2] = doc.components['http://sys-bio.org/DC3']

# Create the DNAplotlib renderer
dr = dpl_sbol.SBOLRenderer()

design = []
for dc in module:
    SO_term = dc.type.split('/')[-1]
    part = {}
    if SO_term in dr.SO_terms().keys():
Beispiel #9
0
def crispr_tutorial_short():
    sbol.setHomespace('http://sbols.org/CRISPR_Example') 
    doc = sbol.Document()
    
    target_gene = sbol.ComponentDefinition("target_gene", sbol.BIOPAX_DNA)
    target_gene.roles = sbol.SO_PROMOTER
    doc.addComponentDefinition(target_gene)
    target = sbol.ComponentDefinition("target", sbol.BIOPAX_PROTEIN)
    doc.addComponentDefinition(target)


    CRISPR_Template = sbol.ModuleDefinition("CRISPR_Template")
    doc.addModuleDefinition(CRISPR_Template)



    target_gene_fc = CRISPR_Template.functionalComponents.create("target_gene_fc")
    target_gene_fc.definition = target_gene.identity
    target_gene_fc.access = sbol.SBOL_ACCESS_PUBLIC
    target_gene_fc.direction = sbol.SBOL_DIRECTION_IN_OUT

    target_fc = CRISPR_Template.functionalComponents.create("target_fc")
    target_fc.definition = target.identity
    target_fc.access = sbol.SBOL_ACCESS_PUBLIC
    target_fc.direction = sbol.SBOL_DIRECTION_IN_OUT
    
    
    target_generic_gene_inhibition = CRISPR_Template.interactions.create("target_gene_inhibition_interaction")
    target_generic_gene_inhibition.types = sbol.SBO_GENETIC_PRODUCTION
    target_gene_participation = target_generic_gene_inhibition.participations.create("target_gene_participation")
    target_gene_participation.roles = sbol.SBO_PROMOTER
    target_gene_participation.participant = target_gene_fc.identity
    target_participation = target_generic_gene_inhibition.participations.create("target_participation")
    target_participation.roles = sbol.SBO_PRODUCT
    target_participation.participant = target_fc.identity




    gRNA_gene = sbol.ComponentDefinition("gRNA_gene",sbol.BIOPAX_DNA)
    gRNA_gene.roles = sbol.SO_PROMOTER
    doc.addComponentDefinition(gRNA_gene)
    gRNA_b = sbol.ComponentDefinition("gRNA_b",sbol.BIOPAX_RNA)
    gRNA_b.roles = sbol.SO_SGRNA
    doc.addComponentDefinition(gRNA_b)

    CRPb_circuit = sbol.ModuleDefinition("CRPb_characterization_Circuit")
    doc.addModuleDefinition(CRPb_circuit)
    
    gRNA_b_fc = CRPb_circuit.functionalComponents.create("gRNA_b_fc")
    gRNA_b_fc.definition = gRNA_b.identity
    gRNA_b_fc.access = sbol.SBOL_ACCESS_PUBLIC
    gRNA_b_fc.direction = sbol.SBOL_DIRECTION_NONE
    gRNA_b_fc.version = 1
    gRNA_gene_fc = CRPb_circuit.functionalComponents.create("gRNA_gene_fc")
    gRNA_gene_fc.definition = gRNA_gene.identity
    gRNA_gene_fc.access = sbol.SBOL_ACCESS_PUBLIC
    gRNA_gene_fc.direction = sbol.SBOL_DIRECTION_NONE
    gRNA_gene_fc.version = 1



    gRNA_b_production = CRPb_circuit.interactions.create("gRNA_b_production")
    gRNA_b_production.types = sbol.SBO_GENETIC_PRODUCTION
    gRNA_b_gene_participant = gRNA_b_production.participations.create("gRNA_b_gene")
    gRNA_b_gene_participant.roles = sbol.SBO_PROMOTER
    gRNA_b_gene_participant.participant = gRNA_gene_fc.identity
    gRNA_b_participant = gRNA_b_production.participations.create("gRNA_b")
    gRNA_b_participant.roles = sbol.SBO_PRODUCT
    gRNA_b_participant.participant = gRNA_b_fc.identity
    

    gRNA_b_BFP_deg = CRPb_circuit.interactions.create("gRNA_b_BFP_deg")
    gRNA_b_BFP_deg.types = sbol.SBO_DEGRADATION
    gRNA_b_BFP_participant = gRNA_b_BFP_deg.participations.create("gRNA_b_BFP")
    gRNA_b_BFP_participant.roles = sbol.SBO_REACTANT
    gRNA_b_BFP_participant.participant = gRNA_b_fc.identity



    Template_Module = CRPb_circuit.modules.create("CRISPR_Template")
    Template_Module.definition = CRISPR_Template.identity

    gRNA_b_map = Template_Module.mapsTos.create("gRNA_b_map")
    gRNA_b_map.refinement = sbol.SBOL_REFINEMENT_USE_LOCAL
    gRNA_b_map.local = gRNA_b_fc.identity
    gRNA_b_map.remote = gRNA_gene_fc.identity
    gRNA_b_map.name = "Hnelo"


    results = doc.write("CRISPR_example_short_2.xml")
    print(results)