Example #1
0
def get_response_content(fs):
    """
    @param fs: a FieldStorage object containing the cgi arguments
    @return: the response
    """
    # get a properly formatted newick tree with branch lengths
    T, B, N = FtreeIO.newick_to_TBN(fs.tree)
    # get the vertex valuations
    all_valuations = TB_to_harmonic_valuations(T, B)
    valuations = all_valuations[fs.first_index:]
    nfigures = (fs.last_index - fs.first_index) + 1
    # do the layout
    if fs.equal_arc_layout:
        v_to_location = FtreeAux.equal_arc_layout(T, B)
    elif fs.equal_daylight_layout:
        v_to_location = FtreeAux.equal_daylight_layout(T, B, 3)
    # draw the image
    physical_size = (fs.width, fs.height)
    tikzpicture = DrawEigenLacing.get_forest_image_ftree(
            T, B, N, v_to_location,
            physical_size, valuations, nfigures, fs.inner_margin,
            fs.reflect_trees, fs.show_vertex_labels, fs.show_subfigure_labels)
    packages = []
    preamble = '\\usetikzlibrary{snakes}'
    return tikz.get_figure_response(
            tikzpicture, fs.tikzformat, g_figure_caption, g_figure_label,
            packages, preamble)
Example #2
0
def get_response_content(fs):
    # get a properly formatted newick tree with branch lengths
    tree_string = '((1:1, 2:1)6:1, 3:1, (4:1, 5:1)7:1)8;'
    tree = Newick.parse(tree_string, SpatialTree.SpatialTree)
    # get the fiedler-like vertex valuation
    fiedler = [1, 1, -1, -1, -1, 1, -1, -1]
    # create a node id map
    ids = [None]*8
    for node in tree.preorder():
        index = int(node.name) - 1
        ids[index] = id(node)
    # convert fiedler into a dictionary
    v1 = dict((ids[i], float(fiedler[i])) for i in range(8))
    # convert the annotations into dictionaries
    v2s = [dict((ids[i], float(v[i])) for i in range(8)) for v in g_annotation]
    # do the layout
    try:
        layout = FastDaylightLayout.StraightBranchLayout()
        layout.do_layout(tree)
    except RuntimeError as e:
        pass
    # draw the image
    try:
        ext = Form.g_imageformat_to_ext[fs.imageformat]
        return DrawEigenLacing.get_eg2_image(
                tree, (640, 480), ext,
                v1, v2s,
                fs.draw_background, fs.draw_vertices, fs.draw_labels)
    except CairoUtil.CairoUtilError as e:
        raise HandlingError(e)
Example #3
0
def get_response_content(fs):
    # get a properly formatted newick tree with branch lengths
    tree_string = '((1:1, 2:1)6:1, 3:1, (4:1, 5:1)7:1)8;'
    tree = Newick.parse(tree_string, SpatialTree.SpatialTree)
    # get the fiedler-like vertex valuation
    fiedler = [1, 1, -1, -1, -1, 1, -1, -1]
    # create a node id map
    ids = [None] * 8
    for node in tree.preorder():
        index = int(node.name) - 1
        ids[index] = id(node)
    # convert fiedler into a dictionary
    v1 = dict((ids[i], float(fiedler[i])) for i in range(8))
    # convert the annotations into dictionaries
    v2s = [dict((ids[i], float(v[i])) for i in range(8)) for v in g_annotation]
    # do the layout
    try:
        layout = FastDaylightLayout.StraightBranchLayout()
        layout.do_layout(tree)
    except RuntimeError as e:
        pass
    # draw the image
    try:
        ext = Form.g_imageformat_to_ext[fs.imageformat]
        return DrawEigenLacing.get_eg2_image(tree, (640, 480), ext, v1, v2s,
                                             fs.draw_background,
                                             fs.draw_vertices, fs.draw_labels)
    except CairoUtil.CairoUtilError as e:
        raise HandlingError(e)
Example #4
0
def get_response_content(fs):
    # get a properly formatted newick tree with branch lengths
    tree = Newick.parse(fs.tree, SpatialTree.SpatialTree)
    # get the vertex valuations
    id_to_v1 = Harmonic.get_harmonic_valuations(tree, fs.eig_idx1)
    id_to_v2 = Harmonic.get_harmonic_valuations(tree, fs.eig_idx2)
    # do the layout
    try:
        layout = FastDaylightLayout.StraightBranchLayout()
        layout.do_layout(tree)
    except RuntimeError as e:
        pass
    # draw the image
    try:
        ext = Form.g_imageformat_to_ext[fs.imageformat]
        return DrawEigenLacing.get_single_tree_image(
                tree, (640, 480), ext, id_to_v1, id_to_v2)
    except CairoUtil.CairoUtilError as e:
        raise HandlingError(e)
Example #5
0
def draw_labels_ftree(T, N, context, v_to_location):
    """
    Use degree anchors for label placement.
    """
    for v in Ftree.T_to_order(T):
        if v not in N:
            continue
        label = N[v]
        # get the parameters for the label
        theta = DrawEigenLacing.get_free_angle_ftree(T, v, v_to_location)
        x, y = v_to_location[v]
        # draw the text relative to the location
        theta += math.pi
        float_degree = ((theta % (2 * math.pi)) * 360) / (2 * math.pi)
        degree = int(math.floor(float_degree))
        #style = 'anchor=%s,inner sep=1pt' % degree
        style = 'anchor=%s' % degree
        context.add_line('\\node[%s] at (%.4f,%.4f) {%s};' %
                         (style, x, y, label))
Example #6
0
def get_response_content(fs):
    # get a properly formatted newick tree with branch lengths
    tree = Newick.parse(fs.tree, SpatialTree.SpatialTree)
    # get the vertex valuations
    id_to_v1 = Harmonic.get_harmonic_valuations(tree, fs.eig_idx1)
    id_to_v2 = Harmonic.get_harmonic_valuations(tree, fs.eig_idx2)
    # do the layout
    try:
        layout = FastDaylightLayout.StraightBranchLayout()
        layout.do_layout(tree)
    except RuntimeError as e:
        pass
    # draw the image
    try:
        ext = Form.g_imageformat_to_ext[fs.imageformat]
        return DrawEigenLacing.get_single_tree_image(tree, (640, 480), ext,
                                                     id_to_v1, id_to_v2)
    except CairoUtil.CairoUtilError as e:
        raise HandlingError(e)
Example #7
0
def draw_labels_ftree(T, N, context, v_to_location):
    """
    Use degree anchors for label placement.
    """
    for v in Ftree.T_to_order(T):
        if v not in N:
            continue
        label = N[v]
        # get the parameters for the label
        theta = DrawEigenLacing.get_free_angle_ftree(T, v, v_to_location)
        x, y = v_to_location[v]
        # draw the text relative to the location
        theta += math.pi
        float_degree = ((theta % (2 * math.pi)) * 360) / (2 * math.pi)
        degree = int(math.floor(float_degree))
        #style = 'anchor=%s,inner sep=1pt' % degree
        style = 'anchor=%s' % degree
        context.add_line(
                '\\node[%s] at (%.4f,%.4f) {%s};' % (
                    style, x, y, label))
Example #8
0
def get_response_content(fs):
    # get a properly formatted newick tree with branch lengths
    tree = Newick.parse(fs.tree, SpatialTree.SpatialTree)
    # get the vertex valuations
    valuations = [Harmonic.get_harmonic_valuations(
        tree, i) for i in range(fs.first_index, fs.last_index+1)]
    # do the layout
    try:
        layout = FastDaylightLayout.StraightBranchLayout()
        layout.do_layout(tree)
    except RuntimeError as e:
        pass
    # draw the image
    try:
        ext = Form.g_imageformat_to_ext[fs.imageformat]
        return DrawEigenLacing.get_forest_image(
                tree, (640, 480), ext, valuations,
                fs.draw_background, fs.draw_vertices, fs.draw_labels)
    except CairoUtil.CairoUtilError as e:
        raise HandlingError(e)
Example #9
0
def get_response_content(fs):
    # get a properly formatted newick tree with branch lengths
    tree = Newick.parse(fs.tree, SpatialTree.SpatialTree)
    # get the vertex valuations
    valuations = [
        Harmonic.get_harmonic_valuations(tree, i)
        for i in range(fs.first_index, fs.last_index + 1)
    ]
    # do the layout
    try:
        layout = FastDaylightLayout.StraightBranchLayout()
        layout.do_layout(tree)
    except RuntimeError as e:
        pass
    # draw the image
    try:
        ext = Form.g_imageformat_to_ext[fs.imageformat]
        physical_size = (fs.width, fs.height)
        return DrawEigenLacing.get_forest_image_revised(
            tree, physical_size, ext, valuations, fs.draw_background,
            fs.draw_labels, fs.inner_margin, fs.outer_margin, fs.reflect_trees)
    except CairoUtil.CairoUtilError as e:
        raise HandlingError(e)