1 | // ============================================================= // |
---|
2 | // // |
---|
3 | // File : MP_mo_liste.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // ============================================================= // |
---|
10 | |
---|
11 | #include "MP_externs.hxx" |
---|
12 | #include "MultiProbe.hxx" |
---|
13 | |
---|
14 | #include <aw_msg.hxx> |
---|
15 | #include <arbdbt.h> |
---|
16 | #include <client.h> |
---|
17 | |
---|
18 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Methoden MO_Liste |
---|
19 | |
---|
20 | GBDATA *MO_Liste::gb_main = NULL; |
---|
21 | |
---|
22 | MO_Liste::MO_Liste() { |
---|
23 | mp_assert(gb_main); |
---|
24 | |
---|
25 | laenge = 0; |
---|
26 | mo_liste = NULL; |
---|
27 | current = 0; |
---|
28 | hashptr = NULL; |
---|
29 | // Nach dem new muss die MO_Liste erst mit fill_all_bakts bzw fill_marked_bakts gefuellt werden |
---|
30 | } |
---|
31 | |
---|
32 | MO_Liste::~MO_Liste() |
---|
33 | { |
---|
34 | while (laenge) |
---|
35 | { |
---|
36 | delete mo_liste[laenge-1]; |
---|
37 | laenge--; |
---|
38 | } |
---|
39 | delete [] mo_liste; |
---|
40 | if (hashptr) GBS_free_hash(hashptr); |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | void MO_Liste::get_all_species() { |
---|
45 | const char *servername = NULL; |
---|
46 | char *match_name = NULL; |
---|
47 | char toksep[2]; |
---|
48 | char *probe = NULL; |
---|
49 | char *locs_error; |
---|
50 | bytestring bs; |
---|
51 | int i = 0; |
---|
52 | long j = 0, nr_of_species; |
---|
53 | |
---|
54 | if (!(servername=MP_probe_pt_look_for_server())) { |
---|
55 | return; |
---|
56 | } |
---|
57 | |
---|
58 | mp_pd_gl.link = aisc_open(servername, &mp_pd_gl.com, AISC_MAGIC_NUMBER); |
---|
59 | servername = 0; |
---|
60 | |
---|
61 | if (!mp_pd_gl.link) { |
---|
62 | aw_message ("Cannot contact Probe bank server "); |
---|
63 | return; |
---|
64 | } |
---|
65 | if (MP_init_local_com_struct()) { |
---|
66 | aw_message ("Cannot contact Probe bank server (2)"); |
---|
67 | return; |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | if (aisc_put(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs, NULL)) |
---|
72 | { |
---|
73 | free(probe); |
---|
74 | aw_message ("Connection to PT_SERVER lost (4)"); |
---|
75 | return; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | bs.data = 0; |
---|
80 | aisc_get(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs, |
---|
81 | LOCS_MP_ALL_SPECIES_STRING, &bs, |
---|
82 | LOCS_MP_COUNT_ALL_SPECIES, &nr_of_species, |
---|
83 | LOCS_ERROR, &locs_error, |
---|
84 | NULL); |
---|
85 | |
---|
86 | if (*locs_error) |
---|
87 | { |
---|
88 | aw_message(locs_error); |
---|
89 | } |
---|
90 | |
---|
91 | free(locs_error); |
---|
92 | |
---|
93 | laenge = nr_of_species; |
---|
94 | mo_liste = new Bakt_Info*[laenge+2]; |
---|
95 | while (j<laenge+2) |
---|
96 | { |
---|
97 | mo_liste[j] = NULL; |
---|
98 | j++; |
---|
99 | } |
---|
100 | current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULL |
---|
101 | |
---|
102 | // Initialisieren der Hashtabelle |
---|
103 | |
---|
104 | hashptr = GBS_create_hash(laenge + 1, GB_IGNORE_CASE); |
---|
105 | |
---|
106 | |
---|
107 | toksep[0] = 1; |
---|
108 | toksep[1] = 0; |
---|
109 | if (bs.data) |
---|
110 | { |
---|
111 | |
---|
112 | match_name = strtok(bs.data, toksep); |
---|
113 | GB_push_transaction(gb_main); |
---|
114 | while (match_name) |
---|
115 | { |
---|
116 | i++; |
---|
117 | if (!GBT_find_species(gb_main, match_name)) |
---|
118 | { // Testen, ob Bakterium auch im Baum existiert, um |
---|
119 | pt_server_different = true; |
---|
120 | return; |
---|
121 | } |
---|
122 | put_entry(match_name); |
---|
123 | match_name = strtok(0, toksep); |
---|
124 | } |
---|
125 | GB_pop_transaction(gb_main); |
---|
126 | } |
---|
127 | else |
---|
128 | aw_message("DB-query produced no species.\n"); |
---|
129 | |
---|
130 | |
---|
131 | aisc_close(mp_pd_gl.link); |
---|
132 | free(bs.data); |
---|
133 | |
---|
134 | delete match_name; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | positiontype MO_Liste::fill_marked_bakts() |
---|
140 | { |
---|
141 | long j = 0; |
---|
142 | GBDATA *gb_species; |
---|
143 | |
---|
144 | |
---|
145 | GB_push_transaction(gb_main); |
---|
146 | laenge = GBT_count_marked_species(gb_main); // laenge ist immer zuviel oder gleich der Anzahl wirklick markierter. weil pT-Server nur |
---|
147 | // die Bakterien mit Sequenz zurueckliefert. |
---|
148 | |
---|
149 | if (!laenge) { |
---|
150 | aw_message("Please mark some species!"); |
---|
151 | laenge = 1; |
---|
152 | } |
---|
153 | mo_liste = new Bakt_Info*[laenge+2]; |
---|
154 | |
---|
155 | while (j<laenge+2) |
---|
156 | { |
---|
157 | mo_liste[j] = NULL; |
---|
158 | j++; |
---|
159 | } |
---|
160 | current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULL |
---|
161 | |
---|
162 | hashptr = GBS_create_hash(laenge, GB_IGNORE_CASE); |
---|
163 | |
---|
164 | |
---|
165 | for (gb_species = GBT_first_marked_species(gb_main); |
---|
166 | gb_species; |
---|
167 | gb_species = GBT_next_marked_species(gb_species)) |
---|
168 | { |
---|
169 | put_entry(GBT_read_name(gb_species)); |
---|
170 | } |
---|
171 | |
---|
172 | GB_pop_transaction(gb_main); |
---|
173 | |
---|
174 | anz_elem_marked = laenge; |
---|
175 | |
---|
176 | return laenge; |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | long MO_Liste::get_laenge() |
---|
182 | { |
---|
183 | return laenge; |
---|
184 | } |
---|
185 | |
---|
186 | long MO_Liste::debug_get_current() |
---|
187 | { |
---|
188 | return current; |
---|
189 | } |
---|
190 | |
---|
191 | long MO_Liste::put_entry(const char* name) { |
---|
192 | // Pruefe: Gibts den Bakter schon in dieser Liste?? |
---|
193 | if (get_index_by_entry(name)) // wanns den Bakter scho gibt |
---|
194 | { |
---|
195 | // nicht eintragen |
---|
196 | } |
---|
197 | else |
---|
198 | { |
---|
199 | mo_liste[current] = new Bakt_Info(name); // MEL koennte mit match_name zusammenhaengen |
---|
200 | GBS_write_hash(hashptr, name, current); |
---|
201 | current++; |
---|
202 | } |
---|
203 | return current; |
---|
204 | } |
---|
205 | |
---|
206 | char* MO_Liste::get_entry_by_index(long index) |
---|
207 | { |
---|
208 | if ((0<index) && (index < current)) |
---|
209 | return mo_liste[index]->get_name(); |
---|
210 | else |
---|
211 | return NULL; |
---|
212 | } |
---|
213 | |
---|
214 | long MO_Liste::get_index_by_entry(const char* key) |
---|
215 | { |
---|
216 | if (key) |
---|
217 | return (GBS_read_hash(hashptr, key)); |
---|
218 | else |
---|
219 | return 0; |
---|
220 | } |
---|
221 | |
---|
222 | Bakt_Info* MO_Liste::get_bakt_info_by_index(long index) |
---|
223 | { |
---|
224 | if ((0<index) && (index < current)) |
---|
225 | return mo_liste[index]; |
---|
226 | else |
---|
227 | return NULL; |
---|
228 | } |
---|
229 | |
---|