source: branches/profile/TOOLS/arb_2_bin.cxx

Last change on this file was 11464, checked in by westram, 10 years ago
  • un-dummy-fied transaction (renames only)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : arb_2_bin.cxx                                     //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11
12#include <arbdbt.h>
13
14int ARB_main(int argc, char *argv[]) {
15    GB_ERROR error = 0;
16
17    fprintf(stderr, "arb_2_bin - ARB database ascii to binary converter\n");
18
19    if (argc <= 1 || strcmp(argv[1], "--help") == 0) {
20        fprintf(stderr,
21                "\n"
22                "Purpose: Converts a database to binary format\n"
23                "Syntax:  arb_2_bin [Options] database [newdatabase]\n"
24                "Options: -m            create map file too\n"
25                "         -r            try to repair destroyed database\n"
26                "         -c[tree_xxx]  optimize database using tree_xxx or largest tree\n"
27                "\n"
28                "database my be '-' in which case arb_2_bin reads from stdin.\n"
29                "\n"
30            );
31
32        if (strcmp(argv[1], "--help") != 0) { error = "Missing arguments"; }
33    }
34    else {
35        char rtype[256];
36        char wtype[256];
37        int  ci   = 1;
38        int  nidx = 0;
39
40        const char *opt_tree = 0;
41
42        {
43            char *rtypep = rtype;
44            char *wtypep = wtype;
45
46            memset(rtype, 0, 10);
47            memset(wtype, 0, 10);
48            *(wtypep++) = 'b';
49            *(rtypep++) = 'r';
50            *(rtypep++) = 'w';
51
52            while (argv[ci][0] == '-' && argv[ci][1] != 0) {
53                if (!strcmp(argv[ci], "-m")) { ci++; *(wtypep++) = 'm'; }
54                if (!strcmp(argv[ci], "-r")) { ci++; *(rtypep++) = 'R'; }
55                if (!strncmp(argv[ci], "-c", 2)) { opt_tree = argv[ci]+2; ci++; }
56                if (!strncmp(argv[ci], "-i", 2)) { nidx = atoi(argv[ci]+2); ci++; }
57            }
58        }
59
60        const char *in  = argv[ci++];
61        const char *out = ci >= argc ? in : argv[ci++];
62
63        printf("Reading database...\n");
64        GB_shell  shell;
65        GBDATA   *gb_main = GBT_open(in, rtype);
66        if (!gb_main) {
67            error = GB_await_error();
68        }
69        else {
70            if (opt_tree) {
71                char *ali_name;
72                {
73                    GB_transaction ta(gb_main);
74                    ali_name = GBT_get_default_alignment(gb_main);
75                }
76                if (!strlen(opt_tree)) opt_tree = 0;
77
78                printf("Optimizing database...\n");
79                error = GBT_compress_sequence_tree2(gb_main, opt_tree, ali_name);
80                if (error) error = GBS_global_string("Error during optimize: %s", error);
81                free(ali_name);
82            }
83
84            if (!error) {
85                GB_set_next_main_idx(nidx);
86                printf("Saving database...\n");
87                error = GB_save(gb_main, out, wtype);
88            }
89            GB_close(gb_main);
90        }
91    }
92
93    if (error) {
94        fprintf(stderr, "arb_2_bin: Error: %s\n", error);
95        return EXIT_FAILURE;
96    }
97    return EXIT_SUCCESS;
98}
Note: See TracBrowser for help on using the repository browser.