def do_search(self, comm, trees=None): cm = self.cm if trees == None: first_tree = [tree.one_tree(cm)] first_len = first_tree[0].length(cm) print "Initial tree length: %d" % first_len else: first_tree = trees first_len = trees[0].length(cm) while not comm.need_to_communicate(): # preserve outgroup t = first_tree[0] new_tree = tree.node(t.left, rearrange_tree(t.right)) new_len = new_tree.length(cm) if new_len < first_len: print "New length, current minimum length: %d, %d" % (new_len, first_len) first_len = new_len first_tree = [new_tree] elif new_len == first_len: first_tree.append(new_tree) random.shuffle(first_tree) # commmunicate back return first_tree
def run_tests(): # random_not_in my_set = set([1, 2, 3, 4]) assert random_not_in(5, my_set) == 0, "it can only be 0" # random_in assert random_in(5, my_set) in my_set, "number must be in set" # list_tree itself import charmatrix # prepare trees cm = charmatrix.charmatrix('data/shortoryzos.txt') t = tree.one_tree(cm) # test conversion with tree lt = list_tree(tree=t) tt = lt.to_tree() assert tt == t, "list_tree <=> tree conversion should be reversible" # test length assert t.length(cm) == lt.length(cm), "tree length should give same result for tree and list_tree" # test init_from_taxa taxa = cm.taxon_set() outgroup = cm.get_outgroup() lt2 = list_tree(taxa=taxa, outgroup=outgroup) assert lt2.to_tree().taxon_set() == taxa
def initial_tree(self): return tree.one_tree(cm)