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)
def get_tikz_tree(self, layout_mode): """ Return the tikz text for the tree figure. @param layout_mode: equal_arc vs equal_daylight @return: tikz text """ if layout_mode == 'equal_daylight': v_to_point = FtreeAux.equal_daylight_layout(self.T, self.B, 3) else: v_to_point = FtreeAux.equal_arc_layout(self.T, self.B) # define vertices vertex_lines = [] for v, (x, y) in v_to_point.items(): line = get_vertex_line(v, x, y) vertex_lines.append(line) # draw edges edge_lines = [] for va, vb in self.T: line = get_edge_line(va, vb) edge_lines.append(line) # draw the labels label_lines = [] if self.label_mode == 'label_mode_show': for v, (x, y) in v_to_point.items(): label_lines.append(get_label_line(x, y, self.N_short[v])) elif self.label_mode == 'label_mode_leaf_only': for v in self.leaves: x, y = v_to_point[v] if v in self.N: label_lines.append(get_label_line(x, y, self.N[v])) # return the tikz tikz_lines = vertex_lines + edge_lines + label_lines return '\n'.join(tikz_lines)