ARB
ED4_visualizeSAI.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : ED4_visualizeSAI.cxx //
4 // Purpose : Visualize sequence associated information (SAI) //
5 // in the Editor //
6 // //
7 // Coded by Yadhu Kumar //
8 // Institute of Microbiology (Technical University Munich) //
9 // http://www.arb-home.de/ //
10 // //
11 // =============================================================== //
12 
13 #include <ed4_extern.hxx>
14 #include "ed4_class.hxx"
15 
16 #include <awt_canvas.hxx>
17 #include <awt_sel_boxes.hxx>
18 #include <awt_prompt.hxx>
19 
20 #include <aw_awars.hxx>
21 #include <aw_preset.hxx>
22 #include <aw_msg.hxx>
23 #include <aw_root.hxx>
24 #include <aw_question.hxx>
25 #include <aw_select.hxx>
26 
27 #include <arbdbt.h>
28 #include <ad_cb.h>
29 
30 #include <arb_strbuf.h>
31 
32 #include <iostream>
33 
34 // --------------------------------------------------------------------------------
35 
36 #define AWAR_SAI_CLR_TAB "saicolors/"
37 #define AWAR_SAI_VISUALIZED AWAR_SAI_CLR_TAB "current" // current visualized SAI
38 #define AWAR_SAI_CLR_DEF AWAR_SAI_CLR_TAB "clr_trans_tab/" // container for definitions
39 #define AWAR_SAI_ENABLE AWAR_SAI_CLR_TAB "enable" // global enable of visualization
40 #define AWAR_SAI_ALL_SPECIES AWAR_SAI_CLR_TAB "all_species" // 1 = all / 0 = marked
41 #define AWAR_SAI_AUTO_SELECT AWAR_SAI_CLR_TAB "auto_select" // 1 = auto select / 0 = manual select
42 #define AWAR_SAI_CLR_TRANS_TABLE AWAR_SAI_CLR_TAB "clr_trans_table" // current translation table
43 #define AWAR_SAI_CLR_TRANS_TAB_NAMES AWAR_SAI_CLR_TAB "clr_trans_tab_names" // ;-separated list of existing translation tables
44 #define AWAR_SAI_CLR_TRANS_TAB_REL AWAR_SAI_CLR_TAB "sai_relation/" // container to store trans tables for each SAI
45 
46 #define AWAR_SAI_CLR "tmp/sai/color_0" // the definition of the current translation table (number runs from 0 to 9)
47 #define AWAR_SAI_CLR_COUNT 10
48 
49 // --------------------------------------------------------------------------------
50 
51 extern GBDATA *GLOBAL_gb_main;
52 
53 static bool clrDefinitionsChanged = false;
54 static bool inCallback = false; // used to avoid multiple refreshes
55 static bool in_colorDefChanged_callback = false; // used to avoid colorDef correction
56 
57 // --------------------------------------------------------------------------------
58 
59 #define BUFSIZE 100
60 static const char *getAwarName(int awarNo) {
61  static char buf[BUFSIZE];
62 
63  strcpy(buf, AWAR_SAI_CLR);
64  (strchr(buf, 0)-1)[0] = '0'+awarNo;
65 
66  return buf;
67 }
68 
69 static const char *getClrDefAwar(const char *awarName) {
70  static char buf[BUFSIZE];
71 
72  e4_assert(awarName);
73  e4_assert(awarName[0]); // empty awar is bad
74 
75  IF_ASSERTION_USED(int size =) sprintf(buf, AWAR_SAI_CLR_DEF "%s", awarName);
76  e4_assert(size<BUFSIZE);
77  return buf;
78 }
79 #undef BUFSIZE
80 
81 // ---------------------------------------------------------
82 
83 static void setVisualizeSAI_cb(AW_root *awr) {
86 }
87 
91 }
92 
93 static bool colorTransTable_exists(AW_root *awr, const char *name) {
94  char *tableNames = awr->awar(AWAR_SAI_CLR_TRANS_TAB_NAMES)->read_string();
95  const char *searchFrom = tableNames;
96  int len = strlen(name);
97 
98  while (searchFrom) {
99  const char *found = strstr(searchFrom, name);
100 
101  if (found) {
102  if ((found == tableNames || found[-1] == '\n') && // found start of entry
103  (found[len] == '\n' || found[len] == 0)) // avoid partial entry
104  {
105  break; // exists!
106  }
107  else { // search next match
108  searchFrom = found+1;
109  }
110  }
111  else {
112  searchFrom = NULp;
113  }
114  }
115 
116  free(tableNames);
117  return searchFrom;
118 }
119 
120 static void colorDefChanged_callback(AW_root *awr, int awarNo) {
121  clrDefinitionsChanged = true;
122 
123  if (!in_colorDefChanged_callback) { // this callback is special, because it may change all other color defs
125 
126  {
127  LocallyModify<bool> in_cb(inCallback, true);
128 
129  char *clrTabName = awr->awar(AWAR_SAI_CLR_TRANS_TABLE)->read_string();
130  if (clrTabName[0]) {
131  unsigned char charUsed[256]; memset(charUsed, 255, 256);
132 
133  {
134  for (int i=0; i<10; i++) {
135  char *awarString_next = awr->awar_string(getAwarName(i))->read_string();
136  for (int c=0; awarString_next[c]; ++c) {
137  charUsed[(unsigned char)awarString_next[c]] = i;
138  }
139  free(awarString_next);
140  }
141 
142  char *awarString = awr->awar_string(getAwarName(awarNo))->read_string();
143  for (int c=0; awarString[c]; ++c) {
144  charUsed[(unsigned char)awarString[c]] = awarNo;
145  }
146  free(awarString);
147  }
148 
149  typedef unsigned char mystr[256];
150  mystr s[10];
151  for (int i=0; i<10; i++) s[i][0]=0; // initializing the strings
152 
153  for (int i=0; i<256; i++) {
154  int table = charUsed[i];
155  if (table != 255) {
156  char *eos = strchr((char *)s[table], 0); // get pointer to end of string
157  eos[0] = char(i);
158  eos[1] = 0;
159  }
160  }
161 
162  {
163  GBS_strstruct clrDefStr(500);
164  for (int i=0; i<10; i++) {
165  awr->awar_string(getAwarName(i))->write_string((char *)s[i]);
166 
167  char *escaped = GBS_escape_string((char*)s[i], ";", '&');
168  clrDefStr.cat(escaped);
169  free(escaped);
170 
171  clrDefStr.put(';');
172  }
173 
174  AW_awar *awar_def = awr->awar_string(getClrDefAwar(clrTabName), "", AW_ROOT_DEFAULT);
175  awar_def->write_string(clrDefStr.get_data());
176  }
177  }
178  else {
179  if (!in_cb.old_value()) { // only warn when user really changed the setting
180  aw_message("Please select a VALID Color Translation Table to EDIT.");
181  }
182  }
183  free(clrTabName);
184  }
185 
187  }
188 }
189 
190 static AW_awar *sai_transtab_awar(AW_root *awr, const char *saiName) {
191  char *sai_key = GBS_string_2_key(saiName);
192  const char *awarname = GBS_global_string(AWAR_SAI_CLR_TRANS_TAB_REL "%s", sai_key);
193  free(sai_key);
194  return awr->awar_string(awarname, "", AW_ROOT_DEFAULT);
195 }
196 
198  char *clrTabName = awr->awar(AWAR_SAI_CLR_TRANS_TABLE)->read_string();
199  {
201  {
202  LocallyModify<bool> flag2(in_colorDefChanged_callback, true); // avoid correction
203 
204  // clear current translation table definition
205  for (int i=0; i<10; i++) {
206  AW_awar *transDef_awar = awr->awar_string(getAwarName(i), "", AW_ROOT_DEFAULT);
207  transDef_awar->write_string("");
208  }
209 
210  if (clrTabName[0]) {
211  AW_awar *clrTabDef_awar = awr->awar_string(getClrDefAwar(clrTabName), "", AW_ROOT_DEFAULT);
212  char *clrTabDef = clrTabDef_awar->read_string();
213 
214  if (clrTabDef[0]) {
215  int i = 0;
216  int tokStart = 0;
217 
218  for (int si = 0; clrTabDef[si]; ++si) {
219  if (clrTabDef[si] == ';') {
220  e4_assert(i >= 0 && i<10);
221  AW_awar *awar = awr->awar(getAwarName(i));
222 
223  if (tokStart == si) { // empty definition
224  awar->write_string("");
225  }
226  else {
227  int toklen = si-tokStart;
228 
229  e4_assert(toklen > 0);
230  e4_assert(clrTabDef[tokStart+toklen] == ';');
231  clrTabDef[tokStart+toklen] = 0;
232 
233  char *unescaped = GBS_unescape_string(clrTabDef+tokStart, ";", '&');
234  awar->write_string(unescaped);
235  free(unescaped);
236 
237  clrTabDef[tokStart+toklen] = ';';
238  }
239  ++i;
240  tokStart = si+1;
241  }
242  }
243  e4_assert(i == 10);
244  }
245  free(clrTabDef);
246  }
247  }
248  colorDefChanged_callback(awr, 0); // correct first def manually
249 
250  // store the selected table as default for the visualized SAI:
251  const char *saiName = awr->awar(AWAR_SAI_VISUALIZED)->read_char_pntr();
252  if (saiName[0]) sai_transtab_awar(awr, saiName)->write_string(clrTabName);
253  }
254  free(clrTabName);
255 
257 }
258 
259 static void refresh_display_cb(GB_CB_TYPE cb_type) {
260  if ((cb_type & GB_CB_CHANGED) &&
262  {
265  }
266 }
267 
268 static void saiChanged_callback(AW_root *awr) {
269  char *saiName = NULp;
270  {
272  {
273  static GBDATA *gb_last_SAI = NULp;
274 
275  if (gb_last_SAI) {
276  GB_transaction ta(GLOBAL_gb_main);
277  GB_remove_callback(gb_last_SAI, GB_CB_CHANGED, makeDatabaseCallback(refresh_display_cb));
278  gb_last_SAI = NULp;
279  }
280 
281  saiName = awr->awar(AWAR_SAI_VISUALIZED)->read_string();
282  char *transTabName = NULp;
283 
284  if (saiName[0]) {
285  transTabName = sai_transtab_awar(awr, saiName)->read_string();
286  }
287 
288  {
289  GB_transaction ta(GLOBAL_gb_main);
290  gb_last_SAI = GBT_find_SAI(GLOBAL_gb_main, saiName);
291  if (gb_last_SAI) {
292  GB_add_callback(gb_last_SAI, GB_CB_CHANGED, makeDatabaseCallback(refresh_display_cb));
293  }
294  }
295  awr->awar(AWAR_SAI_CLR_TRANS_TABLE)->write_string(null2empty(transTabName));
296  free(transTabName);
297 
298  clrDefinitionsChanged = true; // SAI changed -> update needed
299  }
300  }
301 
303  // SAI changed notify Global SAI Awar AWAR_SAI_GLOBAL
304  awr->awar(AWAR_SAI_GLOBAL)->write_string(saiName);
306  }
307  free(saiName);
308 }
309 
310 static void update_ClrTransTabNamesList_cb(AW_root *awr, AW_selection_list *colorTransList) {
311  char *clrTransTabNames = awr->awar(AWAR_SAI_CLR_TRANS_TAB_NAMES)->read_string();
312 
313  colorTransList->clear();
314 
315  for (char *tok = strtok(clrTransTabNames, "\n"); tok; tok = strtok(NULp, "\n")) {
316  colorTransList->insert(tok, tok);
317  }
318  colorTransList->insert_default("????", "");
319  colorTransList->update();
320 
321  free(clrTransTabNames);
322 }
323 
324 static void autoselect_cb(AW_root *aw_root) {
325  char *curr_sai = aw_root->awar(AWAR_SAI_NAME)->read_string();
326 #if defined(DEBUG)
327  printf("curr_sai='%s'\n", curr_sai);
328 #endif // DEBUG
329  aw_root->awar(AWAR_SAI_VISUALIZED)->write_string(curr_sai);
330  free(curr_sai);
331 }
332 
333 static void set_autoselect_cb(AW_root *aw_root) {
334  static bool callback_active = false;
335 
336  if (aw_root->awar(AWAR_SAI_AUTO_SELECT)->read_int()) { // auto select is activated
338  callback_active = true;
339  }
340  else {
341  if (callback_active) { // only remove if added
343  callback_active = false;
344  }
345  }
346 }
347 
348 static void addOrUpdateTransTable(AW_root *aw_root, const char *newClrTransTabName, const char *defaultDefinition, bool autoselect) {
349  AW_awar *table_def_awar = aw_root->awar_string(getClrDefAwar(newClrTransTabName), defaultDefinition, AW_ROOT_DEFAULT);
350  table_def_awar->write_string(defaultDefinition);
351 
352  if (!colorTransTable_exists(aw_root, newClrTransTabName)) {
353  AW_awar *names_awar = aw_root->awar(AWAR_SAI_CLR_TRANS_TAB_NAMES);
354  const char *old_names = names_awar->read_char_pntr();
355  names_awar->write_string(old_names[0]
356  ? GBS_global_string("%s\n%s", old_names, newClrTransTabName)
357  : newClrTransTabName); // add new name
358  }
359 
360  if (autoselect) {
361  aw_root->awar(AWAR_SAI_CLR_TRANS_TABLE)->write_string(newClrTransTabName); // select new
362  }
363 }
364 
365 static void addDefaultTransTable(AW_root *aw_root, const char *newClrTransTabName, const char *defaultDefinition) {
366  addOrUpdateTransTable(aw_root, newClrTransTabName, defaultDefinition, false);
367 }
368 
369 void ED4_createVisualizeSAI_Awars(AW_root *aw_root, AW_default aw_def) { // --- Creating and initializing AWARS -----
370  aw_root->awar_int(AWAR_SAI_ENABLE, 0, aw_def);
371  aw_root->awar_int(AWAR_SAI_ALL_SPECIES, 0, aw_def);
372  aw_root->awar_int(AWAR_SAI_AUTO_SELECT, 0, aw_def);
373 
374  aw_root->awar_string(AWAR_SAI_VISUALIZED, "", aw_def);
375  aw_root->awar_string(AWAR_SAI_CLR_TRANS_TABLE, "", aw_def);
376  aw_root->awar_string(AWAR_SAI_CLR_TRANS_TAB_NAMES, "", aw_def);
377 
378  for (int i=0; i<10; i++) { // initializing 10 color definition string AWARS
379  AW_awar *def_awar = aw_root->awar_string(getAwarName(i), "", aw_def);
380  def_awar->add_callback(makeRootCallback(colorDefChanged_callback, i));
381  }
387 
390 
391  // create some defaults:
392  addDefaultTransTable(aw_root, "numeric", "0;1;2;3;4;5;6;7;8;9;");
393  addDefaultTransTable(aw_root, "binary", ".0;;+1;;;;;;;;");
394  addDefaultTransTable(aw_root, "consensus", "=ACGTU;;acgtu;.;;;;;;;");
395  addDefaultTransTable(aw_root, "PVP", "012;345;678;9ABab;CDEcde;FGHfgh;IJKLijkl;MNOPmnop;QRSTqrst;UVWXYZuvwxyz;");
396  addDefaultTransTable(aw_root, "helix", ";;<>;;;;;[];;;");
397  addDefaultTransTable(aw_root, "xstring", ";x;;;;;;;;;");
398  addDefaultTransTable(aw_root, "gaps", ";-.;;;;;;;;;");
399 
400  LocallyModify<bool> flag(inCallback, true); // avoid refresh
401  saiChanged_callback(aw_root);
402  colorDefTabNameChanged_callback(aw_root); // init awars for selected table
403  set_autoselect_cb(aw_root);
404 }
405 
407  ED4_VIS_CREATE, // creates a new (empty) color translation table
408  ED4_VIS_COPY, // copies the selected color translation table
409 };
410 
411 static GB_ERROR createCopy_table_handler(const char *dest_table_input, CreationMode mode) {
412  GB_ERROR error = NULp;
413  if (!dest_table_input[0]) error = "not a valid name";
414  else {
415  AW_root *aw_root = AW_root::SINGLETON;
416  char *dest_table = GBS_string_2_key(dest_table_input);
417  if (colorTransTable_exists(aw_root, dest_table)) {
418  error = GBS_global_string("Color translation table '%s' already exists.", dest_table);
419  }
420  else {
421  switch (mode) {
422  case ED4_VIS_CREATE:
423  addOrUpdateTransTable(aw_root, dest_table, "", true);
424  break;
425 
426  case ED4_VIS_COPY: {
427  const char *src_table = aw_root->awar(AWAR_SAI_CLR_TRANS_TABLE)->read_char_pntr();
428  if (!src_table[0]) error = "Please select a valid source table";
429  else {
430  const char *src_def = aw_root->awar(getClrDefAwar(src_table))->read_char_pntr();
431  addOrUpdateTransTable(aw_root, dest_table, src_def, true);
432  }
433  break;
434  }
435  }
436  }
437 
438  free(dest_table);
439  }
440  return error;
441 }
442 
444  AW_root *aw_root = aww->get_root();
445  const char *selected_table = aw_root->awar(AWAR_SAI_CLR_TRANS_TABLE)->read_char_pntr();
446  ResultHandler handler = makeResultHandler(createCopy_table_handler, mode);
447  const char *helpfile = "visualizeSAI.hlp";
448 
449  switch (mode) {
450  case ED4_VIS_CREATE: AWT_activate_prompt("Create new color translation table", "Enter name of new table:", selected_table, "Create", handler, helpfile); break;
451  case ED4_VIS_COPY: AWT_activate_prompt("Copy color translation table", "Enter destination table name:", selected_table, "Copy", handler, helpfile); break;
452  }
453 }
454 
456  AW_root *aw_root = aws->get_root();
457  const char *clrTabName = aw_root->awar_string(AWAR_SAI_CLR_TRANS_TABLE)->read_char_pntr();
458 
459  if (clrTabName[0]) {
460  AW_awar *awar_tabNames = aw_root->awar(AWAR_SAI_CLR_TRANS_TAB_NAMES);
461  char *clrTransTabNames = awar_tabNames->read_string();
462  GBS_strstruct newTransTabName(strlen(clrTransTabNames));
463 
464  for (const char *tok = strtok(clrTransTabNames, "\n"); tok; tok = strtok(NULp, "\n")) {
465  if (strcmp(clrTabName, tok) != 0) { // merge all not to delete
466  newTransTabName.cat(tok);
467  newTransTabName.put('\n');
468  }
469  }
470 
471  aw_root->awar_string(getClrDefAwar(clrTabName))->write_string("");
472  awar_tabNames->write_string(newTransTabName.get_data()); // updates selection list
473 
474  free(clrTransTabNames);
475  }
476  else {
477  aw_message("Selected Color Translation Table is not VALID and cannot be DELETED!");
478  }
479 }
480 
482  AW_root *awr = aws->get_root();
484 
485  update_ClrTransTabNamesList_cb(awr, colorTransList);
486 
487  return colorTransList;
488 }
489 
490 const char *ED4_getSaiColorString(AW_root *awr, int start, int end) {
491  static int seqBufferSize = 0;
492  static char *saiColors = NULp;
493  static int lastStart = -1;
494  static int lastEnd = -1;
495  static bool lastVisualize = false;
496 
497  e4_assert(start<=end);
498 
499  if (lastStart==start && lastEnd==end && !clrDefinitionsChanged && lastVisualize) {
500  return saiColors-start; // if start and end positions are same as the previous positions and no settings
501  } // were changed return the last calculated saiColors string
502 
503  lastStart = start; lastEnd = end; clrDefinitionsChanged = false; // storing start and end positions
504 
505  int seqSize = end-start+1;
506 
507  if (seqSize>seqBufferSize) {
508  free(saiColors);
509  seqBufferSize = seqSize;
510  ARB_calloc(saiColors, seqBufferSize);
511  }
512  else memset(saiColors, 0, sizeof(char)*seqSize);
513 
514  char *saiSelected = awr->awar(AWAR_SAI_VISUALIZED)->read_string();
515 
516  GB_push_transaction(GLOBAL_gb_main);
517  char *alignment_name = GBT_get_default_alignment(GLOBAL_gb_main);
518  GBDATA *gb_extended = GBT_find_SAI(GLOBAL_gb_main, saiSelected);
519  bool visualize = false; // set to true if all goes fine
520 
521  if (gb_extended) {
522  GBDATA *gb_ali = GB_entry(gb_extended, alignment_name);
523  if (gb_ali) {
524  const char *saiData = NULp;
525  bool free_saiData = false;
526 
527  {
528  GBDATA *saiSequence = GB_entry(gb_ali, "data"); // search "data" entry (normal SAI)
529  if (saiSequence) {
530  saiData = GB_read_char_pntr(saiSequence); // not allocated
531  }
532  else {
533  saiSequence = GB_entry(gb_ali, "bits"); // search "bits" entry (binary SAI)
534  if (saiSequence) {
535  saiData = GB_read_as_string(saiSequence); // allocated
536  free_saiData = true; // free saiData below
537  }
538  }
539  }
540 
541  if (saiData) {
542  char trans_table[256];
543  {
544  // build the translation table:
545  memset(trans_table, 0, 256);
546  for (int i = 0; i<AWAR_SAI_CLR_COUNT; ++i) {
547  char *def = awr->awar(getAwarName(i))->read_string();
548  int clrRange = ED4_G_CBACK_0 + i;
549 
550  for (char *d = def; *d; ++d) {
551  trans_table[(unsigned char)*d] = clrRange;
552  }
553  free(def);
554  }
555  }
556 
557  // translate SAI to colors
558  for (int i = start; i <= end; ++i) {
559  saiColors[i-start] = trans_table[(unsigned char)saiData[i]];
560  }
561 
562  visualize = true;
563  }
564 
565  if (free_saiData) {
566  free(const_cast<char*>(saiData)); // in this case saiData is allocated (see above)
567  }
568  }
569  }
570  free(alignment_name);
571  free(saiSelected);
572  GB_pop_transaction(GLOBAL_gb_main);
573 
574  lastVisualize = visualize;
575  if (visualize) {
576  e4_assert(saiColors);
577  return saiColors-start;
578  }
579 
580  return NULp; // don't visualize (sth went wrong)
581 }
582 
583 
584 // -------------------- Creating Windows and Display dialogs --------------------
585 
587  AW_root *aw_root = aww->get_root();
588 
589  int j = AWAR_SAI_CLR_COUNT-1;
590  for (int i = 0; i<AWAR_SAI_CLR_COUNT/2+1; ++i, --j) {
591  if (i<j) {
592  AW_awar *aw_i = aw_root->awar(getAwarName(i));
593  AW_awar *aw_j = aw_root->awar(getAwarName(j));
594 
595  char *ci = aw_i->read_string();
596  char *cj = aw_j->read_string();
597 
598  aw_i->write_string(cj);
599  aw_j->write_string(ci);
600 
601  free(ci);
602  free(cj);
603  }
604  }
605 }
606 
607 static AW_window *create_editColorTranslationTable_window(AW_root *aw_root) { // creates edit color translation table window
608  static AW_window_simple *aws = NULp;
609  if (!aws) {
610  aws = new AW_window_simple;
611  aws->init(aw_root, "EDIT_CTT", "Color Translation Table");
612  aws->load_xfig("saiColorRange.fig");
613 
614  char at_name[] = "rangex";
615  char *dig = strchr(at_name, 0)-1;
616 
617  for (int i = 0; i<AWAR_SAI_CLR_COUNT; ++i) {
618  dig[0] = '0'+i;
619  aws->at(at_name);
620  aws->create_input_field(getAwarName(i), 20);
621  }
622 
623  aws->at("close");
624  aws->callback(AW_POPDOWN);
625  aws->create_button("CLOSE", "CLOSE", "C");
626 
627  aws->at("reverse");
628  aws->callback(reverseColorTranslationTable);
629  aws->create_button("REVERSE", "Reverse", "R");
630 
631  aws->at("colors");
632  aws->callback(makeWindowCallback(ED4_popup_gc_window, ED4_ROOT->gc_manager));
633  aws->button_length(0);
634  aws->create_button("COLORS", "#colors.xpm");
635  }
636  return aws;
637 }
638 
640  static AW_window_simple *aws = NULp;
641  if (!aws) {
642  aws = new AW_window_simple;
643 
644  aws->init(aw_root, "VISUALIZE_SAI", "Visualize SAIs");
645  aws->load_xfig("visualizeSAI.fig");
646 
647  aws->callback(makeHelpCallback("visualizeSAI.hlp"));
648  aws->at("help");
649  aws->create_button("HELP", "HELP", "H");
650 
651  aws->at("close");
652  aws->callback(AW_POPDOWN);
653  aws->create_button("CLOSE", "CLOSE", "C");
654 
655  aws->at("enable");
656  aws->create_toggle(AWAR_SAI_ENABLE);
657 
658  aws->at("sai");
659  aws->button_length(30);
661 
662  aws->at("auto_select");
663  aws->create_toggle(AWAR_SAI_AUTO_SELECT);
664 
665  aws->at("clrTrList");
666  AW_selection_list *clrTransTableLst = buildClrTransTabNamesList(aws);
667 
668  aws->at("edit");
669  aws->button_length(10);
671  aws->create_button("EDIT", "EDIT");
672 
673  aws->at("create");
674  aws->callback(makeWindowCallback(createCopy_ClrTransTab_cb, ED4_VIS_CREATE));
675  aws->create_button("CREATE", "CREATE");
676 
677  aws->at("copy");
678  aws->callback(makeWindowCallback(createCopy_ClrTransTab_cb, ED4_VIS_COPY));
679  aws->create_button("COPY", "COPY");
680 
681  aws->at("delete");
682  aws->callback(deleteColorTranslationTable);
683  aws->create_button("DELETE", "DELETE");
684 
685  aws->at("marked");
686  aws->create_toggle_field(AWAR_SAI_ALL_SPECIES, 1);
687  aws->insert_toggle("MARKED SPECIES", "M", 0);
688  aws->insert_toggle("ALL SPECIES", "A", 1);
689  aws->update_toggle_field();
690 
691  AW_awar *trans_tabs = aw_root->awar(AWAR_SAI_CLR_TRANS_TAB_NAMES);
692  trans_tabs->add_callback(makeRootCallback(update_ClrTransTabNamesList_cb, clrTransTableLst));
693  trans_tabs->touch(); // force update
694  }
695  aws->show();
696 
697  return aws;
698 }
699 
const char * GB_ERROR
Definition: arb_core.h:25
#define AWAR_SAI_ALL_SPECIES
static AW_selection_list * buildClrTransTabNamesList(AW_window *aws)
static void reverseColorTranslationTable(AW_window *aww)
void insert_default(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:385
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
Definition: ad_cb.cxx:356
const char * ED4_getSaiColorString(AW_root *awr, int start, int end)
#define AWAR_SAI_ENABLE
static const char * getClrDefAwar(const char *awarName)
static void autoselect_cb(AW_root *aw_root)
static void createCopy_ClrTransTab_cb(AW_window *aww, CreationMode mode)
static AW_window * create_editColorTranslationTable_window(AW_root *aw_root)
char * GB_read_as_string(GBDATA *gbd)
Definition: arbdb.cxx:1030
long read_int() const
Definition: AW_awar.cxx:187
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
#define AWAR_SAI_VISUALIZED
ED4_root * ED4_ROOT
Definition: ED4_main.cxx:48
static char * alignment_name
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
char * GBS_escape_string(const char *str, const char *chars_to_escape, char escape_char)
Definition: adstring.cxx:124
char * GBS_string_2_key(const char *str)
Definition: adstring.cxx:52
void cat(const char *from)
Definition: arb_strbuf.h:156
static void deleteColorTranslationTable(AW_window *aws)
#define AWAR_SAI_CLR_TRANS_TAB_NAMES
void awt_create_SAI_selection_button(GBDATA *gb_main, AW_window *aws, const char *varname, const SaiSelectionlistFilterCallback &fcb)
static void setVisualizeSAI_cb(AW_root *awr)
AW_gc_manager * gc_manager
Definition: ed4_class.hxx:1444
static void refresh_display_cb(GB_CB_TYPE cb_type)
static bool in_colorDefChanged_callback
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2458
static GB_ERROR createCopy_table_handler(const char *dest_table_input, CreationMode mode)
CreationMode
#define e4_assert(bed)
Definition: ed4_class.hxx:11
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
void insert(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:380
static HelixNrInfo * start
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:172
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
static AW_root * SINGLETON
Definition: aw_root.hxx:102
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
#define AWAR_SAI_CLR_DEF
const char * awarname(const char *awarname_template, int idx)
Definition: ED4_flags.cxx:37
#define AWAR_SAI_GLOBAL
AW_selection_list * create_selection_list(const char *awar_name, int columns, int rows, bool fallback2default)
Definition: AW_button.cxx:1212
static void colorDefChanged_callback(AW_root *awr, int awarNo)
void touch()
Definition: AW_awar.cxx:210
static void error(const char *msg)
Definition: mkptypes.cxx:96
void ED4_createVisualizeSAI_Awars(AW_root *aw_root, AW_default aw_def)
static void addDefaultTransTable(AW_root *aw_root, const char *newClrTransTabName, const char *defaultDefinition)
static void setVisualizeSAI_options_cb(AW_root *awr)
#define AWAR_SAI_NAME
GBDATA * GLOBAL_gb_main
Definition: DI_main.cxx:27
char * read_string() const
Definition: AW_awar.cxx:201
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2488
#define AWAR_SAI_CLR_TRANS_TABLE
AW_awar * remove_callback(const RootCallback &cb)
Definition: AW_awar.cxx:527
long int flag
Definition: f2c.h:39
char * GBS_unescape_string(const char *str, const char *escaped_chars, char escape_char)
Definition: adstring.cxx:175
static bool colorTransTable_exists(AW_root *awr, const char *name)
#define AWAR_SAI_AUTO_SELECT
bool visualizeSAI_allSpecies
Definition: ed4_class.hxx:1458
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
TYPE * ARB_calloc(size_t nelem)
Definition: arb_mem.h:81
#define IF_ASSERTION_USED(x)
Definition: arb_assert.h:308
bool visualizeSAI
Definition: ed4_class.hxx:1457
static bool clrDefinitionsChanged
static void set_autoselect_cb(AW_root *aw_root)
#define AWAR_SAI_CLR_COUNT
void GB_remove_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
Definition: ad_cb.cxx:360
AW_root * aw_root
Definition: ed4_class.hxx:1424
static void update_ClrTransTabNamesList_cb(AW_root *awr, AW_selection_list *colorTransList)
static void colorDefTabNameChanged_callback(AW_root *awr)
void aw_message(const char *msg)
Definition: AW_status.cxx:932
void ED4_popup_gc_window(AW_window *awp, AW_gc_manager *gcman)
Definition: ED4_root.cxx:1255
AW_window * ED4_createVisualizeSAI_window(AW_root *aw_root)
AW_root * get_root()
Definition: aw_window.hxx:348
static void saiChanged_callback(AW_root *awr)
#define NULp
Definition: cxxforward.h:97
void request_refresh_for_sequence_terminals()
Definition: ED4_root.cxx:106
static bool inCallback
#define AWAR_SAI_CLR_TRANS_TAB_REL
GB_ERROR write_string(const char *aw_string)
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:675
const char * get_data() const
Definition: arb_strbuf.h:70
T old_value() const
Definition: arbtools.h:135
static const char * getAwarName(int awarNo)
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:874
static AW_awar * sai_transtab_awar(AW_root *awr, const char *saiName)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
static void addOrUpdateTransTable(AW_root *aw_root, const char *newClrTransTabName, const char *defaultDefinition, bool autoselect)
GB_CB_TYPE
Definition: arbdb_base.h:46
#define AWAR_SAI_CLR
#define BUFSIZE
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
void put(char c)
Definition: arb_strbuf.h:138
void AWT_activate_prompt(const char *title, const char *prompt, const char *defaultResult, const char *button, const ResultHandler &handle_result, const char *helpfile, const char *srt)
Definition: AWT_prompt.cxx:62
GB_write_int const char s
Definition: AW_awar.cxx:156