def as_phyloxml(self, **kwargs): """Convert this tree to a PhyloXML-compatible Phylogeny. This lets you use the additional annotation types PhyloXML defines, and save this information when you write this tree as 'phyloxml'. """ from Bio.Phylo.PhyloXML import Phylogeny return Phylogeny.from_tree(self, **kwargs)
def out(): infile = e1.get() tree = Phylo.read(infile, "newick") tree = Phylogeny.from_tree(tree) tree.root.color = "#808080" mrca = tree.common_ancestor({"name": "E"}, {"name": "F"}) mrca.color = "salmon" tree.clade[0, 1].color = "blue" Phylo.draw(tree) win.destroy()
def tree_coevol(tree_folder): """ @tree_folder - folder name that contains all the phylogeny tree dataset This function uses pairwise distance obtained from the tree branch lengths to perform coevolution test. """ tree_data = dict() tree_objects = glob.glob(tree_folder + "/*.*") taxa_dict = dict() toolbar_width = len(tree_objects) print("Importing branch lengths\n") for c, tree_file in enumerate(tree_objects): tree = Phylo.read(tree_file, "newick") phy = Phylogeny.from_tree(tree) taxa = [x. name for x in phy.get_terminals('level')] taxa_dict[tree_file] = (taxa) tree_data[tree_file] = dict() taxon_pairs = unique_pairs(taxa) for paired_taxa in taxon_pairs: tree_data[tree_file][paired_taxa[0] + "-" + paired_taxa[1]] = phy.distance(paired_taxa[0], paired_taxa[1]) p = str((float(c)/toolbar_width)*100)[:5] sys.stdout.write("\r%s%%" %p) sys.stdout.flush() tree_pairs = unique_pairs(tree_objects) correl = dict() toolbar_width = len(tree_pairs) print("Running coevolution test\n") for c, Obj in enumerate(tree_pairs): if len(tree_data[Obj[0]]) != len(tree_data[Obj[1]]): common_taxa = [key for key, val in tree_data[Obj[0]].items() if key in [key2 for key2, val2 in tree_data[Obj[1]].items()]] else: common_taxa = tree_data[Obj[0]].keys() correl[Obj[0].lstrip(tree_folder).lstrip("/") + "-" + Obj[1].lstrip(tree_folder).lstrip("/")] = \ pearsonr([val for key, val in _sort_dict_by_key(tree_data[Obj[0]]) if key in common_taxa], \ [val for key, val in _sort_dict_by_key(tree_data[Obj[1]]) if key in common_taxa]) p = str((float(c)/toolbar_width)*100)[:5] sys.stdout.write("\r%s%%" %p) sys.stdout.flush() for key, val in correl.items(): print key, val
def phyloxml_tree_generator(tree): children = phyloxml_tree_generator_recurse(tree, taxid=1) return Phylogeny(name='gi2tax - Common tree', root=children)
Execução: python bio16_filo.py ''' #importando from Bio import Phylo tree = Phylo.read("simple.dnd", "newick") print(tree) Phylo.draw_ascii(tree) tree.rooted = True Phylo.draw(tree) tree = tree.as_phyloxml() from Bio.Phylo.PhyloXML import Phylogeny tree = Phylogeny.from_tree(tree) tree.root.color = (128, 128, 128) mrca = tree.common_ancestor({"name": "E"}, {"name": "F"}) mrca.color = "salmon" tree.clade[0, 1].color = "blue" Phylo.draw(tree)