def buildTree(conf, stree, gene2species): params = Spidir.readParams(conf["param"]) if "correcttree" in conf: conf["correcthash"] = phylo.hash_tree(conf["correcttree"]) if "dist" in conf: for i in range(len(conf["dist"])): distfile = conf["dist"][i] labels, distmat = phylip.read_dist_matrix(distfile) # read in different labels if needed if "labels" in conf: labels = Spidir.readLabels(conf["labels"][i]) conf["aln"] = fasta.read_fasta(conf["labels"][i]) tree, logl = Spidir.spidir(conf, distmat, labels, stree, gene2species, params) tree.write(Spidir.outTreeFile(conf)) # test for correctness if "correcttree" in conf: correctTree = conf["correcttree"] phylo.hash_order_tree(correctTree) phylo.hash_order_tree(tree) thash1 = phylo.hash_tree(tree) thash2 = phylo.hash_tree(correctTree) print "spidir: " treelib.draw_tree(tree, maxlen=5, minlen=5) print print "correct:" treelib.draw_tree(correctTree, maxlen=5, minlen=5) print if len(tree.leaves()) > 3: rferror = Spidir.robinson_foulds_error(correctTree, tree) else: rferror = 0.0 if thash1 == thash2: print "CORRECT TREE FOUND" else: print "WRONG TREE FOUND (RF: %f)" % rferror