| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : PH_main.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #include "phylo.hxx" |
|---|
| 12 | #include "phwin.hxx" |
|---|
| 13 | #include "PH_display.hxx" |
|---|
| 14 | |
|---|
| 15 | #include <awt_sel_boxes.hxx> |
|---|
| 16 | #include <aw_preset.hxx> |
|---|
| 17 | #include <aw_awar.hxx> |
|---|
| 18 | #include <aw_msg.hxx> |
|---|
| 19 | #include <awt.hxx> |
|---|
| 20 | #include <aw_root.hxx> |
|---|
| 21 | #include <arbdbt.h> |
|---|
| 22 | #include <arb_strarray.h> |
|---|
| 23 | |
|---|
| 24 | #include <macros.hxx> |
|---|
| 25 | #include <aw_question.hxx> |
|---|
| 26 | |
|---|
| 27 | AW_HEADER_MAIN |
|---|
| 28 | |
|---|
| 29 | const char *filter_text[FILTER_MODES] = { |
|---|
| 30 | "don't count (ignore) ", // DONT_COUNT |
|---|
| 31 | "if occurs most often => forget whole column", // SKIP_COLUMN_IF_MAX |
|---|
| 32 | "if occurs => forget whole column ", // SKIP_COLUMN_IF_OCCUR |
|---|
| 33 | "count, but do NOT use as maximum ", // COUNT_DONT_USE_MAX |
|---|
| 34 | "treat as uppercase character ", // TREAT_AS_UPPERCASE |
|---|
| 35 | "treat as regular character ", // TREAT_AS_REGULAR |
|---|
| 36 | }; |
|---|
| 37 | |
|---|
| 38 | static bool valid_alignment_selected(AW_root *aw_root, GBDATA *gb_main) { |
|---|
| 39 | GB_transaction ta(gb_main); |
|---|
| 40 | const char *aliname = aw_root->awar(AWAR_PHYLO_ALIGNMENT)->read_char_pntr(); |
|---|
| 41 | if (GBT_get_alignment_len(gb_main, aliname)<1) { |
|---|
| 42 | GB_clear_error(); |
|---|
| 43 | return false; |
|---|
| 44 | } |
|---|
| 45 | return true; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | static void startup_sequence_cb(AW_window *alisel_window, AW_window *main_window, PH_root *ph_root) { |
|---|
| 49 | AW_root *aw_root = main_window->get_root(); |
|---|
| 50 | GBDATA *gb_main = ph_root->get_gb_main(); |
|---|
| 51 | |
|---|
| 52 | if (valid_alignment_selected(aw_root, gb_main)) { |
|---|
| 53 | char *use = aw_root->awar(AWAR_PHYLO_ALIGNMENT)->read_string(); |
|---|
| 54 | PHDATA *phd = new PHDATA(aw_root, ph_root); |
|---|
| 55 | |
|---|
| 56 | GB_ERROR error = GBT_set_startup_alignment(gb_main, use); // freeze default alignment in ARB_PHYLO (AFAIK it is not used, but will prevent wrong future use) |
|---|
| 57 | if (error) { |
|---|
| 58 | aw_message(error); |
|---|
| 59 | } |
|---|
| 60 | else { |
|---|
| 61 | if (alisel_window) alisel_window->hide(); |
|---|
| 62 | |
|---|
| 63 | GB_set_cache_size(gb_main, PH_DB_CACHE_SIZE); |
|---|
| 64 | phd->load(use); |
|---|
| 65 | phd->ROOT = phd; |
|---|
| 66 | |
|---|
| 67 | long len = PHDATA::ROOT->get_seq_len(); // @@@ off by one? |
|---|
| 68 | aw_root->awar(AWAR_PHYLO_FILTER_STOPCOL)->write_int(len); |
|---|
| 69 | aw_root->awar(AWAR_PHYLO_FILTER_STARTCOL)->set_minmax(0, len); |
|---|
| 70 | aw_root->awar(AWAR_PHYLO_FILTER_STOPCOL)->set_minmax(0, len); |
|---|
| 71 | |
|---|
| 72 | main_window->activate(); |
|---|
| 73 | ph_view_species_cb(); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | else { |
|---|
| 77 | if (alisel_window) { |
|---|
| 78 | aw_message("Please select a valid alignment"); |
|---|
| 79 | } |
|---|
| 80 | else { |
|---|
| 81 | GBK_terminate("Expected to have a valid alignment"); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | __ATTR__NORETURN static void ph_exit(AW_window *aw_window, PH_root *ph_root) { |
|---|
| 87 | AW_root *aw_root = aw_window->get_root(); |
|---|
| 88 | shutdown_macro_recording(aw_root); |
|---|
| 89 | |
|---|
| 90 | GBDATA *gb_main = ph_root->get_gb_main(); |
|---|
| 91 | if (gb_main) { |
|---|
| 92 | aw_root->unlink_awars_from_DB(gb_main); |
|---|
| 93 | #if defined(DEBUG) |
|---|
| 94 | AWT_browser_forget_db(gb_main); |
|---|
| 95 | #endif // DEBUG |
|---|
| 96 | GB_close(gb_main); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | exit(EXIT_SUCCESS); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | void expose_cb() { |
|---|
| 104 | if (PH_display::ph_display && PH_display::ph_display->displayed()!=DISP_NONE) { |
|---|
| 105 | PH_display::ph_display->clear_window(); |
|---|
| 106 | PH_display::ph_display->display(); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | static void resize_cb() { |
|---|
| 111 | if (PH_display::ph_display) { |
|---|
| 112 | PH_display::ph_display->resized(); |
|---|
| 113 | PH_display::ph_display->display(); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | static void gc_changed_cb(GcChange whatChanged) { |
|---|
| 118 | switch (whatChanged) { |
|---|
| 119 | case GC_COLOR_GROUP_USE_CHANGED: |
|---|
| 120 | ph_assert(0); // not used atm |
|---|
| 121 | FALLTHROUGH; // in NDEBUG |
|---|
| 122 | case GC_COLOR_CHANGED: |
|---|
| 123 | expose_cb(); |
|---|
| 124 | break; |
|---|
| 125 | case GC_FONT_CHANGED: |
|---|
| 126 | resize_cb(); |
|---|
| 127 | break; |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | static GB_ERROR PH_create_ml_multiline_SAI(GB_CSTR sai_name, int nr, GBDATA **gb_sai_ptr, PH_root *ph_root) { |
|---|
| 132 | GBDATA *gb_sai = GBT_find_or_create_SAI(ph_root->get_gb_main(), sai_name); |
|---|
| 133 | GBDATA *gbd, *gb2; |
|---|
| 134 | GB_ERROR error = ph_check_initialized(); |
|---|
| 135 | |
|---|
| 136 | if (!error) { |
|---|
| 137 | for (gbd = GB_child(gb_sai); gbd; gbd = gb2) { |
|---|
| 138 | gb2 = GB_nextChild(gbd); |
|---|
| 139 | |
|---|
| 140 | const char *key = GB_read_key_pntr(gbd); |
|---|
| 141 | if (!strcmp(key, "name")) continue; |
|---|
| 142 | if (!strncmp(key, "ali_", 4)) continue; |
|---|
| 143 | |
|---|
| 144 | error = GB_delete(gbd); |
|---|
| 145 | if (error) break; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | if (!error) { |
|---|
| 150 | GBDATA *gb_ali = GB_search(gb_sai, PHDATA::ROOT->use, GB_FIND); |
|---|
| 151 | if (gb_ali) { |
|---|
| 152 | for (gbd = GB_child(gb_ali); gbd; gbd = gb2) { |
|---|
| 153 | gb2 = GB_nextChild(gbd); |
|---|
| 154 | |
|---|
| 155 | const char *key = GB_read_key_pntr(gbd); |
|---|
| 156 | if (!strcmp(key, "data")) continue; |
|---|
| 157 | if (!strcmp(key, "_TYPE")) continue; |
|---|
| 158 | |
|---|
| 159 | error = GB_delete(gbd); |
|---|
| 160 | if (error) break; |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | GBDATA *gb_data = NULp, *gb_TYPE = NULp; |
|---|
| 166 | |
|---|
| 167 | if (!error) { |
|---|
| 168 | gb_data = GBT_add_data(gb_sai, PHDATA::ROOT->use, "data", GB_STRING); |
|---|
| 169 | if (!gb_data) error = GB_await_error(); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | if (!error) { |
|---|
| 173 | gb_TYPE = GBT_add_data(gb_sai, PHDATA::ROOT->use, "_TYPE", GB_STRING); |
|---|
| 174 | if (!gb_TYPE) error = GB_await_error(); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | if (!error && !PHDATA::ROOT->markerline) { |
|---|
| 178 | error = "Nothing calculated yet"; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | if (!error) { |
|---|
| 182 | char *full_save_name = NULp; |
|---|
| 183 | FILE *saveResults = NULp; |
|---|
| 184 | if (nr == 2) { |
|---|
| 185 | char *save_name = GB_unique_filename("conservationProfile", "gnu"); |
|---|
| 186 | saveResults = GB_fopen_tempfile(save_name, "w+", &full_save_name); |
|---|
| 187 | GB_remove_on_exit(full_save_name); |
|---|
| 188 | free(save_name); |
|---|
| 189 | |
|---|
| 190 | if (!saveResults) error = GB_await_error(); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | if (!error) { |
|---|
| 194 | AW_window *main_win = PH_used_windows::windowList->phylo_main_window; |
|---|
| 195 | long minhom = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int(); |
|---|
| 196 | long maxhom = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int(); |
|---|
| 197 | long startcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int(); |
|---|
| 198 | long stopcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int(); |
|---|
| 199 | float *markerline = PHDATA::ROOT->markerline; |
|---|
| 200 | long len = PHDATA::ROOT->get_seq_len(); |
|---|
| 201 | |
|---|
| 202 | char *data = ARB_calloc<char>(len+1); |
|---|
| 203 | int cnt = 0; |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | for (int x=0; x<len; x++) { |
|---|
| 207 | char c; |
|---|
| 208 | |
|---|
| 209 | if (x<startcol || x>stopcol) { |
|---|
| 210 | c = '.'; |
|---|
| 211 | } |
|---|
| 212 | else { |
|---|
| 213 | float ml = markerline[x]; |
|---|
| 214 | if (nr==2 && ml>0.0) { |
|---|
| 215 | ph_assert(saveResults); |
|---|
| 216 | fprintf(saveResults, "%i\t%.2f\n", cnt, ml); |
|---|
| 217 | cnt++; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | if (ml>=0.0 && ml>=minhom && ml<=maxhom) { |
|---|
| 221 | int digit = -1; |
|---|
| 222 | switch (nr) { |
|---|
| 223 | case 0: // hundred |
|---|
| 224 | if (ml>=100.0) digit = 1; |
|---|
| 225 | break; |
|---|
| 226 | case 1: // ten |
|---|
| 227 | if (ml>=10.0) digit = int(ml/10); |
|---|
| 228 | break; |
|---|
| 229 | case 2: // one |
|---|
| 230 | digit = int(ml); |
|---|
| 231 | break; |
|---|
| 232 | default: |
|---|
| 233 | ph_assert(0); |
|---|
| 234 | break; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | if (digit<0) c = '-'; |
|---|
| 238 | else c = '0' + digit%10; |
|---|
| 239 | } |
|---|
| 240 | else { |
|---|
| 241 | c = '-'; |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | data[x] = c; |
|---|
| 246 | } |
|---|
| 247 | data[len] = 0; |
|---|
| 248 | |
|---|
| 249 | if (saveResults) { |
|---|
| 250 | fclose(saveResults); |
|---|
| 251 | fprintf(stderr, "Note: Frequencies as well saved to '%s'\n", full_save_name); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | error = GB_write_string(gb_data, data); |
|---|
| 255 | if (!error) { |
|---|
| 256 | const char *buffer = GBS_global_string("FMX: Filter by Maximum Frequency: " |
|---|
| 257 | "Start %li; Stop %li; Minhom %li%%; Maxhom %li%%", |
|---|
| 258 | startcol, stopcol, minhom, maxhom); |
|---|
| 259 | error = GB_write_string(gb_TYPE, buffer); |
|---|
| 260 | } |
|---|
| 261 | free(data); |
|---|
| 262 | } |
|---|
| 263 | free(full_save_name); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | if (!error) *gb_sai_ptr = gb_sai; |
|---|
| 267 | return error; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | static void PH_save_ml_multiline_cb(AW_window *aww, PH_root *ph_root) { |
|---|
| 271 | GB_transaction ta(ph_root->get_gb_main()); |
|---|
| 272 | |
|---|
| 273 | GB_ERROR error = NULp; |
|---|
| 274 | char *fname = aww->get_root()->awar(AWAR_PHYLO_MARKERLINENAME)->read_string(); |
|---|
| 275 | int fname_len = strlen(fname); |
|---|
| 276 | { |
|---|
| 277 | char *digit_appended = ARB_alloc<char>(fname_len+2); |
|---|
| 278 | memcpy(digit_appended, fname, fname_len); |
|---|
| 279 | strcpy(digit_appended+fname_len, "0"); |
|---|
| 280 | |
|---|
| 281 | freeset(fname, digit_appended); |
|---|
| 282 | } |
|---|
| 283 | GBDATA *gb_sai[3]; |
|---|
| 284 | int i; |
|---|
| 285 | for (i=0; !error && i<3; i++) { |
|---|
| 286 | fname[fname_len] = '0'+i; |
|---|
| 287 | error = PH_create_ml_multiline_SAI(fname, i, &gb_sai[i], ph_root); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | delete fname; |
|---|
| 291 | |
|---|
| 292 | aw_message_if(ta.close(error)); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | static void PH_save_ml_cb(AW_window *aww, PH_root *ph_root) { |
|---|
| 296 | GBDATA *gb_main = ph_root->get_gb_main(); |
|---|
| 297 | GB_transaction ta(gb_main); |
|---|
| 298 | |
|---|
| 299 | char *fname = aww->get_root()->awar(AWAR_PHYLO_MARKERLINENAME)->read_string(); |
|---|
| 300 | GBDATA *gb_sai = GBT_find_or_create_SAI(gb_main, fname); |
|---|
| 301 | |
|---|
| 302 | GB_ERROR error = ph_check_initialized(); |
|---|
| 303 | |
|---|
| 304 | if (!error) { |
|---|
| 305 | for (GBDATA *gbd = GB_child(gb_sai), *gbnext; gbd; gbd = gbnext) { |
|---|
| 306 | gbnext = GB_nextChild(gbd); |
|---|
| 307 | |
|---|
| 308 | const char *key = GB_read_key_pntr(gbd); |
|---|
| 309 | if (!strcmp(key, "name")) continue; |
|---|
| 310 | if (!strncmp(key, "ali_", 4)) continue; |
|---|
| 311 | |
|---|
| 312 | error = GB_delete(gbd); |
|---|
| 313 | if (error) break; |
|---|
| 314 | } |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | if (!error) { |
|---|
| 318 | GBDATA *gb_ali = GB_search(gb_sai, PHDATA::ROOT->use, GB_FIND); |
|---|
| 319 | if (gb_ali) { |
|---|
| 320 | for (GBDATA *gbd = GB_child(gb_ali), *gbnext; gbd; gbd = gbnext) { |
|---|
| 321 | gbnext = GB_nextChild(gbd); |
|---|
| 322 | |
|---|
| 323 | const char *key = GB_read_key_pntr(gbd); |
|---|
| 324 | if (!strcmp(key, "bits")) continue; |
|---|
| 325 | if (!strcmp(key, "_TYPE")) continue; |
|---|
| 326 | |
|---|
| 327 | error = GB_delete(gbd); |
|---|
| 328 | if (error) break; |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | GBDATA *gb_bits = NULp, *gb_TYPE = NULp; |
|---|
| 334 | |
|---|
| 335 | if (!error) { |
|---|
| 336 | gb_bits = GBT_add_data(gb_sai, PHDATA::ROOT->use, "bits", GB_BITS); |
|---|
| 337 | if (!gb_bits) error = GB_await_error(); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | if (!error) { |
|---|
| 341 | gb_TYPE = GBT_add_data(gb_sai, PHDATA::ROOT->use, "_TYPE", GB_STRING); |
|---|
| 342 | if (!gb_TYPE) error = GB_await_error(); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | if (!error && !PHDATA::ROOT->markerline) { |
|---|
| 346 | error = "Nothing calculated yet"; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | if (!error) { |
|---|
| 350 | AW_window *main_win = PH_used_windows::windowList->phylo_main_window; |
|---|
| 351 | long minhom = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MINHOM)->read_int(); |
|---|
| 352 | long maxhom = main_win->get_root()->awar(AWAR_PHYLO_FILTER_MAXHOM)->read_int(); |
|---|
| 353 | long startcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STARTCOL)->read_int(); |
|---|
| 354 | long stopcol = main_win->get_root()->awar(AWAR_PHYLO_FILTER_STOPCOL)->read_int(); |
|---|
| 355 | long len = PHDATA::ROOT->get_seq_len(); |
|---|
| 356 | char *bits = ARB_calloc<char>(len+1); |
|---|
| 357 | int x; |
|---|
| 358 | float *markerline = PHDATA::ROOT->markerline; |
|---|
| 359 | |
|---|
| 360 | for (x=0; x<len; x++) { |
|---|
| 361 | int bit; |
|---|
| 362 | |
|---|
| 363 | if (x < startcol || x>stopcol) { |
|---|
| 364 | bit = 0; |
|---|
| 365 | } |
|---|
| 366 | else { |
|---|
| 367 | float ml = markerline[x]; |
|---|
| 368 | |
|---|
| 369 | if (ml>=0.0 && ml>=minhom && ml<=maxhom) bit = 1; |
|---|
| 370 | else bit = 0; |
|---|
| 371 | |
|---|
| 372 | } |
|---|
| 373 | bits[x] = '0'+bit; |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | error = GB_write_bits(gb_bits, bits, len, "0"); |
|---|
| 377 | |
|---|
| 378 | if (!error) { |
|---|
| 379 | char buffer[1024]; |
|---|
| 380 | sprintf(buffer, "FMX: Filter by Maximum Frequency: " |
|---|
| 381 | "Start %li; Stop %li; Minhom %li%%; Maxhom %li%%", |
|---|
| 382 | startcol, stopcol, minhom, maxhom); |
|---|
| 383 | |
|---|
| 384 | error = GB_write_string(gb_TYPE, buffer); |
|---|
| 385 | } |
|---|
| 386 | free(bits); |
|---|
| 387 | } |
|---|
| 388 | free(fname); |
|---|
| 389 | aw_message_if(ta.close(error)); |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | static AW_window *PH_save_markerline(AW_root *root, PH_root *ph_root, int multi_line) { |
|---|
| 394 | // multi_line ==1 -> save three SAI's usable as column percentage |
|---|
| 395 | |
|---|
| 396 | root->awar_string(AWAR_PHYLO_MARKERLINENAME, "markerline", AW_ROOT_DEFAULT); |
|---|
| 397 | |
|---|
| 398 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 399 | |
|---|
| 400 | if (multi_line) { |
|---|
| 401 | aws->init(root, "EXPORT_FREQUENCY_LINES", "Export Frequency Lines"); |
|---|
| 402 | } |
|---|
| 403 | else { |
|---|
| 404 | aws->init(root, "EXPORT_MARKER_LINE", "Export Marker Line"); |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | aws->load_xfig("phylo/save_markerline.fig"); |
|---|
| 408 | |
|---|
| 409 | aws->callback(AW_POPDOWN); |
|---|
| 410 | aws->at("close"); |
|---|
| 411 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 412 | |
|---|
| 413 | aws->callback(makeHelpCallback("ph_export_markerline.hlp")); |
|---|
| 414 | aws->at("help"); |
|---|
| 415 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 416 | |
|---|
| 417 | aws->at("name"); |
|---|
| 418 | aws->create_input_field(AWAR_PHYLO_MARKERLINENAME); |
|---|
| 419 | |
|---|
| 420 | aws->at("box"); |
|---|
| 421 | awt_create_SAI_selection_list(ph_root->get_gb_main(), aws, AWAR_PHYLO_MARKERLINENAME); |
|---|
| 422 | |
|---|
| 423 | aws->at("save"); |
|---|
| 424 | if (multi_line) aws->callback(makeWindowCallback(PH_save_ml_multiline_cb, ph_root)); |
|---|
| 425 | else aws->callback(makeWindowCallback(PH_save_ml_cb, ph_root)); |
|---|
| 426 | aws->create_button("EXPORT", "EXPORT", "E"); |
|---|
| 427 | |
|---|
| 428 | return aws; |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | static AW_window *create_phyl_main_window(AW_root *aw_root, PH_root *ph_root) { |
|---|
| 432 | AW_window_menu_modes *awm = new AW_window_menu_modes; |
|---|
| 433 | awm->init(aw_root, "ARB_PHYLO", "ARB_PHYLO", 830, 630); |
|---|
| 434 | |
|---|
| 435 | // create menus and menu inserts with callbacks |
|---|
| 436 | |
|---|
| 437 | const GcChangedCallback gcChangedCb = makeGcChangedCallback(gc_changed_cb); |
|---|
| 438 | |
|---|
| 439 | AW_gc_manager *gcmiddle = |
|---|
| 440 | AW_manage_GC(awm, |
|---|
| 441 | awm->get_window_id(), |
|---|
| 442 | awm->get_device(AW_MIDDLE_AREA), |
|---|
| 443 | PH_GC_DRAG, AW_GCM_DATA_AREA, |
|---|
| 444 | gcChangedCb, |
|---|
| 445 | "#C4B6D0", |
|---|
| 446 | "#SEQUENCE$#000000", |
|---|
| 447 | "#MARKER$#E0F570", |
|---|
| 448 | "NOT_MARKER$#A270C0", |
|---|
| 449 | NULp); |
|---|
| 450 | |
|---|
| 451 | AW_manage_GC(awm, |
|---|
| 452 | "ARB_PHYLO_BOTTOM", |
|---|
| 453 | awm->get_device(AW_BOTTOM_AREA), |
|---|
| 454 | PH_GC_BOTTOM_DRAG, AW_GCM_WINDOW_AREA, |
|---|
| 455 | gcChangedCb, |
|---|
| 456 | "lightgrey", |
|---|
| 457 | "#FOOTER", |
|---|
| 458 | NULp); |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | #if defined(DEBUG) |
|---|
| 462 | AWT_create_debug_menu(awm); |
|---|
| 463 | #endif // DEBUG |
|---|
| 464 | |
|---|
| 465 | // File menu |
|---|
| 466 | awm->create_menu("File", "F"); |
|---|
| 467 | awm->insert_menu_topic("export_filter", "Export Filter", "E", "ph_export_markerline.hlp", AWM_ALL, makeCreateWindowCallback(PH_save_markerline, ph_root, 0)); |
|---|
| 468 | awm->insert_menu_topic("export_freq", "Export Frequencies", "F", "ph_export_markerline.hlp", AWM_ALL, makeCreateWindowCallback(PH_save_markerline, ph_root, 1)); |
|---|
| 469 | insert_macro_menu_entry(awm, false); |
|---|
| 470 | |
|---|
| 471 | awm->insert_menu_topic("quit", "Quit", "Q", "quit.hlp", AWM_ALL, makeWindowCallback(ph_exit, ph_root)); |
|---|
| 472 | |
|---|
| 473 | // Calculate menu |
|---|
| 474 | awm->create_menu("Calculate", "C"); |
|---|
| 475 | awm->insert_menu_topic("calc_column_filter", "Column Filter", "F", "no help", AWM_ALL, makeWindowCallback(ph_calc_filter_cb)); |
|---|
| 476 | |
|---|
| 477 | // Config menu |
|---|
| 478 | awm->create_menu("Config", "o"); |
|---|
| 479 | awm->insert_menu_topic("config_column_filter", "Column Filter", "F", "no help", AWM_ALL, PH_create_filter_window); |
|---|
| 480 | |
|---|
| 481 | // Properties menu |
|---|
| 482 | awm->create_menu("Properties", "P"); |
|---|
| 483 | awm->insert_menu_topic("props_menu", "Frame settings ...", "F", "props_frame.hlp", AWM_ALL, AW_preset_window); |
|---|
| 484 | awm->insert_menu_topic("props_data", "Colors and Fonts ...", "C", "color_props.hlp", AWM_ALL, makeCreateWindowCallback(AW_create_gc_window, gcmiddle)); |
|---|
| 485 | awm->sep______________(); |
|---|
| 486 | AW_insert_common_property_menu_entries(awm); |
|---|
| 487 | awm->sep______________(); |
|---|
| 488 | awm->insert_menu_topic("save_props", "Save Properties (phylo.arb)", "S", "savedef.hlp", AWM_ALL, AW_save_properties); |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | // set window areas |
|---|
| 492 | awm->set_info_area_height(30); |
|---|
| 493 | awm->at(5, 2); |
|---|
| 494 | awm->auto_space(5, -2); |
|---|
| 495 | |
|---|
| 496 | awm->callback(makeWindowCallback(ph_exit, ph_root)); |
|---|
| 497 | awm->button_length(0); |
|---|
| 498 | awm->help_text("quit.hlp"); |
|---|
| 499 | awm->create_button("QUIT", "QUIT"); |
|---|
| 500 | |
|---|
| 501 | awm->callback(makeHelpCallback("phylo.hlp")); |
|---|
| 502 | awm->button_length(0); |
|---|
| 503 | awm->create_button("HELP", "HELP", "H"); |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | awm->set_bottom_area_height(120); |
|---|
| 507 | |
|---|
| 508 | awm->set_expose_callback(AW_MIDDLE_AREA, makeWindowCallback(expose_cb)); |
|---|
| 509 | awm->set_resize_callback(AW_MIDDLE_AREA, makeWindowCallback(resize_cb)); |
|---|
| 510 | awm->set_expose_callback(AW_BOTTOM_AREA, makeWindowCallback(display_status_cb)); |
|---|
| 511 | awm->set_resize_callback(AW_BOTTOM_AREA, makeWindowCallback(display_status_cb)); |
|---|
| 512 | |
|---|
| 513 | return awm; |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | static AW_window *create_select_alignment_window(AW_root *aw_root, AW_window *main_window, PH_root *ph_root) { |
|---|
| 518 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 519 | |
|---|
| 520 | aws->init(aw_root, "SELECT_ALIGNMENT", "ARB_PHYLO: Select alignment"); |
|---|
| 521 | aws->load_xfig("phylo/select_ali.fig"); |
|---|
| 522 | aws->button_length(10); |
|---|
| 523 | |
|---|
| 524 | aws->at("which_alignment"); |
|---|
| 525 | awt_create_ALI_selection_list(ph_root->get_gb_main(), (AW_window *)aws, AWAR_PHYLO_ALIGNMENT, "*="); |
|---|
| 526 | |
|---|
| 527 | aws->auto_space(10, 10); |
|---|
| 528 | |
|---|
| 529 | aws->at("ok"); |
|---|
| 530 | aws->callback(makeWindowCallback(startup_sequence_cb, main_window, ph_root)); |
|---|
| 531 | aws->create_button("OK", "Ok", "D"); |
|---|
| 532 | |
|---|
| 533 | aws->callback(makeWindowCallback(ph_exit, ph_root)); |
|---|
| 534 | aws->create_button("ABORT", "Abort", "D"); |
|---|
| 535 | |
|---|
| 536 | return aws; |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 | PH_used_windows::PH_used_windows() { |
|---|
| 542 | memset((char *) this, 0, sizeof(PH_used_windows)); |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | // initialize 'globals' |
|---|
| 546 | PH_used_windows *PH_used_windows::windowList = NULp; |
|---|
| 547 | PH_display *PH_display::ph_display = NULp; |
|---|
| 548 | PHDATA *PHDATA::ROOT = NULp; |
|---|
| 549 | |
|---|
| 550 | static void create_variables(AW_root *aw_root, AW_default def, GBDATA *gb_main) { |
|---|
| 551 | aw_root->awar_string(AWAR_PHYLO_ALIGNMENT, "", def); |
|---|
| 552 | aw_root->awar_string(AWAR_PHYLO_FILTER_FILTER, "", def); |
|---|
| 553 | PH_create_filter_variables(aw_root, def, gb_main); |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | int ARB_main(int argc, char *argv[]) { |
|---|
| 557 | aw_initstatus(); |
|---|
| 558 | |
|---|
| 559 | GB_shell shell; |
|---|
| 560 | AW_root *aw_root = AWT_create_root("phylo.arb", "ARB_PHYLO", need_macro_ability()); |
|---|
| 561 | |
|---|
| 562 | int exitcode = EXIT_SUCCESS; |
|---|
| 563 | if (argc > 2 || (argc == 2 && strcmp(argv[1], "--help") == 0)) { |
|---|
| 564 | fprintf(stderr, "Usage: arb_phylo [database]\n"); |
|---|
| 565 | exitcode = EXIT_FAILURE; |
|---|
| 566 | } |
|---|
| 567 | else { |
|---|
| 568 | const char *db_server = (argc == 2 ? argv[1] : ":"); |
|---|
| 569 | |
|---|
| 570 | PH_used_windows *puw = new PH_used_windows; |
|---|
| 571 | PH_display *phd = new PH_display; |
|---|
| 572 | |
|---|
| 573 | PH_root *ph_root = new PH_root; |
|---|
| 574 | GB_ERROR error = ph_root->open(db_server); |
|---|
| 575 | |
|---|
| 576 | if (!error) error = configure_macro_recording(aw_root, "ARB_PHYLO", ph_root->get_gb_main()); |
|---|
| 577 | if (!error) { |
|---|
| 578 | GBDATA *gb_main = ph_root->get_gb_main(); |
|---|
| 579 | |
|---|
| 580 | // create arb_phylo awars : |
|---|
| 581 | create_variables(aw_root, AW_ROOT_DEFAULT, gb_main); |
|---|
| 582 | ARB_init_global_awars(aw_root, AW_ROOT_DEFAULT, gb_main); |
|---|
| 583 | #if defined(DEBUG) |
|---|
| 584 | AWT_create_db_browser_awars(aw_root, AW_ROOT_DEFAULT); |
|---|
| 585 | #endif // DEBUG |
|---|
| 586 | |
|---|
| 587 | #if defined(DEBUG) |
|---|
| 588 | AWT_announce_db_to_browser(gb_main, GBS_global_string("ARB-database (%s)", db_server)); |
|---|
| 589 | #endif // DEBUG |
|---|
| 590 | |
|---|
| 591 | // create main window : |
|---|
| 592 | |
|---|
| 593 | puw->phylo_main_window = create_phyl_main_window(aw_root, ph_root); |
|---|
| 594 | puw->windowList = puw; |
|---|
| 595 | |
|---|
| 596 | phd->ph_display = phd; |
|---|
| 597 | |
|---|
| 598 | // loading database |
|---|
| 599 | GB_push_transaction(gb_main); |
|---|
| 600 | |
|---|
| 601 | ConstStrArray alignment_names; |
|---|
| 602 | GBT_get_alignment_names(alignment_names, gb_main); |
|---|
| 603 | |
|---|
| 604 | int num_alignments; |
|---|
| 605 | for (num_alignments = 0; alignment_names[num_alignments]; num_alignments++) {} |
|---|
| 606 | |
|---|
| 607 | if (num_alignments > 1) { |
|---|
| 608 | char *defaultAli = GBT_get_default_alignment(gb_main); |
|---|
| 609 | if (!defaultAli) { |
|---|
| 610 | aw_message_if(GB_await_error()); |
|---|
| 611 | defaultAli = ARB_strdup(""); |
|---|
| 612 | } |
|---|
| 613 | aw_root->awar(AWAR_PHYLO_ALIGNMENT)->write_string(defaultAli); |
|---|
| 614 | create_select_alignment_window(aw_root, puw->phylo_main_window, ph_root)->show(); |
|---|
| 615 | free(defaultAli); |
|---|
| 616 | } |
|---|
| 617 | else { |
|---|
| 618 | aw_root->awar(AWAR_PHYLO_ALIGNMENT)->write_string(alignment_names[0]); |
|---|
| 619 | startup_sequence_cb(NULp, puw->phylo_main_window, ph_root); |
|---|
| 620 | } |
|---|
| 621 | GB_pop_transaction(gb_main); |
|---|
| 622 | |
|---|
| 623 | AWT_install_cb_guards(); |
|---|
| 624 | aw_root->main_loop(); |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | if (error) { |
|---|
| 628 | aw_popup_exit(error); |
|---|
| 629 | exitcode = EXIT_FAILURE; |
|---|
| 630 | } |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | delete aw_root; |
|---|
| 634 | return exitcode; |
|---|
| 635 | } |
|---|
| 636 | |
|---|