예제 #1
0
def extract_clades(newick_file, processed_newick_out=None):
    """ the outer logic for tree splitting """
    # preprocess tree
    print("Pre-processing tree ({})".format(newick_file))
    tree = PhyloTree(newick_file)
    R = tree.get_midpoint_outgroup()
    tree.set_outgroup(R)
    tree.ladderize()
    tree.convert_to_ultrametric()
    if (processed_newick_out is not None):
        tree.write(format=1, outfile=processed_newick_out)
    # calculate clades
    print("Calling clades ({})".format(newick_file))

    def get_branch_length(node):
        for l in node:
            return l.get_distance(node)

    len_tree = len(tree)
    dist_tree = get_branch_length(tree)

    def condition_discard(node, tree):
        return (len(node) < 3)

    def condition_ok(node, tree):
        return len(node) < max(10, len_tree / 50)

    branches = get_pruned_branch(tree, tree, condition_discard, condition_ok,
                                 [])
    clades = {}
    for i, branch in enumerate(
            sorted(branches, key=lambda nodes: -1 * len(nodes))):
        clades[str(i + 1)] = [node.name for node in branch]
    return clades
    item=seqs.get_seq(leaf.name)
    name_face = AttrFace(item, fsize=24)
    Bars = SequenceFace(item, seqtype='aa', fsize=24, bg_colors={'G': 'Khaki', 'A': 'Khaki', 'S': 'Khaki', 'T': 'Khaki', 'C': 'LightGreen', 'V': 'LightGreen', 'I': 'LightGreen', 'L': 'LightGreen', 'P': 'LightGreen', 'F': 'LightGreen', 'Y': 'LightGreen', 'M': 'YellowGreen', 'W': 'LightGreen', 'N': 'Thistle', 'Q': 'Thistle', 'H': 'Thistle', 'D': 'DarkSalmon', 'E': 'DarkSalmon', 'K': 'SkyBlue', 'R': 'SkyBlue', 'X':'Black', '-':'White' }, fg_colors=None, codon=None, col_w=1.5, alt_col_w=3, special_col=None, interactive=False)
    leaf.add_face(Bars, 2, "aligned")    
    
t.render("tree_and_alignment.png", h=100, units="mm")
t.render("tree_and_alignment.svg", h=100, units="mm")





t2 = PhyloTree( tree_input , format=1, quoted_node_names=True )
for node in t2.traverse():
    node.set_style(nodestyle1)
t2.convert_to_ultrametric(tree_length=None, strategy='balanced')
cladogram = TreeStyle()
cladogram.scale = 20
t2.render("cladogram.png", h=75, units="mm", tree_style=cladogram)

for leaf in t2.iter_leaves():
    leaf.name = " "
t2.render("cladogram_nameless.png", h=75, units="mm", tree_style=cladogram)




#colour options here: http://etetoolkit.org/docs/latest/reference/reference_treeview.html?highlight=colors#ete3.SVG_COLORS

#colours adapted from: http://www.bioinformatics.nl/~berndb/aacolour.html
#Lesk