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 | |
---|
32 | GBDATA *gb_main = get_gb_main(); |
---|
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 | |
---|
77 | ARB_calloc(hash_elements, nentries); |
---|
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 | |
---|