-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathCommandLineParser.cpp
1323 lines (1199 loc) · 53 KB
/
CommandLineParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "CommandLineParser.hpp"
#include "version.h"
#include <getopt.h>
#ifdef _RAXML_PTHREADS
#include <thread>
#endif
using namespace std;
static struct option long_options[] =
{
{"help", no_argument, 0, 0 }, /* 0 */
{"version", no_argument, 0, 0 }, /* 1 */
{"evaluate", no_argument, 0, 0 }, /* 2 */
{"search", no_argument, 0, 0 }, /* 3 */
{"msa", required_argument, 0, 0 }, /* 4 */
{"tree", required_argument, 0, 0 }, /* 5 */
{"prefix", required_argument, 0, 0 }, /* 6 */
{"model", required_argument, 0, 0 }, /* 7 */
{"data-type", required_argument, 0, 0 }, /* 8 */
{"opt-model", required_argument, 0, 0 }, /* 9 */
{"opt-branches", required_argument, 0, 0 }, /* 10 */
{"prob-msa", required_argument, 0, 0 }, /* 11 */
{"pat-comp", required_argument, 0, 0 }, /* 12 */
{"tip-inner", required_argument, 0, 0 }, /* 13 */
{"brlen", required_argument, 0, 0 }, /* 14 */
{"spr-radius", required_argument, 0, 0 }, /* 15 */
{"spr-cutoff", required_argument, 0, 0 }, /* 16 */
{"lh-epsilon", required_argument, 0, 0 }, /* 17 */
{"seed", required_argument, 0, 0 }, /* 18 */
{"threads", required_argument, 0, 0 }, /* 19 */
{"simd", required_argument, 0, 0 }, /* 20 */
{"msa-format", required_argument, 0, 0 }, /* 21 */
{"rate-scalers", required_argument, 0, 0 }, /* 22 */
{"log", required_argument, 0, 0 }, /* 23 */
{"bootstrap", no_argument, 0, 0 }, /* 24 */
{"all", no_argument, 0, 0 }, /* 25 */
{"bs-trees", required_argument, 0, 0 }, /* 26 */
{"redo", no_argument, 0, 0 }, /* 27 */
{"force", optional_argument, 0, 0 }, /* 28 */
{"site-repeats", required_argument, 0, 0 }, /* 29 */
{"support", no_argument, 0, 0 }, /* 30 */
{"terrace", no_argument, 0, 0 }, /* 31 */
{"terrace-maxsize", required_argument, 0, 0 }, /* 32 */
{"check", no_argument, 0, 0 }, /* 33 */
{"parse", no_argument, 0, 0 }, /* 34 */
{"blopt", required_argument, 0, 0 }, /* 35 */
{"blmin", required_argument, 0, 0 }, /* 36 */
{"blmax", required_argument, 0, 0 }, /* 37 */
{"tree-constraint", required_argument, 0, 0 }, /* 38 */
{"nofiles", optional_argument, 0, 0 }, /* 39 */
{"start", no_argument, 0, 0 }, /* 40 */
{"loglh", no_argument, 0, 0 }, /* 41 */
{"precision", required_argument, 0, 0 }, /* 42 */
{"outgroup", required_argument, 0, 0 }, /* 43 */
{"bs-cutoff", required_argument, 0, 0 }, /* 44 */
{"bsconverge", no_argument, 0, 0 }, /* 45 */
{"extra", required_argument, 0, 0 }, /* 46 */
{"bs-metric", required_argument, 0, 0 }, /* 47 */
{"search1", no_argument, 0, 0 }, /* 48 */
{"bsmsa", no_argument, 0, 0 }, /* 49 */
{"rfdist", optional_argument, 0, 0 }, /* 50 */
{"rf", optional_argument, 0, 0 }, /* 51 */
{"consense", optional_argument, 0, 0 }, /* 52 */
{"ancestral", optional_argument, 0, 0 }, /* 53 */
{"workers", required_argument, 0, 0 }, /* 54 */
{"sitelh", no_argument, 0, 0 }, /* 55 */
{"site-weights", required_argument, 0, 0 }, /* 56 */
{"bs-write-msa", no_argument, 0, 0 }, /* 57 */
{"lh-epsilon-triplet", required_argument, 0, 0 }, /* 58 */
{"adaptive", optional_argument, 0, 0 }, /* 59 */
{"diff_pred_trees", required_argument, 0, 0}, /* 60 */
{"nni-tolerance", required_argument, 0, 0 }, /* 61 */
{"nni-epsilon", required_argument, 0, 0 }, /* 62 */
{"pythia", optional_argument, 0, 0 }, /* 63 */
{"pt", optional_argument, 0, 0 }, /* 64 */
{"sh", optional_argument, 0, 0 }, /* 65 */
{"sh-reps", required_argument, 0, 0 }, /* 66 */
{"sh-epsilon", required_argument, 0, 0 }, /* 67 */
{"opt-topology", required_argument, 0, 0 }, /* 68 */
{ 0, 0, 0, 0 }
};
static std::string get_cmdline(int argc, char** argv)
{
ostringstream s;
for (int i = 0; i < argc; ++i)
s << argv[i] << (i < argc-1 ? " " : "");
return s.str();
}
void CommandLineParser::check_options(Options &opts)
{
/* check for mandatory options for each command */
if (opts.command == Command::evaluate || opts.command == Command::search ||
opts.command == Command::bootstrap || opts.command == Command::all ||
opts.command == Command::terrace || opts.command == Command::check ||
opts.command == Command::parse || opts.command == Command::start ||
opts.command == Command::ancestral)
{
if (opts.msa_file.empty())
throw OptionException("You must specify a multiple alignment file with --msa switch");
}
if (opts.command == Command::evaluate || opts.command == Command::support ||
opts.command == Command::terrace || opts.command == Command::rfdist ||
opts.command == Command::sitelh || opts.command == Command::ancestral ||
opts.command == Command::consense)
{
if (opts.tree_file.empty())
throw OptionException("Please provide a valid Newick file as an argument of --tree option.");
}
if (opts.command == Command::start && !opts.tree_file.empty())
{
throw OptionException("You specified a user starting tree) for the starting tree generation "
"command, which does not make any sense!\n"
"Please choose whether you want to generate parsimony or random starting trees!");
}
if (opts.command == Command::support || opts.command == Command::bsconverge)
{
if (opts.outfile_names.bootstrap_trees.empty())
{
throw OptionException("You must specify a Newick file with replicate trees, e.g., "
"--bs-trees bootstrap.nw");
}
}
if (opts.command == Command::support || opts.command == Command::rfdist ||
opts.command == Command::consense)
{
assert(!opts.tree_file.empty());
if (opts.outfile_prefix.empty())
opts.outfile_prefix = opts.tree_file;
}
if (opts.command == Command::bsconverge)
{
assert(!opts.outfile_names.bootstrap_trees.empty());
if (opts.bootstop_criterion == BootstopCriterion::none)
opts.bootstop_criterion = BootstopCriterion::autoMRE;
if (opts.outfile_prefix.empty())
opts.outfile_prefix = opts.outfile_names.bootstrap_trees;
}
if (opts.command == Command::bsmsa)
{
if (!opts.num_bootstraps)
{
throw OptionException("You must specify the desired number of replicate MSAs, e.g., "
"--bs-trees 100");
}
}
if (opts.num_bootstraps > 0 && opts.command != Command::bsmsa &&
opts.command != Command::bootstrap && opts.command != Command::all)
{
throw OptionException("You specified the number of bootstrap replicates with --bs-trees option, "
"but the current command does not perform bootstrapping.\n"
"Did you forget --all option?");
}
if (opts.write_bs_msa && opts.command != Command::bsmsa &&
opts.command != Command::bootstrap && opts.command != Command::all)
{
throw OptionException("You specified to write out boostrap alignments with --bs-write-msa option, "
"but the current command does not perform bootstrapping.\n"
"Did you forget --all option?");
}
if (opts.simd_arch > sysutil_simd_autodetect())
{
if (opts.force_mode)
corax_hardware_ignore();
else
{
throw OptionException("Cannot detect " + opts.simd_arch_name() +
" instruction set on your system. If you are absolutely sure "
"it is supported, please use --force option to disable this check.");
}
}
}
void CommandLineParser::compute_num_searches(Options &opts)
{
if (opts.command == Command::search || opts.command == Command::all ||
opts.command == Command::evaluate || opts.command == Command::start ||
opts.command == Command::ancestral || opts.command == Command::sitelh)
{
assert(!opts.start_trees.empty());
auto def_tree_count = 10;
for (auto& it: opts.start_trees)
{
if (it.first == StartingTree::user)
it.second = 1;
else if (it.first != StartingTree::adaptive)
it.second = it.second > 0 ? it.second : def_tree_count;
}
for (const auto& it: opts.start_trees)
opts.num_searches += it.second;
}
else if (opts.command == Command::parse || opts.command == Command::check)
{
/* ignore random and parsimony starting trees in check/parse mode */
opts.start_trees.clear();
if (!opts.tree_file.empty())
opts.num_searches = opts.start_trees[StartingTree::user] = 1;
}
}
void CommandLineParser::parse_start_trees(Options &opts, const string& arg)
{
auto start_trees = split_string(arg, ',');
for (const auto& st_tree: start_trees)
{
StartingTree st_tree_type;
unsigned int num_searches = 0;
if (st_tree == "rand" || st_tree == "random" ||
sscanf(st_tree.c_str(), "rand{%u}", &num_searches) == 1 ||
sscanf(st_tree.c_str(), "random{%u}", &num_searches) == 1)
{
st_tree_type = StartingTree::random;
}
else if (st_tree == "pars" || st_tree == "parsimony" ||
sscanf(st_tree.c_str(), "pars{%u}", &num_searches) == 1 ||
sscanf(st_tree.c_str(), "parsimony{%u}", &num_searches) == 1)
{
st_tree_type = StartingTree::parsimony;
}
else if (st_tree == "auto" || st_tree == "adaptive")
{
st_tree_type = StartingTree::adaptive;
}
else
{
opts.tree_file += (opts.tree_file.empty() ? "" : ",") + st_tree;
st_tree_type = StartingTree::user;
}
if (!opts.start_trees.count(st_tree_type) || num_searches > 0)
opts.start_trees[st_tree_type] = num_searches;
}
}
void CommandLineParser::parse_options(int argc, char** argv, Options &opts)
{
opts.cmdline = get_cmdline(argc, argv);
/* if no command specified, default to --adaptive (or --help if no args were given) */
opts.command = (argc > 1) ? Command::search : Command::help;
opts.start_trees.clear();
opts.random_seed = (long)time(NULL);
/* compress alignment patterns by default */
opts.use_pattern_compression = true;
/* do not use tip-inner case optimization by default */
opts.use_tip_inner = false;
/* use site repeats */
opts.use_repeats = true;
/* do not use per-rate-category CLV scalers */
opts.use_rate_scalers = false;
/* use probabilistic MSA _if available_ (e.g. CATG file was provided) */
opts.use_prob_msa = true;
/* use RBA partial loading whenever appropriate/possible */
opts.use_rba_partload = true;
/* use new split-based constraint checking method -> slightly slower, but more reliable */
opts.use_old_constraint = false;
/* enable incremental CLV updates across pruned subtrees in SPR rounds */
opts.use_spr_fastclv = true;
/* optimize model and branch lengths */
opts.optimize_model = true;
opts.optimize_brlen = true;
/* initialize LH epsilon with default value */
opts.lh_epsilon = DEF_LH_EPSILON;
opts.lh_epsilon_brlen_triplet = DEF_LH_EPSILON_BRLEN_TRIPLET;
/* default: autodetect best SPR radius */
opts.spr_radius = -1;
opts.spr_cutoff = 1.0;
/* default: nni parameters */
opts.nni_tolerance = 1.0;
opts.nni_epsilon = 10;
/* default: SH parameters */
opts.num_sh_reps = 1000;
opts.sh_epsilon = 0.1;
/* bootstrapping / bootstopping */
opts.bs_metrics.insert(BranchSupportMetric::fbp);
opts.bootstop_criterion = BootstopCriterion::autoMRE;
opts.bootstop_cutoff = RAXML_BOOTSTOP_CUTOFF;
opts.bootstop_interval = RAXML_BOOTSTOP_INTERVAL;
opts.bootstop_permutations = RAXML_BOOTSTOP_PERMUTES;
/* default: linked branch lengths */
opts.brlen_linkage = CORAX_BRLEN_SCALED;
opts.brlen_min = RAXML_BRLEN_MIN;
opts.brlen_max = RAXML_BRLEN_MAX;
/* by default, autodetect optimal number of threads and workers for the dataset */
opts.num_threads = 0;
opts.num_workers = 0;
/* Difficulty preditction num trees */
opts.diff_pred_pars_trees = RAXML_CPYTHIA_TREES_NUM;
bool use_adaptive_search = true;
opts.topology_opt_method = TopologyOptMethod::adaptive;
/* max #threads = # available CPU cores */
#if !defined(_RAXML_PTHREADS)
opts.num_threads = 1;
#else
if (ParallelContext::ranks_per_node() == 1)
opts.num_threads_max = std::max(1u, sysutil_task_cpu_cores(true));
else
opts.num_threads_max = std::max(1u, (unsigned int) (sysutil_get_cpu_cores() / ParallelContext::ranks_per_node()));
#endif
#if defined(_RAXML_MPI)
opts.thread_pinning = ParallelContext::ranks_per_node() == 1 ? true : false;
#else
opts.thread_pinning = false;
#endif
opts.model_file = "";
opts.tree_file = "";
// autodetect CPU instruction set and use respective SIMD kernels
opts.simd_arch = sysutil_simd_autodetect();
opts.load_balance_method = LoadBalancing::benoit;
opts.num_searches = 0;
opts.num_bootstraps = 0;
opts.write_bs_msa = false;
opts.force_mode = false;
opts.safety_checks = SafetyCheck::all;
opts.redo_mode = false;
opts.nofiles_mode = false;
opts.tbe_naive = false;
int compat_ver = RAXML_INTVER;
bool log_level_set = false;
bool lh_epsilon_set = false;
string optarg_tree = "";
int option_index = 0;
int c;
int num_commands = 0;
/* getopt_long_only() uses this global variable to track progress;
* need this re-initialization to make function re-enterable... */
optind = 0;
while ((c = getopt_long_only(argc, argv, "", long_options, &option_index)) == 0)
{
/* optional arguments in getopt() are broken, this hack is needed fix them... */
if (!optarg
&& optind < argc // make sure optind is valid
&& long_options[option_index].has_arg == optional_argument // and has optional argument
&& NULL != argv[optind] // make sure it's not a null string
&& '\0' != argv[optind][0] // ... or an empty string
&& '-' != argv[optind][0] // ... or another option
)
{
// update optind so the next getopt_long invocation skips argv[optind]
optarg = argv[optind++];
}
switch (option_index)
{
case 0:
opts.command = Command::help;
num_commands++;
break;
case 1:
opts.command = Command::version;
num_commands++;
break;
case 2:
opts.command = Command::evaluate;
num_commands++;
break;
case 3:
opts.command = Command::search;
num_commands++;
break;
case 4: /* alignment file */
opts.msa_file = optarg;
break;
case 5: /* starting tree */
if (optarg_tree.empty())
optarg_tree = strdup(optarg);
break;
case 6: /* set prefix for output files */
opts.outfile_prefix = optarg;
break;
case 7: /* model */
opts.model_file = optarg;
break;
case 8: /* data-type */
if (strcasecmp(optarg, "dna") == 0)
opts.data_type = DataType::dna;
else if (strcasecmp(optarg, "aa") == 0)
opts.data_type = DataType::protein;
else if (strcasecmp(optarg, "binary") == 0 || strcasecmp(optarg, "bin") == 0)
opts.data_type = DataType::binary;
else if (strcasecmp(optarg, "diploid10") == 0)
opts.data_type = DataType::genotype10;
else if (strcasecmp(optarg, "multi") == 0)
opts.data_type = DataType::multistate;
else if (strcasecmp(optarg, "auto") == 0)
opts.data_type = DataType::autodetect;
else
throw InvalidOptionValueException("Unknown data type: " + string(optarg));
break;
case 9: /* optimize model */
opts.optimize_model = !optarg || (strcasecmp(optarg, "off") != 0);
break;
case 10: /* optimize branches */
opts.optimize_brlen = !optarg || (strcasecmp(optarg, "off") != 0);
break;
case 11: /* prob-msa = use probabilitic MSA */
if (!optarg || (strcasecmp(optarg, "off") != 0))
{
opts.use_prob_msa = true;
opts.use_pattern_compression = false;
opts.use_tip_inner = false;
opts.use_repeats = false;
opts.use_pythia = false;
use_adaptive_search = false;
}
else
opts.use_prob_msa = false;
break;
case 12: /* disable pattern compression */
opts.use_pattern_compression = !optarg || (strcasecmp(optarg, "off") != 0);
break;
case 13: /* disable tip-inner optimization */
opts.use_tip_inner = !optarg || (strcasecmp(optarg, "off") != 0);
if (opts.use_tip_inner)
opts.use_repeats = false;
break;
case 14: /* branch length linkage mode */
if (strcasecmp(optarg, "scaled") == 0 || strcasecmp(optarg, "proportional") == 0)
opts.brlen_linkage = CORAX_BRLEN_SCALED;
else if (strcasecmp(optarg, "linked") == 0)
opts.brlen_linkage = CORAX_BRLEN_LINKED;
else if (strcasecmp(optarg, "unlinked") == 0)
opts.brlen_linkage = CORAX_BRLEN_UNLINKED;
else
throw InvalidOptionValueException("Unknown branch linkage mode: " + string(optarg));
break;
case 15: /* spr-radius = maximum radius for fast SPRs */
if (sscanf(optarg, "%d", &opts.spr_radius) != 1 || opts.spr_radius <= 0)
{
throw InvalidOptionValueException("Invalid SPR radius: " + string(optarg) +
", please provide a positive integer!");
}
break;
case 16: /* spr-cutoff = relative LH cutoff to discard subtrees */
if (strcasecmp(optarg, "off") == 0)
{
opts.spr_cutoff = 0.;
}
else if (sscanf(optarg, "%lf", &opts.spr_cutoff) != 1)
{
throw InvalidOptionValueException("Invalid SPR cutoff: " + string(optarg) +
", please provide a real number!");
}
break;
case 17: /* LH epsilon */
if(sscanf(optarg, "%lf", &opts.lh_epsilon) != 1 || opts.lh_epsilon < 0.)
throw InvalidOptionValueException("Invalid LH epsilon parameter value: " +
string(optarg) +
", please provide a positive real number.");
lh_epsilon_set = true;
break;
case 18: /* random seed */
opts.random_seed = atol(optarg);
break;
case 19: /* number of threads */
if (strncasecmp(optarg, "auto", 4) == 0)
{
opts.num_threads = 0;
sscanf(optarg, "auto{%u}", &opts.num_threads_max);
}
else if (sscanf(optarg, "%u", &opts.num_threads) != 1 || opts.num_threads == 0)
{
throw InvalidOptionValueException("Invalid number of threads: %s " + string(optarg) +
", please provide a positive integer number or `auto`!");
}
break;
case 20: /* SIMD instruction set */
if (strcasecmp(optarg, "none") == 0 || strcasecmp(optarg, "scalar") == 0)
{
#ifdef HAVE_AUTOVEC
throw InvalidOptionValueException("Non-vectorized kernels not available!\n"
"Please recompile RAxML-NG in portable mode, or use '--simd native' for auto-vectorized kernels.");
#else
opts.simd_arch = CORAX_ATTRIB_ARCH_CPU;
#endif
}
else if (strcasecmp(optarg, "native") == 0 || strcasecmp(optarg, "autovec") == 0)
{
#ifdef HAVE_AUTOVEC
opts.simd_arch = CORAX_ATTRIB_ARCH_CPU;
#else
throw InvalidOptionValueException("Auto-vectorized kernels not available!\n"
"Please recompile RAxML-NG in native mode, or use '--simd none' for non-vectorized kernels.");
#endif
}
else if (strcasecmp(optarg, "sse3") == 0 || strcasecmp(optarg, "sse") == 0)
{
opts.simd_arch = CORAX_ATTRIB_ARCH_SSE;
}
else if (strcasecmp(optarg, "avx") == 0)
{
opts.simd_arch = CORAX_ATTRIB_ARCH_AVX;
}
else if (strcasecmp(optarg, "avx2") == 0)
{
opts.simd_arch = CORAX_ATTRIB_ARCH_AVX2;
}
else if (strcasecmp(optarg, "auto") != 0)
{
throw InvalidOptionValueException("Unknown SIMD instruction set: " + string(optarg));
}
break;
case 21: /* MSA file format */
if (strcasecmp(optarg, "auto") == 0 )
{
opts.msa_format = FileFormat::autodetect;
}
else if (strcasecmp(optarg, "fasta") == 0)
{
opts.msa_format = FileFormat::fasta;
}
else if (strcasecmp(optarg, "fasta_longlabels") == 0)
{
opts.msa_format = FileFormat::fasta_longlabels;
}
else if (strcasecmp(optarg, "phylip") == 0)
{
opts.msa_format = FileFormat::phylip;
}
else if (strcasecmp(optarg, "vcf") == 0)
{
opts.msa_format = FileFormat::vcf;
}
else if (strcasecmp(optarg, "catg") == 0)
{
opts.msa_format = FileFormat::catg;
}
else if (strcasecmp(optarg, "binary") == 0)
{
opts.msa_format = FileFormat::binary;
}
else
{
throw InvalidOptionValueException("Unknown MSA file format: " + string(optarg));
}
break;
case 22: /* enable per-rate scalers */
opts.use_rate_scalers = !optarg || (strcasecmp(optarg, "off") != 0);
break;
case 23: /* log level */
log_level_set = true;
if (strcasecmp(optarg, "error") == 0 )
opts.log_level = LogLevel::error;
else if (strcasecmp(optarg, "warning") == 0)
opts.log_level = LogLevel::warning;
else if (strcasecmp(optarg, "result") == 0)
opts.log_level = LogLevel::result;
else if (strcasecmp(optarg, "info") == 0)
opts.log_level = LogLevel::info;
else if (strcasecmp(optarg, "progress") == 0)
opts.log_level = LogLevel::progress;
else if (strcasecmp(optarg, "verbose") == 0)
opts.log_level = LogLevel::verbose;
else if (strcasecmp(optarg, "debug") == 0)
opts.log_level = LogLevel::debug;
else
throw InvalidOptionValueException("Unknown log level: " + string(optarg));
break;
case 24:
opts.command = Command::bootstrap;
num_commands++;
break;
case 25:
opts.command = Command::all;
/* quickfix: TBE-nature implementation requires traversal-based CLV IDs assignment! */
opts.tbe_naive = true;
num_commands++;
break;
case 26: /* number of bootstrap replicates */
opts.bootstop_criterion = BootstopCriterion::none;
if (sysutil_file_exists(optarg) && !sysutil_isnumber(optarg))
{
opts.outfile_names.bootstrap_trees = optarg;
}
else if (strncasecmp(optarg, "autoMRE", 7) == 0)
{
string optstr = optarg;
std::transform(optstr.begin(), optstr.end(), optstr.begin(), ::tolower);
opts.bootstop_criterion = BootstopCriterion::autoMRE;
if (sscanf(optstr.c_str(), "automre{%u}", &opts.num_bootstraps) != 1)
opts.num_bootstraps = 1000;
}
else if (sscanf(optarg, "%u", &opts.num_bootstraps) != 1 || opts.num_bootstraps == 0)
{
throw InvalidOptionValueException("Invalid number of num_bootstraps: " + string(optarg) +
", please provide a positive integer number!");
}
break;
case 27:
opts.redo_mode = true;
break;
case 28:
opts.force_mode = true;
if (!optarg || strlen(optarg) == 0)
{
opts.safety_checks = SafetyCheck::none;
}
else
{
try
{
opts.safety_checks.unset(optarg);
}
catch(runtime_error& e)
{
throw InvalidOptionValueException("Invalid --force option: " + string(optarg));
}
}
break;
case 29: /* site repeats */
if (!optarg || (strcasecmp(optarg, "off") != 0))
{
opts.use_repeats = true;
opts.use_tip_inner = false;
}
else
opts.use_repeats = false;
break;
case 30: /* support */
opts.command = Command::support;
num_commands++;
break;
case 31: /* terrace */
#ifdef _RAXML_TERRAPHAST
opts.command = Command::terrace;
opts.brlen_linkage = CORAX_BRLEN_UNLINKED;
num_commands++;
#else
throw OptionException("Unsupported command: --terrace.\n"
"Please build RAxML-NG with TERRAPHAST support.");
#endif
break;
case 32: /* maximum number of terrace trees to output */
if (sscanf(optarg, "%llu", &opts.terrace_maxsize) != 1 || opts.terrace_maxsize == 0)
{
throw InvalidOptionValueException("Invalid number of terrace trees to output: "
+ string(optarg) + ", please provide a positive integer number!");
}
break;
case 33: /* check */
opts.command = Command::check;
num_commands++;
break;
case 34: /* parse */
opts.command = Command::parse;
num_commands++;
break;
case 35: /* branch length optimization method */
if (strcasecmp(optarg, "nr_fast") == 0)
opts.brlen_opt_method = CORAX_OPT_BLO_NEWTON_FAST;
else if (strcasecmp(optarg, "nr_oldfast") == 0)
opts.brlen_opt_method = CORAX_OPT_BLO_NEWTON_OLDFAST;
else if (strcasecmp(optarg, "nr_safe") == 0)
opts.brlen_opt_method = CORAX_OPT_BLO_NEWTON_SAFE;
else if (strcasecmp(optarg, "nr_oldsafe") == 0)
opts.brlen_opt_method = CORAX_OPT_BLO_NEWTON_OLDSAFE;
else if (strcasecmp(optarg, "nr_fallback") == 0)
opts.brlen_opt_method = CORAX_OPT_BLO_NEWTON_FALLBACK;
else if (strcasecmp(optarg, "nr_global") == 0)
opts.brlen_opt_method = CORAX_OPT_BLO_NEWTON_GLOBAL;
else if (strcasecmp(optarg, "off") == 0 || strcasecmp(optarg, "none") == 0)
opts.optimize_brlen = false;
else
throw InvalidOptionValueException("Unknown branch length optimization method: " + string(optarg));
break;
case 36: /* min brlen */
if(sscanf(optarg, "%lf", &opts.brlen_min) != 1 || opts.brlen_min <= 0.)
{
throw InvalidOptionValueException("Invalid minimum branch length value: " +
string(optarg) +
", please provide a positive real number.");
}
if (opts.precision.empty() && opts.brlen_min < 1.)
opts.precision[LogElement::brlen] = ceil(-1 * log10(opts.brlen_min));
break;
case 37: /* max brlen */
if(sscanf(optarg, "%lf", &opts.brlen_max) != 1 || opts.brlen_max <= 0.)
{
throw InvalidOptionValueException("Invalid maximum branch length value: " +
string(optarg) +
", please provide a positive real number.");
}
break;
case 38: /* constraint tree */
opts.constraint_tree_file = optarg;
break;
case 39: /* no output files (only console output) */
if (!optarg || strlen(optarg) == 0)
{
opts.nofiles_mode = true;
opts.write_interim_results = false;
}
else
{
auto files = split_string(optarg, ',');
for (const auto& f: files)
{
if (f == "interim")
opts.write_interim_results = false;
else
throw InvalidOptionValueException("Invalid --nofiles option: " + f);
}
}
break;
case 40: /* start tree generation */
opts.command = Command::start;
num_commands++;
break;
case 41: /* compute tree logLH w/o optimization */
opts.command = Command::evaluate;
opts.optimize_model = false;
opts.optimize_brlen = false;
opts.nofiles_mode = true;
opts.log_level = LogLevel::result;
log_level_set = true;
num_commands++;
break;
case 42: /* precision */
{
unsigned int prec = 0;
if (sscanf(optarg, "%u", &prec) != 1 || prec == 0)
{
throw InvalidOptionValueException("Invalid precision: " + string(optarg) +
", please provide a positive integer number!");
}
else
{
opts.precision.clear();
opts.precision[LogElement::all] = prec;
}
}
break;
case 43: /* outgroup */
opts.outgroup_taxa = split_string(optarg, ',');
if (opts.outgroup_taxa.empty())
{
throw InvalidOptionValueException("Invalid outgroup: %s " + string(optarg));
}
break;
case 44: /* bootstopping cutoff */
if(sscanf(optarg, "%lf", &opts.bootstop_cutoff) == 1 &&
opts.bootstop_cutoff >= 0. && opts.bootstop_cutoff <= 1.0)
{
if (opts.bootstop_criterion == BootstopCriterion::none)
opts.bootstop_criterion = BootstopCriterion::autoMRE;
}
else
{
throw InvalidOptionValueException("Invalid bootstopping cutoff value: " +
string(optarg) +
", please provide a number between 0.0 and 1.0.");
}
break;
case 45: /* bootstrap convergence test */
opts.command = Command::bsconverge;
num_commands++;
if (opts.bootstop_criterion == BootstopCriterion::none)
opts.bootstop_criterion = BootstopCriterion::autoMRE;
break;
case 46: /* extra options */
{
auto extra_opts = split_string(optarg, ',');
for (auto& eopt: extra_opts)
{
if (eopt == "lb-naive")
opts.load_balance_method = LoadBalancing::naive;
else if (eopt == "lb-kassian")
opts.load_balance_method = LoadBalancing::kassian;
else if (eopt == "lb-benoit")
opts.load_balance_method = LoadBalancing::benoit;
else if (eopt == "thread-pin")
opts.thread_pinning = true;
else if (eopt == "thread-nopin")
opts.thread_pinning = false;
else if (eopt == "tbe-naive")
opts.tbe_naive = true;
else if (eopt == "tbe-nature")
opts.tbe_naive = false;
else if (eopt == "rba-nopartload")
opts.use_rba_partload = false;
else if (eopt == "energy-off")
opts.use_energy_monitor = false;
else if (eopt == "constraint-old")
opts.use_old_constraint = true;
else if (eopt == "constraint-new")
opts.use_old_constraint = false;
else if (eopt == "fastclv-on")
opts.use_spr_fastclv = true;
else if (eopt == "fastclv-off")
opts.use_spr_fastclv = false;
else if (eopt == "bs-start-pars")
opts.use_bs_pars = true;
else if (eopt == "bs-start-rand")
opts.use_bs_pars = false;
else if (eopt == "pars-par")
opts.use_par_pars = true;
else if (eopt == "pars-seq")
opts.use_par_pars = false;
else if (eopt == "pythia-on")
opts.use_pythia = true;
else if (eopt == "pythia-off")
opts.use_pythia = false;
else if (eopt == "compat-v11")
{
compat_ver = 110;
opts.use_spr_fastclv = false;
opts.use_bs_pars = false;
opts.use_par_pars = false;
opts.use_pythia = false;
opts.topology_opt_method = TopologyOptMethod::classic;
if (!lh_epsilon_set)
opts.lh_epsilon = DEF_LH_EPSILON_V11;
opts.lh_epsilon_brlen_triplet = DEF_LH_EPSILON_V11;
}
else
throw InvalidOptionValueException("Unknown extra option: " + string(eopt));
}
}
break;
case 47: /* branch support metric */
{
opts.bs_metrics.clear();
auto methods = split_string(optarg, ',');
for (const auto& m: methods)
{
if (strncasecmp(m.c_str(), "fbp", 3) == 0)
{
opts.bs_metrics.insert(BranchSupportMetric::fbp);
}
else if (strncasecmp(m.c_str(), "rbs", 3) == 0)
{
opts.bs_metrics.insert(BranchSupportMetric::rbs);
}
else if (strncasecmp(m.c_str(), "tbe", 3) == 0)
{
opts.bs_metrics.insert(BranchSupportMetric::tbe);
}
else if (strncasecmp(m.c_str(), "sh", 3) == 0 || strncasecmp(m.c_str(), "alrt", 3) == 0)
{
opts.bs_metrics.insert(BranchSupportMetric::sh_alrt);
}
else
{
throw InvalidOptionValueException("Unknown branch support metric: " + string(optarg));
}
if (opts.bs_metrics.count(BranchSupportMetric::fbp) && opts.bs_metrics.count(BranchSupportMetric::rbs))
{
throw OptionException("Invalid branch support metric: FBP and RBS can not be used together!");
}
}
}
break;
case 48: /* search1: search from a single starting tree */
opts.command = Command::search;
optarg_tree = "default1";
num_commands++;
break;
case 49: /* generate bootstrap replicate MSAs */
opts.command = Command::bsmsa;
opts.use_par_pars = false;
num_commands++;
break;
case 50: /* compute RF distance */
opts.command = Command::rfdist;
num_commands++;
if (optarg)
optarg_tree = optarg;
break;
case 51: /* compute and print average RF distance w/o noise */
opts.command = Command::rfdist;
opts.nofiles_mode = true;
opts.log_level = LogLevel::result;
log_level_set = true;
num_commands++;
if (optarg)
optarg_tree = optarg;
break;
case 52: /* build consensus tree */
opts.command = Command::consense;
num_commands++;
if (optarg)
{
if (strcasecmp(optarg, "mr") == 0)
opts.consense_cutoff = ConsenseCutoff::MR;
else if (strcasecmp(optarg, "mre") == 0)
opts.consense_cutoff = ConsenseCutoff::MRE;
else if (strcasecmp(optarg, "strict") == 0)
opts.consense_cutoff = ConsenseCutoff::strict;
else if (sscanf(optarg, "%*[Mm]%*[Rr]%u", &opts.consense_cutoff) != 1 ||
opts.consense_cutoff < 50 || opts.consense_cutoff > 100)
{
auto errmsg = "Invalid consensus type or threshold value: " +
string(optarg) + "\n" +
"Allowed values: MR, MRE, STRICT or MR<n>, where 50 <= n <= 100.";
throw InvalidOptionValueException(errmsg);
}
}
else
opts.consense_cutoff = ConsenseCutoff::MR;
break;
case 53: /* ancestral state reconstruction */
opts.command = Command::ancestral;
opts.use_pattern_compression = false;
opts.use_repeats = false;
opts.use_tip_inner = true;
if (opts.precision.empty())
opts.precision[LogElement::other] = 5;
num_commands++;
break;
case 54: /* number of workers (=parallel tree searches) */
if (strncasecmp(optarg, "auto", 4) == 0)
{
opts.num_workers = 0;
sscanf(optarg, "auto{%u}", &opts.num_workers_max);