| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : AP_conservProfile2Gnuplot.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 | #include "AP_conservProfile2Gnuplot.h" |
|---|
| 13 | |
|---|
| 14 | #include <aw_window.hxx> |
|---|
| 15 | #include <aw_file.hxx> |
|---|
| 16 | #include <aw_awar.hxx> |
|---|
| 17 | #include <aw_msg.hxx> |
|---|
| 18 | #include <aw_root.hxx> |
|---|
| 19 | #include <arbdbt.h> |
|---|
| 20 | |
|---|
| 21 | static void AP_conservProfile2Gnuplot_callback(AW_window *aww) { |
|---|
| 22 | GB_ERROR error = 0; |
|---|
| 23 | char *command_file; |
|---|
| 24 | char *cmdName = GB_unique_filename("arb", "gnuplot"); |
|---|
| 25 | FILE *cmdFile = GB_fopen_tempfile(cmdName, "wt", &command_file); |
|---|
| 26 | |
|---|
| 27 | if (!cmdFile) error = GB_await_error(); |
|---|
| 28 | else { |
|---|
| 29 | char *fname = aww->get_root()->awar(AP_AWAR_CONSPRO_FILENAME)->read_string(); |
|---|
| 30 | char *smooth = aww->get_root()->awar(AP_AWAR_CONSPRO_SMOOTH_GNUPLOT)->read_string(); |
|---|
| 31 | char *legend = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_LEGEND)->read_string(); |
|---|
| 32 | int dispPos = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_DISP_POS)->read_int(); |
|---|
| 33 | int minX = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MIN_X)->read_int(); |
|---|
| 34 | int maxX = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MAX_X)->read_int(); |
|---|
| 35 | int minY = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MIN_Y)->read_int(); |
|---|
| 36 | int maxY = aww->get_root()->awar(AP_AWAR_CONSPRO_GNUPLOT_MAX_Y)->read_int(); |
|---|
| 37 | |
|---|
| 38 | if (minX>0 || maxX>0) fprintf(cmdFile, "set xrange [%i:%i]\n", minX, maxX); |
|---|
| 39 | if (minY>0 || maxY>0) fprintf(cmdFile, "set yrange [%i:%i]\n", minY, maxY); |
|---|
| 40 | |
|---|
| 41 | fprintf(cmdFile, "plot \"%s\" %s title \"%s\"\n", fname, smooth, legend); |
|---|
| 42 | |
|---|
| 43 | if (dispPos) fprintf(cmdFile, "replot \"%s\" title \"Base Positions\"\n", fname); |
|---|
| 44 | |
|---|
| 45 | fprintf(cmdFile, "pause -1 \"Press RETURN to close gnuplot\"\n"); |
|---|
| 46 | |
|---|
| 47 | free(legend); |
|---|
| 48 | free(smooth); |
|---|
| 49 | free(fname); |
|---|
| 50 | |
|---|
| 51 | fclose(cmdFile); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | if (!error) { |
|---|
| 55 | char *script = GBS_global_string_copy("gnuplot %s && rm -f %s", command_file, command_file); |
|---|
| 56 | GB_xcmd(script, true, true); // execute GNUPLOT using command_file |
|---|
| 57 | free(script); |
|---|
| 58 | } |
|---|
| 59 | free(command_file); |
|---|
| 60 | free(cmdName); |
|---|
| 61 | |
|---|
| 62 | if (error) aw_message(error); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | static AW_window *AP_createConservationProfileWindow(AW_root *root) { // @@@ unused! test and add to menu if useful |
|---|
| 67 | |
|---|
| 68 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 69 | |
|---|
| 70 | aws->init(root, "DISP_CONSERV_PROFILE_GNUPLOT", "Conservation Profile Using Base Frequency Filter"); |
|---|
| 71 | aws->load_xfig("conservProfile2Gnuplot.fig"); |
|---|
| 72 | |
|---|
| 73 | root->awar_string(AP_AWAR_CONSPRO_SMOOTH_GNUPLOT); |
|---|
| 74 | root->awar_string(AP_AWAR_BASE_FREQ_FILTER_NAME); |
|---|
| 75 | |
|---|
| 76 | AW_create_fileselection_awars(root, AP_AWAR_CONSPRO, "", ".gnu", "noname.gnu"); |
|---|
| 77 | |
|---|
| 78 | root->awar_string(AP_AWAR_CONSPRO_GNUPLOT_LEGEND); |
|---|
| 79 | root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_DISP_POS); |
|---|
| 80 | root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MIN_X); |
|---|
| 81 | root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MAX_X); |
|---|
| 82 | root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MIN_Y); |
|---|
| 83 | root->awar_int(AP_AWAR_CONSPRO_GNUPLOT_MAX_Y); |
|---|
| 84 | |
|---|
| 85 | aws->at("close"); aws->callback((AW_CB0)AW_POPDOWN); |
|---|
| 86 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 87 | |
|---|
| 88 | aws->at("help"); aws->callback(makeHelpCallback("conservProfile2Gnuplot.hlp")); |
|---|
| 89 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 90 | |
|---|
| 91 | AW_create_standard_fileselection(aws, AP_AWAR_CONSPRO); |
|---|
| 92 | |
|---|
| 93 | aws->at("baseFreqFlt"); |
|---|
| 94 | aws->create_button("SELECT_FILTER", AP_AWAR_BASE_FREQ_FILTER_NAME); |
|---|
| 95 | |
|---|
| 96 | aws->at("minX"); |
|---|
| 97 | aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MIN_X); |
|---|
| 98 | |
|---|
| 99 | aws->at("maxX"); |
|---|
| 100 | aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MAX_X); |
|---|
| 101 | |
|---|
| 102 | aws->at("minY"); |
|---|
| 103 | aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MIN_Y); |
|---|
| 104 | |
|---|
| 105 | aws->at("maxY"); |
|---|
| 106 | aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_MAX_Y); |
|---|
| 107 | |
|---|
| 108 | aws->at("legend"); |
|---|
| 109 | aws->create_input_field(AP_AWAR_CONSPRO_GNUPLOT_LEGEND); |
|---|
| 110 | |
|---|
| 111 | aws->at("smooth"); |
|---|
| 112 | aws->create_toggle_field(AP_AWAR_CONSPRO_SMOOTH_GNUPLOT, 1); |
|---|
| 113 | aws->insert_default_toggle("None", "N", ""); |
|---|
| 114 | aws->insert_toggle("Unique", "U", "smooth unique"); |
|---|
| 115 | aws->insert_toggle("Bezier", "B", "smooth bezier"); |
|---|
| 116 | aws->update_toggle_field(); |
|---|
| 117 | |
|---|
| 118 | aws->at("dispPos"); |
|---|
| 119 | aws->create_toggle(AP_AWAR_CONSPRO_GNUPLOT_DISP_POS); |
|---|
| 120 | |
|---|
| 121 | aws->at("dispProfile"); |
|---|
| 122 | aws->callback(AP_conservProfile2Gnuplot_callback); |
|---|
| 123 | aws->create_button("DISPLAY_PROFILE", "SAVE & DISPLAY CONSERVATION PROFILE"); |
|---|
| 124 | |
|---|
| 125 | return aws; |
|---|
| 126 | } |
|---|
| 127 | |
|---|