1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : ad_transpro.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "NT_local.h" |
---|
12 | |
---|
13 | #include <TranslateRealign.h> |
---|
14 | #include <awt_sel_boxes.hxx> |
---|
15 | #include <AP_codon_table.hxx> |
---|
16 | #include <AP_pro_a_nucs.hxx> |
---|
17 | #include <aw_awars.hxx> |
---|
18 | #include <aw_root.hxx> |
---|
19 | #include <aw_msg.hxx> |
---|
20 | #include <arbdbt.h> |
---|
21 | #include <arb_defs.h> |
---|
22 | |
---|
23 | #define AWAR_TRANSPRO_PREFIX "transpro/" |
---|
24 | #define AWAR_TRANSPRO_SOURCE AWAR_TRANSPRO_PREFIX "source" |
---|
25 | #define AWAR_TRANSPRO_DEST AWAR_TRANSPRO_PREFIX "dest" |
---|
26 | |
---|
27 | // translator only: |
---|
28 | #define AWAR_TRANSPRO_POS AWAR_TRANSPRO_PREFIX "pos" // [0..3]: 0-2 = reading frame; 3 = autodetect |
---|
29 | #define AWAR_TRANSPRO_MODE AWAR_TRANSPRO_PREFIX "mode" |
---|
30 | #define AWAR_TRANSPRO_XSTART AWAR_TRANSPRO_PREFIX "xstart" |
---|
31 | #define AWAR_TRANSPRO_WRITE AWAR_TRANSPRO_PREFIX "write" |
---|
32 | |
---|
33 | // realigner only: |
---|
34 | #define AWAR_REALIGN_INCALI AWAR_TRANSPRO_PREFIX "incali" |
---|
35 | #define AWAR_REALIGN_UNMARK AWAR_TRANSPRO_PREFIX "unmark" |
---|
36 | #define AWAR_REALIGN_CUTOFF "tmp/" AWAR_TRANSPRO_PREFIX "cutoff" // dangerous -> do not save |
---|
37 | |
---|
38 | static void transpro_event(AW_window *aww) { |
---|
39 | GB_ERROR error = GB_begin_transaction(GLOBAL.gb_main); |
---|
40 | if (!error) { |
---|
41 | #if defined(DEBUG) && 0 |
---|
42 | test_AWT_get_codons(); |
---|
43 | #endif |
---|
44 | AW_root *aw_root = aww->get_root(); |
---|
45 | char *ali_source = aw_root->awar(AWAR_TRANSPRO_SOURCE)->read_string(); |
---|
46 | char *ali_dest = aw_root->awar(AWAR_TRANSPRO_DEST)->read_string(); |
---|
47 | char *mode = aw_root->awar(AWAR_TRANSPRO_MODE)->read_string(); |
---|
48 | int startpos = aw_root->awar(AWAR_TRANSPRO_POS)->read_int(); |
---|
49 | bool save2fields = aw_root->awar(AWAR_TRANSPRO_WRITE)->read_int(); |
---|
50 | bool translate_all = aw_root->awar(AWAR_TRANSPRO_XSTART)->read_int(); |
---|
51 | |
---|
52 | error = ALI_translate_marked(GLOBAL.gb_main, strcmp(mode, "fields") == 0, save2fields, startpos, translate_all, ali_source, ali_dest); |
---|
53 | if (!error) error = GBT_check_data(GLOBAL.gb_main, NULp); |
---|
54 | |
---|
55 | free(mode); |
---|
56 | free(ali_dest); |
---|
57 | free(ali_source); |
---|
58 | } |
---|
59 | GB_end_transaction_show_error(GLOBAL.gb_main, error, aw_message); |
---|
60 | } |
---|
61 | |
---|
62 | static void nt_trans_cursorpos_changed(AW_root *awr) { |
---|
63 | AW_awar *awar_startpos = awr->awar(AWAR_TRANSPRO_POS); |
---|
64 | |
---|
65 | if (awar_startpos->read_int() != AUTODETECT_STARTPOS) { |
---|
66 | int pos = bio2info(awr->awar(AWAR_CURSOR_POSITION)->read_int()); |
---|
67 | pos = pos % 3; |
---|
68 | awar_startpos->write_int(pos); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | AW_window *NT_create_dna_2_pro_window(AW_root *root) { |
---|
73 | GB_transaction ta(GLOBAL.gb_main); |
---|
74 | |
---|
75 | AW_window_simple *aws = new AW_window_simple; |
---|
76 | aws->init(root, "TRANSLATE_DNA_TO_PRO", "TRANSLATE DNA TO PRO"); |
---|
77 | |
---|
78 | aws->load_xfig("transpro.fig"); |
---|
79 | |
---|
80 | aws->at("close"); |
---|
81 | aws->callback(AW_POPDOWN); |
---|
82 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
83 | |
---|
84 | aws->callback(makeHelpCallback("translate_dna_2_pro.hlp")); |
---|
85 | aws->at("help"); |
---|
86 | aws->create_button("HELP", "HELP", "H"); |
---|
87 | |
---|
88 | aws->at("source"); |
---|
89 | awt_create_ALI_selection_list(GLOBAL.gb_main, (AW_window *)aws, AWAR_TRANSPRO_SOURCE, "dna=:rna="); |
---|
90 | |
---|
91 | aws->at("dest"); |
---|
92 | awt_create_ALI_selection_list(GLOBAL.gb_main, (AW_window *)aws, AWAR_TRANSPRO_DEST, "pro=:ami="); |
---|
93 | |
---|
94 | root->awar_int(AWAR_PROTEIN_TYPE, AWAR_PROTEIN_TYPE_bacterial_code_index, GLOBAL.gb_main); |
---|
95 | aws->at("table"); |
---|
96 | aws->create_option_menu(AWAR_PROTEIN_TYPE, true); |
---|
97 | for (int code_nr=0; code_nr<AWT_CODON_TABLES; code_nr++) { |
---|
98 | aws->insert_option(AWT_get_codon_code_name(code_nr), "", code_nr); |
---|
99 | } |
---|
100 | aws->update_option_menu(); |
---|
101 | |
---|
102 | aws->at("mode"); |
---|
103 | aws->create_toggle_field(AWAR_TRANSPRO_MODE, NULp, ""); |
---|
104 | aws->insert_toggle("from fields 'codon_start' and 'transl_table'", "", "fields"); |
---|
105 | aws->insert_default_toggle("use settings below (same for all species):", "", "settings"); |
---|
106 | aws->update_toggle_field(); |
---|
107 | |
---|
108 | aws->at("pos"); |
---|
109 | aws->create_option_menu(AWAR_TRANSPRO_POS, true); |
---|
110 | for (int p = 1; p <= 3; ++p) { |
---|
111 | char label[2] = { char(p+'0'), 0 }; |
---|
112 | aws->insert_option(label, label, bio2info(p)); |
---|
113 | } |
---|
114 | aws->insert_option("choose best", "choose best", AUTODETECT_STARTPOS); |
---|
115 | |
---|
116 | aws->update_option_menu(); |
---|
117 | aws->get_root()->awar_int(AWAR_CURSOR_POSITION)->add_callback(nt_trans_cursorpos_changed); |
---|
118 | |
---|
119 | aws->at("write"); |
---|
120 | aws->label("Save settings (to 'codon_start'+'transl_table')"); |
---|
121 | aws->create_toggle(AWAR_TRANSPRO_WRITE); |
---|
122 | |
---|
123 | aws->at("start"); |
---|
124 | aws->label("Translate all data"); |
---|
125 | aws->create_toggle(AWAR_TRANSPRO_XSTART); |
---|
126 | |
---|
127 | aws->at("translate"); |
---|
128 | aws->callback(transpro_event); |
---|
129 | aws->highlight(); |
---|
130 | aws->create_button("TRANSLATE", "TRANSLATE", "T"); |
---|
131 | |
---|
132 | aws->window_fit(); |
---|
133 | |
---|
134 | return aws; |
---|
135 | } |
---|
136 | |
---|
137 | static void realign_event(AW_window *aww) { |
---|
138 | AW_root *aw_root = aww->get_root(); |
---|
139 | char *ali_source = aw_root->awar(AWAR_TRANSPRO_DEST)->read_string(); |
---|
140 | char *ali_dest = aw_root->awar(AWAR_TRANSPRO_SOURCE)->read_string(); |
---|
141 | bool unmark_succeeded = aw_root->awar(AWAR_REALIGN_UNMARK)->read_int(); |
---|
142 | bool cutoff_dna = aw_root->awar(AWAR_REALIGN_CUTOFF)->read_int(); |
---|
143 | size_t neededLength = 0; |
---|
144 | GBDATA *gb_main = GLOBAL.gb_main; |
---|
145 | GB_ERROR error = ALI_realign_marked(gb_main, ali_source, ali_dest, neededLength, unmark_succeeded, cutoff_dna); |
---|
146 | |
---|
147 | if (!error && neededLength) { |
---|
148 | bool auto_inc_alisize = aw_root->awar(AWAR_REALIGN_INCALI)->read_int(); |
---|
149 | if (auto_inc_alisize) { |
---|
150 | { |
---|
151 | GB_transaction ta(gb_main); |
---|
152 | error = ta.close(GBT_set_alignment_len(gb_main, ali_dest, neededLength)); |
---|
153 | } |
---|
154 | if (!error) { |
---|
155 | aw_message(GBS_global_string("Alignment length of '%s' has been set to %zu\n" |
---|
156 | "running re-aligner again!", |
---|
157 | ali_dest, neededLength)); |
---|
158 | |
---|
159 | error = ALI_realign_marked(gb_main, ali_source, ali_dest, neededLength, unmark_succeeded, cutoff_dna); |
---|
160 | if (neededLength) { |
---|
161 | error = GBS_global_string("internal error: neededLength=%zu (after autoinc)", neededLength); |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | else { |
---|
166 | GB_transaction ta(gb_main); |
---|
167 | long destLen = GBT_get_alignment_len(gb_main, ali_dest); |
---|
168 | nt_assert(destLen>0 && size_t(destLen)<neededLength); |
---|
169 | error = GBS_global_string("Missing %zu columns in alignment '%s' (got=%li, need=%zu)\n" |
---|
170 | "(check toggle to permit auto-increment)", |
---|
171 | size_t(neededLength-destLen), ali_dest, destLen, neededLength); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | if (error) aw_message(error); |
---|
176 | free(ali_dest); |
---|
177 | free(ali_source); |
---|
178 | } |
---|
179 | |
---|
180 | AW_window *NT_create_realign_dna_window(AW_root *root) { |
---|
181 | AW_window_simple *aws = new AW_window_simple; |
---|
182 | aws->init(root, "REALIGN_DNA", "Realign DNA"); |
---|
183 | |
---|
184 | aws->load_xfig("realign_dna.fig"); |
---|
185 | |
---|
186 | aws->at("close"); |
---|
187 | aws->callback(AW_POPDOWN); |
---|
188 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
189 | |
---|
190 | aws->callback(makeHelpCallback("realign_dna.hlp")); |
---|
191 | aws->at("help"); |
---|
192 | aws->create_button("HELP", "HELP", "H"); |
---|
193 | |
---|
194 | aws->at("source"); |
---|
195 | #if defined(DEVEL_RALF) |
---|
196 | awt_create_ALI_selection_button(GLOBAL.gb_main, aws, AWAR_TRANSPRO_SOURCE, "dna=:rna="); // @@@ nonsense here - just testing awt_create_ALI_selection_button somewhere |
---|
197 | #else // !defined(DEVEL_RALF) |
---|
198 | awt_create_ALI_selection_list(GLOBAL.gb_main, aws, AWAR_TRANSPRO_SOURCE, "dna=:rna="); |
---|
199 | #endif |
---|
200 | aws->at("dest"); |
---|
201 | awt_create_ALI_selection_list(GLOBAL.gb_main, aws, AWAR_TRANSPRO_DEST, "pro=:ami="); |
---|
202 | |
---|
203 | aws->at("autolen"); aws->create_toggle(AWAR_REALIGN_INCALI); |
---|
204 | aws->at("unmark"); aws->create_toggle(AWAR_REALIGN_UNMARK); |
---|
205 | aws->at("cutoff"); aws->create_toggle(AWAR_REALIGN_CUTOFF); |
---|
206 | |
---|
207 | aws->at("realign"); |
---|
208 | aws->callback(realign_event); |
---|
209 | aws->create_autosize_button("REALIGN", "Realign marked species", "R"); |
---|
210 | |
---|
211 | return aws; |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | void NT_create_transpro_variables(AW_root *root, AW_default props) { |
---|
216 | root->awar_string(AWAR_TRANSPRO_SOURCE, "", props); |
---|
217 | root->awar_string(AWAR_TRANSPRO_DEST, "", props); |
---|
218 | root->awar_string(AWAR_TRANSPRO_MODE, "settings", props); |
---|
219 | |
---|
220 | root->awar_int(AWAR_TRANSPRO_POS, 0, props); |
---|
221 | root->awar_int(AWAR_TRANSPRO_XSTART, 1, props); |
---|
222 | root->awar_int(AWAR_TRANSPRO_WRITE, 0, props); |
---|
223 | root->awar_int(AWAR_REALIGN_INCALI, 0, props); |
---|
224 | root->awar_int(AWAR_REALIGN_UNMARK, 0, props); |
---|
225 | root->awar_int(AWAR_REALIGN_CUTOFF, 0, props); |
---|
226 | } |
---|
227 | |
---|