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 | 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 | |
---|
75 | ARB_calloc(hash_elements, nentries); |
---|
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 | |
---|