1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : GEN_map.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in 2001 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include "GEN_local.hxx" |
---|
13 | #include "GEN_gene.hxx" |
---|
14 | #include "GEN_graphic.hxx" |
---|
15 | #include "GEN_nds.hxx" |
---|
16 | #include "EXP_local.hxx" |
---|
17 | |
---|
18 | #include <dbui.h> |
---|
19 | #include <db_query.h> |
---|
20 | |
---|
21 | #include <awt.hxx> |
---|
22 | #include <awt_prompt.hxx> |
---|
23 | #include <awt_input_mask.hxx> |
---|
24 | |
---|
25 | #include <aw_preset.hxx> |
---|
26 | #include <aw_awars.hxx> |
---|
27 | #include <aw_question.hxx> |
---|
28 | #include <AW_rename.hxx> |
---|
29 | #include <aw_msg.hxx> |
---|
30 | #include <aw_root.hxx> |
---|
31 | |
---|
32 | #include <adGene.h> |
---|
33 | #include <ad_cb.h> |
---|
34 | |
---|
35 | #include <arb_progress.h> |
---|
36 | #include <rootAsWin.h> |
---|
37 | #include <mode_text.h> |
---|
38 | |
---|
39 | #include <map> |
---|
40 | |
---|
41 | using namespace std; |
---|
42 | |
---|
43 | extern GBDATA *GLOBAL_gb_main; |
---|
44 | |
---|
45 | // ----------------------- |
---|
46 | // GEN_map_window |
---|
47 | |
---|
48 | class GEN_map_window : public AW_window_menu_modes { // derived from a Noncopyable |
---|
49 | int window_nr; |
---|
50 | GEN_graphic *gen_graphic; |
---|
51 | AWT_canvas *gen_canvas; |
---|
52 | |
---|
53 | public: |
---|
54 | GEN_map_window(int window_nr_) : |
---|
55 | AW_window_menu_modes(), |
---|
56 | window_nr(window_nr_), |
---|
57 | gen_graphic(NULp), |
---|
58 | gen_canvas(NULp) |
---|
59 | {} |
---|
60 | |
---|
61 | void init(AW_root *root, GBDATA *gb_main); |
---|
62 | |
---|
63 | GEN_graphic *get_graphic() const { gen_assert(gen_graphic); return gen_graphic; } |
---|
64 | AWT_canvas *get_canvas() const { gen_assert(gen_canvas); return gen_canvas; } |
---|
65 | int get_nr() const { return window_nr; } |
---|
66 | |
---|
67 | GBDATA *get_gb_main() const { return get_canvas()->gb_main; } |
---|
68 | }; |
---|
69 | |
---|
70 | // ------------------------ |
---|
71 | // GEN_map_manager |
---|
72 | |
---|
73 | DECLARE_CBTYPE_FVV_AND_BUILDERS(GenmapWindowCallback, void, GEN_map_window*); // generates makeGenmapWindowCallback |
---|
74 | |
---|
75 | class GEN_map_manager : virtual Noncopyable { |
---|
76 | static AW_root *aw_root; |
---|
77 | static GBDATA *gb_main; |
---|
78 | static GEN_map_manager *the_manager; // there can be only one! |
---|
79 | |
---|
80 | int window_counter; |
---|
81 | GEN_map_window **windows; // array of managed windows |
---|
82 | int windows_size; // size of 'windows' array |
---|
83 | |
---|
84 | public: |
---|
85 | |
---|
86 | GEN_map_manager(); |
---|
87 | |
---|
88 | static bool initialized() { return aw_root; } |
---|
89 | static void initialize(AW_root *aw_root_, GBDATA *gb_main_) { aw_root = aw_root_; gb_main = gb_main_; } |
---|
90 | |
---|
91 | static GEN_map_manager *get_map_manager(); |
---|
92 | |
---|
93 | GEN_map_window *get_map_window(int nr); |
---|
94 | |
---|
95 | int no_of_managed_windows() { return window_counter; } |
---|
96 | |
---|
97 | static void with_all_mapped_windows(const GenmapWindowCallback& gwcb); |
---|
98 | static void with_all_mapped_windows(void (*cb)(GEN_map_window*)) { with_all_mapped_windows(makeGenmapWindowCallback(cb)); } |
---|
99 | }; |
---|
100 | |
---|
101 | // ____________________________________________________________ |
---|
102 | // start of implementation of class GEN_map_manager: |
---|
103 | |
---|
104 | AW_root *GEN_map_manager::aw_root = NULp; |
---|
105 | GBDATA *GEN_map_manager::gb_main = NULp; |
---|
106 | GEN_map_manager *GEN_map_manager::the_manager = NULp; |
---|
107 | |
---|
108 | GEN_map_manager::GEN_map_manager() : |
---|
109 | window_counter(0), |
---|
110 | windows(new GEN_map_window *[5]), |
---|
111 | windows_size(5) |
---|
112 | { |
---|
113 | gen_assert(!the_manager); // only one instance allowed |
---|
114 | the_manager = this; |
---|
115 | } |
---|
116 | |
---|
117 | GEN_map_manager *GEN_map_manager::get_map_manager() { |
---|
118 | if (!the_manager) { |
---|
119 | gen_assert(aw_root); // call initialize() before! |
---|
120 | new GEN_map_manager; // sets the manager |
---|
121 | gen_assert(the_manager); |
---|
122 | } |
---|
123 | return the_manager; |
---|
124 | } |
---|
125 | |
---|
126 | void GEN_map_manager::with_all_mapped_windows(const GenmapWindowCallback& gwcb) { |
---|
127 | if (aw_root) { // no genemap opened yet |
---|
128 | GEN_map_manager *mm = get_map_manager(); |
---|
129 | int winCount = mm->no_of_managed_windows(); |
---|
130 | for (int nr = 0; nr<winCount; ++nr) { |
---|
131 | gwcb(mm->get_map_window(nr)); |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | GEN_map_window *GEN_map_manager::get_map_window(int nr) { |
---|
137 | gen_assert(aw_root); |
---|
138 | gen_assert(nr >= 0); |
---|
139 | if (nr<window_counter) { |
---|
140 | return windows[nr]; // window has already been created before |
---|
141 | } |
---|
142 | |
---|
143 | gen_assert(nr == window_counter); // increase nr sequentially! |
---|
144 | |
---|
145 | window_counter++; |
---|
146 | if (window_counter>windows_size) { |
---|
147 | int new_windows_size = windows_size+5; |
---|
148 | GEN_map_window **new_windows = new GEN_map_window*[new_windows_size]; |
---|
149 | |
---|
150 | for (int i = 0; i<windows_size; ++i) new_windows[i] = windows[i]; |
---|
151 | |
---|
152 | delete [] windows; |
---|
153 | windows = new_windows; |
---|
154 | windows_size = new_windows_size; |
---|
155 | } |
---|
156 | |
---|
157 | gen_assert(nr<windows_size); |
---|
158 | |
---|
159 | windows[nr] = new GEN_map_window(nr); |
---|
160 | windows[nr]->init(aw_root, gb_main); |
---|
161 | |
---|
162 | return windows[nr]; |
---|
163 | } |
---|
164 | |
---|
165 | // -end- of implementation of class GEN_map_manager. |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | const char *GEN_window_local_awar_name(const char *awar_name, int window_nr) { |
---|
170 | return GBS_global_string("%s_%i", awar_name, window_nr); |
---|
171 | } |
---|
172 | |
---|
173 | static void reinit_NDS_4_window(GEN_map_window *win) { |
---|
174 | AWT_auto_refresh allowed_on(win->get_canvas()); |
---|
175 | win->get_graphic()->get_gen_root()->reinit_NDS(); |
---|
176 | win->get_canvas()->request_refresh(); |
---|
177 | } |
---|
178 | |
---|
179 | static void GEN_NDS_changed(GBDATA *gb_viewkey) { |
---|
180 | GBDATA *gb_main = GB_get_root(gb_viewkey); |
---|
181 | GEN_make_node_text_init(gb_main); |
---|
182 | GEN_map_manager::with_all_mapped_windows(reinit_NDS_4_window); |
---|
183 | } |
---|
184 | |
---|
185 | struct gene_container_changed_cb_data { |
---|
186 | AWT_canvas *canvas; |
---|
187 | GEN_graphic *graphic; |
---|
188 | GBDATA *gb_gene_data; // callback was installed for this gene_data |
---|
189 | |
---|
190 | gene_container_changed_cb_data() : canvas(NULp), graphic(NULp), gb_gene_data(NULp) {} |
---|
191 | gene_container_changed_cb_data(AWT_canvas *canvas_, GEN_graphic *graphic_, GBDATA *gb_gene_data_) : |
---|
192 | canvas(canvas_), |
---|
193 | graphic(graphic_), |
---|
194 | gb_gene_data(gb_gene_data_) |
---|
195 | {} |
---|
196 | }; |
---|
197 | |
---|
198 | static void GEN_gene_container_changed_cb(GBDATA*, gene_container_changed_cb_data *cb_data) { |
---|
199 | AWT_auto_refresh allowed_on(cb_data->canvas); |
---|
200 | cb_data->graphic->reinit_gen_root(cb_data->canvas, true); |
---|
201 | cb_data->canvas->request_refresh(); |
---|
202 | } |
---|
203 | |
---|
204 | int GEN_find_windowNr_for(GEN_graphic *wanted_graphic) { |
---|
205 | // returns window_nr of GEN_map_window using 'wanted_graphic' (or -1) |
---|
206 | if (GEN_map_manager::initialized()) { |
---|
207 | GEN_map_manager *mapman = GEN_map_manager::get_map_manager(); |
---|
208 | for (int window_nr = 0; window_nr<mapman->no_of_managed_windows(); ++window_nr) { |
---|
209 | GEN_map_window *mapwin = mapman->get_map_window(window_nr); |
---|
210 | if (mapwin && mapwin->get_graphic() == wanted_graphic) { |
---|
211 | return window_nr; |
---|
212 | } |
---|
213 | } |
---|
214 | } |
---|
215 | return -1; |
---|
216 | } |
---|
217 | |
---|
218 | inline GBDATA *GEN_get_local_gene_data(GEN_graphic *gg) { |
---|
219 | int window_nr = GEN_find_windowNr_for(gg); |
---|
220 | gen_assert(window_nr>=0); |
---|
221 | |
---|
222 | GBDATA *gb_gene_data = NULp; |
---|
223 | if (window_nr>=0) { |
---|
224 | const char *organism = gg->get_aw_root()->awar(AWAR_LOCAL_ORGANISM_NAME(window_nr))->read_char_pntr(); |
---|
225 | if (organism) { |
---|
226 | GBDATA *gb_main = gg->get_gb_main(); |
---|
227 | GBDATA *gb_species = GBT_find_species(gb_main, organism); |
---|
228 | if (gb_species) gb_gene_data = GEN_expect_gene_data(gb_species); |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | return gb_gene_data; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | static void GEN_gene_container_cb_installer(CbInstallMode install, AWT_canvas *gmw, GEN_graphic *gg) { |
---|
237 | typedef map<GEN_graphic*, gene_container_changed_cb_data> callback_dict; |
---|
238 | static callback_dict installed_callbacks; |
---|
239 | |
---|
240 | callback_dict::iterator found = installed_callbacks.find(gg); |
---|
241 | if (found == installed_callbacks.end()) { |
---|
242 | gen_assert(install == INSTALL_CBS); // if not installing -> entry has to exist! |
---|
243 | installed_callbacks[gg] = gene_container_changed_cb_data(gmw, gg, NULp); |
---|
244 | found = installed_callbacks.find(gg); |
---|
245 | gen_assert(found != installed_callbacks.end()); |
---|
246 | } |
---|
247 | |
---|
248 | gene_container_changed_cb_data *curr_cb_data = &(found->second); |
---|
249 | |
---|
250 | switch (install) { |
---|
251 | case INSTALL_CBS: { |
---|
252 | gen_assert(!curr_cb_data->gb_gene_data); // NULp means : no callback installed |
---|
253 | |
---|
254 | GBDATA *gb_main = gg->get_gb_main(); |
---|
255 | GB_transaction ta(gb_main); |
---|
256 | |
---|
257 | curr_cb_data->gb_gene_data = GEN_get_local_gene_data(gg); |
---|
258 | |
---|
259 | if (curr_cb_data->gb_gene_data) { |
---|
260 | GB_add_callback(curr_cb_data->gb_gene_data, GB_CB_CHANGED_OR_DELETED, makeDatabaseCallback(GEN_gene_container_changed_cb, curr_cb_data)); |
---|
261 | } |
---|
262 | break; |
---|
263 | } |
---|
264 | case REMOVE_CBS: { |
---|
265 | if (curr_cb_data->gb_gene_data) { // if callback is installed |
---|
266 | GB_remove_callback(curr_cb_data->gb_gene_data, GB_CB_CHANGED_OR_DELETED, makeDatabaseCallback(GEN_gene_container_changed_cb, curr_cb_data)); |
---|
267 | curr_cb_data->gb_gene_data = NULp; |
---|
268 | } |
---|
269 | break; |
---|
270 | } |
---|
271 | case FORGET_CBS: { |
---|
272 | curr_cb_data->gb_gene_data = NULp; |
---|
273 | break; |
---|
274 | } |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | static void GEN_jump_cb(AW_window *aww, bool force_center_if_fits) { |
---|
279 | // force_center_if_fits==true => center gene if it fits into display |
---|
280 | GEN_map_window *win = DOWNCAST(GEN_map_window*, aww); |
---|
281 | |
---|
282 | AW_device *device = win->get_graphic()->get_device(); |
---|
283 | const AW_screen_area& screen = device->get_area_size(); |
---|
284 | #if defined(DEBUG) |
---|
285 | printf("Window %i: screen is: %i/%i -> %i/%i\n", win->get_nr(), screen.l, screen.t, screen.r, screen.b); |
---|
286 | #endif // DEBUG |
---|
287 | |
---|
288 | AWT_canvas *canvas = win->get_canvas(); |
---|
289 | AWT_auto_refresh allowed_on(canvas); |
---|
290 | const GEN_root *gen_root = win->get_graphic()->get_gen_root(); |
---|
291 | if (gen_root) { |
---|
292 | const AW::Rectangle& wrange = gen_root->get_selected_range(); |
---|
293 | |
---|
294 | if (wrange.valid()) { |
---|
295 | #if defined(DEBUG) |
---|
296 | printf("Window %i: Draw world range of selected gene is: %f/%f -> %f/%f\n", |
---|
297 | win->get_nr(), wrange.left(), wrange.top(), wrange.right(), wrange.bottom()); |
---|
298 | #endif // DEBUG |
---|
299 | |
---|
300 | AW::Rectangle srange = device->transform(wrange); |
---|
301 | #if defined(DEBUG) |
---|
302 | printf("Window %i: Draw screen range of selected gene is: %f/%f -> %f/%f\n", |
---|
303 | win->get_nr(), srange.left(), srange.top(), srange.right(), srange.bottom()); |
---|
304 | #endif // DEBUG |
---|
305 | |
---|
306 | int scrollx = 0; |
---|
307 | int scrolly = 0; |
---|
308 | |
---|
309 | if (srange.top() < 0) { |
---|
310 | scrolly = AW_INT(srange.top())-2; |
---|
311 | } |
---|
312 | else if (srange.bottom() > screen.b) { |
---|
313 | scrolly = AW_INT(srange.bottom())-screen.b+2; |
---|
314 | } |
---|
315 | if (srange.left() < 0) { |
---|
316 | scrollx = AW_INT(srange.left())-2; |
---|
317 | } |
---|
318 | else if (srange.right() > screen.r) { |
---|
319 | scrollx = AW_INT(srange.right())-screen.r+2; |
---|
320 | } |
---|
321 | |
---|
322 | if (force_center_if_fits) { |
---|
323 | if (!scrollx) { // no scrolling needed, i.e. gene fits onto display horizontally |
---|
324 | int gene_center_x = AW_INT((srange.left()+srange.right())/2); |
---|
325 | int screen_center_x = (screen.l+screen.r)/2; |
---|
326 | scrollx = gene_center_x-screen_center_x; |
---|
327 | #if defined(DEBUG) |
---|
328 | printf("center x\n"); |
---|
329 | #endif // DEBUG |
---|
330 | } |
---|
331 | if (!scrolly) { // no scrolling needed, i.e. gene fits onto display vertically |
---|
332 | int gene_center_y = AW_INT((srange.top()+srange.bottom())/2); |
---|
333 | int screen_center_y = (screen.t+screen.b)/2; |
---|
334 | scrolly = gene_center_y-screen_center_y; |
---|
335 | #if defined(DEBUG) |
---|
336 | printf("center y\n"); |
---|
337 | #endif // DEBUG |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | #if defined(DEBUG) |
---|
342 | printf("scroll %i/%i\n", scrollx, scrolly); |
---|
343 | #endif // DEBUG |
---|
344 | |
---|
345 | canvas->scroll(scrollx, scrolly); |
---|
346 | } |
---|
347 | } |
---|
348 | canvas->request_refresh(); |
---|
349 | } |
---|
350 | |
---|
351 | static void GEN_jump_cb_auto(AW_root *root, GEN_map_window *win, bool force_refresh, bool force_zoom_reset) { |
---|
352 | AWT_canvas *ntw = win->get_canvas(); |
---|
353 | assert_no_auto_refresh_for(ntw); // otherwise jump doesn't work! |
---|
354 | |
---|
355 | int jump = root->awar(AWAR_GENMAP_AUTO_JUMP)->read_int(); |
---|
356 | if (jump || force_refresh || force_zoom_reset) { |
---|
357 | AWT_auto_refresh allowed_on(ntw); |
---|
358 | if (force_zoom_reset) ntw->request_zoom_reset(); |
---|
359 | ntw->request_refresh(); |
---|
360 | } |
---|
361 | if (jump) { |
---|
362 | GEN_jump_cb(win, false); |
---|
363 | } |
---|
364 | } |
---|
365 | |
---|
366 | static void GEN_local_organism_or_gene_name_changed_cb(AW_root *awr, GEN_map_window *win) { |
---|
367 | { |
---|
368 | AWT_auto_refresh allowed_on(win->get_canvas()); |
---|
369 | win->get_graphic()->reinit_gen_root(win->get_canvas(), false); |
---|
370 | } |
---|
371 | GEN_jump_cb_auto(awr, win, true, false); |
---|
372 | } |
---|
373 | |
---|
374 | #define DISPLAY_TYPE_BIT(disp_type) (1<<(disp_type)) |
---|
375 | #define ALL_DISPLAY_TYPES (DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLES)-1) |
---|
376 | |
---|
377 | static void GEN_map_window_refresh(GEN_map_window *win) { |
---|
378 | AWT_auto_refresh allowed_on(win->get_canvas()); |
---|
379 | win->get_canvas()->request_refresh(); |
---|
380 | } |
---|
381 | void GEN_refresh_all_windows() { |
---|
382 | GEN_map_manager::with_all_mapped_windows(GEN_map_window_refresh); |
---|
383 | } |
---|
384 | |
---|
385 | static void GEN_map_window_refresh_if_display_type(GEN_map_window *win, bool zoom_reset, int display_type_mask) { |
---|
386 | int my_display_type = win->get_graphic()->get_display_style(); |
---|
387 | if (display_type_mask & DISPLAY_TYPE_BIT(my_display_type)) { |
---|
388 | if (zoom_reset) { |
---|
389 | GEN_jump_cb_auto(AW_root::SINGLETON, win, true, true); |
---|
390 | } |
---|
391 | else { |
---|
392 | GEN_map_window_refresh(win); |
---|
393 | } |
---|
394 | } |
---|
395 | } |
---|
396 | |
---|
397 | static void GEN_update_unlocked_organism_and_gene_awars(GEN_map_window *win, const char *organismName, const char *geneName) { |
---|
398 | AW_root *aw_root = win->get_graphic()->get_aw_root(); |
---|
399 | int window_nr = win->get_nr(); |
---|
400 | if (!aw_root->awar(AWAR_LOCAL_ORGANISM_LOCK(window_nr))->read_int()) { |
---|
401 | aw_root->awar(AWAR_LOCAL_ORGANISM_NAME(window_nr))->write_string(organismName); |
---|
402 | } |
---|
403 | if (!aw_root->awar(AWAR_LOCAL_GENE_LOCK(window_nr))->read_int()) { |
---|
404 | aw_root->awar(AWAR_LOCAL_GENE_NAME(window_nr))->write_string(geneName); |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | static void GEN_organism_or_gene_changed_cb(AW_root *awr) { |
---|
409 | char *organism = awr->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
410 | char *gene = awr->awar(AWAR_GENE_NAME)->read_string(); |
---|
411 | |
---|
412 | GEN_map_manager::with_all_mapped_windows(makeGenmapWindowCallback(GEN_update_unlocked_organism_and_gene_awars, organism, gene)); |
---|
413 | |
---|
414 | free(gene); |
---|
415 | free(organism); |
---|
416 | } |
---|
417 | |
---|
418 | |
---|
419 | static void GEN_local_lock_changed_cb(AW_root *awr, GEN_map_window *win, bool gene_lock) { |
---|
420 | int window_nr = win->get_nr(); |
---|
421 | |
---|
422 | const char *local_awar_name = NULp; |
---|
423 | const char *local_lock_awar_name = NULp; |
---|
424 | const char *global_awar_name = NULp; |
---|
425 | |
---|
426 | if (gene_lock) { |
---|
427 | local_awar_name = AWAR_LOCAL_GENE_NAME(window_nr); |
---|
428 | local_lock_awar_name = AWAR_LOCAL_GENE_LOCK(window_nr); |
---|
429 | global_awar_name = AWAR_GENE_NAME; |
---|
430 | } |
---|
431 | else { // otherwise organism |
---|
432 | local_awar_name = AWAR_LOCAL_ORGANISM_NAME(window_nr); |
---|
433 | local_lock_awar_name = AWAR_LOCAL_ORGANISM_LOCK(window_nr); |
---|
434 | global_awar_name = AWAR_ORGANISM_NAME; |
---|
435 | } |
---|
436 | |
---|
437 | AW_awar *local_awar = awr->awar(local_awar_name); |
---|
438 | AW_awar *global_awar = awr->awar(global_awar_name); |
---|
439 | |
---|
440 | int lock_value = awr->awar(local_lock_awar_name)->read_int(); |
---|
441 | if (lock_value == 0) { // lock has been removed -> map to global awar |
---|
442 | local_awar->map(global_awar); |
---|
443 | } |
---|
444 | else { // lock has been installed -> unmap from global awar |
---|
445 | local_awar->unmap(); |
---|
446 | char *content = global_awar->read_string(); |
---|
447 | local_awar->write_string(content); |
---|
448 | free(content); |
---|
449 | } |
---|
450 | } |
---|
451 | |
---|
452 | // ------------------------------------- |
---|
453 | // display parameter change cb |
---|
454 | |
---|
455 | static void GEN_display_param_changed_cb(AW_root*, bool zoom_reset, int display_type_mask) { |
---|
456 | GEN_map_manager::with_all_mapped_windows(makeGenmapWindowCallback(GEN_map_window_refresh_if_display_type, zoom_reset, display_type_mask)); |
---|
457 | } |
---|
458 | inline void set_display_update_callback(AW_root *awr, const char *awar_name, bool zoom_reset, int display_type_mask) { |
---|
459 | awr->awar(awar_name)->add_callback(makeRootCallback(GEN_display_param_changed_cb, zoom_reset, display_type_mask)); |
---|
460 | } |
---|
461 | |
---|
462 | // -------------------------- |
---|
463 | // View-local AWARS |
---|
464 | |
---|
465 | static void GEN_create_genemap_local_awars(AW_root *aw_root, AW_default /* def */, int window_nr) { |
---|
466 | // awars local to each view |
---|
467 | |
---|
468 | aw_root->awar_int(AWAR_GENMAP_DISPLAY_TYPE(window_nr), GEN_DISPLAY_STYLE_RADIAL); // @@@ FIXME: make local |
---|
469 | |
---|
470 | aw_root->awar_string(AWAR_LOCAL_ORGANISM_NAME(window_nr), ""); |
---|
471 | aw_root->awar_string(AWAR_LOCAL_GENE_NAME(window_nr), ""); |
---|
472 | |
---|
473 | aw_root->awar_int(AWAR_LOCAL_ORGANISM_LOCK(window_nr), 0); |
---|
474 | aw_root->awar_int(AWAR_LOCAL_GENE_LOCK(window_nr), 0); |
---|
475 | } |
---|
476 | |
---|
477 | static void GEN_add_local_awar_callbacks(AW_root *awr, AW_default /* def */, GEN_map_window *win) { |
---|
478 | int window_nr = win->get_nr(); |
---|
479 | |
---|
480 | RootCallback nameChangedCb = makeRootCallback(GEN_local_organism_or_gene_name_changed_cb, win); |
---|
481 | awr->awar(AWAR_LOCAL_ORGANISM_NAME(window_nr))->add_callback(nameChangedCb); |
---|
482 | awr->awar(AWAR_LOCAL_GENE_NAME(window_nr)) ->add_callback(nameChangedCb); |
---|
483 | |
---|
484 | AW_awar *awar_lock_orga = awr->awar(AWAR_LOCAL_ORGANISM_LOCK(window_nr)); |
---|
485 | AW_awar *awar_lock_gene = awr->awar(AWAR_LOCAL_GENE_LOCK(window_nr)); |
---|
486 | |
---|
487 | awar_lock_orga->add_callback(makeRootCallback(GEN_local_lock_changed_cb, win, false)); |
---|
488 | awar_lock_gene->add_callback(makeRootCallback(GEN_local_lock_changed_cb, win, true)); |
---|
489 | |
---|
490 | awar_lock_orga->touch(); |
---|
491 | awar_lock_gene->touch(); |
---|
492 | } |
---|
493 | |
---|
494 | // ---------------------- |
---|
495 | // global AWARS |
---|
496 | |
---|
497 | static void GEN_create_genemap_global_awars(AW_root *aw_root, AW_default def, GBDATA *gb_main) { |
---|
498 | // layout options: |
---|
499 | |
---|
500 | aw_root->awar_int(AWAR_GENMAP_ARROW_SIZE, 150)->set_minmax(0, 500); |
---|
501 | aw_root->awar_int(AWAR_GENMAP_SHOW_HIDDEN, 0); |
---|
502 | aw_root->awar_int(AWAR_GENMAP_SHOW_ALL_NDS, 0); |
---|
503 | |
---|
504 | aw_root->awar_int(AWAR_GENMAP_BOOK_BASES_PER_LINE, 15000)->set_minmax(1, 100000); |
---|
505 | aw_root->awar_float(AWAR_GENMAP_BOOK_WIDTH_FACTOR, 0.1)->set_minmax(0, 1); |
---|
506 | aw_root->awar_int(AWAR_GENMAP_BOOK_LINE_HEIGHT, 20)->set_minmax(0, 100); |
---|
507 | aw_root->awar_int(AWAR_GENMAP_BOOK_LINE_SPACE, 5)->set_minmax(-20, 20); |
---|
508 | |
---|
509 | aw_root->awar_float(AWAR_GENMAP_VERTICAL_FACTOR_X, 1.0)->set_minmax(0, 10); |
---|
510 | aw_root->awar_float(AWAR_GENMAP_VERTICAL_FACTOR_Y, 0.3)->set_minmax(0, 10); |
---|
511 | |
---|
512 | aw_root->awar_float(AWAR_GENMAP_RADIAL_INSIDE, 50)->set_minmax(0, 100); |
---|
513 | aw_root->awar_float(AWAR_GENMAP_RADIAL_OUTSIDE, 4)->set_minmax(0, 100); |
---|
514 | |
---|
515 | // other options: |
---|
516 | |
---|
517 | aw_root->awar_int(AWAR_GENMAP_AUTO_JUMP, 1); |
---|
518 | |
---|
519 | GEN_create_nds_vars(aw_root, def, gb_main, makeDatabaseCallback(GEN_NDS_changed)); |
---|
520 | } |
---|
521 | |
---|
522 | static void GEN_add_global_awar_callbacks(AW_root *awr) { |
---|
523 | enum { REFRESH_ONLY = 0, ZOOM_RESET = 1 }; |
---|
524 | |
---|
525 | set_display_update_callback(awr, AWAR_GENMAP_ARROW_SIZE, REFRESH_ONLY, ALL_DISPLAY_TYPES^DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_BOOK)); |
---|
526 | set_display_update_callback(awr, AWAR_GENMAP_SHOW_HIDDEN, REFRESH_ONLY, ALL_DISPLAY_TYPES); |
---|
527 | set_display_update_callback(awr, AWAR_GENMAP_SHOW_ALL_NDS, REFRESH_ONLY, ALL_DISPLAY_TYPES); |
---|
528 | |
---|
529 | set_display_update_callback(awr, AWAR_GENMAP_BOOK_BASES_PER_LINE, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_BOOK)); |
---|
530 | set_display_update_callback(awr, AWAR_GENMAP_BOOK_WIDTH_FACTOR, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_BOOK)); |
---|
531 | set_display_update_callback(awr, AWAR_GENMAP_BOOK_LINE_HEIGHT, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_BOOK)); |
---|
532 | set_display_update_callback(awr, AWAR_GENMAP_BOOK_LINE_SPACE, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_BOOK)); |
---|
533 | |
---|
534 | set_display_update_callback(awr, AWAR_GENMAP_VERTICAL_FACTOR_X, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_VERTICAL)); |
---|
535 | set_display_update_callback(awr, AWAR_GENMAP_VERTICAL_FACTOR_Y, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_VERTICAL)); |
---|
536 | |
---|
537 | set_display_update_callback(awr, AWAR_GENMAP_RADIAL_INSIDE, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_RADIAL)); |
---|
538 | set_display_update_callback(awr, AWAR_GENMAP_RADIAL_OUTSIDE, ZOOM_RESET, DISPLAY_TYPE_BIT(GEN_DISPLAY_STYLE_RADIAL)); |
---|
539 | |
---|
540 | awr->awar(AWAR_ORGANISM_NAME)->add_callback(GEN_organism_or_gene_changed_cb); |
---|
541 | awr->awar(AWAR_GENE_NAME)->add_callback(GEN_organism_or_gene_changed_cb); |
---|
542 | } |
---|
543 | |
---|
544 | |
---|
545 | // -------------------------------------------------------------------------------- |
---|
546 | |
---|
547 | static void GEN_mode_event(AW_window *aws, GEN_map_window *win, AWT_COMMAND_MODE mode) { |
---|
548 | const char *text = NULp; |
---|
549 | switch (mode) { |
---|
550 | case AWT_MODE_SELECT: text = MODE_TEXT_1BUTTON("SELECT", "click to select a gene"); break; |
---|
551 | case AWT_MODE_INFO: text = MODE_TEXT_1BUTTON("INFO", "click for info"); break; |
---|
552 | |
---|
553 | case AWT_MODE_ZOOM: text = MODE_TEXT_STANDARD_ZOOMMODE(); break; |
---|
554 | |
---|
555 | default: text = no_mode_text_defined(); break; |
---|
556 | } |
---|
557 | |
---|
558 | gen_assert(strlen(text) < AWAR_FOOTER_MAX_LEN); // text too long! |
---|
559 | |
---|
560 | aws->get_root()->awar(AWAR_FOOTER)->write_string(text); |
---|
561 | |
---|
562 | AWT_canvas *canvas = win->get_canvas(); |
---|
563 | AWT_auto_refresh allowed_on(canvas); |
---|
564 | |
---|
565 | canvas->set_mode(mode); |
---|
566 | canvas->request_refresh(); |
---|
567 | } |
---|
568 | |
---|
569 | static void GEN_undo_cb(AW_window*, GB_UNDO_TYPE undo_type, GBDATA *gb_main) { |
---|
570 | GB_ERROR error = GB_undo(gb_main, undo_type); |
---|
571 | if (error) { |
---|
572 | aw_message(error); |
---|
573 | } |
---|
574 | else { |
---|
575 | GB_begin_transaction(gb_main); |
---|
576 | GB_commit_transaction(gb_main); |
---|
577 | } |
---|
578 | } |
---|
579 | |
---|
580 | static AW_window *GEN_create_options_window(AW_root *awr) { |
---|
581 | static AW_window_simple *aws = NULp; |
---|
582 | |
---|
583 | if (!aws) { |
---|
584 | aws = new AW_window_simple; |
---|
585 | |
---|
586 | aws->init(awr, "GEN_OPTS", "Genemap options"); |
---|
587 | aws->load_xfig("gen_options.fig"); |
---|
588 | |
---|
589 | aws->at("close"); |
---|
590 | aws->callback(AW_POPDOWN); |
---|
591 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
592 | |
---|
593 | aws->callback(makeHelpCallback("gen_options.hlp")); |
---|
594 | aws->at("help"); |
---|
595 | aws->create_button("HELP", "HELP", "H"); |
---|
596 | |
---|
597 | aws->auto_space(5, 5); |
---|
598 | aws->label_length(26); |
---|
599 | |
---|
600 | const int FIELDWIDTH = 12; |
---|
601 | const int SCALERWIDTH = 300; |
---|
602 | |
---|
603 | // all displays: |
---|
604 | aws->at("arrow_size"); aws->create_input_field_with_scaler(AWAR_GENMAP_ARROW_SIZE, FIELDWIDTH, SCALERWIDTH); |
---|
605 | |
---|
606 | aws->at("show_hidden"); |
---|
607 | aws->label("Show hidden genes"); |
---|
608 | aws->create_toggle(AWAR_GENMAP_SHOW_HIDDEN); |
---|
609 | |
---|
610 | aws->at("show_all"); |
---|
611 | aws->label("Show NDS for all genes"); |
---|
612 | aws->create_toggle(AWAR_GENMAP_SHOW_ALL_NDS); |
---|
613 | |
---|
614 | aws->at("autojump"); |
---|
615 | aws->label("Auto jump to selected gene"); |
---|
616 | aws->create_toggle(AWAR_GENMAP_AUTO_JUMP); |
---|
617 | |
---|
618 | // book-style: |
---|
619 | aws->at("base_pos"); aws->create_input_field_with_scaler(AWAR_GENMAP_BOOK_BASES_PER_LINE, FIELDWIDTH, SCALERWIDTH); |
---|
620 | aws->at("width_factor"); aws->create_input_field_with_scaler(AWAR_GENMAP_BOOK_WIDTH_FACTOR, FIELDWIDTH, SCALERWIDTH, AW_SCALER_EXP_LOWER); |
---|
621 | aws->at("line_height"); aws->create_input_field_with_scaler(AWAR_GENMAP_BOOK_LINE_HEIGHT, FIELDWIDTH, SCALERWIDTH, AW_SCALER_EXP_LOWER); |
---|
622 | aws->at("line_space"); aws->create_input_field_with_scaler(AWAR_GENMAP_BOOK_LINE_SPACE, FIELDWIDTH, SCALERWIDTH); |
---|
623 | |
---|
624 | // vertical-style: |
---|
625 | aws->at("factor_x"); aws->create_input_field_with_scaler(AWAR_GENMAP_VERTICAL_FACTOR_X, FIELDWIDTH, SCALERWIDTH, AW_SCALER_EXP_LOWER); |
---|
626 | aws->at("factor_y"); aws->create_input_field_with_scaler(AWAR_GENMAP_VERTICAL_FACTOR_Y, FIELDWIDTH, SCALERWIDTH, AW_SCALER_EXP_LOWER); |
---|
627 | |
---|
628 | // radial style: |
---|
629 | aws->at("inside"); aws->create_input_field_with_scaler(AWAR_GENMAP_RADIAL_INSIDE, FIELDWIDTH, SCALERWIDTH, AW_SCALER_EXP_LOWER); |
---|
630 | aws->at("outside"); aws->create_input_field_with_scaler(AWAR_GENMAP_RADIAL_OUTSIDE, FIELDWIDTH, SCALERWIDTH, AW_SCALER_EXP_LOWER); |
---|
631 | } |
---|
632 | return aws; |
---|
633 | } |
---|
634 | |
---|
635 | static AW_window *GEN_create_gc_window(AW_root *awr, AW_gc_manager *gcman) { |
---|
636 | // only create one gc window for all genemap views |
---|
637 | static AW_window *awgc = NULp; |
---|
638 | if (!awgc) awgc = AW_create_gc_window_named(awr, gcman, "GENMAP_COLOR_DEF", "Genemap colors and fonts"); // use named gc window (otherwise clashes with ARB_NTREE gc window) |
---|
639 | return awgc; |
---|
640 | } |
---|
641 | |
---|
642 | enum GEN_PERFORM_MODE { |
---|
643 | GEN_PERFORM_ALL_ORGANISMS, |
---|
644 | GEN_PERFORM_CURRENT_ORGANISM, |
---|
645 | GEN_PERFORM_ALL_BUT_CURRENT_ORGANISM, |
---|
646 | GEN_PERFORM_MARKED_ORGANISMS, |
---|
647 | |
---|
648 | GEN_PERFORM_MODES, // counter |
---|
649 | }; |
---|
650 | |
---|
651 | static const char *GEN_PERFORM_MODE_id[GEN_PERFORM_MODES] = { |
---|
652 | "org_all", |
---|
653 | "org_current", |
---|
654 | "org_butcur", |
---|
655 | "org_marked", |
---|
656 | }; |
---|
657 | |
---|
658 | inline string performmode_relative_id(const char *id, GEN_PERFORM_MODE pmode) { |
---|
659 | return GBS_global_string("%s_%s", GEN_PERFORM_MODE_id[pmode], id); |
---|
660 | } |
---|
661 | |
---|
662 | enum GEN_MARK_MODE { |
---|
663 | GEN_MARK, |
---|
664 | GEN_UNMARK, |
---|
665 | GEN_INVERT_MARKED, |
---|
666 | GEN_COUNT_MARKED, |
---|
667 | |
---|
668 | // GEN_MARK_COLORED, done by awt_colorize_marked now |
---|
669 | // GEN_UNMARK_COLORED, |
---|
670 | // GEN_INVERT_COLORED, |
---|
671 | // GEN_COLORIZE_MARKED, |
---|
672 | |
---|
673 | GEN_EXTRACT_MARKED, |
---|
674 | |
---|
675 | GEN_MARK_HIDDEN, |
---|
676 | GEN_MARK_VISIBLE, |
---|
677 | GEN_UNMARK_HIDDEN, |
---|
678 | GEN_UNMARK_VISIBLE |
---|
679 | }; |
---|
680 | |
---|
681 | enum GEN_HIDE_MODE { |
---|
682 | GEN_HIDE_ALL, |
---|
683 | GEN_UNHIDE_ALL, |
---|
684 | GEN_INVERT_HIDE_ALL, |
---|
685 | |
---|
686 | GEN_HIDE_MARKED, |
---|
687 | GEN_UNHIDE_MARKED, |
---|
688 | GEN_INVERT_HIDE_MARKED |
---|
689 | }; |
---|
690 | |
---|
691 | // -------------------------------------------------------------------------------- |
---|
692 | |
---|
693 | inline bool nameIsUnique(const char *short_name, GBDATA *gb_species_data) { |
---|
694 | return !GBT_find_species_rel_species_data(gb_species_data, short_name); |
---|
695 | } |
---|
696 | |
---|
697 | static GB_ERROR GEN_species_add_entry(GBDATA *gb_pseudo, const char *key, const char *value) { |
---|
698 | GB_ERROR error = NULp; |
---|
699 | GB_clear_error(); |
---|
700 | GBDATA *gbd = GB_entry(gb_pseudo, key); |
---|
701 | |
---|
702 | if (!gbd) { // key does not exist yet -> create |
---|
703 | gbd = GB_create(gb_pseudo, key, GB_STRING); |
---|
704 | if (!gbd) error = GB_await_error(); |
---|
705 | } |
---|
706 | else { // key exists |
---|
707 | if (GB_read_type(gbd) != GB_STRING) { // test correct key type |
---|
708 | error = GB_export_errorf("field '%s' exists and has wrong type", key); |
---|
709 | } |
---|
710 | } |
---|
711 | |
---|
712 | if (!error) error = GB_write_string(gbd, value); |
---|
713 | |
---|
714 | return error; |
---|
715 | } |
---|
716 | |
---|
717 | static AW_repeated_question *ask_about_existing_gene_species = NULp; |
---|
718 | static AW_repeated_question *ask_to_overwrite_alignment = NULp; |
---|
719 | |
---|
720 | struct EG2PS_data : virtual Noncopyable { |
---|
721 | arb_progress progress; |
---|
722 | GBDATA *gb_species_data; |
---|
723 | char *ali; |
---|
724 | UniqueNameDetector existing; |
---|
725 | GB_HASH *pseudo_hash; |
---|
726 | int duplicateSpecies; // counts created gene-species with identical ACC |
---|
727 | bool nameProblem; // nameserver and DB disagree about names |
---|
728 | |
---|
729 | EG2PS_data(const char *ali_, GBDATA *gb_species_data_, long marked_genes_) |
---|
730 | : progress(marked_genes_), |
---|
731 | gb_species_data(gb_species_data_), |
---|
732 | ali(ARB_strdup(ali_)), |
---|
733 | existing(gb_species_data, marked_genes_), |
---|
734 | duplicateSpecies(0), |
---|
735 | nameProblem(false) |
---|
736 | { |
---|
737 | pseudo_hash = GEN_create_pseudo_species_hash(GB_get_root(gb_species_data), marked_genes_); |
---|
738 | } |
---|
739 | |
---|
740 | ~EG2PS_data() { |
---|
741 | if (duplicateSpecies>0) { |
---|
742 | aw_message(GBS_global_string("There are %i duplicated gene-species (with identical sequence and accession number)\n" |
---|
743 | "Duplicated gene-species got names with numerical postfixes ('.1', '.2', ...)" |
---|
744 | , duplicateSpecies)); |
---|
745 | } |
---|
746 | if (nameProblem) { |
---|
747 | aw_message("Naming problems occurred.\nYou have to call 'Species/Synchronize IDs'!"); |
---|
748 | } |
---|
749 | GBS_free_hash(pseudo_hash); |
---|
750 | free(ali); |
---|
751 | } |
---|
752 | }; |
---|
753 | |
---|
754 | static const char* readACC(GBDATA *gb_species_data, const char *name) { |
---|
755 | const char *other_acc = NULp; |
---|
756 | GBDATA *gb_other_species = GBT_find_species_rel_species_data(gb_species_data, name); |
---|
757 | if (gb_other_species) { |
---|
758 | GBDATA *gb_other_acc = GB_entry(gb_other_species, "acc"); |
---|
759 | if (gb_other_acc) other_acc = GB_read_char_pntr(gb_other_acc); |
---|
760 | } |
---|
761 | return other_acc; |
---|
762 | } |
---|
763 | |
---|
764 | static void gen_extract_gene_2_pseudoSpecies(GBDATA *gb_species, GBDATA *gb_gene, EG2PS_data *eg2ps) { |
---|
765 | const char *gene_name = GBT_read_name(gb_gene); |
---|
766 | const char *species_name = GBT_read_name(gb_species); |
---|
767 | const char *full_species_name = GBT_read_char_pntr(gb_species, "full_name"); |
---|
768 | |
---|
769 | if (!full_species_name) full_species_name = species_name; |
---|
770 | |
---|
771 | char *full_name = GBS_global_string_copy("%s [%s]", full_species_name, gene_name); |
---|
772 | char *sequence = GBT_read_gene_sequence(gb_gene, true, 0); |
---|
773 | GB_ERROR error = NULp; |
---|
774 | |
---|
775 | if (!sequence) error = GB_await_error(); |
---|
776 | else { |
---|
777 | const char *ali = eg2ps->ali; |
---|
778 | long id = GBS_checksum(sequence, 1, ".-"); |
---|
779 | char acc[100]; |
---|
780 | |
---|
781 | sprintf(acc, "ARB_GENE_%lX", id); |
---|
782 | |
---|
783 | // test if this gene has been already extracted to a gene-species |
---|
784 | |
---|
785 | GBDATA *gb_main = GB_get_root(gb_species); |
---|
786 | GBDATA *gb_exist_geneSpec = GEN_find_pseudo_species(gb_main, species_name, gene_name, eg2ps->pseudo_hash); |
---|
787 | bool create_new_gene_species = true; |
---|
788 | char *short_name = NULp; |
---|
789 | |
---|
790 | if (gb_exist_geneSpec) { |
---|
791 | const char *existing_name = GBT_read_name(gb_exist_geneSpec); |
---|
792 | |
---|
793 | gen_assert(ask_about_existing_gene_species); |
---|
794 | gen_assert(ask_to_overwrite_alignment); |
---|
795 | |
---|
796 | char *question = GBS_global_string_copy("Already have a gene-species for %s/%s ('%s')", species_name, gene_name, existing_name); |
---|
797 | int answer = ask_about_existing_gene_species->get_answer("existing_pseudo_species", question, "Overwrite species,Insert new alignment,Skip,Create new", "all", true); |
---|
798 | |
---|
799 | create_new_gene_species = false; |
---|
800 | |
---|
801 | switch (answer) { |
---|
802 | case 0: { // Overwrite species |
---|
803 | // @@@ FIXME: delete species needed here |
---|
804 | create_new_gene_species = true; |
---|
805 | short_name = ARB_strdup(existing_name); |
---|
806 | break; |
---|
807 | } |
---|
808 | case 1: { // Insert new alignment or overwrite alignment |
---|
809 | GBDATA *gb_ali = GB_entry(gb_exist_geneSpec, ali); |
---|
810 | if (gb_ali) { // the alignment already exists |
---|
811 | char *question2 = GBS_global_string_copy("Gene-species '%s' already has data in '%s'", existing_name, ali); |
---|
812 | int overwrite_answer = ask_to_overwrite_alignment->get_answer("overwrite_gene_data", question2, "Overwrite data,Skip", "all", true); |
---|
813 | |
---|
814 | if (overwrite_answer == 1) error = GBS_global_string("Skipped gene-species '%s' (already had data in alignment)", existing_name); // Skip |
---|
815 | else if (overwrite_answer == 2) error = "Aborted."; // Abort |
---|
816 | // @@@ FIXME: overwrite data is missing |
---|
817 | |
---|
818 | free(question2); |
---|
819 | } |
---|
820 | break; |
---|
821 | } |
---|
822 | case 2: { // Skip existing ones |
---|
823 | error = GBS_global_string("Skipped gene-species '%s'", existing_name); |
---|
824 | break; |
---|
825 | } |
---|
826 | case 3: { // Create with new name |
---|
827 | create_new_gene_species = true; |
---|
828 | break; |
---|
829 | } |
---|
830 | case 4: { // Abort |
---|
831 | error = "Aborted."; |
---|
832 | break; |
---|
833 | } |
---|
834 | default: gen_assert(0); |
---|
835 | } |
---|
836 | free(question); |
---|
837 | } |
---|
838 | |
---|
839 | if (!error) { |
---|
840 | if (create_new_gene_species) { |
---|
841 | if (!short_name) { // create a new name |
---|
842 | error = AWTC_generate_one_name(gb_main, full_name, acc, NULp, short_name); |
---|
843 | if (!error) { // name has been created |
---|
844 | if (eg2ps->existing.name_known(short_name)) { // nameserver-generated name is already in use |
---|
845 | const char *other_acc = readACC(eg2ps->gb_species_data, short_name); |
---|
846 | if (other_acc) { |
---|
847 | if (strcmp(acc, other_acc) == 0) { // duplicate (gene-)species -> generate postfixed name |
---|
848 | char *newName = NULp; |
---|
849 | for (int postfix = 1; ; ++postfix) { |
---|
850 | newName = GBS_global_string_copy("%s.%i", short_name, postfix); |
---|
851 | if (!eg2ps->existing.name_known(newName)) { |
---|
852 | eg2ps->duplicateSpecies++; |
---|
853 | break; |
---|
854 | } |
---|
855 | |
---|
856 | other_acc = readACC(eg2ps->gb_species_data, newName); |
---|
857 | if (!other_acc || strcmp(acc, other_acc) != 0) { |
---|
858 | eg2ps->nameProblem = true; |
---|
859 | error = GBS_global_string("Unexpected acc-mismatch for '%s'", newName); |
---|
860 | break; |
---|
861 | } |
---|
862 | } |
---|
863 | |
---|
864 | if (!error) freeset(short_name, newName); |
---|
865 | else free(newName); |
---|
866 | } |
---|
867 | else { // different acc, but uses name generated by nameserver |
---|
868 | eg2ps->nameProblem = true; |
---|
869 | error = GBS_global_string("acc of '%s' differs from acc stored in nameserver", short_name); |
---|
870 | } |
---|
871 | } |
---|
872 | else { // can't detect acc of existing species |
---|
873 | eg2ps->nameProblem = true; |
---|
874 | error = GBS_global_string("can't detect acc of species '%s'", short_name); |
---|
875 | } |
---|
876 | } |
---|
877 | } |
---|
878 | if (error) { // try to make a random name |
---|
879 | const char *msg = GBS_global_string("%s\nGenerating a random name instead.", error); |
---|
880 | aw_message(msg); |
---|
881 | error = NULp; |
---|
882 | |
---|
883 | short_name = AWTC_generate_random_name(eg2ps->existing); |
---|
884 | if (!short_name) error = GBS_global_string("Failed to create a new name for pseudo gene-species '%s'", full_name); |
---|
885 | } |
---|
886 | } |
---|
887 | |
---|
888 | if (!error) { // create the species |
---|
889 | gen_assert(short_name); |
---|
890 | gb_exist_geneSpec = GBT_find_or_create_species(gb_main, short_name, true); |
---|
891 | if (!gb_exist_geneSpec) error = GB_export_errorf("Failed to create pseudo-species '%s'", short_name); |
---|
892 | else eg2ps->existing.add_name(short_name); |
---|
893 | } |
---|
894 | } |
---|
895 | else { |
---|
896 | gen_assert(gb_exist_geneSpec); // do not generate new or skip -> should only occur when gene-species already existed |
---|
897 | } |
---|
898 | |
---|
899 | if (!error) { // write sequence data |
---|
900 | GBDATA *gb_data = GBT_add_data(gb_exist_geneSpec, ali, "data", GB_STRING); |
---|
901 | if (!gb_data) error = GB_await_error(); |
---|
902 | else error = GB_write_string(gb_data, sequence); |
---|
903 | } |
---|
904 | |
---|
905 | // write other entries: |
---|
906 | if (!error) error = GEN_species_add_entry(gb_exist_geneSpec, "full_name", full_name); |
---|
907 | if (!error) error = GEN_species_add_entry(gb_exist_geneSpec, "ARB_origin_species", species_name); |
---|
908 | if (!error) error = GEN_species_add_entry(gb_exist_geneSpec, "ARB_origin_gene", gene_name); |
---|
909 | if (!error) GEN_add_pseudo_species_to_hash(gb_exist_geneSpec, eg2ps->pseudo_hash); |
---|
910 | if (!error) error = GEN_species_add_entry(gb_exist_geneSpec, "acc", acc); |
---|
911 | |
---|
912 | // copy codon_start and transl_table : |
---|
913 | const char *codon_start = NULp; |
---|
914 | const char *transl_table = NULp; |
---|
915 | { |
---|
916 | GBDATA *gb_codon_start = GB_entry(gb_gene, "codon_start"); |
---|
917 | GBDATA *gb_transl_table = GB_entry(gb_gene, "transl_table"); |
---|
918 | |
---|
919 | if (gb_codon_start) codon_start = GB_read_char_pntr(gb_codon_start); |
---|
920 | if (gb_transl_table) transl_table = GB_read_char_pntr(gb_transl_table); |
---|
921 | } |
---|
922 | |
---|
923 | if (!error && codon_start) error = GEN_species_add_entry(gb_exist_geneSpec, "codon_start", codon_start); |
---|
924 | if (!error && transl_table) error = GEN_species_add_entry(gb_exist_geneSpec, "transl_table", transl_table); |
---|
925 | } |
---|
926 | |
---|
927 | free(short_name); |
---|
928 | free(sequence); |
---|
929 | } |
---|
930 | if (error) aw_message(error); |
---|
931 | |
---|
932 | free(full_name); |
---|
933 | } |
---|
934 | |
---|
935 | static long gen_count_marked_genes = 0; // used to count marked genes |
---|
936 | |
---|
937 | static void do_mark_command_for_one_species(int imode, GBDATA *gb_species, AW_CL cl_user) { |
---|
938 | GEN_MARK_MODE mode = (GEN_MARK_MODE)imode; |
---|
939 | |
---|
940 | for (GBDATA *gb_gene = GEN_first_gene(gb_species); |
---|
941 | gb_gene; |
---|
942 | gb_gene = GEN_next_gene(gb_gene)) |
---|
943 | { |
---|
944 | bool mark_flag = GB_read_flag(gb_gene) != 0; |
---|
945 | bool org_mark_flag = mark_flag; |
---|
946 | |
---|
947 | switch (mode) { |
---|
948 | case GEN_MARK: mark_flag = 1; break; |
---|
949 | case GEN_UNMARK: mark_flag = 0; break; |
---|
950 | case GEN_INVERT_MARKED: mark_flag = !mark_flag; break; |
---|
951 | |
---|
952 | case GEN_COUNT_MARKED: { |
---|
953 | if (mark_flag) ++gen_count_marked_genes; |
---|
954 | break; |
---|
955 | } |
---|
956 | case GEN_EXTRACT_MARKED: { |
---|
957 | if (mark_flag) { |
---|
958 | EG2PS_data *eg2ps = (EG2PS_data*)cl_user; |
---|
959 | gen_extract_gene_2_pseudoSpecies(gb_species, gb_gene, eg2ps); |
---|
960 | eg2ps->progress.inc(); |
---|
961 | } |
---|
962 | break; |
---|
963 | } |
---|
964 | default: { |
---|
965 | GBDATA *gb_hidden = GB_entry(gb_gene, ARB_HIDDEN); |
---|
966 | bool hidden = gb_hidden ? GB_read_byte(gb_hidden) != 0 : false; |
---|
967 | |
---|
968 | switch (mode) { |
---|
969 | case GEN_MARK_HIDDEN: if (hidden) mark_flag = 1; break; |
---|
970 | case GEN_UNMARK_HIDDEN: if (hidden) mark_flag = 0; break; |
---|
971 | case GEN_MARK_VISIBLE: if (!hidden) mark_flag = 1; break; |
---|
972 | case GEN_UNMARK_VISIBLE: if (!hidden) mark_flag = 0; break; |
---|
973 | default: gen_assert(0); break; |
---|
974 | } |
---|
975 | } |
---|
976 | } |
---|
977 | |
---|
978 | if (mark_flag != org_mark_flag) GB_write_flag(gb_gene, mark_flag ? 1 : 0); |
---|
979 | } |
---|
980 | } |
---|
981 | |
---|
982 | static void do_hide_command_for_one_species(int imode, GBDATA *gb_species, AW_CL /* cl_user */) { |
---|
983 | GEN_HIDE_MODE mode = (GEN_HIDE_MODE)imode; |
---|
984 | |
---|
985 | for (GBDATA *gb_gene = GEN_first_gene(gb_species); |
---|
986 | gb_gene; |
---|
987 | gb_gene = GEN_next_gene(gb_gene)) |
---|
988 | { |
---|
989 | bool marked = GB_read_flag(gb_gene) != 0; |
---|
990 | |
---|
991 | GBDATA *gb_hidden = GB_entry(gb_gene, ARB_HIDDEN); |
---|
992 | bool hidden = gb_hidden ? (GB_read_byte(gb_hidden) != 0) : false; |
---|
993 | bool org_hidden = hidden; |
---|
994 | |
---|
995 | switch (mode) { |
---|
996 | case GEN_HIDE_ALL: hidden = true; break; |
---|
997 | case GEN_UNHIDE_ALL: hidden = false; break; |
---|
998 | case GEN_INVERT_HIDE_ALL: hidden = !hidden; break; |
---|
999 | case GEN_HIDE_MARKED: if (marked) hidden = true; break; |
---|
1000 | case GEN_UNHIDE_MARKED: if (marked) hidden = false; break; |
---|
1001 | case GEN_INVERT_HIDE_MARKED: if (marked) hidden = !hidden; break; |
---|
1002 | default: gen_assert(0); break; |
---|
1003 | } |
---|
1004 | |
---|
1005 | if (hidden != org_hidden) { |
---|
1006 | if (!gb_hidden) gb_hidden = GB_create(gb_gene, ARB_HIDDEN, GB_BYTE); |
---|
1007 | GB_write_byte(gb_hidden, hidden ? 1 : 0); // change gene visibility |
---|
1008 | } |
---|
1009 | } |
---|
1010 | } |
---|
1011 | |
---|
1012 | static void GEN_perform_command(GBDATA *gb_main, GEN_PERFORM_MODE pmode, |
---|
1013 | void (*do_command)(int cmode, GBDATA *gb_species, AW_CL cl_user), int mode, AW_CL cl_user) { |
---|
1014 | GB_ERROR error = NULp; |
---|
1015 | |
---|
1016 | GB_begin_transaction(gb_main); |
---|
1017 | |
---|
1018 | switch (pmode) { |
---|
1019 | case GEN_PERFORM_ALL_ORGANISMS: { |
---|
1020 | for (GBDATA *gb_organism = GEN_first_organism(gb_main); |
---|
1021 | gb_organism; |
---|
1022 | gb_organism = GEN_next_organism(gb_organism)) |
---|
1023 | { |
---|
1024 | do_command(mode, gb_organism, cl_user); |
---|
1025 | } |
---|
1026 | break; |
---|
1027 | } |
---|
1028 | case GEN_PERFORM_MARKED_ORGANISMS: { |
---|
1029 | for (GBDATA *gb_organism = GEN_first_marked_organism(gb_main); |
---|
1030 | gb_organism; |
---|
1031 | gb_organism = GEN_next_marked_organism(gb_organism)) |
---|
1032 | { |
---|
1033 | do_command(mode, gb_organism, cl_user); |
---|
1034 | } |
---|
1035 | break; |
---|
1036 | } |
---|
1037 | case GEN_PERFORM_ALL_BUT_CURRENT_ORGANISM: { |
---|
1038 | GBDATA *gb_curr_organism = GEN_get_current_organism(gb_main); |
---|
1039 | for (GBDATA *gb_organism = GEN_first_organism(gb_main); |
---|
1040 | gb_organism; |
---|
1041 | gb_organism = GEN_next_organism(gb_organism)) |
---|
1042 | { |
---|
1043 | if (gb_organism != gb_curr_organism) do_command(mode, gb_organism, cl_user); |
---|
1044 | } |
---|
1045 | break; |
---|
1046 | } |
---|
1047 | case GEN_PERFORM_CURRENT_ORGANISM: { |
---|
1048 | GBDATA *gb_organism = GEN_get_current_organism(gb_main); |
---|
1049 | if (!gb_organism) { |
---|
1050 | error = "First you have to select a species."; |
---|
1051 | } |
---|
1052 | else { |
---|
1053 | do_command(mode, gb_organism, cl_user); |
---|
1054 | } |
---|
1055 | break; |
---|
1056 | } |
---|
1057 | default: { |
---|
1058 | gen_assert(0); |
---|
1059 | break; |
---|
1060 | } |
---|
1061 | } |
---|
1062 | |
---|
1063 | GB_end_transaction_show_error(gb_main, error, aw_message); |
---|
1064 | } |
---|
1065 | |
---|
1066 | class GEN_unique_param { |
---|
1067 | GEN_unique_param(GBDATA *gb_main_, AW_CL unique_) : |
---|
1068 | unique(unique_), |
---|
1069 | gb_main(gb_main_) |
---|
1070 | {} |
---|
1071 | |
---|
1072 | typedef map<AW_CL, GEN_unique_param> ExistingParams; |
---|
1073 | static ExistingParams existing_params; // to ensure exactly one instance per 'command_mode' |
---|
1074 | |
---|
1075 | AW_CL unique; |
---|
1076 | public: |
---|
1077 | GBDATA *gb_main; |
---|
1078 | |
---|
1079 | AW_CL get_unique() { return unique; } |
---|
1080 | |
---|
1081 | static GEN_unique_param *get(GBDATA *gb_main_, AW_CL unique_) { // get unique instance for each 'unique_' |
---|
1082 | pair<ExistingParams::iterator, bool> created = existing_params.insert(ExistingParams::value_type(unique_, GEN_unique_param(gb_main_, unique_))); |
---|
1083 | ExistingParams::iterator wanted = created.first; |
---|
1084 | GEN_unique_param& param = wanted->second; |
---|
1085 | return ¶m; |
---|
1086 | } |
---|
1087 | }; |
---|
1088 | GEN_unique_param::ExistingParams GEN_unique_param::existing_params; |
---|
1089 | |
---|
1090 | |
---|
1091 | struct GEN_command_mode_param : public GEN_unique_param { |
---|
1092 | static GEN_command_mode_param *get(GBDATA *gb_main_, AW_CL command_mode_) { return (GEN_command_mode_param*)GEN_unique_param::get(gb_main_, command_mode_); } |
---|
1093 | AW_CL get_command_mode() { return get_unique(); } |
---|
1094 | }; |
---|
1095 | |
---|
1096 | |
---|
1097 | static void GEN_hide_command(AW_window*, GEN_PERFORM_MODE perform_mode, GEN_command_mode_param *param) { |
---|
1098 | GEN_perform_command(param->gb_main, perform_mode, do_hide_command_for_one_species, param->get_command_mode(), 0); |
---|
1099 | } |
---|
1100 | |
---|
1101 | static void GEN_mark_command(AW_window*, GEN_PERFORM_MODE perform_mode, GEN_command_mode_param *param) { |
---|
1102 | gen_count_marked_genes = 0; |
---|
1103 | GEN_perform_command(param->gb_main, perform_mode, do_mark_command_for_one_species, param->get_command_mode(), 0); |
---|
1104 | |
---|
1105 | if ((GEN_MARK_MODE)param->get_command_mode() == GEN_COUNT_MARKED) { |
---|
1106 | const char *where = NULp; |
---|
1107 | |
---|
1108 | switch (perform_mode) { |
---|
1109 | case GEN_PERFORM_CURRENT_ORGANISM: where = "the current species"; break; |
---|
1110 | case GEN_PERFORM_MARKED_ORGANISMS: where = "all marked species"; break; |
---|
1111 | case GEN_PERFORM_ALL_ORGANISMS: where = "all species"; break; |
---|
1112 | case GEN_PERFORM_ALL_BUT_CURRENT_ORGANISM: where = "all but the current species"; break; |
---|
1113 | default: gen_assert(0); break; |
---|
1114 | } |
---|
1115 | aw_message(GBS_global_string("There are %li marked genes in %s", gen_count_marked_genes, where)); |
---|
1116 | } |
---|
1117 | } |
---|
1118 | |
---|
1119 | struct GEN_extract_mode_param : public GEN_unique_param { |
---|
1120 | static GEN_extract_mode_param *get(GBDATA *gb_main_, GEN_PERFORM_MODE perform_mode) { return (GEN_extract_mode_param*)GEN_unique_param::get(gb_main_, perform_mode); } |
---|
1121 | GEN_PERFORM_MODE get_perform_mode() { return (GEN_PERFORM_MODE)get_unique(); } |
---|
1122 | }; |
---|
1123 | |
---|
1124 | static GB_ERROR gene_extract_handler(const char *ali, GEN_extract_mode_param *param) { |
---|
1125 | GBDATA *gb_main = param->gb_main; |
---|
1126 | GB_ERROR error = GBT_check_alignment_name(ali); |
---|
1127 | |
---|
1128 | if (!error) { |
---|
1129 | GB_transaction ta(gb_main); |
---|
1130 | GBDATA *gb_ali = GBT_get_alignment(gb_main, ali); |
---|
1131 | |
---|
1132 | if (!gb_ali) { |
---|
1133 | GB_clear_error(); // ali not found |
---|
1134 | if (!GBT_create_alignment(gb_main, ali, 0, 0, 0, "dna")) { |
---|
1135 | error = GB_await_error(); |
---|
1136 | } |
---|
1137 | } |
---|
1138 | } |
---|
1139 | |
---|
1140 | if (!error) { |
---|
1141 | ask_about_existing_gene_species = new AW_repeated_question; |
---|
1142 | ask_to_overwrite_alignment = new AW_repeated_question; |
---|
1143 | |
---|
1144 | arb_progress progress("Extracting pseudo-species"); |
---|
1145 | { |
---|
1146 | EG2PS_data *eg2ps = NULp; |
---|
1147 | { |
---|
1148 | gen_count_marked_genes = 0; |
---|
1149 | GEN_perform_command(gb_main, param->get_perform_mode(), do_mark_command_for_one_species, GEN_COUNT_MARKED, 0); |
---|
1150 | |
---|
1151 | GB_transaction ta(gb_main); |
---|
1152 | GBDATA *gb_species_data = GBT_get_species_data(gb_main); |
---|
1153 | eg2ps = new EG2PS_data(ali, gb_species_data, gen_count_marked_genes); |
---|
1154 | } |
---|
1155 | |
---|
1156 | PersistentNameServerConnection stayAlive; |
---|
1157 | |
---|
1158 | GEN_perform_command(gb_main, param->get_perform_mode(), do_mark_command_for_one_species, GEN_EXTRACT_MARKED, (AW_CL)eg2ps); |
---|
1159 | delete eg2ps; |
---|
1160 | } |
---|
1161 | |
---|
1162 | delete ask_to_overwrite_alignment; |
---|
1163 | delete ask_about_existing_gene_species; |
---|
1164 | ask_to_overwrite_alignment = NULp; |
---|
1165 | ask_about_existing_gene_species = NULp; |
---|
1166 | } |
---|
1167 | return error; |
---|
1168 | } |
---|
1169 | static void gene_extract_cb(AW_window*, GEN_extract_mode_param *param) { |
---|
1170 | AWT_activate_prompt("Extract genes to alignment", "Enter the name of the alignment to extract to:", "ali_gene_", "Extract", makeResultHandler(gene_extract_handler, param), "", SRT_AUTOCORRECT_ALINAME); |
---|
1171 | } |
---|
1172 | |
---|
1173 | enum MarkCommand { |
---|
1174 | UNMARK, // UNMARK and MARK have to be 0 and 1! |
---|
1175 | MARK, |
---|
1176 | INVERT, |
---|
1177 | MARK_UNMARK_REST, |
---|
1178 | }; |
---|
1179 | |
---|
1180 | static void mark_organisms(AW_window*, MarkCommand mark, GBDATA *gb_main) { |
---|
1181 | GB_transaction ta(gb_main); |
---|
1182 | |
---|
1183 | if (mark == MARK_UNMARK_REST) { |
---|
1184 | GBT_mark_all(gb_main, 0); // unmark all species |
---|
1185 | mark = MARK; |
---|
1186 | } |
---|
1187 | |
---|
1188 | for (GBDATA *gb_org = GEN_first_organism(gb_main); |
---|
1189 | gb_org; |
---|
1190 | gb_org = GEN_next_organism(gb_org)) |
---|
1191 | { |
---|
1192 | if (mark == INVERT) { |
---|
1193 | GB_write_flag(gb_org, !GB_read_flag(gb_org)); // invert mark of organism |
---|
1194 | } |
---|
1195 | else { |
---|
1196 | GB_write_flag(gb_org, mark); // mark/unmark organism |
---|
1197 | } |
---|
1198 | } |
---|
1199 | } |
---|
1200 | |
---|
1201 | |
---|
1202 | static void mark_gene_species(AW_window*, MarkCommand mark, GBDATA *gb_main) { |
---|
1203 | GB_transaction ta(gb_main); |
---|
1204 | |
---|
1205 | if (mark == MARK_UNMARK_REST) { |
---|
1206 | GBT_mark_all(gb_main, 0); // unmark all species |
---|
1207 | mark = MARK; |
---|
1208 | } |
---|
1209 | |
---|
1210 | for (GBDATA *gb_pseudo = GEN_first_pseudo_species(gb_main); |
---|
1211 | gb_pseudo; |
---|
1212 | gb_pseudo = GEN_next_pseudo_species(gb_pseudo)) |
---|
1213 | { |
---|
1214 | if (mark == INVERT) { |
---|
1215 | GB_write_flag(gb_pseudo, !GB_read_flag(gb_pseudo)); // invert mark of pseudo-species |
---|
1216 | } |
---|
1217 | else { |
---|
1218 | GB_write_flag(gb_pseudo, mark); // mark/unmark gene-species |
---|
1219 | } |
---|
1220 | } |
---|
1221 | } |
---|
1222 | |
---|
1223 | static void mark_gene_species_of_marked_genes(AW_window*, GBDATA *gb_main) { |
---|
1224 | GB_transaction ta(gb_main); |
---|
1225 | GB_HASH *organism_hash = GBT_create_organism_hash(gb_main); |
---|
1226 | |
---|
1227 | for (GBDATA *gb_pseudo = GEN_first_pseudo_species(gb_main); |
---|
1228 | gb_pseudo; |
---|
1229 | gb_pseudo = GEN_next_pseudo_species(gb_pseudo)) |
---|
1230 | { |
---|
1231 | GBDATA *gb_gene = GEN_find_origin_gene(gb_pseudo, organism_hash); |
---|
1232 | if (GB_read_flag(gb_gene)) { |
---|
1233 | GB_write_flag(gb_pseudo, 1); // mark pseudo |
---|
1234 | } |
---|
1235 | } |
---|
1236 | |
---|
1237 | GBS_free_hash(organism_hash); |
---|
1238 | } |
---|
1239 | |
---|
1240 | |
---|
1241 | |
---|
1242 | static void mark_organisms_with_marked_genes(AW_window*, GBDATA *gb_main) { |
---|
1243 | GB_transaction ta(gb_main); |
---|
1244 | |
---|
1245 | for (GBDATA *gb_species = GEN_first_organism(gb_main); |
---|
1246 | gb_species; |
---|
1247 | gb_species = GEN_next_organism(gb_species)) |
---|
1248 | { |
---|
1249 | for (GBDATA *gb_gene = GEN_first_gene(gb_species); |
---|
1250 | gb_gene; |
---|
1251 | gb_gene = GEN_next_gene(gb_gene)) |
---|
1252 | { |
---|
1253 | if (GB_read_flag(gb_gene)) { |
---|
1254 | GB_write_flag(gb_species, 1); |
---|
1255 | break; // continue with next organism |
---|
1256 | } |
---|
1257 | } |
---|
1258 | } |
---|
1259 | } |
---|
1260 | static void mark_gene_species_using_current_alignment(AW_window*, GBDATA *gb_main) { |
---|
1261 | GB_transaction ta(gb_main); |
---|
1262 | char *ali = GBT_get_default_alignment(gb_main); |
---|
1263 | |
---|
1264 | for (GBDATA *gb_pseudo = GEN_first_pseudo_species(gb_main); |
---|
1265 | gb_pseudo; |
---|
1266 | gb_pseudo = GEN_next_pseudo_species(gb_pseudo)) |
---|
1267 | { |
---|
1268 | GBDATA *gb_ali = GB_entry(gb_pseudo, ali); |
---|
1269 | if (gb_ali) { |
---|
1270 | GBDATA *gb_data = GB_entry(gb_ali, "data"); |
---|
1271 | if (gb_data) { |
---|
1272 | GB_write_flag(gb_pseudo, 1); |
---|
1273 | } |
---|
1274 | } |
---|
1275 | } |
---|
1276 | } |
---|
1277 | static void mark_genes_of_marked_gene_species(AW_window*, GBDATA *gb_main) { |
---|
1278 | GB_transaction ta(gb_main); |
---|
1279 | GB_HASH *organism_hash = GBT_create_organism_hash(gb_main); |
---|
1280 | |
---|
1281 | for (GBDATA *gb_pseudo = GEN_first_pseudo_species(gb_main); |
---|
1282 | gb_pseudo; |
---|
1283 | gb_pseudo = GEN_next_pseudo_species(gb_pseudo)) |
---|
1284 | { |
---|
1285 | if (GB_read_flag(gb_pseudo)) { |
---|
1286 | GBDATA *gb_gene = GEN_find_origin_gene(gb_pseudo, organism_hash); |
---|
1287 | GB_write_flag(gb_gene, 1); // mark gene |
---|
1288 | } |
---|
1289 | } |
---|
1290 | |
---|
1291 | GBS_free_hash(organism_hash); |
---|
1292 | } |
---|
1293 | |
---|
1294 | static void GEN_insert_extract_submenu(AW_window_menu_modes *awm, GBDATA *gb_main, const char *macro_prefix, const char *submenu_name, const char *hot_key, const char *help_file) { |
---|
1295 | awm->insert_sub_menu(submenu_name, hot_key); |
---|
1296 | |
---|
1297 | char macro_name_buffer[50]; |
---|
1298 | |
---|
1299 | sprintf(macro_name_buffer, "%s_of_current", macro_prefix); |
---|
1300 | awm->insert_menu_topic(awm->local_id(macro_name_buffer), "of current species...", "c", help_file, AWM_ALL, makeWindowCallback(gene_extract_cb, GEN_extract_mode_param::get(gb_main, GEN_PERFORM_CURRENT_ORGANISM))); |
---|
1301 | |
---|
1302 | sprintf(macro_name_buffer, "%s_of_marked", macro_prefix); |
---|
1303 | awm->insert_menu_topic(awm->local_id(macro_name_buffer), "of marked species...", "m", help_file, AWM_ALL, makeWindowCallback(gene_extract_cb, GEN_extract_mode_param::get(gb_main, GEN_PERFORM_MARKED_ORGANISMS))); |
---|
1304 | |
---|
1305 | sprintf(macro_name_buffer, "%s_of_all", macro_prefix); |
---|
1306 | awm->insert_menu_topic(awm->local_id(macro_name_buffer), "of all species...", "a", help_file, AWM_ALL, makeWindowCallback(gene_extract_cb, GEN_extract_mode_param::get(gb_main, GEN_PERFORM_ALL_ORGANISMS))); |
---|
1307 | |
---|
1308 | awm->close_sub_menu(); |
---|
1309 | } |
---|
1310 | |
---|
1311 | static void GEN_insert_multi_submenu(AW_window_menu_modes *awm, const char *macro_prefix, const char *submenu_name, const char *hot_key, |
---|
1312 | const char *help_file, void (*command)(AW_window*, GEN_PERFORM_MODE, GEN_command_mode_param*), GEN_command_mode_param *command_mode) |
---|
1313 | { |
---|
1314 | awm->insert_sub_menu(submenu_name, hot_key); |
---|
1315 | |
---|
1316 | char macro_name_buffer[50]; |
---|
1317 | |
---|
1318 | sprintf(macro_name_buffer, "%s_of_current", macro_prefix); |
---|
1319 | awm->insert_menu_topic(macro_name_buffer, "of current species", "c", help_file, AWM_ALL, makeWindowCallback(command, GEN_PERFORM_CURRENT_ORGANISM, command_mode)); |
---|
1320 | |
---|
1321 | sprintf(macro_name_buffer, "%s_of_all_but_current", macro_prefix); |
---|
1322 | awm->insert_menu_topic(macro_name_buffer, "of all but current species", "b", help_file, AWM_ALL, makeWindowCallback(command, GEN_PERFORM_ALL_BUT_CURRENT_ORGANISM, command_mode)); |
---|
1323 | |
---|
1324 | sprintf(macro_name_buffer, "%s_of_marked", macro_prefix); |
---|
1325 | awm->insert_menu_topic(macro_name_buffer, "of marked species", "m", help_file, AWM_ALL, makeWindowCallback(command, GEN_PERFORM_MARKED_ORGANISMS, command_mode)); |
---|
1326 | |
---|
1327 | sprintf(macro_name_buffer, "%s_of_all", macro_prefix); |
---|
1328 | awm->insert_menu_topic(macro_name_buffer, "of all species", "a", help_file, AWM_ALL, makeWindowCallback(command, GEN_PERFORM_ALL_ORGANISMS, command_mode)); |
---|
1329 | |
---|
1330 | awm->close_sub_menu(); |
---|
1331 | } |
---|
1332 | |
---|
1333 | static void GEN_insert_mark_submenu(AW_window_menu_modes *awm, GBDATA *gb_main, const char *macro_prefix, const char *submenu_name, const char *hot_key, const char *help_file, GEN_MARK_MODE mark_mode) { |
---|
1334 | GEN_insert_multi_submenu(awm, macro_prefix, submenu_name, hot_key, help_file, GEN_mark_command, GEN_command_mode_param::get(gb_main, mark_mode)); |
---|
1335 | } |
---|
1336 | static void GEN_insert_hide_submenu(AW_window_menu_modes *awm, GBDATA *gb_main, const char *macro_prefix, const char *submenu_name, const char *hot_key, const char *help_file, GEN_HIDE_MODE hide_mode) { |
---|
1337 | GEN_insert_multi_submenu(awm, macro_prefix, submenu_name, hot_key, help_file, GEN_hide_command, GEN_command_mode_param::get(gb_main, hide_mode)); |
---|
1338 | } |
---|
1339 | |
---|
1340 | #if defined(DEBUG) |
---|
1341 | static AW_window *GEN_create_awar_debug_window(AW_root *aw_root) { |
---|
1342 | static AW_window_simple *aws = NULp; |
---|
1343 | if (!aws) { |
---|
1344 | aws = new AW_window_simple; |
---|
1345 | |
---|
1346 | aws->init(aw_root, "DEBUG_AWARS", "DEBUG AWARS"); |
---|
1347 | aws->at(10, 10); |
---|
1348 | aws->auto_space(10, 10); |
---|
1349 | |
---|
1350 | const int width = 50; |
---|
1351 | |
---|
1352 | ; aws->label("AWAR_SPECIES_NAME "); aws->create_input_field(AWAR_SPECIES_NAME, width); |
---|
1353 | aws->at_newline(); aws->label("AWAR_ORGANISM_NAME "); aws->create_input_field(AWAR_ORGANISM_NAME, width); |
---|
1354 | aws->at_newline(); aws->label("AWAR_GENE_NAME "); aws->create_input_field(AWAR_GENE_NAME, width); |
---|
1355 | aws->at_newline(); aws->label("AWAR_COMBINED_GENE_NAME "); aws->create_input_field(AWAR_COMBINED_GENE_NAME, width); |
---|
1356 | aws->at_newline(); aws->label("AWAR_EXPERIMENT_NAME "); aws->create_input_field(AWAR_EXPERIMENT_NAME, width); |
---|
1357 | aws->at_newline(); aws->label("AWAR_COMBINED_EXPERIMENT_NAME"); aws->create_input_field(AWAR_COMBINED_EXPERIMENT_NAME, width); |
---|
1358 | aws->at_newline(); aws->label("AWAR_PROTEOM_NAME "); aws->create_input_field(AWAR_PROTEOM_NAME, width); |
---|
1359 | aws->at_newline(); aws->label("AWAR_PROTEIN_NAME "); aws->create_input_field(AWAR_PROTEIN_NAME, width); |
---|
1360 | |
---|
1361 | aws->window_fit(); |
---|
1362 | } |
---|
1363 | return aws; |
---|
1364 | } |
---|
1365 | #endif // DEBUG |
---|
1366 | |
---|
1367 | // --------------------------- |
---|
1368 | // user mask section |
---|
1369 | |
---|
1370 | struct GEN_item_type_species_selector : public awt_item_type_selector { |
---|
1371 | GEN_item_type_species_selector() : awt_item_type_selector(AWT_IT_GENE) {} |
---|
1372 | ~GEN_item_type_species_selector() OVERRIDE {} |
---|
1373 | |
---|
1374 | const char *get_self_awar() const OVERRIDE { |
---|
1375 | return AWAR_COMBINED_GENE_NAME; |
---|
1376 | } |
---|
1377 | size_t get_self_awar_content_length() const OVERRIDE { |
---|
1378 | return 12 + 1 + 40; // species-name+'/'+gene_name |
---|
1379 | } |
---|
1380 | GBDATA *current(AW_root *root, GBDATA *gb_main) const OVERRIDE { // give the current item |
---|
1381 | char *species_name = root->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
1382 | char *gene_name = root->awar(AWAR_GENE_NAME)->read_string(); |
---|
1383 | GBDATA *gb_gene = NULp; |
---|
1384 | |
---|
1385 | if (species_name[0] && gene_name[0]) { |
---|
1386 | GB_transaction ta(gb_main); |
---|
1387 | GBDATA *gb_species = GBT_find_species(gb_main, species_name); |
---|
1388 | if (gb_species) { |
---|
1389 | gb_gene = GEN_find_gene(gb_species, gene_name); |
---|
1390 | } |
---|
1391 | } |
---|
1392 | |
---|
1393 | free(gene_name); |
---|
1394 | free(species_name); |
---|
1395 | |
---|
1396 | return gb_gene; |
---|
1397 | } |
---|
1398 | const char *getKeyPath() const OVERRIDE { // give the keypath for items |
---|
1399 | return CHANGE_KEY_PATH_GENES; |
---|
1400 | } |
---|
1401 | }; |
---|
1402 | |
---|
1403 | static GEN_item_type_species_selector item_type_gene; |
---|
1404 | |
---|
1405 | static void GEN_open_mask_window(AW_window *aww, int id, GBDATA *gb_main) { |
---|
1406 | const awt_input_mask_descriptor *descriptor = AWT_look_input_mask(id); |
---|
1407 | gen_assert(descriptor); |
---|
1408 | if (descriptor) { |
---|
1409 | AWT_initialize_input_mask(aww->get_root(), gb_main, &item_type_gene, descriptor->get_internal_maskname(), descriptor->is_local_mask()); |
---|
1410 | } |
---|
1411 | } |
---|
1412 | |
---|
1413 | static void GEN_create_mask_submenu(AW_window_menu_modes *awm, GBDATA *gb_main) { |
---|
1414 | AWT_create_mask_submenu(awm, AWT_IT_GENE, GEN_open_mask_window, gb_main); |
---|
1415 | } |
---|
1416 | |
---|
1417 | static AW_window *create_colorize_genes_window(AW_root *aw_root, GBDATA *gb_main) { |
---|
1418 | return QUERY::create_colorize_items_window(aw_root, gb_main, GEN_get_selector()); |
---|
1419 | } |
---|
1420 | |
---|
1421 | static AW_window *create_colorize_organisms_window(AW_root *aw_root, GBDATA *gb_main) { |
---|
1422 | return QUERY::create_colorize_items_window(aw_root, gb_main, ORGANISM_get_selector()); |
---|
1423 | } |
---|
1424 | |
---|
1425 | static void GEN_create_organism_submenu(AW_window_menu_modes *awm, GBDATA *gb_main, bool submenu) { |
---|
1426 | const char *title = "Organisms"; |
---|
1427 | const char *hotkey = "O"; |
---|
1428 | |
---|
1429 | if (submenu) awm->insert_sub_menu(title, hotkey); |
---|
1430 | else awm->create_menu(title, hotkey, AWM_ALL); |
---|
1431 | |
---|
1432 | { |
---|
1433 | awm->insert_menu_topic("organism_info", "Organism information", "i", "sp_info.hlp", AWM_ALL, RootAsWindowCallback::simple(DBUI::popup_organism_info_window, gb_main)); |
---|
1434 | |
---|
1435 | awm->sep______________(); |
---|
1436 | |
---|
1437 | awm->insert_menu_topic("mark_organisms", "Mark All organisms", "A", "organism_mark.hlp", AWM_ALL, makeWindowCallback(mark_organisms, MARK, gb_main)); |
---|
1438 | awm->insert_menu_topic("mark_organisms_unmark_rest", "Mark all organisms, unmark Rest", "R", "organism_mark.hlp", AWM_ALL, makeWindowCallback(mark_organisms, MARK_UNMARK_REST, gb_main)); |
---|
1439 | awm->insert_menu_topic("unmark_organisms", "Unmark all organisms", "U", "organism_mark.hlp", AWM_ALL, makeWindowCallback(mark_organisms, UNMARK, gb_main)); |
---|
1440 | awm->insert_menu_topic("invmark_organisms", "Invert marks of all organisms", "v", "organism_mark.hlp", AWM_ALL, makeWindowCallback(mark_organisms, INVERT, gb_main)); |
---|
1441 | awm->sep______________(); |
---|
1442 | awm->insert_menu_topic("mark_organisms_with_marked_genes", "Mark organisms with marked Genes", "G", "organism_mark.hlp", AWM_ALL, makeWindowCallback(mark_organisms_with_marked_genes, gb_main)); |
---|
1443 | awm->sep______________(); |
---|
1444 | awm->insert_menu_topic(awm->local_id("organism_colors"), "Colors ...", "C", "colorize.hlp", AWM_ALL, makeCreateWindowCallback(create_colorize_organisms_window, gb_main)); |
---|
1445 | } |
---|
1446 | if (submenu) awm->close_sub_menu(); |
---|
1447 | } |
---|
1448 | |
---|
1449 | static void GEN_create_gene_species_submenu(AW_window_menu_modes *awm, GBDATA *gb_main, bool submenu) { |
---|
1450 | const char *title = "Gene-Species"; |
---|
1451 | const char *hotkey = "S"; |
---|
1452 | |
---|
1453 | if (submenu) awm->insert_sub_menu(title, hotkey); |
---|
1454 | else awm->create_menu(title, hotkey, AWM_ALL); |
---|
1455 | |
---|
1456 | { |
---|
1457 | awm->insert_menu_topic("mark_gene_species", "Mark All gene-species", "A", "gene_species_mark.hlp", AWM_ALL, makeWindowCallback(mark_gene_species, MARK, gb_main)); |
---|
1458 | awm->insert_menu_topic("mark_gene_species_unmark_rest", "Mark all gene-species, unmark Rest", "R", "gene_species_mark.hlp", AWM_ALL, makeWindowCallback(mark_gene_species, MARK_UNMARK_REST, gb_main)); |
---|
1459 | awm->insert_menu_topic("unmark_gene_species", "Unmark all gene-species", "U", "gene_species_mark.hlp", AWM_ALL, makeWindowCallback(mark_gene_species, UNMARK, gb_main)); |
---|
1460 | awm->insert_menu_topic("invmark_gene_species", "Invert marks of all gene-species", "I", "gene_species_mark.hlp", AWM_ALL, makeWindowCallback(mark_gene_species, INVERT, gb_main)); |
---|
1461 | awm->sep______________(); |
---|
1462 | awm->insert_menu_topic("mark_gene_species_of_marked_genes", "Mark gene-species of marked genes", "M", "gene_species_mark.hlp", AWM_ALL, makeWindowCallback(mark_gene_species_of_marked_genes, gb_main)); |
---|
1463 | awm->insert_menu_topic("mark_gene_species_curr_ali", "Mark all gene-species using Current alignment", "C", "gene_species_mark.hlp", AWM_ALL, makeWindowCallback(mark_gene_species_using_current_alignment, gb_main)); |
---|
1464 | } |
---|
1465 | |
---|
1466 | if (submenu) awm->close_sub_menu(); |
---|
1467 | } |
---|
1468 | |
---|
1469 | struct GEN_update_info { |
---|
1470 | AWT_canvas *canvas1; // just canvasses of different windows (needed for updates) |
---|
1471 | AWT_canvas *canvas2; |
---|
1472 | }; |
---|
1473 | |
---|
1474 | void GEN_create_genes_submenu(AW_window_menu_modes *awm, GBDATA *gb_main, bool for_ARB_NTREE) { |
---|
1475 | awm->create_menu("Genome", "G", AWM_ALL); |
---|
1476 | { |
---|
1477 | #if defined(DEBUG) |
---|
1478 | awm->insert_menu_topic(awm->local_id("debug_awars"), "[DEBUG] Show main AWARs", "A", NULp, AWM_ALL, GEN_create_awar_debug_window); |
---|
1479 | awm->sep______________(); |
---|
1480 | #endif // DEBUG |
---|
1481 | |
---|
1482 | if (for_ARB_NTREE) { |
---|
1483 | awm->insert_menu_topic("gene_map", "Gene Map", "p", "gene_map.hlp", AWM_ALL, makeCreateWindowCallback(GEN_create_first_map, gb_main)); // initial gene map |
---|
1484 | awm->sep______________(); |
---|
1485 | |
---|
1486 | GEN_create_gene_species_submenu(awm, gb_main, true); // Gene-species |
---|
1487 | GEN_create_organism_submenu (awm, gb_main, true); // Organisms |
---|
1488 | EXP_create_experiments_submenu (awm, gb_main, true); // Experiments |
---|
1489 | awm->sep______________(); |
---|
1490 | } |
---|
1491 | |
---|
1492 | awm->insert_menu_topic("gene_info", "Gene information", "i", "gene_info.hlp", AWM_ALL, RootAsWindowCallback::simple(GEN_popup_gene_infowindow, gb_main)); |
---|
1493 | awm->insert_menu_topic(awm->local_id("gene_search"), "Search and Query", "Q", "gene_search.hlp", AWM_ALL, makeCreateWindowCallback (GEN_create_gene_query_window, gb_main)); |
---|
1494 | |
---|
1495 | GEN_create_mask_submenu(awm, gb_main); |
---|
1496 | |
---|
1497 | awm->sep______________(); |
---|
1498 | |
---|
1499 | GEN_insert_mark_submenu(awm, gb_main, "gene_mark_all", "Mark all genes", "M", "gene_mark.hlp", GEN_MARK); |
---|
1500 | GEN_insert_mark_submenu(awm, gb_main, "gene_unmark_all", "Unmark all genes", "U", "gene_mark.hlp", GEN_UNMARK); |
---|
1501 | GEN_insert_mark_submenu(awm, gb_main, "gene_invert_marked", "Invert marked genes", "v", "gene_mark.hlp", GEN_INVERT_MARKED); |
---|
1502 | GEN_insert_mark_submenu(awm, gb_main, "gene_count_marked", "Count marked genes", "C", "gene_mark.hlp", GEN_COUNT_MARKED); |
---|
1503 | |
---|
1504 | awm->insert_menu_topic(awm->local_id("gene_colors"), "Colors ...", "l", "colorize.hlp", AWM_ALL, makeCreateWindowCallback(create_colorize_genes_window, gb_main)); |
---|
1505 | |
---|
1506 | awm->sep______________(); |
---|
1507 | |
---|
1508 | awm->insert_menu_topic("mark_genes_of_marked_gene_species", "Mark genes of marked gene-species", "g", "gene_mark.hlp", AWM_ALL, makeWindowCallback(mark_genes_of_marked_gene_species, gb_main)); |
---|
1509 | |
---|
1510 | awm->sep______________(); |
---|
1511 | |
---|
1512 | GEN_insert_extract_submenu(awm, gb_main, "gene_extract_marked", "Extract marked genes", "E", "gene_extract.hlp"); |
---|
1513 | |
---|
1514 | if (!for_ARB_NTREE) { // only in ARB_GENE_MAP: |
---|
1515 | awm->sep______________(); |
---|
1516 | GEN_insert_mark_submenu(awm, gb_main, "gene_mark_hidden", "Mark hidden genes", "h", "gene_hide.hlp", GEN_MARK_HIDDEN); |
---|
1517 | GEN_insert_mark_submenu(awm, gb_main, "gene_mark_visible", "Mark visible genes", "s", "gene_hide.hlp", GEN_MARK_VISIBLE); |
---|
1518 | |
---|
1519 | awm->sep______________(); |
---|
1520 | GEN_insert_mark_submenu(awm, gb_main, "gene_unmark_hidden", "Unmark hidden genes", "d", "gene_hide.hlp", GEN_UNMARK_HIDDEN); |
---|
1521 | GEN_insert_mark_submenu(awm, gb_main, "gene_unmark_visible", "Unmark visible genes", "r", "gene_hide.hlp", GEN_UNMARK_VISIBLE); |
---|
1522 | } |
---|
1523 | } |
---|
1524 | } |
---|
1525 | |
---|
1526 | static void GEN_create_hide_submenu(AW_window_menu_modes *awm, GBDATA *gb_main) { |
---|
1527 | awm->create_menu("Hide", "H", AWM_ALL); |
---|
1528 | { |
---|
1529 | GEN_insert_hide_submenu(awm, gb_main, "gene_hide_marked", "Hide marked genes", "H", "gene_hide.hlp", GEN_HIDE_MARKED); |
---|
1530 | GEN_insert_hide_submenu(awm, gb_main, "gene_unhide_marked", "Unhide marked genes", "U", "gene_hide.hlp", GEN_UNHIDE_MARKED); |
---|
1531 | GEN_insert_hide_submenu(awm, gb_main, "gene_invhide_marked", "Invert-hide marked genes", "v", "gene_hide.hlp", GEN_INVERT_HIDE_MARKED); |
---|
1532 | |
---|
1533 | awm->sep______________(); |
---|
1534 | GEN_insert_hide_submenu(awm, gb_main, "gene_hide_all", "Hide all genes", "a", "gene_hide.hlp", GEN_HIDE_ALL); |
---|
1535 | GEN_insert_hide_submenu(awm, gb_main, "gene_unhide_all", "Unhide all genes", "l", "gene_hide.hlp", GEN_UNHIDE_ALL); |
---|
1536 | GEN_insert_hide_submenu(awm, gb_main, "gene_invhide_all", "Invert-hide all genes", "I", "gene_hide.hlp", GEN_INVERT_HIDE_ALL); |
---|
1537 | } |
---|
1538 | } |
---|
1539 | |
---|
1540 | static void GEN_set_display_style(AW_window *aww, GEN_DisplayStyle style) { |
---|
1541 | GEN_map_window *win = DOWNCAST(GEN_map_window*, aww); |
---|
1542 | AWT_auto_refresh allowed_on(win->get_canvas()); |
---|
1543 | |
---|
1544 | win->get_root()->awar(AWAR_GENMAP_DISPLAY_TYPE(win->get_nr()))->write_int(style); |
---|
1545 | win->get_graphic()->set_display_style(style); |
---|
1546 | } |
---|
1547 | |
---|
1548 | static AW_window *GEN_create_map(AW_root *aw_root, GEN_create_map_param *param) { |
---|
1549 | // param->window_nr shall be 0 for first window (called from ARB_NTREE) |
---|
1550 | // additional views are always created by the previous window created with GEN_map |
---|
1551 | GEN_map_manager *manager = NULp; |
---|
1552 | |
---|
1553 | if (!GEN_map_manager::initialized()) { // first call |
---|
1554 | gen_assert(param->window_nr == 0); // has to be 0 for first call |
---|
1555 | |
---|
1556 | GEN_map_manager::initialize(aw_root, param->gb_main); |
---|
1557 | manager = GEN_map_manager::get_map_manager(); // creates the manager |
---|
1558 | |
---|
1559 | // global initialization (AWARS etc.) done here : |
---|
1560 | |
---|
1561 | GEN_create_genemap_global_awars(aw_root, AW_ROOT_DEFAULT, param->gb_main); |
---|
1562 | GEN_add_global_awar_callbacks(aw_root); |
---|
1563 | { |
---|
1564 | GB_transaction ta(param->gb_main); |
---|
1565 | GEN_make_node_text_init(param->gb_main); |
---|
1566 | } |
---|
1567 | } |
---|
1568 | else { |
---|
1569 | manager = GEN_map_manager::get_map_manager(); |
---|
1570 | } |
---|
1571 | |
---|
1572 | GEN_map_window *gmw = manager->get_map_window(param->window_nr); |
---|
1573 | return gmw; |
---|
1574 | } |
---|
1575 | |
---|
1576 | AW_window *GEN_create_first_map(AW_root *aw_root, GBDATA *gb_main) { |
---|
1577 | return GEN_create_map(aw_root, new GEN_create_map_param(gb_main, 0)); |
---|
1578 | } |
---|
1579 | |
---|
1580 | // ------------------------ |
---|
1581 | // GEN_map_window |
---|
1582 | |
---|
1583 | void GEN_map_window::init(AW_root *awr, GBDATA *gb_main) { |
---|
1584 | { |
---|
1585 | char *windowName = (window_nr == 0) ? ARB_strdup("ARB Gene Map") : GBS_global_string_copy("ARB Gene Map %i", window_nr); |
---|
1586 | char *windowID = (window_nr == 0) ? ARB_strdup("ARB_GENE_MAP") : GBS_global_string_copy("ARB_GENE_MAP_%i", window_nr); |
---|
1587 | |
---|
1588 | AW_window_menu_modes::init(awr, windowID, windowName, 200, 200); |
---|
1589 | |
---|
1590 | free(windowID); |
---|
1591 | free(windowName); |
---|
1592 | } |
---|
1593 | |
---|
1594 | GEN_create_genemap_local_awars(awr, AW_ROOT_DEFAULT, window_nr); |
---|
1595 | |
---|
1596 | gen_graphic = new GEN_graphic(awr, gb_main, GEN_gene_container_cb_installer, window_nr); |
---|
1597 | gen_canvas = new AWT_canvas(gb_main, this, get_window_id(), gen_graphic); |
---|
1598 | |
---|
1599 | GEN_add_local_awar_callbacks(awr, AW_ROOT_DEFAULT, this); |
---|
1600 | |
---|
1601 | AWT_auto_refresh allowed_on(gen_canvas); |
---|
1602 | { |
---|
1603 | GB_transaction ta(gb_main); |
---|
1604 | gen_graphic->reinit_gen_root(gen_canvas, false); |
---|
1605 | } |
---|
1606 | gen_canvas->request_resize(); |
---|
1607 | gen_canvas->set_mode(AWT_MODE_SELECT); // Default-Mode |
---|
1608 | |
---|
1609 | // --------------- |
---|
1610 | // menus |
---|
1611 | |
---|
1612 | // File Menu |
---|
1613 | create_menu("File", "F", AWM_ALL); |
---|
1614 | insert_menu_topic("close", "Close", "C", NULp, AWM_ALL, AW_POPDOWN); |
---|
1615 | insert_menu_topic(local_id("new_view"), "New view", "v", "gen_new_view.hlp", AWM_ALL, makeCreateWindowCallback(GEN_create_map, new GEN_create_map_param(gb_main, window_nr+1))); |
---|
1616 | |
---|
1617 | GEN_create_genes_submenu (this, gb_main, false); // Genes |
---|
1618 | GEN_create_gene_species_submenu(this, gb_main, false); // Gene-species |
---|
1619 | GEN_create_organism_submenu (this, gb_main, false); // Organisms |
---|
1620 | EXP_create_experiments_submenu (this, gb_main, false); // Experiments |
---|
1621 | GEN_create_hide_submenu(this, gb_main); // Hide Menu |
---|
1622 | |
---|
1623 | // Properties Menu |
---|
1624 | create_menu("Properties", "r", AWM_ALL); |
---|
1625 | insert_menu_topic(local_id("gene_props_menu"), "Frame settings ...", "M", "props_frame.hlp", AWM_ALL, AW_preset_window); |
---|
1626 | insert_menu_topic(local_id("gene_props"), "GENEMAP: Colors and Fonts ...", "C", "color_props.hlp", AWM_ALL, makeCreateWindowCallback(GEN_create_gc_window, gen_canvas->gc_manager)); |
---|
1627 | insert_menu_topic(local_id("gene_options"), "Options", "O", "gen_options.hlp", AWM_ALL, GEN_create_options_window); |
---|
1628 | insert_menu_topic(local_id("gene_nds"), "NDS ( Select Gene Information ) ...", "N", "props_nds.hlp", AWM_ALL, makeCreateWindowCallback(GEN_open_nds_window, gb_main)); |
---|
1629 | sep______________(); |
---|
1630 | AW_insert_common_property_menu_entries(this); |
---|
1631 | sep______________(); |
---|
1632 | insert_menu_topic("gene_save_props", "Save Defaults (ntree.arb)", "D", "savedef.hlp", AWM_ALL, AW_save_properties); |
---|
1633 | |
---|
1634 | // ---------------------- |
---|
1635 | // mode buttons |
---|
1636 | |
---|
1637 | create_mode("mode_select.xpm", "gen_mode.hlp", AWM_ALL, makeWindowCallback(GEN_mode_event, this, AWT_MODE_SELECT)); |
---|
1638 | create_mode("mode_zoom.xpm", "gen_mode.hlp", AWM_ALL, makeWindowCallback(GEN_mode_event, this, AWT_MODE_ZOOM)); |
---|
1639 | create_mode("mode_info.xpm", "gen_mode.hlp", AWM_ALL, makeWindowCallback(GEN_mode_event, this, AWT_MODE_INFO)); |
---|
1640 | |
---|
1641 | // ------------------- |
---|
1642 | // info area |
---|
1643 | |
---|
1644 | set_info_area_height(250); |
---|
1645 | at(11, 2); |
---|
1646 | auto_space(2, -2); |
---|
1647 | shadow_width(1); |
---|
1648 | |
---|
1649 | // close + undo button, info area, define line y-positions: |
---|
1650 | |
---|
1651 | int cur_x, cur_y, start_x, first_line_y, second_line_y, third_line_y; |
---|
1652 | get_at_position(&start_x, &first_line_y); |
---|
1653 | button_length(6); |
---|
1654 | |
---|
1655 | at(start_x, first_line_y); |
---|
1656 | help_text("quit.hlp"); |
---|
1657 | callback(AW_POPDOWN); |
---|
1658 | create_button("Close", "Close"); |
---|
1659 | |
---|
1660 | get_at_position(&cur_x, &cur_y); |
---|
1661 | |
---|
1662 | int gene_x = cur_x; |
---|
1663 | at_newline(); |
---|
1664 | get_at_position(&cur_x, &second_line_y); |
---|
1665 | |
---|
1666 | at(start_x, second_line_y); |
---|
1667 | help_text("undo.hlp"); |
---|
1668 | callback(makeWindowCallback(GEN_undo_cb, GB_UNDO_UNDO, gb_main)); |
---|
1669 | create_button("Undo", "Undo"); |
---|
1670 | |
---|
1671 | at_newline(); |
---|
1672 | get_at_position(&cur_x, &third_line_y); |
---|
1673 | |
---|
1674 | button_length(AWAR_FOOTER_MAX_LEN); |
---|
1675 | create_button(NULp, AWAR_FOOTER); |
---|
1676 | |
---|
1677 | at_newline(); |
---|
1678 | get_at_position(&cur_x, &cur_y); |
---|
1679 | set_info_area_height(cur_y+6); |
---|
1680 | |
---|
1681 | // gene+species buttons: |
---|
1682 | button_length(20); |
---|
1683 | |
---|
1684 | at(gene_x, first_line_y); |
---|
1685 | help_text("sp_search.hlp"); |
---|
1686 | callback(makeCreateWindowCallback(DBUI::create_species_query_window, gb_main)); // @@@ should use an organism search (using ITEM_organism) |
---|
1687 | create_button("SEARCH_ORGANISM", AWAR_LOCAL_ORGANISM_NAME(window_nr)); |
---|
1688 | |
---|
1689 | at(gene_x, second_line_y); |
---|
1690 | help_text("gene_search.hlp"); |
---|
1691 | callback(makeCreateWindowCallback(GEN_create_gene_query_window, gb_main)); |
---|
1692 | create_button("SEARCH_GENE", AWAR_LOCAL_GENE_NAME(window_nr)); |
---|
1693 | |
---|
1694 | get_at_position(&cur_x, &cur_y); |
---|
1695 | int lock_x = cur_x; |
---|
1696 | |
---|
1697 | at(lock_x, first_line_y); |
---|
1698 | create_toggle(AWAR_LOCAL_ORGANISM_LOCK(window_nr)); |
---|
1699 | |
---|
1700 | at(lock_x, second_line_y); |
---|
1701 | create_toggle(AWAR_LOCAL_GENE_LOCK(window_nr)); |
---|
1702 | |
---|
1703 | get_at_position(&cur_x, &cur_y); |
---|
1704 | int dtype_x1 = cur_x; |
---|
1705 | |
---|
1706 | // display type buttons: |
---|
1707 | |
---|
1708 | button_length(4); |
---|
1709 | |
---|
1710 | at(dtype_x1, first_line_y); |
---|
1711 | help_text("gen_disp_style.hlp"); |
---|
1712 | callback(makeWindowCallback(GEN_set_display_style, GEN_DISPLAY_STYLE_RADIAL)); |
---|
1713 | create_button("RADIAL_DISPLAY_TYPE", "#gen_radial.xpm"); |
---|
1714 | |
---|
1715 | help_text("gen_disp_style.hlp"); |
---|
1716 | callback(makeWindowCallback(GEN_set_display_style, GEN_DISPLAY_STYLE_BOOK)); |
---|
1717 | create_button("BOOK_DISPLAY_TYPE", "#gen_book.xpm"); |
---|
1718 | |
---|
1719 | get_at_position(&cur_x, &cur_y); |
---|
1720 | int jump_x = cur_x; |
---|
1721 | |
---|
1722 | at(dtype_x1, second_line_y); |
---|
1723 | help_text("gen_disp_style.hlp"); |
---|
1724 | callback(makeWindowCallback(GEN_set_display_style, GEN_DISPLAY_STYLE_VERTICAL)); |
---|
1725 | create_button("VERTICAL_DISPLAY_TYPE", "#gen_vertical.xpm"); |
---|
1726 | |
---|
1727 | // jump button: |
---|
1728 | |
---|
1729 | button_length(0); |
---|
1730 | |
---|
1731 | at(jump_x, first_line_y); |
---|
1732 | help_text("gen_jump.hlp"); |
---|
1733 | callback(makeWindowCallback(GEN_jump_cb, true)); |
---|
1734 | create_button("Jump", "Jump"); |
---|
1735 | |
---|
1736 | // help buttons: |
---|
1737 | |
---|
1738 | get_at_position(&cur_x, &cur_y); |
---|
1739 | int help_x = cur_x; |
---|
1740 | |
---|
1741 | at(help_x, first_line_y); |
---|
1742 | help_text("help.hlp"); |
---|
1743 | callback(makeHelpCallback("gene_map.hlp")); |
---|
1744 | create_button("HELP", "HELP", "H"); |
---|
1745 | |
---|
1746 | at(help_x, second_line_y); |
---|
1747 | callback(AW_help_entry_pressed); |
---|
1748 | create_button(NULp, "?"); |
---|
1749 | } |
---|