1 /*
2 
3 PhyML:  a program that  computes maximum likelihood phylogenies from
4 DNA or AA homologous sequences.
5 
6 Copyright (C) Stephane Guindon. Oct 2003 onward.
7 
8 All parts of the source except where indicated are distributed under
9 the GNU public licence. See http://www.opensource.org for details.
10 
11 */
12 
13 #include "cl.h"
14 
15 
16 /*********************************************************/
17 /**
18 * Fill the Option fields, with the argc array
19 */
Read_Command_Line(option * io,int argc,char ** argv)20 int Read_Command_Line(option *io, int argc, char **argv)
21 {
22   int c;
23   int idx;
24   int i;
25   int writemode;
26 
27   writemode = WRITE;
28 
29   if(argc == 1) Exit("\n. No argument was passed to the program. Please check the documentation. \n");
30   PhyML_Printf("",writemode);
31 
32   struct option longopts[] =
33     {
34       {"n_rgrft",           required_argument,NULL,0},
35       {"n_globl",           required_argument,NULL,1},
36       {"max_dist",          required_argument,NULL,2},
37       {"n_optim",           required_argument,NULL,3},
38       {"n_best",            required_argument,NULL,4},
39       {"model",             required_argument,NULL,5},
40       {"search",            required_argument,NULL,6},
41       {"datatype",          required_argument,NULL,7},
42       {"multiple",          required_argument,NULL,8},
43       {"input",             required_argument,NULL,9},
44       {"bootstrap",         required_argument,NULL,10},
45       {"ts/tv",             required_argument,NULL,11},
46       {"nclasses",          required_argument,NULL,12},
47       {"pinv",              required_argument,NULL,13},
48       {"alpha",             required_argument,NULL,14},
49       {"inputtree",         required_argument,NULL,15},
50       {"min_diff_lk_local", required_argument,NULL,16},
51       {"min_diff_lk_global",required_argument,NULL,17},
52       {"steph_spr",         no_argument,NULL,18},
53       {"brent_it_max",      required_argument,NULL,19},
54       {"rand_start",        no_argument,NULL,20},
55       {"n_rand_starts",     required_argument,NULL,21},
56       {"sequential",        no_argument,NULL,22},
57       {"inside_opt",        no_argument,NULL,23},
58       {"p_moves",           required_argument,NULL,24},
59       {"fast_nni",          no_argument,NULL,25},
60       {"g_pars",            no_argument,NULL,26},
61       {"r_seed",            required_argument,NULL,27},
62       {"collapse_boot",     required_argument,NULL,28},
63       {"random_boot",       required_argument,NULL,29},
64       {"print_trace",       no_argument,NULL,30},
65       {"print_site_lnl",    no_argument,NULL,31},
66       {"print_site_lk",    no_argument,NULL,31},
67       {"cov",               no_argument,NULL,32},
68       {"cov_delta",         required_argument,NULL,33},
69       {"cov_alpha",         required_argument,NULL,34},
70       {"cov_ncats",         required_argument,NULL,35},
71       {"ps",                no_argument,NULL,36},
72       {"cov_free",          no_argument,NULL,37},
73       {"no_gap",            no_argument,NULL,38},
74       {"n_rr_branch",       required_argument,NULL,39},
75       {"append",            no_argument,NULL,40},
76       {"no_five_branch",    no_argument,NULL,41},
77       {"pars_thresh",       required_argument,NULL,42},
78       {"min_diff_lk_move",  required_argument,NULL,43},
79       {"hybrid",            no_argument,NULL,44},
80       {"use_median",        no_argument,NULL,45},
81       {"run_id",            required_argument,NULL,46},
82       {"pars",              no_argument,NULL,47},
83       {"quiet",             no_argument,NULL,48},
84       {"version",           no_argument,NULL,49},
85       {"calibration_file",    required_argument,NULL,50},
86       {"calibration",         required_argument,NULL,50},
87       {"clade_file",          required_argument,NULL,50},
88       {"boot_progress_every", required_argument,NULL,51},
89       {"aa_rate_file",        required_argument,NULL,52},
90       {"chain_len",           required_argument,NULL,53},
91       {"sample_freq",         required_argument,NULL,54},
92       {"burnin",              required_argument,NULL,55},
93       {"no_memory_check",     no_argument,NULL,56},
94       {"no_colalias",         no_argument,NULL,57},
95       {"alias_subpatt",       no_argument,NULL,58},
96       {"no_sequences",        no_argument,NULL,59},
97       {"prior",               no_argument,NULL,59},
98       {"fastlk",              no_argument,NULL,60},
99       {"free_rates",          no_argument,NULL,61},
100       {"freerates",           no_argument,NULL,61},
101       {"freerate",            no_argument,NULL,61},
102       {"free_rate",            no_argument,NULL,61},
103       {"is",                  no_argument,NULL,62},
104       // no 63 since it corresponds to character '?'
105       {"rate_model",          required_argument,NULL,64},
106       {"ratemodel",           required_argument,NULL,64},
107       {"log_l",               no_argument,NULL,65},
108       {"gamma_lens",          no_argument,NULL,66},
109       {"il",                  no_argument,NULL,66},
110       {"codpos",              required_argument,NULL,67},
111       {"constraint_file",     required_argument,NULL,68},
112       {"constraint_tree",     required_argument,NULL,68},
113       {"help",                no_argument,NULL,69},
114       {"mutmap",              no_argument,NULL,70},
115       {"parvals",             required_argument,NULL,71},
116       {"constrained_lens",    no_argument,NULL,72},
117       {"xml",                 required_argument,NULL,73},
118       {"l_var",               required_argument,NULL,74},
119 #ifdef BEAGLE
120       {"beagle_resource",     required_argument,NULL,75},
121 #endif
122       {"ancestral",           no_argument,NULL,76},
123       {"anc",                 no_argument,NULL,76},
124       {"coord_file",          required_argument,NULL,77},
125       {"json_trace",          no_argument,NULL,78},
126       {"weights",             required_argument,NULL,79},
127       {"tbe",                 no_argument,NULL,80},
128       {"leave_duplicates",    no_argument,NULL,81},
129       {"precision",           required_argument,NULL,82},
130       {"l_min",               required_argument,NULL,83},
131       {0,0,0,0}
132     };
133 
134   io->datatype = UNDEFINED;
135 
136   #ifndef PHYML
137   int open_ps_file = 0;
138   #endif
139 
140   idx=-1;
141 
142     do
143     {
144       c = getopt_long(argc,argv,"qi:d:m:b:n:t:f:zk:v:c:a:u:ho:s:x:g:l:ep",longopts,&idx);
145 
146       switch(c)
147 	{
148         case 83 :
149           {
150             io->mod->l_min = String_To_Dbl(optarg);
151             break;
152           }
153 	case 82 :
154 	  {
155 	    if ((!atoi(optarg)) || (atoi(optarg) < 1) || (atoi(optarg) > DECIMAL_DIG -3))
156 	      {
157 		    PhyML_Printf("\n. The number of digits must be [1 - %d]\n", DECIMAL_DIG -3);
158 		    Exit("\n");
159 	      }
160 	    else
161 	      {
162 		io->precision = atoi(optarg);
163 	      }
164 	    break;
165 	  }
166 	case 81 :
167 	  {
168 	    io->leave_duplicates = YES;
169 	    break;
170 	  }
171 	case 80 :
172 	  {
173 	    io->do_tbe = YES;
174 	    io->do_boot = NO;
175             io->do_alrt = NO;
176 	    break;
177 	  }
178         case 79:
179           {
180             io->has_io_weights = YES;
181             strcpy(io->weight_file, optarg);
182             break;
183           }
184         case 78:
185           {
186 	    io->print_json_trace = YES;
187 	    break;
188           }
189 
190         case 77:
191           {
192 	    char *tmp;
193 	    tmp = (char *)mCalloc(T_MAX_FILE, sizeof(char));
194 
195 	    if(strlen(optarg) > T_MAX_FILE -11)
196 	      {
197 		char choix;
198 		strcpy (tmp, "\n. The file name'");
199 		strcat (tmp, optarg);
200 		strcat (tmp, "' is too long.\n");
201 		PhyML_Printf("%s",tmp);
202 		PhyML_Printf("\n. Type any key to exit.\n");
203 		if(!scanf("%c",&choix)) Exit("\n");
204 		Exit("\n");
205 	      }
206 	    else if (!Filexists (optarg))
207 	      {
208 		char choix;
209 		strcpy (tmp, "\n. The file '");
210 		strcat (tmp, optarg);
211 		strcat (tmp, "' doesn't exist.\n");
212 		PhyML_Printf("%s",tmp);
213 		PhyML_Printf("\n. Type any key to exit.\n");
214 		if(!scanf("%c",&choix)) Exit("\n");
215 		Exit("\n");
216 	      }
217 	    else
218 	      {
219                 strcpy(io->in_coord_file, optarg);
220                 io->fp_in_coord = Openfile(io->in_coord_file,READ);
221 	      }
222 	    Free(tmp);
223             break;
224           }
225 
226 	case 76:
227           {
228             io->ancestral = YES;
229             break;
230           }
231 #ifdef BEAGLE
232 	case 75:
233           {
234             io->beagle_resource = (int)atoi(optarg);
235             break;
236           }
237 #endif
238 	case 74:
239           {
240             io->mod->l_var_sigma = String_To_Dbl(optarg);
241             break;
242           }
243 	case 73:
244 	  {
245 #ifdef INVITEE
246 
247             Free_Optimiz(io->mod->s_opt);
248             Free_Model_Basic(io->mod);
249             Free_Input(io);
250             PhyTime_XML(optarg);
251             return 0;
252 
253 #elif defined(PHYML)
254 
255             Free_Optimiz(io->mod->s_opt);
256             Free_Model_Basic(io->mod);
257             Free_Input(io);
258             io = PhyML_XML(optarg);
259             Free(io);
260             return 0;
261 
262 #elif defined(PHYTIME)
263 
264             Free_Optimiz(io->mod->s_opt);
265             Free_Model_Basic(io->mod);
266             Free_Input(io);
267             DATE_XML(optarg);
268             return 0;
269 
270 #elif defined(PHYREX)
271 
272             Free_Optimiz(io->mod->s_opt);
273             Free_Model_Basic(io->mod);
274             Free_Input(io);
275             PHYREX_XML(optarg);
276             return 0;
277 
278 #endif
279             break;
280 	  }
281 	case 72:
282 	  {
283 	    io->mod->s_opt->constrained_br_len = YES;
284 	    break;
285 	  }
286 	case 71:
287 	  {
288 	    io->mcmc->in_fp_par = fopen(optarg,"r");
289 	    io->mcmc->randomize = NO;
290 	    break;
291 	  }
292 	case 70:
293 	  {
294 	    io->mutmap = YES;
295 	    break;
296 	  }
297 	case 68:
298 	  {
299 	    char *tmp;
300 	    tmp = (char *)mCalloc(T_MAX_FILE, sizeof(char));
301 
302 	    if(strlen(optarg) > T_MAX_FILE -11)
303 	      {
304 		char choix;
305 		strcpy (tmp, "\n. The file name'");
306 		strcat (tmp, optarg);
307 		strcat (tmp, "' is too long.\n");
308 		PhyML_Printf("%s",tmp);
309 		PhyML_Printf("\n. Type any key to exit.\n");
310 		if(!scanf("%c",&choix)) Exit("\n");
311 		Exit("\n");
312 	      }
313 	    else if (!Filexists (optarg))
314 	      {
315 		char choix;
316 		strcpy (tmp, "\n. The file '");
317 		strcat (tmp, optarg);
318 		strcat (tmp, "' doesn't exist.\n");
319 		PhyML_Printf("%s",tmp);
320 		PhyML_Printf("\n. Type any key to exit.\n");
321 		if(!scanf("%c",&choix)) Exit("\n");
322 		Exit("\n");
323 	      }
324 	    else
325 	      {
326 		strcpy(io->in_constraint_tree_file, optarg);
327 		io->fp_in_constraint_tree = Openfile(io->in_constraint_tree_file,0);
328 	      }
329 	    Free(tmp);
330 	    break;
331 	  }
332 	case 67:
333 	  {
334 	    phydbl pos;
335 	    pos = atof(optarg);
336 	    io->codpos = (int)pos;
337 	    if(io->codpos < 1 || io->codpos > 3)
338 	      {
339 		char choix;
340 		PhyML_Printf("\n. Coding position must be set to 1, 2 or 3.\n");
341 		PhyML_Printf("\n. Type any key to exit.\n");
342 		if(!scanf("%c",&choix)) Exit("\n");
343 		Exit("\n");
344 	      }
345 	    break;
346 
347 	    break;
348 	  }
349 	case 66:
350 	  {
351 	    io->mod->gamma_mgf_bl = YES;
352 	    io->mod->s_opt->opt_gamma_br_len = YES;
353 	    break;
354 	  }
355 	case 65:
356 	  {
357 	    io->mod->log_l = YES;
358 	    break;
359 	  }
360 	case 64:
361 	  {
362 	    char *s;
363 	    int i;
364 	    s = (char *)mCalloc(T_MAX_NAME,sizeof(char));
365 	    i = 0;
366 	    while(optarg[i++]) s[i]=tolower(optarg[i]);
367 	    if(!strcmp(optarg,"gbd")) io->rates->model               = THORNE;
368 	    else if(!strcmp(optarg,"geom")) io->rates->model         = GUINDON;
369 	    else if(!strcmp(optarg,"lognorm")) io->rates->model      = LOGNORMAL;
370 	    else if(!strcmp(optarg,"clock")) io->rates->model        = STRICTCLOCK;
371 	    else if(!strcmp(optarg,"strictclock")) io->rates->model  = STRICTCLOCK;
372 	    else if(!strcmp(optarg,"strict_clock")) io->rates->model = STRICTCLOCK;
373 	    else
374 	      {
375 		PhyML_Printf("\n. rate_model should be 'gbs', 'gbd', 'gamma' or 'clock'.");
376 		Exit("\n");
377 	      }
378 	    Free(s);
379 	    break;
380 	  }
381 
382 
383 	case 62:
384 	  {
385 	    io->mcmc->is = YES;
386 	    break;
387 	  }
388 	case 61:
389 	  {
390 	    io->mod->ras->free_mixt_rates            = YES;
391 	    io->mod->s_opt->opt_free_mixt_rates = YES;
392 	    break;
393 	  }
394 	case 60:
395 	  {
396 	    io->lk_approx = NORMAL;
397 	    break;
398 	  }
399 	case 59:
400 	  {
401 	    break;
402 	  }
403 	case 58:
404 	  {
405 	    io->do_alias_subpatt = YES;
406 	    break;
407 	  }
408 	case 57:
409 	  {
410 	    io->colalias = NO;
411 	    break;
412 	  }
413 	case 56:
414 	  {
415 	    io->mem_question = NO;
416 	    break;
417 	  }
418 	case 55:
419 	  {
420 	    phydbl len;
421 	    len = atof(optarg);
422 	    io->mcmc->chain_len_burnin = (int)len;
423 	    if(io->mcmc->chain_len_burnin < 1)
424 	      {
425 		char choix;
426 		PhyML_Printf("\n. chain_len_burnin must be an integer greater than 0.\n");
427 		PhyML_Printf("\n. Type any key to exit.\n");
428 		if(!scanf("%c",&choix)) Exit("\n");
429 		Exit("\n");
430 	      }
431 	    break;
432 	  }
433 	case 54:
434 	  {
435 	    phydbl len;
436 	    len = atof(optarg);
437 	    io->mcmc->sample_interval = (int)len;
438 	    if(io->mcmc->sample_interval < 1)
439 	      {
440 		char choix;
441 		PhyML_Printf("\n. sample_interval must be an integer greater than 0.\n");
442 		PhyML_Printf("\n. Type any key to exit.\n");
443 		if(!scanf("%c",&choix)) Exit("\n");
444 		Exit("\n");
445 	      }
446 	    break;
447 	  }
448 	case 53:
449 	  {
450 	    phydbl len;
451 	    len = atof(optarg);
452 	    io->mcmc->chain_len = (int)len;
453 	    if(io->mcmc->chain_len < 1)
454 	      {
455 		char choix;
456 		PhyML_Printf("\n. chain_len must be an integer greater than 0.\n");
457 		PhyML_Printf("\n. Type any key to exit.\n");
458 		if(!scanf("%c",&choix)) Exit("\n");
459 		Exit("\n");
460 	      }
461 	    break;
462 	  }
463 	case 52:
464 	  {
465 	    char *s;
466 	    s = (char *)mCalloc(T_MAX_FILE, sizeof(char));
467 	    strcpy(s,optarg);
468 	    io->mod->fp_aa_rate_mat = Openfile(s,0);
469 	    strcpy(io->mod->aa_rate_mat_file->s,s);
470 	    Free(s);
471 	    break;
472 	  }
473 	case 51:
474 	  {
475 	    io->boot_prog_every = atoi(optarg);
476 	    if(io->boot_prog_every < 1)
477 	      {
478 		char choix;
479 		PhyML_Printf("\n. boot_progress_every must be an integer greater than 0.\n");
480 		PhyML_Printf("\n. Type any key to exit.\n");
481 		if(!scanf("%c",&choix)) Exit("\n");
482 		Exit("\n");
483 	      }
484 	    break;
485 	  }
486 	case 50:
487 	  {
488 	    strcpy(io->clade_list_file,optarg);
489 	    break;
490 	  }
491 	case 49:
492 	  {
493 	    PhyML_Printf("\n. This is PhyML version %s.\n\n",VERSION);
494 	    Exit("");
495 	    break;
496 	  }
497 	case 48 :
498 	  {
499 	    io->quiet = 1;
500 	    break;
501 	  }
502 	case 'p' : case 47 :
503 	  {
504 	    io->in_tree = 1;
505 	    break;
506 	  }
507 	case 46 :
508 	  {
509             if(strlen(optarg) > 0)
510               {
511                 io->append_run_ID = YES;
512                 strcpy(io->run_id_string,optarg);
513               }
514             break;
515 	  }
516 	case 45 :
517 	  {
518 	    io->mod->ras->gamma_median = 1;
519 	    break;
520 	  }
521 	case 44 :
522 	  {
523 	    io->mod->s_opt->hybrid_thresh = 0;
524 	    break;
525 	  }
526 	case 43 :
527 	  {
528 	    io->mod->s_opt->min_diff_lk_move = atof(optarg);
529 	    if(io->mod->s_opt->min_diff_lk_move < 0)
530 	      {
531 		char choix;
532 		PhyML_Printf("\n. Min_diff_lk_move must be a double greater than 0.\n");
533 		PhyML_Printf("\n. Type any key to exit.\n");
534 		if(!scanf("%c",&choix)) Exit("\n");
535 		Exit("\n");
536 	      }
537 	    break;
538 	  }
539 	case 42 :
540 	  {
541 	    io->mod->s_opt->pars_thresh = (int)atoi(optarg);
542 	    if(io->mod->s_opt->pars_thresh < 0)
543 	      {
544 		PhyML_Printf("\n. The parsimony threshold must be an integer greater than 0.\n");
545 		PhyML_Printf("\n. Type any key to exit.\n");
546 		Exit("\n");
547 	      }
548 	    break;
549 	  }
550 	case 41 :
551 	  {
552 	    io->mod->s_opt->opt_five_branch = 0;
553 	    break;
554 	  }
555 	case 40 :
556 	  {
557 	    writemode = APPEND;
558 	    break;
559 	  }
560 	case 39 :
561 	  {
562 	    break;
563 	  }
564 	case 38 :
565 	  {
566 	    io->rm_ambigu = 1;
567 	    break;
568 	  }
569 	case 37 :
570 	  {
571 	    io->mod->s_opt->opt_cov_free_rates = YES;
572 #ifdef M4
573 	    io->mod->m4mod->use_cov_alpha      = NO;
574 	    io->mod->m4mod->use_cov_free       = YES;
575 #endif
576 	    break;
577 	  }
578 	case 36 :
579 	  {
580 #ifndef PHYML
581             open_ps_file = 1;
582 #endif
583 	    break;
584 	  }
585 	case 35 :
586 	  {
587 #ifdef M4
588 	    io->mod->m4mod->n_h = (int)atoi(optarg);
589 
590 	    if(io->mod->m4mod->n_h < 1)
591 	      {
592 		char choix;
593 		PhyML_Printf("\n. The number of classes must be greater than 0.\n");
594 		PhyML_Printf("\n. Type any key to exit.\n");
595 		if(!scanf("%c",&choix)) Exit("\n");
596 		Exit("\n");
597 	      }
598 #endif
599 	    break;
600 	  }
601 	case 34 :
602 	  {
603 #ifdef M4
604 	    io->mod->m4mod->use_cov_alpha = YES;
605 	    io->mod->m4mod->use_cov_free  = NO;
606 
607 	    if(!strcmp(optarg,"e") || !strcmp(optarg,"E") ||
608 	       !strcmp(optarg,"estimated") || !strcmp(optarg,"ESTIMATED"))
609 	      {
610 		io->mod->s_opt->opt_cov_alpha = YES;
611 		io->mod->m4mod->alpha         = 1.0;
612 	      }
613 	    else
614 	      {
615 		io->mod->m4mod->alpha = (phydbl)atof(optarg);
616 
617 		if(io->mod->m4mod->alpha < 1.E-5)
618 		  {
619 		    char choix;
620 		    PhyML_Printf("\n. The value of alpha must be greater than 1.E-5.\n");
621 		    PhyML_Printf("\n. Type any key to exit.\n");
622 		    if(!scanf("%c",&choix)) Exit("\n");
623 		    Exit("\n");
624 		  }
625 	      }
626 #endif
627 	    break;
628 	  }
629 	case 33 :
630 	  {
631 #ifdef M4
632 	    if(!strcmp(optarg,"e") || !strcmp(optarg,"E") ||
633 	       !strcmp(optarg,"estimated") || !strcmp(optarg,"ESTIMATED"))
634 	      {
635 		io->mod->s_opt->opt_cov_delta = YES;
636 		io->mod->m4mod->delta         = 1.0;
637 	      }
638 	    else
639 	      {
640 		io->mod->m4mod->delta = (phydbl)atof(optarg);
641 
642 		if(atof(optarg) < 1.E-10)
643 		  {
644 		    char choix;
645 		    PhyML_Printf("\n. The value of delta must be larger than 1.E-10.\n");
646 		    PhyML_Printf("\n. Type any key to exit.\n");
647 		    if(!scanf("%c",&choix)) Exit("\n");
648 		    Exit("\n");
649 		  }
650 	      }
651 #endif
652 	    break;
653 	  }
654 	case 32 :
655 	  {
656 	    io->mod->use_m4mod = YES;
657 	    break;
658 	  }
659 	case 31 :
660 	  {
661 	    io->print_site_lnl = YES;
662 	    break;
663 	  }
664 	case 30 :
665 	  {
666 	    io->print_trace = YES;
667 	    break;
668 	  }
669 	case 29 :
670 	  {
671 	    io->random_boot_seq_order = (int)atoi(optarg);
672 	    break;
673 	  }
674 	case 28 :
675 	  {
676 	    io->collapse_boot = (int)atoi(optarg);
677 	    break;
678 	  }
679 	case 27 :
680 	  {
681 	    io->r_seed = (int)atoi(optarg);
682 	    break;
683 	  }
684 	case 26 :
685 	  {
686 	    io->mod->s_opt->general_pars = YES;
687 	    break;
688 	  }
689 	case 25 :
690 	  {
691 	    io->mod->s_opt->fast_nni = YES;
692 	    break;
693 	  }
694 	case 24 :
695 	  {
696 	    io->mod->s_opt->p_moves_to_examine = (phydbl)atof(optarg);
697 	    break;
698 	  }
699 	case 23 :
700 	  {
701 	    io->mod->s_opt->wim_inside_opt = 1;
702 	    break;
703 	  }
704 	case 0 :
705 	  {
706 	    io->mod->s_opt->wim_n_rgrft = atoi(optarg);
707 	    break;
708 	  }
709 	case 1 :
710 	  {
711 	    io->mod->s_opt->wim_n_globl = atoi(optarg);
712 	    break;
713 	  }
714 	case 2 :
715 	  {
716 	    io->mod->s_opt->wim_max_dist = atoi(optarg);
717 	    break;
718 	  }
719 	case 3 :
720 	  {
721 	    io->mod->s_opt->wim_n_optim = atoi(optarg);
722 	    break;
723 	  }
724 	case 4 :
725 	  {
726 	    io->mod->s_opt->wim_n_best = atoi(optarg);
727 	    break;
728 	  }
729 	case 16 :
730 	  {
731 	    io->mod->s_opt->min_diff_lk_local = atof(optarg);
732 	    break;
733 	  }
734 	case 17 :
735 	  {
736 	    io->mod->s_opt->min_diff_lk_global = atof(optarg);
737 	    break;
738 	  }
739 	case 18 :
740 	  {
741 	    io->mod->s_opt->steph_spr = NO;
742 	    io->mod->s_opt->greedy    = YES;
743 	    break;
744 	  }
745 	case 19 :
746 	  {
747 	    io->mod->s_opt->brent_it_max = atoi(optarg);
748 	    break;
749 	  }
750 	case 20 :
751 	  {
752 	    io->mod->s_opt->random_input_tree = YES;
753 	    break;
754 	  }
755 	case 21 :
756 	  {
757 	    io->mod->s_opt->random_input_tree = YES;
758 	    io->mod->s_opt->n_rand_starts = atoi(optarg);
759 	    if(io->mod->s_opt->n_rand_starts < 1) Exit("\n. Number of random starting trees must be > 0.\n\n");
760 	  }
761 	case 's':case 6:
762 	  {
763 	    if((!strcmp(optarg,"spr")) || (!strcmp(optarg,"SPR")))
764 	      {
765 		io->mod->s_opt->topo_search = SPR_MOVE;
766 		io->mod->s_opt->greedy      = (io->mod->s_opt->steph_spr)?(0):(1);
767 	      }
768 	    else if((!strcmp(optarg,"nni")) || (!strcmp(optarg,"NNI")))
769 	      {
770                 PhyML_Printf("\n. The NNI option is deprecated. PhyML now uses a mix of SPRs and NNIs.");
771 		io->mod->s_opt->topo_search         = NNI_MOVE;
772 		io->mod->s_opt->random_input_tree   = 0;
773 	      }
774 	    else if((!strcmp(optarg,"best")) || (!strcmp(optarg,"BEST")))
775 	      {
776                 PhyML_Printf("\n. The BEST option is deprecated. PhyML now uses a mix of SPRs and NNIs.");
777 		io->mod->s_opt->topo_search = BEST_OF_NNI_AND_SPR;
778 		io->mod->s_opt->greedy      = (io->mod->s_opt->steph_spr)?(0):(1);
779 	      }
780 	    break;
781 	  }
782 
783 	case 'd':case 7:
784 	  {
785 	    if(!strcmp(optarg,"nt"))
786 	      {
787 		io->datatype        = NT;
788 		io->mod->ns         = 4;
789 #ifdef M4
790                 io->mod->m4mod->n_o = 4;
791 #endif
792 
793 		if((io->mod->whichmodel == LG)        ||
794 		   (io->mod->whichmodel == WAG)       ||
795 		   (io->mod->whichmodel == DAYHOFF)   ||
796 		   (io->mod->whichmodel == JTT)       ||
797 		   (io->mod->whichmodel == BLOSUM62)  ||
798 		   (io->mod->whichmodel == MTREV)     ||
799 		   (io->mod->whichmodel == RTREV)     ||
800 		   (io->mod->whichmodel == CPREV)     ||
801 		   (io->mod->whichmodel == DCMUT)     ||
802 		   (io->mod->whichmodel == VT)        ||
803 		   (io->mod->whichmodel == MTMAM)     ||
804 		   (io->mod->whichmodel == MTART)     ||
805 		   (io->mod->whichmodel == HIVW)      ||
806 		   (io->mod->whichmodel == HIVB)      ||
807 		   (io->mod->whichmodel == AB)        ||
808 		   (io->mod->whichmodel == CUSTOMAA)
809 		   )
810 		  {
811 		    io->mod->whichmodel = HKY85;
812 		    strcpy(io->mod->modelname->s, "HKY85\0");
813 		  }
814 	      }
815 	    else if (!strcmp(optarg,"aa"))
816 	      {
817 		io->datatype              = AA;
818 		io->mod->s_opt->opt_kappa = NO;
819 		io->mod->ns               = 20;
820 #ifdef M4
821 		io->mod->m4mod->n_o       = 20;
822 #endif
823 
824 		if(
825 		   (io->mod->whichmodel == JC69)   ||
826 		   (io->mod->whichmodel == K80)    ||
827 		   (io->mod->whichmodel == F81)    ||
828 		   (io->mod->whichmodel == HKY85)  ||
829 		   (io->mod->whichmodel == F84)    ||
830 		   (io->mod->whichmodel == TN93)   ||
831 		   (io->mod->whichmodel == GTR)    ||
832 		   (io->mod->whichmodel == CUSTOM)
833 		   )
834 		  {
835 		    io->mod->whichmodel = LG;
836 		    strcpy(io->mod->modelname->s, "LG\0");
837 		  }
838 	      }
839 	    else if ((!strcmp(optarg,"generic")) || (!strcmp(optarg,"gen")))
840 	      {
841 		io->datatype = GENERIC;
842 	      }
843 	    else
844 	      {
845 		char choix;
846 		PhyML_Printf("\n. Unknown argument to -d option: please use `nt' for DNA or `aa' for Amino-Acids\n");
847 		PhyML_Printf("\n. Type any key to exit.\n");
848 		if(!scanf("%c",&choix)) Exit("\n");
849 		Exit("\n");
850 	      }
851 
852 	    break;
853 	  }
854 	case 'm': case 5 :
855 	  {
856 	    if (!isalpha(optarg[0]))
857               {
858                 if(strchr(optarg,',') == NULL)
859                   {
860                     strcpy(io->mod->custom_mod_string->s,optarg);
861                     if (strlen(io->mod->custom_mod_string->s) != 6)
862                       {
863                         Warn_And_Exit("\n. The custom model string should be of length 6.\n");
864                       }
865 
866                     io->datatype              = NT;
867                     io->mod->whichmodel       = CUSTOM;
868                     strcpy(io->mod->modelname->s, "custom");
869                     io->mod->s_opt->opt_kappa = NO;
870                     io->mod->s_opt->opt_rr    = YES;
871                   }
872                 else
873                   {
874                     phydbl v;
875                     int n_rr;
876                     const char *d = ",";
877                     char *tok = strtok(optarg,d);
878 
879                     io->datatype           = NT;
880                     io->mod->ns            = 4;
881                     io->mod->whichmodel    = GTR;
882                     io->mod->s_opt->opt_rr = NO;
883 
884                     io->mod->r_mat = (t_rmat *)Make_Rmat(io->mod->ns);
885                     Init_Rmat(io->mod->r_mat);
886                     Make_Custom_Model(io->mod);
887 
888                     n_rr = 0;
889                     while(tok && n_rr < 6)
890                       {
891                         v = strtod(tok,NULL);
892                         if (v != 0)
893                           {
894                             io->mod->r_mat->rr->v[n_rr] = v;
895                             io->mod->r_mat->rr_val->v[n_rr] = log(v);
896                           }
897                         else
898                           {
899                             PhyML_Printf("\n. Invalid relative rate parameter value: '%s'.\n", tok);
900                             Exit("\n");
901                           }
902                         tok = strtok (NULL,d);
903                         n_rr++;
904                       }
905                     assert(n_rr <= 6);
906                   }
907               }
908             else
909               {
910                 char *s = To_Upper_String(optarg);
911 
912                 if (strcmp(s, "JC69") == 0)
913                   {
914                     io->datatype              = NT;
915                     io->mod->ns               = 4;
916                     io->mod->whichmodel       = JC69;
917                   }
918                 else if(strcmp(s, "K80") == 0)
919                   {
920                     io->datatype              = NT;
921                     io->mod->ns               = 4;
922                     io->mod->whichmodel       = K80;
923                   }
924                 else if(strcmp(s, "F81") == 0)
925                   {
926                     io->datatype              = NT;
927                     io->mod->ns               = 4;
928                     io->mod->whichmodel       = F81;
929                   }
930                 else if (strcmp(s, "HKY85") == 0)
931                   {
932                     io->datatype              = NT;
933                     io->mod->ns               = 4;
934                     io->mod->whichmodel       = HKY85;
935                   }
936                 else if(strcmp(s, "F84") == 0)
937                   {
938                     io->datatype              = NT;
939                     io->mod->ns               = 4;
940                     io->mod->whichmodel       = F84;
941                   }
942                 else if (strcmp(s,"TN93") == 0)
943                   {
944                     io->datatype              = NT;
945                     io->mod->ns               = 4;
946                     io->mod->whichmodel       = TN93;
947                   }
948                 else if(strncmp(s, "GTR", 3) == 0)
949                   {
950                     io->datatype              = NT;
951                     io->mod->ns               = 4;
952                     io->mod->whichmodel       = GTR;
953                     io->mod->s_opt->opt_rr    = YES;
954                   }
955                 else if(strcmp(s, "DAYHOFF") == 0)
956                   {
957                     io->datatype              = AA;
958                     io->mod->ns               = 20;
959                     io->mod->whichmodel       = DAYHOFF;
960                   }
961                 else if(strcmp(s, "JTT") == 0)
962                   {
963                     io->datatype              = AA;
964                     io->mod->ns               = 20;
965                     io->mod->whichmodel       = JTT;
966                   }
967                 else if(strcmp(s, "MTREV") == 0)
968                   {
969                     io->datatype             = AA;
970                     io->mod->ns              = 20;
971                     io->mod->whichmodel      = MTREV;
972                   }
973                 else if(strcmp(s, "LG") == 0)
974                   {
975                     io->datatype              = AA;
976                     io->mod->ns               = 20;
977                     io->mod->whichmodel       = LG;
978                   }
979                 else if(strcmp(s, "WAG") == 0)
980                   {
981                     io->datatype              = AA;
982                     io->mod->ns               = 20;
983                     io->mod->whichmodel       = WAG;
984                   }
985                 else if(strcmp(s, "DCMUT") == 0)
986                   {
987                     io->datatype              = AA;
988                     io->mod->ns               = 20;
989                     io->mod->whichmodel       = DCMUT;
990                   }
991                 else if(strcmp(s, "RTREV") == 0)
992                   {
993                     io->datatype              = AA;
994                     io->mod->ns               = 20;
995                     io->mod->whichmodel       = RTREV;
996                   }
997                 else if(strcmp(s, "CPREV") == 0)
998                   {
999                     io->datatype              = AA;
1000                     io->mod->ns               = 20;
1001                     io->mod->whichmodel       = CPREV;
1002                   }
1003                 else if(strcmp(s, "VT") == 0)
1004                   {
1005                     io->datatype              = AA;
1006                     io->mod->ns               = 20;
1007                     io->mod->whichmodel       = VT;
1008                   }
1009                 else if(strcmp(s, "BLOSUM62") == 0)
1010                   {
1011                     io->datatype              = AA;
1012                     io->mod->ns               = 20;
1013                     io->mod->whichmodel       = BLOSUM62;
1014                   }
1015                 else if(strcmp(s, "MTMAM") == 0)
1016                   {
1017                     io->datatype              = AA;
1018                     io->mod->ns               = 20;
1019                     io->mod->whichmodel       = MTMAM;
1020                   }
1021                 else if (strcmp(s,"MTART") == 0)
1022                   {
1023                     io->datatype              = AA;
1024                     io->mod->ns               = 20;
1025                     io->mod->whichmodel       = MTART;
1026                   }
1027                 else if (strcmp(s,"HIVW") == 0)
1028                   {
1029                     io->datatype              = AA;
1030                     io->mod->ns               = 20;
1031                     io->mod->whichmodel       = HIVW;
1032                   }
1033                 else if(strcmp(s, "HIVB") == 0)
1034                   {
1035                     io->datatype              = AA;
1036                     io->mod->ns               = 20;
1037                     io->mod->whichmodel       = HIVB;
1038                   }
1039                 else if(strcmp(s, "AB") == 0)
1040                   {
1041                     io->datatype              = AA;
1042                     io->mod->ns               = 20;
1043                     io->mod->whichmodel       = AB;
1044                   }
1045                 else if (strcmp(s, "CUSTOM") == 0)
1046                   {
1047                     io->datatype              = AA;
1048                     io->mod->ns               = 20;
1049                     io->mod->whichmodel       = CUSTOMAA;
1050                   }
1051                 else if(strcmp(s, "FLU") == 0)
1052                   {
1053                     io->datatype              = AA;
1054                     io->mod->ns               = 20;
1055                     io->mod->whichmodel       = FLU;
1056                   }
1057                 else
1058                   {
1059                     PhyML_Printf("\n. The model name is incorrect. Please see the documentation.\n");
1060                     Exit("\n");
1061                   }
1062                 Free(s);
1063               }
1064 
1065 
1066             Set_Model_Name(io->mod);
1067 
1068 	    break;
1069 	  }
1070 
1071 	case 'a':case 14 :
1072 	  {
1073 	    if ((strcmp (optarg, "e") == 0) ||
1074 		(strcmp (optarg, "E") == 0) ||
1075 		(strcmp (optarg, "estimated") == 0) ||
1076 		(strcmp (optarg, "ESTIMATED") == 0))
1077 	      {
1078 		io->mod->s_opt->opt_alpha = YES;
1079 	      }
1080 	    else if (atof(optarg) < 1.E-10)
1081 	      {
1082 		char choix;
1083 		PhyML_Printf("\n. Alpha must be > 1.E-10.\n");
1084 		PhyML_Printf("\n. Type any key to exit.\n");
1085 		if(!scanf("%c",&choix)) Exit("\n");
1086 		Exit("\n");
1087 	      }
1088 	    else
1089 	      {
1090 		io->mod->ras->alpha->v = (phydbl)atof(optarg);
1091 		io->mod->s_opt->opt_alpha  = NO;
1092 	      }
1093 	    break;
1094 	  }
1095 	case 'b':case 10:
1096 	  {
1097 	    if ((int)String_To_Dbl(optarg) < -5)
1098 	      {
1099 		char choix;
1100 		PhyML_Printf("\n. Branch test value must be a positive integer for bootstrap, or between -1 and -4 for aLRT branch test\n");
1101 		PhyML_Printf("\n. Type any key to exit.\n");
1102 		if(!scanf("%c",&choix)) Exit("\n");
1103 		Exit("\n");
1104 	      }
1105 	    else
1106 	      {
1107 		if((int)String_To_Dbl(optarg) > 0)
1108 		  {
1109                     io->do_alrt           = NO;
1110 		    io->ratio_test        = 0;
1111 		    io->n_boot_replicates = (int)atoi(optarg);
1112 		    io->print_boot_trees  = 1;
1113 
1114 		    if(io->n_data_sets > 1)
1115 		      {
1116 			char choix;
1117 			PhyML_Printf("\n. Bootstrap option is not allowed with multiple data sets\n");
1118 			PhyML_Printf("\n. Type any key to exit.\n");
1119 			if(!scanf("%c",&choix)) Exit("\n");
1120 			Exit("\n");
1121 		      }
1122 		  }
1123 		else if (atoi(optarg)==0)
1124 		  {
1125 		    io->do_alrt    = NO;
1126                     io->do_tbe     = NO;
1127                     io->do_boot    = NO;
1128 		    io->ratio_test = 0;
1129 		  }
1130 		else
1131 		  {
1132                     io->do_alrt = YES;
1133                     io->do_tbe  = NO;
1134                     io->do_boot = NO;
1135 		    io->ratio_test = -(int)atoi(optarg);
1136 		  }
1137 	      }
1138 	    break;
1139 	  }
1140 	case 'c':case 12:
1141 	  {
1142 	    if ((!atoi(optarg)) || (atoi(optarg) < 0))
1143 	      {
1144 		char choix;
1145 		PhyML_Printf("\n. Unknown argument to -c option: the number of rate categories must be a positive integer\n");
1146 		PhyML_Printf("\n. Type any key to exit.\n");
1147 		if(!scanf("%c",&choix)) Exit("\n");
1148 		Exit("\n");
1149 	      }
1150 	    else
1151 	      {
1152 		io->mod->ras->n_catg = atoi(optarg);
1153 		if(io->mod->ras->n_catg < 1)
1154 		  {
1155 		    PhyML_Printf("\n. The number of rate categories must be a positive integer\n");
1156 		    Exit("\n");
1157 		  }
1158 	      }
1159 	    break;
1160 	  }
1161 	case 'f':
1162 	  {
1163 	    if(!strcmp(optarg,"e"))
1164 	      {
1165 	        if(io->datatype == NT)
1166 		  io->mod->s_opt->opt_state_freq = NO;
1167 		else if (io->datatype == AA)
1168 		  io->mod->s_opt->opt_state_freq = YES;
1169 		else
1170 		  {
1171 		    PhyML_Printf("\n. Please define the data type (nt or aa) before setting the -f option\n");
1172 		    Exit("\n");
1173 		  }
1174 	      }
1175 	    else if(!strcmp(optarg,"m"))
1176 	      {
1177 	        if (io->datatype == NT)
1178 		  io->mod->s_opt->opt_state_freq = YES;
1179 		else if (io->datatype == AA)
1180 		  io->mod->s_opt->opt_state_freq = NO;
1181 		else
1182 		  {
1183 		    PhyML_Printf("\n. Please define the data type (nt or aa) before setting the -f option\n");
1184 		    Exit("\n");
1185 		  }
1186 	      }
1187 	    else if(!isalpha(optarg[0]))
1188 	      {
1189 		phydbl sum;
1190 		double val1,val2,val3,val4;
1191 
1192                 io->mod->e_frq = (t_efrq *)Make_Efrq(4);
1193                 Init_Efrq(NULL,io->mod->e_frq);
1194 
1195 		io->mod->s_opt->opt_state_freq  = NO;
1196                 io->mod->e_frq->user_state_freq = YES;
1197 
1198 		sscanf(optarg,"%lf,%lf,%lf,%lf",&val1,&val2,&val3,&val4);
1199 		io->mod->e_frq->user_b_freq->v[0] = (phydbl)val1;
1200 		io->mod->e_frq->user_b_freq->v[1] = (phydbl)val2;
1201 		io->mod->e_frq->user_b_freq->v[2] = (phydbl)val3;
1202 		io->mod->e_frq->user_b_freq->v[3] = (phydbl)val4;
1203 
1204 		sum =
1205 		  (io->mod->e_frq->user_b_freq->v[0] +
1206 		   io->mod->e_frq->user_b_freq->v[1] +
1207 		   io->mod->e_frq->user_b_freq->v[2] +
1208 		   io->mod->e_frq->user_b_freq->v[3]);
1209 
1210 		io->mod->e_frq->user_b_freq->v[0] /= sum;
1211 		io->mod->e_frq->user_b_freq->v[1] /= sum;
1212 		io->mod->e_frq->user_b_freq->v[2] /= sum;
1213 		io->mod->e_frq->user_b_freq->v[3] /= sum;
1214 
1215 
1216 		if(io->mod->e_frq->user_b_freq->v[0] < .0 ||
1217 		   io->mod->e_frq->user_b_freq->v[1] < .0 ||
1218 		   io->mod->e_frq->user_b_freq->v[2] < .0 ||
1219 		   io->mod->e_frq->user_b_freq->v[3] < .0 ||
1220 		   io->mod->e_frq->user_b_freq->v[0] > 1. ||
1221 		   io->mod->e_frq->user_b_freq->v[1] > 1. ||
1222 		   io->mod->e_frq->user_b_freq->v[2] > 1. ||
1223 		   io->mod->e_frq->user_b_freq->v[3] > 1.)
1224 		  {
1225 		    Warn_And_Exit("\n. Invalid base frequencies.\n");
1226 		  }
1227 	      }
1228 	    break;
1229 	  }
1230 
1231 	case 'h':case 69:
1232 	  {
1233 	    Usage();
1234 	    break;
1235 	  }
1236 
1237 	case 'i':case 9:
1238 	  {
1239 	    char *tmp;
1240 	    tmp = (char *) mCalloc (T_MAX_FILE, sizeof(char));
1241 	    if (strlen (optarg) > T_MAX_FILE -16)
1242 	      {
1243 		char choix;
1244 		strcpy (tmp, "\n. The file name'");
1245 		strcat (tmp, optarg);
1246 		strcat (tmp, "' is too long.\n");
1247 		PhyML_Printf("%s",tmp);
1248 		PhyML_Printf("\n. Type any key to exit.\n");
1249 		if(!scanf("%c",&choix)) Exit("\n");
1250 		Exit("\n");
1251 	      }
1252 
1253 	    else if (!Filexists (optarg))
1254 	      {
1255 		char choix;
1256 		strcpy (tmp, "\n. The file '");
1257 		strcat (tmp, optarg);
1258 		strcat (tmp, "' does not exist.\n");
1259 		PhyML_Printf("%s",tmp);
1260 		PhyML_Printf("\n. Type any key to exit.\n");
1261 		if(!scanf("%c",&choix)) Exit("\n");
1262 		Exit("\n");
1263 	      }
1264 	    else
1265 	      {
1266 		strcpy(io->in_align_file, optarg);
1267 		io->fp_in_align = Openfile(io->in_align_file,0);
1268 
1269 		strcpy(io->out_file, optarg);
1270 		strcpy(io->out_tree_file,optarg);
1271 #ifdef PHYML
1272 		strcat(io->out_tree_file,"_phyml_tree");
1273 #elif M4
1274 		strcat(io->out_tree_file,"_m4_tree");
1275 #elif PHYREX
1276 		strcat(io->out_tree_file,"_phyrex_tree");
1277 #endif
1278 
1279 		strcpy(io->out_stats_file,optarg);
1280 #ifdef PHYML
1281 		strcat(io->out_stats_file,"_phyml_stats");
1282 #elif M4
1283 		strcat(io->out_stats_file,"_m4_stats");
1284 #elif PHYREX
1285 		strcat(io->out_stats_file,"_phyrex_stats");
1286 #endif
1287 
1288 
1289 #ifdef PHYREX
1290 		strcpy(io->out_summary_file,optarg);
1291 		strcat(io->out_summary_file,"_phyrex_summary");
1292 #endif
1293 
1294 
1295 	      }
1296 	    Free (tmp);
1297 	    break;
1298 	  }
1299 
1300 	case 't':case 11:
1301 	  {
1302             if ((io->mod->whichmodel != JC69) && (io->mod->whichmodel != F81) && (io->mod->whichmodel != GTR))
1303               {
1304                 if ((strcmp(optarg, "e") == 0) ||
1305                     (strcmp(optarg, "E") == 0) ||
1306                     (strcmp(optarg, "estimated") == 0) ||
1307                     (strcmp(optarg, "ESTIMATED") == 0))
1308                   {
1309                     io->mod->kappa->v = 4.0;
1310                     io->mod->s_opt->opt_kappa = YES;
1311                     if (io->mod->whichmodel == TN93)
1312                       io->mod->s_opt->opt_lambda   = YES;
1313                   }
1314                 else
1315                   {
1316                     io->mod->s_opt->opt_kappa  = NO;
1317                     io->mod->s_opt->opt_lambda = NO;
1318 
1319 
1320                     // Added the 2 TsTv ratios for TN93
1321                     // lambda is the ratio of both TsTv ratios
1322                     // kappa is the mean of both TsTv ratios
1323                     if (io->mod->whichmodel == TN93)
1324                       {
1325                         double TsTvPur, TsTvPyr;
1326                         TsTvPur = TsTvPyr = -1.;
1327                         if(!isalpha(optarg[0]))
1328                           {
1329                             sscanf(optarg,"%lf,%lf",&TsTvPur,&TsTvPyr);
1330                           }
1331                         else
1332                           {
1333                             PhyML_Fprintf(stderr,"\n. The TN93 model requires two Ts/Tv ratios.\n");
1334                             Exit("\n");
1335                           }
1336                         if ( (TsTvPur < .0) || (TsTvPyr < .0) )
1337                           {
1338                             PhyML_Fprintf(stderr,"\n. The Ts/Tv ratio must be a positive number.\n");
1339                             Exit("\n");
1340                           }
1341                         io->mod->lambda->v = (phydbl)(TsTvPur / TsTvPyr);
1342                         io->mod->kappa->v = (phydbl)((TsTvPur + TsTvPyr)/2.);
1343                       }
1344                     else
1345                       {
1346                         // -- End TN93 rates for purines & pyrimidines
1347                         if (atof(optarg) < .0)
1348                           {
1349                             char choix;
1350                             PhyML_Printf("\n. The Ts/Tv ratio must be a positive number\n");
1351                             PhyML_Printf("\n. Type any key to exit.\n");
1352                             if(!scanf("%c",&choix)) Exit("\n");
1353                             Exit("\n");
1354                           }
1355                         else
1356                           {
1357                             io->mod->kappa->v = (phydbl)atof(optarg);
1358                           }
1359                       }
1360                   }
1361 	      }
1362 	    break;
1363 	  }
1364 	case 'n':case 8:
1365 	  {
1366 	    if ((!atoi(optarg)) || (atoi(optarg) < 0))
1367 	      {
1368 		char choix;
1369 		PhyML_Printf("\n. The number of alignments must be a positive integer\n");
1370 		PhyML_Printf("\n. Type any key to exit.\n");
1371 		if(!scanf("%c",&choix)) Exit("\n");
1372 		Exit("\n");
1373 	      }
1374 	    else io->n_data_sets = atoi (optarg);
1375 	    break;
1376 	  }
1377 	case 'q':case 22:
1378 	  {
1379 	    io->interleaved = NO;
1380 	    break;
1381 	  }
1382 	case 'u':case 15:
1383 	  {
1384 	    char *tmp;
1385 	    tmp = (char *)mCalloc(T_MAX_FILE, sizeof(char));
1386 	    if(strlen(optarg) > T_MAX_FILE -11)
1387 	      {
1388 		char choix;
1389 		strcpy (tmp, "\n. The file name'");
1390 		strcat (tmp, optarg);
1391 		strcat (tmp, "' is too long.\n");
1392 		PhyML_Printf("%s",tmp);
1393 		PhyML_Printf("\n. Type any key to exit.\n");
1394 		if(!scanf("%c",&choix)) Exit("\n");
1395 		Exit("\n");
1396 	      }
1397 	    else if (! Filexists (optarg))
1398 	      {
1399 		char choix;
1400 		strcpy (tmp, "\n. The file '");
1401 		strcat (tmp, optarg);
1402 		strcat (tmp, "' doesn't exist.\n");
1403 		PhyML_Printf("%s",tmp);
1404 		PhyML_Printf("\n. Type any key to exit.\n");
1405 		if(!scanf("%c",&choix)) Exit("\n");
1406 		Exit("\n");
1407 	      }
1408 	    else
1409 	      {
1410 		strcpy(io->in_tree_file, optarg);
1411 		io->in_tree = 2;
1412 		io->fp_in_tree = Openfile(io->in_tree_file,READ);
1413 	      }
1414 	    Free(tmp);
1415 	    break;
1416 	  }
1417 
1418 	case 'v':case 13:
1419 	  {
1420 	    if ((strcmp (optarg, "e") == 0) ||
1421 		(strcmp (optarg, "E") == 0) ||
1422 		(strcmp (optarg, "estimated") == 0) ||
1423 		(strcmp (optarg, "ESTIMATED") == 0))
1424 	      {
1425 		io->mod->s_opt->opt_pinvar = YES;
1426 		io->mod->ras->invar        = YES;
1427 	      }
1428 
1429 	    else if ((atof(optarg) < 0.0) || (atof(optarg) > 1.0))
1430 	      {
1431 		char choix;
1432 		PhyML_Printf("\n. The proportion of invariable site must be a number between 0.0 and 1.0\n");
1433 		PhyML_Printf("\n. Type any key to exit.");
1434 		if(!scanf("%c",&choix)) Exit("\n");
1435 		Exit("\n");
1436 	      }
1437 	    else
1438 	      {
1439 		io->mod->ras->pinvar->v = (phydbl)atof(optarg);
1440 		if (io->mod->ras->pinvar->v > 0.0+SMALL)
1441 		  io->mod->ras->invar = 1;
1442 		else
1443 		  io->mod->ras->invar = 0;
1444 		io->mod->s_opt->opt_pinvar = 0;
1445 	      }
1446 	    break;
1447 	  }
1448 	case 'o':
1449 	  {
1450 	    if(!strcmp(optarg,"tlr"))
1451 	      {
1452 		io->mod->s_opt->opt_topo        = YES;
1453 		io->mod->s_opt->opt_bl          = YES;
1454 		io->mod->s_opt->opt_subst_param = YES;
1455 	      }
1456 	    else if(!strcmp(optarg,"tl"))
1457 	      {
1458 		io->mod->s_opt->opt_topo        = YES;
1459 		io->mod->s_opt->opt_bl          = YES;
1460 		io->mod->s_opt->opt_subst_param = NO;
1461 	      }
1462 	    else if(!strcmp(optarg,"t"))
1463 	      {
1464 		Warn_And_Exit("\n. You can't optimize the topology without adjusting branch length too...\n");
1465 	      }
1466 	    else if(!strcmp(optarg,"lr"))
1467 	      {
1468 		io->mod->s_opt->opt_topo        = NO;
1469 		io->mod->s_opt->opt_bl          = YES;
1470 		io->mod->s_opt->opt_subst_param = YES;
1471 	      }
1472 	    else if(!strcmp(optarg,"l"))
1473 	      {
1474 		io->mod->s_opt->opt_topo        = NO;
1475 		io->mod->s_opt->opt_bl          = YES;
1476 		io->mod->s_opt->opt_subst_param = NO;
1477 	      }
1478 	    else if(!strcmp(optarg,"r"))
1479 	      {
1480 		io->mod->s_opt->opt_topo        = NO;
1481 		io->mod->s_opt->opt_bl          = NO;
1482 		io->mod->s_opt->opt_subst_param = YES;
1483 	      }
1484 	    else if(!strcmp(optarg,"none") || !strcmp(optarg,"n"))
1485 	      {
1486 		io->mod->s_opt->opt_topo        = NO;
1487 		io->mod->s_opt->opt_bl          = NO;
1488 		io->mod->s_opt->opt_subst_param = NO;
1489 	      }
1490 	    else
1491 	      {
1492 		char choix;
1493 		PhyML_Printf ("\n. The optimization parameter must be 'tlr' or 'tl' or 'lr' or 'l' or 'r' or 'n'.");
1494 		PhyML_Printf("\n. Type any key to exit.\n");
1495 		if(!scanf("%c",&choix)) Exit("\n");
1496 		Exit("\n");
1497 	      }
1498 	    break;
1499 	  }
1500 
1501 	case '?':
1502 	  {
1503 	    Exit("\n");
1504 	    break;
1505 	  }
1506 
1507 	case -1:
1508 	  {
1509 	    break;
1510 	  }
1511 
1512 	default:
1513 	  {
1514 	    Usage();
1515 	    break;
1516 	  }
1517 	}
1518     }while(c != -1);
1519 
1520 
1521   /*   if((io->mod->whichmodel == K80) || (io->mod->whichmodel == JC69)) */
1522   /*     { */
1523   /*       if(io->mod->s_opt->opt_state_freq) */
1524   /* 	{ */
1525   /* 	  char c; */
1526   /* 	  PhyML_Printf("\n. WARNING: nucleotide frequencies must be set to 1/4 with this model.\n"); */
1527   /* 	  PhyML_Printf("\n. Type the enter key to resume the analysis.\n"); */
1528   /* 	  scanf("%c",&c); */
1529   /* 	} */
1530   /*       io->mod->s_opt->opt_state_freq = 0; */
1531   /*     } */
1532 
1533 
1534   if(io->mod->s_opt->constrained_br_len == YES)
1535     {
1536       io->mod->s_opt->opt_topo = NO;
1537       /* io->mod->s_opt->opt_bl   = NO; */
1538     }
1539 
1540 
1541   if(io->do_tbe == YES)
1542     {
1543       io->do_alrt = NO;
1544       io->do_boot = NO;
1545     }
1546   else
1547     {
1548       if(io->do_alrt == NO && io->n_boot_replicates > 0) io->do_boot = YES;
1549     }
1550 
1551 #ifndef PHYML
1552   if((open_ps_file) || (io->m4_model == YES))
1553     {
1554       strcpy(io->out_ps_file,io->in_align_file);
1555       strcat(io->out_ps_file, "_mc_tree.ps");
1556       io->fp_out_ps = Openfile(io->out_ps_file,WRITE);
1557     }
1558 #endif
1559 
1560 
1561   if(io->datatype == UNDEFINED) io->datatype = NT;
1562 
1563   if ((io->datatype == NT) && (io->mod->whichmodel > 10))
1564     {
1565       char choix;
1566       PhyML_Printf("\n. Err.: model incompatible with the data type. Please use JC69, K80, F81, HKY, F84, TN93 or GTR\n");
1567       PhyML_Printf("\n. Type any key to exit.\n");
1568       if(!scanf("%c",&choix)) Exit("\n");
1569       Warn_And_Exit("\n");
1570     }
1571   else if ((io->datatype == AA) && (io->mod->whichmodel < 11))
1572     {
1573       char choix;
1574       PhyML_Printf("\n. Err.: model incompatible with the data type. Please use LG, Dayhoff, JTT, MtREV, WAG, DCMut, RtREV, CpREV, VT, Blosum62, MtMam, MtArt, HIVw, HIVb or AB.\n");
1575       PhyML_Printf("\n. Type any key to exit.\n");
1576       if(!scanf("%c",&choix)) Exit("\n");
1577       Exit("\n");
1578     }
1579 
1580   if(io->mod->use_m4mod == NO)
1581     {
1582       io->mod->s_opt->opt_cov_delta      = 0;
1583       io->mod->s_opt->opt_cov_alpha      = 0;
1584       io->mod->s_opt->opt_cov_free_rates = 0;
1585     }
1586 
1587   if((io->mod->s_opt->opt_cov_free_rates) && (io->mod->s_opt->opt_cov_alpha))
1588     {
1589       io->mod->s_opt->opt_cov_free_rates = 1;
1590 #ifdef M4
1591       io->mod->m4mod->use_cov_alpha      = 0;
1592       io->mod->m4mod->use_cov_free       = 1;
1593 #endif
1594     }
1595 
1596   if(io->print_site_lnl && io->fp_in_align != NULL)
1597     {
1598       strcpy(io->out_lk_file,io->in_align_file);
1599       strcat(io->out_lk_file, "_phyml_lk");
1600       if(io->append_run_ID) { strcat(io->out_lk_file,"_"); strcat(io->out_lk_file,io->run_id_string); }
1601       strcat(io->out_lk_file, ".txt");
1602       io->fp_out_lk = Openfile(io->out_lk_file,1);
1603     }
1604 
1605   if(io->print_trace && io->fp_in_align != NULL)
1606     {
1607       strcpy(io->out_trace_file,io->in_align_file);
1608       strcat(io->out_trace_file,"_phyml_trace");
1609       if(io->append_run_ID) { strcat(io->out_trace_file,"_"); strcat(io->out_trace_file,io->run_id_string); }
1610       strcat(io->out_trace_file,".txt");
1611       io->fp_out_trace = Openfile(io->out_trace_file,WRITE);
1612     }
1613 
1614   if(io->print_json_trace && io->fp_in_align != NULL)
1615     {
1616       strcpy(io->out_json_trace_file,io->in_align_file);
1617       strcat(io->out_json_trace_file,"_phyml_trace");
1618       if(io->append_run_ID) { strcat(io->out_json_trace_file,"_"); strcat(io->out_json_trace_file,io->run_id_string); }
1619       strcat(io->out_json_trace_file,".json");
1620       io->fp_out_json_trace = Openfile(io->out_json_trace_file,READWRITE);
1621     }
1622 
1623 
1624   if(io->mod->s_opt->random_input_tree && io->fp_in_align != NULL)
1625     {
1626       strcpy(io->out_trees_file,io->in_align_file);
1627       strcat(io->out_trees_file,"_phyml_rand_trees");
1628       if(io->append_run_ID) { strcat(io->out_trees_file,"_"); strcat(io->out_trees_file,io->run_id_string); }
1629       strcat(io->out_trees_file,".txt");
1630       io->fp_out_trees = Openfile(io->out_trees_file,1);
1631     }
1632 
1633   if((io->print_boot_trees) && (io->do_boot == YES) && (io->fp_in_align != NULL))
1634     {
1635       strcpy(io->out_boot_tree_file,io->in_align_file);
1636       strcat(io->out_boot_tree_file,"_phyml_boot_trees");
1637       if(io->append_run_ID) { strcat(io->out_boot_tree_file,"_"); strcat(io->out_boot_tree_file,io->run_id_string); }
1638       strcat(io->out_boot_tree_file,".txt");
1639       io->fp_out_boot_tree = Openfile(io->out_boot_tree_file,1);
1640 
1641       strcpy(io->out_boot_stats_file,io->in_align_file);
1642       strcat(io->out_boot_stats_file,"_phyml_boot_stats");
1643       if(io->append_run_ID) { strcat(io->out_boot_stats_file,"_"); strcat(io->out_boot_stats_file,io->run_id_string); }
1644       strcat(io->out_boot_stats_file,".txt");
1645       io->fp_out_boot_stats = Openfile(io->out_boot_stats_file,1);
1646     }
1647 
1648   if(io->append_run_ID && io->fp_in_align != NULL)
1649     {
1650       strcat(io->out_tree_file,"_");
1651       strcat(io->out_stats_file,"_");
1652       strcat(io->out_tree_file,io->run_id_string);
1653       strcat(io->out_stats_file,io->run_id_string);
1654     }
1655 
1656   if(io->fp_in_align != NULL)
1657     {
1658       strcat(io->out_tree_file,".txt");
1659       strcat(io->out_stats_file,".txt");
1660     }
1661 
1662 
1663 #ifdef PHYREX
1664   strcat(io->out_summary_file,".txt");
1665 #endif
1666 
1667 
1668   if(io->mod->ras->n_catg == 1) io->mod->s_opt->opt_alpha = 0;
1669 
1670   if(io->mod->s_opt->opt_subst_param == NO)
1671     {
1672       io->mod->s_opt->opt_alpha  = NO;
1673       io->mod->s_opt->opt_kappa  = NO;
1674       io->mod->s_opt->opt_lambda = NO;
1675       io->mod->s_opt->opt_pinvar = NO;
1676       io->mod->s_opt->opt_rr     = NO;
1677     }
1678 
1679   if(io->mod->whichmodel != K80 &&
1680      io->mod->whichmodel != HKY85 &&
1681      io->mod->whichmodel != F84 &&
1682      io->mod->whichmodel != TN93)
1683     {
1684       io->mod->s_opt->opt_kappa = NO;
1685     }
1686 
1687   if(io->datatype == AA && io->mod->whichmodel == CUSTOMAA && !io->mod->fp_aa_rate_mat)
1688     {
1689       PhyML_Printf("\n. Custom model option with amino-acid requires you to specify a rate matrix file through the '--aa_rate_file' option.\n");
1690       Exit("\n");
1691     }
1692 
1693 #if !defined(PHYTIME)
1694   // Make sure you don't erase the input file...
1695   if(!strcmp(io->out_tree_file,io->in_align_file) ||
1696      !strcmp(io->out_stats_file,io->in_align_file))
1697     {
1698       PhyML_Fprintf(stderr,"\n. The alignment file '%s' does not seem to exist...",io->in_align_file);
1699       Generic_Exit(__FILE__,__LINE__,__FUNCTION__);
1700     }
1701 
1702   if(io->fp_in_align != NULL)
1703     {
1704       io->fp_out_tree  = Openfile(io->out_tree_file,writemode);
1705       io->fp_out_stats = Openfile(io->out_stats_file,writemode);
1706     }
1707 #endif
1708 
1709 #if defined(PHYREX)
1710   if(io->fp_in_align != NULL) io->fp_out_summary = Openfile(io->out_summary_file,writemode);
1711 #endif
1712 
1713 
1714     if(io->quiet == NO)
1715     {
1716       PhyML_Printf("\n\n. Command line: ");
1717       for(i=0;i<argc;i++) PhyML_Printf("%s ",argv[i]);
1718     }
1719 
1720   return 1;
1721 }
1722 
1723 //////////////////////////////////////////////////////////////
1724 //////////////////////////////////////////////////////////////
1725 
1726