| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : ali_global.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #include "ali_global.hxx" |
|---|
| 12 | |
|---|
| 13 | #define EXCLUSIVE_FLAG_DEFAULT 1 |
|---|
| 14 | #define MARK_FAMILY_FLAG_DEFAULT 0 |
|---|
| 15 | #define MARK_EXTENSION_FLAG_DEFAULT 0 |
|---|
| 16 | #define FIND_FAMILY_MODE_DEFAULT 1 |
|---|
| 17 | #define MAX_FAMILY_SIZE_DEFAULT 10 |
|---|
| 18 | #define MIN_FAMILY_SIZE_DEFAULT 5 |
|---|
| 19 | #define MIN_WEIGHT_DEFAULT 0.7 |
|---|
| 20 | #define EXT_MAX_WEIGHT_DEFAULT 0.2 |
|---|
| 21 | #define MULTI_GAP_FACTOR_DEFAULT 0.1 |
|---|
| 22 | #define INSERT_FACTOR_DEFAULT 2.0; |
|---|
| 23 | #define MULTI_INSERT_FACTOR_DEFAULT 0.5; |
|---|
| 24 | #define COST_LOW_DEFAULT 0.25 |
|---|
| 25 | #define COST_MIDDLE_DEFAULT 0.5 |
|---|
| 26 | #define COST_HIGH_DEFAULT 0.8 |
|---|
| 27 | #define MAX_COST_OF_SUB_PERCENT_DEFAULT 0.5 |
|---|
| 28 | #define MAX_COST_OF_HELIX 2.0 |
|---|
| 29 | #define ERROR_COUNT_DEFAULT 2 |
|---|
| 30 | #define MAX_NUMBER_OF_MAPS_DEFAULT 10 // 100 |
|---|
| 31 | #define MAX_NUMBER_OF_MAPS_ALIGNER_DEFAULT 2 |
|---|
| 32 | #define INTERVAL_BORDER_DEFAULT 5 |
|---|
| 33 | #define INTERVAL_CENTER_DEFAULT 5 |
|---|
| 34 | |
|---|
| 35 | // ACHTUNG: muss noch durch parameter belegbar sein |
|---|
| 36 | #define MATCHES_MIN_DEFAULT 1000 |
|---|
| 37 | #define PERCENT_MIN_DEFAULT 0.75 |
|---|
| 38 | #define FAM_LIST_MAX_DEFAULT 5 |
|---|
| 39 | #define EXT_LIST_MAX_DEFAULT 10 |
|---|
| 40 | #define USE_SPECIFIED_FAMILY_DEFAULT 0 |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | static double default_substitute_matrix[5][5] = { |
|---|
| 44 | // a c g u - |
|---|
| 45 | { 0.0, 3.0, 1.0, 3.0, 5.0 }, // a |
|---|
| 46 | { 3.0, 0.0, 3.0, 1.0, 5.0 }, // c |
|---|
| 47 | { 1.0, 3.0, 0.0, 3.0, 5.0 }, // g |
|---|
| 48 | { 3.0, 1.0, 3.0, 0.0, 5.0 }, // u |
|---|
| 49 | { 5.0, 5.0, 5.0, 5.0, 0.0 } // - |
|---|
| 50 | }; |
|---|
| 51 | |
|---|
| 52 | static double default_binding_matrix[5][5] = { |
|---|
| 53 | // a c g u - |
|---|
| 54 | { 9.9, 9.9, 2.0, 0.9, 9.9 }, // a |
|---|
| 55 | { 9.9, 9.9, 0.6, 9.9, 9.9 }, // c |
|---|
| 56 | { 2.0, 0.6, 5.0, 1.1, 9.9 }, // g |
|---|
| 57 | { 0.9, 9.9, 1.1, 9.9, 9.9 }, // u |
|---|
| 58 | { 9.9, 9.9, 9.9, 9.9, 0.0 } // - |
|---|
| 59 | }; |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | void ALI_GLOBAL::init(int *argc, const char *argv[]) |
|---|
| 63 | { |
|---|
| 64 | int kill, i, h, j, ret; |
|---|
| 65 | const char *pos; |
|---|
| 66 | arb_params *params; |
|---|
| 67 | float fl; |
|---|
| 68 | |
|---|
| 69 | params = arb_trace_argv(argc, argv); |
|---|
| 70 | |
|---|
| 71 | prog_name = argv[0]; |
|---|
| 72 | species_name = params->species_name; |
|---|
| 73 | default_file = params->default_file; |
|---|
| 74 | db_server = params->db_server; |
|---|
| 75 | |
|---|
| 76 | // Set the defaults |
|---|
| 77 | |
|---|
| 78 | for (i = 0; i < 5; i++) |
|---|
| 79 | for (j = 0; j < 5; j++) { |
|---|
| 80 | prof_context.substitute_matrix[i][j] = default_substitute_matrix[i][j]; |
|---|
| 81 | prof_context.binding_matrix[i][j] = default_binding_matrix[i][j]; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | cost_low = COST_LOW_DEFAULT; |
|---|
| 85 | cost_middle = COST_MIDDLE_DEFAULT; |
|---|
| 86 | cost_high = COST_HIGH_DEFAULT; |
|---|
| 87 | preali_context.max_number_of_maps = MAX_NUMBER_OF_MAPS_DEFAULT; |
|---|
| 88 | preali_context.max_number_of_maps_aligner = |
|---|
| 89 | MAX_NUMBER_OF_MAPS_ALIGNER_DEFAULT; |
|---|
| 90 | preali_context.interval_border = INTERVAL_BORDER_DEFAULT; |
|---|
| 91 | preali_context.interval_center = INTERVAL_CENTER_DEFAULT; |
|---|
| 92 | preali_context.max_cost_of_sub_percent = MAX_COST_OF_SUB_PERCENT_DEFAULT; |
|---|
| 93 | preali_context.max_cost_of_helix = MAX_COST_OF_HELIX; |
|---|
| 94 | preali_context.error_count = ERROR_COUNT_DEFAULT; |
|---|
| 95 | mark_species_flag = 0; |
|---|
| 96 | |
|---|
| 97 | prof_context.find_family_mode = FIND_FAMILY_MODE_DEFAULT; |
|---|
| 98 | prof_context.exclusive_flag = EXCLUSIVE_FLAG_DEFAULT; |
|---|
| 99 | prof_context.mark_family_flag = MARK_FAMILY_FLAG_DEFAULT; |
|---|
| 100 | prof_context.mark_family_extension_flag = MARK_EXTENSION_FLAG_DEFAULT; |
|---|
| 101 | prof_context.max_family_size = MAX_FAMILY_SIZE_DEFAULT; |
|---|
| 102 | prof_context.min_family_size = MIN_FAMILY_SIZE_DEFAULT; |
|---|
| 103 | prof_context.min_weight = MIN_WEIGHT_DEFAULT; |
|---|
| 104 | prof_context.ext_max_weight = EXT_MAX_WEIGHT_DEFAULT; |
|---|
| 105 | prof_context.multi_gap_factor = MULTI_GAP_FACTOR_DEFAULT; |
|---|
| 106 | prof_context.insert_factor = INSERT_FACTOR_DEFAULT; |
|---|
| 107 | prof_context.multi_insert_factor = MULTI_INSERT_FACTOR_DEFAULT; |
|---|
| 108 | |
|---|
| 109 | pt_context.matches_min = MATCHES_MIN_DEFAULT; |
|---|
| 110 | pt_context.percent_min = PERCENT_MIN_DEFAULT; |
|---|
| 111 | pt_context.fam_list_max = FAM_LIST_MAX_DEFAULT; |
|---|
| 112 | pt_context.ext_list_max = EXT_LIST_MAX_DEFAULT; |
|---|
| 113 | pt_context.use_specified_family = USE_SPECIFIED_FAMILY_DEFAULT; |
|---|
| 114 | |
|---|
| 115 | // evaluate the parameters |
|---|
| 116 | |
|---|
| 117 | for (i = 1; i < *argc;) { |
|---|
| 118 | kill = 0; |
|---|
| 119 | if (strcmp("-nx", argv[i]) == 0 && kill == 0) { |
|---|
| 120 | prof_context.exclusive_flag = 0; |
|---|
| 121 | kill = i; |
|---|
| 122 | } |
|---|
| 123 | if (strncmp("-f", argv[i], 2) == 0 && kill == 0) { |
|---|
| 124 | pt_context.use_specified_family = strdup(argv[i] + 2); |
|---|
| 125 | kill = i; |
|---|
| 126 | } |
|---|
| 127 | if (strcmp("-ms", argv[i]) == 0 && kill == 0) { |
|---|
| 128 | mark_species_flag = 1; |
|---|
| 129 | kill = i; |
|---|
| 130 | } |
|---|
| 131 | if (strcmp("-mf", argv[i]) == 0 && kill == 0) { |
|---|
| 132 | prof_context.mark_family_flag = 1; |
|---|
| 133 | kill = i; |
|---|
| 134 | } |
|---|
| 135 | if (strcmp("-mfe", argv[i]) == 0 && kill == 0) { |
|---|
| 136 | prof_context.mark_family_extension_flag = 1; |
|---|
| 137 | kill = i; |
|---|
| 138 | } |
|---|
| 139 | if (strncmp("-mgf", argv[i], 4) == 0 && kill == 0) { |
|---|
| 140 | kill = i; |
|---|
| 141 | pos = argv[i] + 4; |
|---|
| 142 | ret = sscanf(pos, "%f", &prof_context.multi_gap_factor); |
|---|
| 143 | if (ret != 1) { |
|---|
| 144 | ali_warning("Wrong format for -mgf"); |
|---|
| 145 | break; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | if (strncmp("-if", argv[i], 3) == 0 && kill == 0) { |
|---|
| 149 | kill = i; |
|---|
| 150 | pos = argv[i] + 3; |
|---|
| 151 | ret = sscanf(pos, "%f", &prof_context.insert_factor); |
|---|
| 152 | if (ret != 1) { |
|---|
| 153 | ali_warning("Wrong format for -if"); |
|---|
| 154 | break; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | if (strncmp("-mif", argv[i], 4) == 0 && kill == 0) { |
|---|
| 158 | kill = i; |
|---|
| 159 | pos = argv[i] + 4; |
|---|
| 160 | ret = sscanf(pos, "%f", &prof_context.multi_insert_factor); |
|---|
| 161 | if (ret != 1) { |
|---|
| 162 | ali_warning("Wrong format for -mif"); |
|---|
| 163 | break; |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | if (strcmp("-m", argv[i]) == 0 && kill == 0) { |
|---|
| 167 | mark_species_flag = 1; |
|---|
| 168 | prof_context.mark_family_flag = 1; |
|---|
| 169 | kill = i; |
|---|
| 170 | } |
|---|
| 171 | if (strncmp("-msub", argv[i], 5) == 0 && kill == 0) { |
|---|
| 172 | kill = i; |
|---|
| 173 | pos = argv[i] + 5; |
|---|
| 174 | for (h = 0; h < 5; h++) |
|---|
| 175 | for (j = 0; j < 5; j++) { |
|---|
| 176 | ret = sscanf(pos, "%f", &fl); |
|---|
| 177 | if (ret != 1) { |
|---|
| 178 | ali_warning("wrong format for -msub"); |
|---|
| 179 | break; |
|---|
| 180 | } |
|---|
| 181 | else |
|---|
| 182 | prof_context.substitute_matrix[h][j] = (double) fl; |
|---|
| 183 | pos = strchr(pos, ','); |
|---|
| 184 | if ((h != 4 || j != 4) && pos == 0) { |
|---|
| 185 | ali_warning("Not enought values for -msub"); |
|---|
| 186 | break; |
|---|
| 187 | } |
|---|
| 188 | pos++; |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | if (strncmp("-mbind", argv[i], 6) == 0 && kill == 0) { |
|---|
| 192 | kill = i; |
|---|
| 193 | pos = argv[i] + 6; |
|---|
| 194 | for (h = 0; h < 5; h++) |
|---|
| 195 | for (j = 0; j < 5; j++) { |
|---|
| 196 | ret = sscanf(pos, "%f", &fl); |
|---|
| 197 | if (ret != 1) { |
|---|
| 198 | ali_warning("Wrong format for -mbind"); |
|---|
| 199 | break; |
|---|
| 200 | } |
|---|
| 201 | else |
|---|
| 202 | prof_context.binding_matrix[h][j] = (double) fl; |
|---|
| 203 | pos = strchr(pos, ','); |
|---|
| 204 | if ((h != 4 || j != 4) && pos == 0) { |
|---|
| 205 | ali_warning("Not enought values for -mbind"); |
|---|
| 206 | break; |
|---|
| 207 | } |
|---|
| 208 | pos++; |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | if (strncmp("-maxf", argv[i], 5) == 0 && kill == 0) { |
|---|
| 212 | kill = i; |
|---|
| 213 | pos = argv[i] + 5; |
|---|
| 214 | ret = sscanf(pos, "%d", &prof_context.max_family_size); |
|---|
| 215 | if (ret != 1) { |
|---|
| 216 | ali_warning("Wrong format for -maxf"); |
|---|
| 217 | break; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | if (strncmp("-minf", argv[i], 5) == 0 && kill == 0) { |
|---|
| 221 | kill = i; |
|---|
| 222 | pos = argv[i] + 5; |
|---|
| 223 | ret = sscanf(pos, "%d", &prof_context.min_family_size); |
|---|
| 224 | if (ret != 1) { |
|---|
| 225 | ali_warning("Wrong format for -minf"); |
|---|
| 226 | break; |
|---|
| 227 | } |
|---|
| 228 | } |
|---|
| 229 | if (strncmp("-minw", argv[i], 5) == 0 && kill == 0) { |
|---|
| 230 | kill = i; |
|---|
| 231 | pos = argv[i] + 5; |
|---|
| 232 | ret = sscanf(pos, "%f", &prof_context.min_weight); |
|---|
| 233 | if (ret != 1) { |
|---|
| 234 | ali_warning("Wrong format for -minw"); |
|---|
| 235 | break; |
|---|
| 236 | } |
|---|
| 237 | } |
|---|
| 238 | if (strncmp("-maxew", argv[i], 6) == 0 && kill == 0) { |
|---|
| 239 | kill = i; |
|---|
| 240 | pos = argv[i] + 6; |
|---|
| 241 | ret = sscanf(pos, "%f", &prof_context.ext_max_weight); |
|---|
| 242 | if (ret != 1) { |
|---|
| 243 | ali_warning("Wrong format for -minw"); |
|---|
| 244 | break; |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | // ACHTUNG: Unused BEGIN |
|---|
| 249 | if (strncmp("-cl", argv[i], 3) == 0 && kill == 0) { |
|---|
| 250 | kill = i; |
|---|
| 251 | pos = argv[i] + 3; |
|---|
| 252 | ret = sscanf(pos, "%f", &cost_low); |
|---|
| 253 | if (ret != 1) { |
|---|
| 254 | ali_warning("Wrong format for -cl"); |
|---|
| 255 | break; |
|---|
| 256 | } |
|---|
| 257 | } |
|---|
| 258 | if (strncmp("-cm", argv[i], 3) == 0 && kill == 0) { |
|---|
| 259 | kill = i; |
|---|
| 260 | pos = argv[i] + 3; |
|---|
| 261 | ret = sscanf(pos, "%f", &cost_middle); |
|---|
| 262 | if (ret != 1) { |
|---|
| 263 | ali_warning("Wrong format for -cm"); |
|---|
| 264 | break; |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | if (strncmp("-ch", argv[i], 3) == 0 && kill == 0) { |
|---|
| 268 | kill = i; |
|---|
| 269 | pos = argv[i] + 3; |
|---|
| 270 | ret = sscanf(pos, "%f", &cost_high); |
|---|
| 271 | if (ret != 1) { |
|---|
| 272 | ali_warning("Wrong format for -ch"); |
|---|
| 273 | break; |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | // ACHTUNG: Unused END |
|---|
| 277 | |
|---|
| 278 | if (strncmp("-csub", argv[i], 5) == 0 && kill == 0) { |
|---|
| 279 | kill = i; |
|---|
| 280 | pos = argv[i] + 5; |
|---|
| 281 | ret = sscanf(pos, "%f", &preali_context.max_cost_of_sub_percent); |
|---|
| 282 | if (ret != 1) { |
|---|
| 283 | ali_warning("Wrong format for -csub"); |
|---|
| 284 | break; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | if (strncmp("-chel", argv[i], 5) == 0 && kill == 0) { |
|---|
| 288 | kill = i; |
|---|
| 289 | pos = argv[i] + 5; |
|---|
| 290 | ret = sscanf(pos, "%f", &preali_context.max_cost_of_helix); |
|---|
| 291 | if (ret != 1) { |
|---|
| 292 | ali_warning("Wrong format for -chel"); |
|---|
| 293 | break; |
|---|
| 294 | } |
|---|
| 295 | } |
|---|
| 296 | if (strncmp("-mma", argv[i], 4) == 0 && kill == 0) { |
|---|
| 297 | kill = i; |
|---|
| 298 | pos = argv[i] + 4; |
|---|
| 299 | ret = sscanf(pos, "%ld", &preali_context.max_number_of_maps_aligner); |
|---|
| 300 | if (ret != 1) { |
|---|
| 301 | ali_warning("Wrong format for -mma"); |
|---|
| 302 | break; |
|---|
| 303 | } |
|---|
| 304 | } |
|---|
| 305 | if (strncmp("-mm", argv[i], 3) == 0 && kill == 0) { |
|---|
| 306 | kill = i; |
|---|
| 307 | pos = argv[i] + 3; |
|---|
| 308 | ret = sscanf(pos, "%ld", &preali_context.max_number_of_maps); |
|---|
| 309 | if (ret != 1) { |
|---|
| 310 | ali_warning("Wrong format for -mm"); |
|---|
| 311 | break; |
|---|
| 312 | } |
|---|
| 313 | } |
|---|
| 314 | if (strncmp("-ec", argv[i], 3) == 0 && kill == 0) { |
|---|
| 315 | kill = i; |
|---|
| 316 | pos = argv[i] + 3; |
|---|
| 317 | ret = sscanf(pos, "%ld", &preali_context.error_count); |
|---|
| 318 | if (ret != 1) { |
|---|
| 319 | ali_warning("Wrong format for -ec"); |
|---|
| 320 | break; |
|---|
| 321 | } |
|---|
| 322 | } |
|---|
| 323 | if (strncmp("-ib", argv[i], 3) == 0 && kill == 0) { |
|---|
| 324 | kill = i; |
|---|
| 325 | pos = argv[i] + 3; |
|---|
| 326 | ret = sscanf(pos, "%d", &preali_context.interval_border); |
|---|
| 327 | if (ret != 1) { |
|---|
| 328 | ali_warning("Wrong format for -ib"); |
|---|
| 329 | break; |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | if (strncmp("-ic", argv[i], 3) == 0 && kill == 0) { |
|---|
| 333 | kill = i; |
|---|
| 334 | pos = argv[i] + 3; |
|---|
| 335 | ret = sscanf(pos, "%d", &preali_context.interval_center); |
|---|
| 336 | if (ret != 1) { |
|---|
| 337 | ali_warning("Wrong format for -ic"); |
|---|
| 338 | break; |
|---|
| 339 | } |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | if (kill > 0) { |
|---|
| 343 | for (i++; i < *argc; i++) |
|---|
| 344 | argv[i-1] = argv[i]; |
|---|
| 345 | (*argc)--; |
|---|
| 346 | i = kill; |
|---|
| 347 | } |
|---|
| 348 | else |
|---|
| 349 | i++; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | // Check for consistency |
|---|
| 353 | |
|---|
| 354 | if (prof_context.min_family_size > prof_context.max_family_size) { |
|---|
| 355 | ali_warning("minf <= maxf"); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | if (prof_context.ext_max_weight < 0 || prof_context.ext_max_weight > 1.0) { |
|---|
| 359 | ali_warning("0 <= maxew <= 1.0"); |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | if (prof_context.min_weight < 0 || prof_context.min_weight > 1.0) { |
|---|
| 363 | ali_warning("0 <= minw <= 1.0"); |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | if (cost_low > cost_middle || cost_middle > cost_high || |
|---|
| 367 | cost_low < 0 || cost_high > 1.0) { |
|---|
| 368 | ali_warning("0 <= cl <= cm <= ch <= 1.0"); |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | // Open Database and Pt server |
|---|
| 372 | |
|---|
| 373 | ali_message("Connecting to Database server"); |
|---|
| 374 | if (arbdb.open(db_server) != 0) { |
|---|
| 375 | ali_error("Can't connect to Database server"); |
|---|
| 376 | } |
|---|
| 377 | ali_message("Connection established"); |
|---|
| 378 | prof_context.arbdb = &arbdb; |
|---|
| 379 | |
|---|
| 380 | pt_context.servername = params->pt_server; |
|---|
| 381 | pt_context.gb_main = arbdb.gb_main; |
|---|
| 382 | |
|---|
| 383 | pt = new ALI_PT(&pt_context); |
|---|
| 384 | |
|---|
| 385 | prof_context.pt = pt; |
|---|
| 386 | } |
|---|