source: tags/arb_5.0/TOOLS/arb_export_tree.cxx

Last change on this file was 6143, checked in by westram, 15 years ago
  • backport [6141] (parts changing code, but only strings and comments)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1#include <stdio.h>
2
3#include <arbdbt.h>
4#include <TreeWrite.h>
5
6/*      Input   Tree_name       argv[1]
7 *      Output(stdout)  one line tree
8 *      */
9
10
11int main(int argc, char **argv){
12    int exitcode = EXIT_SUCCESS;
13
14    if (argc < 2) {
15        fprintf(stderr, "\narb_export_tree - exports tree from running ARB to stdout\n"
16                        "syntax: arb_export_tree [--bifurcated] TREE_NAME\n"
17                        "        --bifurcated     write a bifurcated tree (default is a trifurcated tree)\n"
18                        "        --nobranchlens   do not write branchlengths\n"
19                        "        --doublequotes   use doublequotes (default is singlequotes)\n"
20                        "\n"
21                "Note: If TREE_NAME is '\?\?\?\?' or '' an empty tree is written.");
22        exitcode = EXIT_FAILURE;
23    }
24    else {
25        GB_ERROR  error   = 0;
26        GBDATA   *gb_main = GBT_open(":","r",0);
27       
28        if (!gb_main){
29            error    = GB_await_error();
30            exitcode = EXIT_FAILURE;
31        }
32        else {
33            bool        trifurcated  = true;
34            bool        branchlens   = true;
35            bool        doublequotes = false;
36            const char *tree_name    = 0;
37
38            for (int a = 1; a < argc; a++) {
39                if (strcmp(argv[a], "--bifurcated") == 0) trifurcated = false;
40                else if (strcmp(argv[a], "--nobranchlens") == 0) branchlens = false;
41                else if (strcmp(argv[a], "--doublequotes") == 0) doublequotes = true;
42                else tree_name = argv[a];
43            }
44
45            if (!tree_name) error = "Missing argument TREE_NAME";
46            else {
47                GB_transaction dummy(gb_main);
48                GBT_TREE *tree = GBT_read_tree(gb_main,tree_name, - sizeof(GBT_TREE));
49                if (tree) {
50                    error = TREE_export_tree(gb_main, stdout, tree, trifurcated, branchlens, doublequotes);
51                }
52                else {
53                    if (tree_name[0] && strcmp(tree_name, "????") != 0) // ignore tree names '????' and '' (no error, just export empty tree)
54                    {
55                        char *err = GBS_global_string_copy("arb_export_tree: Tree '%s' does not exist in DB\n", tree_name);
56                        GBT_message(gb_main, err);
57                        free(err);
58                    }
59                    else {
60                        error = GB_await_error();
61                    }
62                }
63                printf(";\n"); // aka empty tree
64            }
65            GB_close(gb_main);
66        }
67
68        if (error) {
69            fprintf(stderr, "\narb_export_tree: Error: %s\n", error);
70        }
71    }
72    return exitcode;
73}
74
Note: See TracBrowser for help on using the repository browser.