def main(): option_parser, options, args = parse_command_line_parameters(**script_info) create_dir(options.output_dir, fail_on_exist=False) master_tree, support_trees = load_tree_files(options.master_tree, options.support_dir) # get support of each node in master new_master, bootstraps = bootstrap_support(master_tree, support_trees) write_bootstrap_support_files(new_master, bootstraps, options.output_dir, len(support_trees))
def test_bootstrap_support(self): """ bootstrap_support should have correct bootstrap for a tree with unlabeled internal nodes """ master_tree = parse_newick('((a:2,b:3):2,(c:1,d:2):7);') """ /-------.5 /-a ---1| \-b \------.5 /-c \-d """ t1 = parse_newick('((a:6,b:8.2):2,(c:1,d:2):7);') # same structure t2 = parse_newick('((a:2,b:3,c:33):2,d:7);') # abc are siblings new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2]) self.assertFloatEqual(sorted(bootstraps.values()),sorted([1.0, .5, .5]))
def test_bootstrap_support(self): """ bootstrap_support should have correct bootstrap for a tree with unlabeled internal nodes """ master_tree = parse_newick("((a:2,b:3):2,(c:1,d:2):7);") """ /-------.5 /-a ---1| \-b \------.5 /-c \-d """ t1 = parse_newick("((a:6,b:8.2):2,(c:1,d:2):7);") # same structure t2 = parse_newick("((a:2,b:3,c:33):2,d:7);") # abc are siblings new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2]) self.assertFloatEqual(sorted(bootstraps.values()), sorted([1.0, 0.5, 0.5]))
def test_bootstrap_support_labeled(self): """ bootstrap_support should have correct bootstrap on a tree with labeled internal nodes """ master_tree = parse_newick('((a:2,b:3)ab:2,(c:1,d:2)cd:7)rt;') """ /-------.5 /-a ---1| \-b \------.5 /-c \-d """ t1 = parse_newick('((a:6,b:8.2)hi:2,(c:1,d:2):7);') # same structure t2 = parse_newick('((a:2,b:3,c:33)ho:2,d:7);') # abc are siblings new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2]) expected = dict([('ab', .5),('cd',.5),('rt',1.0)]) self.assertFloatEqual(bootstraps, expected)
def test_bootstrap_support_labeled(self): """ bootstrap_support should have correct bootstrap on a tree with labeled internal nodes """ master_tree = parse_newick('((a:2,b:3)ab:2,(c:1,d:2)cd:7)rt;') """ /-------.5 /-a ---1| \-b \------.5 /-c \-d """ t1 = parse_newick('((a:6,b:8.2)hi:2,(c:1,d:2):7);') # same structure t2 = parse_newick('((a:2,b:3,c:33)ho:2,d:7);') # abc are siblings new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2]) expected = dict([('ab', .5), ('cd', .5), ('rt', 1.0)]) self.assertDictEqual(bootstraps, expected)
def test_bootstrap_support_subset(self): """ bootstrap_support should have correct bootstrap on a tree when one support tree is missing a tip """ master_tree = parse_newick("((a:2,b:3)ab:2,(c:1,d:2)cd:7)rt;") """ /-------.5 /-a ---1| \-b \------.5 /-c \-d """ t1 = parse_newick("((a:6,b:8.2)hi:2,(c:1,d:2):7);") # same structure t2 = parse_newick("((a:2,b:3,c:33)ho:2,d:7);") # abc are siblings t3 = parse_newick("((a:6)hi:2,(c:1,d:2):7);") # b missing t4 = parse_newick("(a:8,(c:1,d:2):7);") # b missing, and pruned new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2, t3, t4]) expected = dict([("cd", 0.75), ("rt", 1.0)]) self.assertFloatEqual(bootstraps, expected)
def test_bootstrap_support_subset(self): """ bootstrap_support should have correct bootstrap on a tree when one support tree is missing a tip """ master_tree = parse_newick('((a:2,b:3)ab:2,(c:1,d:2)cd:7)rt;') """ /-------.5 /-a ---1| \-b \------.5 /-c \-d """ t1 = parse_newick('((a:6,b:8.2)hi:2,(c:1,d:2):7);') # same structure t2 = parse_newick('((a:2,b:3,c:33)ho:2,d:7);') # abc are siblings t3 = parse_newick('((a:6)hi:2,(c:1,d:2):7);') # b missing t4 = parse_newick('(a:8,(c:1,d:2):7);') # b missing, and pruned new_master, bootstraps = tc.bootstrap_support(master_tree, [t1, t2,t3,t4]) expected = dict([('cd',.75),('rt',1.0)]) self.assertFloatEqual(bootstraps, expected)