1 | // ============================================================= // |
---|
2 | // // |
---|
3 | // File : GEN_interface.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in February 2001 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // ============================================================== // |
---|
11 | |
---|
12 | #include "GEN_local.hxx" |
---|
13 | |
---|
14 | #include <db_scanner.hxx> |
---|
15 | #include <db_query.h> |
---|
16 | #include <dbui.h> |
---|
17 | #include <item_sel_list.h> |
---|
18 | #include <info_window.h> |
---|
19 | |
---|
20 | #include <awt_sel_boxes.hxx> |
---|
21 | #include <awt_prompt.hxx> |
---|
22 | |
---|
23 | #include <aw_awar_defs.hxx> |
---|
24 | #include <aw_root.hxx> |
---|
25 | #include <aw_msg.hxx> |
---|
26 | #include <aw_question.hxx> |
---|
27 | |
---|
28 | #include <adGene.h> |
---|
29 | #include <Location.h> |
---|
30 | |
---|
31 | #include <arb_strarray.h> |
---|
32 | #include <arb_strbuf.h> |
---|
33 | |
---|
34 | using namespace std; |
---|
35 | |
---|
36 | // -------------------------------------------------------------------------------- |
---|
37 | |
---|
38 | #define AWAR_GENE_DEST "tmp/gene/dest" |
---|
39 | |
---|
40 | // -------------------------------------------------------------------------------- |
---|
41 | |
---|
42 | #define AD_F_ALL AWM_ALL // @@@ replace all occurrences of AD_F_ALL by AWM_ALL |
---|
43 | |
---|
44 | // -------------------------------------------------------------------------------- |
---|
45 | |
---|
46 | static void GEN_select_gene(GBDATA* /* gb_main */, AW_root *aw_root, const char *item_name) { |
---|
47 | char *organism = ARB_strdup(item_name); |
---|
48 | char *gene = strchr(organism, '/'); |
---|
49 | |
---|
50 | if (gene) { |
---|
51 | *gene++ = 0; |
---|
52 | aw_root->awar(AWAR_ORGANISM_NAME)->write_string(organism); |
---|
53 | aw_root->awar(AWAR_GENE_NAME)->write_string(gene); |
---|
54 | } |
---|
55 | else if (!item_name[0]) { // accept empty input -> deselect gene/organism |
---|
56 | aw_root->awar(AWAR_GENE_NAME)->write_string(""); |
---|
57 | aw_root->awar(AWAR_ORGANISM_NAME)->write_string(""); |
---|
58 | } |
---|
59 | else { |
---|
60 | aw_message(GBS_global_string("Illegal item_name '%s' in GEN_select_gene()", item_name)); |
---|
61 | } |
---|
62 | free(organism); |
---|
63 | } |
---|
64 | |
---|
65 | static char *gen_get_gene_id(GBDATA * /* gb_main */, GBDATA *gb_gene) { |
---|
66 | GBDATA *gb_species = GB_get_grandfather(gb_gene); |
---|
67 | return GBS_global_string_copy("%s/%s", GBT_get_name_or_description(gb_species), GBT_get_name_or_description(gb_gene)); |
---|
68 | } |
---|
69 | |
---|
70 | static GBDATA *gen_find_gene_by_id(GBDATA *gb_main, const char *id) { |
---|
71 | char *organism = ARB_strdup(id); |
---|
72 | char *gene = strchr(organism, '/'); |
---|
73 | GBDATA *result = NULp; |
---|
74 | |
---|
75 | if (gene) { |
---|
76 | *gene++ = 0; |
---|
77 | GBDATA *gb_organism = GEN_find_organism(gb_main, organism); |
---|
78 | if (gb_organism) { |
---|
79 | result = GEN_find_gene(gb_organism, gene); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | free(organism); |
---|
84 | return result; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | GB_ERROR GEN_mark_organism_or_corresponding_organism(GBDATA *gb_species, int */*client_data*/) { |
---|
89 | GB_ERROR error = NULp; |
---|
90 | |
---|
91 | if (GEN_is_pseudo_gene_species(gb_species)) { |
---|
92 | GBDATA *gb_organism = GEN_find_origin_organism(gb_species, NULp); |
---|
93 | if (gb_organism) { |
---|
94 | GB_write_flag(gb_organism, 1); |
---|
95 | } |
---|
96 | else { |
---|
97 | error = GEN_organism_not_found(gb_species); |
---|
98 | } |
---|
99 | } |
---|
100 | else if (GEN_is_organism(gb_species)) { |
---|
101 | GB_write_flag(gb_species, 1); |
---|
102 | } |
---|
103 | |
---|
104 | return error; |
---|
105 | } |
---|
106 | |
---|
107 | static char *old_species_marks = NULp; // configuration storing marked species |
---|
108 | |
---|
109 | inline void gen_restore_old_species_marks(GBDATA *gb_main) { |
---|
110 | if (old_species_marks) { |
---|
111 | GBT_restore_marked_species(gb_main, old_species_marks); |
---|
112 | freenull(old_species_marks); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | static GBDATA *GEN_get_first_gene_data(GBDATA *gb_main, AW_root *aw_root, QUERY_RANGE range) { |
---|
117 | GBDATA *gb_organism = NULp; |
---|
118 | GB_ERROR error = NULp; |
---|
119 | |
---|
120 | gen_restore_old_species_marks(gb_main); |
---|
121 | |
---|
122 | switch (range) { |
---|
123 | case QUERY_CURRENT_ITEM: { |
---|
124 | char *species_name = aw_root->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
125 | gb_organism = GEN_find_organism(gb_main, species_name); |
---|
126 | free(species_name); |
---|
127 | break; |
---|
128 | } |
---|
129 | case QUERY_MARKED_ITEMS: { |
---|
130 | gb_organism = GEN_first_marked_organism(gb_main); |
---|
131 | GBDATA *gb_pseudo = GEN_first_marked_pseudo_species(gb_main); |
---|
132 | |
---|
133 | if (gb_pseudo) { // there are marked pseudo-species.. |
---|
134 | old_species_marks = GBT_store_marked_species(gb_main, true); // store and unmark marked species |
---|
135 | |
---|
136 | error = GBT_with_stored_species(gb_main, old_species_marks, GEN_mark_organism_or_corresponding_organism, NULp); // mark organisms related with stored |
---|
137 | if (!error) gb_organism = GEN_first_marked_organism(gb_main); |
---|
138 | } |
---|
139 | |
---|
140 | break; |
---|
141 | } |
---|
142 | case QUERY_ALL_ITEMS: { |
---|
143 | gb_organism = GEN_first_organism(gb_main); |
---|
144 | break; |
---|
145 | } |
---|
146 | default: { |
---|
147 | gen_assert(0); |
---|
148 | break; |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | if (error) GB_export_error(error); |
---|
153 | return gb_organism ? GEN_expect_gene_data(gb_organism) : NULp; |
---|
154 | } |
---|
155 | |
---|
156 | static GBDATA *GEN_get_next_gene_data(GBDATA *gb_gene_data, QUERY_RANGE range) { |
---|
157 | GBDATA *gb_organism = NULp; |
---|
158 | switch (range) { |
---|
159 | case QUERY_CURRENT_ITEM: { |
---|
160 | break; |
---|
161 | } |
---|
162 | case QUERY_MARKED_ITEMS: { |
---|
163 | GBDATA *gb_last_organism = GB_get_father(gb_gene_data); |
---|
164 | gb_organism = GEN_next_marked_organism(gb_last_organism); |
---|
165 | |
---|
166 | if (!gb_organism) gen_restore_old_species_marks(GB_get_root(gb_last_organism)); // got all -> clean up |
---|
167 | |
---|
168 | break; |
---|
169 | } |
---|
170 | case QUERY_ALL_ITEMS: { |
---|
171 | GBDATA *gb_last_organism = GB_get_father(gb_gene_data); |
---|
172 | gb_organism = GEN_next_organism(gb_last_organism); |
---|
173 | break; |
---|
174 | } |
---|
175 | default: { |
---|
176 | gen_assert(0); |
---|
177 | break; |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | return gb_organism ? GEN_expect_gene_data(gb_organism) : NULp; |
---|
182 | } |
---|
183 | |
---|
184 | static GBDATA *GEN_get_current_gene(GBDATA *gb_main, AW_root *aw_root) { |
---|
185 | GBDATA *gb_species = GEN_get_current_organism(gb_main); |
---|
186 | GBDATA *gb_gene = NULp; |
---|
187 | |
---|
188 | if (gb_species) { |
---|
189 | char *gene_name = aw_root->awar(AWAR_GENE_NAME)->read_string(); |
---|
190 | gb_gene = GEN_find_gene(gb_species, gene_name); |
---|
191 | free(gene_name); |
---|
192 | } |
---|
193 | |
---|
194 | return gb_gene; |
---|
195 | } |
---|
196 | |
---|
197 | static void add_selected_gene_changed_cb(AW_root *aw_root, const RootCallback& cb) { |
---|
198 | aw_root->awar(AWAR_GENE_NAME)->add_callback(cb); |
---|
199 | ORGANISM_get_selector().add_selection_changed_cb(aw_root, cb); |
---|
200 | } |
---|
201 | |
---|
202 | static GBDATA *first_gene_in_range(GBDATA *gb_gene_data, QUERY_RANGE range) { |
---|
203 | GBDATA *gb_first = NULp; |
---|
204 | switch (range) { |
---|
205 | case QUERY_ALL_ITEMS: gb_first = GEN_first_gene_rel_gene_data(gb_gene_data); break; |
---|
206 | case QUERY_MARKED_ITEMS: gb_first = GB_first_marked(gb_gene_data, "gene"); break; |
---|
207 | case QUERY_CURRENT_ITEM: gb_first = GEN_get_current_gene(GB_get_root(gb_gene_data), AW_root::SINGLETON); break; |
---|
208 | } |
---|
209 | return gb_first; |
---|
210 | } |
---|
211 | static GBDATA *next_gene_in_range(GBDATA *gb_prev, QUERY_RANGE range) { |
---|
212 | GBDATA *gb_next = NULp; |
---|
213 | switch (range) { |
---|
214 | case QUERY_ALL_ITEMS: gb_next = GEN_next_gene(gb_prev); break; |
---|
215 | case QUERY_MARKED_ITEMS: gb_next = GEN_next_marked_gene(gb_prev); break; |
---|
216 | case QUERY_CURRENT_ITEM: gb_next = NULp; break; |
---|
217 | } |
---|
218 | return gb_next; |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | static void refresh_displayed_genes() { |
---|
223 | GEN_refresh_all_windows(); |
---|
224 | } |
---|
225 | |
---|
226 | static struct MutableItemSelector GEN_item_selector = { // @@@ move GEN_item_selector to SL/ITEMS |
---|
227 | QUERY_ITEM_GENES, |
---|
228 | GEN_select_gene, |
---|
229 | gen_get_gene_id, |
---|
230 | gen_find_gene_by_id, |
---|
231 | gene_field_selection_list_update_cb, |
---|
232 | -1, // unknown |
---|
233 | CHANGE_KEY_PATH_GENES, |
---|
234 | "gene", |
---|
235 | "genes", |
---|
236 | "name", |
---|
237 | GEN_get_first_gene_data, |
---|
238 | GEN_get_next_gene_data, |
---|
239 | first_gene_in_range, |
---|
240 | next_gene_in_range, |
---|
241 | GEN_get_current_gene, |
---|
242 | add_selected_gene_changed_cb, |
---|
243 | &ORGANISM_get_selector(), GB_get_grandfather, |
---|
244 | refresh_displayed_genes, |
---|
245 | }; |
---|
246 | |
---|
247 | ItemSelector& GEN_get_selector() { return GEN_item_selector; } |
---|
248 | |
---|
249 | static void GEN_species_name_changed_cb(AW_root *awr, GBDATA *gb_main) { |
---|
250 | char *species_name = awr->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
251 | GB_transaction ta(gb_main); |
---|
252 | GBDATA *gb_species = GBT_find_species(gb_main, species_name); |
---|
253 | |
---|
254 | if (gb_species) { |
---|
255 | if (GEN_is_pseudo_gene_species(gb_species)) { |
---|
256 | awr->awar(AWAR_ORGANISM_NAME)->write_string(GEN_origin_organism(gb_species)); |
---|
257 | awr->awar(AWAR_GENE_NAME)->write_string(GEN_origin_gene(gb_species)); |
---|
258 | } |
---|
259 | else { |
---|
260 | awr->awar(AWAR_ORGANISM_NAME)->write_string(species_name); |
---|
261 | } |
---|
262 | } |
---|
263 | free(species_name); |
---|
264 | } |
---|
265 | |
---|
266 | static void auto_select_pseudo_species(AW_root *awr, GBDATA *gb_main, const char *organism, const char *gene) { |
---|
267 | GB_transaction ta(gb_main); |
---|
268 | GBDATA *gb_pseudo = GEN_find_pseudo_species(gb_main, organism, gene, NULp); // search for pseudo species.. |
---|
269 | |
---|
270 | awr->awar(AWAR_SPECIES_NAME)->write_string(gb_pseudo |
---|
271 | ? GBT_get_name_or_description(gb_pseudo) // .. if found select |
---|
272 | : organism); // otherwise select organism |
---|
273 | } |
---|
274 | |
---|
275 | static void GEN_update_GENE_CONTENT(GBDATA *gb_main, AW_root *awr) { |
---|
276 | GB_transaction ta(gb_main); |
---|
277 | GBDATA *gb_gene = GEN_get_current_gene(gb_main, awr); |
---|
278 | bool clear = true; |
---|
279 | AW_awar *awar_content = awr->awar(AWAR_GENE_CONTENT); |
---|
280 | |
---|
281 | if (gb_gene) { |
---|
282 | // ignore complement here (to highlight gene in ARB_EDIT4); |
---|
283 | // separate multiple parts by \n |
---|
284 | char *gene_content = GBT_read_gene_sequence(gb_gene, false, '\n'); |
---|
285 | if (gene_content) { |
---|
286 | awar_content->write_string(gene_content); |
---|
287 | clear = false; |
---|
288 | free(gene_content); |
---|
289 | } |
---|
290 | else { |
---|
291 | awar_content->write_string(GB_await_error()); |
---|
292 | } |
---|
293 | } |
---|
294 | else { |
---|
295 | char *gene_name = awr->awar(AWAR_GENE_NAME)->read_string(); |
---|
296 | const int prefix_len = 10; |
---|
297 | |
---|
298 | if (strncmp(gene_name, "intergene_", prefix_len) == 0) { // special case (non-gene result from gene pt server) |
---|
299 | char *start_pos_ptr = gene_name+prefix_len; |
---|
300 | char *end_pos_ptr = strchr(start_pos_ptr, '_'); |
---|
301 | |
---|
302 | gen_assert(end_pos_ptr); |
---|
303 | if (end_pos_ptr) { |
---|
304 | *end_pos_ptr++ = 0; |
---|
305 | long start_pos = atol(start_pos_ptr); |
---|
306 | long end_pos = atol(end_pos_ptr); |
---|
307 | |
---|
308 | gen_assert(end_pos >= start_pos); |
---|
309 | |
---|
310 | GBDATA *gb_organism = GEN_get_current_organism(gb_main); |
---|
311 | if (gb_organism) { |
---|
312 | GBDATA *gb_seq = GBT_find_sequence(gb_organism, GENOM_ALIGNMENT); |
---|
313 | const char *seq_data = GB_read_char_pntr(gb_seq); |
---|
314 | |
---|
315 | long len = end_pos-start_pos+1; |
---|
316 | char *buffer = ARB_strndup(seq_data+start_pos, len); |
---|
317 | |
---|
318 | awar_content->write_string(buffer); |
---|
319 | clear = false; |
---|
320 | |
---|
321 | free(buffer); |
---|
322 | } |
---|
323 | } |
---|
324 | } |
---|
325 | free(gene_name); |
---|
326 | } |
---|
327 | |
---|
328 | if (clear) { |
---|
329 | awar_content->write_string(""); // if we did not detect any gene sequence -> clear |
---|
330 | } |
---|
331 | } |
---|
332 | |
---|
333 | static void GEN_update_combined_cb(AW_root *awr, GBDATA *gb_main) { |
---|
334 | char *organism = awr->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
335 | char *gene = awr->awar(AWAR_GENE_NAME)->read_string(); |
---|
336 | char *old_combined = awr->awar(AWAR_COMBINED_GENE_NAME)->read_string(); |
---|
337 | const char *combined = GBS_global_string("%s/%s", organism, gene); |
---|
338 | |
---|
339 | if (strcmp(combined, old_combined) != 0) { |
---|
340 | awr->awar(AWAR_COMBINED_GENE_NAME)->write_string(combined); |
---|
341 | auto_select_pseudo_species(awr, gb_main, organism, gene); |
---|
342 | GEN_update_GENE_CONTENT(gb_main, awr); |
---|
343 | } |
---|
344 | |
---|
345 | free(old_combined); |
---|
346 | free(gene); |
---|
347 | free(organism); |
---|
348 | } |
---|
349 | |
---|
350 | void GEN_create_awars(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main) { |
---|
351 | aw_root->awar_string(AWAR_COMBINED_GENE_NAME, "", gb_main); |
---|
352 | aw_root->awar_string(AWAR_GENE_CONTENT, NULp, gb_main); |
---|
353 | |
---|
354 | RootCallback update_combined_cb = makeRootCallback(GEN_update_combined_cb, gb_main); |
---|
355 | |
---|
356 | aw_root->awar_string(AWAR_GENE_NAME, "", gb_main)->add_callback(update_combined_cb); |
---|
357 | aw_root->awar_string(AWAR_ORGANISM_NAME, "", gb_main)->add_callback(update_combined_cb); |
---|
358 | aw_root->awar_string(AWAR_SPECIES_NAME, "", gb_main)->add_callback(makeRootCallback(GEN_species_name_changed_cb, gb_main)); |
---|
359 | |
---|
360 | aw_root->awar_string(AWAR_GENE_DEST, "", aw_def); |
---|
361 | } |
---|
362 | |
---|
363 | GBDATA *GEN_get_current_organism(GBDATA *gb_main) { |
---|
364 | char *species_name = AW_root::SINGLETON->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
365 | GBDATA *gb_species = GBT_find_species(gb_main, species_name); |
---|
366 | free(species_name); |
---|
367 | return gb_species; |
---|
368 | } |
---|
369 | |
---|
370 | static GBDATA* get_current_gene_data(GBDATA *gb_main) { |
---|
371 | GBDATA *gb_species = GEN_get_current_organism(gb_main); |
---|
372 | GBDATA *gb_gene_data = NULp; |
---|
373 | |
---|
374 | if (gb_species) gb_gene_data = GEN_expect_gene_data(gb_species); |
---|
375 | |
---|
376 | return gb_gene_data; |
---|
377 | } |
---|
378 | |
---|
379 | static QUERY::DbQuery *GLOBAL_gene_query = NULp; |
---|
380 | |
---|
381 | static GB_ERROR gene_rename_handler(const char *dest, GBDATA *gb_main) { |
---|
382 | AW_root *aw_root = AW_root::SINGLETON; |
---|
383 | const char *source = aw_root->awar(AWAR_GENE_NAME)->read_char_pntr(); |
---|
384 | GB_ERROR error = NULp; |
---|
385 | |
---|
386 | if (strcmp(source, dest) != 0) { |
---|
387 | error = GB_begin_transaction(gb_main); |
---|
388 | |
---|
389 | if (!error) { |
---|
390 | GBDATA *gb_gene_data = get_current_gene_data(gb_main); |
---|
391 | |
---|
392 | if (!gb_gene_data) error = "Please select an organism"; |
---|
393 | else if (!dest[0]) error = "empty name not possible"; |
---|
394 | else { |
---|
395 | GBDATA *gb_source = GEN_find_gene_rel_gene_data(gb_gene_data, source); |
---|
396 | GBDATA *gb_dest = GEN_find_gene_rel_gene_data(gb_gene_data, dest); |
---|
397 | |
---|
398 | if (!gb_source) error = "Please select a gene"; |
---|
399 | else if (gb_dest) error = GBS_global_string("Gene '%s' already exists", dest); |
---|
400 | else { |
---|
401 | GBDATA *gb_name = GB_search(gb_source, "name", GB_STRING); |
---|
402 | |
---|
403 | if (!gb_name) error = GB_await_error(); |
---|
404 | else { |
---|
405 | error = GB_write_string(gb_name, dest); |
---|
406 | if (!error) aw_root->awar(AWAR_GENE_NAME)->write_string(dest); |
---|
407 | } |
---|
408 | } |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | error = GB_end_transaction(gb_main, error); |
---|
413 | } |
---|
414 | return error; |
---|
415 | } |
---|
416 | |
---|
417 | static GB_ERROR gene_copy_handler(const char *dest, GBDATA *gb_main) { |
---|
418 | AW_root *aw_root = AW_root::SINGLETON; |
---|
419 | const char *source = aw_root->awar(AWAR_GENE_NAME)->read_char_pntr(); |
---|
420 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
421 | |
---|
422 | if (!error) { |
---|
423 | GBDATA *gb_gene_data = get_current_gene_data(gb_main); |
---|
424 | |
---|
425 | if (!gb_gene_data) error = "Please select an organism"; |
---|
426 | else if (!dest[0]) error = "empty name not possible"; |
---|
427 | else { |
---|
428 | GBDATA *gb_source = GEN_find_gene_rel_gene_data(gb_gene_data, source); |
---|
429 | GBDATA *gb_dest = GEN_find_gene_rel_gene_data(gb_gene_data, dest); |
---|
430 | |
---|
431 | if (!gb_source) error = "Please select a gene"; |
---|
432 | else if (gb_dest) error = GBS_global_string("Gene '%s' already exists", dest); |
---|
433 | else { |
---|
434 | gb_dest = GB_create_container(gb_gene_data, "gene"); |
---|
435 | if (!gb_dest) error = GB_await_error(); |
---|
436 | else error = GB_copy_dropProtectMarksAndTempstate(gb_dest, gb_source); |
---|
437 | |
---|
438 | if (!error) error = GBT_write_string(gb_dest, "name", dest); |
---|
439 | if (!error) aw_root->awar(AWAR_GENE_NAME)->write_string(dest); |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | |
---|
444 | error = GB_end_transaction(gb_main, error); |
---|
445 | |
---|
446 | return error; |
---|
447 | } |
---|
448 | |
---|
449 | static void gene_rename_cb(AW_window *aww, GBDATA *gb_main) { |
---|
450 | AW_root *aw_root = aww->get_root(); |
---|
451 | const char *source = aw_root->awar(AWAR_GENE_NAME)->read_char_pntr(); |
---|
452 | AWT_activate_prompt("Rename gene", "Enter new name of gene:", source, "Rename", makeResultHandler(gene_rename_handler, gb_main)); |
---|
453 | } |
---|
454 | static void gene_copy_cb(AW_window *aww, GBDATA *gb_main) { |
---|
455 | AW_root *aw_root = aww->get_root(); |
---|
456 | const char *source = aw_root->awar(AWAR_GENE_NAME)->read_char_pntr(); |
---|
457 | AWT_activate_prompt("Copy gene", "Enter name of new gene:", source, "Copy", makeResultHandler(gene_copy_handler, gb_main)); |
---|
458 | } |
---|
459 | |
---|
460 | // ----------------------- |
---|
461 | // LocationEditor |
---|
462 | |
---|
463 | const int NAME_WIDTH = 33; |
---|
464 | const int POS_WIDTH = NAME_WIDTH; |
---|
465 | const int CER_WIDTH = POS_WIDTH/2; |
---|
466 | const int LOC_WIDTH = 53; |
---|
467 | |
---|
468 | #define GLE_POS1 "pos1" |
---|
469 | #define GLE_POS2 "pos2" |
---|
470 | #define GLE_CERT1 "cert1" |
---|
471 | #define GLE_CERT2 "cert2" |
---|
472 | #define GLE_COMPLEMENT "complement" |
---|
473 | #define GLE_JOINABLE "joinable" |
---|
474 | #define GLE_READABLE "location" |
---|
475 | #define GLE_STATUS "status" |
---|
476 | |
---|
477 | class LocationEditor : virtual Noncopyable { // GLE |
---|
478 | typedef void (*PosChanged_cb)(AW_root *aw_root, LocationEditor *loced); |
---|
479 | |
---|
480 | char *tag; |
---|
481 | AW_root *aw_root; |
---|
482 | GBDATA *gb_main; |
---|
483 | char *status; |
---|
484 | GEN_position *pos; |
---|
485 | PosChanged_cb pos_changed_cb; |
---|
486 | |
---|
487 | void createAwars(); |
---|
488 | |
---|
489 | void createInputField(AW_window *aws, const char *at, const char *aname, int width) const { |
---|
490 | aws->at(at); |
---|
491 | aws->create_input_field(loc_awar_name(aname), width); |
---|
492 | } |
---|
493 | |
---|
494 | public: |
---|
495 | LocationEditor(AW_root *aw_root_, GBDATA *gb_main_, const char *tag_) : |
---|
496 | tag(ARB_strdup(tag_)), |
---|
497 | aw_root(aw_root_), |
---|
498 | gb_main(gb_main_), |
---|
499 | status(NULp), |
---|
500 | pos(NULp), |
---|
501 | pos_changed_cb(NULp) |
---|
502 | { |
---|
503 | createAwars(); |
---|
504 | set_status(NULp); |
---|
505 | } |
---|
506 | ~LocationEditor() { |
---|
507 | free(tag); |
---|
508 | free(status); |
---|
509 | GEN_free_position(pos); |
---|
510 | } |
---|
511 | |
---|
512 | GBDATA *get_gb_main() const { return gb_main; } |
---|
513 | |
---|
514 | void add_pos_changed_cb(PosChanged_cb cb) { pos_changed_cb = cb; } |
---|
515 | |
---|
516 | const GEN_position *get_pos() const { return pos; } |
---|
517 | void set_pos(GEN_position*& pos_) { |
---|
518 | GEN_free_position(pos); |
---|
519 | pos = pos_; |
---|
520 | pos_ = NULp; // take ownership |
---|
521 | set_status(status); |
---|
522 | |
---|
523 | if (pos && pos_changed_cb) { |
---|
524 | pos_changed_cb(aw_root, this); |
---|
525 | } |
---|
526 | } |
---|
527 | void set_status(const char *status_) { |
---|
528 | if (status != status_) freedup(status, status_); |
---|
529 | loc_awar(GLE_STATUS)->write_string(status ? status : (pos ? "Ok" : "No data")); |
---|
530 | } |
---|
531 | |
---|
532 | const char *loc_awar_name(const char *aname) const { |
---|
533 | const int BUFSIZE = 100; |
---|
534 | static char buf[BUFSIZE]; |
---|
535 | |
---|
536 | IF_ASSERTION_USED(int printed =) sprintf(buf, "tmp/loc/%s/%s", tag, aname); |
---|
537 | gen_assert(printed<BUFSIZE); |
---|
538 | |
---|
539 | return buf; |
---|
540 | } |
---|
541 | AW_awar *loc_awar(const char *aname) const { return aw_root->awar(loc_awar_name(aname)); } |
---|
542 | const char *awar_charp_value(const char *aname) const { return loc_awar(aname)->read_char_pntr(); } |
---|
543 | |
---|
544 | void createEditFields(AW_window *aws); |
---|
545 | |
---|
546 | GEN_position *create_GEN_position_from_fields(GB_ERROR& error); |
---|
547 | void revcomp() { |
---|
548 | loc_awar(GLE_READABLE)->write_string(GBS_global_string("complement(%s)", awar_charp_value(GLE_READABLE))); |
---|
549 | } |
---|
550 | }; |
---|
551 | |
---|
552 | inline const char *elemOr(ConstStrArray& a, size_t i, const char *Default) { |
---|
553 | return i<a.size() ? a[i] : Default; |
---|
554 | } |
---|
555 | inline char elemOr(const char *a, size_t len, size_t i, char Default) { |
---|
556 | return i<len ? a[i] : Default; |
---|
557 | } |
---|
558 | |
---|
559 | GEN_position *LocationEditor::create_GEN_position_from_fields(GB_ERROR& error) { |
---|
560 | const char *ipos1 = awar_charp_value(GLE_POS1); |
---|
561 | const char *ipos2 = awar_charp_value(GLE_POS2); |
---|
562 | const char *icert1 = awar_charp_value(GLE_CERT1); |
---|
563 | const char *icert2 = awar_charp_value(GLE_CERT2); |
---|
564 | const char *icomp = awar_charp_value(GLE_COMPLEMENT); |
---|
565 | |
---|
566 | const char *sep = ",; "; |
---|
567 | |
---|
568 | ConstStrArray pos1, pos2; |
---|
569 | GBT_split_string(pos1, ipos1, sep, true); |
---|
570 | GBT_split_string(pos2, ipos2, sep, true); |
---|
571 | |
---|
572 | size_t clen1 = strlen(icert1); |
---|
573 | size_t clen2 = strlen(icert2); |
---|
574 | size_t clen = strlen(icomp); |
---|
575 | |
---|
576 | size_t max_size = pos1.size(); |
---|
577 | bool joinable = loc_awar(GLE_JOINABLE)->read_int(); |
---|
578 | |
---|
579 | GEN_position *gp = NULp; |
---|
580 | if (max_size>0) { |
---|
581 | gp = GEN_new_position(max_size, joinable); |
---|
582 | GEN_use_uncertainties(gp); |
---|
583 | |
---|
584 | for (size_t i = 0; i<max_size; ++i) { |
---|
585 | const char *p1c = elemOr(pos1, i, "1"); |
---|
586 | size_t p1 = atoi(p1c); |
---|
587 | size_t p2 = atoi(elemOr(pos2, i, p1c)); |
---|
588 | |
---|
589 | char c = elemOr(icomp, clen, i, '0'); |
---|
590 | char c1 = elemOr(icert1, clen1, i, '='); |
---|
591 | char c2 = elemOr(icert2, clen2, i, '='); |
---|
592 | |
---|
593 | gen_assert(c1 && c2); |
---|
594 | |
---|
595 | gp->start_pos[i] = p1; |
---|
596 | gp->stop_pos[i] = p2; |
---|
597 | gp->complement[i] = !!(c-'0'); |
---|
598 | gp->start_uncertain[i] = c1; |
---|
599 | gp->stop_uncertain[i] = c2; |
---|
600 | } |
---|
601 | } |
---|
602 | else { |
---|
603 | error = "No data"; |
---|
604 | } |
---|
605 | |
---|
606 | return gp; |
---|
607 | } |
---|
608 | |
---|
609 | static int loc_update_running = 0; |
---|
610 | |
---|
611 | inline GB_ERROR update_location_from_GEN_position(LocationEditor *loced, const GEN_position *gp) { |
---|
612 | GB_ERROR error = NULp; |
---|
613 | if (gp) { |
---|
614 | try { |
---|
615 | LocationPtr loc = to_Location(gp); |
---|
616 | loced->loc_awar(GLE_READABLE)->write_string(loc->as_string().c_str()); |
---|
617 | } |
---|
618 | catch (const char *& err) { error = GBS_static_string(err); } |
---|
619 | catch (string& err) { error = GBS_static_string(err.c_str()); } |
---|
620 | catch (...) { gen_assert(0); } |
---|
621 | } |
---|
622 | return error; |
---|
623 | } |
---|
624 | |
---|
625 | |
---|
626 | static void GLE_update_from_detailFields(AW_root *, LocationEditor *loced) { |
---|
627 | // update location according to other fields |
---|
628 | if (!loc_update_running) { |
---|
629 | loc_update_running++; |
---|
630 | |
---|
631 | GB_ERROR error = NULp; |
---|
632 | GEN_position *gp = loced->create_GEN_position_from_fields(error); |
---|
633 | |
---|
634 | if (!error) { |
---|
635 | error = update_location_from_GEN_position(loced, gp); |
---|
636 | } |
---|
637 | |
---|
638 | loced->set_pos(gp); |
---|
639 | loced->set_status(error); |
---|
640 | |
---|
641 | loc_update_running--; |
---|
642 | } |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | static SmartCharPtr sizetarray2string(const size_t *array, int size) { |
---|
647 | GBS_strstruct out(size*5); |
---|
648 | for (int i = 0; i<size; ++i) { |
---|
649 | out.putlong(array[i]); |
---|
650 | out.put(' '); |
---|
651 | } |
---|
652 | out.cut_tail(1); |
---|
653 | return out.release(); |
---|
654 | } |
---|
655 | inline SmartCharPtr dupSizedPart(const unsigned char *in, int size) { |
---|
656 | const char *in2 = reinterpret_cast<const char*>(in); |
---|
657 | return ARB_strpartdup(in2, in2+size-1); |
---|
658 | } |
---|
659 | inline SmartCharPtr dupComplement(const unsigned char *in, int size) { |
---|
660 | char *dup = ARB_alloc<char>(size+1); |
---|
661 | for (int i = 0; i<size; ++i) { // LOOP_VECTORIZED // tested down to gcc 5.5.0 (may fail on older gcc versions) |
---|
662 | dup[i] = in[i] ? '1' : '0'; |
---|
663 | } |
---|
664 | dup[size] = 0; |
---|
665 | return dup; |
---|
666 | } |
---|
667 | |
---|
668 | static void GLE_update_from_location(AW_root *, LocationEditor *loced) { |
---|
669 | // update other fields according to location |
---|
670 | if (!loc_update_running) { |
---|
671 | loc_update_running++; |
---|
672 | |
---|
673 | GB_ERROR error = NULp; |
---|
674 | const char *locstr = loced->awar_charp_value(GLE_READABLE); |
---|
675 | GEN_position *gp = NULp; |
---|
676 | |
---|
677 | try { |
---|
678 | LocationPtr loc = parseLocation(locstr); |
---|
679 | gp = loc->create_GEN_position(); |
---|
680 | } |
---|
681 | catch (const char *& err) { error = GBS_static_string(err); } |
---|
682 | catch (string& err) { error = GBS_static_string(err.c_str()); } |
---|
683 | catch (...) { gen_assert(0); } |
---|
684 | |
---|
685 | if (!error) { |
---|
686 | loced->loc_awar(GLE_POS1)->write_string(&*sizetarray2string(gp->start_pos, gp->parts)); |
---|
687 | loced->loc_awar(GLE_POS2)->write_string(&*sizetarray2string(gp->stop_pos, gp->parts)); |
---|
688 | |
---|
689 | loced->loc_awar(GLE_CERT1)->write_string(&*dupSizedPart(gp->start_uncertain, gp->parts)); |
---|
690 | loced->loc_awar(GLE_CERT2)->write_string(&*dupSizedPart(gp->stop_uncertain, gp->parts)); |
---|
691 | loced->loc_awar(GLE_COMPLEMENT)->write_string(&*dupComplement(gp->complement, gp->parts)); |
---|
692 | |
---|
693 | loced->loc_awar(GLE_JOINABLE)->write_int(gp->parts>1 ? gp->joinable : 1); |
---|
694 | } |
---|
695 | |
---|
696 | loced->set_pos(gp); |
---|
697 | loced->set_status(error); |
---|
698 | |
---|
699 | loc_update_running--; |
---|
700 | } |
---|
701 | } |
---|
702 | |
---|
703 | static void GLE_revcomp_cb(AW_window*, LocationEditor *loced) { |
---|
704 | loced->revcomp(); |
---|
705 | } |
---|
706 | |
---|
707 | void LocationEditor::createAwars() { |
---|
708 | RootCallback update_from_detail = makeRootCallback(GLE_update_from_detailFields, this); |
---|
709 | |
---|
710 | aw_root->awar_string(loc_awar_name(GLE_POS1), "", gb_main)->add_callback(update_from_detail); |
---|
711 | aw_root->awar_string(loc_awar_name(GLE_POS2), "", gb_main)->add_callback(update_from_detail); |
---|
712 | aw_root->awar_string(loc_awar_name(GLE_CERT1), "", gb_main)->add_callback(update_from_detail); |
---|
713 | aw_root->awar_string(loc_awar_name(GLE_CERT2), "", gb_main)->add_callback(update_from_detail); |
---|
714 | aw_root->awar_string(loc_awar_name(GLE_COMPLEMENT), "", gb_main)->add_callback(update_from_detail); |
---|
715 | aw_root->awar_int (loc_awar_name(GLE_JOINABLE), 1, gb_main)->add_callback(update_from_detail); |
---|
716 | aw_root->awar_string(loc_awar_name(GLE_READABLE), "", gb_main)->add_callback(makeRootCallback(GLE_update_from_location, this)); |
---|
717 | aw_root->awar_string(loc_awar_name(GLE_STATUS), "", gb_main); |
---|
718 | } |
---|
719 | |
---|
720 | void LocationEditor::createEditFields(AW_window *aws) { |
---|
721 | createInputField(aws, "pos1", GLE_POS1, POS_WIDTH); |
---|
722 | createInputField(aws, "cert1", GLE_CERT1, CER_WIDTH); |
---|
723 | createInputField(aws, "pos2", GLE_POS2, POS_WIDTH); |
---|
724 | createInputField(aws, "cert2", GLE_CERT2, CER_WIDTH); |
---|
725 | createInputField(aws, "comp", GLE_COMPLEMENT, CER_WIDTH); |
---|
726 | createInputField(aws, "loc", GLE_READABLE, LOC_WIDTH); |
---|
727 | createInputField(aws, "status", GLE_STATUS, LOC_WIDTH); |
---|
728 | |
---|
729 | aws->at("rev"); |
---|
730 | aws->callback(makeWindowCallback(GLE_revcomp_cb, this)); |
---|
731 | aws->button_length(8); |
---|
732 | aws->create_button("REV", "RevComp"); |
---|
733 | |
---|
734 | aws->at("join"); |
---|
735 | aws->create_toggle(loc_awar_name(GLE_JOINABLE)); |
---|
736 | } |
---|
737 | |
---|
738 | static void gene_changed_cb(AW_root *aw_root, LocationEditor *loced) { |
---|
739 | GBDATA *gb_gene = GEN_get_current_gene(loced->get_gb_main(), aw_root); |
---|
740 | GEN_position *pos = gb_gene ? GEN_read_position(gb_gene) : NULp; |
---|
741 | |
---|
742 | GB_ERROR error = NULp; |
---|
743 | if (pos) { |
---|
744 | GEN_use_uncertainties(pos); |
---|
745 | error = update_location_from_GEN_position(loced, pos); |
---|
746 | } |
---|
747 | loced->set_pos(pos); |
---|
748 | loced->set_status(error); |
---|
749 | } |
---|
750 | |
---|
751 | static void boundloc_changed_cb(AW_root *aw_root, LocationEditor *loced) { |
---|
752 | GBDATA* gb_main = loced->get_gb_main(); |
---|
753 | const GEN_position *pos = loced->get_pos(); |
---|
754 | gen_assert(pos); |
---|
755 | |
---|
756 | GB_push_transaction(gb_main); |
---|
757 | GBDATA *gb_gene = GEN_get_current_gene(gb_main, aw_root); |
---|
758 | GB_ERROR error; |
---|
759 | if (gb_gene) { |
---|
760 | error = GEN_write_position(gb_gene, pos, 0); |
---|
761 | } |
---|
762 | else { |
---|
763 | error = "That had no effect (no gene is selected)"; |
---|
764 | } |
---|
765 | GB_end_transaction_show_error(gb_main, error, aw_message); |
---|
766 | |
---|
767 | if (error) { |
---|
768 | gene_changed_cb(aw_root, loced); |
---|
769 | } |
---|
770 | } |
---|
771 | |
---|
772 | static void gene_create_cb(AW_window *aww, GBDATA *gb_main, LocationEditor *loced) { |
---|
773 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
774 | |
---|
775 | if (!error) { |
---|
776 | AW_root *aw_root = aww->get_root(); |
---|
777 | GBDATA *gb_gene_data = get_current_gene_data(gb_main); |
---|
778 | |
---|
779 | if (!gb_gene_data) error = "Please select an organism"; |
---|
780 | else { |
---|
781 | char *dest = aw_root->awar(AWAR_GENE_DEST)->read_string(); |
---|
782 | GBDATA *gb_dest = GEN_find_gene_rel_gene_data(gb_gene_data, dest); |
---|
783 | |
---|
784 | if (gb_dest) error = GBS_global_string("Gene '%s' already exists", dest); |
---|
785 | else { |
---|
786 | const GEN_position *pos = loced->get_pos(); |
---|
787 | |
---|
788 | if (!pos) error = "Won't create a gene with invalid position"; |
---|
789 | else { |
---|
790 | gb_dest = GEN_find_or_create_gene_rel_gene_data(gb_gene_data, dest); |
---|
791 | if (!gb_dest) error = GB_await_error(); |
---|
792 | else error = GEN_write_position(gb_dest, pos, 0); |
---|
793 | |
---|
794 | if (!error) { |
---|
795 | aw_root->awar(AWAR_GENE_NAME)->write_string(dest); |
---|
796 | aww->hide(); |
---|
797 | } |
---|
798 | } |
---|
799 | } |
---|
800 | |
---|
801 | free(dest); |
---|
802 | } |
---|
803 | } |
---|
804 | GB_end_transaction_show_error(gb_main, error, aw_message); |
---|
805 | |
---|
806 | gen_assert(!GB_have_error()); |
---|
807 | } |
---|
808 | |
---|
809 | static AW_window *get_gene_create_or_locationEdit_window(AW_root *root, bool createGene, GBDATA *gb_main) { |
---|
810 | static AW_window_simple *awa[2] = { NULp, NULp}; |
---|
811 | static LocationEditor *le[2] = { NULp, NULp}; |
---|
812 | |
---|
813 | AW_window_simple*& aws = awa[createGene]; |
---|
814 | LocationEditor*& loced = le[createGene]; |
---|
815 | |
---|
816 | if (!aws) { |
---|
817 | gen_assert(gb_main); |
---|
818 | |
---|
819 | aws = new AW_window_simple; |
---|
820 | loced = new LocationEditor(root, gb_main, createGene ? "create" : "edit"); |
---|
821 | |
---|
822 | if (createGene) aws->init(root, "CREATE_GENE", "GENE CREATE"); |
---|
823 | else aws->init(root, "EDIT_LOCATION", "EDIT LOCATION"); |
---|
824 | |
---|
825 | aws->load_xfig("ad_gen_create.fig"); |
---|
826 | |
---|
827 | aws->at("close"); |
---|
828 | aws->callback(AW_POPDOWN); |
---|
829 | aws->create_button("CLOSE", "Close", "C"); |
---|
830 | |
---|
831 | aws->at("help"); |
---|
832 | aws->callback(makeHelpCallback("gen_create.hlp")); |
---|
833 | aws->create_button("HELP", "Help", "H"); |
---|
834 | |
---|
835 | aws->button_length(NAME_WIDTH); |
---|
836 | |
---|
837 | aws->at("organism"); |
---|
838 | aws->create_button(NULp, AWAR_ORGANISM_NAME, NULp, "+"); |
---|
839 | |
---|
840 | aws->at("gene"); |
---|
841 | if (createGene) { |
---|
842 | aws->create_input_field(AWAR_GENE_DEST, NAME_WIDTH); |
---|
843 | } |
---|
844 | else { |
---|
845 | aws->create_button(NULp, AWAR_GENE_NAME, NULp, "+"); |
---|
846 | AW_awar *awar_cgene = aws->get_root()->awar(AWAR_COMBINED_GENE_NAME); |
---|
847 | awar_cgene->add_callback(makeRootCallback(gene_changed_cb, loced)); |
---|
848 | awar_cgene->touch(); |
---|
849 | |
---|
850 | loced->add_pos_changed_cb(boundloc_changed_cb); |
---|
851 | } |
---|
852 | aws->button_length(0); |
---|
853 | |
---|
854 | loced->createEditFields(aws); |
---|
855 | |
---|
856 | if (createGene) { |
---|
857 | aws->at_shift(0, 30); |
---|
858 | aws->callback(makeWindowCallback(gene_create_cb, gb_main, loced)); |
---|
859 | aws->create_autosize_button("CREATE", "Create gene", "G"); |
---|
860 | } |
---|
861 | } |
---|
862 | return aws; |
---|
863 | } |
---|
864 | static void popup_gene_location_editor(AW_window *aww, GBDATA *gb_main) { |
---|
865 | AW_window *aws = get_gene_create_or_locationEdit_window(aww->get_root(), false, gb_main); |
---|
866 | aws->activate(); |
---|
867 | } |
---|
868 | static AW_window *create_gene_create_window(AW_root *root, GBDATA *gb_main) { |
---|
869 | return get_gene_create_or_locationEdit_window(root, true, gb_main); |
---|
870 | } |
---|
871 | |
---|
872 | static void gene_delete_cb(AW_window *aww, GBDATA *gb_main) { |
---|
873 | if (aw_ask_sure("gene_delete", "Are you sure to delete the gene?")) { |
---|
874 | GB_transaction ta(gb_main); |
---|
875 | GBDATA *gb_gene = GEN_get_current_gene(gb_main, aww->get_root()); |
---|
876 | |
---|
877 | GB_ERROR error = gb_gene ? GB_delete(gb_gene) : "Please select a gene first"; |
---|
878 | if (error) { |
---|
879 | error = ta.close(error); |
---|
880 | aw_message(error); |
---|
881 | } |
---|
882 | } |
---|
883 | } |
---|
884 | |
---|
885 | static void GEN_create_field_items(AW_window *aws, GBDATA *gb_main) { |
---|
886 | static BoundItemSel *bis = new BoundItemSel(gb_main, GEN_get_selector()); |
---|
887 | gen_assert(bis->gb_main == gb_main); |
---|
888 | |
---|
889 | aws->insert_menu_topic(aws->local_id("gen_reorder_fields"), "Reorder fields ...", "R", "spaf_reorder.hlp", AD_F_ALL, makeCreateWindowCallback(DBUI::create_fields_reorder_window, bis)); |
---|
890 | aws->insert_menu_topic(aws->local_id("gen_delete_field"), "Delete/Hide field ...", "D", "spaf_delete.hlp", AD_F_ALL, makeCreateWindowCallback(DBUI::create_field_delete_window, bis)); |
---|
891 | aws->insert_menu_topic(aws->local_id("gen_create_field"), "Create fields ...", "C", "spaf_create.hlp", AD_F_ALL, makeCreateWindowCallback(DBUI::create_field_create_window, bis)); |
---|
892 | aws->sep______________(); |
---|
893 | aws->insert_menu_topic("gen_unhide_fields", "Show all hidden fields", "S", "scandb.hlp", AD_F_ALL, makeWindowCallback(gene_field_selection_list_unhide_all_cb, gb_main)); |
---|
894 | aws->insert_menu_topic("gen_refresh_fields", "Refresh fields", "f", "scandb.hlp", AD_F_ALL, makeWindowCallback(gene_field_selection_list_update_cb, gb_main)); |
---|
895 | } |
---|
896 | |
---|
897 | static AW_window *popup_new_gene_window(AW_root *aw_root, GBDATA *gb_main, int detach_id); |
---|
898 | |
---|
899 | static void popup_detached_gene_window(AW_window *aw_parent, const InfoWindow *infoWin) { |
---|
900 | const InfoWindow *reusable = InfoWindowRegistry::infowin.find_reusable_of_same_type_as(*infoWin); |
---|
901 | if (reusable) { |
---|
902 | reusable->reuse(); |
---|
903 | } |
---|
904 | else { // create a new window if none is reusable |
---|
905 | popup_new_gene_window(aw_parent->get_root(), |
---|
906 | infoWin->get_gbmain(), |
---|
907 | InfoWindowRegistry::infowin.allocate_detach_id(*infoWin)); |
---|
908 | } |
---|
909 | } |
---|
910 | |
---|
911 | static AW_window *popup_new_gene_window(AW_root *aw_root, GBDATA *gb_main, int detach_id) { // INFO_WINDOW_CREATOR |
---|
912 | AW_window_simple_menu *aws = new AW_window_simple_menu; |
---|
913 | const ItemSelector& itemType = GEN_get_selector(); |
---|
914 | |
---|
915 | DBUI::init_info_window(aw_root, aws, itemType, detach_id); |
---|
916 | aws->load_xfig("ad_spec.fig"); |
---|
917 | |
---|
918 | aws->button_length(8); |
---|
919 | |
---|
920 | aws->at("close"); |
---|
921 | aws->callback(AW_POPDOWN); |
---|
922 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
923 | |
---|
924 | aws->at("search"); |
---|
925 | aws->callback(makeCreateWindowCallback(GEN_create_gene_query_window, gb_main)); |
---|
926 | aws->create_button("SEARCH", "SEARCH", "S", "+"); |
---|
927 | |
---|
928 | aws->at("help"); |
---|
929 | aws->callback(makeHelpCallback("gene_info.hlp")); |
---|
930 | aws->create_button("HELP", "HELP", "H"); |
---|
931 | |
---|
932 | DbScanner *scanner = DbScanner::create(gb_main, |
---|
933 | InfoWindowRegistry::localize_scanner_id("gene", detach_id), |
---|
934 | aws, "box", "field", "enable", DB_KEYVIEWER, "mark", itemType); |
---|
935 | |
---|
936 | const InfoWindow& infoWin = InfoWindowRegistry::infowin.registerInfoWindow(aws, scanner, detach_id); |
---|
937 | |
---|
938 | if (infoWin.is_maininfo()) { |
---|
939 | aws->create_menu("GENE", "G", AD_F_ALL); |
---|
940 | aws->insert_menu_topic("gene_delete", "Delete", "D", "spa_delete.hlp", AD_F_ALL, makeWindowCallback (gene_delete_cb, gb_main)); |
---|
941 | aws->insert_menu_topic("gene_rename", "Rename ...", "R", "spa_rename.hlp", AD_F_ALL, makeWindowCallback (gene_rename_cb, gb_main)); |
---|
942 | aws->insert_menu_topic("gene_copy", "Copy ...", "y", "spa_copy.hlp", AD_F_ALL, makeWindowCallback (gene_copy_cb, gb_main)); |
---|
943 | aws->insert_menu_topic("gene_create", "Create ...", "C", "gen_create.hlp", AD_F_ALL, makeCreateWindowCallback(create_gene_create_window, gb_main)); |
---|
944 | aws->sep______________(); |
---|
945 | aws->insert_menu_topic("gen_edit_loc", "Edit gene location", "l", "gen_create.hlp", AD_F_ALL, makeWindowCallback (popup_gene_location_editor, gb_main)); |
---|
946 | } |
---|
947 | |
---|
948 | aws->create_menu("FIELDS", "F", AD_F_ALL); |
---|
949 | GEN_create_field_items(aws, gb_main); |
---|
950 | |
---|
951 | aws->at("detach"); |
---|
952 | infoWin.add_detach_area(popup_detached_gene_window); |
---|
953 | |
---|
954 | aws->show(); |
---|
955 | infoWin.attach_selected_item(); |
---|
956 | |
---|
957 | return aws; |
---|
958 | } |
---|
959 | |
---|
960 | void GEN_popup_gene_infowindow(AW_root *aw_root, GBDATA *gb_main) { // @@@ move to SL/DB_UI |
---|
961 | static AW_window *aws = NULp; |
---|
962 | if (!aws) { |
---|
963 | aws = popup_new_gene_window(aw_root, gb_main, InfoWindow::MAIN_WINDOW); |
---|
964 | } |
---|
965 | else { |
---|
966 | InfoWindowRegistry::reactivate(aws); |
---|
967 | } |
---|
968 | } |
---|
969 | |
---|
970 | AW_window *GEN_create_gene_query_window(AW_root *aw_root, GBDATA *gb_main) { // @@@ move to SL/DB_UI |
---|
971 | static AW_window_simple_menu *aws = NULp; |
---|
972 | |
---|
973 | if (!aws) { |
---|
974 | aws = new AW_window_simple_menu; |
---|
975 | aws->init(aw_root, "GEN_QUERY", "Gene SEARCH and QUERY"); |
---|
976 | aws->create_menu("More functions", "f"); |
---|
977 | aws->load_xfig("ad_query.fig"); |
---|
978 | |
---|
979 | QUERY::query_spec awtqs(GEN_get_selector()); |
---|
980 | |
---|
981 | awtqs.gb_main = gb_main; |
---|
982 | awtqs.species_name = AWAR_SPECIES_NAME; |
---|
983 | awtqs.tree_name = AWAR_TREE; |
---|
984 | awtqs.select_bit = GB_USERFLAG_QUERY; |
---|
985 | awtqs.use_menu = 1; |
---|
986 | awtqs.ere_pos_fig = "ere3"; |
---|
987 | awtqs.where_pos_fig = "where3"; |
---|
988 | awtqs.by_pos_fig = "by3"; |
---|
989 | awtqs.qbox_pos_fig = "qbox"; |
---|
990 | awtqs.key_pos_fig = NULp; |
---|
991 | awtqs.query_pos_fig = "content"; |
---|
992 | awtqs.result_pos_fig = "result"; |
---|
993 | awtqs.count_pos_fig = "count"; |
---|
994 | awtqs.do_query_pos_fig = "doquery"; |
---|
995 | awtqs.config_pos_fig = "doconfig"; |
---|
996 | awtqs.do_mark_pos_fig = "domark"; |
---|
997 | awtqs.do_unmark_pos_fig = "dounmark"; |
---|
998 | awtqs.do_delete_pos_fig = "dodelete"; |
---|
999 | awtqs.do_set_pos_fig = "doset"; |
---|
1000 | awtqs.do_refresh_pos_fig = "dorefresh"; |
---|
1001 | awtqs.open_parser_pos_fig = "openparser"; |
---|
1002 | awtqs.popup_info_window = GEN_popup_gene_infowindow; |
---|
1003 | |
---|
1004 | QUERY::DbQuery *query = create_query_box(aws, &awtqs, "gen"); |
---|
1005 | GLOBAL_gene_query = query; |
---|
1006 | |
---|
1007 | aws->create_menu("More search", "s"); |
---|
1008 | aws->insert_menu_topic("gen_search_equal_fields_within_db", "Search For Equal Fields and Mark Duplicates", "E", "search_duplicates.hlp", AWM_ALL, makeWindowCallback(QUERY::search_duplicated_field_content, query, false)); |
---|
1009 | aws->insert_menu_topic("gen_search_equal_words_within_db", "Search For Equal Words Between Fields and Mark Duplicates", "W", "search_duplicates.hlp", AWM_ALL, makeWindowCallback(QUERY::search_duplicated_field_content, query, true)); |
---|
1010 | |
---|
1011 | aws->button_length(7); |
---|
1012 | |
---|
1013 | aws->at("close"); |
---|
1014 | aws->callback(AW_POPDOWN); |
---|
1015 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
1016 | |
---|
1017 | aws->at("help"); |
---|
1018 | aws->callback(makeHelpCallback("gene_search.hlp")); |
---|
1019 | aws->create_button("HELP", "HELP", "H"); |
---|
1020 | } |
---|
1021 | |
---|
1022 | return aws; |
---|
1023 | } |
---|