source: branches/profile/MULTI_PROBE/MP_Window.cxx

Last change on this file was 12759, checked in by westram, 10 years ago
  • remove unused code
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.7 KB
Line 
1// ================================================================ //
2//                                                                  //
3//   File      : MP_Window.cxx                                      //
4//   Purpose   :                                                    //
5//                                                                  //
6//   Institute of Microbiology (Technical University Munich)        //
7//   http://www.arb-home.de/                                        //
8//                                                                  //
9// ================================================================ //
10
11#include "MP_externs.hxx"
12#include "MultiProbe.hxx"
13#include "mp_proto.hxx"
14
15#include <awt_sel_boxes.hxx>
16#include <awt_modules.hxx>
17#include <aw_select.hxx>
18#include <aw_file.hxx>
19#include <aw_msg.hxx>
20#include <aw_root.hxx>
21#include <aw_awar_defs.hxx>
22
23#include <arb_strarray.h>
24#include <arb_defs.h>
25#include <arb_strbuf.h>
26#include <arbdbt.h>
27#include <ad_cb.h>
28#include <RegExpr.hxx>
29
30// **************************************************************************
31
32struct mp_gl_struct mp_pd_gl; // global link
33
34AW_selection_list *selected_list;
35AW_selection_list *probelist;
36AW_selection_list *result_probes_list;
37
38
39AW_window_simple *MP_Window::create_result_window(AW_root *aw_root) {
40    if (!result_window) {
41        result_window = new AW_window_simple;
42        result_window->init(aw_root, "MULTIPROBE_RESULTS", "MultiProbe combination results");
43        result_window->load_xfig("mp_results.fig");
44
45        result_window->auto_space(5, 5);
46       
47        result_window->button_length(7);
48        result_window->at("close");
49        result_window->callback(AW_POPDOWN);
50        result_window->create_button("CLOSE", "CLOSE");
51
52        result_window->at("Help");
53        result_window->callback(makeHelpCallback("multiproberesults.hlp"));
54        result_window->create_button("HELP", "HELP");
55
56        result_window->at("Comment");
57        result_window->callback(MP_Comment, (AW_CL)0);
58        result_window->create_input_field(MP_AWAR_RESULTPROBESCOMMENT);
59
60        result_window->at("box");
61        result_window->callback(MP_result_chosen); // @@@ used as SELLIST_CLICK_CB (see #559)
62        result_probes_list = result_window->create_selection_list(MP_AWAR_RESULTPROBES, true);
63        result_probes_list->set_file_suffix("mpr");
64        result_probes_list->insert_default("", "");
65
66        const StorableSelectionList *storable_probes_list = new StorableSelectionList(TypedSelectionList("mpr", result_probes_list, "multiprobes", "multi_probes"));
67
68        result_window->at("buttons");
69        result_window->callback(makeCreateWindowCallback(create_load_box_for_selection_lists, storable_probes_list));
70        result_window->create_button("LOAD_RPL", "LOAD");
71
72        result_window->callback(makeCreateWindowCallback(create_save_box_for_selection_lists, storable_probes_list));
73        result_window->create_button("SAVE_RPL", "SAVE");
74
75        result_window->callback(makeWindowCallback(awt_clear_selection_list_cb, result_probes_list));
76        result_window->create_button("CLEAR", "CLEAR");
77
78        result_window->callback(makeWindowCallback(MP_delete_selected, result_probes_list));
79        result_window->create_button("DELETE", "DELETE");
80
81        // change comment :
82
83        result_window->button_length(8);
84
85        result_window->at("comment");
86        result_window->callback(MP_Comment, (AW_CL) "Bad");
87        result_window->create_button("MARK_AS_BAD", "BAD");
88
89        result_window->callback(MP_Comment, (AW_CL) "???");
90        result_window->create_button("MARK_AS_GOOD", "???");
91
92        result_window->callback(MP_Comment, (AW_CL) "Good");
93        result_window->create_button("MARK_AS_BEST", "Good");
94
95        result_window->at("auto");
96        result_window->create_toggle(MP_AWAR_AUTOADVANCE);
97
98        // tree actions :
99
100        result_window->button_length(3);
101
102        result_window->at("ct_back");
103        result_window->callback(MP_show_probes_in_tree_move, (AW_CL)1, (AW_CL)result_probes_list);
104        result_window->create_button("COLOR_TREE_BACKWARD", "#rightleft_small.xpm");
105
106        result_window->at("ct_fwd");
107        result_window->callback(MP_show_probes_in_tree_move, (AW_CL)0, (AW_CL)result_probes_list);
108        result_window->create_button("COLOR_TREE_FORWARD", "#leftright_small.xpm");
109
110        result_window->button_length(8);
111
112        result_window->at("ColorTree");
113        result_window->button_length(4);
114        result_window->callback(MP_show_probes_in_tree);
115        result_window->create_button("COLOR_TREE", "GO");
116
117        result_window->at("MarkTree");
118        result_window->callback(MP_mark_probes_in_tree);
119        result_window->create_button("MARK_TREE", "GO");
120
121        result_window->at("GroupAll");
122        result_window->callback(MP_group_all_except_marked);
123        result_window->create_button("GROUP_UNMARKED", "GO");
124
125        result_window->at("StandardColor");
126        result_window->callback(MP_normal_colors_in_tree);
127        result_window->create_button("RESET_COLORS", "GO");
128    }
129    return result_window;
130}
131
132// --------------------------------------------------------------------------------
133// Format of probe-list for multi-probes:
134//
135// The saved format is identical to the internal format (of sellist entries; where value always equals displayed!)
136//     "quality#singlemismatch#ecolipos#target"
137//
138// When loading input probes, several other formats are accepted:
139//
140//     "quality,singlemismatch#ecolipos#probe"                      (old save format)
141//     "target le pos apos ecol grps GC 4gc2at probe | ..."         (save of probe design; old format)
142//     "target le pos apos ecol grps GC 4gc2at probe | ...,target"  (save of probe design)
143//
144// above
145//   'target' is the target-string of the 'probe'. Internally MP works with target strings,
146//   so when loading the old save-format, 'probe' gets reverse-complemented into 'target'
147
148
149#define SPACED(expr) "[[:space:]]*" expr "[[:space:]]*"
150
151inline char *gen_display(int quality, int singleMis, int ecoliPos, const char *probe) {
152    return GBS_global_string_copy("%i#%i#%5i#%s", quality, singleMis, ecoliPos, probe);
153}
154
155static GB_ERROR mp_list2file(const CharPtrArray& display, const CharPtrArray& value, StrArray& line) {
156    GB_ERROR error = NULL;
157
158    if (value.empty()) error = "nothing to save";
159
160    for (size_t i = 0; i<display.size() && !error; ++i) {
161        line.put(strdup(display[i]));
162    }
163
164    return error;
165}
166
167static char T_or_U_for_load = 0;
168
169static GB_ERROR mp_file2list(const CharPtrArray& line, StrArray& display, StrArray& value) {
170    GB_ERROR error = NULL;
171
172    if (line.empty()) error = "empty file";
173
174    // detect format
175    if (!error) {
176        // 1. try to read probes saved from multiprobes inputlist
177        RegExpr reg_saved("^" SPACED("([0-9]+)") "([,#])" SPACED("([0-9])+") "#" SPACED("([0-9]+)") "#" SPACED("([A-Z]+)") "$", true);
178        bool    isSavedFormat = true;
179
180        for (size_t i = 0; i<line.size() && isSavedFormat; ++i) {
181            const RegMatch *match = reg_saved.match(line[i]);
182            if (!match || reg_saved.subexpr_count() != 5) {
183                isSavedFormat = false;
184            }
185            else {
186                char T_or_U = T_or_U_for_load ? T_or_U_for_load : 'U';
187
188                std::string sep = reg_saved.subexpr_match(2)->extract(line[i]);
189
190                int quality   = atoi(reg_saved.subexpr_match(1)->extract(line[i]).c_str());
191                int singlemis = atoi(reg_saved.subexpr_match(3)->extract(line[i]).c_str());
192                int ecoli     = atoi(reg_saved.subexpr_match(4)->extract(line[i]).c_str());
193
194                std::string probe = reg_saved.subexpr_match(5)->extract(line[i]);
195
196                if (sep[0] == ',') { // old format (saved probe instead of probe-target)
197                    size_t  plen   = probe.length();
198                    char   *dprobe = GB_strndup(probe.c_str(), plen);
199
200                    GBT_reverseComplementNucSequence(dprobe, plen, T_or_U);
201                    probe = dprobe;
202                    free(dprobe);
203                }
204
205                char *entry = gen_display(quality, singlemis, ecoli, probe.c_str());
206                display.put(entry); // transfers ownership - dont free!
207                value.put(strdup(entry));
208            }
209        }
210
211        if (!isSavedFormat) {
212            // delete attempt to read saved format:
213            display.clear();
214            value.clear();
215
216            // try to read designed list
217            RegExpr reg_designed("^([A-Z]+)"            // subexpr #1 (target)
218                                 "[[:space:]]+[0-9]+"
219                                 "[[:space:]]+[A-Z][=+-]"
220                                 "[[:space:]]*[0-9]+"
221                                 "[[:space:]]+([0-9]+)" // subexpr #2 (ecoli pos)
222                                 "([[:space:]]+[0-9]+){1,2}" // accept with and without quality entry
223                                 "([[:space:]]+[0-9.]+){2}"
224                                 "[[:space:]]+[A-Z]+"
225                                 "[[:space:]]+[|]", true);
226
227            for (size_t i = 0; i<line.size() && !error; ++i) {
228                char *probe       = NULL;
229                char *description = NULL;
230                bool  new_format  = false;
231
232                const char *comma = strchr(line[i], ',');
233                if (comma) {
234                    description = GB_strpartdup(line[i], comma-1);
235
236                    const char *cprobe = comma+1;
237                    while (cprobe[0] == ' ') ++cprobe;
238                    probe = strdup(cprobe);
239                   
240                    new_format = true;
241                }
242                else {
243                    description = strdup(line[i]);
244                }
245
246                const RegMatch *match = reg_designed.match(description);
247                if (match) { // line from probe design (old + new format)
248                    mp_assert(match->didMatch());
249
250                    match = reg_designed.subexpr_match(1);
251                    mp_assert(match->didMatch());
252                    std::string parsed_probe = match->extract(description);
253
254                    if (new_format) { // already got probe value -> compare
255                        if (strcmp(probe, parsed_probe.c_str()) != 0) {
256                            error = GBS_global_string("probe string mismatch (probe='%s', parsed_probe='%s', parsed from='%s')",
257                                                      probe, parsed_probe.c_str(), line[i]);
258                        }
259                    }
260                    else {
261                        probe = strdup(parsed_probe.c_str());
262                    }
263
264                    if (!error) {
265                        int quality, ecoli;
266                       
267                        match   = reg_designed.subexpr_match(2);
268                        mp_assert(match->didMatch());
269                        ecoli   = atoi(match->extract(description).c_str());
270                        quality = 3;
271
272                        char *entry = gen_display(quality, 0, ecoli, probe);
273                        display.put(entry); // transfers ownership - dont free!
274                        value.put(strdup(entry));
275                    }
276                }
277                else if (new_format && probe[0]) {
278                    error = GBS_global_string("can't parse line '%s'", line[i]);
279                }
280                // (when loading old format -> silently ignore non-matching lines)
281
282                free(probe);
283                free(description);
284            }
285        }
286    }
287
288    return error;
289}
290
291static void track_ali_change_cb(AW_root*, GBDATA *gb_main) {
292    GB_transaction     ta(gb_main);
293    char              *aliname = GBT_get_default_alignment(gb_main);
294    GB_alignment_type  alitype = GBT_get_alignment_type(gb_main, aliname);
295
296    GBT_determine_T_or_U(alitype, &T_or_U_for_load, "reverse-complement"); // T_or_U_for_load is set to 0 in error-case
297    GB_clear_error();
298
299    free(aliname);
300}
301
302static void MP_collect_probes(AW_window*, awt_collect_mode mode, AW_CL) {
303    switch (mode) {
304        case ACM_ADD:
305            if (!probelist->default_is_selected()) {
306                int                        idx = probelist->get_index_of_selected();
307                AW_selection_list_iterator sel(probelist, idx);
308                selected_list->insert(sel.get_displayed(), sel.get_value());
309                MP_delete_selected(NULL, probelist);
310            }
311            break;
312
313        case ACM_REMOVE:
314            if (!selected_list->default_is_selected()) {
315                int                        idx = selected_list->get_index_of_selected();
316                AW_selection_list_iterator sel(selected_list, idx);
317                probelist->insert(sel.get_displayed(), sel.get_value());
318                MP_delete_selected(NULL, selected_list);
319            }
320            break;
321           
322        case ACM_FILL:
323            probelist->move_content_to(selected_list);
324            break;
325
326        case ACM_EMPTY:
327            selected_list->move_content_to(probelist);
328            break;
329    }
330
331    selected_list->sort(false, true);
332
333    probelist->update();
334    selected_list->update();
335}
336
337MP_Window::MP_Window(AW_root *aw_root, GBDATA *gb_main) {
338    int max_seq_col = 35;
339    int max_seq_hgt = 15;
340
341#if defined(DEBUG)
342    static bool initialized = false;
343    mp_assert(!initialized); // this function may only be called once!
344    initialized             = true;
345#endif
346
347    aw_root->awar(AWAR_DEFAULT_ALIGNMENT)->add_callback(makeRootCallback(track_ali_change_cb, gb_main));
348    track_ali_change_cb(aw_root, gb_main);
349
350    result_window = NULL;
351
352    aws = new AW_window_simple;
353    aws->init(aw_root, "MULTIPROBE", "MULTI_PROBE");
354    aws->load_xfig("multiprobe.fig");
355
356    aws->at("close");
357    aws->callback(MP_close_main);
358    aws->create_button("CLOSE", "CLOSE");
359
360    aws->at("help");
361    aws->callback(makeHelpCallback("multiprobe.hlp"));
362    aws->create_button("HELP", "HELP");
363
364    aws->button_length(7);
365    aws->at("Selectedprobes");
366    aws->callback(MP_selected_chosen); // @@@ used as SELLIST_CLICK_CB (see #559)
367    selected_list = aws->create_selection_list(MP_AWAR_SELECTEDPROBES, max_seq_col, max_seq_hgt, true);
368    const StorableSelectionList *storable_selected_list = new StorableSelectionList(TypedSelectionList("prb", selected_list, "probes", "selected_probes"), mp_list2file, mp_file2list);
369
370    selected_list->insert_default("", "");
371
372    aws->at("Probelist");
373    probelist = aws->create_selection_list(MP_AWAR_PROBELIST, true);
374    const StorableSelectionList *storable_probelist = new StorableSelectionList(TypedSelectionList("prb", probelist, "probes", "all_probes"), mp_list2file, mp_file2list);
375    probelist->insert_default("", "");
376
377    aws->at("collect");
378    awt_create_collect_buttons(aws, true, MP_collect_probes, 0);
379   
380    aws->auto_space(5, 5);
381    aws->button_length(7);
382
383    for (int rightSide = 0; rightSide <= 1; ++rightSide) {
384        const StorableSelectionList *storableList = rightSide ? storable_selected_list : storable_probelist;
385        const char                  *id_suffix    = rightSide ? "SELECTED_PROBES" : "PROBES";
386
387        AW_selection_list *sellist = storableList->get_typedsellist().get_sellist();
388
389        aws->at(rightSide ? "RightButtons" : "LeftButtons");
390
391        aws->callback(makeCreateWindowCallback(create_load_box_for_selection_lists, storableList));
392        aws->create_button(GBS_global_string("LOAD_%s", id_suffix), "LOAD");
393
394        aws->callback(makeCreateWindowCallback(create_save_box_for_selection_lists, storableList));
395        aws->create_button(GBS_global_string("SAVE_%s", id_suffix), "SAVE");
396
397        aws->callback(makeWindowCallback(awt_clear_selection_list_cb, sellist));
398        aws->create_button(GBS_global_string("CLEAR_%s", id_suffix), "CLEAR");
399
400        aws->callback(makeWindowCallback(MP_delete_selected, sellist));
401        aws->create_button(GBS_global_string("DELETE_%s", id_suffix), "DELETE");
402    }
403
404    aws->at("Quality");
405    aws->callback(MP_cache_sonden);
406    aws->create_option_menu(MP_AWAR_QUALITY, true);
407    aws->insert_option("High Priority", "", 5);
408    aws->insert_option("       4", "", 4);
409    aws->insert_option("Normal 3", "", 3);
410    aws->insert_option("       2", "", 2);
411    aws->insert_option("Low Prio. 1", "", 1);
412    aws->update_option_menu();
413
414    aws->at("add");
415    aws->callback(MP_new_sequence);
416    aws->create_autosize_button("ADD_PROBE", "ADD");
417    aws->at("seqin");
418    aws->create_input_field(MP_AWAR_SEQIN, 25);
419
420    // --------------------------------
421    //      multi probe parameters
422
423    aws->at("PTServer");
424    awt_create_PTSERVER_selection_button(aws, MP_AWAR_PTSERVER);
425    aw_root->awar(MP_AWAR_PTSERVER)->add_callback(MP_cache_sonden2); // remove cached probes when changing pt-server
426
427    aws->at("NoOfProbes");
428    aws->create_option_menu(MP_AWAR_NOOFPROBES, true);
429    aws->callback(MP_cache_sonden);
430    aws->insert_option("Compute  1 probe ", "", 1);
431    char str[50];
432    for (int i=2; i<=MAXPROBECOMBIS; i++) {
433        sprintf(str, "%2d-probe-combinations", i);
434        aws->insert_option(str, "", i);
435    }
436    aws->update_option_menu();
437
438    aws->button_length(10);
439    aws->at("Compute");
440    aws->callback(MP_compute, (AW_CL)gb_main);
441    aws->highlight();
442    aws->help_text("Compute possible Solutions");
443    aws->create_button("GO", "GO");
444
445    aws->button_length(20);
446    aws->at("Results");
447    aws->callback(MP_popup_result_window);
448    aws->create_button("OPEN_RESULT_WIN", "Open result window");
449
450    aws->at("Komplement");
451    aws->callback(MP_cache_sonden);
452    aws->create_toggle(MP_AWAR_COMPLEMENT);
453
454    aws->at("WeightedMismatches");
455    aws->callback(MP_cache_sonden);
456    aws->create_toggle(MP_AWAR_WEIGHTEDMISMATCHES);
457
458    // max non group hits
459    aws->at("Border1");
460    aws->callback(MP_cache_sonden);
461    aws->create_input_field(MP_AWAR_QUALITYBORDER1, 6);
462
463    aws->at("OutsideMismatches");
464    aws->callback(MP_cache_sonden);
465    aws->create_option_menu(MP_AWAR_OUTSIDEMISMATCHES, true);
466    aws->insert_option("3.0", "", (float)3.0);
467    aws->insert_option("2.5", "", (float)2.5);
468    aws->insert_option("2.0", "", (float)2.0);
469    aws->insert_option("1.5", "", (float)1.5);
470    aws->insert_option("1.0", "", (float)1.0);
471    aws->update_option_menu();
472
473    // max mismatches for group
474    aws->at("Greyzone");
475    aws->callback(MP_cache_sonden);
476    aws->create_option_menu(MP_AWAR_GREYZONE, true);
477    aws->insert_default_option("0.0", "", (float)0.0);
478    for (float lauf=0.1; lauf<(float)1.0; lauf+=0.1) {
479        char strs[20];
480        sprintf(strs, "%.1f", lauf);
481        aws->insert_option(strs, "", lauf);
482    }
483    aws->update_option_menu();
484
485}
486
487
488MP_Window::~MP_Window()
489{
490    if (result_window)  result_window->hide();
491    if (aws)            aws->hide();
492
493    delete result_window;
494    delete aws;
495}
496
497// --------------------------------------------------------------------------------
498
499#ifdef UNIT_TESTS
500#ifndef TEST_UNIT_H
501#include <test_unit.h>
502#endif
503#include <command_output.h>
504
505inline void array2cpa(const char **content, int count, ConstStrArray& array) {
506    array.erase();
507    for (int i = 0; i<count; ++i) {
508        array.put(content[i]);
509    }
510}
511
512inline char *array2string(const CharPtrArray& array) {
513    GBS_strstruct out(1000);
514
515    for (size_t i = 0; i<array.size(); ++i) {
516        out.cat(array[i]);
517        out.put('\n');
518    }
519
520    return out.release();
521}
522
523static arb_test::match_expectation inputConvertsInto(const char *input, const char *expected_result) {
524    ConstStrArray lines;
525    GBT_split_string(lines, input, "\n", true);
526
527    using namespace   arb_test;
528    expectation_group expected;
529
530    StrArray display, value;
531    expected.add(doesnt_report_error(mp_file2list(lines, display, value)));
532
533    char *displ_as_string = array2string(display);
534    char *value_as_string = array2string(value);
535
536    expected.add(that(displ_as_string).is_equal_to(expected_result));
537    expected.add(that(value_as_string).is_equal_to(expected_result));
538
539    free(value_as_string);
540    free(displ_as_string);
541
542    return all().ofgroup(expected);
543}
544
545#define TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS(input,expected)         TEST_EXPECTATION(inputConvertsInto(input, expected))
546#define TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS__BROKEN(input,expected) TEST_EXPECTATION__BROKEN(inputConvertsInto(input, expected))
547
548void TEST_load_probe_design_results() {
549    {
550        const char *expected =
551            "3#0#  521#GCAGCCGCGGUAAUACGG\n"
552            "3#0#  510#ACUCCGUGCCAGCAGCCG\n"
553            "3#0#  511#CUCCGUGCCAGCAGCCGC\n"
554            "3#0#  512#UCCGUGCCAGCAGCCGCG\n"
555            "3#0#  513#CCGUGCCAGCAGCCGCGG\n"
556            "3#0#  509#AACUCCGUGCCAGCAGCC\n";
557
558        const char *old_probeDesignSave =
559            "Probe design Parameters:\n"
560            "Length of probe      18\n"
561            "Temperature        [30.0 -100.0]\n"
562            "GC-Content         [50.0 -100.0]\n"
563            "E.Coli Position    [any]\n"
564            "Max Non Group Hits     0\n"
565            "Min Group Hits        50%\n"
566            "Target             le     apos ecol grps  G+C 4GC+2AT Probe sequence     | Decrease T by n*.3C -> probe matches n non group species\n"
567            "GCAGCCGCGGUAAUACGG 18 A=  4398  521   23 66.7 60.0    CCGUAUUACCGCGGCUGC |  0;  0;  0;  0;  0;  0;  0;  0; 35; 35; 35; 38; 74; 74; 74; 77;113;113;113;148;\n"
568            "ACUCCGUGCCAGCAGCCG 18 B=  3852  510   23 72.2 62.0    CGGCUGCUGGCACGGAGU |  0;  0;  0;  0;  0; 40; 40; 40; 80; 80; 80; 80;120;120;120;200;200;200;200;201;\n"
569            "CUCCGUGCCAGCAGCCGC 18 B+     4  511   23 77.8 64.0    GCGGCUGCUGGCACGGAG |  0;  0;  0;  0;  0; 40; 40; 40; 40; 80; 80; 80;160;160;160;160;201;201;201;201;\n"
570            "UCCGUGCCAGCAGCCGCG 18 B+     7  512   23 77.8 64.0    CGCGGCUGCUGGCACGGA |  0;  0;  0;  0;  0; 40; 40; 40;120;120;120;120;160;160;161;201;201;201;202;202;\n"
571            "CCGUGCCAGCAGCCGCGG 18 B+     9  513   23 83.3 66.0    CCGCGGCUGCUGGCACGG |  0;  0;  0;  0;  0; 80; 80; 80; 80;120;120;121;161;161;161;162;203;203;204;204;\n"
572            "AACUCCGUGCCAGCAGCC 18 B-     1  509   22 66.7 60.0    GGCUGCUGGCACGGAGUU |  0;  0;  0;  0;  0; 40; 40; 40; 80; 80; 80;120;120;120;120;160;160;160;240;240;\n";
573
574        TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS(old_probeDesignSave, expected);
575
576
577        const char *old_multiprobeInputSave = // old multi-probe saved probe (i.e. not target) sequences -> load shall correct that
578            "3,0#   521#CCGUAUUACCGCGGCUGC\n"
579            "3,0#   510#CGGCUGCUGGCACGGAGU\n"
580            "3,0#   511#GCGGCUGCUGGCACGGAG\n"
581            "3,0#   512#CGCGGCUGCUGGCACGGA\n"
582            "3,0#   513#CCGCGGCUGCUGGCACGG\n"
583            "3,0#   509#GGCUGCUGGCACGGAGUU\n";
584
585        {
586            LocallyModify<char> TorU(T_or_U_for_load, 'U');
587            TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS(old_multiprobeInputSave, expected);
588        }
589
590        const char *new_probeDesignSave_v1 =
591            "Probe design Parameters:,\n"
592            "Length of probe      18,\n"
593            "Temperature        [30.0 -100.0],\n"
594            "GC-Content         [50.0 -100.0],\n"
595            "E.Coli Position    [any],\n"
596            "Max Non Group Hits     0,\n"
597            "Min Group Hits        50%,\n"
598            "Target             le     apos ecol grps  G+C 4GC+2AT Probe sequence     | Decrease T by n*.3C -> probe matches n non group species,\n"
599            "GCAGCCGCGGUAAUACGG 18 A=  4398  521   23 66.7 60.0    CCGUAUUACCGCGGCUGC |  0;  0;  0;  0;  0;  0;  0;  0; 35; 35; 35; 38; 74; 74; 74; 77;113;113;113;148;,GCAGCCGCGGUAAUACGG\n"
600            "ACUCCGUGCCAGCAGCCG 18 B=  3852  510   23 72.2 62.0    CGGCUGCUGGCACGGAGU |  0;  0;  0;  0;  0; 40; 40; 40; 80; 80; 80; 80;120;120;120;200;200;200;200;201;,ACUCCGUGCCAGCAGCCG\n"
601            "CUCCGUGCCAGCAGCCGC 18 B+     4  511   23 77.8 64.0    GCGGCUGCUGGCACGGAG |  0;  0;  0;  0;  0; 40; 40; 40; 40; 80; 80; 80;160;160;160;160;201;201;201;201;,CUCCGUGCCAGCAGCCGC\n"
602            "UCCGUGCCAGCAGCCGCG 18 B+     7  512   23 77.8 64.0    CGCGGCUGCUGGCACGGA |  0;  0;  0;  0;  0; 40; 40; 40;120;120;120;120;160;160;161;201;201;201;202;202;,UCCGUGCCAGCAGCCGCG\n"
603            "CCGUGCCAGCAGCCGCGG 18 B+     9  513   23 83.3 66.0    CCGCGGCUGCUGGCACGG |  0;  0;  0;  0;  0; 80; 80; 80; 80;120;120;121;161;161;161;162;203;203;204;204;,CCGUGCCAGCAGCCGCGG\n"
604            "AACUCCGUGCCAGCAGCC 18 B-     1  509   22 66.7 60.0    GGCUGCUGGCACGGAGUU |  0;  0;  0;  0;  0; 40; 40; 40; 80; 80; 80;120;120;120;120;160;160;160;240;240;,AACUCCGUGCCAGCAGCC\n";
605
606        TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS(new_probeDesignSave_v1, expected);
607
608
609        const char *new_multiprobeInputSave =
610            "3#0#  521#GCAGCCGCGGUAAUACGG\n"
611            "3#0#  510#ACUCCGUGCCAGCAGCCG\n"
612            "3#0#  511#CUCCGUGCCAGCAGCCGC\n"
613            "3#0#  512#UCCGUGCCAGCAGCCGCG\n"
614            "3#0#  513#CCGUGCCAGCAGCCGCGG\n"
615            "3#0#  509#AACUCCGUGCCAGCAGCC\n";
616
617        TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS(new_multiprobeInputSave, expected);
618    }
619}
620
621static const char *recent_expected =
622    "3#0#   82#CGAAAGGAAGAUUA\n"
623    "3#0#   82#CGAAAGGAAGAUUAA\n"
624    "3#0#   86#AGGAAGAUUAAUACC\n"
625    "3#0#   87#GGAAGAUUAAUACC\n"
626    "3#0#   21#GUCGAGCGAUGAAG\n"
627    "3#0#   20#AGUCGAGCGAUGAAG\n"
628    "3#0#   20#AGUCGAGCGAUGAA\n"
629    "3#0#   19#AAGUCGAGCGAUGAA\n"
630    "3#0#   18#CAAGUCGAGCGAUGA\n"
631    "3#0#   19#AAGUCGAGCGAUGA\n"
632    "3#0#   17#UCAAGUCGAGCGAUG\n"
633    "3#0#   18#CAAGUCGAGCGAUG\n"
634    "3#0#   16#AUCAAGUCGAGCGAU\n"
635    "3#0#   17#UCAAGUCGAGCGAU\n"
636    "3#0#   16#AUCAAGUCGAGCGA\n";
637
638static const char *recent_probeDesignSave =
639    "Probe design parameters:,\n"
640    "Length of probe    14-15,\n"
641    "Temperature        [ 0.0 -400.0],\n"
642    "GC-content         [30.0 - 80.0],\n"
643    "E.Coli position    [any],\n"
644    "Max. nongroup hits 0,\n"
645    "Min. group hits    100% (max. rejected coverage: 75%),\n"
646    "Target          le apos ecol qual grps   G+C temp  Probe sequence | Decrease T by n*.3C -> probe matches n non group species,\n"
647    "CGAAAGGAAGAUUA  14 A=94   82   77    4  35.7 38.0  UAAUCUUCCUUUCG | - - - - - - - - - - - - - - - - - - - -,CGAAAGGAAGAUUA\n"
648    "CGAAAGGAAGAUUAA 15 A+ 0   82   77    4  33.3 40.0 UUAAUCUUCCUUUCG | - - - - - - - - - - - - - - - - - - - -,CGAAAGGAAGAUUAA\n"
649    "AGGAAGAUUAAUACC 15 A+ 4   86   77    4  33.3 40.0 GGUAUUAAUCUUCCU | - - - - - - - - - - - - - - - - - - - -,AGGAAGAUUAAUACC\n"
650    "GGAAGAUUAAUACC  14 A+ 5   87   77    4  35.7 38.0  GGUAUUAAUCUUCC | - - - - - - - - - - - - - - - - - - - -,GGAAGAUUAAUACC\n"
651    "GUCGAGCGAUGAAG  14 B=22   21   77    4  57.1 44.0  CUUCAUCGCUCGAC | - - - - - - - - - - - - - - - - - - - 2,GUCGAGCGAUGAAG\n"
652    "AGUCGAGCGAUGAAG 15 B- 1   20   73    4  53.3 46.0 CUUCAUCGCUCGACU | - - - - - - - - - - - - - - - - - - 2 2,AGUCGAGCGAUGAAG\n"
653    "AGUCGAGCGAUGAA  14 B- 1   20   57    4  50.0 42.0  UUCAUCGCUCGACU | - - - - - - - - - - - - - - 2 2 2 2 2 2,AGUCGAGCGAUGAA\n"
654    "AAGUCGAGCGAUGAA 15 B- 2   19   53    4  46.7 44.0 UUCAUCGCUCGACUU | - - - - - - - - - - - - - 2 2 2 2 2 2 2,AAGUCGAGCGAUGAA\n"
655    "CAAGUCGAGCGAUGA 15 B- 3   18   41    4  53.3 46.0 UCAUCGCUCGACUUG | - - - - - - - - - - 2 2 2 2 2 2 2 2 2 2,CAAGUCGAGCGAUGA\n"
656    "AAGUCGAGCGAUGA  14 B- 2   19   41    4  50.0 42.0  UCAUCGCUCGACUU | - - - - - - - - - - 2 2 2 2 2 2 2 2 2 2,AAGUCGAGCGAUGA\n"
657    "UCAAGUCGAGCGAUG 15 B- 4   17   25    4  53.3 46.0 CAUCGCUCGACUUGA | - - - - - - 2 2 2 2 2 2 2 2 2 2 2 2 9 9,UCAAGUCGAGCGAUG\n"
658    "CAAGUCGAGCGAUG  14 B- 3   18   25    4  57.1 44.0  CAUCGCUCGACUUG | - - - - - - 2 2 2 2 2 2 2 2 2 2 2 2 2 2,CAAGUCGAGCGAUG\n"
659    "AUCAAGUCGAGCGAU 15 B- 5   16    5    4  46.7 44.0 AUCGCUCGACUUGAU | - 2 2 2 2 2 2 2 9 9 9 9 9 9 9 9 9 9 9 9,AUCAAGUCGAGCGAU\n"
660    "UCAAGUCGAGCGAU  14 B- 4   17    5    4  50.0 42.0  AUCGCUCGACUUGA | - 2 2 2 2 2 2 2 2 9 9 9 9 9 9 9 9 9 9 9,UCAAGUCGAGCGAU\n"
661    "AUCAAGUCGAGCGA  14 B- 5   16    5    4  50.0 42.0  UCGCUCGACUUGAU | - 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9,AUCAAGUCGAGCGA";
662
663void TEST_AFTER_SLOW_recent_probe_design_result() {
664    // --------------------------------------------------------------------------------
665    // whenever probe design output changes, copy current 'recent_probeDesignSave' and
666    // 'recent_expected' into TEST_load_probe_design_results, to ensure ARB can load
667    // any saved probe design ever created with ARB.
668
669    TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS(recent_probeDesignSave, recent_expected);
670}
671
672void TEST_SLOW_design_probes_and_load_result() {
673    TEST_SETUP_GLOBAL_ENVIRONMENT("ptserver");
674
675    CommandOutput designed_probes("arb_probe serverid=-666 designprobelength=14 designmaxprobelength=15 designnames=ClnCorin#CltBotul#CPPParap#ClfPerfr designmintargets=100", true);
676    TEST_EXPECT_NO_ERROR(designed_probes.get_error());
677
678    // Simulate result of designing probes in ARB_NT and saving the result to a file:
679    char *saved_design_result = NULL; // content of that file
680    {
681        ConstStrArray lines;
682        GBT_split_string(lines, designed_probes.get_stdoutput(), "\n", true);
683
684        StrArray saved_lines;
685
686        for (size_t i = 0; i<lines.size(); ++i) {
687            char *probe; // same as awar-value of probe-design-resultlist in ARB_NT
688            {
689                size_t plen = strspn(lines[i], "acgtuACGTU");
690                if (plen<10) { // no probe at start // @@@ 10 is min. probelen, use a global definition here!
691                    probe = strdup("");
692                }
693                else {
694                    probe = GB_strndup(lines[i], plen);
695                }
696            }
697
698            char *conv4save = GBS_string_eval(lines[i], ":,=;", NULL); // saving selection list converts comma to semicolon
699            arb_assert(conv4save);
700
701            saved_lines.put(GBS_global_string_copy("%s,%s", conv4save, probe));
702
703            free(conv4save);
704            free(probe);
705        }
706
707        saved_design_result = GBT_join_names(saved_lines, '\n');
708        TEST_EXPECT_EQUAL(saved_design_result, recent_probeDesignSave); // see comment in TEST_LATE_recent_probe_design_result
709    }
710
711    TEST_EXPECT_LOADS_INTO_MULTIPROBE_AS(saved_design_result, recent_expected);
712    free(saved_design_result);
713}
714
715
716#endif // UNIT_TESTS
717
718// --------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.