1 | // ==================================================================== // |
---|
2 | // // |
---|
3 | // File : MG_gene_species.cxx // |
---|
4 | // Purpose : Transfer fields from organism and gene when // |
---|
5 | // transferring gene species // |
---|
6 | // // |
---|
7 | // // |
---|
8 | // Coded by Ralf Westram (coder@reallysoft.de) in July 2002 // |
---|
9 | // Copyright Department of Microbiology (Technical University Munich) // |
---|
10 | // // |
---|
11 | // Visit our web site at: http://www.arb-home.de/ // |
---|
12 | // // |
---|
13 | // // |
---|
14 | // ==================================================================== // |
---|
15 | |
---|
16 | #include "merge.hxx" |
---|
17 | |
---|
18 | #include <awt_config_manager.hxx> |
---|
19 | #include <aw_awar.hxx> |
---|
20 | #include <aw_root.hxx> |
---|
21 | #include <aw_msg.hxx> |
---|
22 | #include <aw_select.hxx> |
---|
23 | #include <arbdbt.h> |
---|
24 | #include <arb_str.h> |
---|
25 | |
---|
26 | #define AWAR_MERGE_GENE_SPECIES_SAV AWAR_MERGE_SAV "gene_species/" |
---|
27 | #define AWAR_MERGE_GENE_SPECIES_TMP AWAR_MERGE_TMP "gene_species/" |
---|
28 | |
---|
29 | // for input : |
---|
30 | |
---|
31 | #define AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD AWAR_MERGE_GENE_SPECIES_TMP "current" |
---|
32 | #define AWAR_MERGE_GENE_SPECIES_DEST AWAR_MERGE_GENE_SPECIES_TMP "dest" |
---|
33 | #define AWAR_MERGE_GENE_SPECIES_SOURCE AWAR_MERGE_GENE_SPECIES_TMP "source" |
---|
34 | #define AWAR_MERGE_GENE_SPECIES_METHOD AWAR_MERGE_GENE_SPECIES_TMP "method" |
---|
35 | #define AWAR_MERGE_GENE_SPECIES_ACI AWAR_MERGE_GENE_SPECIES_TMP "aci" |
---|
36 | #define AWAR_MERGE_GENE_SPECIES_EXAMPLE AWAR_MERGE_GENE_SPECIES_TMP "example" |
---|
37 | #define AWAR_MERGE_GENE_SPECIES_FIELDS_SAVE AWAR_MERGE_GENE_SPECIES_TMP "save" // only used to save/load config |
---|
38 | |
---|
39 | // saved awars : |
---|
40 | #define AWAR_MERGE_GENE_SPECIES_CREATE_FIELDS AWAR_MERGE_GENE_SPECIES_SAV "activated" |
---|
41 | #define AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS AWAR_MERGE_GENE_SPECIES_SAV "field_defs" |
---|
42 | |
---|
43 | enum CreationMethod { |
---|
44 | MG_CREATE_COPY_ORGANISM, |
---|
45 | MG_CREATE_COPY_GENE, |
---|
46 | MG_CREATE_USING_ACI_ONLY |
---|
47 | }; |
---|
48 | |
---|
49 | static AW_default MG_props = 0; // pointer current applications properties database |
---|
50 | |
---|
51 | void MG_create_gene_species_awars(AW_root *aw_root, AW_default aw_def) { |
---|
52 | aw_root->awar_int(AWAR_MERGE_GENE_SPECIES_METHOD, 0, aw_def); |
---|
53 | aw_root->awar_string(AWAR_MERGE_GENE_SPECIES_ACI, "", aw_def); |
---|
54 | aw_root->awar_string(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD, "", aw_def); |
---|
55 | aw_root->awar_string(AWAR_MERGE_GENE_SPECIES_DEST, "", aw_def); |
---|
56 | aw_root->awar_string(AWAR_MERGE_GENE_SPECIES_EXAMPLE, "", aw_def); |
---|
57 | aw_root->awar_string(AWAR_MERGE_GENE_SPECIES_SOURCE, "", aw_def); |
---|
58 | |
---|
59 | aw_root->awar_int(AWAR_MERGE_GENE_SPECIES_CREATE_FIELDS, 0, aw_def); |
---|
60 | aw_root->awar_string(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS, ";", aw_def); |
---|
61 | aw_root->awar_string(AWAR_MERGE_GENE_SPECIES_FIELDS_SAVE, "", aw_def); |
---|
62 | |
---|
63 | MG_props = aw_def; |
---|
64 | } |
---|
65 | |
---|
66 | #define BUFSIZE 100 |
---|
67 | |
---|
68 | inline char *strcpydest(char *dest, const char *src) { |
---|
69 | // like strcpy, but returns pointer to zero terminator |
---|
70 | int i = 0; |
---|
71 | while (src[i]) { |
---|
72 | dest[i] = src[i]; |
---|
73 | i++; |
---|
74 | } |
---|
75 | dest[i] = 0; |
---|
76 | return dest+i; |
---|
77 | } |
---|
78 | |
---|
79 | inline const char *field_awar(const char *field_name, const char *subfield) { |
---|
80 | static char buffer[BUFSIZE]; |
---|
81 | |
---|
82 | char *end = strcpydest(strcpydest(buffer, AWAR_MERGE_GENE_SPECIES_SAV"def_"), field_name); |
---|
83 | *end++ = '/'; |
---|
84 | IF_DEBUG(end=) strcpydest(end, subfield); |
---|
85 | |
---|
86 | mg_assert((end-buffer)<BUFSIZE); |
---|
87 | |
---|
88 | return buffer; |
---|
89 | } |
---|
90 | |
---|
91 | inline const char *current_field_awar(AW_root *aw_root, const char *subfield) { |
---|
92 | static char *cur_field = 0; |
---|
93 | |
---|
94 | freeset(cur_field, aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->read_string()); |
---|
95 | |
---|
96 | if (cur_field[0]) return field_awar(cur_field, subfield); |
---|
97 | return 0; // no field definition selected |
---|
98 | } |
---|
99 | |
---|
100 | static void create_awars_for_field(const char *cur_field) { |
---|
101 | // Note : MG_current_field_def_changed_cb also creates these awars! |
---|
102 | AW_root *aw_root = AW_root::SINGLETON; |
---|
103 | aw_root->awar_string(field_awar(cur_field, "source"), cur_field, MG_props); |
---|
104 | aw_root->awar_int(field_awar(cur_field, "method"), 1, MG_props); |
---|
105 | aw_root->awar_string(field_awar(cur_field, "aci"), "", MG_props); |
---|
106 | } |
---|
107 | |
---|
108 | static char *MG_create_field_content(GBDATA *gb_species, CreationMethod method, const char *origins_field, const char *aci, GB_ERROR& error, GB_HASH *organism_hash) { |
---|
109 | // does not write to database (only creates the content) |
---|
110 | mg_assert(GEN_is_pseudo_gene_species(gb_species)); |
---|
111 | |
---|
112 | char *result = 0; |
---|
113 | GBDATA *gb_origin = 0; |
---|
114 | |
---|
115 | switch (method) { |
---|
116 | case MG_CREATE_COPY_ORGANISM: |
---|
117 | gb_origin = GEN_find_origin_organism(gb_species, organism_hash); |
---|
118 | if (!gb_origin) { |
---|
119 | error = GBS_global_string("Origin-Organism '%s' not found", GEN_origin_organism(gb_species)); |
---|
120 | } |
---|
121 | break; |
---|
122 | case MG_CREATE_COPY_GENE: |
---|
123 | gb_origin = GEN_find_origin_gene(gb_species, organism_hash); |
---|
124 | if (!gb_origin) { |
---|
125 | error = GBS_global_string("Origin-Gene '%s/%s' not found", |
---|
126 | GEN_origin_organism(gb_species), GEN_origin_gene(gb_species)); |
---|
127 | } |
---|
128 | break; |
---|
129 | case MG_CREATE_USING_ACI_ONLY: |
---|
130 | break; |
---|
131 | } |
---|
132 | |
---|
133 | if (gb_origin) { // read source field |
---|
134 | if (origins_field[0]) { |
---|
135 | GBDATA *gb_field = GB_entry(gb_origin, origins_field); |
---|
136 | if (!gb_field) { |
---|
137 | error = GBS_global_string("Field not found: '%s'", origins_field); |
---|
138 | } |
---|
139 | else { |
---|
140 | result = GB_read_as_string(gb_field); |
---|
141 | } |
---|
142 | } |
---|
143 | else { |
---|
144 | error = "Specify a 'Source field'"; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | if (!error) { |
---|
149 | char *aci_result = 0; |
---|
150 | |
---|
151 | if (method == MG_CREATE_USING_ACI_ONLY) { |
---|
152 | mg_assert(!result); |
---|
153 | aci_result = GB_command_interpreter(GLOBAL_gb_src, "", aci, gb_species, 0); |
---|
154 | if (!aci_result) error = GB_await_error(); |
---|
155 | } |
---|
156 | else { |
---|
157 | if (aci && aci[0]) { |
---|
158 | aci_result = GB_command_interpreter(GLOBAL_gb_src, result ? result : "", aci, gb_origin, 0); |
---|
159 | if (!aci_result) error = GB_await_error(); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | if (aci_result) freeset(result, aci_result); |
---|
164 | } |
---|
165 | |
---|
166 | if (error) freenull(result); |
---|
167 | |
---|
168 | mg_assert(result||error); |
---|
169 | return result; |
---|
170 | } |
---|
171 | |
---|
172 | GB_ERROR MG_export_fields(AW_root *aw_root, GBDATA *gb_src, GBDATA *gb_dst, GB_HASH *error_suppressor, GB_HASH *source_organism_hash) { |
---|
173 | // Export fields from pseudo-species' source-organism to exported destination-species |
---|
174 | // error_suppressor and source_organism_hash may be NULL |
---|
175 | |
---|
176 | int export_fields = aw_root->awar(AWAR_MERGE_GENE_SPECIES_CREATE_FIELDS)->read_int(); |
---|
177 | |
---|
178 | if (export_fields) { // should fields be exported ? |
---|
179 | mg_assert(GEN_is_pseudo_gene_species(gb_src)); |
---|
180 | |
---|
181 | char *existing_definitions = aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->read_string(); |
---|
182 | char *start = existing_definitions+1; |
---|
183 | |
---|
184 | mg_assert(existing_definitions[0] == ';'); |
---|
185 | |
---|
186 | GB_ERROR error = 0; |
---|
187 | while (!error && start[0]) { // parse existing definitions and add them to selection list |
---|
188 | char *end = strchr(start, ';'); |
---|
189 | if (!end) end = strchr(start, 0); |
---|
190 | int len = end-start; |
---|
191 | if (len<1) break; |
---|
192 | |
---|
193 | mg_assert(end[0] == ';'); |
---|
194 | end[0] = 0; |
---|
195 | |
---|
196 | // export one field (start contains destination field name) |
---|
197 | { |
---|
198 | create_awars_for_field(start); |
---|
199 | CreationMethod method = (CreationMethod)aw_root->awar(field_awar(start, "method"))->read_int(); |
---|
200 | char *source = aw_root->awar(field_awar(start, "source"))->read_string(); |
---|
201 | char *aci = aw_root->awar(field_awar(start, "aci"))->read_string(); |
---|
202 | |
---|
203 | char *result = MG_create_field_content(gb_src, method, source, aci, error, source_organism_hash); |
---|
204 | mg_assert(result || error); |
---|
205 | |
---|
206 | if (result) { |
---|
207 | error = GBT_write_string(gb_dst, start, result); |
---|
208 | free(result); |
---|
209 | } |
---|
210 | else { |
---|
211 | long error_seen = error_suppressor ? GBS_read_hash(error_suppressor, error) : 0; |
---|
212 | #define MAX_EQUAL_WARNINGS 10 |
---|
213 | if (error_seen >= MAX_EQUAL_WARNINGS) { |
---|
214 | if (error_seen == MAX_EQUAL_WARNINGS) { |
---|
215 | aw_message(GBS_global_string("More than %i warnings about '%s' (suppressing)", MAX_EQUAL_WARNINGS, error)); |
---|
216 | } |
---|
217 | } |
---|
218 | else { |
---|
219 | aw_message(GBS_global_string("'%s' when exporting %s (continuing)", error, GBT_read_name(gb_src))); |
---|
220 | } |
---|
221 | if (error_suppressor) { |
---|
222 | GBS_incr_hash(error_suppressor, error); |
---|
223 | GBS_optimize_hash(error_suppressor); |
---|
224 | } |
---|
225 | error = 0; |
---|
226 | } |
---|
227 | |
---|
228 | free(aci); |
---|
229 | free(source); |
---|
230 | } |
---|
231 | |
---|
232 | start = end+1; |
---|
233 | } |
---|
234 | |
---|
235 | aw_message_if(error); |
---|
236 | free(existing_definitions); |
---|
237 | } |
---|
238 | |
---|
239 | return 0; |
---|
240 | } |
---|
241 | |
---|
242 | static char *MG_create_current_field_content(AW_root *aw_root, GBDATA *gb_species, GB_ERROR& error) { |
---|
243 | CreationMethod method = (CreationMethod)aw_root->awar(AWAR_MERGE_GENE_SPECIES_METHOD)->read_int(); |
---|
244 | char *origins_field = aw_root->awar(AWAR_MERGE_GENE_SPECIES_SOURCE)->read_string(); |
---|
245 | char *aci = aw_root->awar(AWAR_MERGE_GENE_SPECIES_ACI)->read_string(); |
---|
246 | |
---|
247 | char *result = MG_create_field_content(gb_species, method, origins_field, aci, error, 0); |
---|
248 | |
---|
249 | free(aci); |
---|
250 | free(origins_field); |
---|
251 | |
---|
252 | return result; |
---|
253 | } |
---|
254 | |
---|
255 | static void MG_update_example(AW_root *aw_root) { |
---|
256 | char *result = 0; |
---|
257 | GB_ERROR error = 0; |
---|
258 | char *curr_species = aw_root->awar(MG_left_AWAR_SPECIES_NAME())->read_string(); |
---|
259 | |
---|
260 | if (!curr_species || !curr_species[0]) error = "No species selected."; |
---|
261 | else { |
---|
262 | GB_transaction ta(GLOBAL_gb_src); |
---|
263 | GBDATA *gb_species = GBT_find_species(GLOBAL_gb_src, curr_species); |
---|
264 | |
---|
265 | if (!gb_species) error = GB_export_errorf("No such species: '%s'", curr_species); |
---|
266 | else if (!GEN_is_pseudo_gene_species(gb_species)) error = "Selected species is no gene-species"; |
---|
267 | else { |
---|
268 | result = MG_create_current_field_content(aw_root, gb_species, error); |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | if (!error && !result) error = "no result"; |
---|
273 | if (error) freeset(result, GBS_global_string_copy("<%s>", error)); |
---|
274 | |
---|
275 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_EXAMPLE)->write_string(result); |
---|
276 | |
---|
277 | free(result); |
---|
278 | free(curr_species); |
---|
279 | } |
---|
280 | |
---|
281 | static void check_and_correct_current_field(char*& cur_field) { |
---|
282 | if (ARB_stricmp(cur_field, "name") == 0 || ARB_stricmp(cur_field, "acc") == 0) { |
---|
283 | aw_message("rules writing to 'name' or 'acc' are not allowed."); |
---|
284 | freeset(cur_field, GBS_global_string_copy("%s_not_allowed", cur_field)); |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | static bool allow_callbacks = true; |
---|
290 | |
---|
291 | static void MG_current_field_def_changed_cb(AW_root *aw_root) { |
---|
292 | if (allow_callbacks) { |
---|
293 | LocallyModify<bool> flag(allow_callbacks, false); |
---|
294 | |
---|
295 | char *cur_field = aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->read_string(); |
---|
296 | check_and_correct_current_field(cur_field); |
---|
297 | |
---|
298 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->write_string(cur_field); |
---|
299 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_DEST)->write_string(cur_field); |
---|
300 | |
---|
301 | if (cur_field[0]) { |
---|
302 | const char *awar_name = field_awar(cur_field, "source"); |
---|
303 | |
---|
304 | // read stored source field (if undef default to new value of destination field) |
---|
305 | char *source_field = aw_root->awar_string(awar_name, cur_field, MG_props)->read_string(); |
---|
306 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_SOURCE)->write_string(source_field); |
---|
307 | free(source_field); |
---|
308 | |
---|
309 | // read stored method (if undef then default to currently visible method) |
---|
310 | awar_name = field_awar(cur_field, "method"); |
---|
311 | int def_method = aw_root->awar(AWAR_MERGE_GENE_SPECIES_METHOD)->read_int(); |
---|
312 | int method = aw_root->awar_int(awar_name, def_method, MG_props)->read_int(); |
---|
313 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_METHOD)->write_int(method); |
---|
314 | |
---|
315 | // read stored aci (if undef then default to currently visible aci ) |
---|
316 | awar_name = field_awar(cur_field, "aci"); |
---|
317 | char *curr_aci = aw_root->awar(AWAR_MERGE_GENE_SPECIES_ACI)->read_string(); |
---|
318 | char *aci = aw_root->awar_string(awar_name, curr_aci, MG_props)->read_string(); |
---|
319 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_ACI)->write_string(aci); |
---|
320 | free(aci); |
---|
321 | free(curr_aci); |
---|
322 | |
---|
323 | MG_update_example(aw_root); |
---|
324 | } |
---|
325 | |
---|
326 | free(cur_field); |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | static void MG_source_field_changed_cb(AW_root *aw_root) { |
---|
331 | if (allow_callbacks) { |
---|
332 | const char *awar_name = current_field_awar(aw_root, "source"); |
---|
333 | if (awar_name) { // if a rule is selected |
---|
334 | char *source_field = aw_root->awar(AWAR_MERGE_GENE_SPECIES_SOURCE)->read_string(); |
---|
335 | int method = aw_root->awar(AWAR_MERGE_GENE_SPECIES_METHOD)->read_int(); |
---|
336 | |
---|
337 | if (source_field[0] && method == MG_CREATE_USING_ACI_ONLY) { |
---|
338 | aw_message("Source field is not used with this method"); |
---|
339 | source_field[0] = 0; |
---|
340 | } |
---|
341 | |
---|
342 | aw_root->awar(awar_name)->write_string(source_field); |
---|
343 | free(source_field); |
---|
344 | |
---|
345 | MG_update_example(aw_root); |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | static void MG_dest_field_changed_cb(AW_root *aw_root) { |
---|
351 | if (allow_callbacks) { |
---|
352 | // if this is changed -> a new definition will be generated |
---|
353 | char *dest_field = aw_root->awar(AWAR_MERGE_GENE_SPECIES_DEST)->read_string(); |
---|
354 | check_and_correct_current_field(dest_field); |
---|
355 | |
---|
356 | const char *search = GBS_global_string(";%s;", dest_field); |
---|
357 | char *existing_definitions = aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->read_string(); |
---|
358 | |
---|
359 | mg_assert(existing_definitions[0] == ';'); |
---|
360 | |
---|
361 | if (strstr(existing_definitions, search) == 0) { // not found -> create a new definition |
---|
362 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS) |
---|
363 | ->write_string(GBS_global_string("%s%s;", existing_definitions, dest_field)); |
---|
364 | |
---|
365 | } |
---|
366 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->write_string(dest_field); |
---|
367 | |
---|
368 | free(existing_definitions); |
---|
369 | free(dest_field); |
---|
370 | |
---|
371 | MG_update_example(aw_root); |
---|
372 | } |
---|
373 | } |
---|
374 | |
---|
375 | static void MG_method_changed_cb(AW_root *aw_root) { |
---|
376 | if (allow_callbacks) { |
---|
377 | const char *awar_name = current_field_awar(aw_root, "method"); |
---|
378 | |
---|
379 | if (awar_name) { |
---|
380 | int method = aw_root->awar(AWAR_MERGE_GENE_SPECIES_METHOD)->read_int(); |
---|
381 | aw_root->awar(awar_name)->write_int(method); |
---|
382 | if (method == MG_CREATE_USING_ACI_ONLY) { |
---|
383 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_SOURCE)->write_string(""); // clear source field |
---|
384 | } |
---|
385 | MG_update_example(aw_root); |
---|
386 | } |
---|
387 | } |
---|
388 | } |
---|
389 | |
---|
390 | static void MG_delete_selected_field_def(AW_window *aww) { |
---|
391 | AW_root *aw_root = aww->get_root(); |
---|
392 | char *cur_field = aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->read_string(); |
---|
393 | |
---|
394 | if (cur_field[0]) { |
---|
395 | char *existing_definitions = aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->read_string(); |
---|
396 | const char *search = GBS_global_string(";%s;", cur_field); |
---|
397 | |
---|
398 | mg_assert(existing_definitions[0] == ';'); |
---|
399 | |
---|
400 | char *found = strstr(existing_definitions, search); |
---|
401 | mg_assert(found); |
---|
402 | if (found) { |
---|
403 | strcpy(found, found+strlen(cur_field)+1); // remove that config |
---|
404 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->write_string(existing_definitions); |
---|
405 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->write_string(""); |
---|
406 | } |
---|
407 | |
---|
408 | free(existing_definitions); |
---|
409 | } |
---|
410 | else { |
---|
411 | aw_message("No field selected."); |
---|
412 | } |
---|
413 | |
---|
414 | free(cur_field); |
---|
415 | } |
---|
416 | |
---|
417 | static void MG_aci_changed_cb(AW_root *aw_root) { |
---|
418 | if (allow_callbacks) { |
---|
419 | const char *awar_name = current_field_awar(aw_root, "aci"); |
---|
420 | if (awar_name) { // if a rule is selected |
---|
421 | char *aci = aw_root->awar(AWAR_MERGE_GENE_SPECIES_ACI)->read_string(); |
---|
422 | aw_root->awar(awar_name)->write_string(aci); |
---|
423 | free(aci); |
---|
424 | MG_update_example(aw_root); |
---|
425 | } |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | static void MG_update_selection_list_on_field_transfers(AW_root *aw_root, AW_selection_list *geneSpecFieldList) { |
---|
430 | geneSpecFieldList->clear(); |
---|
431 | |
---|
432 | { |
---|
433 | char *existing_definitions = aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->read_string(); |
---|
434 | char *start = existing_definitions+1; |
---|
435 | |
---|
436 | mg_assert(existing_definitions[0] == ';'); |
---|
437 | |
---|
438 | while (start[0]) { // parse existing definitions and add them to selection list |
---|
439 | char *end = strchr(start, ';'); |
---|
440 | if (!end) end = strchr(start, 0); |
---|
441 | int len = end-start; |
---|
442 | if (len<1) break; |
---|
443 | |
---|
444 | mg_assert(end[0] == ';'); |
---|
445 | end[0] = 0; |
---|
446 | geneSpecFieldList->insert(start, start); |
---|
447 | start = end+1; |
---|
448 | } |
---|
449 | |
---|
450 | free(existing_definitions); |
---|
451 | } |
---|
452 | |
---|
453 | geneSpecFieldList->insert_default("", ""); |
---|
454 | geneSpecFieldList->update(); |
---|
455 | } |
---|
456 | |
---|
457 | static void init_gene_species_xfer_fields_subconfig(AWT_config_definition& cdef, char *existing_definitions) { |
---|
458 | char *start = existing_definitions+1; |
---|
459 | mg_assert(existing_definitions[0] == ';'); |
---|
460 | |
---|
461 | for (int count = 0; start[0]; ++count) { // parse existing definitions and add them to config |
---|
462 | char *end = strchr(start, ';'); |
---|
463 | if (!end) end = strchr(start, 0); |
---|
464 | int len = end-start; |
---|
465 | if (len<1) break; |
---|
466 | |
---|
467 | mg_assert(end[0] == ';'); |
---|
468 | end[0] = 0; |
---|
469 | |
---|
470 | // add config : |
---|
471 | #define add_config(s, id) cdef.add(field_awar(s, id), id, count) |
---|
472 | |
---|
473 | create_awars_for_field(start); |
---|
474 | |
---|
475 | add_config(start, "source"); |
---|
476 | add_config(start, "method"); |
---|
477 | add_config(start, "aci"); |
---|
478 | |
---|
479 | #undef add_config |
---|
480 | |
---|
481 | end[0] = ';'; |
---|
482 | |
---|
483 | start = end+1; |
---|
484 | } |
---|
485 | } |
---|
486 | static void init_gene_species_xfer_fields_config(AWT_config_definition& cdef) { |
---|
487 | cdef.add(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS, "fields"); |
---|
488 | cdef.add(AWAR_MERGE_GENE_SPECIES_FIELDS_SAVE, "defs"); |
---|
489 | } |
---|
490 | static char *store_gene_species_xfer_fields(AW_CL, AW_CL) { |
---|
491 | AW_root *aw_root = AW_root::SINGLETON; |
---|
492 | { |
---|
493 | char *existing_definitions = aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->read_string(); |
---|
494 | AWT_config_definition cdef; |
---|
495 | |
---|
496 | init_gene_species_xfer_fields_subconfig(cdef, existing_definitions); |
---|
497 | |
---|
498 | char *sub_config = cdef.read(); // save single configs to sub_config |
---|
499 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_SAVE)->write_string(sub_config); |
---|
500 | |
---|
501 | free(sub_config); |
---|
502 | free(existing_definitions); |
---|
503 | } |
---|
504 | |
---|
505 | // save AWAR_MERGE_GENE_SPECIES_FIELDS_SAVE and AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS |
---|
506 | AWT_config_definition sub_cdef; |
---|
507 | init_gene_species_xfer_fields_config(sub_cdef); |
---|
508 | return sub_cdef.read(); |
---|
509 | } |
---|
510 | static void load_gene_species_xfer_fields(const char *stored_string, AW_CL cl_geneSpecFieldList, AW_CL) { |
---|
511 | AW_root *aw_root = AW_root::SINGLETON; |
---|
512 | |
---|
513 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->write_string(""); // de-select |
---|
514 | |
---|
515 | // Load 'AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS' and 'AWAR_MERGE_GENE_SPECIES_FIELDS_SAVE' |
---|
516 | { |
---|
517 | AWT_config_definition sub_cdef; |
---|
518 | init_gene_species_xfer_fields_config(sub_cdef); |
---|
519 | sub_cdef.write(stored_string); |
---|
520 | } |
---|
521 | |
---|
522 | { |
---|
523 | char *existing_definitions = aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->read_string(); |
---|
524 | char *sub_config = aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_SAVE)->read_string(); |
---|
525 | |
---|
526 | AWT_config_definition cdef; |
---|
527 | init_gene_species_xfer_fields_subconfig(cdef, existing_definitions); |
---|
528 | cdef.write(sub_config); |
---|
529 | |
---|
530 | free(sub_config); |
---|
531 | free(existing_definitions); |
---|
532 | } |
---|
533 | |
---|
534 | // refresh mask : |
---|
535 | MG_update_selection_list_on_field_transfers(aw_root, (AW_selection_list*)cl_geneSpecFieldList); |
---|
536 | } |
---|
537 | |
---|
538 | AW_window *MG_gene_species_create_field_transfer_def_window(AW_root *aw_root) { |
---|
539 | static AW_window_simple *aws = 0; |
---|
540 | if (aws) return aws; |
---|
541 | |
---|
542 | aws = new AW_window_simple; |
---|
543 | aws->init(aw_root, "DEFINE_GENE_SPECIES_FIELDS", "DEFINE FIELDS EXPORTED WITH GENE SPECIES"); |
---|
544 | aws->load_xfig("merge/mg_def_gene_species_fields.fig"); |
---|
545 | |
---|
546 | aws->at("close"); |
---|
547 | aws->callback(AW_POPDOWN); |
---|
548 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
549 | |
---|
550 | aws->at("help"); |
---|
551 | aws->callback(makeHelpCallback("gene_species_field_transfer.hlp")); |
---|
552 | aws->create_button("HELP", "HELP"); |
---|
553 | |
---|
554 | aws->at("active"); |
---|
555 | aws->create_toggle(AWAR_MERGE_GENE_SPECIES_CREATE_FIELDS); |
---|
556 | |
---|
557 | aws->at("src"); |
---|
558 | aws->create_input_field(AWAR_MERGE_GENE_SPECIES_SOURCE); |
---|
559 | |
---|
560 | aws->at("delete"); |
---|
561 | aws->callback(MG_delete_selected_field_def); |
---|
562 | aws->create_button("DELETE", "DELETE"); |
---|
563 | |
---|
564 | aws->at("sel_method"); |
---|
565 | aws->create_toggle_field(AWAR_MERGE_GENE_SPECIES_METHOD, 0, ""); |
---|
566 | aws->insert_toggle("Copy from organism", "O", MG_CREATE_COPY_ORGANISM); |
---|
567 | aws->insert_toggle("Copy from gene", "G", MG_CREATE_COPY_GENE); |
---|
568 | aws->insert_toggle("Only use ACI below", "A", MG_CREATE_USING_ACI_ONLY); |
---|
569 | aws->update_toggle_field(); |
---|
570 | |
---|
571 | aws->at("aci"); |
---|
572 | aws->create_input_field(AWAR_MERGE_GENE_SPECIES_ACI); |
---|
573 | |
---|
574 | aws->at("dest"); |
---|
575 | aws->create_input_field(AWAR_MERGE_GENE_SPECIES_DEST); |
---|
576 | |
---|
577 | aws->at("example"); |
---|
578 | aws->create_text_field(AWAR_MERGE_GENE_SPECIES_EXAMPLE, 40, 3); |
---|
579 | |
---|
580 | aws->at("fields"); |
---|
581 | AW_selection_list *geneSpecFieldList = aws->create_selection_list(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD, 10, 30, true); |
---|
582 | |
---|
583 | MG_update_selection_list_on_field_transfers(aw_root, geneSpecFieldList); |
---|
584 | |
---|
585 | aws->at("save"); |
---|
586 | AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "gene_species_field_xfer", |
---|
587 | store_gene_species_xfer_fields, load_gene_species_xfer_fields, (AW_CL)geneSpecFieldList, 0); |
---|
588 | |
---|
589 | // add callbacks for this window : |
---|
590 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_FIELDS_DEFS)->add_callback(makeRootCallback(MG_update_selection_list_on_field_transfers, geneSpecFieldList)); |
---|
591 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_CURRENT_FIELD)->add_callback(MG_current_field_def_changed_cb); |
---|
592 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_SOURCE)->add_callback(MG_source_field_changed_cb); |
---|
593 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_DEST)->add_callback(MG_dest_field_changed_cb); |
---|
594 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_METHOD)->add_callback(MG_method_changed_cb); |
---|
595 | aw_root->awar(AWAR_MERGE_GENE_SPECIES_ACI)->add_callback(MG_aci_changed_cb); |
---|
596 | aw_root->awar(MG_left_AWAR_SPECIES_NAME())->add_callback(MG_update_example); |
---|
597 | |
---|
598 | return aws; |
---|
599 | } |
---|
600 | |
---|
601 | |
---|
602 | |
---|
603 | |
---|
604 | |
---|