-
Notifications
You must be signed in to change notification settings - Fork 192
/
axml.c
14213 lines (11484 loc) · 400 KB
/
axml.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
/* RAxML-VI-HPC (version 2.2) a program for sequential and parallel estimation of phylogenetic trees
* Copyright August 2006 by Alexandros Stamatakis
*
* Partially derived from
* fastDNAml, a program for estimation of phylogenetic trees from sequences by Gary J. Olsen
*
* and
*
* Programs of the PHYLIP package by Joe Felsenstein.
*
* This program is free software; you may redistribute it and/or modify its
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program 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.
*
*
* For any other enquiries send an Email to Alexandros Stamatakis
*
* When publishing work that is based on the results from RAxML-VI-HPC please cite:
*
* Alexandros Stamatakis:"RAxML-VI-HPC: maximum likelihood-based phylogenetic analyses with thousands of taxa and mixed models".
* Bioinformatics 2006; doi: 10.1093/bioinformatics/btl446
*/
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN // skips unwanted headers like socket etc.
#include <windows.h>
#include <direct.h>
#endif
#ifndef WIN32
#include <sys/times.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <time.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <inttypes.h>
#include <getopt.h>
//#include <stdbool.h>
#if (defined(_WAYNE_MPI) || defined (_QUARTET_MPI))
#include <mpi.h>
#endif
#ifdef _USE_PTHREADS
#include <pthread.h>
#endif
#if ! (defined(__ppc) || defined(__powerpc__) || defined(__POWERPC__) || defined(PPC) || defined(__aarch64__))
#include <xmmintrin.h>
/*
special bug fix, enforces denormalized numbers to be flushed to zero,
without this program is a tiny bit faster though.
#include <emmintrin.h>
#define MM_DAZ_MASK 0x0040
#define MM_DAZ_ON 0x0040
#define MM_DAZ_OFF 0x0000
*/
#elif __aarch64__
#include "sse2neon.h"
#endif
#include "axml.h"
#include "globalVariables.h"
#define _PORTABLE_PTHREADS
/***************** UTILITY FUNCTIONS **************************/
double FABS(double x)
{
/* if(x < -1.0E-10)
assert(0);*/
/* if(x < 0.0)
printf("%1.40f\n", x); */
return fabs(x);
}
FILE *getNumberOfTrees(tree *tr, char *fileName, analdef *adef)
{
FILE
*f = myfopen(fileName, "r");
int
trees = 0,
ch;
while((ch = fgetc(f)) != EOF)
if(ch == ';')
trees++;
assert(trees > 0);
tr->numberOfTrees = trees;
if(!adef->allInOne)
printBothOpen("\n\nFound %d trees in File %s\n\n", trees, fileName);
rewind(f);
return f;
}
static void checkStdoutFlush(void)
{
/* If stdout is redirected, other processes monitoring RAxML's output
(e.g., via tail, or a pipe) do not receive any standard output until
stdio gets around to flushing the file, which may be a long time.
To provide more continuous feeding of RAxML output to these processes,
we force a flush of the stdout stream once per second.
(Dave Swofford 16july2016)
*/
static clock_t
lastFlush;
clock_t
now = clock();
if(now - lastFlush > CLOCKS_PER_SEC)
{
fflush(stdout);
lastFlush = now;
}
}
static void printBoth(FILE *f, const char* format, ... )
{
va_list args;
va_start(args, format);
vfprintf(f, format, args );
va_end(args);
va_start(args, format);
vprintf(format, args );
va_end(args);
checkStdoutFlush();
}
void printBothOpen(const char* format, ... )
{
#ifdef _QUARTET_MPI
if(processID == 0)
#endif
{
FILE *f = myfopen(infoFileName, "ab");
va_list args;
va_start(args, format);
vfprintf(f, format, args );
va_end(args);
va_start(args, format);
vprintf(format, args );
va_end(args);
checkStdoutFlush();
fclose(f);
}
}
void printBothOpenMPI(const char* format, ... )
{
#ifdef _WAYNE_MPI
if(processID == 0)
#endif
{
FILE *f = myfopen(infoFileName, "ab");
va_list args;
va_start(args, format);
vfprintf(f, format, args );
va_end(args);
va_start(args, format);
vprintf(format, args );
va_end(args);
checkStdoutFlush();
fclose(f);
}
}
boolean getSmoothFreqs(int dataType)
{
assert(MIN_MODEL < dataType && dataType < MAX_MODEL);
return pLengths[dataType].smoothFrequencies;
}
const unsigned int *getBitVector(int dataType)
{
assert(MIN_MODEL < dataType && dataType < MAX_MODEL);
return pLengths[dataType].bitVector;
}
int getStates(int dataType)
{
assert(MIN_MODEL < dataType && dataType < MAX_MODEL);
return pLengths[dataType].states;
}
unsigned char getUndetermined(int dataType)
{
assert(MIN_MODEL < dataType && dataType < MAX_MODEL);
return pLengths[dataType].undetermined;
}
char getInverseMeaning(int dataType, unsigned char state)
{
assert(MIN_MODEL < dataType && dataType < MAX_MODEL);
return pLengths[dataType].inverseMeaning[state];
}
partitionLengths *getPartitionLengths(pInfo *p)
{
int
dataType = p->dataType,
states = p->states,
tipLength = p->maxTipStates;
assert(states != -1 && tipLength != -1);
assert(MIN_MODEL < dataType && dataType < MAX_MODEL);
pLength.leftLength = pLength.rightLength = states * states;
pLength.eignLength = states -1;
pLength.evLength = states * states;
pLength.eiLength = states * states - states;
pLength.substRatesLength = (states * states - states) / 2;
pLength.frequenciesLength = states;
pLength.tipVectorLength = tipLength * states;
pLength.symmetryVectorLength = (states * states - states) / 2;
pLength.frequencyGroupingLength = states;
pLength.nonGTR = FALSE;
//pLength.optimizeBaseFrequencies = FALSE;
return (&pLengths[dataType]);
}
static boolean isCat(analdef *adef)
{
if(adef->model == M_PROTCAT || adef->model == M_GTRCAT || adef->model == M_BINCAT || adef->model == M_32CAT || adef->model == M_64CAT)
return TRUE;
else
return FALSE;
}
static boolean isGamma(analdef *adef)
{
if(adef->model == M_PROTGAMMA || adef->model == M_GTRGAMMA || adef->model == M_BINGAMMA ||
adef->model == M_32GAMMA || adef->model == M_64GAMMA)
return TRUE;
else
return FALSE;
}
static int stateAnalyzer(tree *tr, int model, int maxStates)
{
boolean
counter[256],
previous,
inputError = FALSE;
int
lower = tr->partitionData[model].lower,
upper = tr->partitionData[model].upper,
i,
j,
states = 0;
for(i = 0; i < 256; i++)
counter[i] = FALSE;
for(i = 0; i < tr->rdta->numsp; i++)
{
unsigned char *yptr = &(tr->rdta->y0[((size_t)i) * ((size_t)tr->originalCrunchedLength)]);
for(j = lower; j < upper; j++)
if(yptr[j] != getUndetermined(GENERIC_32))
counter[yptr[j]] = TRUE;
}
for(i = 0; i < maxStates; i++)
{
if(counter[i])
states++;
}
previous = counter[0];
for(i = 1; i < 256; i++)
{
if(previous == FALSE && counter[i] == TRUE)
{
inputError = TRUE;
break;
}
else
{
if(previous == TRUE && counter[i] == FALSE)
previous = FALSE;
}
}
if(inputError)
{
printf("Multi State Error, characters must be used in the order they are available, i.e.\n");
printf("0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V\n");
printf("You are using the following characters: \n");
for(i = 0; i < 256; i++)
if(counter[i])
printf("%c ", inverseMeaningGeneric32[i]);
printf("\n");
exit(-1);
}
return states;
}
static void setRateHetAndDataIncrement(tree *tr, analdef *adef)
{
int model;
if(isCat(adef))
tr->rateHetModel = CAT;
else
{
if(adef->useInvariant)
tr->rateHetModel = GAMMA_I;
else
tr->rateHetModel = GAMMA;
}
switch(tr->rateHetModel)
{
case GAMMA:
case GAMMA_I:
tr->discreteRateCategories = 4;
break;
case CAT:
if((adef->boot && !adef->bootstrapBranchLengths) || (adef->mode == CLASSIFY_ML) || (tr->catOnly))
tr->discreteRateCategories = 1;
else
tr->discreteRateCategories = 4;
break;
default:
assert(0);
}
if(adef->bootstrapBranchLengths)
assert(tr->discreteRateCategories == 4);
for(model = 0; model < tr->NumberOfModels; model++)
{
int
states = -1,
maxTipStates = getUndetermined(tr->partitionData[model].dataType) + 1;
switch(tr->partitionData[model].dataType)
{
case BINARY_DATA:
case DNA_DATA:
case AA_DATA:
case SECONDARY_DATA:
case SECONDARY_DATA_6:
case SECONDARY_DATA_7:
states = getStates(tr->partitionData[model].dataType);
break;
case GENERIC_32:
case GENERIC_64:
states = stateAnalyzer(tr, model, getStates(tr->partitionData[model].dataType));
break;
default:
assert(0);
}
tr->partitionData[model].states = states;
tr->partitionData[model].maxTipStates = maxTipStates;
}
}
double gettime(void)
{
#ifdef WIN32 // WINDOWS build
FILETIME tm;
ULONGLONG t;
#if defined(NTDDI_WIN8) && NTDDI_VERSION >= NTDDI_WIN8 // >= WIN8
GetSystemTimePreciseAsFileTime( &tm );
#else // < WIN8
GetSystemTimeAsFileTime( &tm );
#endif
t = ((ULONGLONG)tm.dwHighDateTime << 32) | (ULONGLONG)tm.dwLowDateTime;
return (double)t / 10000000.0;
#else // Unixoid build
struct timeval ttime;
gettimeofday(&ttime , NULL);
return ttime.tv_sec + ttime.tv_usec * 0.000001;
#endif
}
double randum (int64_t *seed)
{
int64_t sum, mult0, mult1, seed0, seed1, seed2, newseed0, newseed1, newseed2;
double res;
mult0 = 1549;
seed0 = *seed & 4095;
sum = mult0 * seed0;
newseed0 = sum & 4095;
sum >>= 12;
seed1 = (*seed >> 12) & 4095;
mult1 = 406;
sum += mult0 * seed1 + mult1 * seed0;
newseed1 = sum & 4095;
sum >>= 12;
seed2 = (*seed >> 24) & 255;
sum += mult0 * seed2 + mult1 * seed1;
newseed2 = sum & 255;
*seed = newseed2 << 24 | newseed1 << 12 | newseed0;
res = 0.00390625 * (newseed2 + 0.000244140625 * (newseed1 + 0.000244140625 * newseed0));
return res;
}
int filexists(char *filename)
{
FILE *fp;
int res;
fp = fopen(filename,"rb");
if(fp)
{
res = 1;
fclose(fp);
}
else
res = 0;
return res;
}
FILE *myfopen(const char *path, const char *mode)
{
FILE *fp = fopen(path, mode);
if(strcmp(mode,"r") == 0 || strcmp(mode,"rb") == 0)
{
if(fp)
return fp;
else
{
if(processID == 0)
printf("The file %s you want to open for reading does not exist, exiting ...\n", path);
errorExit(-1);
return (FILE *)NULL;
}
}
else
{
if(fp)
return fp;
else
{
if(processID == 0)
printf("The file %s RAxML wants to open for writing or appending can not be opened [mode: %s], exiting ...\n",
path, mode);
errorExit(-1);
return (FILE *)NULL;
}
}
}
/********************* END UTILITY FUNCTIONS ********************/
/******************************some functions for the likelihood computation ****************************/
boolean isTip(int number, int maxTips)
{
assert(number > 0);
if(number <= maxTips)
return TRUE;
else
return FALSE;
}
void getxnode (nodeptr p)
{
nodeptr s;
if ((s = p->next)->x || (s = s->next)->x)
{
p->x = s->x;
s->x = 0;
}
assert(p->x);
}
void hookup (nodeptr p, nodeptr q, double *z, int numBranches)
{
int i;
p->back = q;
q->back = p;
for(i = 0; i < numBranches; i++)
p->z[i] = q->z[i] = z[i];
#ifdef _BASTIEN
for(i = 0; i < numBranches; i++)
p->secondDerivativeValid[i] = q->secondDerivativeValid[i] = FALSE;
#endif
}
void hookupDefault (nodeptr p, nodeptr q, int numBranches)
{
int i;
p->back = q;
q->back = p;
for(i = 0; i < numBranches; i++)
p->z[i] = q->z[i] = defaultz;
#ifdef _BASTIEN
for(i = 0; i < numBranches; i++)
p->secondDerivativeValid[i] = q->secondDerivativeValid[i] = FALSE;
#endif
}
/***********************reading and initializing input ******************/
static void rax_getline_insptr_valid(char **lineptr, size_t *n, size_t ins_ptr )
{
const size_t
n_inc = 1024;
if(ins_ptr >= *n)
{
assert( *n <= (SSIZE_MAX - n_inc));
*n += n_inc;
*lineptr = (char*)rax_realloc((void*)(*lineptr), *n * sizeof(char), FALSE);
assert(*lineptr != 0);
}
}
ssize_t rax_getline(char **lineptr, size_t *n, FILE *h)
{
size_t
ins_ptr = 0;
/* this implementation does not conform to the standard regarding error checking (i.e., asserts on errors ) */
assert(h != (FILE*)NULL);
if(*lineptr == (char *)NULL)
*n = 0;
while(1)
{
int
c = fgetc(h);
/* handle EOF: if no character has been read on the current line throw an error.
Otherwise treat as end-of-line. Don't know if this is correct,
as I don't have the POSIX standard and the linux manpage is unclear. */
if(c == EOF)
{
if(ins_ptr == 0)
return -1;
else
c = '\n';
//break;
}
if(c == '\r')
{
//this is the original GNU implementation
/* windows line-end: must be followed by a '\n'. Don't tolerate anything else. */
//c = fgetc(h);
//assert(c == '\n');
//fixed to essentialy replace windows line endings by '\n'
c = '\n';
}
/* insert character (including '\n') into buffer */
rax_getline_insptr_valid(lineptr, n, ins_ptr);
(*lineptr)[ins_ptr] = c;
++ins_ptr;
if(c == '\n')
break;
}
/* null-terminate */
rax_getline_insptr_valid( lineptr, n, ins_ptr );
(*lineptr)[ins_ptr] = 0;
return ((ssize_t)ins_ptr);
}
static void getnums (rawdata *rdta, analdef *adef)
{
if(fscanf(INFILE, "%d %d", & rdta->numsp, & rdta->sites) != 2)
{
char
*line = NULL;
size_t
len = 0;
ssize_t
read;
int
sequenceLength = 0,
sequences = 0,
taxa = 0,
sites =0;
if(processID == 0)
{
printf("\nRAxML can't, parse the alignment file as phylip file \n");
printf("it will now try to parse it as FASTA file\n\n");
}
while((read = rax_getline(&line, &len, INFILE)) != -1)
{
ssize_t
i = 0;
while((i < read - 1) && (line[i] == ' ' || line[i] == '\t'))
i++;
if(line[i] == '>')
{
if(taxa == 1)
sequenceLength = sites;
if(taxa > 0)
{
if(sites == 0 && processID == 0)
{
printf("Fasta parsing error, RAxML was expecting sequence data before: %s\n", line);
errorExit(-1);
}
assert(sites > 0);
sequences++;
}
if(taxa > 0)
{
if(sequenceLength != sites && processID == 0)
{
printf("Fasta parsing error, RAxML expects an alignment.\n");
printf("the sequence before taxon %s: seems to have a different length\n", line);
errorExit(-1);
}
assert(sequenceLength == sites);
}
taxa++;
sites = 0;
}
else
{
while(i < read - 1)
{
if(!(line[i] == ' ' || line[i] == '\t'))
{
sites++;
}
i++;
}
//printf("sites %d %s\n", sites, line);
}
}
if(sites > 0)
sequences++;
if(taxa != sequences && processID == 0)
{
printf("Fasta parsing error, the number of taxa %d and sequences %d are not equal!\n", taxa, sequences);
errorExit(-1);
}
assert(taxa == sequences);
if(sequenceLength != sites && processID == 0)
{
printf("Fasta parsing error, RAxML expects an alignment.\n");
printf("the last sequence in the alignment seems to have a different length\n");
errorExit(-1);
}
assert(sites == sequenceLength);
if(line)
rax_free(line);
rewind(INFILE);
adef->alignmentFileType = FASTA;
rdta->numsp = taxa;
rdta->sites = sites;
}
if (rdta->numsp < 4)
{
if(processID == 0)
printf("TOO FEW SPECIES\n");
errorExit(-1);
}
if (rdta->sites < 1)
{
if(processID == 0)
printf("TOO FEW SITES\n");
errorExit(-1);
}
return;
}
boolean whitechar (int ch)
{
return (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r');
}
static void uppercase (int *chptr)
{
int ch;
ch = *chptr;
if ((ch >= 'a' && ch <= 'i') || (ch >= 'j' && ch <= 'r')
|| (ch >= 's' && ch <= 'z'))
*chptr = ch + 'A' - 'a';
}
static void getyspace (rawdata *rdta)
{
size_t size = 4 * ((size_t)(rdta->sites / 4 + 1));
int i;
unsigned char *y0;
rdta->y = (unsigned char **) rax_malloc((rdta->numsp + 1) * sizeof(unsigned char *));
assert(rdta->y);
y0 = (unsigned char *) rax_malloc(((size_t)(rdta->numsp + 1)) * size * sizeof(unsigned char));
assert(y0);
rdta->y0 = y0;
for (i = 0; i <= rdta->numsp; i++)
{
rdta->y[i] = y0;
y0 += size;
}
return;
}
static unsigned int KISS32(void)
{
static unsigned int
x = 123456789,
y = 362436069,
z = 21288629,
w = 14921776,
c = 0;
unsigned int t;
x += 545925293;
y ^= (y<<13);
y ^= (y>>17);
y ^= (y<<5);
t = z + w + c;
z = w;
c = (t>>31);
w = t & 2147483647;
return (x+y+w);
}
static boolean setupTree (tree *tr, analdef *adef)
{
nodeptr p0, p, q;
int
i,
j,
tips,
inter;
tr->storedBrLens = (double*)NULL;
if(!adef->readTaxaOnly)
{
tr->bigCutoff = FALSE;
tr->patternPosition = (int*)NULL;
tr->columnPosition = (int*)NULL;
tr->maxCategories = MAX(4, adef->categories);
tr->partitionContributions = (double *)rax_malloc(sizeof(double) * tr->NumberOfModels);
for(i = 0; i < tr->NumberOfModels; i++)
tr->partitionContributions[i] = -1.0;
tr->perPartitionLH = (double *)rax_malloc(sizeof(double) * tr->NumberOfModels);
tr->storedPerPartitionLH = (double *)rax_malloc(sizeof(double) * tr->NumberOfModels);
for(i = 0; i < tr->NumberOfModels; i++)
{
tr->perPartitionLH[i] = 0.0;
tr->storedPerPartitionLH[i] = 0.0;
}
if(adef->grouping)
tr->grouped = TRUE;
else
tr->grouped = FALSE;
if(adef->constraint)
tr->constrained = TRUE;
else
tr->constrained = FALSE;
tr->treeID = 0;
}
tips = tr->mxtips;
inter = tr->mxtips - 1;
if(!adef->readTaxaOnly)
{
tr->yVector = (unsigned char **) rax_malloc((tr->mxtips + 1) * sizeof(unsigned char *));
tr->likelihoods = (double *)rax_malloc(adef->multipleRuns * sizeof(double));
}
tr->numberOfTrees = -1;
tr->treeStringLength =
2 * (size_t)tr->mxtips + //parentheses
2 * (size_t)tr->mxtips * 64 + //branche lengths with : and . and branch labels and
(size_t)tr->mxtips + //commas
1 + //closing semicolon
(size_t)tr->mxtips * nmlngth; //taxon names
//tr->treeStringLength = tr->mxtips * (nmlngth+128) + 256 + tr->mxtips * 2;
//printf("tips %d Tree String Length %d old length %d\n", tr->mxtips, tr->treeStringLength,tr->mxtips * (nmlngth+128) + 256 + tr->mxtips * 2 );
tr->tree_string = (char*)rax_calloc(tr->treeStringLength, sizeof(char));
if(!adef->readTaxaOnly)
{
tr->td[0].count = 0;
tr->td[0].ti = (traversalInfo *)rax_malloc(sizeof(traversalInfo) * tr->mxtips);
tr->constraintVector = (int *)rax_malloc((2 * tr->mxtips) * sizeof(int));
tr->nameList = (char **)rax_malloc(sizeof(char *) * (tips + 1));
}
if (!(p0 = (nodeptr) rax_malloc((tips + 3*inter) * sizeof(node))))
{
printf("ERROR: Unable to obtain sufficient tree memory\n");
return FALSE;
}
if (!(tr->nodep = (nodeptr *) rax_malloc((2*tr->mxtips) * sizeof(nodeptr))))
{
printf("ERROR: Unable to obtain sufficient tree memory, too\n");
return FALSE;
}
tr->nodep[0] = (node *) NULL; /* Use as 1-based array */
for (i = 1; i <= tips; i++)
{
p = p0++;
p->hash = KISS32(); /* hast table stuff */
p->x = 0;
p->number = i;
p->next = p;
p->back = (node *)NULL;
p->bInf = (branchInfo *)NULL;
tr->nodep[i] = p;
}
for (i = tips + 1; i <= tips + inter; i++)
{
q = (node *) NULL;
for (j = 1; j <= 3; j++)
{