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