1 | #include <cstdlib> |
---|
2 | #include <cstring> |
---|
3 | #include <awt.hxx> |
---|
4 | #include <awt_canvas.hxx> |
---|
5 | #include <awt_item_sel_list.hxx> |
---|
6 | #include <awt_sel_boxes.hxx> |
---|
7 | #include <aw_awars.hxx> |
---|
8 | #include <db_scanner.hxx> |
---|
9 | |
---|
10 | #include <arbdbt.h> |
---|
11 | #include <probe_design.hxx> |
---|
12 | |
---|
13 | #include <ntree.hxx> |
---|
14 | #include <../NTREE/ad_spec.hxx> |
---|
15 | #include <../NTREE/nt_internal.h> |
---|
16 | |
---|
17 | #ifndef GEN_LOCAL_HXX |
---|
18 | #include "GEN_local.hxx" |
---|
19 | #endif |
---|
20 | #ifndef GEN_NDS_HXX |
---|
21 | #include "GEN_nds.hxx" |
---|
22 | #endif |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | // -------------------------------------------------------------------------------- |
---|
27 | |
---|
28 | #define AD_F_ALL (AW_active)(-1) |
---|
29 | |
---|
30 | // -------------------------------------------------------------------------------- |
---|
31 | |
---|
32 | void GEN_select_gene(GBDATA* /*gb_main*/, AW_root *aw_root, const char *item_name) { |
---|
33 | char *organism = strdup(item_name); |
---|
34 | char *gene = strchr(organism, '/'); |
---|
35 | |
---|
36 | if (gene) { |
---|
37 | *gene++ = 0; |
---|
38 | aw_root->awar(AWAR_ORGANISM_NAME)->write_string(organism); |
---|
39 | aw_root->awar(AWAR_GENE_NAME)->write_string(gene); |
---|
40 | } |
---|
41 | else if (!item_name[0]) { // accept empty input -> deselect gene/organism |
---|
42 | aw_root->awar(AWAR_GENE_NAME)->write_string(""); |
---|
43 | aw_root->awar(AWAR_ORGANISM_NAME)->write_string(""); |
---|
44 | } |
---|
45 | else { |
---|
46 | aw_message(GBS_global_string("Illegal item_name '%s' in GEN_select_gene()", item_name)); |
---|
47 | } |
---|
48 | free(organism); |
---|
49 | } |
---|
50 | |
---|
51 | static char *gen_get_gene_id(GBDATA */*gb_main*/, GBDATA *gb_gene) { |
---|
52 | GBDATA *gb_species = GB_get_grandfather(gb_gene); |
---|
53 | return GBS_global_string_copy("%s/%s", GBT_read_name(gb_species), GBT_read_name(gb_gene)); |
---|
54 | } |
---|
55 | |
---|
56 | static GBDATA *gen_find_gene_by_id(GBDATA *gb_main, const char *id) { |
---|
57 | char *organism = strdup(id); |
---|
58 | char *gene = strchr(organism, '/'); |
---|
59 | GBDATA *result = 0; |
---|
60 | |
---|
61 | if (gene) { |
---|
62 | *gene++ = 0; |
---|
63 | GBDATA *gb_organism = GEN_find_organism(gb_main, organism); |
---|
64 | if (gb_organism) { |
---|
65 | result = GEN_find_gene(gb_organism, gene); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | free(organism); |
---|
70 | return result; |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | extern "C" GB_ERROR GEN_mark_organism_or_corresponding_organism(GBDATA *gb_species, int *client_data) { |
---|
75 | AWUSE(client_data); |
---|
76 | GB_ERROR error = 0; |
---|
77 | |
---|
78 | if (GEN_is_pseudo_gene_species(gb_species)) { |
---|
79 | GBDATA *gb_organism = GEN_find_origin_organism(gb_species, 0); |
---|
80 | if (gb_organism) { |
---|
81 | GB_write_flag(gb_organism, 1); |
---|
82 | } |
---|
83 | else { |
---|
84 | error = GEN_organism_not_found(gb_species); |
---|
85 | } |
---|
86 | } |
---|
87 | else if (GEN_is_organism(gb_species)) { |
---|
88 | GB_write_flag(gb_species, 1); |
---|
89 | } |
---|
90 | |
---|
91 | return error; |
---|
92 | } |
---|
93 | |
---|
94 | static char *old_species_marks = 0; // configuration storing marked species |
---|
95 | |
---|
96 | inline void gen_restore_old_species_marks() { |
---|
97 | if (old_species_marks) { |
---|
98 | GBT_restore_marked_species(GLOBAL_gb_main, old_species_marks); |
---|
99 | freeset(old_species_marks, 0); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | static GBDATA *GEN_get_first_gene_data(GBDATA *gb_main, AW_root *aw_root, AWT_QUERY_RANGE range) { |
---|
104 | GBDATA *gb_organism = 0; |
---|
105 | GB_ERROR error = 0; |
---|
106 | |
---|
107 | gen_restore_old_species_marks(); |
---|
108 | |
---|
109 | switch (range) { |
---|
110 | case AWT_QUERY_CURRENT_SPECIES: { |
---|
111 | char *species_name = aw_root->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
112 | gb_organism = GEN_find_organism(gb_main, species_name); |
---|
113 | free(species_name); |
---|
114 | break; |
---|
115 | } |
---|
116 | case AWT_QUERY_MARKED_SPECIES: { |
---|
117 | gb_organism = GEN_first_marked_organism(gb_main); |
---|
118 | GBDATA *gb_pseudo = GEN_first_marked_pseudo_species(gb_main); |
---|
119 | |
---|
120 | if (gb_pseudo) { // there are marked pseudo-species.. |
---|
121 | old_species_marks = GBT_store_marked_species(gb_main, 1); // store and unmark marked species |
---|
122 | |
---|
123 | error = GBT_with_stored_species(gb_main, old_species_marks, GEN_mark_organism_or_corresponding_organism, 0); // mark organisms related with stored |
---|
124 | if (!error) gb_organism = GEN_first_marked_organism(gb_main); |
---|
125 | } |
---|
126 | |
---|
127 | break; |
---|
128 | } |
---|
129 | case AWT_QUERY_ALL_SPECIES: { |
---|
130 | gb_organism = GEN_first_organism(gb_main); |
---|
131 | break; |
---|
132 | } |
---|
133 | default: { |
---|
134 | gen_assert(0); |
---|
135 | break; |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | if (error) GB_export_error(error); |
---|
140 | return gb_organism ? GEN_expect_gene_data(gb_organism) : 0; |
---|
141 | } |
---|
142 | |
---|
143 | static GBDATA *GEN_get_next_gene_data(GBDATA *gb_gene_data, AWT_QUERY_RANGE range) { |
---|
144 | GBDATA *gb_organism = 0; |
---|
145 | switch (range) { |
---|
146 | case AWT_QUERY_CURRENT_SPECIES: { |
---|
147 | break; |
---|
148 | } |
---|
149 | case AWT_QUERY_MARKED_SPECIES: { |
---|
150 | GBDATA *gb_last_organism = GB_get_father(gb_gene_data); |
---|
151 | gb_organism = GEN_next_marked_organism(gb_last_organism); |
---|
152 | |
---|
153 | if (!gb_organism) gen_restore_old_species_marks(); // got all -> clean up |
---|
154 | |
---|
155 | break; |
---|
156 | } |
---|
157 | case AWT_QUERY_ALL_SPECIES: { |
---|
158 | GBDATA *gb_last_organism = GB_get_father(gb_gene_data); |
---|
159 | gb_organism = GEN_next_organism(gb_last_organism); |
---|
160 | break; |
---|
161 | } |
---|
162 | default: { |
---|
163 | gen_assert(0); |
---|
164 | break; |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | return gb_organism ? GEN_expect_gene_data(gb_organism) : 0; |
---|
169 | } |
---|
170 | |
---|
171 | // -------------------------- |
---|
172 | // GEN_item_selector |
---|
173 | |
---|
174 | struct ad_item_selector GEN_item_selector = { |
---|
175 | AWT_QUERY_ITEM_GENES, |
---|
176 | GEN_select_gene, |
---|
177 | gen_get_gene_id, |
---|
178 | gen_find_gene_by_id, |
---|
179 | (AW_CB)awt_gene_field_selection_list_update_cb, |
---|
180 | -1, // unknown |
---|
181 | CHANGE_KEY_PATH_GENES, |
---|
182 | "gene", |
---|
183 | "genes", |
---|
184 | "name", |
---|
185 | GEN_get_first_gene_data, |
---|
186 | GEN_get_next_gene_data, |
---|
187 | GEN_first_gene_rel_gene_data, |
---|
188 | GEN_next_gene, |
---|
189 | GEN_get_current_gene, |
---|
190 | &AWT_organism_selector, GB_get_grandfather, |
---|
191 | }; |
---|
192 | |
---|
193 | ad_item_selector *GEN_get_selector() { return &GEN_item_selector; } |
---|
194 | |
---|
195 | void GEN_species_name_changed_cb(AW_root *awr) { |
---|
196 | char *species_name = awr->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
197 | GB_transaction ta(GLOBAL_gb_main); |
---|
198 | GBDATA *gb_species = GBT_find_species(GLOBAL_gb_main, species_name); |
---|
199 | |
---|
200 | if (gb_species) { |
---|
201 | if (GEN_is_pseudo_gene_species(gb_species)) { |
---|
202 | awr->awar(AWAR_ORGANISM_NAME)->write_string(GEN_origin_organism(gb_species)); |
---|
203 | awr->awar(AWAR_GENE_NAME)->write_string(GEN_origin_gene(gb_species)); |
---|
204 | } |
---|
205 | else { |
---|
206 | awr->awar(AWAR_ORGANISM_NAME)->write_string(species_name); |
---|
207 | } |
---|
208 | } |
---|
209 | free(species_name); |
---|
210 | } |
---|
211 | |
---|
212 | static void auto_select_pseudo_species(AW_root *awr, GBDATA *gb_main, const char *organism, const char *gene) { |
---|
213 | GB_transaction ta(gb_main); |
---|
214 | GBDATA *gb_pseudo = GEN_find_pseudo_species(gb_main, organism, gene, 0); // search for pseudo species.. |
---|
215 | |
---|
216 | awr->awar(AWAR_SPECIES_NAME)->write_string(gb_pseudo |
---|
217 | ? GBT_read_name(gb_pseudo) // .. if found select |
---|
218 | : organism); // otherwise select organism |
---|
219 | } |
---|
220 | |
---|
221 | void GEN_update_GENE_CONTENT(GBDATA *gb_main, AW_root *awr) { |
---|
222 | GB_transaction dummy(gb_main); |
---|
223 | GBDATA *gb_gene = GEN_get_current_gene(gb_main, awr); |
---|
224 | bool clear = true; |
---|
225 | |
---|
226 | if (gb_gene) { |
---|
227 | // ignore complement here (to highlight gene in ARB_EDIT4); |
---|
228 | // separate multiple parts by \n |
---|
229 | char *gene_content = GBT_read_gene_sequence(gb_gene, GB_FALSE, '\n'); |
---|
230 | |
---|
231 | awr->awar(AWAR_GENE_CONTENT)->write_string(gene_content); |
---|
232 | clear = false; |
---|
233 | free(gene_content); |
---|
234 | } |
---|
235 | else { |
---|
236 | char *gene_name = awr->awar(AWAR_GENE_NAME)->read_string(); |
---|
237 | const int prefix_len = 10; |
---|
238 | |
---|
239 | if (strncmp(gene_name, "intergene_", prefix_len) == 0) { // special case (non-gene result from gene pt server) |
---|
240 | char *start_pos_ptr = gene_name+prefix_len; |
---|
241 | char *end_pos_ptr = strchr(start_pos_ptr, '_'); |
---|
242 | |
---|
243 | gen_assert(end_pos_ptr); |
---|
244 | if (end_pos_ptr) { |
---|
245 | *end_pos_ptr++ = 0; |
---|
246 | long start_pos = atol(start_pos_ptr); |
---|
247 | long end_pos = atol(end_pos_ptr); |
---|
248 | |
---|
249 | gen_assert(end_pos >= start_pos); |
---|
250 | |
---|
251 | GBDATA *gb_organism = GEN_get_current_organism(gb_main, awr); |
---|
252 | if (gb_organism) { |
---|
253 | GBDATA *gb_seq = GBT_read_sequence(gb_organism, GENOM_ALIGNMENT); |
---|
254 | const char *seq_data = GB_read_char_pntr(gb_seq); |
---|
255 | |
---|
256 | long len = end_pos-start_pos+1; |
---|
257 | char *buffer = (char*)malloc(len+1); |
---|
258 | memcpy(buffer, seq_data+start_pos, len); |
---|
259 | buffer[len] = 0; |
---|
260 | |
---|
261 | awr->awar(AWAR_GENE_CONTENT)->write_string(buffer); |
---|
262 | clear = false; |
---|
263 | |
---|
264 | free(buffer); |
---|
265 | } |
---|
266 | } |
---|
267 | } |
---|
268 | free(gene_name); |
---|
269 | } |
---|
270 | |
---|
271 | if (clear) { |
---|
272 | awr->awar(AWAR_GENE_CONTENT)->write_string(""); // if we did not detect any gene sequence -> clear |
---|
273 | } |
---|
274 | } |
---|
275 | |
---|
276 | void GEN_update_combined_cb(AW_root *awr) { |
---|
277 | char *organism = awr->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
278 | char *gene = awr->awar(AWAR_GENE_NAME)->read_string(); |
---|
279 | char *old_combined = awr->awar(AWAR_COMBINED_GENE_NAME)->read_string(); |
---|
280 | const char *combined = GBS_global_string("%s/%s", organism, gene); |
---|
281 | |
---|
282 | if (strcmp(combined, old_combined) != 0) { |
---|
283 | awr->awar(AWAR_COMBINED_GENE_NAME)->write_string(combined); |
---|
284 | auto_select_pseudo_species(awr, GLOBAL_gb_main, organism, gene); |
---|
285 | GEN_update_GENE_CONTENT(GLOBAL_gb_main, awr); |
---|
286 | } |
---|
287 | |
---|
288 | free(old_combined); |
---|
289 | free(gene); |
---|
290 | free(organism); |
---|
291 | } |
---|
292 | |
---|
293 | void GEN_create_awars(AW_root *aw_root, AW_default aw_def) { |
---|
294 | aw_root->awar_string(AWAR_COMBINED_GENE_NAME,"",GLOBAL_gb_main); |
---|
295 | aw_root->awar_string(AWAR_GENE_CONTENT,"",GLOBAL_gb_main); |
---|
296 | |
---|
297 | aw_root->awar_string(AWAR_GENE_NAME, "" , GLOBAL_gb_main)->add_callback((AW_RCB0)GEN_update_combined_cb); |
---|
298 | aw_root->awar_string(AWAR_ORGANISM_NAME, "" , GLOBAL_gb_main)->add_callback((AW_RCB0)GEN_update_combined_cb); |
---|
299 | |
---|
300 | aw_root->awar_string(AWAR_SPECIES_NAME,"",GLOBAL_gb_main)->add_callback((AW_RCB0)GEN_species_name_changed_cb); |
---|
301 | |
---|
302 | aw_root->awar_string(AWAR_GENE_DEST, "" , aw_def); |
---|
303 | aw_root->awar_string(AWAR_GENE_POS1, "" , aw_def); |
---|
304 | aw_root->awar_string(AWAR_GENE_POS2, "" , aw_def); |
---|
305 | aw_root->awar_int(AWAR_GENE_COMPLEMENT, 0, aw_def); |
---|
306 | |
---|
307 | aw_root->awar_string(AWAR_GENE_EXTRACT_ALI, "ali_gene_" , aw_def); |
---|
308 | } |
---|
309 | |
---|
310 | GBDATA *GEN_get_current_organism(GBDATA *gb_main, AW_root *aw_root) { |
---|
311 | char *species_name = aw_root->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
312 | GBDATA *gb_species = GBT_find_species(gb_main,species_name); |
---|
313 | free(species_name); |
---|
314 | return gb_species; |
---|
315 | } |
---|
316 | |
---|
317 | GBDATA* GEN_get_current_gene_data(GBDATA *gb_main, AW_root *aw_root) { |
---|
318 | GBDATA *gb_species = GEN_get_current_organism(gb_main, aw_root); |
---|
319 | GBDATA *gb_gene_data = 0; |
---|
320 | |
---|
321 | if (gb_species) gb_gene_data = GEN_expect_gene_data(gb_species); |
---|
322 | |
---|
323 | return gb_gene_data; |
---|
324 | } |
---|
325 | |
---|
326 | GBDATA *GEN_get_current_gene(GBDATA *gb_main, AW_root *aw_root) { |
---|
327 | GBDATA *gb_species = GEN_get_current_organism(gb_main, aw_root); |
---|
328 | GBDATA *gb_gene = 0; |
---|
329 | |
---|
330 | if (gb_species) { |
---|
331 | char *gene_name = aw_root->awar(AWAR_GENE_NAME)->read_string(); |
---|
332 | gb_gene = GEN_find_gene(gb_species,gene_name); |
---|
333 | free(gene_name); |
---|
334 | } |
---|
335 | |
---|
336 | return gb_gene; |
---|
337 | } |
---|
338 | |
---|
339 | |
---|
340 | static AW_CL ad_global_scannerid = 0; |
---|
341 | static AW_root *ad_global_scannerroot = 0; |
---|
342 | AW_CL gene_query_global_cbs = 0; |
---|
343 | |
---|
344 | void gene_rename_cb(AW_window *aww) { |
---|
345 | AW_root *aw_root = aww->get_root(); |
---|
346 | char *source = aw_root->awar(AWAR_GENE_NAME)->read_string(); |
---|
347 | char *dest = aw_root->awar(AWAR_GENE_DEST)->read_string(); |
---|
348 | |
---|
349 | if (strcmp(source, dest) != 0) { |
---|
350 | GB_ERROR error = GB_begin_transaction(GLOBAL_gb_main); |
---|
351 | |
---|
352 | if (!error) { |
---|
353 | GBDATA *gb_gene_data = GEN_get_current_gene_data(GLOBAL_gb_main, aww->get_root()); |
---|
354 | |
---|
355 | if (!gb_gene_data) error = "Please select a species"; |
---|
356 | else { |
---|
357 | GBDATA *gb_source = GEN_find_gene_rel_gene_data(gb_gene_data, source); |
---|
358 | GBDATA *gb_dest = GEN_find_gene_rel_gene_data(gb_gene_data, dest); |
---|
359 | |
---|
360 | if (!gb_source) error = "Please select a gene first"; |
---|
361 | else if (gb_dest) error = GB_export_errorf("Gene '%s' already exists", dest); |
---|
362 | else { |
---|
363 | GBDATA *gb_name = GB_search(gb_source, "name", GB_STRING); |
---|
364 | |
---|
365 | if (!gb_name) error = GB_await_error(); |
---|
366 | else { |
---|
367 | error = GB_write_string(gb_name, dest); |
---|
368 | if (!error) aww->get_root()->awar(AWAR_GENE_NAME)->write_string(dest); |
---|
369 | } |
---|
370 | } |
---|
371 | } |
---|
372 | } |
---|
373 | |
---|
374 | error = GB_end_transaction(GLOBAL_gb_main, error); |
---|
375 | aww->hide_or_notify(error); |
---|
376 | } |
---|
377 | |
---|
378 | free(source); |
---|
379 | free(dest); |
---|
380 | } |
---|
381 | |
---|
382 | AW_window *create_gene_rename_window(AW_root *root) |
---|
383 | { |
---|
384 | AW_window_simple *aws = new AW_window_simple; |
---|
385 | aws->init( root, "RENAME_GENE", "GENE RENAME"); |
---|
386 | aws->load_xfig("ad_al_si.fig"); |
---|
387 | |
---|
388 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
389 | aws->at("close"); |
---|
390 | aws->create_button("CLOSE","CLOSE","C"); |
---|
391 | |
---|
392 | aws->at("label"); |
---|
393 | aws->create_autosize_button(0,"Please enter the new name\nof the gene"); |
---|
394 | |
---|
395 | aws->at("input"); |
---|
396 | aws->create_input_field(AWAR_GENE_DEST,15); |
---|
397 | aws->at("ok"); |
---|
398 | aws->callback(gene_rename_cb); |
---|
399 | aws->create_button("GO","GO","G"); |
---|
400 | |
---|
401 | return (AW_window *)aws; |
---|
402 | } |
---|
403 | |
---|
404 | void gene_copy_cb(AW_window *aww){ |
---|
405 | char *source = aww->get_root()->awar(AWAR_GENE_NAME)->read_string(); |
---|
406 | char *dest = aww->get_root()->awar(AWAR_GENE_DEST)->read_string(); |
---|
407 | GB_ERROR error = GB_begin_transaction(GLOBAL_gb_main); |
---|
408 | if (!error) { |
---|
409 | GBDATA *gb_gene_data = GEN_get_current_gene_data(GLOBAL_gb_main, aww->get_root()); |
---|
410 | |
---|
411 | if (!gb_gene_data) { |
---|
412 | error = "Please select a species first."; |
---|
413 | } |
---|
414 | else { |
---|
415 | GBDATA *gb_source = GEN_find_gene_rel_gene_data(gb_gene_data, source); |
---|
416 | GBDATA *gb_dest = GEN_find_gene_rel_gene_data(gb_gene_data, dest); |
---|
417 | |
---|
418 | if (!gb_source) error = "Please select a gene"; |
---|
419 | else if (gb_dest) error = GB_export_errorf("Gene '%s' already exists", dest); |
---|
420 | else { |
---|
421 | gb_dest = GB_create_container(gb_gene_data,"gene"); |
---|
422 | if (!gb_dest) error = GB_await_error(); |
---|
423 | else error = GB_copy(gb_dest, gb_source); |
---|
424 | |
---|
425 | if (!error) error = GBT_write_string(gb_dest, "name", dest); |
---|
426 | if (!error) aww->get_root()->awar(AWAR_GENE_NAME)->write_string(dest); |
---|
427 | } |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | error = GB_end_transaction(GLOBAL_gb_main, error); |
---|
432 | aww->hide_or_notify(error); |
---|
433 | |
---|
434 | free(source); |
---|
435 | free(dest); |
---|
436 | } |
---|
437 | |
---|
438 | AW_window *create_gene_copy_window(AW_root *root) |
---|
439 | { |
---|
440 | AW_window_simple *aws = new AW_window_simple; |
---|
441 | aws->init( root, "COPY_GENE", "GENE COPY"); |
---|
442 | aws->load_xfig("ad_al_si.fig"); |
---|
443 | |
---|
444 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
445 | aws->at("close"); |
---|
446 | aws->create_button("CLOSE","CLOSE","C"); |
---|
447 | |
---|
448 | aws->at("label"); |
---|
449 | aws->create_autosize_button(0,"Please enter the name\nof the new gene"); |
---|
450 | |
---|
451 | aws->at("input"); |
---|
452 | aws->create_input_field(AWAR_GENE_DEST,15); |
---|
453 | |
---|
454 | aws->at("ok"); |
---|
455 | aws->callback(gene_copy_cb); |
---|
456 | aws->create_button("GO","GO","G"); |
---|
457 | |
---|
458 | return (AW_window *)aws; |
---|
459 | } |
---|
460 | |
---|
461 | void gene_create_cb(AW_window *aww){ |
---|
462 | GB_begin_transaction(GLOBAL_gb_main); |
---|
463 | |
---|
464 | GB_ERROR error = 0; |
---|
465 | AW_root *aw_root = aww->get_root(); |
---|
466 | char *dest = aw_root->awar(AWAR_GENE_DEST)->read_string(); |
---|
467 | int pos1 = atoi(aw_root->awar(AWAR_GENE_POS1)->read_string()); |
---|
468 | int pos2 = atoi(aw_root->awar(AWAR_GENE_POS2)->read_string()); |
---|
469 | int complement = aw_root->awar(AWAR_GENE_COMPLEMENT)->read_int(); |
---|
470 | GBDATA *gb_gene_data = GEN_get_current_gene_data(GLOBAL_gb_main, aw_root); |
---|
471 | GBDATA *gb_dest = GEN_find_gene_rel_gene_data(gb_gene_data, dest); |
---|
472 | |
---|
473 | if (!gb_gene_data) error = "Please select a species first"; |
---|
474 | else if (gb_dest) error = GBS_global_string("Gene '%s' already exists", dest); |
---|
475 | else { |
---|
476 | GB_ERROR pos_error = 0; |
---|
477 | if (pos1<1 || pos2<1) pos_error = "positions have to be above zero"; |
---|
478 | else if (pos2<pos1) pos_error = "endpos has to be greater or equal to startpos"; |
---|
479 | else { |
---|
480 | GBDATA *gb_organism = GB_get_father(gb_gene_data); |
---|
481 | GBDATA *gb_genome = GBT_read_sequence(gb_organism, GENOM_ALIGNMENT); |
---|
482 | int genome_length = GB_read_count(gb_genome); |
---|
483 | |
---|
484 | if (pos2 > genome_length) { |
---|
485 | pos_error = GBS_global_string("endpos is behind sequence end (%i)", genome_length); |
---|
486 | } |
---|
487 | } |
---|
488 | |
---|
489 | if (pos_error) { |
---|
490 | error = GBS_global_string("Illegal position(s): %s", pos_error); |
---|
491 | } |
---|
492 | else { |
---|
493 | gb_dest = GEN_find_or_create_gene_rel_gene_data(gb_gene_data, dest); |
---|
494 | |
---|
495 | if (!gb_dest) error = GB_await_error(); |
---|
496 | else { |
---|
497 | error = GBT_write_int(gb_dest, "pos_start", pos1); |
---|
498 | if (!error) error = GBT_write_int(gb_dest, "pos_stop", pos2); |
---|
499 | if (!error) error = GBT_write_byte(gb_dest, "complement", complement); |
---|
500 | } |
---|
501 | |
---|
502 | if (!error) aww->get_root()->awar(AWAR_GENE_NAME)->write_string(dest); |
---|
503 | } |
---|
504 | } |
---|
505 | GB_end_transaction_show_error(GLOBAL_gb_main, error, aw_message); |
---|
506 | free(dest); |
---|
507 | } |
---|
508 | |
---|
509 | AW_window *create_gene_create_window(AW_root *root) |
---|
510 | { |
---|
511 | AW_window_simple *aws = new AW_window_simple; |
---|
512 | aws->init( root, "CREATE_GENE","GENE CREATE"); |
---|
513 | aws->load_xfig("ad_al_si3.fig"); |
---|
514 | |
---|
515 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
516 | aws->at("close"); |
---|
517 | aws->create_button("CLOSE","CLOSE","C"); |
---|
518 | |
---|
519 | aws->at("label"); aws->create_autosize_button(0,"Please enter the name\nof the new gene"); |
---|
520 | aws->at("input"); aws->create_input_field(AWAR_GENE_DEST,15); |
---|
521 | |
---|
522 | aws->at("label1"); aws->create_autosize_button(0,"Start position"); |
---|
523 | aws->at("input1"); aws->create_input_field(AWAR_GENE_POS1,12); |
---|
524 | |
---|
525 | aws->at("label2"); aws->create_autosize_button(0,"End position"); |
---|
526 | aws->at("input2"); aws->create_input_field(AWAR_GENE_POS2,12); |
---|
527 | |
---|
528 | aws->at("toggle"); |
---|
529 | aws->label("Complementary strand"); |
---|
530 | aws->create_toggle(AWAR_GENE_COMPLEMENT); |
---|
531 | |
---|
532 | aws->at("ok"); |
---|
533 | aws->callback(gene_create_cb); |
---|
534 | aws->create_button("GO","GO","G"); |
---|
535 | |
---|
536 | return (AW_window *)aws; |
---|
537 | } |
---|
538 | |
---|
539 | void gene_delete_cb(AW_window *aww){ |
---|
540 | if (aw_ask_sure("Are you sure to delete the gene?")) { |
---|
541 | GB_transaction ta(GLOBAL_gb_main); |
---|
542 | GB_ERROR error = 0; |
---|
543 | GBDATA *gb_gene = GEN_get_current_gene(GLOBAL_gb_main, aww->get_root()); |
---|
544 | |
---|
545 | error = gb_gene ? GB_delete(gb_gene) : "Please select a gene first"; |
---|
546 | if (error) { |
---|
547 | error = ta.close(error); |
---|
548 | aw_message(error); |
---|
549 | } |
---|
550 | } |
---|
551 | } |
---|
552 | |
---|
553 | void GEN_map_gene(AW_root *aw_root, AW_CL scannerid) |
---|
554 | { |
---|
555 | GB_transaction dummy(GLOBAL_gb_main); |
---|
556 | GBDATA *gb_gene = GEN_get_current_gene(GLOBAL_gb_main, aw_root); |
---|
557 | |
---|
558 | if (gb_gene) awt_map_arbdb_scanner(scannerid, gb_gene, 0, CHANGE_KEY_PATH_GENES); |
---|
559 | } |
---|
560 | |
---|
561 | void GEN_create_field_items(AW_window *aws) { |
---|
562 | aws->insert_menu_topic("gen_reorder_fields", "Reorder fields ...", "R", "spaf_reorder.hlp", AD_F_ALL, AW_POPUP, (AW_CL)NT_create_ad_list_reorder, (AW_CL)&GEN_item_selector); |
---|
563 | aws->insert_menu_topic("gen_delete_field", "Delete/Hide field ...", "D", "spaf_delete.hlp", AD_F_ALL, AW_POPUP, (AW_CL)NT_create_ad_field_delete, (AW_CL)&GEN_item_selector); |
---|
564 | aws->insert_menu_topic("gen_create_field", "Create fields ...", "C", "spaf_create.hlp", AD_F_ALL, AW_POPUP, (AW_CL)NT_create_ad_field_create, (AW_CL)&GEN_item_selector); |
---|
565 | aws->insert_separator(); |
---|
566 | aws->insert_menu_topic("gen_unhide_fields", "Show all hidden fields", "S", "scandb.hlp", AD_F_ALL, (AW_CB)awt_gene_field_selection_list_unhide_all_cb, (AW_CL)GLOBAL_gb_main, AWT_NDS_FILTER); |
---|
567 | aws->insert_separator(); |
---|
568 | aws->insert_menu_topic("gen_scan_unknown_fields", "Scan unknown fields", "u", "scandb.hlp", AD_F_ALL, (AW_CB)awt_gene_field_selection_list_scan_unknown_cb, (AW_CL)GLOBAL_gb_main, AWT_NDS_FILTER); |
---|
569 | aws->insert_menu_topic("gen_del_unused_fields", "Remove unused fields", "e", "scandb.hlp", AD_F_ALL, (AW_CB)awt_gene_field_selection_list_delete_unused_cb, (AW_CL)GLOBAL_gb_main, AWT_NDS_FILTER); |
---|
570 | aws->insert_menu_topic("gen_refresh_fields", "Refresh fields (both)", "f", "scandb.hlp", AD_F_ALL, (AW_CB)awt_gene_field_selection_list_update_cb, (AW_CL)GLOBAL_gb_main, AWT_NDS_FILTER); |
---|
571 | } |
---|
572 | |
---|
573 | AW_window *GEN_create_gene_window(AW_root *aw_root) { |
---|
574 | static AW_window_simple_menu *aws = 0; |
---|
575 | if (!aws) { |
---|
576 | |
---|
577 | aws = new AW_window_simple_menu; |
---|
578 | aws->init( aw_root, "GENE_INFORMATION", "GENE INFORMATION"); |
---|
579 | aws->load_xfig("ad_spec.fig"); |
---|
580 | |
---|
581 | aws->button_length(8); |
---|
582 | |
---|
583 | aws->at("close"); |
---|
584 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
585 | aws->create_button("CLOSE","CLOSE","C"); |
---|
586 | |
---|
587 | aws->at("search"); |
---|
588 | aws->callback(AW_POPUP, (AW_CL)GEN_create_gene_query_window, 0); |
---|
589 | aws->create_button("SEARCH","SEARCH","S"); |
---|
590 | |
---|
591 | aws->at("help"); |
---|
592 | aws->callback(AW_POPUP_HELP, (AW_CL)"gene_info.hlp"); |
---|
593 | aws->create_button("HELP","HELP","H"); |
---|
594 | |
---|
595 | |
---|
596 | AW_CL scannerid = awt_create_arbdb_scanner(GLOBAL_gb_main, aws, "box",0,"field","enable",AWT_VIEWER,0,"mark",AWT_NDS_FILTER, &GEN_item_selector); |
---|
597 | ad_global_scannerid = scannerid; |
---|
598 | ad_global_scannerroot = aws->get_root(); |
---|
599 | |
---|
600 | aws->create_menu("GENE", "G", "spa_gene.hlp", AD_F_ALL ); |
---|
601 | aws->insert_menu_topic("gene_delete", "Delete", "D","spa_delete.hlp", AD_F_ALL, (AW_CB)gene_delete_cb, 0, 0); |
---|
602 | aws->insert_menu_topic("gene_rename", "Rename ...", "R","spa_rename.hlp", AD_F_ALL, AW_POPUP, (AW_CL)create_gene_rename_window, 0); |
---|
603 | aws->insert_menu_topic("gene_copy", "Copy ...", "y","spa_copy.hlp", AD_F_ALL, AW_POPUP, (AW_CL)create_gene_copy_window, 0); |
---|
604 | aws->insert_menu_topic("gene_create", "Create ...", "C","spa_create.hlp", AD_F_ALL, AW_POPUP, (AW_CL)create_gene_create_window, 0); |
---|
605 | aws->insert_separator(); |
---|
606 | |
---|
607 | aws->create_menu("FIELDS", "F", "gene_fields.hlp", AD_F_ALL ); |
---|
608 | GEN_create_field_items(aws); |
---|
609 | |
---|
610 | { |
---|
611 | Awar_Callback_Info *cb_info = new Awar_Callback_Info(aws->get_root(), AWAR_GENE_NAME, GEN_map_gene, scannerid); // do not delete! |
---|
612 | AW_detach_information *detach_info = new AW_detach_information(cb_info); // do not delete! |
---|
613 | |
---|
614 | cb_info->add_callback(); |
---|
615 | |
---|
616 | aws->at("detach"); |
---|
617 | aws->callback(NT_detach_information_window, (AW_CL)&aws, (AW_CL)detach_info); |
---|
618 | aws->create_button("DETACH", "DETACH", "D"); |
---|
619 | |
---|
620 | detach_info->set_detach_button(aws->get_last_widget()); |
---|
621 | } |
---|
622 | |
---|
623 | // aws->get_root()->awar(AWAR_GENE_NAME)->add_callback(GEN_map_gene,scannerid); |
---|
624 | GEN_map_gene(aws->get_root(),scannerid); |
---|
625 | aws->show(); |
---|
626 | } |
---|
627 | else { |
---|
628 | aws->show(); |
---|
629 | } |
---|
630 | |
---|
631 | return aws; |
---|
632 | } |
---|
633 | |
---|
634 | void GEN_popup_gene_window(AW_window *aww, AW_CL, AW_CL) { // w/o this DETACH does not work |
---|
635 | AW_window *aws = GEN_create_gene_window(aww->get_root()); |
---|
636 | aws->activate(); |
---|
637 | } |
---|
638 | |
---|
639 | AW_window *GEN_create_gene_query_window(AW_root *aw_root) { |
---|
640 | |
---|
641 | static AW_window_simple_menu *aws = 0; |
---|
642 | if (aws){ |
---|
643 | return (AW_window *)aws; |
---|
644 | } |
---|
645 | aws = new AW_window_simple_menu; |
---|
646 | aws->init( aw_root, "GEN_QUERY", "Gene SEARCH and QUERY"); |
---|
647 | aws->create_menu("More functions","f"); |
---|
648 | aws->load_xfig("ad_query.fig"); |
---|
649 | |
---|
650 | awt_query_struct awtqs; |
---|
651 | |
---|
652 | awtqs.gb_main = GLOBAL_gb_main; |
---|
653 | awtqs.species_name = AWAR_SPECIES_NAME; |
---|
654 | awtqs.tree_name = AWAR_TREE; |
---|
655 | // awtqs.query_genes = true; |
---|
656 | // awtqs.gene_name = AWAR_GENE_NAME; |
---|
657 | awtqs.select_bit = 1; |
---|
658 | awtqs.use_menu = 1; |
---|
659 | awtqs.ere_pos_fig = "ere3"; |
---|
660 | awtqs.where_pos_fig = "where3"; |
---|
661 | awtqs.by_pos_fig = "by3"; |
---|
662 | awtqs.qbox_pos_fig = "qbox"; |
---|
663 | awtqs.rescan_pos_fig = 0; |
---|
664 | awtqs.key_pos_fig = 0; |
---|
665 | awtqs.query_pos_fig = "content"; |
---|
666 | awtqs.result_pos_fig = "result"; |
---|
667 | awtqs.count_pos_fig = "count"; |
---|
668 | awtqs.do_query_pos_fig = "doquery"; |
---|
669 | awtqs.config_pos_fig = "doconfig"; |
---|
670 | awtqs.do_mark_pos_fig = "domark"; |
---|
671 | awtqs.do_unmark_pos_fig = "dounmark"; |
---|
672 | awtqs.do_delete_pos_fig = "dodelete"; |
---|
673 | awtqs.do_set_pos_fig = "doset"; |
---|
674 | awtqs.do_refresh_pos_fig = "dorefresh"; |
---|
675 | awtqs.open_parser_pos_fig = "openparser"; |
---|
676 | awtqs.create_view_window = (AW_CL)GEN_create_gene_window; |
---|
677 | awtqs.selector = &GEN_item_selector; |
---|
678 | |
---|
679 | AW_CL cbs = (AW_CL)awt_create_query_box(aws, &awtqs, "gen"); |
---|
680 | gene_query_global_cbs = cbs; |
---|
681 | |
---|
682 | aws->create_menu("More search", "s" ); |
---|
683 | aws->insert_menu_topic("gen_search_equal_fields_within_db", "Search For Equal Fields and Mark Duplicates", "E", "search_duplicates.hlp", AWM_ALL, (AW_CB)awt_search_equal_entries, cbs, 0); |
---|
684 | 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, (AW_CB)awt_search_equal_entries, cbs, 1); |
---|
685 | |
---|
686 | aws->button_length(7); |
---|
687 | |
---|
688 | aws->at("close"); |
---|
689 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
690 | aws->create_button("CLOSE","CLOSE","C"); |
---|
691 | aws->at("help"); |
---|
692 | aws->callback( AW_POPUP_HELP,(AW_CL)"gene_search.hlp"); |
---|
693 | aws->create_button("HELP","HELP","H"); |
---|
694 | |
---|
695 | return (AW_window *)aws; |
---|
696 | |
---|
697 | } |
---|
698 | |
---|
699 | |
---|