1 | /* edit_tools.cxx |
---|
2 | *******************************************/ |
---|
3 | |
---|
4 | #include <stdio.h> |
---|
5 | #include <stdlib.h> // system |
---|
6 | #include <string.h> |
---|
7 | |
---|
8 | #include <arbdb.h> |
---|
9 | #include <arbdb++.hxx> |
---|
10 | #include <adtools.hxx> |
---|
11 | #include <aw_root.hxx> |
---|
12 | #include <aw_device.hxx> |
---|
13 | #include <aw_window.hxx> |
---|
14 | #include <BI_helix.hxx> |
---|
15 | #include "edit.hxx" |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | //************************************************************************** |
---|
20 | void create_tool_variables(AW_root *root,AW_default db1) |
---|
21 | { |
---|
22 | root->awar_string( "tmp/tools/search/string", "" , db1); |
---|
23 | root->awar_string( "tmp/tools/search/replace_string", "" , db1); |
---|
24 | root->awar_int( "tmp/tools/search/mismatches", 0, db1); |
---|
25 | root->awar_int( "tmp/tools/search/mistakes_found", 0, db1); |
---|
26 | root->awar_int( "tmp/tools/search/t_equal_u", 0, db1); |
---|
27 | root->awar_int( "tmp/tools/search/upper_eq_lower", 0, db1); |
---|
28 | root->awar_int( "tmp/tools/search/gaps", -1, db1); |
---|
29 | //-----------------------------------------------------------complement |
---|
30 | root->awar_int( "tmp/tools/complement/action", 0, db1); |
---|
31 | root->awar_int( "tmp/tools/complement/gaps_points", 0, db1); |
---|
32 | root->awar_int( "tmp/tools/complement/left", 0, db1); |
---|
33 | root->awar_int( "tmp/tools/complement/right", 0, db1); |
---|
34 | } |
---|
35 | //************************************************************************** |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | //************************************************************************** |
---|
41 | // Search/Replace Liefert alle Sequenzen eines Bereiches. |
---|
42 | //************************************************************************** |
---|
43 | void search_get_area( AED_window *aedw, AED_area_entry *get_area_current, |
---|
44 | ADT_SEARCH *ptr_adt_search, ADT_EDIT *ptr_adt_edit ) { |
---|
45 | |
---|
46 | AD_ERR *ad_err; |
---|
47 | |
---|
48 | //================================Sequenzsuche solange AREA nicht leer. |
---|
49 | while( get_area_current != NULL ) { |
---|
50 | ADT_SEQUENCE *get_area_adt_sequence; |
---|
51 | |
---|
52 | if( ptr_adt_search->replace_option != ADT_NO_REPLACE ) { |
---|
53 | if (aw_status()) break; |
---|
54 | } |
---|
55 | //----------------------------------------selektierte sequence |
---|
56 | if(get_area_current->is_selected != 0) { |
---|
57 | ptr_adt_edit->selection = 1; |
---|
58 | // im Alignement selektierten String gefunden |
---|
59 | } |
---|
60 | //---------------------------------------------------end selec |
---|
61 | |
---|
62 | //-------------------------------------------func aufruf/fehler |
---|
63 | get_area_adt_sequence = get_area_current->adt_sequence; |
---|
64 | |
---|
65 | if( (ptr_adt_edit->selection == 1) && |
---|
66 | (get_area_adt_sequence != NULL) ){ |
---|
67 | ad_err = get_area_adt_sequence-> |
---|
68 | show_edit_seq_search(ptr_adt_search, ptr_adt_edit); |
---|
69 | //############################################### |
---|
70 | |
---|
71 | if(ad_err) { |
---|
72 | // printf("**** ERROR ADT_SEARCH"); |
---|
73 | // printf(" show_edit_replace()\n"); |
---|
74 | aw_message(ad_err->show()); |
---|
75 | return; |
---|
76 | } // end if(ad_err) |
---|
77 | |
---|
78 | } // end if (selection) |
---|
79 | //---------------------------------------------end func aufruf |
---|
80 | |
---|
81 | //------------------------------------------REPLACE REST EDITOR |
---|
82 | if(ptr_adt_search->replace_option == ADT_REPLACE_REST_EDITOR) { |
---|
83 | ptr_adt_edit->found_matchp = 0; |
---|
84 | ptr_adt_search->replace_loop_sequence = |
---|
85 | ADT_DONT_STOPP_REPLACE; |
---|
86 | } |
---|
87 | //-----------------------------------------------------END REST |
---|
88 | |
---|
89 | //-------------------------------------------get next Sequence |
---|
90 | if( ptr_adt_edit->found_matchp == 0 ) { |
---|
91 | if(ptr_adt_search->search_direction == |
---|
92 | ADT_SEARCH_FORWARD) { |
---|
93 | get_area_current = get_area_current->next; |
---|
94 | } |
---|
95 | else { |
---|
96 | get_area_current = get_area_current->previous; |
---|
97 | } |
---|
98 | |
---|
99 | } |
---|
100 | //----------matchpattern found |
---|
101 | else { |
---|
102 | break; |
---|
103 | } |
---|
104 | //------------------------------------------------------------ |
---|
105 | |
---|
106 | } //===========================================end while: Sequenzsuche |
---|
107 | |
---|
108 | |
---|
109 | //---------------------------------------------------Eintrag in Editor |
---|
110 | if(ptr_adt_edit->found_matchp == 1) { |
---|
111 | set_cursor_to( aedw, |
---|
112 | (int)ptr_adt_edit->actual_cursorpos_editor, |
---|
113 | get_area_current ); |
---|
114 | } |
---|
115 | //--------------------------------------------------ENDE Editoreintrag |
---|
116 | |
---|
117 | } // end func: search_get_area() |
---|
118 | //************************************************************************** |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | //************************************************************************** |
---|
124 | // Aufruf der Dialogbox > search/replace < + deren Funktionalitaeten |
---|
125 | //************************************************************************** |
---|
126 | void edit_tool_search_cb(AW_window *aw, AED_window *aedwindow, |
---|
127 | ADT_BUTTON pressed_button ){ |
---|
128 | |
---|
129 | AW_root *awroot = aw->get_root(); |
---|
130 | ADT_SEARCH adt_search; |
---|
131 | ADT_EDIT adt_edit; |
---|
132 | AD_ERR *adt_error; |
---|
133 | |
---|
134 | long mismatches = awroot->awar("tmp/tools/search/mismatches")->read_int(); //erlaubte Fehler |
---|
135 | char *search = awroot->awar("tmp/tools/search/string")->read_string(); //Suchstring |
---|
136 | char *repl_str = awroot->awar("tmp/tools/search/replace_string")->read_string(); //replace String |
---|
137 | long t_equal_u = awroot->awar("tmp/tools/search/t_equal_u")->read_int(); //t und u gleich? |
---|
138 | long upper_eq_lower = awroot->awar("tmp/tools/search/upper_eq_lower")->read_int(); //GROSS/klein beachten? |
---|
139 | long gaps = awroot->awar("tmp/tools/search/gaps")->read_int(); //Gaps beachten? |
---|
140 | |
---|
141 | adt_search.matchpattern = search; // Suchstring |
---|
142 | adt_search.replace_string = repl_str; |
---|
143 | adt_search.gaps = gaps; // Mit oder ohne Gaps |
---|
144 | |
---|
145 | ADT_SEARCH_DIRECTION direction = ADT_SEARCH_FORWARD; |
---|
146 | ADT_REPLACE_OPTION option = ADT_NO_REPLACE; |
---|
147 | |
---|
148 | switch(pressed_button) { |
---|
149 | |
---|
150 | // SEARCH-Buttons |
---|
151 | case BUTTON_SEARCH_ALL: |
---|
152 | direction = ADT_SEARCH_ALL; |
---|
153 | break; |
---|
154 | case BUTTON_SEARCH_FORWARD: |
---|
155 | direction = ADT_SEARCH_FORWARD; |
---|
156 | break; |
---|
157 | case BUTTON_SEARCH_BACKWARD: |
---|
158 | direction = ADT_SEARCH_BACKWARD; |
---|
159 | break; |
---|
160 | |
---|
161 | // REPLACE-Buttons |
---|
162 | case BUTTON_REPLACE_ONLY: |
---|
163 | option = ADT_REPLACE_ONLY; |
---|
164 | break; |
---|
165 | case BUTTON_REPLACE_AND_SEARCH_NEXT: |
---|
166 | direction = ADT_SEARCH_FORWARD; |
---|
167 | option = ADT_REPLACE_AND_SEARCH_NEXT; |
---|
168 | break; |
---|
169 | case BUTTON_SEARCH_AND_REPLACE_NEXT: |
---|
170 | direction = ADT_SEARCH_FORWARD; |
---|
171 | option = ADT_SEARCH_AND_REPLACE_NEXT; |
---|
172 | break; |
---|
173 | case BUTTON_REPLACE_REST_SEQUENCE: |
---|
174 | direction = ADT_SEARCH_FORWARD; |
---|
175 | option = ADT_REPLACE_REST_SEQUENCE; |
---|
176 | break; |
---|
177 | case BUTTON_REPLACE_REST_EDITOR: |
---|
178 | direction = ADT_SEARCH_FORWARD; |
---|
179 | option = ADT_REPLACE_REST_EDITOR; |
---|
180 | break; |
---|
181 | default: |
---|
182 | GB_warning("Unknown case in switch in search"); |
---|
183 | // Default ueber Konstruktor von ADT_SEARCH |
---|
184 | } |
---|
185 | |
---|
186 | if(option >= 0) { |
---|
187 | adt_search.replace_option = option; |
---|
188 | } |
---|
189 | //Mehr oder gleichviele Fehler erlaubt |
---|
190 | //als Suchstring lang? |
---|
191 | if( strlen(search) == 0 && option < 0 ) { |
---|
192 | aw_message("********* Please insert Matchpattern! *********"); |
---|
193 | free(search); |
---|
194 | return; |
---|
195 | } |
---|
196 | |
---|
197 | /* if( option >= 0 ) { |
---|
198 | if( strlen(repl_str) == 0 ) { |
---|
199 | aw_message("********* Please insert Replace-String! *********"); |
---|
200 | free(search); |
---|
201 | free(repl_str); |
---|
202 | return; |
---|
203 | } |
---|
204 | } |
---|
205 | */ |
---|
206 | |
---|
207 | if( option >= 0 && adt_search.gaps >= 0 ) { |
---|
208 | if( strlen(adt_search.matchpattern) != |
---|
209 | strlen(adt_search.replace_string) ) { |
---|
210 | aw_message("********* WITHOUT GAPS *********\n Search_String length must be\n\n >>>> EQUAL <<<<\n\n as Replace_String length!"); |
---|
211 | free(search); |
---|
212 | free(repl_str); |
---|
213 | return; |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | if( (mismatches > 0) && (strlen(search) <= (unsigned long)mismatches)) { |
---|
218 | aw_message("********* Mismatches must be lower as Search_String length! *********"); |
---|
219 | free(search); |
---|
220 | return; |
---|
221 | } |
---|
222 | |
---|
223 | //--------------------------------------------Anzahl erlaubter Fehler; |
---|
224 | adt_search.mistakes_allowed = mismatches; |
---|
225 | //------------------------------------------------------------------- |
---|
226 | |
---|
227 | //---------------------------------------Suchen ja, aber im Editor ist |
---|
228 | //noch nichts markiert! |
---|
229 | if(aedwindow->one_area_entry_is_selected == AW_FALSE) { |
---|
230 | |
---|
231 | //-------------------------------------no selection no replace |
---|
232 | if( adt_search.replace_option != ADT_NO_REPLACE ) { |
---|
233 | aw_message("There`s nothing SELECTED !!"); |
---|
234 | free(search); |
---|
235 | free(repl_str); |
---|
236 | return; |
---|
237 | } |
---|
238 | //---------------------------------------------end select-repl |
---|
239 | |
---|
240 | adt_search.search_direction=ADT_SEARCH_FORWARD; |
---|
241 | adt_search.search_start_cursor_pos = 0; |
---|
242 | adt_edit.selection=1; |
---|
243 | } |
---|
244 | //-------------------------------------------------------------------- |
---|
245 | |
---|
246 | //-------------------------------------Hole Cursorposition der Sequenz; |
---|
247 | if(aedwindow->cursor_is_managed) { |
---|
248 | adt_edit.actual_cursorpos_editor = (long) aedwindow->cursor; |
---|
249 | } |
---|
250 | //-------------------------------------------------------------------- |
---|
251 | |
---|
252 | //---------------------------------------Suchrichtung, Start der Suche; |
---|
253 | if(direction == ADT_SEARCH_ALL) { |
---|
254 | adt_search.search_direction=ADT_SEARCH_FORWARD; |
---|
255 | adt_search.search_start_cursor_pos = 0; |
---|
256 | adt_edit.actual_cursorpos_editor = -1; |
---|
257 | adt_edit.selection=1; |
---|
258 | } |
---|
259 | else{ |
---|
260 | adt_search.search_direction = direction; |
---|
261 | adt_search.search_start_cursor_pos = |
---|
262 | adt_edit.actual_cursorpos_editor + adt_search.search_direction; |
---|
263 | } // Cursorpos. +/-1 |
---|
264 | //-------------------------------------------------------------------- |
---|
265 | |
---|
266 | //-------------------------------------------- t und u gleichbehandeln; |
---|
267 | if(t_equal_u) { |
---|
268 | adt_search.t_equal_u = 1; // JA |
---|
269 | } |
---|
270 | //-------------------------------------------------------------------- |
---|
271 | |
---|
272 | //----------------------------------------------- GROSS/klein beachten; |
---|
273 | if(upper_eq_lower) { |
---|
274 | adt_search.upper_eq_lower = 1; // JA |
---|
275 | } |
---|
276 | //-------------------------------------------------------------------- |
---|
277 | |
---|
278 | adt_search.compile(); //Stellt Zeichensatz zur Verfuegung |
---|
279 | |
---|
280 | //============================================== REPLACE => DB oeffnen |
---|
281 | AD_MAIN *database_functions = aedwindow->root->ad_main; |
---|
282 | |
---|
283 | if( adt_search.replace_option != ADT_NO_REPLACE ) { |
---|
284 | adt_error = database_functions->begin_transaction(); |
---|
285 | if(adt_error) { |
---|
286 | aw_message("ADT_SEARCH::begin_transaction failed"); |
---|
287 | } |
---|
288 | adt_edit.db_status = ADT_DB_OPEN; |
---|
289 | } |
---|
290 | // ========================================================== DB offen |
---|
291 | |
---|
292 | //--------------------------------------------Funktionsaufrufe liefern |
---|
293 | //die Sequenzen der drei Bereiche: |
---|
294 | //Top, Middle, Bottom, ab !! der |
---|
295 | //markierten Sequenz |
---|
296 | if( adt_search.replace_option != ADT_NO_REPLACE ) { |
---|
297 | aw_openstatus("SEARCH & REPLACE"); |
---|
298 | } |
---|
299 | |
---|
300 | if(adt_search.search_direction == ADT_SEARCH_FORWARD) { |
---|
301 | search_get_area( aedwindow, aedwindow->area_top->first, |
---|
302 | &adt_search, &adt_edit ); |
---|
303 | |
---|
304 | if( adt_edit.found_matchp == 0 ) { |
---|
305 | search_get_area( aedwindow, |
---|
306 | aedwindow->area_middle->first, |
---|
307 | &adt_search, &adt_edit ); |
---|
308 | } |
---|
309 | |
---|
310 | if( adt_edit.found_matchp == 0 ) { |
---|
311 | search_get_area( aedwindow, |
---|
312 | aedwindow->area_bottom->first, |
---|
313 | &adt_search, &adt_edit ); |
---|
314 | } |
---|
315 | }else { // adt_search.search_direction == ADT_SEARCH_BACKWARD |
---|
316 | search_get_area( aedwindow, aedwindow->area_bottom->last, |
---|
317 | &adt_search, &adt_edit ); |
---|
318 | |
---|
319 | if( adt_edit.found_matchp == 0 ) { |
---|
320 | search_get_area( aedwindow, aedwindow->area_middle->last, |
---|
321 | &adt_search, &adt_edit ); |
---|
322 | } |
---|
323 | |
---|
324 | if( adt_edit.found_matchp == 0 ) { |
---|
325 | search_get_area( aedwindow, aedwindow->area_top->last, |
---|
326 | &adt_search, &adt_edit ); |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | aw_closestatus(); |
---|
331 | |
---|
332 | //------------------------------------------------------------------- |
---|
333 | |
---|
334 | // ======================================================DB schliessen |
---|
335 | if( adt_edit.db_status == ADT_DB_OPEN ) { |
---|
336 | adt_error = database_functions->commit_transaction(); |
---|
337 | |
---|
338 | if(adt_error) { |
---|
339 | aw_message("ADT_SEARCH::commit_transaction failed"); |
---|
340 | } |
---|
341 | adt_edit.db_status = ADT_DB_CLOSED; |
---|
342 | } |
---|
343 | // =====================================================DB geschlossen |
---|
344 | |
---|
345 | // ----------------------------------------------------Fehlermeldungen |
---|
346 | if( (adt_edit.found_matchp == 0) && (adt_search.string_replace == 0)) { |
---|
347 | aw_message("******** Nothing found! *********"); |
---|
348 | } |
---|
349 | |
---|
350 | if( adt_edit.seq_equal_match == 0 ) { |
---|
351 | aw_message("********* For Replace_Only *********\nCursor moved ???\nFrom cursorposition on,\nSequence and Matchpattern are not equal! "); |
---|
352 | } |
---|
353 | |
---|
354 | if( adt_edit.replace_overflow == 1 ) { |
---|
355 | aw_message("********* Didn`t you SEARCH ??? *********\nOr Replace-String is longer as Rest-Sequence !!!"); |
---|
356 | } |
---|
357 | //-------------------------------------------------end Fehlermeldungen |
---|
358 | |
---|
359 | //-------------------------------------------------Schreiben in Editor |
---|
360 | //Schreibt Anzahl der gefundenen |
---|
361 | //Fehler in den Editor |
---|
362 | awroot->awar("tmp/tools/search/mistakes_found")->write_int( adt_edit.mistakes_found); |
---|
363 | //------------------------------------------------------end schreiben |
---|
364 | |
---|
365 | //-------------------------------------------------Speicher freigeben |
---|
366 | free(search); |
---|
367 | free(repl_str); |
---|
368 | //------------------------------------------------------------------- |
---|
369 | |
---|
370 | |
---|
371 | } // end edit_tool_search_cb() |
---|
372 | //************************************************************************** |
---|
373 | |
---|
374 | |
---|
375 | |
---|
376 | |
---|
377 | //*************************************************************************** |
---|
378 | // Sucht die richtige Sequenz fuer Complement/Invertieren |
---|
379 | //*************************************************************************** |
---|
380 | void compl_get_area( AED_window *aedw, AED_area_entry *get_area_current, ADT_COMPLEMENT *ptr_adt_complement, ADT_EDIT *ptr_adt_edit ) { |
---|
381 | |
---|
382 | AD_ERR *ad_err; |
---|
383 | AWUSE(aedw); |
---|
384 | |
---|
385 | while(get_area_current != NULL) |
---|
386 | { |
---|
387 | ADT_SEQUENCE *get_area_adt_sequence; |
---|
388 | AD_SPECIES *ptr_ad_species; |
---|
389 | |
---|
390 | //----------------------------------------selektierte sequence |
---|
391 | if(get_area_current->is_selected != 0) { |
---|
392 | ptr_adt_edit->selection = 1; |
---|
393 | // im Alignement selektierten String gefunden |
---|
394 | } |
---|
395 | //---------------------------------------------------end selec |
---|
396 | |
---|
397 | //-------------------------------------------func aufruf/fehler |
---|
398 | get_area_adt_sequence = get_area_current->adt_sequence; |
---|
399 | |
---|
400 | if( (ptr_adt_edit->selection == 1) && (get_area_adt_sequence != NULL) ) { |
---|
401 | //---------------------------------------------- Species name |
---|
402 | ptr_ad_species = get_area_current->ad_species; |
---|
403 | ptr_adt_complement->species_name = ptr_ad_species->name(); |
---|
404 | //------------------------------------------ end Species name |
---|
405 | |
---|
406 | ad_err = get_area_adt_sequence->show_edit_seq_compl( ptr_adt_complement, ptr_adt_edit); |
---|
407 | //############################################### |
---|
408 | |
---|
409 | if(ad_err) { |
---|
410 | // printf("**** ERROR ADT_COMPLEMENT"); |
---|
411 | // printf(" show_edit_seq_compl()\n"); |
---|
412 | aw_message(ad_err->show()); |
---|
413 | return; |
---|
414 | } // end if(ad_err) |
---|
415 | |
---|
416 | //-------------------------------------------get next Sequence |
---|
417 | if((ptr_adt_complement->which_button == BUTTON_COMPL_BLOCK) || |
---|
418 | (ptr_adt_complement->which_button == BUTTON_COMPL_REST_SEQUENCE) || |
---|
419 | (ptr_adt_complement->which_button == BUTTON_COMPL_SEQUENCE)) |
---|
420 | { |
---|
421 | break; |
---|
422 | } |
---|
423 | //------------------------------------------------------------ |
---|
424 | } // end if (selection) |
---|
425 | //---------------------------------------------end func aufruf |
---|
426 | |
---|
427 | get_area_current = get_area_current->next; |
---|
428 | |
---|
429 | } //===========================================end while: Sequenzsuche |
---|
430 | |
---|
431 | } // end compl_get_area() |
---|
432 | //*************************************************************************** |
---|
433 | |
---|
434 | |
---|
435 | |
---|
436 | |
---|
437 | //*************************************************************************** |
---|
438 | // Bildet das Complement und invertiert die Sequence |
---|
439 | //*************************************************************************** |
---|
440 | void edit_tool_complement_cb(AW_window *aw, AED_window *aedwindow, |
---|
441 | ADT_BUTTON pressed_button ){ |
---|
442 | |
---|
443 | AW_root *awroot = aw->get_root(); |
---|
444 | AD_ERR *adt_error; |
---|
445 | ADT_COMPLEMENT adt_complement; |
---|
446 | ADT_EDIT adt_edit; |
---|
447 | |
---|
448 | |
---|
449 | switch(pressed_button) { |
---|
450 | |
---|
451 | case NO_BUTTON: |
---|
452 | aw_message("Oh Sweety - You are really in trouble now."); |
---|
453 | return; |
---|
454 | //break; |
---|
455 | case BUTTON_COMPL_BLOCK: |
---|
456 | adt_complement.which_button = BUTTON_COMPL_BLOCK; |
---|
457 | adt_complement.take_borders = YES; |
---|
458 | break; |
---|
459 | case BUTTON_COMPL_REST_SEQUENCE: |
---|
460 | adt_complement.which_button = BUTTON_COMPL_REST_SEQUENCE; |
---|
461 | adt_complement.take_cursor = YES; |
---|
462 | break; |
---|
463 | case BUTTON_COMPL_SEQUENCE: |
---|
464 | adt_complement.which_button = BUTTON_COMPL_SEQUENCE; |
---|
465 | break; |
---|
466 | case BUTTON_COMPL_REST_TEXT: |
---|
467 | adt_complement.which_button = BUTTON_COMPL_REST_TEXT; |
---|
468 | adt_complement.take_cursor = YES; |
---|
469 | break; |
---|
470 | case BUTTON_COMPL_ALL: |
---|
471 | adt_complement.which_button = BUTTON_COMPL_ALL; |
---|
472 | adt_edit.selection = 1; |
---|
473 | break; |
---|
474 | default: |
---|
475 | GB_warning("Unknown case in switch in search"); |
---|
476 | } |
---|
477 | |
---|
478 | if( (!(adt_complement.which_button == BUTTON_COMPL_ALL)) && |
---|
479 | (aedwindow->one_area_entry_is_selected == AW_FALSE) |
---|
480 | ) { |
---|
481 | aw_message("**** ERROR: no sequence selected !"); |
---|
482 | return; |
---|
483 | } |
---|
484 | |
---|
485 | // adt_complement.ad_species = aedwindow->selected_area_entry->ad_species; |
---|
486 | adt_complement.alignment_type = aedwindow->alignment->type(); |
---|
487 | adt_complement.alignment_name = aedwindow->alignment->name(); |
---|
488 | adt_complement.alignment_length = aedwindow->alignment->len(); |
---|
489 | |
---|
490 | |
---|
491 | //-----------------------------------------------------complement/invert |
---|
492 | long action = awroot->awar("tmp/tools/complement/action")->read_int(); |
---|
493 | if( (action == 0) || (action == 1) ) { // complement |
---|
494 | adt_complement.complement_seq = YES; |
---|
495 | } |
---|
496 | if( (action == 0) || (action == 2) ) { // invert |
---|
497 | adt_complement.invert_seq = YES; |
---|
498 | //adt_complement.complement_buffers(); // wird in der fct aufger |
---|
499 | } |
---|
500 | //-------------------------------------------------end complement/invert |
---|
501 | |
---|
502 | //----------------------------------------------------remove GAPS/points |
---|
503 | long gaps_points = awroot->awar("tmp/tools/complement/gaps_points")->read_int(); |
---|
504 | if(gaps_points == 1) { // DEFAULT: 0 = NO !! |
---|
505 | adt_complement.remove_gaps_points = YES; |
---|
506 | } |
---|
507 | //------------------------------------------------end remove GAPS/points |
---|
508 | |
---|
509 | //-------------------------------------Hole Cursorposition der Sequenz; |
---|
510 | if(aedwindow->cursor_is_managed) { |
---|
511 | adt_edit.actual_cursorpos_editor = (long) aedwindow->cursor; |
---|
512 | } |
---|
513 | else { |
---|
514 | adt_edit.actual_cursorpos_editor = 0; |
---|
515 | } |
---|
516 | //--------------------------------------------------------end cursorpos |
---|
517 | |
---|
518 | //---------------------------------------------------------take borders |
---|
519 | if(adt_complement.take_borders == YES) { |
---|
520 | long left_border = awroot->awar("tmp/tools/complement/left")->read_int(); |
---|
521 | long right_border = awroot->awar("tmp/tools/complement/right")->read_int(); |
---|
522 | |
---|
523 | if(left_border < 0) { |
---|
524 | aw_message("**** ERROR: left border >= 0 !"); |
---|
525 | return; |
---|
526 | } |
---|
527 | if(left_border > (adt_complement.alignment_length - 1)) { |
---|
528 | aw_message("**** ERROR: left border <= alignment length !"); |
---|
529 | return; |
---|
530 | |
---|
531 | } |
---|
532 | if(right_border < left_border) { |
---|
533 | aw_message("**** ERROR: right border >= left border !"); |
---|
534 | return; |
---|
535 | } |
---|
536 | if(right_border > (adt_complement.alignment_length - 1)) { |
---|
537 | right_border = (adt_complement.alignment_length - 1); |
---|
538 | } |
---|
539 | |
---|
540 | adt_complement.left_border = left_border; |
---|
541 | adt_complement.right_border = right_border; |
---|
542 | } |
---|
543 | //----------------------------------------------------------end borders |
---|
544 | |
---|
545 | //---------------------------------------------Complement dna/rna/... ? |
---|
546 | if( adt_complement.complement_seq == YES ) { |
---|
547 | if( strcmp(adt_complement.alignment_type,"rna")==0 ) { |
---|
548 | adt_complement.adt_acid = ADT_ALITYPE_RNA; |
---|
549 | } |
---|
550 | else if( strcmp(adt_complement.alignment_type,"dna")==0 ) { |
---|
551 | adt_complement.adt_acid = ADT_ALITYPE_DNA; |
---|
552 | } |
---|
553 | else if( strcmp(adt_complement.alignment_type,"ami")==0 ) { |
---|
554 | //adt_complement.adt_acid = ADT_ALITYPE_AMI; |
---|
555 | aw_message("NO COMPLEMENT: Alignment Type is AMINO-ACID!"); |
---|
556 | return; |
---|
557 | } |
---|
558 | else { |
---|
559 | //adt_complement.adt_acid = ADT_ALITYPE_UNDEFINED; |
---|
560 | aw_message("NO COMPLEMENT: Alignment Type is UNDEFINED!"); |
---|
561 | return; |
---|
562 | } |
---|
563 | adt_complement.complement_compile(); |
---|
564 | } |
---|
565 | //---------------------------------------------------end compl dna/rna/ |
---|
566 | |
---|
567 | //============================================== REPLACE => DB oeffnen |
---|
568 | AD_MAIN *database_functions = aedwindow->root->ad_main; |
---|
569 | |
---|
570 | adt_error = database_functions->begin_transaction(); |
---|
571 | |
---|
572 | if(adt_error) { |
---|
573 | aw_message("ADT_SEARCH::begin_transaction failed"); |
---|
574 | } |
---|
575 | adt_edit.db_status = ADT_DB_OPEN; |
---|
576 | // ========================================================== DB offen |
---|
577 | |
---|
578 | //--------------------------------------------Funktionsaufrufe liefern |
---|
579 | //die Sequenzen der drei Bereiche: |
---|
580 | //Top, Middle, Bottom, ab !! der |
---|
581 | //markierten Sequenz |
---|
582 | |
---|
583 | //soll entfallen compl_get_area( aedwindow, aedwindow->area_top->first, |
---|
584 | // &adt_complement, &adt_edit ); |
---|
585 | |
---|
586 | compl_get_area( aedwindow, aedwindow->area_middle->first, |
---|
587 | &adt_complement, &adt_edit ); |
---|
588 | |
---|
589 | //soll entfallen compl_get_area( aedwindow, aedwindow->area_bottom->first, |
---|
590 | // &adt_complement, &adt_edit ); |
---|
591 | //------------------------------------------------------------------- |
---|
592 | |
---|
593 | // ======================================================DB schliessen |
---|
594 | adt_error = database_functions->commit_transaction(); |
---|
595 | |
---|
596 | if(adt_error) { |
---|
597 | aw_message("ADT_SEARCH::commit_transaction failed"); |
---|
598 | } |
---|
599 | adt_edit.db_status = ADT_DB_CLOSED; |
---|
600 | // =====================================================DB geschlossen |
---|
601 | |
---|
602 | } // end edit_tool_complement_cb() |
---|
603 | //*************************************************************************** |
---|
604 | |
---|
605 | |
---|
606 | |
---|
607 | |
---|
608 | //*************************************************************************** |
---|
609 | // gemeinsam in SEARCH und REPLACE |
---|
610 | //*************************************************************************** |
---|
611 | AW_window *common_window_features( AW_window_simple *aws, |
---|
612 | AED_window *aedwindow ) |
---|
613 | { |
---|
614 | aws->label_length( 7 ); |
---|
615 | aws->button_length( 14 ); |
---|
616 | |
---|
617 | aws->at( "close" ); |
---|
618 | aws->callback ( (AW_CB0)AW_POPDOWN ); |
---|
619 | aws->create_button( "CLOSE", "CLOSE", "C" ); |
---|
620 | |
---|
621 | aws->label_length( 7 ); |
---|
622 | aws->button_length( 18 ); |
---|
623 | |
---|
624 | aws->at("start"); |
---|
625 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
626 | (AW_CL)BUTTON_SEARCH_FORWARD );// +1 |
---|
627 | aws->create_button( "FIND_NEXT", "FIND NEXT ", "1" ); |
---|
628 | |
---|
629 | aws->at("start_rev"); |
---|
630 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
631 | (AW_CL)BUTTON_SEARCH_BACKWARD );// -1 |
---|
632 | aws->create_button( "FIND_BACK", "FIND BACKWARD ", "2" ); |
---|
633 | |
---|
634 | aws->at("start_all"); |
---|
635 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
636 | (AW_CL)BUTTON_SEARCH_ALL ); // 0 |
---|
637 | aws->create_button( "FIND_ALL", "FIND ALL ", "3" ); |
---|
638 | |
---|
639 | aws->at("search"); |
---|
640 | aws->create_input_field("tmp/tools/search/string",49); |
---|
641 | |
---|
642 | aws->at("mismatches"); |
---|
643 | aws->create_input_field("tmp/tools/search/mismatches",3); |
---|
644 | |
---|
645 | aws->at("mistakes"); |
---|
646 | aws->create_button(0,"tmp/tools/search/mistakes_found"); |
---|
647 | |
---|
648 | aws->at("t_equal_u"); |
---|
649 | aws->create_option_menu("tmp/tools/search/t_equal_u",0,""); |
---|
650 | aws->insert_default_option("T <> U","N",0); |
---|
651 | aws->insert_option("T = U ","Y",1); |
---|
652 | aws->update_option_menu(); |
---|
653 | |
---|
654 | aws->at("upper_eq_lower"); |
---|
655 | aws->create_option_menu("tmp/tools/search/upper_eq_lower",0,""); |
---|
656 | aws->insert_default_option("a <> A","N",0); |
---|
657 | aws->insert_option("a = A ","Y",1); |
---|
658 | aws->update_option_menu(); |
---|
659 | |
---|
660 | aws->at("gaps"); |
---|
661 | aws->create_option_menu("tmp/tools/search/gaps",0,""); |
---|
662 | aws->insert_default_option (" 'A-A' <> 'AA' ","D",-1); |
---|
663 | aws->insert_option (" IGNORE GAPS IN SEQ ","S",0); |
---|
664 | aws->insert_option (" IGNORE GAPS IN SEARCH","M",2); |
---|
665 | aws->insert_option (" IGNORE ALL GAPS ","B",1); |
---|
666 | aws->update_option_menu(); |
---|
667 | |
---|
668 | return aws; |
---|
669 | } |
---|
670 | //*************************************************************************** |
---|
671 | |
---|
672 | |
---|
673 | |
---|
674 | //*************************************************************************** |
---|
675 | // |
---|
676 | //*************************************************************************** |
---|
677 | AW_window *create_tool_search( AW_root *root, AED_window *aedwindow ) |
---|
678 | { |
---|
679 | AW_window_simple *aws = new AW_window_simple; |
---|
680 | aws->init( root, "SEARCH_STRING","EDIT SEARCH", 80, 425 ); |
---|
681 | aws->load_xfig("ed_searc.fig"); |
---|
682 | |
---|
683 | aws->label_length( 7 ); |
---|
684 | aws->button_length( 14 ); |
---|
685 | |
---|
686 | |
---|
687 | common_window_features( aws, aedwindow ); |
---|
688 | |
---|
689 | return aws; |
---|
690 | } |
---|
691 | //*************************************************************************** |
---|
692 | |
---|
693 | |
---|
694 | |
---|
695 | //*************************************************************************** |
---|
696 | // |
---|
697 | //*************************************************************************** |
---|
698 | AW_window *create_tool_replace( AW_root *root, AED_window *aedwindow ) |
---|
699 | { |
---|
700 | AW_window_simple *aws = new AW_window_simple; |
---|
701 | aws->init( root, "REPLACE_STRING", "EDIT REPLACE", 120, 435 ); |
---|
702 | aws->load_xfig("ed_repla.fig"); |
---|
703 | |
---|
704 | aws->label_length( 7 ); |
---|
705 | aws->button_length( 14 ); |
---|
706 | |
---|
707 | // aws->at( "reopen" ); |
---|
708 | // aws->callback ( AW_POPUP, (AW_CL)create_tool_replace, |
---|
709 | // (AW_CL)aedwindow ); |
---|
710 | // aws->create_button( "REOPEN", "R" ); |
---|
711 | |
---|
712 | aws->at("replace"); |
---|
713 | aws->create_input_field("tmp/tools/search/replace_string",49); |
---|
714 | |
---|
715 | aws->button_length( 28 ); |
---|
716 | aws->at("start_replace"); |
---|
717 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
718 | (AW_CL)BUTTON_REPLACE_ONLY ); |
---|
719 | aws->create_button( "REPLACE", "REPLACE", "4" ); |
---|
720 | |
---|
721 | aws->at("replace_and_find_next"); |
---|
722 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
723 | (AW_CL)BUTTON_REPLACE_AND_SEARCH_NEXT ); |
---|
724 | aws->create_button( "REPLACE_FIND", "REPLACE THEN FIND", "5" ); |
---|
725 | |
---|
726 | aws->at("find_and_replace_next"); |
---|
727 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
728 | (AW_CL)BUTTON_SEARCH_AND_REPLACE_NEXT ); |
---|
729 | aws->create_button( "FIND_REPLACE", "FIND THEN REPLACE", "6" ); |
---|
730 | |
---|
731 | aws->at("replace_rest_sequence"); |
---|
732 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
733 | (AW_CL)BUTTON_REPLACE_REST_SEQUENCE ); |
---|
734 | aws->create_button( "REPLACE_TO_END_OF_SEQUENCE", "REPLACE TO END OF SEQUENCE", "7" ); |
---|
735 | |
---|
736 | aws->at("replace_rest_editor"); |
---|
737 | aws->callback ( (AW_CB)edit_tool_search_cb, (AW_CL)aedwindow, |
---|
738 | (AW_CL)BUTTON_REPLACE_REST_EDITOR ); |
---|
739 | aws->create_button( "REPLACE_TO_END_OF_EDITOR", "REPLACE TO END OF EDITOR", "8" ); |
---|
740 | |
---|
741 | common_window_features( aws, aedwindow ); |
---|
742 | return aws; |
---|
743 | } |
---|
744 | //*************************************************************************** |
---|
745 | |
---|
746 | |
---|
747 | |
---|
748 | //*************************************************************************** |
---|
749 | // |
---|
750 | //*************************************************************************** |
---|
751 | AW_window *create_tool_complement( AW_root *root, AED_window *aedwindow ) |
---|
752 | { |
---|
753 | AW_window_simple *aws = new AW_window_simple; |
---|
754 | aws->init( root, "COMPLEMENT_SEQUENCE", "COMPLEMENT and REVERS", 160, 445 ); |
---|
755 | aws->load_xfig("ed_compl.fig"); |
---|
756 | |
---|
757 | aws->label_length( 7 ); |
---|
758 | aws->button_length( 14 ); |
---|
759 | |
---|
760 | aws->at( "close" ); |
---|
761 | aws->callback ( (AW_CB0)AW_POPDOWN ); |
---|
762 | aws->create_button( "CLOSE", "CLOSE", "C" ); |
---|
763 | |
---|
764 | |
---|
765 | aws->at("action"); |
---|
766 | aws->create_option_menu("tmp/tools/complement/action",0,""); |
---|
767 | aws->insert_default_option(" COMPLEMENT AND REVERS ","1",0); |
---|
768 | aws->insert_option (" COMPLEMENT ","2",1); |
---|
769 | aws->insert_option (" REVERS ","3",2); |
---|
770 | aws->update_option_menu(); |
---|
771 | |
---|
772 | aws->at("gaps_points"); |
---|
773 | aws->id("remove_option"); |
---|
774 | aws->create_toggle("tmp/tools/complement/gaps_points"); |
---|
775 | |
---|
776 | aws->at("left"); |
---|
777 | aws->create_input_field("tmp/tools/complement/left",8); |
---|
778 | |
---|
779 | aws->at("right"); |
---|
780 | aws->create_input_field("tmp/tools/complement/right",8); |
---|
781 | |
---|
782 | aws->button_length( 17 ); |
---|
783 | aws->at("block"); |
---|
784 | aws->callback ( (AW_CB)edit_tool_complement_cb, (AW_CL)aedwindow, |
---|
785 | (AW_CL)BUTTON_COMPL_BLOCK ); |
---|
786 | aws->create_button( "COMPLEMENT_PART", "SEQUENCE PART", "P" ); |
---|
787 | |
---|
788 | aws->at("rest_seq"); |
---|
789 | aws->callback ( (AW_CB)edit_tool_complement_cb, (AW_CL)aedwindow, |
---|
790 | (AW_CL)BUTTON_COMPL_REST_SEQUENCE ); |
---|
791 | aws->create_button( "COMPLEMENT_REST", "REST SEQUENCE", "1" ); |
---|
792 | |
---|
793 | aws->at("sequence"); |
---|
794 | aws->callback ( (AW_CB)edit_tool_complement_cb, (AW_CL)aedwindow, |
---|
795 | (AW_CL)BUTTON_COMPL_SEQUENCE ); |
---|
796 | aws->create_button( "COMPLEMENT_SEQUENCE", "SEQUENCE", "2" ); |
---|
797 | |
---|
798 | aws->at("rest_text"); |
---|
799 | aws->callback ( (AW_CB)edit_tool_complement_cb, (AW_CL)aedwindow, |
---|
800 | (AW_CL)BUTTON_COMPL_REST_TEXT ); |
---|
801 | aws->create_button( "COMPLEMENT_REST_EDITOR", "REST EDITOR", "3" ); |
---|
802 | |
---|
803 | aws->at("all"); |
---|
804 | aws->callback ( (AW_CB)edit_tool_complement_cb, (AW_CL)aedwindow, |
---|
805 | (AW_CL)BUTTON_COMPL_ALL ); |
---|
806 | aws->create_button( "COMPLEMENT_ALL", "ALL", "4" ); |
---|
807 | |
---|
808 | return aws; |
---|
809 | } |
---|
810 | //*************************************************************************** |
---|
811 | |
---|
812 | |
---|
813 | |
---|
814 | |
---|