source: tags/ms_r16q3/PHYLO/PH_data.cxx

Last change on this file was 15176, checked in by westram, 8 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
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
14char *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 = 0;
24    nentries = 0;
25    return 0;
26}
27
28char *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  = NULL;
37    nentries = 0;
38
39    PHENTRY *tail = NULL;
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_read_name(gb_species));
56                new_entry->full_name = GBT_read_string(gb_species, "full_name");
57
58                new_entry->prev = tail;
59                new_entry->next = NULL;
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 0;
86}
87
Note: See TracBrowser for help on using the repository browser.