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  entries = NULp;
37  nentries = 0;
38 
39  PHENTRY *tail = NULp;
40  for (GBDATA *gb_species = GBT_first_marked_species(gb_main);
41  gb_species;
42  gb_species = GBT_next_marked_species(gb_species))
43  {
44  GBDATA *gb_ali = GB_entry(gb_species, use);
45 
46  if (gb_ali) { // existing alignment for this species
47  GBDATA *gb_data = GB_entry(gb_ali, "data");
48 
49  if (gb_data) {
50  PHENTRY *new_entry = new PHENTRY;
51 
52  new_entry->gb_species_data_ptr = gb_data;
53 
54  new_entry->key = last_key_number++;
55  new_entry->name = ARB_strdup(GBT_get_name_or_description(gb_species));
56  new_entry->full_name = GBT_read_string(gb_species, "full_name");
57 
58  new_entry->prev = tail;
59  new_entry->next = NULp;
60 
61  if (!entries) {
62  tail = entries = new_entry;
63  }
64  else {
65  tail->next = new_entry;
66  tail = new_entry;
67  }
68  nentries++;
69  }
70  }
71  }
72 
73  GB_pop_transaction(gb_main);
74 
76 
77  {
78  PHENTRY *phentry = entries;
79  for (unsigned int i = 0; i < nentries; i++) {
80  hash_elements[i] = phentry;
81  phentry = phentry->next;
82  }
83  }
84 
85  return NULp;
86 }
87 
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:706
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2458
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
char * use
Definition: phylo.hxx:146
GBDATA * get_gb_main()
Definition: phylo.hxx:144
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2488
TYPE * ARB_calloc(size_t nelem)
Definition: arb_mem.h:81
#define NULp
Definition: cxxforward.h:97
char * load(char *&use)
Definition: PH_data.cxx:28
GBDATA * gb_main
Definition: adname.cxx:33
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:437
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334