-
Notifications
You must be signed in to change notification settings - Fork 7
/
spr_supertree.cpp
executable file
·4203 lines (3883 loc) · 136 KB
/
spr_supertree.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
/*******************************************************************************
spr_supertree.cpp
Copyright 2013-2014 Chris Whidden
http://kiwi.cs.dal.ca/Software/SPR_Supertrees
March 3, 2014
Version 1.2.1
This file is part of spr_supertrees.
spr_supertrees is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
spr_supertrees is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with spr_supertrees. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************
ALGORITHM
*******************************************************************************
These options control what algorithm is used to determine the SPR distance
from the supertree to the input trees. By default -bb is used.
-fpt Calculate the exact rSPR distance with an FPT algorithm
-bb Calculate the exact rSPR distance with a branch-and-bound
FPT algorithm. This is the default option.
-approx Calculate just a linear -time 3-approximation of the rSPR distance
-max k Calculate the exact rSPR distance if it is k or less and
otherwise use the 3-approximation
-split_approx
-split_approx x Calculate the exact rSPR distance if it is k or less and
otherwise use the exponential-time approximation
*******************************************************************************
OPTIMIZATIONS
*******************************************************************************
These options control the use of optimized branching. All optimizations are
enabled by default. Specifying any subset of -cob, -cab, and -sc will use
just that subset of optimizations. See the README for more information.
-allopt Use -cob -cab -sc and a new set of optimizations. This is the default
option
-noopt Use 3-way branching for all FPT algorithms
-cob Use "cut one b" improved branching
-cab Use "cut all b" improved branching
-sc Use "separate components" improved branching
-bipartition_cluster x Do not consider supertree rearrangements that violate
biparitions supported by x% of gene trees containing
at least two members from each side of the bipartition.
Enabled by default with x=0.5
*******************************************************************************
MULTIFURCATING COMPARISON OPTIONS
*******************************************************************************
-allow_multi Allow multifurcating gene trees
-lgt_multi Allow multifurcating input tree for LGT analysis
-support x Collapse bipartitions with less than x support
*******************************************************************************
UNROOTED COMPARISON OPTIONS
*******************************************************************************
-unrooted Compare the supertree to each rooting of the input trees.
Use the best found distance
-unrooted_min_approx Compare the supertree to each rooting of the
input trees.
Run the exact algorithm on the rooting with the
minimum approximate rspr distance
-simple_unrooted Root the gene trees at each iteration using
a bipartition balanced accuracy measure
(fast but potentially less accurate)
Reports an unrooted SPR distance comparison
at the end of each iteration for comparable
iteration scores
-simple_unrooted x Root the gene trees at the first x iterations
-simple_unrooted_fast The same as -simple_unrooted but does not use
an unrooted comparison at the end of each
iteration
-outgroup FILE Root the gene trees with the outgroup taxa
listed in FILE, one per line. Trees with a
polyphyletic outgroup are considered invalid.
-reroot Reroot the super tree at each iteration using
a bipartition balanced accuracy measure
-rspr_reroot Root trees using the SPR distance instead
of the bipartition balanced accuracy
*******************************************************************************
SEARCH STRATEGY OPTIONS
*******************************************************************************
-i x Run for x iterations of the global rearrangement search
-r x Only consider transfers of length x in the global rearrangement
search. Default is infinite (All SPRs). For NNI search use
-r 1
-include_only <file> Build the supertree only from taxa included in
<file>, one per line
-initial_tree <file> Begin the search with the tree in <file>
-num_leaves x Build the supertree from the x taxa that are found
in the largest number of trees
-random_insert_order Insert taxa in random order when building the
greedy addition tree. The default order is
descending occurence
-rf_ties Break SPR distance ties with the RF distance
*******************************************************************************
LGT ANALYSIS
*******************************************************************************
-lgt_analysis Conduct an LGT analysis with the initial user-specified
or greedy addition tree
-lgt_csv Output the LGT analysis seperated by commas rather than
spaces.
-lgt_groups FILE Specify a set of groups (e.g. genus or class) to analyze
with -lgt_analysis. The group FILE contains a set of
groups consisting of a group name on one line, group
members one per line, and a blank line to seperate each
group.
*******************************************************************************
OTHER OPTIONS
*******************************************************************************
-time Print iteration and total CPU time used at each
iteration
-cc Calculate a potentially better approximation with a
quadratic time algorithm
-valid_trees Output the set of trees that appear valid
-valid_trees_rooted Output the set of trees that appear valid after applying
any rooting options.
-multi_trees Output the set of multifurcating or invalid trees
*******************************************************************************/
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
#include <sstream>
#include <climits>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <list>
#include <time.h>
#include "rspr.h"
#include "Forest.h"
#include "ClusterForest.h"
#include "LCA.h"
#include "ClusterInstance.h"
#include "UndoMachine.h"
#include "lgt.h"
#include "sparse_counts.h"
#include "node_glom.h"
using namespace std;
//#define DEBUG_ONE_TREE true
// options to pick default
bool DEFAULT_ALGORITHM=true;
bool DEFAULT_OPTIMIZATIONS=true;
bool DEFAULT_SEARCH_OPTIMIZATIONS=true;
bool FPT = false;
bool QUIET = false;
bool UNROOTED = false;
bool SIMPLE_UNROOTED = false;
bool SIMPLE_UNROOTED_FAST = false;
int SIMPLE_UNROOTED_NUM = INT_MAX;
bool REROOT = false;
bool REROOT_INITIAL = false;
bool APPROX_ROOTING = false;
bool EXACT_ROOTING = false;
bool RANDOM_ROOTING = false;
bool RANDOM_INSERT_ORDER = false;
bool APPROX = false;
bool TIMING = false;
int NUM_ITERATIONS = 25;
bool SMALL_TREES = false;
bool CONVERT_LIST = false;
bool INVALID_TREES = false;
bool VALID_TREES = false;
bool VALID_TREES_ROOTED = false;
bool LGT_ANALYSIS = false;
bool LGT_EVALUATION = false;
bool FIND_MAX_DEGREE = false;
bool MULTI_TREES = false;
int NUM_LEAVES=-1;
int APPROX_SIBLINGS = 0;
int C_SOURCE = -1;
int NUM_SOURCE = -1;
bool RF_TIES = false;
double SUPPORT_THRESHOLD = 0.5;
bool TABOO_SEARCH = false;
bool ONE_TREE_AT_A_TIME = false;
bool NODE_GLOM_CONSTRUCTION = false;
bool USE_PRECOMPUTED_DISTANCES = false;
/*variables Joel added*/
int R_DISTANCE;
bool R_VARIABLE = false;
bool R_LIMIT = false;
bool R_RAND = false;
bool R_CONTROL = false;
bool R_BIAS = false;
float R_PROB;
bool S_LIMIT = false;
int S_NUM = 10;
bool S_STATS = false;
bool D_STATS = false;
bool RANDOM_TREE = false;
bool GREEDY = false;
bool GREEDY_REFINED = false;
string USAGE =
"spr_supertrees, version 1.2.1\n"
"\n"
"usage: spr_supertrees [OPTIONS]\n"
"Calculate binary rooted supertrees that minimize the Subtree Prune and\n"
"Regraft (SPR) distance to a set of rooted or unrooted binary or\n"
"multifurcating trees from STDIN in newick format. Supports arbitrary\n"
"leaf labels. See the README for more information.\n"
"\n"
"Copyright 2011-14 Chris Whidden\n"
"http://kiwi.cs.dal.ca/Software/SPR_Supertrees\n"
"March 3, 2014\n"
"Version 1.2.1\n"
"\n"
"This program comes with ABSOLUTELY NO WARRANTY.\n"
"This is free software, and you are welcome to redistribute it\n"
"under certain conditions; See the README for details.\n"
"\n"
"*******************************************************************************\n"
"ALGORITHM\n"
"*******************************************************************************\n"
"\n"
"These options control what algorithm is used to determine the SPR distance\n"
"from the supertree to the input trees. By default -bb is used.\n"
"\n"
"-fpt Calculate the exact rSPR distance with an FPT algorithm\n"
"\n"
"-bb Calculate the exact rSPR distance with a branch-and-bound\n"
" FPT algorithm. This is the default option.\n"
"\n"
"-approx Calculate just a linear -time 3-approximation of the rSPR distance\n"
"\n"
"-max k Calculate the exact rSPR distance if it is k or less and\n"
" otherwise use the 3-approximation\n"
"\n"
"-split_approx\n"
"-split_approx x Calculate the exact rSPR distance if it is k or less and\n"
" otherwise use the exponential-time approximation\n"
"\n"
"*******************************************************************************\n"
"OPTIMIZATIONS\n"
"*******************************************************************************\n"
"\n"
"These options control the use of optimized branching. All optimizations are\n"
"enabled by default. Specifying any subset of -cob, -cab, and -sc will use\n"
"just that subset of optimizations. See the README for more information.\n"
"\n"
"-allopt Use -cob -cab -sc and a new set of optimizations. This is the default\n"
" option\n"
"\n"
"-noopt Use 3-way branching for all FPT algorithms\n"
"\n"
"-cob Use \"cut one b\" improved branching\n"
"\n"
"-cab Use \"cut all b\" improved branching\n"
"\n"
"-sc Use \"separate components\" improved branching\n"
"\n"
"-bipartition_cluster x Do not consider supertree rearrangements that violate\n"
" biparitions supported by x% of gene trees containing\n"
" at least two members from each side of the bipartition.\n"
" Enabled by default with x=0.5\n"
"\n"
"*******************************************************************************\n"
"MULTIFURCATING COMPARISON OPTIONS\n"
"*******************************************************************************\n"
"\n"
"-allow_multi Allow multifurcating gene trees\n"
"\n"
"-lgt_multi Allow multifurcating input tree for LGT analysis\n"
"\n"
"-support x Collapse bipartitions with less than x support\n"
"\n"
"*******************************************************************************\n"
"UNROOTED COMPARISON OPTIONS\n"
"*******************************************************************************\n"
"\n"
"-unrooted Compare the supertree to each rooting of the input trees.\n"
" Use the best found distance\n"
"\n"
"-unrooted_min_approx Compare the supertree to each rooting of the\n"
" input trees.\n"
" Run the exact algorithm on the rooting with the\n"
" minimum approximate rspr distance\n"
"\n"
"-simple_unrooted Root the gene trees at each iteration using\n"
" a bipartition balanced accuracy measure\n"
" (fast but potentially less accurate)\n"
" Reports an unrooted SPR distance comparison\n"
" at the end of each iteration for comparable\n"
" iteration scores\n"
"\n"
"-simple_unrooted x Root the gene trees at the first x iterations\n"
"\n"
"-simple_unrooted_fast The same as -simple_unrooted but does not use\n"
" an unrooted comparison at the end of each\n"
" iteration\n"
"\n"
"-outgroup FILE Root the gene trees with the outgroup taxa\n"
" listed in FILE, one per line. Trees with a\n"
" polyphyletic outgroup are considered invalid.\n"
"\n"
"-reroot Reroot the super tree at each iteration using\n"
" a bipartition balanced accuracy measure\n"
"\n"
"-rspr_reroot Root trees using the SPR distance instead\n"
" of the bipartition balanced accuracy\n"
"\n"
"\n"
"\n"
"*******************************************************************************\n"
"SEARCH STRATEGY OPTIONS\n"
"*******************************************************************************\n"
"\n"
"-i x Run for x iterations of the global rearrangement search\n"
"\n"
"-r x Only consider transfers of length x in the global rearrangement\n"
" search. Default is infinite (All SPRs). For NNI search use\n"
" -r 1\n"
"\n"
"-include_only <file> Build the supertree only from taxa included in\n"
" <file>, one per line\n"
"\n"
"-initial_tree <file> Begin the search with the tree in <file>\n"
"\n"
"-num_leaves x Build the supertree from the x taxa that are found\n"
" in the largest number of trees\n"
"\n"
"-random_insert_order Insert taxa in random order when building the\n"
" greedy addition tree. The default order is\n"
" descending occurence\n"
"\n"
"-rf_ties Break SPR distance ties with the RF distance\n"
"\n"
"*******************************************************************************\n"
"LGT ANALYSIS\n"
"*******************************************************************************\n"
"\n"
"-lgt_analysis Conduct an LGT analysis with the initial user-specified\n"
" or greedy addition tree\n"
"\n"
"-lgt_csv Output the LGT analysis seperated by commas rather than\n"
" spaces.\n"
"\n"
"-lgt_groups FILE Specify a set of groups (e.g. genus or class) to analyze\n"
" with -lgt_analysis. The group FILE contains a set of\n"
" groups consisting of a group name on one line, group\n"
" members one per line, and a blank line to seperate each\n"
" group.\n"
" \n"
"*******************************************************************************\n"
"OTHER OPTIONS\n"
"*******************************************************************************\n"
"-time Print iteration and total CPU time used at each\n"
" iteration\n"
"\n"
"-cc Calculate a potentially better approximation with a\n"
" quadratic time algorithm\n"
"\n"
"-valid_trees Output the set of trees that appear valid\n"
"-valid_trees_rooted Output the set of trees that appear valid after applying\n"
" any rooting options.\n"
"\n"
"-multi_trees Output the set of multifurcating or invalid trees\n";
Node *find_best_sibling(Node *super_tree, vector<Node *> &gene_trees,
int label);
Node *find_best_sibling(Node *super_tree, vector<Node *> &gene_trees,
vector<Node *> *best_siblings, int label);
void find_best_sibling_helper(Node *n, Node *new_leaf, Node *super_tree,
vector<Node *> &gene_trees, int &min_distance, int &min_tie_distance,
int &num_ties, Node **best_sibling);
vector<Node *> *find_best_siblings(Node *super_tree, vector<Node *> &gene_trees, int label, int num_siblings);
void find_best_siblings_helper(Node *n, Node *new_leaf, Node *super_tree,
vector<Node *> &gene_trees, int &min_distance, int &min_tie_distance,
int &num_ties, multimap<int, Node*> *best_siblings, int num_siblings);
void test_sibling_helper(Node *n, Node *new_leaf, Node *super_tree,
vector<Node *> &gene_trees, int &min_distance, int &min_tie_distance,
int &num_ties, Node **best_sibling);
void find_best_spr(Node *super_tree, vector<Node *> &gene_trees,
Node *&best_spr_move, Node *&best_sibling);
void find_best_spr_helper(Node *n, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties);
void find_best_spr_helper(Node *n, Node *new_sibling, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties);
void get_support(Node *super_tree, vector<Node *> *gene_trees);
void get_support(Node *n, Node *super_tree, vector<Node *> *gene_trees);
void get_transfer_support(Node *super_tree, vector<Node *> *gene_trees);
void get_transfer_support(Node *n, Node *super_tree, vector<Node *> *gene_trees);
void get_bipartition_support(Node *super_tree, vector<Node *> *gene_trees,
enum RELAXATION relaxed);
bool supported_spr(Node *source, Node *target);
bool pair_comparator (pair<int, int> a, pair<int, int> b);
/*Prototypes of Joel's functions*/
void find_best_spr_r(Node *super_tree, vector<Node *> &gene_trees, Node *&best_spr_move, Node *&best_sibling, int r);
void find_best_spr_r(Node *super_tree, vector<Node *> &gene_trees, Node *&best_spr_move, Node *&best_sibling, int r, vector<int> *original_scores);
void find_best_spr_r_helper(Node *n, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, int r);
void find_best_spr_r_helper(Node *n, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &min_tie_distance,
int &num_ties, int r,
vector<int> *original_scores);
void find_best_spr_r_helper(Node *n, Node *new_sibling, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, int r, int origin);
void find_best_spr_r_helper(Node *n, Node *new_sibling, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &min_tie_distance,
int &num_ties, int r, int origin, int offset);
void find_best_spr(Node *super_tree, vector<Node *> &gene_trees, Node *&best_spr_move, Node *&best_sibling, vector <pair <int, pair<int, int> > > &stats);
void find_best_spr_helper(Node *n, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, vector<pair <int, pair<int, int> > > &stats);
void find_best_spr_helper(Node *n, Node *new_sibling, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, vector<pair <int, pair<int, int> > > &stats);
void find_best_spr(Node *super_tree, vector<Node *> &gene_trees, Node *&best_spr_move, Node *&best_sibling, vector<pair <pair<Node*,Node*>, int> > &approx_moves);
void find_best_spr_helper(Node *n, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, vector<pair <pair<Node*,Node*>, int> > &approx_moves);
void find_best_spr_helper(Node *n, Node *new_sibling, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, vector<pair <pair<Node*,Node*>, int> > &approx_moves);
void find_best_spr_helper(Node *n, Node *new_sibling, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, vector<pair <pair<Node*,Node*>, int> > &approx_moves, int offset);
bool sort_approx_moves(const pair<pair<Node*,Node*>, int> &a, const pair<pair<Node*,Node*>, int> &b);
int find_r();
int find_r(double probability);
void find_best_distance(Node * n, Node * super_tree, vector<Node *> &gene_trees, vector< pair<Node*, int> > &scores, int &num_zeros, int &best_distance);
//void find_best_distance_helper(Node *n, Forest *f, vector<Node *> &gene_trees, vector< pair<Node *, int> > &scores);
vector<pair<Node *, int> > get_best_scores(vector<pair<Node *, int> > &scores);
void find_best_spr_r_helper(Node *n, Node *new_sibling, Node *super_tree,
vector<Node *> &gene_trees, Node *&best_spr_move,
Node *&best_sibling, int &min_distance, int &num_ties, int r, int origin, vector<pair <pair<Node*,Node*>, int> > &approx_moves);
bool is_taboo(list<Node> taboo_trees, Node *super_tree);
map<string, int> label_map;
map<int, string> reverse_label_map;
bool is_pow_2(int n) {
return (n) && !(n & (n - 1));
}
bool BIPARTITION_CLUSTER = false;
list<Node> taboo_trees = list<Node>();
int main(int argc, char *argv[]) {
// ignore multifurcating trees by default
IGNORE_MULTI = true;
string INCLUDE_ONLY = "";
bool OUTGROUP_ROOT = false;
string OUTGROUP = "";
string INITIAL_SUPER_TREE = "";
string LGT_GROUPS = "";
bool INITIAL_SUPER_TREE_UNROOTED = false;
bool FIND_SUPPORT = false;
bool FIND_BIPARTITION_SUPPORT = false;
enum RELAXATION RELAXED_BIPARTITION_SUPPORT = NEGATIVE_RELAXED;
bool FIND_CLADE_TRANSFERS = false;
bool LGT_CSV = false;
int max_args = argc-1;
while (argc > 1) {
char *arg = argv[--argc];
if (strcmp(arg, "-fpt") == 0) {
FPT = true;
DEFAULT_ALGORITHM=false;
}
else if (strcmp(arg, "-bb") == 0) {
BB = true;
DEFAULT_ALGORITHM=false;
}
else if (strcmp(arg, "-approx") == 0) {
APPROX=true;
}
else if (strcmp(arg, "-q") == 0)
QUIET = true;
else if (strcmp(arg, "-cc") == 0)
APPROX_CHECK_COMPONENT = true;
else if (strcmp(arg, "-unrooted") == 0)
UNROOTED = true;
else if (strcmp(arg, "-simple_unrooted") == 0) {
SIMPLE_UNROOTED = true;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
SIMPLE_UNROOTED_NUM = atoi(arg2);
cout << "SIMPLE_UNROOTED_NUM=" << SIMPLE_UNROOTED_NUM << endl;
}
}
else if (strcmp(arg, "-simple_unrooted_rspr") == 0) {
SIMPLE_UNROOTED = true;
EXACT_ROOTING = true;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
SIMPLE_UNROOTED_NUM = atoi(arg2);
cout << "SIMPLE_UNROOTED_NUM=" << SIMPLE_UNROOTED_NUM << endl;
}
}
else if (strcmp(arg, "-simple_unrooted_random") == 0) {
SIMPLE_UNROOTED = true;
RANDOM_ROOTING = true;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
SIMPLE_UNROOTED_NUM = atoi(arg2);
cout << "SIMPLE_UNROOTED_NUM=" << SIMPLE_UNROOTED_NUM << endl;
}
}
else if (strcmp(arg, "-simple_unrooted_fast") == 0) {
SIMPLE_UNROOTED=true;
SIMPLE_UNROOTED_FAST=true;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
SIMPLE_UNROOTED_NUM = atoi(arg2);
cout << "SIMPLE_UNROOTED_NUM=" << SIMPLE_UNROOTED_NUM << endl;
}
}
else if (strcmp(arg, "-random_insert_order") == 0) {
RANDOM_INSERT_ORDER = true;
}
else if (strcmp(arg, "-reroot") == 0) {
REROOT = true;
REROOT_INITIAL = true;
}
else if (strcmp(arg, "-reroot_initial") == 0) {
REROOT_INITIAL = true;
}
else if (strcmp(arg, "-rspr_root") == 0) {
EXACT_ROOTING = true;
}
else if (strcmp(arg, "-random_root") == 0) {
RANDOM_ROOTING = true;
}
else if (strcmp(arg, "-unrooted_min_approx") == 0) {
UNROOTED = true;
UNROOTED_MIN_APPROX = true;
}
else if (strcmp(arg, "-noopt") == 0) {
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-cut_one_b") == 0 ||
strcmp(arg, "-cob") == 0) {
CUT_ONE_B = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-reverse_cut_one_b") == 0 ||
strcmp(arg, "-rcob") == 0) {
REVERSE_CUT_ONE_B = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-cut_all_b") == 0 ||
strcmp(arg, "-cab") == 0) {
CUT_ALL_B = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-cut_ac_separate_components") == 0 ||
strcmp(arg, "-sc") == 0) {
CUT_AC_SEPARATE_COMPONENTS = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-cut_one_ab") == 0) {
CUT_ONE_AB = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-h") == 0) {
cout << USAGE;
return 0;
}
/* else if (strcmp(arg, "-cluster") == 0) {
CLUSTER_REDUCTION = true;
PREFER_RHO = true;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
MAX_CLUSTERS = atoi(arg2);
cout << "MAX_CLUSTERS=" << MAX_CLUSTERS << endl;
}
}
*/
else if (strcmp(arg, "-prefer_rho") == 0) {
PREFER_RHO = true;
}
/*
else if (strcmp(arg, "-memoize") == 0) {
MEMOIZE = true;
}
else if (strcmp(arg, "-all_mafs") == 0) {
ALL_MAFS= true;
}
*/
else if (strcmp(arg, "-i") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
NUM_ITERATIONS = atoi(arg2);
cout << "NUM_ITERATIONS=" << NUM_ITERATIONS << endl;
}
}
/*Joel: limit SPR radius*/
else if (strcmp(arg, "-r") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] == 'r'){
R_LIMIT = true;
R_RAND = true;
R_DISTANCE = find_r();
cout << "RANDOM R_DISTANCE=" << R_DISTANCE << endl;
}
else if (arg2[0] != '-'){
R_LIMIT = true;
R_DISTANCE = atoi(arg2);
cout << "R_DISTANCE=" << R_DISTANCE << endl;
}
}
}
else if (strcmp(arg, "-r_variable") == 0) {
R_VARIABLE = true;
DEFAULT_SEARCH_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-p") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (!R_RAND)
R_PROB = 0.500;
else if (arg2[0] != '-'){
R_BIAS = true;
R_PROB = atof(arg2);
cout << "PROBABILITY=" << R_PROB << endl;
}
}
DEFAULT_SEARCH_OPTIMIZATIONS=false;
}
/*Joel: refined greedy search*/
else if(strcmp(arg, "-r_greedy")==0){
GREEDY_REFINED = true;
if(max_args > argc){
char *arg2 = argv[argc+1];
if(arg2[0] != '-')
S_NUM = atoi(arg2);
else
S_NUM = 5;
}
if(max_args > argc){
char *arg2 = argv[argc+2];
if(arg2[0] != '-')
R_DISTANCE = atoi(arg2);
else
R_DISTANCE = 1;
}
DEFAULT_SEARCH_OPTIMIZATIONS=false;
}
/*Joel: limit starting points*/
else if (strcmp(arg, "-num_start") == 0){
S_LIMIT = true;
if(max_args > argc) {
char *arg2 = argv[argc+1];
if(arg2[0] != '-'){
S_NUM = atoi(arg2);
}
}
cout << "STARTING POINTS TO CHECK: " << S_NUM << endl;
DEFAULT_SEARCH_OPTIMIZATIONS=false;
}
/*Joel: limit SPR radius options*/
else if (strcmp(arg, "-stats") == 0){
S_STATS = true;
}
else if (strcmp(arg, "-control") == 0) {
R_CONTROL = true;
DEFAULT_SEARCH_OPTIMIZATIONS=false;
}
/*Joel: stats on approx distance vs total distance*/
else if (strcmp(arg, "-d_stats") == 0)
D_STATS = true;
/*Joel: greedy search*/
else if(strcmp(arg, "-greedy")==0) {
GREEDY = true;
DEFAULT_SEARCH_OPTIMIZATIONS=false;
}
/*Joel: random starting tree*/
else if (strcmp(arg, "-rand_tree") == 0)
RANDOM_TREE = true;
else if (strcmp(arg, "-max") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
MAX_SPR = atoi(arg2);
cout << "MAX_SPR=" << MAX_SPR << endl;
}
}
else if (strcmp(arg, "-cluster_max") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-') {
CLUSTER_MAX_SPR = atoi(arg2);
cout << "CLUSTER_MAX_SPR=" << CLUSTER_MAX_SPR << endl;
}
}
}
else if (strcmp(arg, "-num_leaves") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
NUM_LEAVES = atoi(arg2);
cout << "NUM_LEAVES=" << NUM_LEAVES << endl;
}
}
else if (strcmp(arg, "-time") == 0) {
TIMING= true;
}
else if (strcmp(arg, "-clamp") == 0) {
CLAMP= true;
}
else if (strcmp(arg, "-small_trees") == 0) {
SMALL_TREES=true;
}
else if (strcmp(arg, "-convert_list") == 0) {
CONVERT_LIST=true;
}
else if (strcmp(arg, "-valid_trees") == 0) {
VALID_TREES=true;
}
else if (strcmp(arg, "-invalid_trees") == 0) {
VALID_TREES=true;
INVALID_TREES=true;
}
else if (strcmp(arg, "-valid_trees_rooted") == 0) {
VALID_TREES_ROOTED=true;
}
else if (strcmp(arg, "-lgt_analysis") == 0) {
LGT_ANALYSIS=true;
}
else if (strcmp(arg, "-lgt_move_parent") == 0) {
LGT_MOVE_PARENT=true;
}
else if (strcmp(arg, "-lgt_move_individual_node") == 0) {
LGT_MOVE_INDIVIDUAL_NODE=true;
}
else if (strcmp(arg, "-lgt_maintain_list") == 0) {
LGT_MAINTAIN_LIST=true;
}
else if (strcmp(arg, "-lgt_evaluation") == 0) {
LGT_EVALUATION=true;
}
else if (strcmp(arg, "-lgt_csv") == 0) {
LGT_CSV=true;
}
else if (strcmp(arg, "-max_degree") == 0) {
FIND_MAX_DEGREE=true;
}
else if (strcmp(arg, "-multi_trees") == 0) {
MULTI_TREES=true;
}
else if (strcmp(arg, "-rf_ties") == 0) {
RF_TIES=true;
}
else if (strcmp(arg, "-allow_multi") == 0) {
IGNORE_MULTI = false;
}
else if (strcmp(arg, "-lgt_multi") == 0) {
MULTIFURCATING = true;
}
else if (strcmp(arg, "-protect_edges") == 0) {
EDGE_PROTECTION = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-allow_abort") == 0) {
ABORT_AT_FIRST_SOLUTION = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-preorder_sib_pairs") == 0) {
PREORDER_SIBLING_PAIRS = true;
NEAR_PREORDER_SIBLING_PAIRS = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-near_preorder_sib_pairs") == 0) {
NEAR_PREORDER_SIBLING_PAIRS = true;
DEFAULT_OPTIMIZATIONS=false;
}
else if (strcmp(arg, "-leaf_reduction") == 0) {
LEAF_REDUCTION = true;
}
else if (strcmp(arg, "-leaf_reduction2") == 0) {
LEAF_REDUCTION2 = true;
}
else if (strcmp(arg, "-split_approx") == 0) {
SPLIT_APPROX = true;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
SPLIT_APPROX_THRESHOLD = atoi(arg2);
cout << "SPLIT_APPROX_THRESHOLD=" << SPLIT_APPROX_THRESHOLD
<< endl;
}
}
else if (strcmp(arg, "-support") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
REQUIRED_SUPPORT = atof(arg2);
cout << "REQUIRED_SUPPORT=" << REQUIRED_SUPPORT
<< endl;
}
}
else if (strcmp(arg, "-approx_siblings") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
APPROX_SIBLINGS = atoi(arg2);
cout << "APPROX_SIBLINGS=" << APPROX_SIBLINGS
<< endl;
}
}
else if (strcmp(arg, "-include_only") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
INCLUDE_ONLY = string(arg2);
cout << "INCLUDE_ONLY=" << INCLUDE_ONLY
<< endl;
}
}
else if (strcmp(arg, "-outgroup") == 0) {
OUTGROUP_ROOT = true;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
OUTGROUP = string(arg2);
cout << "OUTGROUP=" << OUTGROUP
<< endl;
}
}
else if (strcmp(arg, "-initial_tree") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
INITIAL_SUPER_TREE = string(arg2);
cout << "INITIAL_TREE=" << INITIAL_SUPER_TREE
<< endl;
}
}
else if (strcmp(arg, "-lgt_groups") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
LGT_GROUPS = string(arg2);
cout << "LGT_GROUPS=" << LGT_GROUPS
<< endl;
}
}
else if (strcmp(arg, "-initial_tree_unrooted") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
INITIAL_SUPER_TREE = string(arg2);
cout << "INITIAL_TREE=" << INITIAL_SUPER_TREE
<< endl;
INITIAL_SUPER_TREE_UNROOTED=true;
REROOT_INITIAL=true;
}
}
else if (strcmp(arg, "-count_losses") == 0) {
COUNT_LOSSES = true;
}
else if (strcmp(arg, "-cut_lost") == 0) {
CUT_LOST = true;
}
else if (strcmp(arg, "-find_support") == 0) {
FIND_SUPPORT = true;
}
else if (strcmp(arg, "-find_bipartition_support") == 0) {
FIND_BIPARTITION_SUPPORT = true;
}
else if (strcmp(arg, "-relaxed_bipartition_support") == 0) {
RELAXED_BIPARTITION_SUPPORT = ALL_RELAXED;
}
else if (strcmp(arg, "-strict_bipartition_support") == 0) {
RELAXED_BIPARTITION_SUPPORT = STRICT;
}
else if (strcmp(arg, "-bipartition_cluster") == 0) {
BIPARTITION_CLUSTER = true;
cout << "BIPARTITION_CLUSTER=true" << endl;
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-')
SUPPORT_THRESHOLD = atof(arg2);
}
cout << "CLUSTER THRESHOLD=" << SUPPORT_THRESHOLD
<< endl;
}
else if (strcmp(arg, "-find_clade_transfers") == 0) {
FIND_CLADE_TRANSFERS = true;
}
else if (strcmp(arg, "-taboo_search") == 0) {
TABOO_SEARCH = true;
}
else if (strcmp(arg, "-one_tree_at_a_time") == 0
|| (strcmp(arg, "-one_tree") == 0) ) {
ONE_TREE_AT_A_TIME = true;
}
else if (strcmp(arg, "-node_glom_construction") == 0
|| (strcmp(arg, "-node_glom") == 0) ) {
NODE_GLOM_CONSTRUCTION = true;
}
else if (strcmp(arg, "-precompute") == 0 ) {
USE_PRECOMPUTED_DISTANCES = true;
}
else if (strcmp(arg, "-cluster_tune") == 0) {
if (max_args > argc) {
char *arg2 = argv[argc+1];
if (arg2[0] != '-') {
CLUSTER_TUNE = atoi(arg2);
cout << "CLUSTER_TUNE=" << CLUSTER_TUNE << endl;
}
}
}
else if (strcmp(arg, "--help") == 0) {
cout << USAGE;
return 0;
}
}
if (DEFAULT_OPTIMIZATIONS) {
CUT_ALL_B=true;