ARB
arb_2_bin.cxx
Go to the documentation of this file.
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 
14 int ARB_main(int argc, char *argv[]) {
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  " -C<type> use extra compression\n"
28  " (known <type>s: %s)\n"
29  "\n"
30  "database my be '-' in which case arb_2_bin reads from stdin.\n"
31  "\n",
33 
34  if (argc>1 && strcmp(argv[1], "--help") != 0) { error = "Missing arguments"; }
35  }
36  else {
37  char rtype[256];
38  char wtype[256];
39  int ci = 1;
40  int nidx = 0;
41 
42  const char *opt_tree = NULp;
43 
44  {
45  char *rtypep = rtype;
46  char *wtypep = wtype;
47 
48  memset(rtype, 0, 10);
49  memset(wtype, 0, 10);
50  *(wtypep++) = 'b';
51  *(rtypep++) = 'r';
52  *(rtypep++) = 'w';
53 
54  while (argv[ci] && argv[ci][0] == '-' && argv[ci][1] != 0 && !error) {
55  if (!strcmp(argv[ci], "-m")) { ci++; *(wtypep++) = 'm'; }
56  else if (!strcmp(argv[ci], "-r")) { ci++; *(rtypep++) = 'R'; }
57  else if (!strncmp(argv[ci], "-c", 2)) { opt_tree = argv[ci]+2; ci++; }
58  else if (!strncmp(argv[ci], "-i", 2)) { nidx = atoi(argv[ci]+2); ci++; }
59  else if (!strncmp(argv[ci], "-C", 2)) {
60  char cflag = argv[ci][2]; ci++;
61  if (!strchr(GB_get_supported_compression_flags(false), cflag)) {
62  error = GBS_global_string("Unknown compression flag '%c'", cflag);
63  }
64  else {
65  *(wtypep++) = cflag;
66  }
67  }
68  else {
69  error = GBS_global_string("Unknown argument '%s'", argv[ci]);
70  break;
71  }
72  }
73  }
74 
75  const char *in = argv[ci++];
76  const char *out = ci >= argc ? in : argv[ci++];
77 
78  if (!error && !in) error = "missing arguments";
79 
80  if (!error) {
81  printf("Reading database...\n");
82  GB_shell shell;
83  GBDATA *gb_main = GBT_open(in, rtype);
84  if (!gb_main) {
85  error = GB_await_error();
86  }
87  else {
88  if (opt_tree) {
89  char *ali_name;
90  {
91  GB_transaction ta(gb_main);
92  ali_name = GBT_get_default_alignment(gb_main);
93  }
94  if (!strlen(opt_tree)) opt_tree = NULp;
95 
96  printf("Optimizing database...\n");
97  error = GBT_compress_sequence_tree2(gb_main, opt_tree, ali_name);
98  if (error) error = GBS_global_string("Error during optimize: %s", error);
99  free(ali_name);
100  }
101 
102  if (!error) {
103  GB_set_next_main_idx(nidx);
104  printf("Saving database...\n");
105  error = GB_save(gb_main, out, wtype);
106  }
107  GB_close(gb_main);
108  }
109  }
110  }
111 
112  if (error) {
113  fprintf(stderr, "arb_2_bin: Error: %s\n", error);
114  return EXIT_FAILURE;
115  }
116  return EXIT_SUCCESS;
117 }
const char * GB_ERROR
Definition: arb_core.h:25
GB_ERROR GB_save(GBDATA *gb, const char *path, const char *savetype)
void GB_set_next_main_idx(long idx)
Definition: ad_load.cxx:918
int ARB_main(int argc, char *argv[])
Definition: arb_2_bin.cxx:14
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
#define EXIT_SUCCESS
Definition: arb_a2ps.c:154
GBDATA * GBT_open(const char *path, const char *opent)
Definition: adtools.cxx:524
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:353
static void error(const char *msg)
Definition: mkptypes.cxx:96
#define EXIT_FAILURE
Definition: arb_a2ps.c:157
GB_ERROR GBT_compress_sequence_tree2(GBDATA *gbd, const char *tree_name, const char *ali_name) __ATTR__USERESULT
Definition: adseqcompr.cxx:889
#define NULp
Definition: cxxforward.h:97
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:675
GB_transaction ta(gb_var)
GBDATA * gb_main
Definition: adname.cxx:33
const char * GB_get_supported_compression_flags(bool verboose)
void GB_close(GBDATA *gbd)
Definition: arbdb.cxx:625