| 1 | // =============================================================== // | 
|---|
| 2 | //                                                                 // | 
|---|
| 3 | //   File      : graph_aligner_gui.cxx                             // | 
|---|
| 4 | //   Purpose   :                                                   // | 
|---|
| 5 | //                                                                 // | 
|---|
| 6 | //   Coded by Elmar Pruesse in October 2008                        // | 
|---|
| 7 | //   Institute of Microbiology (Technical University Munich)       // | 
|---|
| 8 | //   http://www.arb-home.de/                                       // | 
|---|
| 9 | //                                                                 // | 
|---|
| 10 | // =============================================================== // | 
|---|
| 11 |  | 
|---|
| 12 | #include "graph_aligner_gui.hxx" | 
|---|
| 13 |  | 
|---|
| 14 | #include "ed4_defs.hxx" | 
|---|
| 15 |  | 
|---|
| 16 | // need to use AlignDataAccess defined here to get selected species | 
|---|
| 17 | #include <fast_aligner.hxx> | 
|---|
| 18 |  | 
|---|
| 19 | #include <aw_awars.hxx> | 
|---|
| 20 | #include <aw_msg.hxx> | 
|---|
| 21 | #include <aw_root.hxx> | 
|---|
| 22 | #include <awt_sel_boxes.hxx> | 
|---|
| 23 | #include <awt_config_manager.hxx> | 
|---|
| 24 | #include <servercntrl.h> | 
|---|
| 25 | #include <PT_com.h> | 
|---|
| 26 | #include <client.h> | 
|---|
| 27 | #include <arbdbt.h> | 
|---|
| 28 | #include <arb_strbuf.h> | 
|---|
| 29 | #include <arb_misc.h> | 
|---|
| 30 |  | 
|---|
| 31 | #include <sys/types.h> | 
|---|
| 32 | #include <sys/wait.h> | 
|---|
| 33 |  | 
|---|
| 34 | #include <unistd.h> | 
|---|
| 35 |  | 
|---|
| 36 | #include <string> | 
|---|
| 37 | #include <sstream> | 
|---|
| 38 | #include <iostream> | 
|---|
| 39 | #include <vector> | 
|---|
| 40 |  | 
|---|
| 41 | using std::cerr; | 
|---|
| 42 | using std::cout; | 
|---|
| 43 | using std::endl; | 
|---|
| 44 |  | 
|---|
| 45 | #define GA_AWAR_ROOT "sina/" | 
|---|
| 46 |  | 
|---|
| 47 | #define GA_AWAR_CMD            GA_AWAR_ROOT "command" | 
|---|
| 48 | #define GA_AWAR_TGT            GA_AWAR_ROOT "target" | 
|---|
| 49 | #define GA_AWAR_SAI            GA_AWAR_ROOT "sai" | 
|---|
| 50 | #define GA_AWAR_ALIGNMENT      GA_AWAR_ROOT "alignment" | 
|---|
| 51 | #define GA_AWAR_PROTECTION     GA_AWAR_ROOT "protection" | 
|---|
| 52 | #define GA_AWAR_TURN_CHECK     GA_AWAR_ROOT "turncheck" | 
|---|
| 53 | #define GA_AWAR_REALIGN        GA_AWAR_ROOT "realign" | 
|---|
| 54 | #define GA_AWAR_COPYMARKREF    GA_AWAR_ROOT "copymarkref" | 
|---|
| 55 | #define GA_AWAR_MATCH_SCORE    GA_AWAR_ROOT "match_score" | 
|---|
| 56 | #define GA_AWAR_MISMATCH_SCORE GA_AWAR_ROOT "mismatch_score" | 
|---|
| 57 | #define GA_AWAR_GAP_PEN        GA_AWAR_ROOT "gap_pen" | 
|---|
| 58 | #define GA_AWAR_GAP_EXT        GA_AWAR_ROOT "gap_ext" | 
|---|
| 59 | #define GA_AWAR_ADVANCED       GA_AWAR_ROOT "advanced" | 
|---|
| 60 | #define GA_AWAR_FS_MIN         GA_AWAR_ROOT "fs_min" | 
|---|
| 61 | #define GA_AWAR_FS_MAX         GA_AWAR_ROOT "fs_max" | 
|---|
| 62 | #define GA_AWAR_FS_MSC         GA_AWAR_ROOT "fs_msc" | 
|---|
| 63 | #define GA_AWAR_MIN_FULL       GA_AWAR_ROOT "min_full" | 
|---|
| 64 | #define GA_AWAR_FULL_MINLEN    GA_AWAR_ROOT "full_minlen" | 
|---|
| 65 | #define GA_AWAR_OVERHANG       GA_AWAR_ROOT "overhang" | 
|---|
| 66 | #define GA_AWAR_THREADS        GA_AWAR_ROOT "threads" | 
|---|
| 67 | #define GA_AWAR_QSIZE          GA_AWAR_ROOT "qsize" | 
|---|
| 68 | #define GA_AWAR_KMER_LEN       GA_AWAR_ROOT "kmer_len" | 
|---|
| 69 | #define GA_AWAR_KMER_MM        GA_AWAR_ROOT "kmer_mm" | 
|---|
| 70 | #define GA_AWAR_MIN_LEN        GA_AWAR_ROOT "min_len" | 
|---|
| 71 | #define GA_AWAR_WEIGHT         GA_AWAR_ROOT "weight" | 
|---|
| 72 | #define GA_AWAR_INSERT         GA_AWAR_ROOT "insert" | 
|---|
| 73 | #define GA_AWAR_LOWERCASE      GA_AWAR_ROOT "lowercase" | 
|---|
| 74 | #define GA_AWAR_AUTOFILTER     GA_AWAR_ROOT "autofilter" | 
|---|
| 75 | #define GA_AWAR_KMER_NOREL     GA_AWAR_ROOT "kmer_norel" | 
|---|
| 76 | #define GA_AWAR_KMER_NOFAST    GA_AWAR_ROOT "kmer_nofast" | 
|---|
| 77 | #define GA_AWAR_SHOW_DIST      GA_AWAR_ROOT "show_dist" | 
|---|
| 78 | #define GA_AWAR_SHOW_DIFF      GA_AWAR_ROOT "show_diff" | 
|---|
| 79 | #define GA_AWAR_COLOR          GA_AWAR_ROOT "color" | 
|---|
| 80 | #define GA_AWAR_GENE_START     GA_AWAR_ROOT "gene_start" | 
|---|
| 81 | #define GA_AWAR_GENE_END       GA_AWAR_ROOT "gene_end" | 
|---|
| 82 | #define GA_AWAR_FS_COVER_GENE  GA_AWAR_ROOT "fs_cover_gene" | 
|---|
| 83 |  | 
|---|
| 84 | void create_sina_variables(AW_root *root, AW_default db1) { | 
|---|
| 85 | root->awar_string(GA_AWAR_CMD,            "sina",   db1); | 
|---|
| 86 | root->awar_int   (GA_AWAR_TGT,            2,        db1); | 
|---|
| 87 | root->awar_int   (AWAR_PT_SERVER,         0,        db1); | 
|---|
| 88 | root->awar_string(GA_AWAR_SAI,            "",       db1); | 
|---|
| 89 | root->awar_int   (GA_AWAR_PROTECTION,     0,        db1); | 
|---|
| 90 | root->awar_int   (GA_AWAR_TURN_CHECK,     1,        db1); | 
|---|
| 91 | root->awar_int   (GA_AWAR_REALIGN,        1,        db1); | 
|---|
| 92 | root->awar_int   (GA_AWAR_COPYMARKREF,    0,        db1); | 
|---|
| 93 | root->awar_float (GA_AWAR_GAP_PEN,        5.0,      db1); | 
|---|
| 94 | root->awar_float (GA_AWAR_GAP_EXT,        2.0,      db1); | 
|---|
| 95 | root->awar_float (GA_AWAR_MATCH_SCORE,    2.0,      db1); | 
|---|
| 96 | root->awar_float (GA_AWAR_MISMATCH_SCORE, -1.0,     db1); | 
|---|
| 97 | root->awar_int   (GA_AWAR_ADVANCED,       0,        db1); | 
|---|
| 98 | root->awar_int   (GA_AWAR_FS_MIN,         40,       db1); | 
|---|
| 99 | root->awar_int   (GA_AWAR_FS_MAX,         40,       db1); | 
|---|
| 100 | root->awar_float (GA_AWAR_FS_MSC,         .7,       db1); | 
|---|
| 101 | root->awar_int   (GA_AWAR_MIN_FULL,       1,        db1); | 
|---|
| 102 | root->awar_int   (GA_AWAR_FULL_MINLEN,    1400,     db1); | 
|---|
| 103 | root->awar_string(GA_AWAR_OVERHANG,       "attach", db1); | 
|---|
| 104 | root->awar_int   (GA_AWAR_THREADS,        1,        db1); | 
|---|
| 105 | root->awar_int   (GA_AWAR_QSIZE,          1,        db1); | 
|---|
| 106 | root->awar_int   (GA_AWAR_KMER_LEN,       10,       db1); | 
|---|
| 107 | root->awar_int   (GA_AWAR_KMER_MM,        0,        db1); | 
|---|
| 108 | root->awar_int   (GA_AWAR_MIN_LEN,        150,      db1); | 
|---|
| 109 | root->awar_float (GA_AWAR_WEIGHT,         1,        db1); | 
|---|
| 110 | root->awar_string(GA_AWAR_INSERT,         "shift",  db1); | 
|---|
| 111 | root->awar_string(GA_AWAR_LOWERCASE,      "none",   db1); | 
|---|
| 112 | root->awar_string(GA_AWAR_AUTOFILTER,     "none",   db1); | 
|---|
| 113 | root->awar_int   (GA_AWAR_KMER_NOREL,     0,        db1); | 
|---|
| 114 | root->awar_int   (GA_AWAR_KMER_NOFAST,    0,        db1); | 
|---|
| 115 | root->awar_int   (GA_AWAR_SHOW_DIST,      0,        db1); | 
|---|
| 116 | root->awar_int   (GA_AWAR_SHOW_DIFF,      0,        db1); | 
|---|
| 117 | root->awar_int   (GA_AWAR_COLOR,          1,        db1); | 
|---|
| 118 | root->awar_int   (GA_AWAR_GENE_START,     0,        db1); | 
|---|
| 119 | root->awar_int   (GA_AWAR_GENE_END,       0,        db1); | 
|---|
| 120 | root->awar_int   (GA_AWAR_FS_COVER_GENE,  1,        db1); | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | AW_active sina_mask(AW_root *root) { | 
|---|
| 124 | const char *sinaName    = root->awar(GA_AWAR_CMD)->read_char_pntr(); | 
|---|
| 125 | char       *sina        = ARB_executable(sinaName, GB_getenv("PATH")); | 
|---|
| 126 | const char *fail_reason = NULp; | 
|---|
| 127 |  | 
|---|
| 128 | if (sina) { | 
|---|
| 129 | if (ARB_path_contains_unwanted_chars(sina)) { | 
|---|
| 130 | char *description = GBS_global_string_copy("the sina executable derived from\n" | 
|---|
| 131 | "- gui property '%s' and\n" | 
|---|
| 132 | "- environment variable PATH", sinaName); | 
|---|
| 133 | ARB_warn_about_unwanted_chars(sina, description); | 
|---|
| 134 | free(description); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | int exitstatus = system(GBS_global_string("%s --has-cli-vers ARB5.99", sina)); | 
|---|
| 138 | exitstatus     = WEXITSTATUS(exitstatus); | 
|---|
| 139 |  | 
|---|
| 140 | switch (exitstatus) { | 
|---|
| 141 | case EXIT_SUCCESS: | 
|---|
| 142 | break; | 
|---|
| 143 |  | 
|---|
| 144 | case EXIT_FAILURE: | 
|---|
| 145 | fail_reason = "Incompatible SINA and ARB versions"; | 
|---|
| 146 | break; | 
|---|
| 147 |  | 
|---|
| 148 | case 127:                                   // libs missing | 
|---|
| 149 | default:                                    // unexpected | 
|---|
| 150 | fail_reason = GBS_global_string("Could execute SINA binary '%s' (exitstatus was %i)", | 
|---|
| 151 | sinaName, exitstatus); | 
|---|
| 152 | break; | 
|---|
| 153 | } | 
|---|
| 154 | free(sina); | 
|---|
| 155 | } | 
|---|
| 156 | else { | 
|---|
| 157 | fail_reason = GBS_global_string("'%s' not found", sinaName); | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | if (fail_reason) { | 
|---|
| 161 | fprintf(stderr, | 
|---|
| 162 | "Note: SINA (SILVA Aligner) disabled (Reason: %s)\n", | 
|---|
| 163 | fail_reason); | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 | return fail_reason ? AWM_DISABLED : AWM_ALL; | 
|---|
| 167 | } | 
|---|
| 168 |  | 
|---|
| 169 | inline const char *stream2static(const std::stringstream& str) { | 
|---|
| 170 | return GBS_static_string(str.str().c_str()); | 
|---|
| 171 | } | 
|---|
| 172 |  | 
|---|
| 173 | inline const char *empty_as_none(const char *sainame) { | 
|---|
| 174 | // see http://bugs.arb-home.de/ticket/519 | 
|---|
| 175 | if (sainame && !sainame[0]) sainame = "none"; | 
|---|
| 176 | return sainame; | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | static void sina_start(AW_window *window, const AlignDataAccess *data_access) { | 
|---|
| 180 | cerr << "Starting SINA..." << endl; | 
|---|
| 181 |  | 
|---|
| 182 | // make string from pt server selection | 
|---|
| 183 | AW_root *root = window->get_root(); | 
|---|
| 184 | int      pt   = root->awar(AWAR_PT_SERVER)->read_int(); | 
|---|
| 185 |  | 
|---|
| 186 | std::stringstream ptnam; | 
|---|
| 187 | ptnam << "ARB_PT_SERVER" << pt; | 
|---|
| 188 |  | 
|---|
| 189 | const char *pt_server = GBS_read_arb_tcp(ptnam.str().c_str()); | 
|---|
| 190 | GB_ERROR    gb_error  = NULp; | 
|---|
| 191 |  | 
|---|
| 192 | if (!pt_server) { | 
|---|
| 193 | gb_error = GBS_global_string("Unable to find definition for chosen PT-server\n(Reason: %s)", GB_await_error()); | 
|---|
| 194 | } | 
|---|
| 195 | else { | 
|---|
| 196 | const char *pt_db = pt_server + strlen(pt_server) + 1; | 
|---|
| 197 | pt_db += strlen(pt_db)+3; | 
|---|
| 198 |  | 
|---|
| 199 | // start pt server if necessary | 
|---|
| 200 | gb_error = arb_look_and_start_server(AISC_MAGIC_NUMBER, ptnam.str().c_str()); | 
|---|
| 201 | if (gb_error) { | 
|---|
| 202 | std::stringstream tmp; | 
|---|
| 203 | tmp << "Cannot contact PT server. Aborting" << endl | 
|---|
| 204 | << " ID: \"" << tmp.str().c_str() | 
|---|
| 205 | << "\" PORT: \"" << pt_server | 
|---|
| 206 | << "\" DB: \"" << pt_db  << endl | 
|---|
| 207 | << "\" GBERROR: \"" << gb_error << "\"" << endl; | 
|---|
| 208 | gb_error = stream2static(tmp); | 
|---|
| 209 | } | 
|---|
| 210 | else { | 
|---|
| 211 | // create temporary file | 
|---|
| 212 | char* tmpfile; | 
|---|
| 213 | FILE* tmpfile_F; | 
|---|
| 214 | { | 
|---|
| 215 | char* tmpfile_tpl = GB_unique_filename("sina_select", "tmp"); | 
|---|
| 216 | tmpfile_F         = GB_fopen_tempfile(tmpfile_tpl, "w", &tmpfile); | 
|---|
| 217 | free(tmpfile_tpl); | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | if (!tmpfile_F) { | 
|---|
| 221 | std::stringstream tmp; | 
|---|
| 222 | tmp << "Error: Unable to create temporary file \"" << tmpfile << "\"!"; | 
|---|
| 223 | gb_error = stream2static(tmp); | 
|---|
| 224 | } | 
|---|
| 225 | else { | 
|---|
| 226 | GB_remove_on_exit(tmpfile); | 
|---|
| 227 | GBDATA *gb_main = data_access->gb_main; | 
|---|
| 228 |  | 
|---|
| 229 | std::vector<std::string> spec_names; | 
|---|
| 230 | switch (root->awar(GA_AWAR_TGT)->read_int()) { | 
|---|
| 231 | case 0: { // current | 
|---|
| 232 | char *spec_name = root->awar(AWAR_SPECIES_NAME)->read_string(); | 
|---|
| 233 | if (spec_name) { | 
|---|
| 234 | fwrite(spec_name, strlen(spec_name), 1, tmpfile_F); | 
|---|
| 235 | fwrite("\n", 1, 1, tmpfile_F); | 
|---|
| 236 | } | 
|---|
| 237 | else { | 
|---|
| 238 | gb_error = "Unable to get name of currently active species"; | 
|---|
| 239 | } | 
|---|
| 240 | free(spec_name); | 
|---|
| 241 | break; | 
|---|
| 242 | } | 
|---|
| 243 | case 1: { // selected | 
|---|
| 244 | GB_begin_transaction(gb_main); | 
|---|
| 245 | int num_selected = 0; | 
|---|
| 246 | for (GBDATA *gb_spec = data_access->get_first_selected_species(&num_selected); | 
|---|
| 247 | gb_spec; | 
|---|
| 248 | gb_spec = data_access->get_next_selected_species()) | 
|---|
| 249 | { | 
|---|
| 250 | GBDATA *gbd_name = GB_find(gb_spec, "name", SEARCH_CHILD); | 
|---|
| 251 | if (gbd_name) { | 
|---|
| 252 | const char *str = GB_read_char_pntr(gbd_name); | 
|---|
| 253 | fwrite(str, strlen(str), 1, tmpfile_F); | 
|---|
| 254 | fwrite("\n", 1, 1, tmpfile_F); | 
|---|
| 255 | } | 
|---|
| 256 | } | 
|---|
| 257 | GB_commit_transaction(gb_main); | 
|---|
| 258 | break; | 
|---|
| 259 | } | 
|---|
| 260 | case 2: { // marked | 
|---|
| 261 | GB_begin_transaction(gb_main); | 
|---|
| 262 | for (GBDATA *gb_spec = GBT_first_marked_species(gb_main); | 
|---|
| 263 | gb_spec; gb_spec = GBT_next_marked_species(gb_spec)) { | 
|---|
| 264 | GBDATA *gbd_name = GB_find(gb_spec, "name", SEARCH_CHILD); | 
|---|
| 265 | if (gbd_name) { | 
|---|
| 266 | const char *str = GB_read_char_pntr(gbd_name); | 
|---|
| 267 | fwrite(str, strlen(str), 1, tmpfile_F); | 
|---|
| 268 | fwrite("\n", 1, 1, tmpfile_F); | 
|---|
| 269 | } | 
|---|
| 270 | } | 
|---|
| 271 | GB_commit_transaction(gb_main); | 
|---|
| 272 | break; | 
|---|
| 273 | } | 
|---|
| 274 | } | 
|---|
| 275 | fclose(tmpfile_F); | 
|---|
| 276 |  | 
|---|
| 277 | if (!gb_error) { | 
|---|
| 278 | // build command line | 
|---|
| 279 | GBS_strstruct *cl = GBS_stropen(2000); | 
|---|
| 280 |  | 
|---|
| 281 | GBS_strcat(cl, root->awar(GA_AWAR_CMD)->read_char_pntr()); | 
|---|
| 282 | GBS_strcat(cl, " -i :"); | 
|---|
| 283 | GBS_strcat(cl, " --ptdb :"); | 
|---|
| 284 | GBS_strcat(cl, " --ptport ");      GBS_strcat(cl,   pt_server); | 
|---|
| 285 | GBS_strcat(cl, " --turn ");        GBS_strcat(cl,   root->awar(GA_AWAR_TURN_CHECK)->read_int() ? "all" : "none"); | 
|---|
| 286 | GBS_strcat(cl, " --overhang ");    GBS_strcat(cl,   root->awar(GA_AWAR_OVERHANG)->read_char_pntr()); | 
|---|
| 287 | GBS_strcat(cl, " --filter ");      GBS_strcat(cl,   empty_as_none(root->awar(GA_AWAR_SAI)->read_char_pntr())); | 
|---|
| 288 | GBS_strcat(cl, " --fs-min ");      GBS_intcat(cl,   root->awar(GA_AWAR_FS_MIN)->read_int()); | 
|---|
| 289 | GBS_strcat(cl, " --fs-msc ");      GBS_floatcat(cl, root->awar(GA_AWAR_FS_MSC)->read_float()); | 
|---|
| 290 | GBS_strcat(cl, " --fs-max ");      GBS_intcat(cl,   root->awar(GA_AWAR_FS_MAX)->read_int()); | 
|---|
| 291 | GBS_strcat(cl, " --fs-req 1"); | 
|---|
| 292 | GBS_strcat(cl, " --fs-req-full "); GBS_intcat(cl,   root->awar(GA_AWAR_MIN_FULL)->read_int()); | 
|---|
| 293 | GBS_strcat(cl, " --fs-full-len "); GBS_intcat(cl,   root->awar(GA_AWAR_FULL_MINLEN)->read_int()); | 
|---|
| 294 | GBS_strcat(cl, " --fs-kmer-len "); GBS_intcat(cl,   root->awar(GA_AWAR_KMER_LEN)->read_int()); | 
|---|
| 295 | GBS_strcat(cl, " --fs-kmer-mm ");  GBS_intcat(cl,   root->awar(GA_AWAR_KMER_MM)->read_int()); | 
|---|
| 296 | GBS_strcat(cl, " --fs-min-len ");  GBS_intcat(cl,   root->awar(GA_AWAR_MIN_LEN)->read_int()); | 
|---|
| 297 | GBS_strcat(cl, " --fs-weight ");   GBS_intcat(cl,   root->awar(GA_AWAR_WEIGHT)->read_float()); // @@@ possible type conflict? | 
|---|
| 298 | GBS_strcat(cl, " --pen-gap ");     GBS_floatcat(cl, root->awar(GA_AWAR_GAP_PEN)->read_float()); | 
|---|
| 299 | GBS_strcat(cl, " --pen-gapext ");  GBS_floatcat(cl, root->awar(GA_AWAR_GAP_EXT)->read_float()); | 
|---|
| 300 | GBS_strcat(cl, " --match-score "); GBS_floatcat(cl, root->awar(GA_AWAR_MATCH_SCORE)->read_float()); | 
|---|
| 301 | GBS_strcat(cl, " --mismatch-score "); GBS_floatcat(cl, root->awar(GA_AWAR_MISMATCH_SCORE)->read_float()); | 
|---|
| 302 | GBS_strcat(cl, " --prot-level ");  GBS_intcat(cl,   root->awar(GA_AWAR_PROTECTION)->read_int()); | 
|---|
| 303 | GBS_strcat(cl, " --select-file "); GBS_strcat(cl,   tmpfile); | 
|---|
| 304 | GBS_strcat(cl, " --insertion ");   GBS_strcat(cl,   root->awar(GA_AWAR_INSERT)->read_char_pntr()); | 
|---|
| 305 | GBS_strcat(cl, " --lowercase ");   GBS_strcat(cl,   root->awar(GA_AWAR_LOWERCASE)->read_char_pntr()); | 
|---|
| 306 | GBS_strcat(cl, " --auto-filter-field "); GBS_strcat(cl, root->awar(GA_AWAR_AUTOFILTER)->read_char_pntr()); | 
|---|
| 307 | GBS_strcat(cl, " --gene-start ");  GBS_intcat(cl,   root->awar(GA_AWAR_GENE_START)->read_int()); | 
|---|
| 308 | GBS_strcat(cl, " --gene-end ");    GBS_intcat(cl,   root->awar(GA_AWAR_GENE_END)->read_int()); | 
|---|
| 309 | GBS_strcat(cl, " --fs-cover-gene ");GBS_intcat(cl,   root->awar(GA_AWAR_FS_COVER_GENE)->read_int()); | 
|---|
| 310 |  | 
|---|
| 311 |  | 
|---|
| 312 | if (root->awar(GA_AWAR_KMER_NOREL)->read_int()) GBS_strcat(cl, " --fs-kmer-norel "); | 
|---|
| 313 | if (root->awar(GA_AWAR_KMER_NOFAST)->read_int()) GBS_strcat(cl, " --fs-kmer-no-fast "); | 
|---|
| 314 | if (root->awar(GA_AWAR_SHOW_DIST)->read_int()) GBS_strcat(cl, " --show-dist "); | 
|---|
| 315 | if (root->awar(GA_AWAR_SHOW_DIFF)->read_int()) GBS_strcat(cl, " --show-diff "); | 
|---|
| 316 | if (root->awar(GA_AWAR_COLOR)->read_int())     GBS_strcat(cl, " --color"); | 
|---|
| 317 | if (root->awar(GA_AWAR_REALIGN)->read_int())     GBS_strcat(cl, " --realign"); | 
|---|
| 318 |  | 
|---|
| 319 | gb_error = GB_xcmd(GBS_mempntr(cl), XCMD_ASYNC_WAITKEY); | 
|---|
| 320 | GBS_strforget(cl); | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | if (!gb_error) aw_message("SINA finished aligning."); | 
|---|
| 324 | } | 
|---|
| 325 | free(tmpfile); | 
|---|
| 326 | } | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 | aw_message_if(gb_error); | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 |  | 
|---|
| 333 |  | 
|---|
| 334 | static char* filter_posvar_SAI_for_ali(GBDATA *gb_extended, const char *ali_name) { | 
|---|
| 335 | char   *result   = NULp; | 
|---|
| 336 | char   *typePath = GBS_global_string_copy("%s/_TYPE", ali_name); | 
|---|
| 337 | GBDATA *gbd      = GB_search(gb_extended, typePath, GB_FIND); | 
|---|
| 338 | if (gbd) { | 
|---|
| 339 | const char* type = GB_read_char_pntr(gbd); | 
|---|
| 340 | if (type && strncmp("PV", type, 2) == 0) { | 
|---|
| 341 | gbd    = GB_find(gb_extended, "name", SEARCH_CHILD); | 
|---|
| 342 | result = GB_read_string(gbd); | 
|---|
| 343 | } | 
|---|
| 344 | } | 
|---|
| 345 | free(typePath); | 
|---|
| 346 | return result; | 
|---|
| 347 | } | 
|---|
| 348 |  | 
|---|
| 349 | static AWT_config_mapping_def sina_config_mapping[] = { | 
|---|
| 350 | // both | 
|---|
| 351 | { GA_AWAR_TGT,         "target" }, | 
|---|
| 352 | { GA_AWAR_OVERHANG,    "overhang" }, | 
|---|
| 353 | { GA_AWAR_INSERT,      "insertions" }, | 
|---|
| 354 | { GA_AWAR_LOWERCASE,   "lowercase" }, | 
|---|
| 355 | { GA_AWAR_WEIGHT,      "weight" }, | 
|---|
| 356 | { GA_AWAR_FULL_MINLEN, "fullminlen" }, | 
|---|
| 357 |  | 
|---|
| 358 | // advanced only | 
|---|
| 359 | { GA_AWAR_SAI,            "sai" }, | 
|---|
| 360 | { GA_AWAR_AUTOFILTER,     "autofilter" }, | 
|---|
| 361 | { GA_AWAR_TURN_CHECK,     "turncheck" }, | 
|---|
| 362 | { GA_AWAR_REALIGN,        "realign" }, | 
|---|
| 363 | { GA_AWAR_GAP_PEN,        "gappen" }, | 
|---|
| 364 | { GA_AWAR_GAP_EXT,        "gapext" }, | 
|---|
| 365 | { GA_AWAR_MATCH_SCORE,    "matchscore" }, | 
|---|
| 366 | { GA_AWAR_MISMATCH_SCORE, "mismatchscore" }, | 
|---|
| 367 | { GA_AWAR_FS_MIN,         "fs_min" }, | 
|---|
| 368 | { GA_AWAR_FS_MSC,         "fs_minscore" }, | 
|---|
| 369 | { GA_AWAR_FS_MAX,         "fs_min" }, | 
|---|
| 370 | { GA_AWAR_MIN_FULL,       "minfull" }, | 
|---|
| 371 | { GA_AWAR_KMER_LEN,       "kmerlen" }, | 
|---|
| 372 | { GA_AWAR_KMER_MM,        "kmermm" }, | 
|---|
| 373 | { GA_AWAR_MIN_LEN,        "refminlen" }, | 
|---|
| 374 | { GA_AWAR_GENE_START,     "genestart" }, | 
|---|
| 375 | { GA_AWAR_GENE_END,       "geneend" }, | 
|---|
| 376 | { GA_AWAR_FS_COVER_GENE,  "fs_covergene" }, | 
|---|
| 377 | { GA_AWAR_KMER_NOFAST,    "kmernofast" }, | 
|---|
| 378 | { GA_AWAR_KMER_NOREL,     "kmernorel" }, | 
|---|
| 379 |  | 
|---|
| 380 | // both | 
|---|
| 381 | { GA_AWAR_SHOW_DIFF, "showdiff" }, | 
|---|
| 382 | { GA_AWAR_COLOR,     "color" }, | 
|---|
| 383 | { GA_AWAR_SHOW_DIST, "showdist" }, | 
|---|
| 384 |  | 
|---|
| 385 | { NULp, NULp } | 
|---|
| 386 | }; | 
|---|
| 387 |  | 
|---|
| 388 | static AW_window_simple* new_sina_simple(AW_root *root, const AlignDataAccess *alignData, bool adv) { | 
|---|
| 389 | int closex, closey, startx, starty, winx, winy; | 
|---|
| 390 | const int hgap = 10; | 
|---|
| 391 | AW_window_simple *aws = new AW_window_simple; | 
|---|
| 392 |  | 
|---|
| 393 | aws->init(root, adv ? "XSINA" : "SINA", "SINA (SILVA Incremental Aligner)"); | 
|---|
| 394 |  | 
|---|
| 395 | aws->button_length(12); | 
|---|
| 396 | aws->at(10, 10); | 
|---|
| 397 | aws->auto_space(5, 5); | 
|---|
| 398 |  | 
|---|
| 399 | aws->callback(AW_POPDOWN); | 
|---|
| 400 | aws->create_button("CLOSE", "CLOSE", "O"); | 
|---|
| 401 | aws->get_at_position(&closex, &closey); | 
|---|
| 402 |  | 
|---|
| 403 | aws->at_shift(10, 0); | 
|---|
| 404 | aws->label_length(0); | 
|---|
| 405 | aws->label("Show advanced options"); | 
|---|
| 406 | aws->create_toggle(GA_AWAR_ADVANCED); | 
|---|
| 407 |  | 
|---|
| 408 | bool cbInstalled = false; | 
|---|
| 409 | if (!cbInstalled) { | 
|---|
| 410 | root->awar(GA_AWAR_ADVANCED)->add_callback(makeRootCallback(show_sina_window, alignData)); | 
|---|
| 411 | cbInstalled = true; | 
|---|
| 412 | } | 
|---|
| 413 |  | 
|---|
| 414 | aws->at_newline(); | 
|---|
| 415 | aws->at_shift(0, hgap); | 
|---|
| 416 | aws->label_length(15); | 
|---|
| 417 | aws->create_toggle_field(GA_AWAR_TGT, "Align what?", "A"); | 
|---|
| 418 | aws->insert_toggle("Current Species:", "C", 0); | 
|---|
| 419 | aws->insert_toggle("Selected Species", "S", 1); | 
|---|
| 420 | aws->insert_default_toggle("Marked Species", "M", 2); | 
|---|
| 421 | aws->update_toggle_field(); | 
|---|
| 422 |  | 
|---|
| 423 | aws->at_shift(0, 3); | 
|---|
| 424 | aws->create_input_field(AWAR_SPECIES_NAME, 20); | 
|---|
| 425 |  | 
|---|
| 426 | aws->at_newline(); | 
|---|
| 427 | aws->at_shift(0, hgap); | 
|---|
| 428 | aws->button_length(24); | 
|---|
| 429 | aws->label("PT Server:"); | 
|---|
| 430 | awt_create_PTSERVER_selection_button(aws, AWAR_PT_SERVER); | 
|---|
| 431 |  | 
|---|
| 432 | aws->at_newline(); | 
|---|
| 433 | aws->label_length(0); | 
|---|
| 434 | aws->label("Overhang placement"); | 
|---|
| 435 | aws->create_option_menu(GA_AWAR_OVERHANG, true); | 
|---|
| 436 | aws->insert_option("keep attached", NULp, "attach"); | 
|---|
| 437 | aws->insert_option("move to edge",  NULp, "edge"); | 
|---|
| 438 | aws->insert_option("remove",        NULp, "remove"); | 
|---|
| 439 | aws->update_option_menu(); | 
|---|
| 440 |  | 
|---|
| 441 | aws->at_newline(); | 
|---|
| 442 | aws->label("Handling of unmappable insertions"); | 
|---|
| 443 | aws->create_option_menu(GA_AWAR_INSERT, true); | 
|---|
| 444 | aws->insert_option("Shift surrounding bases",    NULp, "shift"); | 
|---|
| 445 | aws->insert_option("Forbid during DP alignment", NULp, "forbid"); | 
|---|
| 446 | aws->insert_option("Delete bases",               NULp, "remove"); | 
|---|
| 447 | aws->update_option_menu(); | 
|---|
| 448 |  | 
|---|
| 449 | aws->at_newline(); | 
|---|
| 450 | aws->label("Character Case"); | 
|---|
| 451 | aws->create_option_menu(GA_AWAR_LOWERCASE, true); | 
|---|
| 452 | aws->insert_option("Do not modify",                      NULp, "original"); | 
|---|
| 453 | aws->insert_option("Show unaligned bases as lower case", NULp, "unaligned"); | 
|---|
| 454 | aws->insert_option("Uppercase all",                      NULp, "none"); | 
|---|
| 455 | aws->update_option_menu(); | 
|---|
| 456 |  | 
|---|
| 457 | aws->at_newline(); | 
|---|
| 458 | aws->label("Family conservation weight (0-1)"); | 
|---|
| 459 | aws->create_input_field(GA_AWAR_WEIGHT, 3); | 
|---|
| 460 |  | 
|---|
| 461 | aws->at_newline(); | 
|---|
| 462 | aws->label("Size of full-length sequences"); | 
|---|
| 463 | aws->create_input_field(GA_AWAR_FULL_MINLEN, 5); | 
|---|
| 464 |  | 
|---|
| 465 | if (adv) { | 
|---|
| 466 | aws->at_newline(); | 
|---|
| 467 | aws->at_shift(0, hgap); | 
|---|
| 468 |  | 
|---|
| 469 | aws->at_newline(); | 
|---|
| 470 |  | 
|---|
| 471 | aws->label("Pos. Var.:"); | 
|---|
| 472 | awt_create_SAI_selection_button(alignData->gb_main, aws, GA_AWAR_SAI, makeSaiSelectionlistFilterCallback(filter_posvar_SAI_for_ali, alignData->alignment_name.c_str())); | 
|---|
| 473 |  | 
|---|
| 474 | aws->at_newline(); | 
|---|
| 475 | aws->label("Field used for automatic filter selection"); | 
|---|
| 476 | aws->create_input_field(GA_AWAR_AUTOFILTER, 20); | 
|---|
| 477 |  | 
|---|
| 478 | aws->label("Turn check"); | 
|---|
| 479 | aws->create_toggle(GA_AWAR_TURN_CHECK); | 
|---|
| 480 |  | 
|---|
| 481 | aws->at_newline(); | 
|---|
| 482 | aws->label("Realign"); | 
|---|
| 483 | aws->create_toggle(GA_AWAR_REALIGN); | 
|---|
| 484 |  | 
|---|
| 485 | /* | 
|---|
| 486 | aws->at_newline(); | 
|---|
| 487 | aws->label("(Copy and) mark sequences used as reference"); | 
|---|
| 488 | aws->create_toggle(GA_AWAR_COPYMARKREF); | 
|---|
| 489 | */ | 
|---|
| 490 |  | 
|---|
| 491 | aws->at_newline(); | 
|---|
| 492 | aws->at_shift(0, hgap); | 
|---|
| 493 | aws->label_length(0); | 
|---|
| 494 |  | 
|---|
| 495 | aws->label("Gap insertion/extension penalties"); | 
|---|
| 496 | aws->create_input_field(GA_AWAR_GAP_PEN, 5); | 
|---|
| 497 | aws->create_input_field(GA_AWAR_GAP_EXT, 5); | 
|---|
| 498 |  | 
|---|
| 499 | aws->at_newline(); | 
|---|
| 500 | aws->label("Match score"); | 
|---|
| 501 | aws->create_input_field(GA_AWAR_MATCH_SCORE, 3); | 
|---|
| 502 | aws->label("Mismatch score"); | 
|---|
| 503 | aws->create_input_field(GA_AWAR_MISMATCH_SCORE, 3); | 
|---|
| 504 |  | 
|---|
| 505 | aws->at_newline(); | 
|---|
| 506 | aws->label("Family search min/min_score/max"); | 
|---|
| 507 | aws->create_input_field(GA_AWAR_FS_MIN, 3); | 
|---|
| 508 | aws->create_input_field(GA_AWAR_FS_MSC, 3); | 
|---|
| 509 | aws->create_input_field(GA_AWAR_FS_MAX, 3); | 
|---|
| 510 |  | 
|---|
| 511 | aws->at_newline(); | 
|---|
| 512 | aws->label("Minimal number of full length sequences"); | 
|---|
| 513 | aws->create_input_field(GA_AWAR_MIN_FULL, 3); | 
|---|
| 514 |  | 
|---|
| 515 | aws->at_newline(); | 
|---|
| 516 | aws->label("Family search oligo length / mismatches"); | 
|---|
| 517 | aws->create_input_field(GA_AWAR_KMER_LEN, 3); | 
|---|
| 518 | aws->create_input_field(GA_AWAR_KMER_MM, 3); | 
|---|
| 519 |  | 
|---|
| 520 | aws->at_newline(); | 
|---|
| 521 | aws->label("Minimal reference sequence length"); | 
|---|
| 522 | aws->create_input_field(GA_AWAR_MIN_LEN, 5); | 
|---|
| 523 |  | 
|---|
| 524 | aws->at_newline(); | 
|---|
| 525 | aws->label("Alignment bounds: start"); | 
|---|
| 526 | aws->create_input_field(GA_AWAR_GENE_START, 6); | 
|---|
| 527 | aws->label("end"); | 
|---|
| 528 | aws->create_input_field(GA_AWAR_GENE_END, 6); | 
|---|
| 529 |  | 
|---|
| 530 | aws->at_newline(); | 
|---|
| 531 | aws->label("Number of references required to touch bounds"); | 
|---|
| 532 | aws->create_input_field(GA_AWAR_FS_COVER_GENE, 3); | 
|---|
| 533 |  | 
|---|
| 534 | aws->at_newline(); | 
|---|
| 535 | aws->label("Disable fast search"); | 
|---|
| 536 | aws->create_toggle(GA_AWAR_KMER_NOFAST); | 
|---|
| 537 |  | 
|---|
| 538 | aws->at_newline(); | 
|---|
| 539 | aws->label("Score search results by absolute oligo match count"); | 
|---|
| 540 | aws->create_toggle(GA_AWAR_KMER_NOREL); | 
|---|
| 541 |  | 
|---|
| 542 | aws->at_newline(); | 
|---|
| 543 | aws->label("SINA command"); | 
|---|
| 544 | aws->create_input_field(GA_AWAR_CMD, 20); | 
|---|
| 545 |  | 
|---|
| 546 | aws->at_shift(0, hgap); | 
|---|
| 547 | } | 
|---|
| 548 |  | 
|---|
| 549 | aws->at_newline(); | 
|---|
| 550 | aws->at_shift(0, hgap); | 
|---|
| 551 |  | 
|---|
| 552 | aws->label_length(17); | 
|---|
| 553 | aws->label("Protection Level"); | 
|---|
| 554 | aws->create_option_menu(GA_AWAR_PROTECTION, true); | 
|---|
| 555 | aws->insert_option("0", NULp, 0); | 
|---|
| 556 | aws->insert_option("1", NULp, 1); | 
|---|
| 557 | aws->insert_option("2", NULp, 2); | 
|---|
| 558 | aws->insert_option("3", NULp, 3); | 
|---|
| 559 | aws->insert_option("4", NULp, 4); | 
|---|
| 560 | aws->insert_option("5", NULp, 5); | 
|---|
| 561 | aws->insert_option("6", NULp, 6); | 
|---|
| 562 | aws->update_option_menu(); | 
|---|
| 563 |  | 
|---|
| 564 | aws->at_newline(); | 
|---|
| 565 | aws->label("Show changed sections of alignment"); | 
|---|
| 566 | aws->create_toggle(GA_AWAR_SHOW_DIFF); | 
|---|
| 567 | aws->label("color bases"); | 
|---|
| 568 | aws->create_toggle(GA_AWAR_COLOR); | 
|---|
| 569 |  | 
|---|
| 570 | aws->at_newline(); | 
|---|
| 571 | aws->label("Show statistics"); | 
|---|
| 572 | aws->create_toggle(GA_AWAR_SHOW_DIST); | 
|---|
| 573 |  | 
|---|
| 574 | aws->get_window_size(winx, winy); | 
|---|
| 575 | aws->get_at_position(&startx, &starty); | 
|---|
| 576 |  | 
|---|
| 577 | aws->button_length(12); | 
|---|
| 578 |  | 
|---|
| 579 | aws->at(winx-closex+5, closey); | 
|---|
| 580 | aws->callback(makeHelpCallback("sina_main.hlp")); | 
|---|
| 581 | aws->create_button("HELP", "HELP"); | 
|---|
| 582 |  | 
|---|
| 583 | aws->at(winx-closex+5, starty); | 
|---|
| 584 | aws->callback(makeWindowCallback(sina_start, alignData)); | 
|---|
| 585 | aws->highlight(); | 
|---|
| 586 | aws->create_button("Start", "Start", "S"); | 
|---|
| 587 |  | 
|---|
| 588 | aws->at(winx-50, starty-50); | 
|---|
| 589 | AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "sina", sina_config_mapping); | 
|---|
| 590 |  | 
|---|
| 591 | return aws; | 
|---|
| 592 | } | 
|---|
| 593 |  | 
|---|
| 594 | void show_sina_window(UNFIXED, const AlignDataAccess *alignData) { | 
|---|
| 595 | AW_root *root = AW_root::SINGLETON; | 
|---|
| 596 |  | 
|---|
| 597 | static AW_window_simple *ga_aws     = new_sina_simple(root, alignData, false); | 
|---|
| 598 | static AW_window_simple *ga_aws_adv = new_sina_simple(root, alignData, true); | 
|---|
| 599 |  | 
|---|
| 600 | if (root->awar(GA_AWAR_ADVANCED)->read_int()) { | 
|---|
| 601 | ga_aws_adv->show(); | 
|---|
| 602 | ga_aws->hide(); | 
|---|
| 603 | } | 
|---|
| 604 | else { | 
|---|
| 605 | ga_aws->show(); | 
|---|
| 606 | ga_aws_adv->hide(); | 
|---|
| 607 | } | 
|---|
| 608 | } | 
|---|
| 609 |  | 
|---|