1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : primer_design.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Wolfram Foerster in February 2001 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include "primer_design.hxx" |
---|
13 | #include "PRD_Design.hxx" |
---|
14 | #include "PRD_SequenceIterator.hxx" |
---|
15 | |
---|
16 | #include <GEN.hxx> |
---|
17 | |
---|
18 | #include <awt_sel_boxes.hxx> |
---|
19 | #include <awt_config_manager.hxx> |
---|
20 | |
---|
21 | #include <aw_awars.hxx> |
---|
22 | #include <aw_msg.hxx> |
---|
23 | #include <arb_progress.h> |
---|
24 | #include <aw_root.hxx> |
---|
25 | #include <aw_question.hxx> |
---|
26 | #include <aw_select.hxx> |
---|
27 | |
---|
28 | #include <arbdbt.h> |
---|
29 | #include <adGene.h> |
---|
30 | |
---|
31 | #include <string> |
---|
32 | #include <cmath> |
---|
33 | |
---|
34 | using std::string; |
---|
35 | |
---|
36 | static AW_window_simple *pdrw = NULp; |
---|
37 | static AW_selection_list *resultList = NULp; |
---|
38 | |
---|
39 | static double get_estimated_memory(AW_root *root) { |
---|
40 | int bases = root->awar(AWAR_PRIMER_DESIGN_LEFT_LENGTH)->read_int() + root->awar(AWAR_PRIMER_DESIGN_RIGHT_LENGTH)->read_int(); |
---|
41 | int length = root->awar(AWAR_PRIMER_DESIGN_LENGTH_MAX)->read_int(); |
---|
42 | double mem = bases*length*0.9*(sizeof(Node)+16); |
---|
43 | return mem; |
---|
44 | } |
---|
45 | |
---|
46 | static void primer_design_event_update_memory(AW_root *root) { |
---|
47 | double mem = get_estimated_memory(root); |
---|
48 | const char *display = NULp; |
---|
49 | |
---|
50 | if (mem > 1073741824) { |
---|
51 | mem = mem / 1073741824; |
---|
52 | display = GBS_global_string("%.1f TB", mem); |
---|
53 | } |
---|
54 | else if (mem > 1048576) { |
---|
55 | mem = mem / 1048576; |
---|
56 | display = GBS_global_string("%.1f MB", mem); |
---|
57 | } |
---|
58 | else if (mem > 1024) { |
---|
59 | mem = mem / 1024; |
---|
60 | display = GBS_global_string("%.1f KB", mem); |
---|
61 | } |
---|
62 | else { |
---|
63 | display = GBS_global_string("%.0f bytes", mem); |
---|
64 | } |
---|
65 | root->awar(AWAR_PRIMER_DESIGN_APROX_MEM)->write_string(display); |
---|
66 | } |
---|
67 | |
---|
68 | static void primer_design_event_check_primer_length(AW_root *root, bool max_changed) { |
---|
69 | static bool avoid_recursion = false; |
---|
70 | |
---|
71 | if (!avoid_recursion) { |
---|
72 | avoid_recursion = true; |
---|
73 | |
---|
74 | int min_length = root->awar(AWAR_PRIMER_DESIGN_LENGTH_MIN)->read_int(); |
---|
75 | int max_length = root->awar(AWAR_PRIMER_DESIGN_LENGTH_MAX)->read_int(); |
---|
76 | |
---|
77 | if (max_length<1) max_length = 1; |
---|
78 | if (min_length<1) min_length = 1; |
---|
79 | |
---|
80 | if (min_length > max_length) { |
---|
81 | if (max_changed) min_length = max_length; |
---|
82 | else max_length = min_length; |
---|
83 | } |
---|
84 | |
---|
85 | prd_assert(min_length>0); |
---|
86 | |
---|
87 | root->awar(AWAR_PRIMER_DESIGN_LENGTH_MIN)->write_int(min_length); |
---|
88 | root->awar(AWAR_PRIMER_DESIGN_LENGTH_MAX)->write_int(max_length); |
---|
89 | |
---|
90 | avoid_recursion = false; |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | void create_primer_design_variables(AW_root *aw_root, AW_default aw_def, AW_default global) { |
---|
95 | aw_root->awar_int(AWAR_PRIMER_DESIGN_LEFT_POS, 0, aw_def); |
---|
96 | aw_root->awar_int(AWAR_PRIMER_DESIGN_LEFT_LENGTH, 100, aw_def)->add_callback(primer_design_event_update_memory); |
---|
97 | aw_root->awar_int(AWAR_PRIMER_DESIGN_RIGHT_POS, 1000, aw_def); |
---|
98 | aw_root->awar_int(AWAR_PRIMER_DESIGN_RIGHT_LENGTH, 100, aw_def)->add_callback(primer_design_event_update_memory); |
---|
99 | aw_root->awar_int(AWAR_PRIMER_DESIGN_LENGTH_MIN, 10, aw_def)->add_callback(makeRootCallback(primer_design_event_check_primer_length, false)); |
---|
100 | aw_root->awar_int(AWAR_PRIMER_DESIGN_LENGTH_MAX, 20, aw_def)->add_callback(makeRootCallback(primer_design_event_check_primer_length, true)); |
---|
101 | aw_root->awar_int(AWAR_PRIMER_DESIGN_DIST_MIN, 1050, aw_def); |
---|
102 | aw_root->awar_int(AWAR_PRIMER_DESIGN_DIST_MAX, 1200, aw_def); |
---|
103 | aw_root->awar_int(AWAR_PRIMER_DESIGN_GCRATIO_MIN, 10, aw_def); |
---|
104 | aw_root->awar_int(AWAR_PRIMER_DESIGN_GCRATIO_MAX, 50, aw_def); |
---|
105 | aw_root->awar_int(AWAR_PRIMER_DESIGN_TEMPERATURE_MIN, 30, aw_def); |
---|
106 | aw_root->awar_int(AWAR_PRIMER_DESIGN_TEMPERATURE_MAX, 80, aw_def); |
---|
107 | aw_root->awar_int(AWAR_PRIMER_DESIGN_ALLOWED_MATCH_MIN_DIST, 0, aw_def); |
---|
108 | aw_root->awar_int(AWAR_PRIMER_DESIGN_EXPAND_IUPAC, 1, aw_def); |
---|
109 | aw_root->awar_int(AWAR_PRIMER_DESIGN_MAX_PAIRS, 25, aw_def); |
---|
110 | aw_root->awar_int(AWAR_PRIMER_DESIGN_GC_FACTOR, 50, aw_def); |
---|
111 | aw_root->awar_int(AWAR_PRIMER_DESIGN_TEMP_FACTOR, 50, aw_def); |
---|
112 | |
---|
113 | aw_root->awar_string(AWAR_PRIMER_DESIGN_APROX_MEM, "", aw_def); |
---|
114 | aw_root->awar_string(AWAR_PRIMER_TARGET_STRING, NULp, global); |
---|
115 | |
---|
116 | primer_design_event_update_memory(aw_root); |
---|
117 | } |
---|
118 | |
---|
119 | static void create_primer_design_result_window(AW_window *aww) { |
---|
120 | if (!pdrw) { |
---|
121 | pdrw = new AW_window_simple; |
---|
122 | pdrw->init(aww->get_root(), "PRD_RESULT", "Primer Design RESULT"); |
---|
123 | pdrw->load_xfig("pd_reslt.fig"); |
---|
124 | |
---|
125 | pdrw->button_length(6); |
---|
126 | pdrw->auto_space(10, 10); |
---|
127 | |
---|
128 | pdrw->at("help"); |
---|
129 | pdrw->callback(makeHelpCallback("primer_result.hlp")); |
---|
130 | pdrw->create_button("HELP", "HELP", "H"); |
---|
131 | |
---|
132 | pdrw->at("result"); |
---|
133 | resultList = pdrw->create_selection_list(AWAR_PRIMER_TARGET_STRING, 40, 5, true); |
---|
134 | |
---|
135 | const StorableSelectionList *storable_primer_list = new StorableSelectionList(TypedSelectionList("prim", resultList, "primers", "primer")); // never freed |
---|
136 | |
---|
137 | pdrw->at("buttons"); |
---|
138 | |
---|
139 | pdrw->callback(AW_POPDOWN); |
---|
140 | pdrw->create_button("CLOSE", "CLOSE", "C"); |
---|
141 | |
---|
142 | pdrw->callback(makeWindowCallback(awt_clear_selection_list_cb, resultList)); |
---|
143 | pdrw->create_button("CLEAR", "CLEAR", "R"); |
---|
144 | |
---|
145 | pdrw->callback(makeCreateWindowCallback(create_load_box_for_selection_lists, storable_primer_list)); |
---|
146 | pdrw->create_button("LOAD", "LOAD", "L"); |
---|
147 | |
---|
148 | pdrw->callback(makeCreateWindowCallback(create_save_box_for_selection_lists, storable_primer_list)); |
---|
149 | pdrw->create_button("SAVE", "SAVE", "S"); |
---|
150 | |
---|
151 | pdrw->callback(makeWindowCallback(create_print_box_for_selection_lists, &storable_primer_list->get_typedsellist())); |
---|
152 | pdrw->create_button("PRINT", "PRINT", "P"); |
---|
153 | } |
---|
154 | |
---|
155 | pdrw->show(); |
---|
156 | } |
---|
157 | |
---|
158 | static void primer_design_event_go(AW_window *aww, GBDATA *gb_main) { |
---|
159 | AW_root *root = aww->get_root(); |
---|
160 | GB_ERROR error = NULp; |
---|
161 | char *sequence = NULp; |
---|
162 | long int length = 0; |
---|
163 | |
---|
164 | if ((get_estimated_memory(root)/1024.0) > GB_get_usable_memory()) { |
---|
165 | if (aw_question(NULp, "ARB may crash due to memory problems.", "Continue, Abort") == 1) { |
---|
166 | return; |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | { |
---|
171 | GB_transaction ta(gb_main); |
---|
172 | char *selected_species = root->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
173 | GBDATA *gb_species = GBT_find_species(gb_main, selected_species); |
---|
174 | |
---|
175 | if (!gb_species) { |
---|
176 | error = "you have to select a species!"; |
---|
177 | } |
---|
178 | else { |
---|
179 | const char *alignment = GBT_get_default_alignment(gb_main); |
---|
180 | GBDATA *gb_seq = GBT_find_sequence(gb_species, alignment); |
---|
181 | |
---|
182 | if (!gb_seq) { |
---|
183 | error = GBS_global_string("Selected species has no sequence data in alignment '%s'", alignment); |
---|
184 | } |
---|
185 | else { |
---|
186 | sequence = GB_read_string(gb_seq); |
---|
187 | length = GB_read_count(gb_seq); |
---|
188 | } |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | if (!error) { |
---|
193 | arb_progress progress("Searching PCR primer pairs"); |
---|
194 | PrimerDesign *PD = |
---|
195 | new PrimerDesign(sequence, length, |
---|
196 | Range(root->awar(AWAR_PRIMER_DESIGN_LEFT_POS)->read_int(), root->awar(AWAR_PRIMER_DESIGN_LEFT_LENGTH)->read_int()), |
---|
197 | Range(root->awar(AWAR_PRIMER_DESIGN_RIGHT_POS)->read_int(), root->awar(AWAR_PRIMER_DESIGN_RIGHT_LENGTH)->read_int()), |
---|
198 | Range(root->awar(AWAR_PRIMER_DESIGN_LENGTH_MIN)->read_int(), root->awar(AWAR_PRIMER_DESIGN_LENGTH_MAX)->read_int()), |
---|
199 | Range(root->awar(AWAR_PRIMER_DESIGN_DIST_MIN)->read_int(), root->awar(AWAR_PRIMER_DESIGN_DIST_MAX)->read_int()), |
---|
200 | Range(root->awar(AWAR_PRIMER_DESIGN_GCRATIO_MIN)->read_int(), root->awar(AWAR_PRIMER_DESIGN_GCRATIO_MAX)->read_int()), |
---|
201 | Range(root->awar(AWAR_PRIMER_DESIGN_TEMPERATURE_MIN)->read_int(), root->awar(AWAR_PRIMER_DESIGN_TEMPERATURE_MAX)->read_int()), |
---|
202 | root->awar(AWAR_PRIMER_DESIGN_ALLOWED_MATCH_MIN_DIST)->read_int(), |
---|
203 | (bool)root->awar(AWAR_PRIMER_DESIGN_EXPAND_IUPAC)->read_int(), |
---|
204 | root->awar(AWAR_PRIMER_DESIGN_MAX_PAIRS)->read_int(), |
---|
205 | (float)root->awar(AWAR_PRIMER_DESIGN_GC_FACTOR)->read_int()/100, |
---|
206 | (float)root->awar(AWAR_PRIMER_DESIGN_TEMP_FACTOR)->read_int()/100 |
---|
207 | ); |
---|
208 | |
---|
209 | try { |
---|
210 | PD->run(); |
---|
211 | } |
---|
212 | |
---|
213 | catch (string& s) { |
---|
214 | error = GBS_static_string(s.c_str()); |
---|
215 | } |
---|
216 | catch (...) { |
---|
217 | error = "Unknown error (maybe out of memory ? )"; |
---|
218 | } |
---|
219 | if (!error) error = PD->get_error(); |
---|
220 | |
---|
221 | if (!error) { |
---|
222 | if (!resultList) create_primer_design_result_window(aww); |
---|
223 | prd_assert(resultList); |
---|
224 | |
---|
225 | // create result-list: |
---|
226 | resultList->clear(); |
---|
227 | int max_primer_length = PD->get_max_primer_length(); |
---|
228 | int max_position_length = int(std::log10(double (PD->get_max_primer_pos())))+1; |
---|
229 | int max_length_length = int(std::log10(double(PD->get_max_primer_length())))+1; |
---|
230 | |
---|
231 | if (max_position_length < 3) max_position_length = 3; |
---|
232 | if (max_length_length < 3) max_length_length = 3; |
---|
233 | |
---|
234 | resultList->insert(GBS_global_string(" Rating | %-*s %-*s %-*s G/C Tmp | %-*s %-*s %-*s G/C Tmp", |
---|
235 | max_primer_length, "Left primer", |
---|
236 | max_position_length, "Pos", |
---|
237 | max_length_length, "Len", |
---|
238 | max_primer_length, "Right primer", |
---|
239 | max_position_length, "Pos", |
---|
240 | max_length_length, "Len"), |
---|
241 | ""); |
---|
242 | |
---|
243 | int r; |
---|
244 | |
---|
245 | for (r = 0; ; ++r) { |
---|
246 | const char *primers = NULp; |
---|
247 | const char *result = PD->get_result(r, primers, max_primer_length, max_position_length, max_length_length); |
---|
248 | if (!result) break; |
---|
249 | resultList->insert(result, primers); |
---|
250 | } |
---|
251 | |
---|
252 | resultList->insert_default(r ? "**** End of list" : "**** There are no results", ""); |
---|
253 | resultList->update(); |
---|
254 | |
---|
255 | pdrw->show(); |
---|
256 | } |
---|
257 | } |
---|
258 | if (sequence) free(sequence); |
---|
259 | if (error) aw_message(error); |
---|
260 | } |
---|
261 | |
---|
262 | |
---|
263 | static void primer_design_event_check_temp_factor(AW_window *aww) { |
---|
264 | AW_root *root = aww->get_root(); |
---|
265 | |
---|
266 | int temp = root->awar(AWAR_PRIMER_DESIGN_TEMP_FACTOR)->read_int(); |
---|
267 | if (temp > 100) temp = 100; |
---|
268 | if (temp < 0) temp = 0; |
---|
269 | root->awar(AWAR_PRIMER_DESIGN_TEMP_FACTOR)->write_int(temp); |
---|
270 | root->awar(AWAR_PRIMER_DESIGN_GC_FACTOR)->write_int(100-temp); |
---|
271 | } |
---|
272 | |
---|
273 | static void primer_design_event_check_gc_factor(AW_window *aww) { |
---|
274 | AW_root *root = aww->get_root(); |
---|
275 | |
---|
276 | int gc = root->awar(AWAR_PRIMER_DESIGN_GC_FACTOR)->read_int(); |
---|
277 | if (gc > 100) gc = 100; |
---|
278 | if (gc < 0) gc = 0; |
---|
279 | root->awar(AWAR_PRIMER_DESIGN_GC_FACTOR)->write_int(gc); |
---|
280 | root->awar(AWAR_PRIMER_DESIGN_TEMP_FACTOR)->write_int(100-gc); |
---|
281 | } |
---|
282 | |
---|
283 | static void primer_design_event_init(AW_window *aww, GBDATA *gb_main, bool from_gene) { |
---|
284 | GB_transaction ta(gb_main); |
---|
285 | |
---|
286 | AW_root *root = aww->get_root(); |
---|
287 | GB_ERROR error = NULp; |
---|
288 | char *selected_species = NULp; |
---|
289 | char *selected_gene = NULp; |
---|
290 | GBDATA *gb_species = NULp; |
---|
291 | GBDATA *gb_gene = NULp; |
---|
292 | GEN_position *genPos = NULp; |
---|
293 | GBDATA *gb_seq = NULp; |
---|
294 | bool is_genom_db = GEN_is_genome_db(gb_main, -1); |
---|
295 | |
---|
296 | if (is_genom_db && from_gene) { |
---|
297 | selected_species = root->awar(AWAR_ORGANISM_NAME)->read_string(); |
---|
298 | selected_gene = root->awar(AWAR_GENE_NAME)->read_string(); |
---|
299 | |
---|
300 | root->awar(AWAR_SPECIES_NAME)->write_string(selected_species); |
---|
301 | } |
---|
302 | else { |
---|
303 | selected_species = root->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
304 | } |
---|
305 | |
---|
306 | gb_species = GBT_find_species(gb_main, selected_species); |
---|
307 | |
---|
308 | if (!gb_species) { |
---|
309 | error = "You have to select a species!"; |
---|
310 | } |
---|
311 | else { |
---|
312 | const char *alignment = GBT_get_default_alignment(gb_main); |
---|
313 | gb_seq = GBT_find_sequence(gb_species, alignment); |
---|
314 | if (!gb_seq) { |
---|
315 | error = GB_export_errorf("Species '%s' has no data in alignment '%s'", selected_species, alignment); |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | if (!error && from_gene) { |
---|
320 | prd_assert(is_genom_db); // otherwise button should not exist |
---|
321 | |
---|
322 | gb_gene = GEN_find_gene(gb_species, selected_gene); |
---|
323 | if (!gb_gene) { |
---|
324 | error = GB_export_errorf("Species '%s' has no gene named '%s'", selected_species, selected_gene); |
---|
325 | } |
---|
326 | else { |
---|
327 | genPos = GEN_read_position(gb_gene); |
---|
328 | if (!genPos) { |
---|
329 | error = GB_await_error(); |
---|
330 | } |
---|
331 | else if (!genPos->joinable) { |
---|
332 | error = GBS_global_string("Gene '%s' is not joinable", selected_gene); |
---|
333 | } |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | if (!error && gb_seq) { |
---|
338 | SequenceIterator *i = NULp; |
---|
339 | PRD_Sequence_Pos length = 0; |
---|
340 | PRD_Sequence_Pos add_offset = 0; // offset to add to positions (used for genes) |
---|
341 | char *sequence = NULp; |
---|
342 | |
---|
343 | if (gb_gene) { |
---|
344 | size_t gene_length; |
---|
345 | sequence = GBT_read_gene_sequence_and_length(gb_gene, false, 0, &gene_length); |
---|
346 | if (!sequence) { |
---|
347 | error = GB_await_error(); |
---|
348 | } |
---|
349 | else { |
---|
350 | length = gene_length; |
---|
351 | add_offset = genPos->start_pos[0]; |
---|
352 | // @@@ does this work with split genes? warn about uncertainties? |
---|
353 | } |
---|
354 | } |
---|
355 | else { |
---|
356 | sequence = GB_read_string(gb_seq); |
---|
357 | length = strlen(sequence); |
---|
358 | } |
---|
359 | |
---|
360 | if (!error) { |
---|
361 | long int dist_min; |
---|
362 | long int dist_max; |
---|
363 | |
---|
364 | // find reasonable parameters |
---|
365 | // left pos (first base from start) |
---|
366 | |
---|
367 | long int left_len = root->awar(AWAR_PRIMER_DESIGN_LEFT_LENGTH)->read_int(); |
---|
368 | if (left_len == 0 || left_len<0) left_len = 100; |
---|
369 | |
---|
370 | i = new SequenceIterator(sequence, 0, SequenceIterator::IGNORE, left_len, SequenceIterator::FORWARD); |
---|
371 | |
---|
372 | i->nextBase(); // find first base from start |
---|
373 | PRD_Sequence_Pos left_min = i->pos; // store pos. of first base |
---|
374 | while (i->nextBase() != SequenceIterator::EOS) ; // step to 'left_len'th base from start |
---|
375 | PRD_Sequence_Pos left_max = i->pos; // store pos. of 'left_len'th base |
---|
376 | |
---|
377 | root->awar(AWAR_PRIMER_DESIGN_LEFT_POS)->write_int(left_min+add_offset); |
---|
378 | root->awar(AWAR_PRIMER_DESIGN_LEFT_LENGTH)->write_int(left_len); |
---|
379 | |
---|
380 | long int right_len = root->awar(AWAR_PRIMER_DESIGN_RIGHT_LENGTH)->read_int(); |
---|
381 | if (right_len == 0 || right_len<0) right_len = 100; |
---|
382 | |
---|
383 | // right pos ('right_len'th base from end) |
---|
384 | i->restart(length, 0, right_len, SequenceIterator::BACKWARD); |
---|
385 | |
---|
386 | i->nextBase(); // find last base |
---|
387 | PRD_Sequence_Pos right_max = i->pos; // store pos. of last base |
---|
388 | while (i->nextBase() != SequenceIterator::EOS) ; // step to 'right_len'th base from end |
---|
389 | PRD_Sequence_Pos right_min = i->pos; // store pos of 'right_len'th base from end |
---|
390 | |
---|
391 | root->awar(AWAR_PRIMER_DESIGN_RIGHT_POS)->write_int(right_min+add_offset); |
---|
392 | root->awar(AWAR_PRIMER_DESIGN_RIGHT_LENGTH)->write_int(right_len); |
---|
393 | |
---|
394 | // primer distance |
---|
395 | if (right_min >= left_max) { // non-overlapping ranges |
---|
396 | i->restart(left_max, right_min, SequenceIterator::IGNORE, SequenceIterator::FORWARD); |
---|
397 | long int bases_between = 0; // count bases from right_min to left_max |
---|
398 | while (i->nextBase() != SequenceIterator::EOS) ++bases_between; |
---|
399 | dist_min = bases_between; // take bases between as min distance |
---|
400 | } |
---|
401 | else { // overlapping ranges |
---|
402 | dist_min = right_min - left_min + 1; |
---|
403 | } |
---|
404 | dist_max = right_max - left_min; |
---|
405 | root->awar(AWAR_PRIMER_DESIGN_DIST_MIN)->write_int(dist_min); |
---|
406 | root->awar(AWAR_PRIMER_DESIGN_DIST_MAX)->write_int(dist_max); |
---|
407 | |
---|
408 | #if defined(DUMP_PRIMER) |
---|
409 | printf ("primer_design_event_init : left_min %7li\n", left_min); |
---|
410 | printf ("primer_design_event_init : left_max %7li\n", left_max); |
---|
411 | printf ("primer_design_event_init : right_min %7li\n", right_min); |
---|
412 | printf ("primer_design_event_init : right_max %7li\n", right_max); |
---|
413 | printf ("primer_design_event_init : dist_min %7li\n", dist_min); |
---|
414 | printf ("primer_design_event_init : dist_max %7li\n\n", dist_max); |
---|
415 | #endif |
---|
416 | } |
---|
417 | delete i; |
---|
418 | free(sequence); |
---|
419 | } |
---|
420 | |
---|
421 | if (error) { |
---|
422 | aw_message(error); |
---|
423 | } |
---|
424 | |
---|
425 | GEN_free_position(genPos); |
---|
426 | free(selected_gene); |
---|
427 | free(selected_species); |
---|
428 | } |
---|
429 | |
---|
430 | static AWT_config_mapping_def primer_design_config_mapping[] = { |
---|
431 | { AWAR_PRIMER_DESIGN_LEFT_POS, "lpos" }, |
---|
432 | { AWAR_PRIMER_DESIGN_LEFT_LENGTH, "llen" }, |
---|
433 | { AWAR_PRIMER_DESIGN_RIGHT_POS, "rpos" }, |
---|
434 | { AWAR_PRIMER_DESIGN_RIGHT_LENGTH, "rlen" }, |
---|
435 | { AWAR_PRIMER_DESIGN_LENGTH_MIN, "lenmin" }, |
---|
436 | { AWAR_PRIMER_DESIGN_LENGTH_MAX, "lenmax" }, |
---|
437 | { AWAR_PRIMER_DESIGN_DIST_MIN, "distmin" }, |
---|
438 | { AWAR_PRIMER_DESIGN_DIST_MAX, "distmax" }, |
---|
439 | { AWAR_PRIMER_DESIGN_GCRATIO_MIN, "gcmin" }, |
---|
440 | { AWAR_PRIMER_DESIGN_GCRATIO_MAX, "gcmax" }, |
---|
441 | { AWAR_PRIMER_DESIGN_TEMPERATURE_MIN, "tempmin" }, |
---|
442 | { AWAR_PRIMER_DESIGN_TEMPERATURE_MAX, "tempmax" }, |
---|
443 | { AWAR_PRIMER_DESIGN_ALLOWED_MATCH_MIN_DIST, "minmatchdist" }, |
---|
444 | { AWAR_PRIMER_DESIGN_EXPAND_IUPAC, "iupac" }, |
---|
445 | { AWAR_PRIMER_DESIGN_MAX_PAIRS, "maxpairs" }, |
---|
446 | { AWAR_PRIMER_DESIGN_GC_FACTOR, "gcfactor" }, |
---|
447 | { AWAR_PRIMER_DESIGN_TEMP_FACTOR, "temp_factor" }, |
---|
448 | { NULp, NULp } |
---|
449 | }; |
---|
450 | |
---|
451 | AW_window *create_primer_design_window(AW_root *root, GBDATA *gb_main) { |
---|
452 | bool is_genome_db; |
---|
453 | { |
---|
454 | GB_transaction ta(gb_main); |
---|
455 | char *selected_species = root->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
456 | GBDATA *gb_species = GBT_find_species(gb_main, selected_species); |
---|
457 | |
---|
458 | if (!gb_species) { |
---|
459 | aw_message("You have to select a species!"); |
---|
460 | } |
---|
461 | |
---|
462 | is_genome_db = GEN_is_genome_db(gb_main, -1); |
---|
463 | } |
---|
464 | |
---|
465 | AW_window_simple *aws = new AW_window_simple; |
---|
466 | aws->init(root, "PRIMER_DESIGN", "PRIMER DESIGN"); |
---|
467 | |
---|
468 | aws->load_xfig("prd_main.fig"); |
---|
469 | |
---|
470 | aws->at("close"); |
---|
471 | aws->callback(AW_POPDOWN); |
---|
472 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
473 | |
---|
474 | aws->at("help"); |
---|
475 | aws->callback(makeHelpCallback("primer_new.hlp")); |
---|
476 | aws->create_button("HELP", "HELP", "H"); |
---|
477 | |
---|
478 | aws->at("init1"); |
---|
479 | aws->callback(makeWindowCallback(primer_design_event_init, gb_main, false)); |
---|
480 | aws->create_button("INIT_FROM_SPECIES", "Species", "I"); |
---|
481 | |
---|
482 | if (is_genome_db) { |
---|
483 | aws->at("init2"); |
---|
484 | aws->callback(makeWindowCallback(primer_design_event_init, gb_main, true)); |
---|
485 | aws->create_button("INIT_FROM_GENE", "Gene", "I"); |
---|
486 | } |
---|
487 | |
---|
488 | aws->at("design"); |
---|
489 | aws->callback(makeWindowCallback(primer_design_event_go, gb_main)); |
---|
490 | aws->create_button("GO", "GO", "G"); |
---|
491 | aws->highlight(); |
---|
492 | |
---|
493 | aws->at("minleft"); |
---|
494 | aws->create_input_field(AWAR_PRIMER_DESIGN_LEFT_POS, 7); |
---|
495 | |
---|
496 | aws->at("maxleft"); |
---|
497 | aws->create_input_field(AWAR_PRIMER_DESIGN_LEFT_LENGTH, 9); |
---|
498 | |
---|
499 | aws->at("minright"); |
---|
500 | aws->create_input_field(AWAR_PRIMER_DESIGN_RIGHT_POS, 7); |
---|
501 | |
---|
502 | aws->at("maxright"); |
---|
503 | aws->create_input_field(AWAR_PRIMER_DESIGN_RIGHT_LENGTH, 9); |
---|
504 | |
---|
505 | aws->at("minlen"); |
---|
506 | aws->create_input_field(AWAR_PRIMER_DESIGN_LENGTH_MIN, 7); |
---|
507 | |
---|
508 | aws->at("maxlen"); |
---|
509 | aws->create_input_field(AWAR_PRIMER_DESIGN_LENGTH_MAX, 7); |
---|
510 | |
---|
511 | aws->at("mindist"); aws->create_input_field(AWAR_PRIMER_DESIGN_DIST_MIN, 7); |
---|
512 | aws->at("maxdist"); aws->create_input_field(AWAR_PRIMER_DESIGN_DIST_MAX, 7); |
---|
513 | aws->at("mingc"); aws->create_input_field(AWAR_PRIMER_DESIGN_GCRATIO_MIN, 7); |
---|
514 | aws->at("maxgc"); aws->create_input_field(AWAR_PRIMER_DESIGN_GCRATIO_MAX, 7); |
---|
515 | aws->at("mintemp"); aws->create_input_field(AWAR_PRIMER_DESIGN_TEMPERATURE_MIN, 7); |
---|
516 | aws->at("maxtemp"); aws->create_input_field(AWAR_PRIMER_DESIGN_TEMPERATURE_MAX, 7); |
---|
517 | aws->at("allowed_match"); aws->create_input_field(AWAR_PRIMER_DESIGN_ALLOWED_MATCH_MIN_DIST, 7); |
---|
518 | aws->at("max_pairs"); aws->create_input_field(AWAR_PRIMER_DESIGN_MAX_PAIRS, 7); |
---|
519 | |
---|
520 | aws->at("expand_IUPAC"); |
---|
521 | aws->create_toggle(AWAR_PRIMER_DESIGN_EXPAND_IUPAC); |
---|
522 | |
---|
523 | aws->at("GC_factor"); |
---|
524 | aws->callback(primer_design_event_check_gc_factor); // @@@ used as INPUTFIELD_CB (see #559) |
---|
525 | aws->create_input_field(AWAR_PRIMER_DESIGN_GC_FACTOR, 7); |
---|
526 | |
---|
527 | aws->at("temp_factor"); |
---|
528 | aws->callback(primer_design_event_check_temp_factor); // @@@ used as INPUTFIELD_CB (see #559) |
---|
529 | aws->create_input_field(AWAR_PRIMER_DESIGN_TEMP_FACTOR, 7); |
---|
530 | |
---|
531 | aws->at("config"); |
---|
532 | AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "pcr_primer_design", primer_design_config_mapping); |
---|
533 | |
---|
534 | aws->at("aprox_mem"); |
---|
535 | aws->button_length(11); |
---|
536 | aws->create_button(NULp, AWAR_PRIMER_DESIGN_APROX_MEM, NULp, "+"); |
---|
537 | |
---|
538 | return aws; |
---|
539 | } |
---|