| 1 | // ============================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : ED4_main.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // ============================================================= // |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #include "ed4_class.hxx" |
|---|
| 13 | #include "ed4_awars.hxx" |
|---|
| 14 | #include "ed4_edit_string.hxx" |
|---|
| 15 | #include "ed4_nds.hxx" |
|---|
| 16 | #include "ed4_visualizeSAI.hxx" |
|---|
| 17 | #include "ed4_ProteinViewer.hxx" |
|---|
| 18 | #include "ed4_protein_2nd_structure.hxx" |
|---|
| 19 | #include "ed4_dots.hxx" |
|---|
| 20 | #include "ed4_naligner.hxx" |
|---|
| 21 | #include "ed4_seq_colors.hxx" |
|---|
| 22 | #include "graph_aligner_gui.hxx" |
|---|
| 23 | #include <ed4_extern.hxx> |
|---|
| 24 | |
|---|
| 25 | #include <st_window.hxx> |
|---|
| 26 | #include <gde.hxx> |
|---|
| 27 | #include <AW_helix.hxx> |
|---|
| 28 | #include <AP_pro_a_nucs.hxx> |
|---|
| 29 | #include <ad_config.h> |
|---|
| 30 | #include <awt_map_key.hxx> |
|---|
| 31 | #include <awt.hxx> |
|---|
| 32 | |
|---|
| 33 | #include <aw_preset.hxx> |
|---|
| 34 | #include <aw_awars.hxx> |
|---|
| 35 | #include <aw_msg.hxx> |
|---|
| 36 | #include <aw_root.hxx> |
|---|
| 37 | #include <aw_advice.hxx> |
|---|
| 38 | |
|---|
| 39 | #include <arbdbt.h> |
|---|
| 40 | |
|---|
| 41 | #include <arb_defs.h> |
|---|
| 42 | #include <arb_global_defs.h> |
|---|
| 43 | #include <macros.hxx> |
|---|
| 44 | #include <aw_question.hxx> |
|---|
| 45 | |
|---|
| 46 | AW_HEADER_MAIN |
|---|
| 47 | |
|---|
| 48 | ED4_root *ED4_ROOT = NULp; |
|---|
| 49 | |
|---|
| 50 | int TERMINAL_HEIGHT; |
|---|
| 51 | |
|---|
| 52 | int INFO_TERM_TEXT_YOFFSET; |
|---|
| 53 | int SEQ_TERM_TEXT_YOFFSET; |
|---|
| 54 | |
|---|
| 55 | int MAXSEQUENCECHARACTERLENGTH; // greatest # of characters in a sequence string terminal |
|---|
| 56 | int MAXNAME_WIDTH; |
|---|
| 57 | int MAXINFO_WIDTH; |
|---|
| 58 | int FLAG_WIDTH; |
|---|
| 59 | |
|---|
| 60 | long ED4_counter = 0; |
|---|
| 61 | |
|---|
| 62 | size_t not_found_counter; // nr of species which haven't been found |
|---|
| 63 | GBS_strstruct *not_found_message; |
|---|
| 64 | |
|---|
| 65 | long max_seq_terminal_length; // global maximum of sequence terminal length |
|---|
| 66 | ED4_EDITMODE awar_edit_mode; |
|---|
| 67 | long awar_edit_rightward; |
|---|
| 68 | bool move_cursor; // only needed for editing in consensus |
|---|
| 69 | bool DRAW; |
|---|
| 70 | |
|---|
| 71 | inline void replaceChars(char *s, char o, char n) { |
|---|
| 72 | while (1) { |
|---|
| 73 | char c = *s++; |
|---|
| 74 | if (!c) { |
|---|
| 75 | break; |
|---|
| 76 | } |
|---|
| 77 | if (c==o) { |
|---|
| 78 | s[-1] = n; |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | inline void set_and_realloc_gde_array(uchar **&the_names, uchar **&the_sequences, long &allocated, long &numberspecies, long &maxalign, |
|---|
| 84 | const char *name, int name_len, const char *seq, int seq_len) |
|---|
| 85 | { |
|---|
| 86 | if (allocated==numberspecies) { |
|---|
| 87 | long new_allocated = (allocated*3)/2; |
|---|
| 88 | |
|---|
| 89 | ARB_recalloc(the_names, allocated, new_allocated); |
|---|
| 90 | ARB_recalloc(the_sequences, allocated, new_allocated); |
|---|
| 91 | allocated = new_allocated; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | the_names[numberspecies] = (uchar*)ARB_strndup(name, name_len); |
|---|
| 95 | the_sequences[numberspecies] = (uchar*)ARB_strndup(seq, seq_len); |
|---|
| 96 | |
|---|
| 97 | replaceChars((char*)the_names[numberspecies], ' ', '_'); |
|---|
| 98 | |
|---|
| 99 | if (seq_len>maxalign) { |
|---|
| 100 | maxalign = seq_len; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | numberspecies++; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | static char *add_area_for_gde(ED4_area_manager *area_man, uchar **&the_names, uchar **&the_sequences, |
|---|
| 107 | long &allocated, long &numberspecies, long &maxalign, |
|---|
| 108 | int show_sequence, int show_SAI, int show_helix, int show_consensus, int show_remark) |
|---|
| 109 | { |
|---|
| 110 | ED4_terminal *terminal = area_man->get_first_terminal(); |
|---|
| 111 | ED4_terminal *last = area_man->get_last_terminal(); |
|---|
| 112 | |
|---|
| 113 | for (; terminal;) { |
|---|
| 114 | if (terminal->is_species_name_terminal()) { |
|---|
| 115 | ED4_species_manager *species_manager = terminal->get_parent(LEV_SPECIES)->to_species_manager(); |
|---|
| 116 | ED4_species_name_terminal *species_name = species_manager->search_spec_child_rek(LEV_SPECIES_NAME)->to_species_name_terminal(); |
|---|
| 117 | int name_len; |
|---|
| 118 | char *name = species_name->resolve_pointer_to_string_copy(&name_len); |
|---|
| 119 | ED4_sequence_terminal *sequence_terminal; |
|---|
| 120 | |
|---|
| 121 | { |
|---|
| 122 | ED4_base *sequence_term = species_manager->search_spec_child_rek(LEV_SEQUENCE_STRING); |
|---|
| 123 | if (!sequence_term) goto end_of_loop; |
|---|
| 124 | sequence_terminal = sequence_term->to_sequence_terminal(); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | int show = -1; |
|---|
| 128 | |
|---|
| 129 | bool is_consensus = false; |
|---|
| 130 | bool is_SAI = false; |
|---|
| 131 | |
|---|
| 132 | if (sequence_terminal->is_consensus_terminal()) { |
|---|
| 133 | is_consensus = true; |
|---|
| 134 | show = show_consensus; |
|---|
| 135 | } |
|---|
| 136 | else if (sequence_terminal->is_SAI_terminal()) { |
|---|
| 137 | is_SAI = true; |
|---|
| 138 | show = show_SAI; |
|---|
| 139 | } |
|---|
| 140 | else { |
|---|
| 141 | show = show_sequence; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | e4_assert(show!=-1); |
|---|
| 145 | |
|---|
| 146 | if (show) { |
|---|
| 147 | int seq_len; |
|---|
| 148 | char *seq = NULp; |
|---|
| 149 | |
|---|
| 150 | if (is_consensus) { |
|---|
| 151 | ED4_group_manager *group_manager = sequence_terminal->get_parent(LEV_GROUP)->to_group_manager(); |
|---|
| 152 | |
|---|
| 153 | seq = group_manager->build_consensus_string(&seq_len); |
|---|
| 154 | e4_assert(seq && strlen(seq) == size_t(seq_len)); |
|---|
| 155 | |
|---|
| 156 | ED4_group_manager *folded_group_man = sequence_terminal->is_in_folded_group(); |
|---|
| 157 | |
|---|
| 158 | if (folded_group_man) { // we are in a folded group |
|---|
| 159 | if (folded_group_man==group_manager) { // we are the consensus of the folded group |
|---|
| 160 | if (folded_group_man->is_in_folded_group()) { // a folded group inside a folded group -> do not show |
|---|
| 161 | freenull(seq); |
|---|
| 162 | } |
|---|
| 163 | else { // group folded but consensus shown -> add '-' before name |
|---|
| 164 | char *new_name = ARB_alloc<char>(name_len+2); |
|---|
| 165 | |
|---|
| 166 | sprintf(new_name, "-%s", name); |
|---|
| 167 | freeset(name, new_name); |
|---|
| 168 | name_len++; |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | else { // we are really inside a folded group -> don't show |
|---|
| 172 | freenull(seq); |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | else { // sequence |
|---|
| 177 | if (!sequence_terminal->is_in_folded_group()) { |
|---|
| 178 | seq = sequence_terminal->resolve_pointer_to_string_copy(&seq_len); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | if (seq) { |
|---|
| 183 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, seq, seq_len); |
|---|
| 184 | if (show_helix && !is_SAI && ED4_ROOT->helix->size()) { |
|---|
| 185 | char *helix = ED4_ROOT->helix->seq_2_helix(seq, '.'); |
|---|
| 186 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, helix, seq_len); |
|---|
| 187 | free(helix); |
|---|
| 188 | } |
|---|
| 189 | if (show_remark && !is_consensus) { |
|---|
| 190 | ED4_manager *ms_man = sequence_terminal->get_parent(LEV_MULTI_SEQUENCE); |
|---|
| 191 | if (ms_man) { |
|---|
| 192 | ED4_base *remark_name_term = ms_man->search_ID("remark"); |
|---|
| 193 | if (remark_name_term) { |
|---|
| 194 | ED4_base *remark_term = remark_name_term->get_next_terminal(); |
|---|
| 195 | e4_assert(remark_term); |
|---|
| 196 | |
|---|
| 197 | int remark_len; |
|---|
| 198 | char *remark = remark_term->resolve_pointer_to_string_copy(&remark_len); |
|---|
| 199 | |
|---|
| 200 | replaceChars(remark, ' ', '_'); |
|---|
| 201 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, remark, remark_len); |
|---|
| 202 | free(remark); |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | free(seq); |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | free(name); |
|---|
| 210 | } |
|---|
| 211 | end_of_loop : |
|---|
| 212 | if (terminal==last) break; |
|---|
| 213 | terminal = terminal->get_next_terminal(); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | return NULp; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | static char *ED4_create_sequences_for_gde(GBDATA **&the_species, uchar **&the_names, uchar **&the_sequences, long &numberspecies, long &maxalign) { |
|---|
| 220 | int top = ED4_ROOT->aw_root->awar("gde/top_area")->read_int(); |
|---|
| 221 | int tops = ED4_ROOT->aw_root->awar("gde/top_area_sai")->read_int(); |
|---|
| 222 | int toph = ED4_ROOT->aw_root->awar("gde/top_area_helix")->read_int(); |
|---|
| 223 | int topk = ED4_ROOT->aw_root->awar("gde/top_area_kons")->read_int(); |
|---|
| 224 | int topr = ED4_ROOT->aw_root->awar("gde/top_area_remark")->read_int(); |
|---|
| 225 | int middle = ED4_ROOT->aw_root->awar("gde/middle_area")->read_int(); |
|---|
| 226 | int middles = ED4_ROOT->aw_root->awar("gde/middle_area_sai")->read_int(); |
|---|
| 227 | int middleh = ED4_ROOT->aw_root->awar("gde/middle_area_helix")->read_int(); |
|---|
| 228 | int middlek = ED4_ROOT->aw_root->awar("gde/middle_area_kons")->read_int(); |
|---|
| 229 | int middler = ED4_ROOT->aw_root->awar("gde/middle_area_remark")->read_int(); |
|---|
| 230 | |
|---|
| 231 | numberspecies = 0; |
|---|
| 232 | maxalign = 0; |
|---|
| 233 | |
|---|
| 234 | long allocated = 100; |
|---|
| 235 | the_species = NULp; |
|---|
| 236 | |
|---|
| 237 | ARB_calloc(the_names, allocated); |
|---|
| 238 | ARB_calloc(the_sequences, allocated); |
|---|
| 239 | |
|---|
| 240 | char *err = add_area_for_gde(ED4_ROOT->top_area_man, the_names, the_sequences, allocated, numberspecies, maxalign, top, tops, toph, topk, topr); |
|---|
| 241 | if (!err) { |
|---|
| 242 | err = add_area_for_gde(ED4_ROOT->middle_area_man, the_names, the_sequences, allocated, numberspecies, maxalign, middle, middles, middleh, middlek, middler); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | if (allocated!=(numberspecies+1)) { |
|---|
| 246 | ARB_recalloc(the_names, allocated, numberspecies+1); |
|---|
| 247 | ARB_recalloc(the_sequences, allocated, numberspecies+1); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | return err; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | void ED4_setup_gaps_and_alitype(const char *gap_chars, GB_alignment_type alitype) { |
|---|
| 254 | BaseFrequencies::setup(gap_chars, alitype); |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | static void ED4_gap_chars_changed(AW_root *root) { |
|---|
| 258 | char *gap_chars = root->awar_string(ED4_AWAR_GAP_CHARS)->read_string(); |
|---|
| 259 | ED4_setup_gaps_and_alitype(gap_chars, ED4_ROOT->alignment_type); |
|---|
| 260 | free(gap_chars); |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | void ED4_with_all_edit_windows(void (*cb)(ED4_window *)) { |
|---|
| 264 | for (ED4_window *win = ED4_ROOT->first_window; win; win = win->next) { |
|---|
| 265 | ED4_LocalWinContext uses(win); |
|---|
| 266 | cb(win); |
|---|
| 267 | } |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | static void redraw_cursor(ED4_window *win) { win->cursor.redraw(); } |
|---|
| 271 | static void ED4_edit_direction_changed(AW_root * /* awr */) { |
|---|
| 272 | ED4_with_all_edit_windows(redraw_cursor); |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | static void ed4_bind_mainDB_awar_callbacks(AW_root *root) { |
|---|
| 276 | // callbacks to main DB awars are bound later |
|---|
| 277 | // (otherwise its easy to crash the editor by clicking around in ARB_NTREE during editor startup) |
|---|
| 278 | |
|---|
| 279 | root->awar(AWAR_SET_CURSOR_POSITION)->add_callback(ED4_remote_set_cursor_cb); |
|---|
| 280 | root->awar(AWAR_SPECIES_NAME)->add_callback(ED4_selected_species_changed_cb); |
|---|
| 281 | root->awar(AWAR_SAI_NAME)->add_callback(ED4_selected_SAI_changed_cb); |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | static void ed4_create_mainDB_awars(AW_root *root) { |
|---|
| 285 | // WARNING: do not bind callbacks here -> do it in ed4_bind_mainDB_awar_callbacks() |
|---|
| 286 | |
|---|
| 287 | GBDATA *gb_main = ED4_ROOT->get_gb_main(); |
|---|
| 288 | |
|---|
| 289 | root->awar_int(AWAR_CURSOR_POSITION, info2bio(0), gb_main); |
|---|
| 290 | root->awar_int(AWAR_CURSOR_POSITION_LOCAL, 0, gb_main); |
|---|
| 291 | root->awar_int(AWAR_SET_CURSOR_POSITION, 1, gb_main); |
|---|
| 292 | |
|---|
| 293 | root->awar_string(AWAR_FIELD_CHOSEN, NO_FIELD_SELECTED, gb_main); |
|---|
| 294 | |
|---|
| 295 | root->awar_string(AWAR_SPECIES_NAME, "", gb_main); |
|---|
| 296 | root->awar_string(AWAR_SAI_NAME, "", gb_main); |
|---|
| 297 | root->awar_string(AWAR_SAI_GLOBAL, "", gb_main); |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | static void ed4_create_all_awars(AW_root *root, const char *config_name) { |
|---|
| 301 | // Note: cursor awars are created in window constructor |
|---|
| 302 | |
|---|
| 303 | root->awar_string(AWAR_EDIT_CONFIGURATION, config_name, AW_ROOT_DEFAULT); |
|---|
| 304 | |
|---|
| 305 | ed4_create_mainDB_awars(root); |
|---|
| 306 | ED4_create_search_awars(root); |
|---|
| 307 | |
|---|
| 308 | #if defined(DEBUG) |
|---|
| 309 | AWT_create_db_browser_awars(root, AW_ROOT_DEFAULT); |
|---|
| 310 | #endif // DEBUG |
|---|
| 311 | |
|---|
| 312 | create_naligner_variables(root, AW_ROOT_DEFAULT); |
|---|
| 313 | create_sina_variables(root, AW_ROOT_DEFAULT); |
|---|
| 314 | |
|---|
| 315 | awar_edit_mode = AD_ALIGN; |
|---|
| 316 | |
|---|
| 317 | int def_sec_level = 0; |
|---|
| 318 | #ifdef DEBUG |
|---|
| 319 | def_sec_level = 6; // don't nag developers |
|---|
| 320 | #endif |
|---|
| 321 | root->awar_int(AWAR_EDIT_SECURITY_LEVEL, def_sec_level, AW_ROOT_DEFAULT); |
|---|
| 322 | |
|---|
| 323 | root->awar_int(AWAR_EDIT_SECURITY_LEVEL_ALIGN, def_sec_level, AW_ROOT_DEFAULT)->add_callback(ed4_changesecurity); |
|---|
| 324 | root->awar_int(AWAR_EDIT_SECURITY_LEVEL_CHANGE, def_sec_level, AW_ROOT_DEFAULT)->add_callback(ed4_changesecurity); |
|---|
| 325 | |
|---|
| 326 | root->awar_int(AWAR_EDIT_MODE, 0)->add_callback(ed4_change_edit_mode); |
|---|
| 327 | root->awar_int(AWAR_INSERT_MODE, 1)->add_callback(ed4_change_edit_mode); |
|---|
| 328 | |
|---|
| 329 | root->awar_int(AWAR_EDIT_RIGHTWARD, 1)->add_target_var(&awar_edit_rightward)->add_callback(ED4_edit_direction_changed); |
|---|
| 330 | root->awar_int(AWAR_EDIT_TITLE_MODE, 0); |
|---|
| 331 | |
|---|
| 332 | root->awar_int(AWAR_EDIT_HELIX_SPACING, 0) ->set_minmax(-30, 30) ->add_target_var(&ED4_ROOT->helix_add_spacing) ->add_callback(makeRootCallback(ED4_request_relayout)); |
|---|
| 333 | root->awar_int(AWAR_EDIT_TERMINAL_SPACING, 0) ->set_minmax(-30, 30) ->add_target_var(&ED4_ROOT->terminal_add_spacing) ->add_callback(makeRootCallback(ED4_request_relayout)); |
|---|
| 334 | |
|---|
| 335 | ed4_changesecurity(root); |
|---|
| 336 | |
|---|
| 337 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_GAPS, 0)->add_callback(makeRootCallback(ED4_compression_toggle_changed_cb, false)); |
|---|
| 338 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_HIDE, 0)->add_callback(makeRootCallback(ED4_compression_toggle_changed_cb, true)); |
|---|
| 339 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_TYPE, 0)->add_callback(ED4_compression_changed_cb); |
|---|
| 340 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_PERCENT, 1)->add_callback(ED4_compression_changed_cb)->set_minmax(1, 99); |
|---|
| 341 | |
|---|
| 342 | root->awar_int(ED4_AWAR_DIGITS_AS_REPEAT, 0); |
|---|
| 343 | root->awar_int(ED4_AWAR_FAST_CURSOR_JUMP, 0); |
|---|
| 344 | root->awar_int(ED4_AWAR_CURSOR_TYPE, (int)ED4_RIGHT_ORIENTED_CURSOR); |
|---|
| 345 | |
|---|
| 346 | ED4_create_consensus_awars(root); |
|---|
| 347 | ED4_create_NDS_awars(root); |
|---|
| 348 | |
|---|
| 349 | root->awar_string(ED4_AWAR_REP_SEARCH_PATTERN, "."); |
|---|
| 350 | root->awar_string(ED4_AWAR_REP_REPLACE_PATTERN, "-"); |
|---|
| 351 | |
|---|
| 352 | root->awar_int(ED4_AWAR_SCROLL_SPEED_X, 40); |
|---|
| 353 | root->awar_int(ED4_AWAR_SCROLL_SPEED_Y, 20); |
|---|
| 354 | root->awar_int(ED4_AWAR_SCROLL_MARGIN, 5); |
|---|
| 355 | |
|---|
| 356 | root->awar_string(ED4_AWAR_SPECIES_TO_CREATE, ""); |
|---|
| 357 | |
|---|
| 358 | root->awar_string(ED4_AWAR_GAP_CHARS, GAP::anyGapChars())->add_callback(ED4_gap_chars_changed); |
|---|
| 359 | ED4_gap_chars_changed(root); |
|---|
| 360 | root->awar_int(ED4_AWAR_ANNOUNCE_CHECKSUM_CHANGES, 0); |
|---|
| 361 | |
|---|
| 362 | GBDATA *gb_main = ED4_ROOT->get_gb_main(); |
|---|
| 363 | { |
|---|
| 364 | GB_ERROR gde_err = GDE_init(ED4_ROOT->aw_root, ED4_ROOT->props_db, gb_main, ED4_create_sequences_for_gde, NULp, GDE_WINDOWTYPE_EDIT4); |
|---|
| 365 | if (gde_err) GBK_terminatef("Fatal error: %s", gde_err); |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | root->awar_string(ED4_AWAR_CREATE_FROM_CONS_REPL_EQUAL, "-"); |
|---|
| 369 | root->awar_string(ED4_AWAR_CREATE_FROM_CONS_REPL_POINT, "?"); |
|---|
| 370 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_CREATE_POINTS, 1); |
|---|
| 371 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_ALL_UPPER, 1); |
|---|
| 372 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_DATA_SOURCE, 0); |
|---|
| 373 | |
|---|
| 374 | ED4_createVisualizeSAI_Awars(root, AW_ROOT_DEFAULT); |
|---|
| 375 | ED4_create_dot_missing_bases_awars(root, AW_ROOT_DEFAULT); |
|---|
| 376 | |
|---|
| 377 | // Create Awars To Be Used In Protein Viewer |
|---|
| 378 | if (ED4_ROOT->alignment_type == GB_AT_DNA) { |
|---|
| 379 | PV_CreateAwars(root, AW_ROOT_DEFAULT); |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | // create awars to be used for protein secondary structure match |
|---|
| 383 | if (ED4_ROOT->alignment_type == GB_AT_AA) { |
|---|
| 384 | root->awar_int(PFOLD_AWAR_ENABLE, 1); |
|---|
| 385 | root->awar_string(PFOLD_AWAR_SELECTED_SAI, "PFOLD"); |
|---|
| 386 | root->awar_int(PFOLD_AWAR_MATCH_METHOD, SECSTRUCT_SEQUENCE); |
|---|
| 387 | int pt; |
|---|
| 388 | char awar[256]; |
|---|
| 389 | for (int i = 0; pfold_match_type_awars[i].name; i++) { |
|---|
| 390 | e4_assert(i<PFOLD_PAIRS); |
|---|
| 391 | pt = pfold_match_type_awars[i].value; |
|---|
| 392 | sprintf(awar, PFOLD_AWAR_PAIR_TEMPLATE, pfold_match_type_awars[i].name); |
|---|
| 393 | root->awar_string(awar, pfold_pairs[pt])->add_target_var(&pfold_pairs[pt]); |
|---|
| 394 | sprintf(awar, PFOLD_AWAR_SYMBOL_TEMPLATE, pfold_match_type_awars[i].name); |
|---|
| 395 | root->awar_string(awar, pfold_pair_chars[pt])->add_target_var(&pfold_pair_chars[pt]); |
|---|
| 396 | } |
|---|
| 397 | root->awar_string(PFOLD_AWAR_SYMBOL_TEMPLATE_2, PFOLD_PAIR_CHARS_2); |
|---|
| 398 | root->awar_string(PFOLD_AWAR_SAI_FILTER, "pfold"); |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | GB_ERROR error = ARB_init_global_awars(root, AW_ROOT_DEFAULT, gb_main); |
|---|
| 402 | if (error) aw_message(error); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | static void ED4_postcbcb(AW_window *aww) { |
|---|
| 406 | ED4_ROOT->announce_useraction_in(aww); |
|---|
| 407 | ED4_trigger_instant_refresh(); |
|---|
| 408 | } |
|---|
| 409 | static void seq_colors_changed_cb() { |
|---|
| 410 | ED4_ROOT->request_refresh_for_sequence_terminals(); |
|---|
| 411 | } |
|---|
| 412 | |
|---|
| 413 | int ARB_main(int argc, char *argv[]) { |
|---|
| 414 | const char *data_path = ":"; |
|---|
| 415 | char *config_name = NULp; |
|---|
| 416 | |
|---|
| 417 | if (argc > 1 && ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0))) { |
|---|
| 418 | fprintf(stderr, |
|---|
| 419 | "Usage: arb_edit4 [options] database\n" |
|---|
| 420 | " database name of database or ':' to connect to arb-database-server\n" |
|---|
| 421 | "\n" |
|---|
| 422 | " options:\n" |
|---|
| 423 | " -c config loads configuration 'config' (default: '" DEFAULT_CONFIGURATION "')\n" |
|---|
| 424 | ); |
|---|
| 425 | return EXIT_SUCCESS; |
|---|
| 426 | } |
|---|
| 427 | |
|---|
| 428 | if (argc > 1 && strcmp(argv[1], "-c") == 0) { |
|---|
| 429 | config_name = new char[strlen(argv[2])+1]; |
|---|
| 430 | strcpy(config_name, argv[2]); |
|---|
| 431 | argc -= 2; argv += 2; |
|---|
| 432 | } |
|---|
| 433 | else { // load default configuration if no command line is given |
|---|
| 434 | config_name = ARB_strdup(DEFAULT_CONFIGURATION); |
|---|
| 435 | printf("Using '%s'\n", DEFAULT_CONFIGURATION); |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | if (argc>1) { |
|---|
| 439 | data_path = argv[1]; |
|---|
| 440 | argc--; argv++; |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | aw_initstatus(); |
|---|
| 444 | |
|---|
| 445 | GB_shell shell; |
|---|
| 446 | ARB_ERROR error; |
|---|
| 447 | GBDATA *gb_main = GB_open(data_path, "rwt"); |
|---|
| 448 | |
|---|
| 449 | if (!gb_main) { |
|---|
| 450 | error = GB_await_error(); |
|---|
| 451 | } |
|---|
| 452 | else { |
|---|
| 453 | #if defined(DEBUG) |
|---|
| 454 | AWT_announce_db_to_browser(gb_main, GBS_global_string("ARB database (%s)", data_path)); |
|---|
| 455 | #endif // DEBUG |
|---|
| 456 | |
|---|
| 457 | ED4_ROOT = new ED4_root(gb_main); |
|---|
| 458 | |
|---|
| 459 | error = configure_macro_recording(ED4_ROOT->aw_root, "ARB_EDIT4", gb_main); |
|---|
| 460 | if (!error) error = ED4_ROOT->init_alignment(); |
|---|
| 461 | if (!error) { |
|---|
| 462 | ed4_create_all_awars(ED4_ROOT->aw_root, config_name); |
|---|
| 463 | |
|---|
| 464 | ED4_ROOT->st_ml = STAT_create_ST_ML(gb_main); |
|---|
| 465 | ED4_ROOT->sequence_colors = new ED4_seq_colors(ED4_G_SEQUENCES, seq_colors_changed_cb); |
|---|
| 466 | |
|---|
| 467 | ED4_ROOT->edk = new ed_key; |
|---|
| 468 | ED4_ROOT->edk->create_awars(ED4_ROOT->aw_root); |
|---|
| 469 | |
|---|
| 470 | ED4_ROOT->helix = new AW_helix(ED4_ROOT->aw_root); |
|---|
| 471 | |
|---|
| 472 | { |
|---|
| 473 | GB_ERROR warning = NULp; |
|---|
| 474 | switch (ED4_ROOT->alignment_type) { |
|---|
| 475 | case GB_AT_RNA: |
|---|
| 476 | case GB_AT_DNA: |
|---|
| 477 | warning = ED4_ROOT->helix->init(gb_main); |
|---|
| 478 | break; |
|---|
| 479 | |
|---|
| 480 | case GB_AT_AA: |
|---|
| 481 | warning = ED4_pfold_set_SAI(&ED4_ROOT->protstruct, gb_main, ED4_ROOT->alignment_name, &ED4_ROOT->protstruct_len); |
|---|
| 482 | break; |
|---|
| 483 | |
|---|
| 484 | default: |
|---|
| 485 | e4_assert(0); |
|---|
| 486 | break; |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | if (warning) aw_message(warning); // write to console |
|---|
| 490 | ED4_ROOT->create_first_window(); |
|---|
| 491 | if (warning) { aw_message(warning); warning = NULp; } // write again to status window |
|---|
| 492 | } |
|---|
| 493 | |
|---|
| 494 | ED4_objspec::init_object_specs(); |
|---|
| 495 | { |
|---|
| 496 | bool found_config = false; |
|---|
| 497 | ED4_LocalWinContext uses(ED4_ROOT->first_window); |
|---|
| 498 | |
|---|
| 499 | if (config_name) { |
|---|
| 500 | GB_transaction ta(gb_main); |
|---|
| 501 | GB_ERROR cfg_error; |
|---|
| 502 | GBT_config cfg(gb_main, config_name, cfg_error); |
|---|
| 503 | |
|---|
| 504 | if (cfg.exists()) { |
|---|
| 505 | ED4_ROOT->create_hierarchy(cfg.get_definition(GBT_config::MIDDLE_AREA), cfg.get_definition(GBT_config::TOP_AREA)); // create internal hierarchy |
|---|
| 506 | found_config = true; |
|---|
| 507 | } |
|---|
| 508 | else { |
|---|
| 509 | aw_message(GBS_global_string("Could not find configuration '%s'", config_name)); |
|---|
| 510 | } |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | if (!found_config) { |
|---|
| 514 | aw_popup_ok("The editor needs a configuration stored in database.\n" |
|---|
| 515 | "Cannot continue and will terminate now."); |
|---|
| 516 | ED4_exit(); |
|---|
| 517 | } |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | // now bind DB depending callbacks |
|---|
| 521 | ed4_bind_mainDB_awar_callbacks(ED4_ROOT->aw_root); |
|---|
| 522 | |
|---|
| 523 | // Create Additional sequence (aminoacid) terminals to be used in Protein Viewer |
|---|
| 524 | if (ED4_ROOT->alignment_type == GB_AT_DNA) { |
|---|
| 525 | PV_CallBackFunction(ED4_ROOT->aw_root); |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | AWT_install_postcb_cb(ED4_postcbcb); |
|---|
| 529 | AWT_install_cb_guards(); |
|---|
| 530 | e4_assert(!ED4_WinContext::have_context()); // no global context shall be active |
|---|
| 531 | ED4_ROOT->aw_root->main_loop(); // enter main-loop |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | shutdown_macro_recording(ED4_ROOT->aw_root); |
|---|
| 535 | GB_close(gb_main); |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | bool have_aw_root = ED4_ROOT && ED4_ROOT->aw_root; |
|---|
| 539 | if (error) { |
|---|
| 540 | if (have_aw_root) aw_popup_ok(error.deliver()); |
|---|
| 541 | else fprintf(stderr, "arb_edit4: Error: %s\n", error.deliver()); |
|---|
| 542 | } |
|---|
| 543 | if (have_aw_root) delete ED4_ROOT->aw_root; |
|---|
| 544 | |
|---|
| 545 | return EXIT_SUCCESS; |
|---|
| 546 | } |
|---|
| 547 | |
|---|