Exemplo n.º 1
0
def save_part_as_component_definition(docu, md, part, part_type):
    part_rd = rd.GlyphRenderer()
    comp = sbol.ComponentDefinition(part.name, sbol.BIOPAX_DNA)
    if part_type != sbol.BIOPAX_RNA:
        comp.roles = part_rd.get_so_term(part_type)
    func_comp = md.functionalComponents.create(comp.displayId)
    func_comp.definition = comp
    save_frame_into_file(comp, part.frame.width, part.frame.height,
                         part.frame.origin[0], part.frame.origin[1])
    docu.addComponentDefinition(comp)
Exemplo n.º 2
0
def main():
	print('executed')
	fig = plt.figure(figsize=(5,5))
	ax = fig.add_subplot(111)
	# need to set axis first 
	ax.set_xlim(-50.0, 50.0)
	ax.set_ylim(-50.0, 50.0)

	strand = render.StrandRenderer()
	renderer = render.GlyphRenderer()
	p1 = renderer.draw_glyph(ax, 'Promoter', (-20.0, 0.0), 5., 0)
	i3 = renderer.draw_glyph(ax, 'Insulator', (20.0, -2.5), 5., 0.)
	strand.add_glyphs([p1, i3])
	strand.draw_backbone_strand(ax, 0.0, 2)

	ax.set_axis_off()
	plt.show()
Exemplo n.º 3
0
def add_parts_to_module(mod, raw_md, d):
    renderer = rd.GlyphRenderer()
    for fc in raw_md.functionalComponents:
        c = d.componentDefinitions[fc.displayId]

        # create part
        if sbol.BIOPAX_DNA in c.types:
            part = dt.Part(mod, fc.displayId,
                           renderer.glyph_soterm_map.get(c.roles[0]))
            mod.add_strand_part(part)
        else:
            if sbol.BIOPAX_RNA in c.types:
                part = dt.Part(mod, fc.displayId, 'RNA')
            elif sbol.BIOPAX_PROTEIN in c.types:
                part = dt.Part(mod, fc.displayId, 'Macromolecule')
            else:
                part = dt.Part(mod, fc.displayId, 'Unspecified')
            mod.add_non_strand_part(part)

    return mod
Exemplo n.º 4
0
def draw_module(ax,
                module,
                module_frame,
                glyph_size,
                module_spacer,
                haveBackbone=True):
    glyph_pos = [
        module_frame.origin[0] + 3 * module_spacer,
        module_frame.origin[1] + 1.5 * module_spacer
    ]
    renderer = rd.GlyphRenderer()
    strand_rd = rd.StrandRenderer()
    module_rd = rd.ModuleRenderer()

    # check whether module is empty or not
    if module.part_list == None:
        if len(module.children) != 0:
            return module_rd.draw_empty_module_box(ax, module_frame)
        elif len(module.other_parts) == 0:
            return

    # draw each glyphs in module part list
    else:
        module.part_list.position = glyph_pos
        for part in module.part_list.parts:
            part.frame = rd.Frame(width=glyph_size,
                                  height=glyph_size,
                                  origin=glyph_pos)
            child = renderer.draw_glyph(ax, part.type, glyph_pos, glyph_size,
                                        0.)
            strand_rd.add_glyphs(child)
            module_rd.add_parts(child)
            glyph_pos = [
                glyph_pos[0] + glyph_size + module_spacer, glyph_pos[1]
            ]

    # draw backbone
    if haveBackbone and module.part_list != None:
        bb = strand_rd.draw_backbone_strand(ax, glyph_pos[1], module_spacer)
        module_rd.add_parts(bb)
        module.part_list.position = bb['frame'].origin

    # draw other parts
    if len(module.other_parts) != 0:
        op_pos_list = __get_other_part_pos(len(module.other_parts),
                                           module_frame, glyph_size,
                                           glyph_size, module_spacer)
        other_part_frames = []
        for i, other_part in enumerate(module.other_parts):
            other_part.frame = rd.Frame(width=glyph_size,
                                        height=glyph_size,
                                        origin=op_pos_list[i])
            other_part_frames.append(other_part.frame)
            other_child = renderer.draw_glyph(ax, other_part.type,
                                              op_pos_list[i], glyph_size, 0.)
            module_rd.add_parts(other_child)

        # do not draw module frame box if only has other part
        if module.part_list == None:
            return get_biggest_module_frame(other_part_frames, module_spacer)

    return module_rd.draw_module_box(ax, module_spacer, module_spacer)
Exemplo n.º 5
0
'''
rough script for rendering three glyphs onto one module
need to be moved outside the example directory 
at the same directory as render.py
'''

import render
import matplotlib.pyplot as plt

# default setting
strand = render.StrandRenderer()
renderer = render.GlyphRenderer()
module = render.ModuleRenderer()

print(renderer.glyphs_library)
print('------------')
print(renderer.glyph_soterm_map)

fig = plt.figure(figsize=(5, 5))
ax = fig.add_subplot(111)
# need to set axis first
ax.set_xlim(-50.0, 50.0)
ax.set_ylim(-50.0, 50.0)

p1 = renderer.draw_glyph(ax, 'Promoter', (-20.0, 0.0), 10., 0)
ori2 = renderer.draw_glyph(ax, 'OriginOfReplication', (0.0, -5.), 10., 0)
i3 = renderer.draw_glyph(ax, 'Insulator', (20.0, -5.), 10., 0.)
strand.add_glyphs([p1, ori2, i3])
bb = strand.draw_backbone_strand(ax, 0., 1.5)
module.add_parts([p1, ori2, i3, bb])
module_frame = module.draw_module_box(
Exemplo n.º 6
0
def draw_module(ax,
                module,
                module_frame,
                glyph_size,
                module_spacer,
                haveBackbone=True,
                user_spec=None):
    strand_adjustment = __get_strand_adjustment(module.part_list, user_spec,
                                                glyph_size)
    glyph_pos = [
        module_frame.origin[0] + 3 * module_spacer,
        module_frame.origin[1] + 1.5 * module_spacer + strand_adjustment
    ]
    renderer = rd.GlyphRenderer()
    strand_rd = rd.StrandRenderer()
    module_rd = rd.ModuleRenderer()

    # check whether module is empty or not
    if module.part_list == None:
        if len(module.children) != 0 and len(module.other_parts) == 0:
            return module_rd.draw_module_box(ax, module_frame)

    # draw each glyphs in module part list
    else:
        module.part_list.position = glyph_pos
        custom_glyph_size = glyph_size
        for part in module.part_list.parts:
            if part.type in LOWER_ORIGIN_GLYPHS:  # adjust for cds etc
                glyph_pos[1] -= strand_adjustment
            if __check_custom_size(part.name, user_spec,
                                   glyph_size) != glyph_size:  # user_param
                glyph_size *= __check_custom_size(part.name, user_spec)

            #rendering
            part.frame = rd.Frame(width=glyph_size,
                                  height=glyph_size,
                                  origin=glyph_pos)
            child = renderer.draw_glyph(ax,
                                        part.type,
                                        glyph_pos,
                                        glyph_size,
                                        0.,
                                        user_parameters=__find_right_spec(
                                            part.name, user_spec))
            strand_rd.add_glyphs(child)
            module_rd.add_parts(child)

            # prepare for next part
            if part.type in LOWER_ORIGIN_GLYPHS:
                glyph_pos[1] += strand_adjustment
            glyph_pos = [
                glyph_pos[0] + glyph_size + module_spacer, glyph_pos[1]
            ]
            if custom_glyph_size != glyph_size: glyph_size = custom_glyph_size

    # draw backbone
    if haveBackbone and module.part_list != None:
        bb = strand_rd.draw_backbone_strand(ax, glyph_pos[1], module_spacer)
        module_rd.add_parts(bb)
        module.part_list.position = bb['frame'].origin

    # draw other parts
    if len(module.other_parts) != 0:
        op_pos_list = __get_other_part_pos(len(module.other_parts),
                                           module_frame, glyph_size,
                                           glyph_size, module_spacer)
        other_part_frames = []
        for i, other_part in enumerate(module.other_parts):
            other_part.frame = rd.Frame(width=glyph_size,
                                        height=glyph_size,
                                        origin=op_pos_list[i])
            other_part_frames.append(other_part.frame)
            other_child = renderer.draw_glyph(
                ax,
                other_part.type,
                op_pos_list[i],
                glyph_size,
                user_parameters=__find_right_spec(other_part.name, user_spec))
            module_rd.add_parts(other_child)

    return module_rd.draw_module_box(ax, module_frame)