def layout(node): node.img_style["size"] = 5 node.img_style["hz_line_width"] = 0 node.img_style["vt_line_width"] = 0 if node.is_leaf(): f = faces.AttrFace("name", fgcolor="steelblue", fsize=20) faces.add_face_to_node(f, node, 0, position="aligned") f = faces.AttrFace("name", fsize=15) faces.add_face_to_node(f, node, 0, position="branch-right") else: f = faces.TextFace("uno", fsize=8) for x in xrange(random.randint(1, 5)): faces.add_face_to_node(f, node, 0, position="branch-top") f = faces.TextFace("otromassssssssssss", fsize=8) for x in xrange(random.randint(1, 5)): faces.add_face_to_node(f, node, 0, position="branch-bottom") f = faces.CircleFace(20, "red") f.opacity = 0.3 faces.add_face_to_node(f, node, 0, position="float") f = faces.CircleFace(23, "blue") f.opacity = 0.3 faces.add_face_to_node(f, node, 0, position="float-behind")
def npr_layout(node): if node.is_leaf(): name = faces.AttrFace("name", fsize=12) faces.add_face_to_node(name, node, 0, position="branch-right") if hasattr(node, "sequence"): seq_face = faces.SeqFace(node.sequence, []) faces.add_face_to_node(seq_face, node, 0, position="aligned") if "alg_type" in node.features: faces.add_face_to_node(faces.AttrFace("alg_type", fsize=8), node, 0, position="branch-top") ttype = faces.AttrFace("tree_type", fsize=8, fgcolor="DarkBlue") faces.add_face_to_node(ttype, node, 0, position="branch-top") #ttype.background.color = "DarkOliveGreen" node.img_style["size"] = 20 node.img_style["fgcolor"] = "red" if "treemerger_rf" in node.features: faces.add_face_to_node(faces.AttrFace("treemerger_rf", fsize=8), node, 0, position="branch-bottom") support_radius = (1.0 - node.support) * 50 if not node.is_leaf() and support_radius > 1: support_face = faces.CircleFace(support_radius, "red") faces.add_face_to_node(support_face, node, 0, position="float-behind") support_face.opacity = 0.25 faces.add_face_to_node(faces.AttrFace("support", fsize=8), node, 0, position="branch-bottom") if "clean_alg_mean_identn" in node.features: identity = node.clean_alg_mean_identn elif "alg_mean_identn" in node.features: identity = node.alg_mean_identn if "highlighted" in node.features: node.img_style["bgcolor"] = "LightCyan" if "npr_iter" in node.features: node.img_style["size"] = 50 if "improve" in node.features: color = "orange" if float(node.improve) < 0 else "green" if float(node.improve) == 0: color = "blue" support_face = faces.CircleFace(200, color) faces.add_face_to_node(support_face, node, 0, position="float-behind")
def ncbi_layout(node): npr_layout(node) global name2color if node.is_leaf(): tax_pos = 10 if hasattr(node, "lineage"): for tax, k in zip(node.lineage, node.named_lineage): f = faces.TextFace("%10s" % k, fsize=15) try: color = name2color[k] except KeyError: name2color[k] = color = treeview.main.random_color() #if hasattr(node, "broken_groups") and tax in node.broken_groups: f.background.color = color faces.add_face_to_node(f, node, tax_pos, position="aligned") tax_pos += 1 f = faces.AttrFace("spname", fsize=15) faces.add_face_to_node(f, node, 10, position="branch-right") else: if getattr(node, "broken_groups", None): for broken in node.broken_groups: f = faces.TextFace(broken, fsize=10, fgcolor="red") faces.add_face_to_node(f, node, 1, position="branch-bottom") if hasattr(node, "changed"): if node.changed == "yes": node.img_style["bgcolor"] = "indianred" else: node.img_style["bgcolor"] = "white"
# Creates a random tree with 8 leaves using a given set of names # t.populate(8, ["Dme", "Dre", "Hsa", "Ptr", "Cfa", "Mms"]) # Set the path in which images are located img_path = "./" # Create faces based on external images humanFace = faces.ImgFace(img_path + "human.png") mouseFace = faces.ImgFace(img_path + "mouse.png") dogFace = faces.ImgFace(img_path + "dog.png") chimpFace = faces.ImgFace(img_path + "chimp.png") fishFace = faces.ImgFace(img_path + "fish.png") flyFace = faces.ImgFace(img_path + "fly.png") # Create a faces ready to read the name attribute of nodes #nameFace = faces.TextFace(open("text").readline().strip(), fsize=20, fgcolor="#009000") nameFace = faces.AttrFace("name", fsize=20, fgcolor="#009000") # Create a conversion between leaf names and real names code2name = { "Dre": "Drosophila melanogaster", "Dme": "Danio rerio", "Hsa": "H**o sapiens", "Ptr": "Pan troglodytes", "Mms": "Mus musculus", "Cfa": "Canis familiaris" } # Creates a dictionary with the descriptions of each leaf name code2desc = { "Dre": """
def get_example_tree(): t = Tree() t.populate(10) # Margins, alignment, border, background and opacity can now be set for any face rs1 = faces.TextFace("branch-right\nmargins&borders", fsize=12, fgcolor="#009000") rs1.margin_top = 10 rs1.margin_bottom = 50 rs1.margin_left = 40 rs1.margin_right = 40 rs1.border.width = 1 rs1.background.color = "lightgreen" rs1.inner_border.width = 0 rs1.inner_border.line_style = 1 rs1.inner_border.color = "red" rs1.opacity = 0.6 rs1.hz_align = 2 # 0 left, 1 center, 2 right rs1.vt_align = 1 # 0 left, 1 center, 2 right br1 = faces.TextFace("branch-right1", fsize=12, fgcolor="#009000") br2 = faces.TextFace("branch-right3", fsize=12, fgcolor="#009000") # New face positions (branch-top and branch-bottom) bb = faces.TextFace("branch-bottom 1", fsize=8, fgcolor="#909000") bb2 = faces.TextFace("branch-bottom 2", fsize=8, fgcolor="#909000") bt = faces.TextFace("branch-top 1", fsize=6, fgcolor="#099000") # And faces can also be used as headers or foot notes of aligned # columns t1 = faces.TextFace("Header Face", fsize=12, fgcolor="#aa0000") t2 = faces.TextFace("Footer Face", fsize=12, fgcolor="#0000aa") # Attribute faces can now contain prefix and suffix fixed text aligned = faces.AttrFace("name", fsize=12, fgcolor="RoyalBlue", text_prefix="Aligned (", text_suffix=")") # horizontal and vertical alignment per face aligned.hz_align = 1 # 0 left, 1 center, 2 right aligned.vt_align = 1 # Node style handling is no longer limited to layout functions. You # can now create fixed node styles and use them many times, save them # or even add them to nodes before drawing (this allows to save and # reproduce an tree image design) style = NodeStyle() style["fgcolor"] = "Gold" style["shape"] = "square" style["size"] = 15 style["vt_line_color"] = "#ff0000" t.set_style(style) # add a face to the style. This face will be render in any node # associated to the style. fixed = faces.TextFace("FIXED branch-right", fsize=11, fgcolor="blue") t.add_face(fixed, column=1, position="branch-right") # Bind the precomputed style to the root node # ETE 2.1 has now support for general image properties ts = TreeStyle() # You can add faces to the tree image (without any node # associated). They will be used as headers and foot notes of the # aligned columns (aligned faces) ts.aligned_header.add_face(t1, column=0) ts.aligned_header.add_face(t1, 1) ts.aligned_header.add_face(t1, 2) ts.aligned_header.add_face(t1, 3) t1.hz_align = 1 # 0 left, 1 center, 2 right t1.border.width = 1 ts.aligned_foot.add_face(t2, column=0) ts.aligned_foot.add_face(t2, 1) ts.aligned_foot.add_face(t2, 2) ts.aligned_foot.add_face(t2, 3) t2.hz_align = 1 # Set tree image style. Note that aligned header and foot is only # visible in "rect" mode. ts.mode = "r" ts.scale = 10 for node in t.traverse(): # If node is a leaf, add the nodes name and a its scientific # name if node.is_leaf(): node.add_face(aligned, column=0, position="aligned") node.add_face(aligned, column=1, position="aligned") node.add_face(aligned, column=3, position="aligned") else: node.add_face(bt, column=0, position="branch-top") node.add_face(bb, column=0, position="branch-bottom") node.add_face(bb2, column=0, position="branch-bottom") node.add_face(br1, column=0, position="branch-right") node.add_face(rs1, column=0, position="branch-right") node.add_face(br2, column=0, position="branch-right") return t, ts
def tree_renderer(tree, treeid, application): # The following part controls the features that are attched to # leaf nodes and that will be shown in the tree image. Node styles # are set it here, and faces are also created. The idea is the # following: user can pass feature names using the URL argument # "tree_features". If the feature is handled by our function and # it is available in nodes, a face will be created and added to # the global variable LEAVE_FACES. Remember that our layout # function uses such variable to add faces to nodes during # rendering. # Extracts from URL query the features that must be drawn in the tree asked_features = application.queries.get("show_features", ["name"])[0].split(",") print >> sys.stderr, asked_features def update_features_avail(feature_key, name, col, fsize, fcolor, prefix, suffix): text_features_avail.setdefault( feature_key, [name, 0, col, fsize, fcolor, prefix, suffix]) text_features_avail[feature_key][1] += 1 tree.add_feature("fgcolor", "#833DB4") tree.add_feature("shape", "sphere") tree.add_feature("bsize", "8") tree.dist = 0 # This are the features that I wanto to convert into image # faces. I use an automatic function to do this. Each element in # the dictionary is a list that contains the information about how # to create a textFace with the feature. leaves = tree.get_leaves() formated_features = { # feature_name: ["Description", face column position, text_size, color, text_prefix, text_suffix ] "name": ["Leaf name", len(leaves), 0, 12, "#000000", "", ""], "spname": ["Species name", len(leaves), 1, 12, "#f00000", " Species:", ""], } # populates the global LEAVE_FACES variable global LEAVE_FACES LEAVE_FACES = [] unknown_faces_pos = 2 for fkey in asked_features: if fkey in formated_features: name, total, pos, size, color, prefix, suffix = formated_features[ fkey] f = faces.AttrFace(fkey, ftype="Arial", fsize=size, fgcolor=color, text_prefix=prefix, text_suffix=suffix) LEAVE_FACES.append([f, fkey, pos]) else: # If the feature has no associated format, let's add something standard prefix = " %s: " % fkey f = faces.AttrFace(fkey, ftype="Arial", fsize=10, fgcolor="#666666", text_prefix=prefix, text_suffix="") LEAVE_FACES.append([f, fkey, unknown_faces_pos]) unknown_faces_pos += 1 text_features_avail = {} for l in leaves: for f in l.features: if not f.startswith("_"): text_features_avail.setdefault(f, 0) text_features_avail[f] = text_features_avail[f] + 1 html_features = """ <div id="tree_features_box"> <div class="tree_box_header">Available tree features <img src="/webplugin/close.png" onclick='$(this).closest("#tree_features_box").hide();'> </div> <form action='javascript: set_tree_features("", "", "");'> """ for fkey, counter in text_features_avail.iteritems(): if fkey in asked_features: tag = "CHECKED" else: tag = "" fname = formated_features.get(fkey, [fkey])[0] #html_features = "<tr>" html_features += '<INPUT NAME="tree_feature_selector" TYPE=CHECKBOX %s VALUE="%s">%s (%s/%s leaves)</input><br> ' %\ (tag, fkey, fname, counter, len(leaves)) # html_features += '<td><INPUT size=7 type="text"></td> <td><input size=7 type="text"></td> <td><input size=7 type="text"></td> <td><input size=1 type="text"></td><br>' #html_features += "</tr>" html_features += """<input type="submit" value="Refresh" onclick='javascript: // This piece of js code extracts the checked features from menu and redraw the tree sending such information var allVals = []; $(this).parent().children("input[name=tree_feature_selector]").each(function(){ if ($(this).is(":checked")){ allVals.push($(this).val()); }}); draw_tree("%s", "", "#img1", {"show_features": allVals.join(",")} );' > </form></div>""" % (treeid) features_button = """ <li><a href="#" onclick='show_box(event, $(this).closest("#tree_panel").children("#tree_features_box"));'> <img width=16 height=16 src="/webplugin/icon_tools.png" alt="Select Tree features"> </a></li>""" download_button = """ <li><a href="/webplugin/tmp/%s.png" target="_blank"> <img width=16 height=16 src="/webplugin/icon_attachment.png" alt="Download tree image"> </a></li>""" % (treeid) search_button = """ <li><a href="#" onclick='javascript: var box = $(this).closest("#tree_panel").children("#search_in_tree_box"); show_box(event, box); '> <img width=16 height=16 src="/webplugin/icon_search.png" alt="Search in tree"> </a></li>""" clean_search_button = """ <li><a href="#" onclick='run_action("%s", "", %s, "clean::clean");'> <img width=16 height=16 src="/webplugin/icon_cancel_search.png" alt="Clear search results"> </a></li>""" %\ (treeid, 0) buttons = '<div id="ete_tree_buttons">' +\ features_button + search_button + clean_search_button + download_button +\ '</div>' search_select = '<select id="ete_search_target">' for fkey in text_features_avail: search_select += '<option value="%s">%s</option>' % (fkey, fkey) search_select += '</select>' search_form = """ <div id="search_in_tree_box"> <div class="tree_box_header"> Search in Tree <img src="/webplugin/close.png" onclick='$(this).closest("#search_in_tree_box").hide();'> </div> <form onsubmit='javascript: search_in_tree("%s", "%s", $(this).closest("form").children("#ete_search_term").val(), $(this).closest("form").children("#ete_search_target").val());' action="javascript:void(0);"> %s <input id="ete_search_term" type="text" value=""'></input> <br><i>(Searches are not case sensitive and accept Perl regular expressions)</i> <br> </form> <i> (Press ENTER to initiate the search)</i> </div> """ %\ (treeid, 0, search_select) # 0 is the action index associated # to the search functionality. This # means that this action is the # first to be registered in WebApplication. tree_panel_html = '<div id="tree_panel">' + search_form + html_features + buttons + '</div>' # Now we render the tree into image and get the HTML that handles it tree_html = application._get_tree_img(treeid=treeid) # Let's return enriched HTML return tree_panel_html + tree_html
def tree_renderer(tree, treeid, alignment, application, img_prop=None): # The following part controls the features that are attched to # leaf nodes and that will be shown in the tree image. Node styles # are set it here, and faces are also created. The idea is the # following: user can pass feature names using the URL argument # "tree_features". If the feature is handled by our function and # it is available in nodes, a face will be created and added to # the global variable LEAVE_FACES. Remember that our layout # function uses such variable to add faces to nodes during # rendering. # Extracts from URL query the features that must be drawn in the tree asked_features = application.queries.get("show_features", ["name"])[0].split(",") def update_features_avail(feature_key, name, col, fsize, fcolor, prefix, suffix): text_features_avail.setdefault( feature_key, [name, 0, col, fsize, fcolor, prefix, suffix]) text_features_avail[feature_key][1] += 1 tree.add_feature("fgcolor", "#833DB4") tree.add_feature("shape", "sphere") tree.add_feature("bsize", "8") tree.dist = 0 if not hasattr(tree.get_leaves()[0], 'nt_sequence'): tree.link_to_alignment(alignment) tree.workdir = '/var/www/webplugin/tmp/' + treeid os.system('mkdir -p ' + tree.workdir) # This are the features that I wanto to convert into image # faces. I use an automatic function to do this. Each element in # the dictionary is a list that contains the information about how # to create a textFace with the feature. leaves = tree.get_leaves() formated_features = { # feature_name: ["Description", face column position, text_size, color, text_prefix, text_suffix ] "name": ["Leaf name", len(leaves), 0, 12, "#000000", "", ""], "spname": ["Species name", len(leaves), 1, 12, "#f00000", " Species:", ""], } # MODELS available model_avail = {'--None--': 'None'} for model in AVAIL: if model.startswith('fb'): model_avail ['%s (%s)' % \ (model, AVAIL[model]['typ'])] = model else: model_avail ['%s (%s%s)' % \ (model, AVAIL[model]['typ'], ', need marks' * AVAIL[model]['allow_mark'])] = model # populates the global LEAVE_FACES variable global LEAVE_FACES LEAVE_FACES = [] unknown_faces_pos = 2 for fkey in asked_features: if fkey in formated_features: _, _, pos, size, color, prefix, suffix = formated_features[fkey] f = faces.AttrFace(fkey, ftype="Arial", fsize=size, fgcolor=color, text_prefix=prefix, text_suffix=suffix) LEAVE_FACES.append([f, fkey, pos]) else: # If the feature has no associated format, let's add something standard prefix = " %s: " % fkey f = faces.AttrFace(fkey, ftype="Arial", fsize=10, fgcolor="#666666", text_prefix=prefix, text_suffix="") LEAVE_FACES.append([f, fkey, unknown_faces_pos]) unknown_faces_pos += 1 text_features_avail = {} for l in leaves: for f in l.features: if not f.startswith("_"): text_features_avail.setdefault(f, 0) text_features_avail[f] = text_features_avail[f] + 1 html_features = ''' <div id="tree_features_box"> <div class="tree_box_header">Available tree features <img src="/webplugin/close.png" onclick='$(this).closest("#tree_features_box").hide();'> </div> <form action='javascript: set_tree_features("", "", "");'> ''' for fkey, counter in text_features_avail.iteritems(): if fkey in asked_features: tag = "CHECKED" else: tag = "" fname = formated_features.get(fkey, [fkey])[0] html_features += '<INPUT NAME="tree_feature_selector" TYPE=CHECKBOX %s VALUE="%s">%s (%s/%s leaves)</input><br> ' %\ (tag, fkey, fname, counter, len(leaves)) html_features += '''<input type="submit" value="Refresh" onclick='javascript: // This piece of js code extracts the checked features from menu and redraw the tree sending such information var allVals = []; $(this).parent().children("input[name=tree_feature_selector]").each(function(){ if ($(this).is(":checked")){ allVals.push($(this).val()); }}); draw_tree("%s", "", "", "#img1", {"show_features": allVals.join(",")} );' > </form></div>''' % (treeid) features_button = ''' <li><pre> </pre><a href="#" title="Select features to display" onclick='show_box(event, $(this).closest("#tree_panel").children("#tree_features_box"));'> <img width=24 height=24 BORDER=0 src="/webplugin/icon_tools.png" alt="Select Tree features"> </a></li>''' download_button = ''' <li><pre> </pre><a href="/webplugin/tmp/%s.png" title="Download tree image" target="_blank"> <img width=24 height=24 BORDER=0 src="/webplugin/icon_attachment.png" alt="Download tree image"> </a></li>''' % (treeid) search_button = ''' <li><pre> </pre><a href="#" title="Search in tree" onclick='javascript: var box = $(this).closest("#tree_panel").children("#search_in_tree_box"); show_box(event, box); '> <img width=24 height=24 BORDER=0 src="/webplugin/icon_search.png" alt="Search in tree"> </a></li>''' evol_button = ''' <li><pre> </pre><a href="#" title="Compute evolutionary model" onclick='javascript: var box = $(this).closest("#tree_panel").children("#evol_box"); show_box(event, box); '> <img width=24 height=24 BORDER=0 src="/webplugin/icon_calc_gray.gif" alt="Compute Evol Model"> </a></li>''' load_model_button = ''' <li><pre> </pre><a href="#" title="Load computed evolutionary model" onclick='javascript: var box = $(this).closest("#tree_panel").children("#load_model_box"); show_box(event, box); '> <img width=24 height=24 BORDER=0 src="/webplugin/evolution.gif" alt="Clear search results"> </a></li>''' compare_model_button = ''' <li><pre> </pre><a href="#" title="Compare (LRT) computed evolutionary model" onclick='javascript: var box = $(this).closest("#tree_panel").children("#compare_model_box"); show_box(event, box); '> <img width=24 height=24 BORDER=0 src="/webplugin/balance_icon.png" alt="Compare models"> </a></li>''' clean_search_button = ''' <li><pre> </pre><a href="#" title="Clean tree" onclick='run_action("%s", "", %s, "clean::clean");'> <img width=24 height=24 BORDER=0 src="/webplugin/icon_cancel_search.png" alt="Clear search results"> </a></li>''' % \ (treeid, 0) buttons = '<div id="ete_tree_buttons"><table border="0">' +\ '<tr align="center" halign="bottom"><td>' + features_button + \ '</td><td>' + search_button + \ '</td><td>' + clean_search_button + \ '</td><td>' + evol_button + \ '</td><td>' + load_model_button + \ '</td><td>' + compare_model_button + \ '</td><td>' + download_button + '</td></tr></table></div>' search_select = '<select id="ete_search_target">' for fkey in text_features_avail: search_select += '<option value="%s">%s</option>' % (fkey, fkey) search_select += '</select>' search_form = ''' <div id="search_in_tree_box"> <div class="tree_box_header"> Search in Tree <img src="/webplugin/close.png" onclick='$(this).closest("#search_in_tree_box").hide();'> </div> <form onsubmit='javascript: search_in_tree("%s", "%s", $(this).closest("form").children("#ete_search_term").val(), $(this).closest("form").children("#ete_search_target").val());' action="javascript:void(0);"> %s <input id="ete_search_term" type="text" value=""></input> <br><i>(Searches are not case sensitive and accept Perl regular expressions)</i> <br> </form> <i> (Press ENTER to initiate the search)</i> </div> ''' % \ (treeid, 0, search_select) # 0 is the action index associated # to the search functionality. This # means that this action is the # first to be registered in WebApplication. load_model_select = '''<select id="model_to_load" onchange="javascript: %s; var objContent = document.getElementById('summary_model'); objContent.innerHTML = models_sum[$(this).val()]; "> ''' % (get_summary_models(tree)) runned_models = ['--None--'] + get_computed_models(tree) for fkey in sorted(runned_models): if fkey == '--None--': load_model_select += \ '<option selected value="None" >--None--</option>\n' continue load_model_select += '<option value="%s">%s</option>\n' % \ (fkey, fkey) load_model_select += '</select>' load_model_form = ''' <div id="load_model_box"> <div class="tree_box_header"> Load Evolutionary Model <img src="/webplugin/close.png" onclick='$(this).closest("#load_model_box").hide();' onload='$(this).closest("#load_model_box").hide();'> </div> <form action="javascript:void(0);"> <font size=2> Computed model:</font> %s </form> <font size="1"> <br><br><br> <div class="contentBox" style="text-align:left" id="summary_model"></div> <div style="text-align:left"> <br><i>If your model does not appear here, try refreshing, <br> -> first icon "Available tree features"</i><br> </div> <input type="submit" value="Load" onclick="javascript: var model = document.getElementById ('model_to_load').value; load_model ('%s', model); var allVals = [%s]; if (model.match(/fb_anc.*/)) { allVals.push('paml_id'); } draw_tree('%s', '', '', '#img1', {'show_features': allVals.join(',')} ); "></font> </div> ''' % (load_model_select, treeid, "'" + "','".join(asked_features) + "'", treeid) #" # first model load_first_model_select = '''<select id="first_model_to_load" onchange="javascript: %s; "> ''' % (get_model_values(tree)) runned_models = ['--None--'] + get_computed_models(tree) for fkey in sorted(runned_models): if fkey == '--None--': load_first_model_select += \ '<option selected value="None" >--None--</option>\n' continue load_first_model_select += '<option value="%s">%s</option>\n' % \ (fkey, fkey) load_first_model_select += '</select>' # second model load_second_model_select = '''<select id="second_model_to_load" onchange="javascript: %s; "> ''' % (get_model_values(tree)) runned_models = ['--None--'] + get_computed_models(tree) for fkey in sorted(runned_models): if fkey == '--None--': load_second_model_select += \ '<option selected value="None" >--None--</option>\n' continue load_second_model_select += '<option value="%s">%s</option>\n' % \ (fkey, fkey) load_second_model_select += '</select>' doc = '<table border=1><tr><th colspan=2>Usual comparisons (Alternative vs Null)</tr><tr><td>' doc += '</td></tr><tr><td>'.join( re.findall('([A-Za-z0-9_]+ +vs +[A-Za-z0-9_]+ +-> +[A-Za-z0-9 =!()]+)', tree.get_most_likely.__doc__)) doc = re.sub('->', '</td><td>', doc) doc += '</tr></table>' compare_model_form = ''' <div id="compare_model_box"> <div class="tree_box_header"> Compare Evolutionary Model <img src="/webplugin/close.png" onclick='$(this).closest("#compare_model_box").hide();' onload='$(this).closest("#compare_model_box").hide();'> </div> <form action="javascript:void(0);"> <font size=2> Alternative model:</font> %s <font size=2> Null model:</font> %s </form> <br><br> <font size=1> <div align="center"> %s </div> </font> <br> <font size="2"> <div class="contentBox" style="text-align:left" id="delta_df"></div> </font> <br> p-value (that alternative model is the best):<br> <rep> </rep><input typ=text id=result size=8 value=""><br> <input type="submit" value="Compare" onclick="javascript: %s; calculate([models_sum[document.getElementById ('first_model_to_load').value], models_sum [document.getElementById ('second_model_to_load').value], document.getElementById ('result'), document.getElementById ('delta_df')]);"> </div> ''' % (load_first_model_select, load_second_model_select, doc, get_model_values(tree)) model_select = '''<select id="model_target" onchange="javascript: %s var objContent = document.getElementById('ctrl_table'); objContent.innerHTML = all_models[$(this).val()]; "> ''' % (get_ctrl_string()) # get control string returns a string to build # a hash "all_models" in javascript. for fkey in sorted(model_avail): if fkey == '--None--': model_select += '<option selected value="None" >--None--</option>\n' continue model_select += '<option value="%s">%s</option>\n' % \ (model_avail [fkey], fkey) model_select += '</select>' evol_form = ''' <div id="evol_box"> <div class="tree_box_header"> Compute Evolutionary Model <img src="/webplugin/close.png" onclick='$(this).closest("#evol_box").hide();' onload='$(this).closest("#evol_box").hide();'> </div> <form action="javascript:void(0);"> <font size=2> Model:</font> %s </form> <font size="2"> name extention**: <input id="extention" type="text" value="%s"> </font> <font size="1"> <table border="0"> <div class="contentBox" id="ctrl_table">Select a model</div> </table> </font> <font size="2"><i> (*) stars in text field figure for default parameters <br> (**) optional, but usefull specially for branch analysis </i> </font> <br> <input type="submit" value="Run" onclick="javascript: var allVals = {}; %s var model = document.getElementById ('model_target').value; for (var i in all_models[model]){ allVals[all_models[model][i]]=document.getElementById (all_models[model][i]).value; }; if (document.getElementById ('extention').value != ''){ model += '.' + document.getElementById ('extention').value; } run_model ('%s', model, allVals); draw_tree('%s', '', '', '#img1', ''); "> </div> ''' % ( model_select, #" ''.join([choice('abcdefghijklmnopqrstuvwxyz') for _ in xrange(4)]), get_ctrl_keys(), treeid, treeid) tree_panel_html = '<div id="tree_panel">' + search_form + evol_form \ + load_model_form + compare_model_form + html_features + buttons + '</div>' # Now we render the tree into image and get the HTML that handles it tree_html = application._get_tree_img(treeid=treeid) # Let's return enriched HTML return tree_panel_html + tree_html
array = t.arraytable # Calculates some stats on the matrix matrix_dist = [i for r in xrange(len(array.matrix))\ for i in array.matrix[r] if numpy.isfinite(i)] matrix_max = numpy.max(matrix_dist) matrix_min = numpy.min(matrix_dist) matrix_avg = matrix_min + ((matrix_max - matrix_min) / 2) # Creates a profile face that will represent node's profile as a # heatmap profileFace = faces.ProfileFace(matrix_max, matrix_min, matrix_avg, \ 200, 14, "heatmap") cbarsFace = faces.ProfileFace(matrix_max, matrix_min, matrix_avg, 200, 70, "cbars") nameFace = faces.AttrFace("name", fsize=8) # Creates my own layout function that uses previous faces def mylayout(node): # If node is a leaf if node.is_leaf(): # And a line profile faces.add_face_to_node(profileFace, node, 0, aligned=True) node.img_style["size"] = 0 faces.add_face_to_node(nameFace, node, 1, aligned=True) # If node is internal else: # If silhouette is good, creates a green bubble if node.silhouette > 0:
def test(node): if node.is_leaf(): faces.add_face_to_node(faces.AttrFace("name"), node, 0, position="aligned")
def leaf_name(node): if node.is_leaf(): nameF = faces.AttrFace("name") nameF.border.width = 1 faces.add_face_to_node(nameF, node, 0, position="branch-right")