ARB
PH_data.cxx
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : PH_data.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================= //
10 
11 #include "phylo.hxx"
12 #include <arbdbt.h>
13 
14 char *PHDATA::unload() { // @@@ never called (PHDATA never destructed)
15  PHENTRY *phentry;
16 
17  freenull(use);
18  for (phentry=entries; phentry; phentry=phentry->next) {
19  free(phentry->name);
20  free(phentry->full_name);
21  free(phentry);
22  }
23  entries = NULp;
24  nentries = 0;
25  return NULp;
26 }
27 
28 char *PHDATA::load(char*& Use) {
29  reassign(use, Use);
30  last_key_number = 0;
31 
33  GB_push_transaction(gb_main);
34 
35  seq_len = GBT_get_alignment_len(gb_main, use);
36  ph_assert(seq_len>0);
37 
38  entries = NULp;
39  nentries = 0;
40 
41  PHENTRY *tail = NULp;
42  for (GBDATA *gb_species = GBT_first_marked_species(gb_main);
43  gb_species;
44  gb_species = GBT_next_marked_species(gb_species))
45  {
46  GBDATA *gb_ali = GB_entry(gb_species, use);
47 
48  if (gb_ali) { // existing alignment for this species
49  GBDATA *gb_data = GB_entry(gb_ali, "data");
50 
51  if (gb_data) {
52  PHENTRY *new_entry = new PHENTRY;
53 
54  new_entry->gb_species_data_ptr = gb_data;
55 
56  new_entry->key = last_key_number++;
57  new_entry->name = ARB_strdup(GBT_get_name_or_description(gb_species));
58  new_entry->full_name = GBT_read_string(gb_species, "full_name");
59 
60  new_entry->prev = tail;
61  new_entry->next = NULp;
62 
63  if (!entries) {
64  tail = entries = new_entry;
65  }
66  else {
67  tail->next = new_entry;
68  tail = new_entry;
69  }
70  nentries++;
71  }
72  }
73  }
74 
75  GB_pop_transaction(gb_main);
76 
78 
79  {
80  PHENTRY *phentry = entries;
81  for (unsigned int i = 0; i < nentries; i++) {
82  hash_elements[i] = phentry;
83  phentry = phentry->next;
84  }
85  }
86 
87  return NULp;
88 }
89 
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:113
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:833
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2494
char * GBT_read_string(GBDATA *gb_container, const char *fieldpath)
Definition: adtools.cxx:267
unsigned int nentries
Definition: phylo.hxx:149
PHENTRY ** hash_elements
Definition: phylo.hxx:148
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
Definition: aditem.cxx:116
#define ph_assert(cond)
Definition: phylo.hxx:24
char * use
Definition: phylo.hxx:146
GBDATA * get_gb_main()
Definition: phylo.hxx:144
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2524
TYPE * ARB_calloc(size_t nelem)
Definition: arb_mem.h:81
#define NULp
Definition: cxxforward.h:116
char * load(char *&use)
Definition: PH_data.cxx:28
GBDATA * gb_main
Definition: adname.cxx:32
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:459
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334