1 | // ==================================================================== // |
---|
2 | // // |
---|
3 | // File : SQ_main.cxx // |
---|
4 | // Purpose : Entrypoint to Seq. Quality analysis; calls funktions // |
---|
5 | // // |
---|
6 | // // |
---|
7 | // Coded by Juergen Huber in July 2003 - February 2004 // |
---|
8 | // Coded by Kai Bader (baderk@in.tum.de) in 2007 - 2008 // |
---|
9 | // Copyright Department of Microbiology (Technical University Munich) // |
---|
10 | // // |
---|
11 | // Visit our web site at: http://www.arb-home.de/ // |
---|
12 | // // |
---|
13 | // ==================================================================== // |
---|
14 | |
---|
15 | |
---|
16 | #include <stdio.h> |
---|
17 | #include <stdlib.h> |
---|
18 | |
---|
19 | #include <arbdb.h> |
---|
20 | #include <arbdbt.h> |
---|
21 | #include <aw_root.hxx> |
---|
22 | #include <aw_device.hxx> |
---|
23 | #include <aw_window.hxx> |
---|
24 | #include <awt.hxx> |
---|
25 | #include <awt_tree.hxx> |
---|
26 | #include "../AWT/awtfilter.hxx" |
---|
27 | #include <awt_sel_boxes.hxx> |
---|
28 | #include <aw_awars.hxx> |
---|
29 | |
---|
30 | #include "seq_quality.h" |
---|
31 | #include "SQ_functions.h" |
---|
32 | |
---|
33 | extern GBDATA *GLOBAL_gb_main; |
---|
34 | |
---|
35 | // -------------------------------------------------------------------------------- |
---|
36 | |
---|
37 | #define AWAR_SQ_PERM "seq_quality/" // saved in properties |
---|
38 | #define AWAR_SQ_TEMP "tmp/seq_quality/" // not saved in properties |
---|
39 | #define AWAR_SQ_WEIGHT_BASES AWAR_SQ_PERM "weight_bases" |
---|
40 | #define AWAR_SQ_WEIGHT_DEVIATION AWAR_SQ_PERM "weight_deviation" |
---|
41 | #define AWAR_SQ_WEIGHT_HELIX AWAR_SQ_PERM "weight_helix" |
---|
42 | #define AWAR_SQ_WEIGHT_CONSENSUS AWAR_SQ_PERM "weight_consensus" |
---|
43 | #define AWAR_SQ_WEIGHT_IUPAC AWAR_SQ_PERM "weight_iupac" |
---|
44 | #define AWAR_SQ_WEIGHT_GC AWAR_SQ_PERM "weight_gc" |
---|
45 | |
---|
46 | #define AWAR_SQ_MARK_ONLY_FLAG AWAR_SQ_PERM "mark_only_flag" |
---|
47 | #define AWAR_SQ_MARK_FLAG AWAR_SQ_PERM "mark_flag" |
---|
48 | #define AWAR_SQ_MARK_BELOW AWAR_SQ_PERM "mark_below" |
---|
49 | #define AWAR_SQ_REEVALUATE AWAR_SQ_PERM "reevaluate" |
---|
50 | |
---|
51 | #define AWAR_FILTER_PREFIX AWAR_SQ_TEMP "filter/" |
---|
52 | #define AWAR_FILTER_NAME AWAR_FILTER_PREFIX "name" |
---|
53 | #define AWAR_FILTER_FILTER AWAR_FILTER_PREFIX "filter" |
---|
54 | #define AWAR_FILTER_ALI AWAR_FILTER_PREFIX "alignment" |
---|
55 | |
---|
56 | void SQ_create_awars(AW_root * aw_root, AW_default aw_def) { |
---|
57 | aw_root->awar_int(AWAR_SQ_WEIGHT_BASES, 5, aw_def); |
---|
58 | aw_root->awar_int(AWAR_SQ_WEIGHT_DEVIATION, 15, aw_def); |
---|
59 | aw_root->awar_int(AWAR_SQ_WEIGHT_HELIX, 15, aw_def); |
---|
60 | aw_root->awar_int(AWAR_SQ_WEIGHT_CONSENSUS, 50, aw_def); |
---|
61 | aw_root->awar_int(AWAR_SQ_WEIGHT_IUPAC, 5, aw_def); |
---|
62 | aw_root->awar_int(AWAR_SQ_WEIGHT_GC, 10, aw_def); |
---|
63 | aw_root->awar_int(AWAR_SQ_MARK_ONLY_FLAG, 0, aw_def); |
---|
64 | aw_root->awar_int(AWAR_SQ_MARK_FLAG, 1, aw_def); |
---|
65 | aw_root->awar_int(AWAR_SQ_MARK_BELOW, 40, aw_def); |
---|
66 | aw_root->awar_int(AWAR_SQ_REEVALUATE, 0, aw_def); |
---|
67 | aw_root->awar_string(AWAR_FILTER_NAME, "none", aw_def); |
---|
68 | aw_root->awar_string(AWAR_FILTER_FILTER, "", aw_def); |
---|
69 | AW_awar *awar_ali = aw_root->awar_string(AWAR_FILTER_ALI, "", aw_def); |
---|
70 | awar_ali->map("presets/use"); |
---|
71 | } |
---|
72 | |
---|
73 | // -------------------------------------------------------------------------------- |
---|
74 | |
---|
75 | |
---|
76 | static void sq_calc_seq_quality_cb(AW_window * aww, AW_CL res_from_awt_create_select_filter) { |
---|
77 | AW_root *aw_root = aww->get_root(); |
---|
78 | GB_ERROR error = 0; |
---|
79 | GBT_TREE *tree = 0; |
---|
80 | bool marked_only = (aw_root->awar(AWAR_SQ_MARK_ONLY_FLAG)->read_int() > 0); |
---|
81 | |
---|
82 | { |
---|
83 | char *treename = aw_root->awar(AWAR_TREE)->read_string(); // contains "tree_????" if no tree is selected |
---|
84 | |
---|
85 | if (treename && strcmp(treename, "tree_????") != 0) { |
---|
86 | error = GB_push_transaction(GLOBAL_gb_main); |
---|
87 | |
---|
88 | if (!error) { |
---|
89 | tree = GBT_read_tree(GLOBAL_gb_main, treename, sizeof(*tree)); |
---|
90 | if (!tree) error = GB_await_error(); |
---|
91 | else { |
---|
92 | error = GBT_link_tree(tree, GLOBAL_gb_main, GB_FALSE, NULL, NULL); |
---|
93 | if (!error) { |
---|
94 | GBT_TREE_REMOVE_TYPE mode = GBT_REMOVE_DELETED; |
---|
95 | if (marked_only) mode = GBT_TREE_REMOVE_TYPE(mode|GBT_REMOVE_NOT_MARKED); |
---|
96 | |
---|
97 | tree = GBT_remove_leafs(tree, mode, NULL, NULL, NULL); |
---|
98 | if (!tree || tree->is_leaf) { |
---|
99 | error = GBS_global_string("Tree contains less than 2 species after removing zombies%s", |
---|
100 | marked_only ? " and non-marked" : ""); |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | error = GB_end_transaction(GLOBAL_gb_main, error); |
---|
107 | } |
---|
108 | free(treename); |
---|
109 | } |
---|
110 | |
---|
111 | // if tree == 0 -> do basic quality calculations that are possible without tree information |
---|
112 | // otherwise -> use all groups found in tree and compare sequences against the groups they are contained in |
---|
113 | |
---|
114 | if (!error) { |
---|
115 | struct SQ_weights weights; |
---|
116 | |
---|
117 | weights.bases = aw_root->awar(AWAR_SQ_WEIGHT_BASES)->read_int(); |
---|
118 | weights.diff_from_average = aw_root->awar(AWAR_SQ_WEIGHT_DEVIATION)->read_int(); |
---|
119 | weights.helix = aw_root->awar(AWAR_SQ_WEIGHT_HELIX)->read_int(); |
---|
120 | weights.consensus = aw_root->awar(AWAR_SQ_WEIGHT_CONSENSUS)->read_int(); |
---|
121 | weights.iupac = aw_root->awar(AWAR_SQ_WEIGHT_IUPAC)->read_int(); |
---|
122 | weights.gc = aw_root->awar(AWAR_SQ_WEIGHT_GC)->read_int(); |
---|
123 | |
---|
124 | int mark_flag = aw_root->awar(AWAR_SQ_MARK_FLAG)->read_int(); |
---|
125 | int mark_below = aw_root->awar(AWAR_SQ_MARK_BELOW)->read_int(); |
---|
126 | int reevaluate = aw_root->awar(AWAR_SQ_REEVALUATE)->read_int(); |
---|
127 | |
---|
128 | // Load and use Sequence-Filter |
---|
129 | AP_filter *filter = awt_get_filter(aw_root, (adfiltercbstruct*)res_from_awt_create_select_filter); |
---|
130 | |
---|
131 | /* |
---|
132 | SQ_evaluate() generates the final estimation for the quality of an alignment. |
---|
133 | It takes the values from the different containers, which are generated by the other functions, weights them |
---|
134 | and calculates a final value. The final value is stored in "value_of_evaluation" (see options). |
---|
135 | With the values stored in "weights" one can customise how important a value stored in a contaier becomes |
---|
136 | for the final result. |
---|
137 | */ |
---|
138 | |
---|
139 | if (tree == 0) { |
---|
140 | if (reevaluate) { |
---|
141 | aw_openstatus("Marking Sequences..."); |
---|
142 | SQ_mark_species(GLOBAL_gb_main, mark_below, marked_only); |
---|
143 | aw_closestatus(); |
---|
144 | } else { |
---|
145 | SQ_GroupData *globalData = new SQ_GroupData_RNA; |
---|
146 | SQ_count_nr_of_species(GLOBAL_gb_main); |
---|
147 | aw_openstatus("Calculating pass 1 of 2 ..."); |
---|
148 | SQ_pass1_no_tree(globalData, GLOBAL_gb_main, filter); |
---|
149 | aw_closestatus(); |
---|
150 | aw_openstatus("Calculating pass 2 of 2 ..."); |
---|
151 | SQ_pass2_no_tree(globalData, GLOBAL_gb_main, filter); |
---|
152 | SQ_evaluate(GLOBAL_gb_main, weights, marked_only); |
---|
153 | aw_closestatus(); |
---|
154 | if (mark_flag) { |
---|
155 | aw_openstatus("Marking Sequences..."); |
---|
156 | SQ_mark_species(GLOBAL_gb_main, mark_below, marked_only); |
---|
157 | aw_closestatus(); |
---|
158 | } |
---|
159 | delete globalData; |
---|
160 | } |
---|
161 | } else { |
---|
162 | aw_openstatus("Checking tree for irregularities..."); |
---|
163 | SQ_TREE_ERROR check = NONE; |
---|
164 | if ((check = SQ_check_tree_structure(tree)) != NONE) { |
---|
165 | switch (check) { |
---|
166 | case ZOMBIE: |
---|
167 | aw_message("Found one or more zombies in the tree.\nPlease remove them or use another tree before running the quality check tool."); |
---|
168 | break; |
---|
169 | case MISSING_NODE: |
---|
170 | aw_message("Missing node(s) or unusable tree structure.\nPlease fix the tree before running the quality check tool."); |
---|
171 | break; |
---|
172 | default: |
---|
173 | aw_message("An error occurred while traversing the tree.\nPlease fix the tree before running the quality check tool."); |
---|
174 | break; |
---|
175 | } |
---|
176 | aw_closestatus(); |
---|
177 | return; |
---|
178 | } |
---|
179 | aw_closestatus(); |
---|
180 | |
---|
181 | if (reevaluate) { |
---|
182 | aw_openstatus("Marking Sequences..."); |
---|
183 | SQ_count_nr_of_species(GLOBAL_gb_main); |
---|
184 | SQ_mark_species(GLOBAL_gb_main, mark_below, marked_only); |
---|
185 | aw_closestatus(); |
---|
186 | } else { |
---|
187 | aw_openstatus("Calculating pass 1 of 2..."); |
---|
188 | SQ_reset_counters(tree); |
---|
189 | SQ_GroupData *globalData = new SQ_GroupData_RNA; |
---|
190 | SQ_calc_and_apply_group_data(tree, GLOBAL_gb_main, globalData, filter); |
---|
191 | aw_closestatus(); |
---|
192 | SQ_reset_counters(tree); |
---|
193 | aw_openstatus("Calculating pass 2 of 2..."); |
---|
194 | SQ_calc_and_apply_group_data2(tree, GLOBAL_gb_main, globalData, filter); |
---|
195 | SQ_evaluate(GLOBAL_gb_main, weights, marked_only); |
---|
196 | aw_closestatus(); |
---|
197 | SQ_reset_counters(tree); |
---|
198 | if (mark_flag) { |
---|
199 | aw_openstatus("Marking Sequences..."); |
---|
200 | SQ_count_nr_of_species(GLOBAL_gb_main); |
---|
201 | SQ_mark_species(GLOBAL_gb_main, mark_below, marked_only); |
---|
202 | aw_closestatus(); |
---|
203 | } |
---|
204 | delete globalData; |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | if (error) { |
---|
210 | aw_message(error); |
---|
211 | } |
---|
212 | |
---|
213 | SQ_clear_group_dictionary(); |
---|
214 | if (tree) GBT_delete_tree(tree); |
---|
215 | } |
---|
216 | |
---|
217 | static void sq_remove_quality_entries_cb(AW_window * /*aww*/) { |
---|
218 | SQ_remove_quality_entries(GLOBAL_gb_main); |
---|
219 | } |
---|
220 | |
---|
221 | // create window for sequence quality calculation (called only once) |
---|
222 | AW_window *SQ_create_seq_quality_window(AW_root * aw_root, AW_CL) { |
---|
223 | AW_window_simple *aws = new AW_window_simple; |
---|
224 | |
---|
225 | aws->init(aw_root, "CALC_SEQ_QUALITY", "CALCULATE SEQUENCE QUALITY"); |
---|
226 | aws->load_xfig("seq_quality.fig"); |
---|
227 | |
---|
228 | aws->at("close"); |
---|
229 | aws->callback((AW_CB0) AW_POPDOWN); |
---|
230 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
231 | |
---|
232 | aws->at("help"); |
---|
233 | aws->callback(AW_POPUP_HELP, (AW_CL) "seq_quality.hlp"); |
---|
234 | aws->create_button("HELP", "HELP", "H"); |
---|
235 | |
---|
236 | aws->at("base"); |
---|
237 | aws->create_input_field(AWAR_SQ_WEIGHT_BASES, 3); |
---|
238 | |
---|
239 | aws->at("deviation"); |
---|
240 | aws->create_input_field(AWAR_SQ_WEIGHT_DEVIATION, 3); |
---|
241 | |
---|
242 | aws->at("no_helices"); |
---|
243 | aws->create_input_field(AWAR_SQ_WEIGHT_HELIX, 3); |
---|
244 | |
---|
245 | aws->at("consensus"); |
---|
246 | aws->create_input_field(AWAR_SQ_WEIGHT_CONSENSUS, 3); |
---|
247 | |
---|
248 | aws->at("iupac"); |
---|
249 | aws->create_input_field(AWAR_SQ_WEIGHT_IUPAC, 3); |
---|
250 | |
---|
251 | aws->at("gc_proportion"); |
---|
252 | aws->create_input_field(AWAR_SQ_WEIGHT_GC, 3); |
---|
253 | |
---|
254 | aws->at("monly"); |
---|
255 | aws->create_toggle(AWAR_SQ_MARK_ONLY_FLAG); |
---|
256 | |
---|
257 | aws->at("mark"); |
---|
258 | aws->create_toggle(AWAR_SQ_MARK_FLAG); |
---|
259 | |
---|
260 | aws->at("mark_below"); |
---|
261 | aws->create_input_field(AWAR_SQ_MARK_BELOW, 3); |
---|
262 | |
---|
263 | aws->at("tree"); |
---|
264 | awt_create_selection_list_on_trees(GLOBAL_gb_main, (AW_window *) aws, AWAR_TREE); |
---|
265 | |
---|
266 | aws->at("filter"); |
---|
267 | adfiltercbstruct *filtercd = awt_create_select_filter(aws->get_root(), GLOBAL_gb_main, AWAR_FILTER_NAME); |
---|
268 | aws->callback(AW_POPUP, (AW_CL) awt_create_select_filter_win, (AW_CL)filtercd); |
---|
269 | aws->create_button("SELECT_FILTER", AWAR_FILTER_NAME); |
---|
270 | |
---|
271 | aws->at("go"); |
---|
272 | aws->callback(sq_calc_seq_quality_cb, (AW_CL)filtercd); |
---|
273 | aws->highlight(); |
---|
274 | aws->create_button("GO", "GO", "G"); |
---|
275 | |
---|
276 | aws->at("remove"); |
---|
277 | aws->callback(sq_remove_quality_entries_cb); |
---|
278 | aws->create_button("Remove", "Remove", "R"); |
---|
279 | |
---|
280 | aws->at("reevaluate"); |
---|
281 | aws->label("Re-Evaluate only"); |
---|
282 | aws->create_toggle(AWAR_SQ_REEVALUATE); |
---|
283 | |
---|
284 | return aws; |
---|
285 | } |
---|