-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtreecompare2.c
20397 lines (17984 loc) · 645 KB
/
treecompare2.c
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
/*
* treecompare2.c
*
*
* Created by Chris Creevey on Sat Oct 04 2003.
* Copyright (c) 2003 - 2016 Chris Creevey. All rights reserved.
*
*/
#include "config.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdarg.h>
#include <time.h>
#include <math.h>
#include <signal.h>
#include <unistd.h> /* For Unix Systems Builds */
/*#include <process.h> */ /* For Windows systems Builds */
#ifdef HAVE_READLINE /* from config.h */
#include <readline/readline.h>
#include <readline/history.h>
#endif
/****** Define ********/
#define FUNDAMENTAL_NUM 1000
#define TREE_LENGTH 1000000
#define TAXA_NUM 1000
#define NAME_LENGTH 1000
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TEMP
#define TEMP 2
#endif
/******** Structure definitions *************/
struct taxon {
int name; /* This holds number which refers to the name of the taxon at this node if it doesn't point to a daughter node */
char *fullname; /* This holds the original name as it was given in the tree file, this allows us to record if there was parts of the name excluded earlier */
float score;
struct taxon *daughter; /* This points to a daughter node, but is only set if name is null */
struct taxon *parent; /* This points to the parent node, however its only set on the first sibling at each level */
struct taxon *prev_sibling; /* Points to the previous sibling at this node */
struct taxon *next_sibling; /* Points to the next sibling at this node */
int tag; /* A tag which is included as something which might be useful at some point */
int tag2; /* sometimes one of something just isn't enough ;o) */
float loss; /* A tag which will tell whether this node was lost.... only used for tree-mapping procedure */
float xpos; /* used to fix the position of the node for graphical representation */
float ypos;
int spr;
char weight[100]; /* this will be used when we have a weight to add to the node like with a Bootstrap proportion */
float length;
int *donor; /* THis is for the HGT analysis */
} taxon_type;
/*********** Function definitions ********************/
void find(struct taxon * position);
int run_main(int argc, char *argv[]);
void input_file_summary(int do_all);
void clean_exit(int error);
char *xgets(char *s);
char inttotext(int c);
void totext(int c, char *array);
int assign_taxa_name(char *name, int fund);
void execute_command(char *filename, int do_all);
int seperate_commands(char *command);
int parse_command(char *command);
void print_commands(int num);
int texttoint(char c);
void cal_fund_scores(int printfundscores);
void pathmetric(char *string, int **scores);
void weighted_pathmetric(char *string, float **scores, int fund_num);
int unroottree(char * tree);
void alltrees_search(int user);
float compare_trees(int spr);
struct taxon * make_taxon(void);
void intTotree(int tree_num, char *array, int num_taxa);
int tree_build (int c, char *treestring, struct taxon *parent, int fromfile, int fund_num);
void prune_tree(struct taxon * super_pos, int fund_num);
int treeToInt(char *array);
int shrink_tree (struct taxon * position);
int print_pruned_tree(struct taxon * position, int count, char *pruned_tree, int fullname, int treenum);
void reset_tree(struct taxon * position);
int count_taxa(struct taxon * position, int count);
void check_tree(struct taxon * position, int tag_id, FILE *reconstructionfile);
int check_taxa(struct taxon * position);
int find_taxa(struct taxon * position, char *query);
int number_tree(struct taxon * position, int num);
void dismantle_tree(struct taxon * position);
void bootstrap_search(void);
void memory_error(int error_num);
void print_named_tree(struct taxon * position, char *tree);
void print_tree(struct taxon * position, char *tree);
int toint(char *number);
void reallocate_retained_supers(void);
void usertrees_search(void);
void heuristic_search(int user, int print, int sample, int nreps);
int average_consensus(int nrep, int missing_method, char * useroutfile, FILE *paupfile);
int do_search(char *tree, int user, int print, int maxswaps, FILE *outfile, int numspectries, int numgenetries);
int branchswap(int number_of_swaps, float score, int numspectries, int numgenetries);
int find_swaps(float * number, struct taxon * position, int number_of_swaps, int numspectries,int numgenetries);
void do_swap(struct taxon * first, struct taxon * second);
int swapper(struct taxon * position,struct taxon * prev_pos, int stepstaken, struct taxon * first_swap, struct taxon * second_swap, float * number, int * swaps, int number_of_swaps, int numspectries, int numgenetries);
void yaptp_search(void);
void randomise_tree(char *tree);
void randomise_taxa(char *tree);
void random_star_decom(char *tree);
int check_if_diff_tree(char *tree);
int coding(int nrep, int scoring, int ptpreps);
int MRP_matrix(char **trees, int num_trees, int consensus);
void set_parameters(void);
float MRC(char *supertree);
float quartet_compatibility(char *supertree);
void condense_coding(void);
void reset_spr (struct taxon *position);
int remaining_spr (struct taxon *position);
int spr(struct taxon * position, int maxswaps, int numspectries, int numgenetries);
int regraft(struct taxon * position, struct taxon * newbie, struct taxon * last, int steps, int maxswaps,int numspectries,int numgenetries);
void get_lengths(struct taxon *position);
int xposition1 (struct taxon *position, int count);
float middle_number(struct taxon *position);
void xposition2(struct taxon *position);
int yposition0(struct taxon *position, int level, int deepest);
int yposition1(struct taxon *position, int level);
void yposition2(struct taxon *position, int deepest);
void print_coordinates(struct taxon *position, char **treearray, int taxa_count, int mapping);
void tree_coordinates(char *tree, int bootstrap, int build, int mapping, int fundnum);
float tofloat(char *number);
void generatetrees(void);
void draw_histogram(FILE *outfile, int bins, float *results, int num_results);
void consensus(int num_trees, char **trees, int num_reps, float percentage, FILE *outfile, FILE *guidetreefile);
void input_fund_tree(char *intree, int fundnum);
int nexusparser(FILE *nexusfile);
void do_consensus(void);
int comment(FILE *file);
void showtrees(int savet);
void exclude(int do_all);
void returntree(char *temptree);
void returntree_fullnames(char *temptree, int treenum);
void quick(float ** items, int count);
void qs(float **items, int left, int right);
void include(int do_all);
void exclude_taxa(int do_all);
void sourcetree_dists();
void prune_taxa_for_exclude(struct taxon * super_pos, int *tobeexcluded);
void spr_dist(void);
int string_SPR(char * string); /* carries out random SPR operations on the tree */
void neighbor_joining( int brlens, char *tree, int names);
void nj(void);
void identify_taxa(struct taxon * position, int *name_array);
void reroot_tree(struct taxon *outgroup);
void clean_pointer_taxa(struct taxon *position);
struct taxon * get_branch(struct taxon *position, int name);
float tree_map(struct taxon * gene_top, struct taxon * species_top, int print);
int number_tree1(struct taxon * position, int num);
int number_tree2(struct taxon * position, int num);
void label_gene_tree(struct taxon * gene_position, struct taxon * species_top, int *presence, int xnum);
int get_min_node(struct taxon * position, int *presence, int num);
void subtree_id(struct taxon * position, int *tmp);
void descend(struct taxon * position, int *presence);
int reconstruct_map(struct taxon *position, struct taxon *species_top);
void add_losses(struct taxon * position, struct taxon *species_top);
int join_losses(struct taxon * position);
int count_losses(struct taxon * position);
struct taxon * construct_tree(struct taxon * spec_pos, struct taxon *gene_pos, int *presence, struct taxon *extra_gene);
int compress_tree (struct taxon * position);
int compress_tree1 (struct taxon * position);
struct taxon * get_taxon(struct taxon *position, int name);
void duplicate_tree(struct taxon * orig_pos, struct taxon * prev_dup_pos);
void find_tagged(struct taxon * position, int *presence);
void up_tree(struct taxon * position, int *presence);
void down_tree(struct taxon * position, struct taxon *prev, int *presence);
void mapunknowns();
void reconstruct(int print_settings);
void put_in_scores(struct taxon * position, float * total);
void assign_ances_desc(struct taxon *position, int ** allowed_species, int * previous);
void isittagged(struct taxon * position);
void hgt_reconstruction();
void assign_hgtdonors(struct taxon * position, int num, int part_num);
void reset_tag2(struct taxon * position);
int assign_tag2(struct taxon * position, int num);
void assign_before_after(struct taxon *position, int *previous, int *before, int *after, int num, int found);
struct taxon * find_remaining(struct taxon * position);
void exhaustive_SPR(char * string);
void print_tree_labels(struct taxon *position, int **results, int treenum, struct taxon *species_tree);
int count_internal_branches(struct taxon *position, int count);
float get_recon_score(char *giventree, int numspectries, int numgenetries);
void print_descendents(struct taxon *position, FILE *outfile);
void do_descendents(struct taxon *position, FILE *outfile);
void resolve_tricotomies(struct taxon *position, struct taxon *species_tree);
void gene_content_parsimony(struct taxon * position, int * array);
struct taxon * do_resolve_tricotomies(struct taxon * gene_tree, struct taxon * species_tree, int basescore);
int presence_of_trichotomies(struct taxon * position);
int are_siblings(struct taxon *position, int first, int second);
int isit_onetoone(struct taxon *position, int onetoone);
void print_onetoone_names(struct taxon *position, int onetoone);
int get_best_node(struct taxon * position, int *presence, int num);
void random_prune(char *fund_tree);
void collapse_clades(struct taxon * position, float user_limit, int * to_delete, FILE *rp_outfile);
int get_brlens(struct taxon * position, float *total, int *count);
float return_length(char *string);
int untag_taxa(struct taxon *position, int * to_delete, int keep, int count, FILE *rp_outfile);
int print_keep(struct taxon *position, int keep, int count, FILE *rp_outfile);
void resolve_tricotomies_dist (struct taxon * gene_tree, struct taxon *species_tree, int ** scores);
void get_taxa(struct taxon *position, int *presence);
void check_treeisok(struct taxon *position);
void pathmetric_internals(char *string, struct taxon * species_tree, int **scores);
void calculate_withins(struct taxon *position, int **within, int *presence);
long extract_length(char * fullname);
long list_taxa_in_clade(struct taxon * position, int * foundtaxa, struct taxon * longest, long seqlength); /* descend through the tree finding what taxa are there (and putting result into an array) and also identifying the longest sequence (the first number in the <<full>> name of the sequence, after the first "." and before the first "|") */
long list_taxa_above(struct taxon * position, int * foundtaxa, struct taxon * longest, long seqlength);
int identify_species_specific_clades(struct taxon * position, int numt, int *taxa_fate, int clannID);
void prune_monophylies();
void untag_nodes_below(struct taxon * position, int * taxa_fate, int clannID);
void untag_nodes_above(struct taxon * position, int * taxa_fate, int clannID);
void tips(int num);
void get_taxa_details(struct taxon *position);
void get_taxa_names(struct taxon *position, char **taxa_fate_names);
int basic_tree_build (int c, char *treestring, struct taxon *parent, int fullnames);
int sort_tree(struct taxon *position);
int spr_new(struct taxon * master, int maxswaps, int numspectries, int numgenetries);
void do_log(void);
void printf2(char *format, ...);
void print_splash(void);
void controlc1(int signal);
void controlc2(int signal);
void controlc3(int signal);
void controlc4(int signal);
void controlc5(int signal);
/****************** Global variable definitions ****************/
FILE * infile = NULL, *BR_file = NULL, *commands_file=NULL, *psfile = NULL, *logfile = NULL, *distributionreconfile = NULL, *onetoonefile = NULL, *strictonetoonefile = NULL, *tempoutfile = NULL;
char **taxa_names = NULL, *commands_filename = NULL, ***fulltaxanames = NULL, **parsed_command = NULL, **fundamentals = NULL, **stored_funds = NULL, **retained_supers = NULL, **stored_commands = NULL, *tempsuper = NULL, **best_topology = NULL, **tree_names = NULL;
int *numtaxaintrees = NULL, fullnamesnum = 0, fullnamesassignments = 1, fundamental_assignments = 0, tree_length_assignments = 1, parsed_command_assignments = 1, name_assignments = 0, *taxa_incidence = NULL, number_of_taxa = 0, Total_fund_trees = 0, *same_tree = NULL, **Cooccurrance = NULL, NUMSWAPS = 0;
int ***fund_scores = NULL, ***stored_fund_scores = NULL, **super_scores = NULL, *number_of_comparisons = NULL, *stored_num_comparisons = NULL, **presence_of_taxa = NULL, **stored_presence_of_taxa = NULL, *presenceof_SPRtaxa = NULL;
int seed, num_commands = 0, number_retained_supers = 10, number_of_steps = 3, largest_tree = 0, smallest_tree = 1000000, criterion = 0, parts = 0, **total_coding = NULL, *coding_from_tree = NULL, total_nodes = 0, quartet_normalising = 3, splits_weight = 2, dweight =1, *from_tree = NULL, method = 2, tried_regrafts = 0, hsprint = TRUE, max_name_length = NAME_LENGTH, got_weights = FALSE, num_excluded_trees = 0, num_excluded_taxa = 0, calculated_fund_scores = FALSE, select_longest=FALSE;
struct taxon *tree_top = NULL, *temp_top = NULL, *temp_top2 = NULL, *branchpointer = NULL, *longestseq = NULL;
float *scores_retained_supers = NULL, *partition_number = NULL, num_partitions = 0, total_partitions = 0, sprscore = -1, *best_topology_scores = NULL, **weighted_scores = NULL, *sourcetree_scores = NULL, *tree_weights = NULL;
float *score_of_bootstraps = NULL, *yaptp_results = NULL, largest_length = 0, dup_weight = 1, loss_weight = 1, hgt_weight = 1, BESTSCORE = -1;
time_t interval1, interval2;
double sup=1;
char saved_supertree[TREE_LENGTH], *test_array, inputfilename[10000], delimiter_char = '.', logfile_name[10000], system_call[100000];
int trees_in_memory = 0, *sourcetreetag = NULL, remainingtrees = 0, GC, user_break = FALSE, delimiter = FALSE, print_log = FALSE, num_gene_nodes, testarraypos = 0, taxaorder=0;
int malloc_check =0, count_now = FALSE, another_check =0;
int main(int argc, char *argv[])
{
int i = 0, j=0, k=0, l=0, m=0, error=FALSE, x, doexecute_command = FALSE, command_line = FALSE, tipnum=0, autocommands=FALSE;
char c, s, *command = NULL, *prev_command = NULL, HOME[1000], PATH[1000], exefilename[1000], string[10000];
time_t time1, time2;
double diff=0;
FILE *tmpclann = NULL;
exefilename[0] = '\0';
inputfilename[0] = '\0';
saved_supertree[0] = '\0';
logfile_name[0] = '\0';
strcpy(logfile_name, "clann.log");
system_call[0] ='\0';
test_array = malloc(TREE_LENGTH*sizeof(int));
test_array[0] = '\0';
/********** START OF READLINE STUFF ***********/
#ifdef HAVE_READLINE
if(command_line == FALSE)
{
PATH[0] ='\0'; HOME[0] = '\0';
system("echo $HOME > clann5361temp1023");
tmpclann = fopen("clann5361temp1023", "r");
fscanf(tmpclann, "%s", HOME);
fclose(tmpclann);
remove("clann5361temp1023");
strcpy(PATH, HOME);
strcat(PATH, "/.clannhistory");
read_history(PATH);
}
#endif
/********** END OF READLINE STUFF *************/
time1 = time(NULL);
/*seed the rand number with the calander time + the PID of the process ---- used for bootstrapping and others */
#ifdef HAVE_READLINE
seed=(int)((time(NULL)/2)+getpid());
srand((unsigned) (seed));
#else
seed=(int)(time(NULL)/2);
srand((unsigned) (seed));
#endif
command = malloc(1000000*sizeof(char));
if(!command) memory_error(74);
command[0] = '\0';
prev_command = malloc(1000000*sizeof(char));
if(!prev_command) memory_error(74);
prev_command[0] = '\0';
tempsuper = malloc(TREE_LENGTH*sizeof(char));
tempsuper[0] = '\0';
/** allocate the array to store multiple commands that are sepatated by ";" on the commandline */
stored_commands = malloc(100*sizeof(char *));
if(!stored_commands) memory_error(62);
for(i=0; i<100; i++)
{
stored_commands[i] = malloc(10000*sizeof(char));
if(!stored_commands[i]) memory_error(63);
stored_commands[i][0] = '\0';
}
/* allocate the array to hold the retained supertrees */
retained_supers = malloc(number_retained_supers*sizeof(char *));
if(!retained_supers) memory_error(45);
for(i=0; i<number_retained_supers; i++)
{
retained_supers[i] = malloc(TREE_LENGTH*sizeof(char));
if(!retained_supers[i]) memory_error(46);
retained_supers[i][0] = '\0';
}
scores_retained_supers = malloc(number_retained_supers*sizeof(float));
if(!scores_retained_supers) memory_error(47);
for(i=0; i<number_retained_supers; i++)
scores_retained_supers[i] = -1;
/* assign the parsed_command array */
parsed_command = malloc(10000*sizeof(char *));
for(i=0; i<10000; i++)
{
parsed_command[i] = malloc(10000*sizeof(char));
parsed_command[i][0] = '\0';
}
if(argc > 1)
{
while ((c = getopt(argc, argv, "nlhc:")) != -1)
{
switch (c)
{
case 'n':
command_line = TRUE;
printf("\nNon-Internactive mode entered - commands must be provided in a nexus \'clann block\' or with \'-c\'\n");
break;
case 'l':
printf2("opening logfile %s\n", logfile_name);
if((logfile = fopen(logfile_name, "w")) == NULL)
{
printf2("Error opening log file named %s\n", logfile_name);
}
else
{
printf2("starting logging to logfile %s\n", logfile_name );
print_log = TRUE;
}
break;
case 'c':
commands_filename = optarg;
printf2("opening commands file %s\n", commands_filename);
if((commands_file = fopen(commands_filename, "r")) == NULL)
{
printf2("Error opening commands file named %s\n", commands_filename);
}
else
{
s = getc(commands_file);
while(!feof(commands_file) && !error)
{
i=0;
while((s == ' ' || s == '\n' || s == '\r' || s == '\t' || s == ';') && !feof(commands_file)) s = getc(commands_file);
if(s == '#') /* skip over lines that start with a '#' -- this allows the user to add comments */
{
while(!feof(commands_file) && s != '\n' && s != '\r') s = getc(commands_file);
}
while(s != ';' && s != '\n' && !feof(commands_file)) /* commands can finish with a ';' or a newline character */
{
string[i] = s;
i++;
s = getc(commands_file);
}
string[i] = ';';
string[i+1] = '\0';
strcpy(stored_commands[parts], string);
parts++;
}
autocommands=TRUE; /* this is used indicate that we need to print the commands both to screen and log, as otherwise they will not appear */
fclose(commands_file);
}
break;
case 'h':
print_splash();
printf("\nUsage: \"clann -lnh [-c commands file] [tree file]\"\n");
printf("\n\tWhere [tree file] is an optional Nexus or Phylip formatted file of phylogenetic trees\n");
printf("\t-l turn on logging of screen output to file \"clann.log\"\n");
printf("\t-n turns off interactive mode - requires commands to be provided in a nexus \'clann block\' or with \'-c\'\n");
printf("\t-c <file name> specifies a file with commands to be executed (one command per line)\n");
printf("\t-h prints this message\n\n");
print_commands(0);
clean_exit(0);
break;
}
}
for (i = optind; i < argc; i++)
{
doexecute_command = TRUE;
strcpy(exefilename, argv[i]);
}
}
if(command_line == TRUE)
{
strcpy(stored_commands[parts], "quit");
parts++;
}
print_splash(); /* Print the Clann splash screen */
if(doexecute_command) /* if the user has specified an input file at the command line */
{
execute_command(exefilename, TRUE);
}
i=0;
while(strcmp(parsed_command[0], "quit") != 0) /* while the user has not chosen to quit */
{
if(num_commands > 0)
{
if(print_log && strcmp(command, "") != 0)
{
fprintf(logfile, "clann> %s\n", command);
if(autocommands==TRUE) printf("clann> %s\n", command);
}
if(strcmp(parsed_command[0], "execute") == 0 || strcmp(parsed_command[0], "exe") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(1);
else
{
if(num_commands > 1)
{
delimiter = FALSE;
execute_command(parsed_command[1], TRUE);
/* test fulltaxaname allocations */
/*for(l=0; l<Total_fund_trees; l++)
{
printf2("fund tree number: %d\n", l);
for(m=0; m<numtaxaintrees[l]; m++)
{
printf2("\ttaxa %d: %s\n", m, fulltaxanames[l][m]);
}
}
printf2("here\n"); */
/*spr_dist(); */
}
}
}
else
{
if(strcmp(parsed_command[0], "help") == 0)
{
print_commands(0);
}
else
{
if(strcmp(parsed_command[0], "alltrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(2);
else
{
if(number_of_taxa > 0)
{
if(criterion == 0 || criterion == 2 || criterion == 3) /** MRP or MSS or QC **/
alltrees_search(TRUE);
else
{
BR_file = fopen("coding.nex", "w");
x = coding(0, 0, 0);
fclose(BR_file);
if(x == FALSE)
{
if(print_log == FALSE)
strcpy(system_call, "paup coding.nex");
else
{
strcpy(system_call, "paup coding.nex");
strcat(system_call, " | tee -a ");
strcat(system_call, logfile_name);
}
if(system(system_call) != 0) printf2("Error calling paup, please execute the file coding.nex in paup to perform the parsimony step\n");
}
if(x == FALSE)
{
remove("clanntmp.chr");
remove("clanntree.chr");
/*pars("coding.nex", "clanntmp.chr"); */
remove("clanntmp.chr");
remove("clanntree.chr");
}
}
}
else
{
printf2("Error: You need to load source trees before using this command\n");
}
}
}
else
{
if(strcmp(parsed_command[0], "usertrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(3);
else
{
if(number_of_taxa > 0)
{
if(criterion == 1)
printf2("Error: You cannont do a user tree search in MRP\n");
else
usertrees_search();
}
else
{
printf2("Error: You need to load source trees before using this command\n");
}
}
}
else
{
if(strcmp(parsed_command[0], "hs") == 0 || strcmp(parsed_command[0], "hsearch") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(4);
else
{
if(number_of_taxa > 0)
{
heuristic_search(TRUE, TRUE, 10000, 10);
}
else
{
printf2("Error: You need to load source trees before using this command\n");
}
}
}
else
{
if(strcmp(parsed_command[0], "bootstrap") == 0 || strcmp(parsed_command[0], "boot") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(5);
else
{
if(number_of_taxa > 0)
{
bootstrap_search();
}
else
{
printf2("Error: You need to load source trees before using this command\n");
}
}
}
else
{
if(strcmp(parsed_command[0], "yaptp") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(6);
else
{
if(number_of_taxa > 0)
{
yaptp_search();
}
else
{
printf2("Error: You need to load source trees before using this command\n");
}
}
}
else
{
if(strcmp(parsed_command[0], "ideal") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(7);
else
{
if(number_of_taxa > 0)
{
/* ideal_search(); */
}
else
{
printf2("Error: You need to load source trees before using this command\n");
}
}
}
else
{
if(strcmp(parsed_command[0], "set") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(8);
else
set_parameters();
}
else
{
if(strcmp(parsed_command[0], "quit") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
{
print_commands(13);
strcpy(parsed_command[0], "hi");
}
}
else
{
if(strcmp(parsed_command[0], "deletetrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(17);
else
{
if(number_of_taxa > 0)
exclude(TRUE);
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "1includetrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(18);
else
{
if(number_of_taxa > 0)
include(TRUE);
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "!") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(12);
else
{
printf2("\n\tType exit to return to Clann\n\n");
system("bash");
}
}
else
{
if(strcmp(parsed_command[0], "generatetrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(14);
else
{
if(number_of_taxa > 0)
generatetrees();
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "showtrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(16);
else
{
if(number_of_taxa > 0)
showtrees(FALSE);
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "rfdists") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(19);
else
{
if(number_of_taxa > 0)
sourcetree_dists();
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "deletetaxa") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(20);
else
{
if(number_of_taxa > 0)
{
exclude_taxa(TRUE);
}
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "consensus") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(15);
else
{
if(number_of_taxa > 0)
do_consensus();
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "nj") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(21);
else
{
if(number_of_taxa > 0)
nj();
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "sprdists") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(22);
else
{
if(number_of_taxa > 0)
spr_dist();
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "mapunknowns") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(23);
else
{
if(number_of_taxa > 0)
mapunknowns();
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "reconstruct") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(24);
else
{
if(number_of_taxa > 0)
reconstruct(TRUE);
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "hgtanalysis") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(23);
else
{
if(number_of_taxa > 0)
hgt_reconstruction();
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "exhaustivespr") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(23);
else
{
if(number_of_taxa > 0)
exhaustive_SPR(fundamentals[0]);
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "pars") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(23);
else
{
if(number_of_taxa > 0)
{
remove("clanntmp.chr");
remove("clanntree.chr");
/*pars();*/
remove("clanntmp.chr");
remove("clanntree.chr");
}
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "randomisetrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(27);
else
{
if(number_of_taxa > 0)
{
for(j=0; j<Total_fund_trees; j++)
{
randomise_tree(fundamentals[j]); /*equiprobable */
}
printf2("The source trees have now been randomised\n");
}
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "randomprune") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(28);
else
{
if(number_of_taxa > 0)
{
for(j=0; j<Total_fund_trees; j++)
{
random_prune(fundamentals[j]); /*equiprobable */
}
}
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "prunemonophylies") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(25);
else
{
if(number_of_taxa > 0)
{
prune_monophylies();
}
else
printf2("Error: You need to load source trees before using this command\n");
}
}
else
{
if(strcmp(parsed_command[0], "tips") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(26);
else
{
if(num_commands == 2 && (tipnum = atoi(parsed_command[1])) > 0 && tipnum < 11)
tips(tipnum-1);
else
tips((int)fmod(rand(), 10));
}
}
else
{
if(strcmp(parsed_command[0], "log") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(29);
else
{
do_log();
}
}
else
{
if(strcmp(parsed_command[0], "savetrees") == 0)
{
if(num_commands == 2 && parsed_command[1][0] == '?')
print_commands(30);
else
{
if(number_of_taxa > 0)
showtrees(TRUE);
else
{
printf2("Error: You need to load source trees before using this command\n");
}
}
}
else
printf2("Error: command not known.\n\tType help at the prompt to get a list of available commands.\n");
}
}
}
}
}
}
}
}
}
}
}
}
}