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