int test_reroot_2() { const char *test_name = "test_reroot_2"; /* A tree whose root has 3 children: * (A:3,B:3,(C:2,(D:1,E:1)f:1)g:1)h; */ struct rooted_tree tree = tree_5(); struct hash *map = create_label2node_map(tree.nodes_in_order); struct rnode *node_f = hash_get(map, "f"); const char *exp = "((D:1,E:1)f:0.5,(C:2,(A:3,B:3)h:1)g:0.5);"; reroot_tree(&tree, node_f); const char *obt = to_newick(tree.root); if (strcmp (exp, obt) != 0) { printf ("%s: expected '%s', got '%s'.\n", test_name, exp, obt); return 1; } printf ("%s: ok.\n", test_name); return 0; }
int reroot(struct rooted_tree *tree, struct llist *outgroup_nodes) { struct rnode *outgroup_root; outgroup_root = lca(tree, outgroup_nodes); if (NULL == outgroup_root) { perror(NULL); exit(EXIT_FAILURE); } if (tree->root == outgroup_root) { return LCA_IS_TREE_ROOT; } if (! reroot_tree (tree, outgroup_root)) { perror(NULL); exit(EXIT_FAILURE); } return REROOT_OK; }
int test_reroot() { const char *test_name = "test_reroot"; struct rooted_tree tree = tree_3(); /* ((A:1,B:1.0)f:2.0,(C:1,(D:1,E:1)g:2)h:3)i; */ struct hash *map = create_label2node_map(tree.nodes_in_order); struct rnode *node_g = hash_get(map, "g"); const char *exp = "((D:1,E:1)g:1,(C:1,(A:1,B:1.0)f:5)h:1);"; reroot_tree(&tree, node_g); const char *obt = to_newick(tree.root); if (strcmp (exp, obt) != 0) { printf ("%s: expected '%s', got '%s'.\n", test_name, exp, obt); return 1; } printf ("%s: ok.\n", test_name); return 0; }
int reroot(struct rooted_tree *tree, struct llist *outgroup_nodes, bool i_node_lbl_as_support) { struct rnode *outgroup_root; if (0 == outgroup_nodes->count) { outgroup_root = node_with_longest_edge(tree); if (NULL == outgroup_root) return NOT_PHYLOGRAM; } else { outgroup_root = lca_from_nodes(tree, outgroup_nodes); if (NULL == outgroup_root) { perror(NULL); exit(EXIT_FAILURE); } } if (tree->root == outgroup_root) { return LCA_IS_TREE_ROOT; } if (! reroot_tree (tree, outgroup_root, i_node_lbl_as_support)) { perror(NULL); exit(EXIT_FAILURE); } return REROOT_OK; }