Exemple #1
0
def main():
    '''main method.'''
    doc = Document()
    doc.read('sbol.xml')

    for seq in doc.sequences:
        print seq.identity.get()
        print seq.elements.get()

    doc.write('out.xml')
Exemple #2
0
def write(dna, filename=None):
    '''Writes a Dna object to SBOL v2.'''
    doc = Document()

    comp_def = ComponentDefinition(dna['disp_id'])
    doc.addComponentDefinition(comp_def)
    _write_dna_comp(comp_def, dna)

    seq = Sequence(get_disp_id(), dna['seq'], SBOL_ENCODING_IUPAC)
    doc.addSequence(seq)

    for feature in dna['features']:
        annot = SequenceAnnotation(feature['disp_id'])
        comp_def.sequenceAnnotations.add(annot)
        _write_dna_comp(annot, feature)

        rnge = Range(get_disp_id())
        annot.locations.add(rnge)
        rnge.start = feature['start']
        rnge.end = feature['end']
        rnge.orientation = SBOL_ORIENTATION_INLINE if feature['forward'] \
            else SBOL_ORIENTATION_REVERSE_COMPLEMENT

    doc.write(filename)

    return doc
Exemple #3
0
def read(filename):
    '''Parses SBOL v1.'''
    doc = Document()
    doc.read(filename)

    comp_def = doc.componentDefinitions[0]

    params = _read_dna_comp(comp_def)
    params.update({'seq': doc.sequences[0].elements})
    dna = DNA(**params)

    for annot in comp_def.sequenceAnnotations:
        _read_annot(dna, annot)

    return dna
def crispr_test():
    '''Simple example.'''
    setHomespace('http://sys-bio.org')
    doc = Document()

    mkate, _ = _add_comp_def(doc, 'mKate')
    gal4vp16, _ = _add_comp_def(doc, 'gal4vp16')
    pconst, _ = _add_comp_def(doc, 'pconst', SO_PROMOTER, 'atgtaa')
    mkate_cds, _ = _add_comp_def(doc, 'mkate_cds', SO_CDS, 'attcga')
    gal4vp16_cds, _ = _add_comp_def(doc, 'gal4vp16_cds', SO_CDS, 'attcga')
    mkate_gene, mkate_gene_seq = _add_comp_def(doc, 'mkate_gene')
    gal4vp16_gene, gal4vp16_gene_seq = _add_comp_def(doc, 'gal4vp16_gene')

    mkate_gene.assemble([pconst, mkate_cds])
    gal4vp16_gene.assemble([pconst, gal4vp16_cds])

    mkate_gene_seq.assemble()
    print mkate_gene_seq.elements.get()

    gal4vp16_gene_seq.assemble()
    print gal4vp16_gene_seq.elements.get()

    doc.write('crispr.xml')
def _convert(rct_uniprot, tirs, max_prot_per_react):
    '''Convert.'''
    setHomespace('http://liverpool.ac.uk')
    doc = Document()

    for rct, uniprot_ids_set in rct_uniprot.items():
        # Specify uniprot-specific assembly region placeholders:
        # (Provides consistent assembly sequence for each reaction group.)
        _5p_assembly = ComponentDefinition('%s_5_prime_assembly' % rct)
        _5p_assembly.roles = dna_utils.SO_ASS_COMP
        _3p_assembly = ComponentDefinition('%s_3_prime_assembly' % rct)
        _3p_assembly.roles = dna_utils.SO_ASS_COMP

        doc.addComponentDefinition([_5p_assembly, _3p_assembly])

        for uniprot_id in uniprot_ids_set[:max_prot_per_react]:
            if tirs:
                for tir in tirs:
                    _add_gene(doc, uniprot_id, tir, _5p_assembly, _3p_assembly)
            else:
                _add_gene(doc, uniprot_id, None, _5p_assembly, _3p_assembly)

    return doc
def combinatorial1():
    '''Combinatorial example.'''
    libsbol.setHomespace('http://www.synbiochem.ac.uk')
    doc = Document()

    # SPECIFY POSITIONS #

    # Specify top-level ComponentDefinition and positional Components....
    top = ComponentDefinition('top')
    pos1cd = ComponentDefinition('pos1cd')
    pos2cd = ComponentDefinition('pos2cd')
    pos3cd = ComponentDefinition('pos3cd')
    doc.addComponentDefinition(top)
    doc.addComponentDefinition(pos1cd)
    doc.addComponentDefinition(pos2cd)
    doc.addComponentDefinition(pos3cd)

    pos1c = top.components.create('pos1c')
    pos2c = top.components.create('pos2c')
    pos3c = top.components.create('pos3c')
    pos1c.definition.set(pos1cd.identity.get())
    pos2c.definition.set(pos2cd.identity.get())
    pos3c.definition.set(pos3cd.identity.get())

    # Specify positional SequenceConstraints...
    # pos1 - pos2 - pos3

    pos_sq1 = top.sequenceConstraints.create('pos_sq1')
    pos_sq1.subject.set(pos1c.identity.get())
    pos_sq1.object.set(pos2c.identity.get())
    pos_sq1.restriction.set(SBOL_RESTRICTION_PRECEDES)

    pos_sq2 = top.sequenceConstraints.create('pos_sq2')
    pos_sq2.subject.set(pos2c.identity.get())
    pos_sq2.object.set(pos3c.identity.get())
    pos_sq2.restriction.set(SBOL_RESTRICTION_PRECEDES)

    # SPECIFY 'PARTS' #

    # Specify ComponentDefinitions....
    rbs1cd = ComponentDefinition('rbs1cd')
    rbs2cd = ComponentDefinition('rbs2cd')
    cds1cd = ComponentDefinition('cds1cd')
    cds2cd = ComponentDefinition('cds2cd')

    doc.addComponentDefinition(rbs1cd)
    doc.addComponentDefinition(rbs2cd)
    doc.addComponentDefinition(cds1cd)
    doc.addComponentDefinition(cds2cd)

    # Specify sequences...
    rbs1_seq = Sequence('rbs1cd', 'aaaa', SBOL_ENCODING_IUPAC)
    rbs2_seq = Sequence('rbs2cd', 'cccc', SBOL_ENCODING_IUPAC)
    cds1_seq = Sequence('cds1cd', 'gggg', SBOL_ENCODING_IUPAC)
    cds2_seq = Sequence('cds2cd', 'attcga', SBOL_ENCODING_IUPAC)
    doc.addSequence(rbs1_seq)
    doc.addSequence(rbs2_seq)
    doc.addSequence(cds1_seq)
    doc.addSequence(cds2_seq)

    # Associate sequences with ComponentDefinition...
    rbs1cd.sequence.set(rbs1_seq.identity.get())
    rbs2cd.sequence.set(rbs2_seq.identity.get())
    cds1cd.sequence.set(cds1_seq.identity.get())
    cds2cd.sequence.set(cds2_seq.identity.get())

    # In SBOL Compliant mode, use create methods to add child objects, instead
    # of constructors and add methods (open-world mode)
    rbs1c = top.components.create('rbs1c')
    rbs2c = top.components.create('rbs2c')
    cds1c = top.components.create('cds1c')
    cds2c = top.components.create('cds2c')

#    # Add components...
#    rbs1c = Component('rbs1c')
#    rbs2c = Component('rbs2c')
#    cds1c = Component('cds1c')
#    cds2c = Component('cds2c')
#    top.components.add(rbs1c)
#    top.components.add(rbs2c)
#    top.components.add(cds1c)
#    top.components.add(cds2c)

    # Associate Components to ComponentDefintions...
    rbs1c.definition.set(pos1cd.identity.get())
    rbs2c.definition.set(pos1cd.identity.get())
    cds1c.definition.set(pos2cd.identity.get())
    cds2c.definition.set(pos2cd.identity.get())

    # The following was causing a segmentation fault!!!  Note that rbs1c
    # already belongs to top.components.
    # A child object can't belong to two parent objects.
    # Unfortunately, this is a tricky error to catch...
#    rbs1cd.components.add(rbs1c)
#    rbs2cd.components.add(rbs2c)
#    cds1cd.components.add(cds1c)
#    cds2cd.components.add(cds2c)

    # SPECIFY COMBINATORIAL CONSTRAINTS #

    # Position 1 can be either rbs1c or rbs2...
    combin_pos1_1 = top.sequenceConstraints.create('combin_pos1_1')
    combin_pos1_1.subject.set(pos1c.identity.get())
    combin_pos1_1.object.set(rbs1c.identity.get())
    combin_pos1_1.restriction.set('can_be')

    combin_pos1_2 = top.sequenceConstraints.create('combin_pos1_2')
    combin_pos1_2.subject.set(pos1c.identity.get())
    combin_pos1_2.object.set(rbs2c.identity.get())
    combin_pos1_2.restriction.set('can_be')

#    combin_pos1_1 = SequenceConstraint(
#        'combin_pos1_1', 'pos1c', 'rbs1c', 'can_be')
#    combin_pos1_2 = SequenceConstraint(
#        'combin_pos1_2', 'pos1c', 'rbs2c', 'can_be')
#    top.sequenceConstraints.add(combin_pos1_1)
#    top.sequenceConstraints.add(combin_pos1_2)

    # Position 2 can be either cds1c or cds2c...
    combin_pos2_1 = top.sequenceConstraints.create('combin_pos2_1')
    combin_pos2_1.subject.set(pos2c.identity.get())
    combin_pos2_1.object.set(cds1c.identity.get())
    combin_pos2_1.restriction.set('can_be')

    combin_pos2_2 = top.sequenceConstraints.create('combin_pos2_2')
    combin_pos2_2.subject.set(pos2c.identity.get())
    combin_pos2_2.object.set(cds2c.identity.get())
    combin_pos2_2.restriction.set('can_be')

#    combin_pos2_1 = SequenceConstraint(
#        'combin_pos2_1', 'pos2c', 'cds1c', 'can_be')
#    combin_pos2_2 = SequenceConstraint(
#        'combin_pos2_2', 'pos2c', 'cds2c', 'can_be')
#    top.sequenceConstraints.add(combin_pos2_1)
#    top.sequenceConstraints.add(combin_pos2_2)

    # Position 3 can be either cds1c or cds2c...
    combin_pos3_1 = top.sequenceConstraints.create('combin_pos3_1')
    combin_pos3_1.subject.set(pos3c.identity.get())
    combin_pos3_1.object.set(cds1c.identity.get())
    combin_pos3_1.restriction.set('can_be')

    combin_pos3_2 = top.sequenceConstraints.create('combin_pos3_2')
    combin_pos3_2.subject.set(pos3c.identity.get())
    combin_pos3_2.object.set(cds2c.identity.get())
    combin_pos3_2.restriction.set('can_be')

#    combin_pos3_1 = SequenceConstraint(
#        'combin_pos3_1', 'pos3c', 'cds1c', 'can_be')
#    combin_pos3_2 = SequenceConstraint(
#        'combin_pos3_2', 'pos3c', 'cds2c', 'can_be')
#    top.sequenceConstraints.add(combin_pos3_1)
#    top.sequenceConstraints.add(combin_pos3_2)

    # But the Component at Position 2 cannot be the same as Position 3...
    combin_pos_not_eq = top.sequenceConstraints.create('combin_pos_not_eq')
    combin_pos_not_eq.subject.set(pos2c.identity.get())
    combin_pos_not_eq.object.set(pos3c.identity.get())
    combin_pos_not_eq.restriction.set('not_equal')

#    combin_pos_not_eq = SequenceConstraint(
#        'combin_pos_not_eq', 'pos2c', 'pos2c', 'not_equal')
#    top.sequenceConstraints.add(combin_pos_not_eq)

    for comp_def in doc.componentDefinitions:
        print comp_def.identity.get()

    doc.write('combinatorial.xml')
Exemple #7
0
def to_query(filename, taxonomy_id):
    '''Convert SBOL documents to PartsGenie query.'''
    doc = Document()
    doc.read(filename)
    return _to_query(doc, taxonomy_id)
Exemple #8
0
def example1():
    '''Simple example.'''
    setHomespace("http://sys-bio.org")
    doc = Document()

    gene = ComponentDefinition("BB0001")
    promoter = ComponentDefinition("R0010")
    cds = ComponentDefinition("B0032")
    rbs = ComponentDefinition("E0040")
    terminator = ComponentDefinition("B0012")

    promoter.roles.set(SO_PROMOTER)
    cds.roles.set(SO_CDS)
    rbs.roles.set(SO_RBS)
    terminator.roles.set(SO_TERMINATOR)

    doc.addComponentDefinition(gene)
    doc.addComponentDefinition(promoter)
    doc.addComponentDefinition(cds)
    doc.addComponentDefinition(rbs)
    doc.addComponentDefinition(terminator)

    gene.assemble([promoter, rbs, cds, terminator])

    first = gene.getFirstComponent()
    print first.identity.get()
    last = gene.getLastComponent()
    print last.identity.get()

    # promoter_seq = Sequence("R0010", "ggctgca")
    # rbs_seq = Sequence("B0032", "aattatataaa")
    # cds_seq = Sequence("E0040", "atgtaa")
    # terminator_seq = Sequence("B0012", "attcga")
    # gene_seq = Sequence("BB0001")

    # doc.addSequence(promoter_seq)
    # doc.addSequence(cds_seq)
    # doc.addSequence(rbs_seq)
    # doc.addSequence(terminator_seq)
    # doc.addSequence(gene_seq)

    # promoter.sequence.set(promoter_seq.identity.get())
    # cds.sequence.set(cds_seq.identity.get())
    # rbs.sequence.set(rbs_seq.identity.get())
    # terminator.sequence.set(terminator_seq.identity.get())
    # gene.sequence.set(gene_seq.identity.get())

    # gene_seq.assemble()
    # print gene_seq.elements.get()

    doc.write("gene_cassette.xml")

    # Round trip...
    doc.write('gene_cassette.xml')

    new_doc = Document()
    new_doc.read('gene_cassette.xml')
    new_doc.write('gene_cassette_out.xml')
Exemple #9
0
 def __init__(self, *, namespace: str, trace: ProvenanceTrace = None):
     # TODO: is it sufficient for homespace to be set at document init?
     setHomespace(namespace)
     self.doc = Document()
     super().__init__(trace)