ARB
ps_arb2asciipaths.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ps_arb2asciipaths.cxx //
4 // Purpose : //
5 // //
6 // Coded by Wolfram Foerster in October 2002 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #include "ps_filebuffer.hxx"
13 #include "ps_pg_tree_functions.hxx"
14 
15 static IDVector *__PATH = new IDVector;
16 
17 static void PS_print_paths(GBDATA *_pb_node) {
18  // recursively print the paths to the leafs
19 
20  // number and species name
21  GBDATA *data = GB_entry(_pb_node, "num");
22  const char *buffer = GB_read_char_pntr(data);
23  SpeciesID id = atoi(buffer);
24 
25  // probe(s)
26  GBDATA *pb_group = GB_entry(_pb_node, "group");
27  if (!pb_group) {
28  id = -id;
29  }
30 
31  // path
32  __PATH->push_back(id);
33 
34  // child(ren)
35  GBDATA *pb_child = PS_get_first_node(_pb_node);
36  if (pb_child) {
37  while (pb_child) {
38  PS_print_paths(pb_child);
39  pb_child = PS_get_next_node(pb_child);
40  }
41  }
42  else {
43  // print path in leaf nodes
44  printf("[%6zu] ", __PATH->size());
45  for (IDVectorCIter i=__PATH->begin(); i != __PATH->end(); ++i) {
46  printf("%6i ", *i);
47  }
48  printf("\n");
49  }
50 
51  // path
52  __PATH->pop_back();
53 }
54 
55 
56 int main(int argc, char *argv[]) {
58  if (argc < 2) {
59  error = GBS_global_string("Missing arguments\n Usage %s <input database name>", argv[0]);
60  }
61  else {
62  const char *input_DB_name = argv[1];
63  printf("Loading probe-group-database '%s'..\n", input_DB_name);
64 
65  GBDATA *pb_main = GB_open(input_DB_name, "rwcN"); // open probe-group-database
66  if (!pb_main) error = GB_await_error();
67  else {
68  GB_transaction ta(pb_main);
69  GBDATA *group_tree = GB_entry(pb_main, "group_tree");
70  if (!group_tree) error = "no 'group_tree' in database";
71  else {
72  GBDATA *first_level_node = PS_get_first_node(group_tree);
73  if (!first_level_node) error = "no 'node' found in group_tree";
74  else {
75  printf("dumping probes... (starting with first toplevel nodes)\n");
76  // print 1st level nodes (and its subtrees)
77  do {
78  PS_print_paths(first_level_node);
79  first_level_node = PS_get_next_node(first_level_node);
80  }
81  while (first_level_node);
82  }
83  }
84  }
85  }
86 
87  if (error) {
88  fprintf(stderr, "Error in %s: %s\n", argv[0], error);
89  return EXIT_FAILURE;
90  }
91  return EXIT_SUCCESS;
92 }
93 
94 
GBDATA * GB_open(const char *path, const char *opent)
Definition: ad_load.cxx:1363
IDVector::const_iterator IDVectorCIter
Definition: ps_defs.hxx:34
const char * id
Definition: AliAdmin.cxx:17
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
static IDVector * __PATH
#define EXIT_SUCCESS
Definition: arb_a2ps.c:154
char buffer[MESSAGE_BUFFERSIZE]
Definition: seq_search.cxx:34
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
GBDATA * PS_get_first_node(GBDATA *pb_nodecontainer)
static void error(const char *msg)
Definition: mkptypes.cxx:96
#define EXIT_FAILURE
Definition: arb_a2ps.c:157
GBDATA * PS_get_next_node(GBDATA *pb_node)
int main(int argc, char *argv[])
std::vector< SpeciesID > IDVector
Definition: ps_defs.hxx:32
#define NULp
Definition: cxxforward.h:116
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:904
static void PS_print_paths(GBDATA *_pb_node)
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334