1 /*
2  *  MrBayes 3
3  *
4  *  (c) 2002-2013
5  *
6  *  John P. Huelsenbeck
7  *  Dept. Integrative Biology
8  *  University of California, Berkeley
9  *  Berkeley, CA 94720-3140
10  *  johnh@berkeley.edu
11  *
12  *  Fredrik Ronquist
13  *  Swedish Museum of Natural History
14  *  Box 50007
15  *  SE-10405 Stockholm, SWEDEN
16  *  fredrik.ronquist@nrm.se
17  *
18  *  With important contributions by
19  *
20  *  Paul van der Mark (paulvdm@sc.fsu.edu)
21  *  Maxim Teslenko (maxkth@gmail.com)
22  *  Chi Zhang (zhangchicool@gmail.com)
23  *
24  *  and by many users (run 'acknowledgments' to see more info)
25  *
26  * This program is free software; you can redistribute it and/or
27  * modify it under the terms of the GNU General Public License
28  * as published by the Free Software Foundation; either version 2
29  * of the License, or (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34  * GNU General Public License for more details (www.gnu.org).
35  *
36  */
37 
38 #include "bayes.h"
39 #include "best.h"
40 #include "command.h"
41 #include "model.h"
42 #include "mcmc.h"
43 #include "proposal.h"
44 #include "sumpt.h"
45 #include "utils.h"
46 #if defined(__MWERKS__)
47 #include "SIOUX.h"
48 #endif
49 
50 #undef  DEBUG_ADDDUMMYCHARS
51 #undef  DEBUG_CONSTRAINTS
52 #undef  DEBUG_COMPRESSDATA
53 #undef  DEBUG_CPP
54 
55 /* local prototypes */
56 int       AddDummyChars (void);
57 void      AllocateCppEvents (Param *p);
58 MCMCMove *AllocateMove (MoveType *moveType, Param *param);
59 int       AllocateNormalParams (void);
60 int       AllocateTreeParams (void);
61 void      CheckCharCodingType (Matrix *m, CharInfo *ci);
62 int       CheckExpandedModels (void);
63 int       CompressData (void);
64 int       InitializeChainTrees (Param *p, int from, int to, int isRooted);
65 int       FillBrlensSubParams (Param *param, int chn, int state);
66 void      FreeCppEvents (Param *p);
67 void      FreeMove (MCMCMove *mv);
68 void      GetPossibleAAs (int aaCode, int aa[]);
69 void      GetPossibleNucs (int nucCode, int nuc[]);
70 void      GetPossibleRestrictionSites (int resSiteCode, int *sites);
71 int       GetUserTreeFromName (int *index, char *treeName);
72 void      InitializeMcmcTrees (Param *p);
73 int       IsApplicable (Param *param);
74 int       IsApplicable_FiveTaxaOrMore (Param *param);
75 int       IsApplicable_FourTaxaOrMore (Param *param);
76 int       IsApplicable_ThreeTaxaOrMore (Param *param);
77 int       IsApplicable_TreeAgeMove (Param *param);
78 int       IsModelSame (int whichParam, int part1, int part2, int *isApplic1, int *isApplic2);
79 int       LargestMovableSubtree(Param *treeParam);
80 int       NumActiveParts (void);
81 int       NumInformativeHardConstraints (ModelParams *mp);
82 int       NumNonExcludedChar (void);
83 int       NumStates (int part);
84 int       PrintCompMatrix (void);
85 int       PrintMatrix (void);
86 int       ProcessStdChars (RandLong *seed);
87 void      SetCode (int part);
88 int       SetModelParams (void);
89 int       SetPopSizeParam (Param *param, int chn, int state, PolyTree *pt);
90 int       SetRelaxedClockParam (Param *param, int chn, int state, PolyTree *pt);
91 int       SetUpLinkTable (void);
92 int       ShowMoves (int used);
93 int       ShowParameters (int showStartVals, int showMoves, int showAllAvailable);
94 int       UpdateCppEvolLength (int *nEvents, MrBFlt **pos, MrBFlt **rateMult, MrBFlt *evolLength, TreeNode *p, MrBFlt baseRate);
95 
96 /* globals */
97 int             *activeParams[NUM_LINKED];              /* a table holding the parameter link status        */
98 int             localOutGroup;                          /* outgroup for non-excluded taxa                   */
99 Calibration     **localTaxonCalibration = NULL;         /* stores local taxon calibrations (ages)           */
100 char            **localTaxonNames = NULL;               /* points to names of non-excluded taxa             */
101 Model           *modelParams;                           /* holds model params                               */
102 ModelInfo       *modelSettings;                         /* stores important info on model params            */
103 MCMCMove        **moves;                                /* vector of pointers to applicable moves           */
104 int             numApplicableMoves;                     /* number of moves applicable to model parameters   */
105 int             numCurrentDivisions;                    /* number of partitions of data                     */
106 int             numGlobalChains;                        /* number of global chains                          */
107 int             numLocalTaxa;                           /* number of non-excluded taxa                      */
108 int             numLocalChar;                           /* number of non-excluded characters                */
109 int             numParams;                              /* number of parameters in model                    */
110 int             numTopologies;                          /* number of topologies for one chain and state     */
111 int             numTrees;                               /* number of trees for one chain and state          */
112 Param           *params;                                /* vector of parameters                             */
113 Param           *printParams;                           /* vector of subst model parameters to print        */
114 ShowmovesParams showmovesParams;                        /* holds parameters for Showmoves command           */
115 Param           *treePrintparams;                       /* vector of tree parameters to print               */
116 int             setUpAnalysisSuccess;                   /* Set to YES if analysis is set without error      */
117 
118 /* globals used to describe and change the current model; allocated in AllocCharacters and SetPartition  */
119 int         *numVars;                                   /* number of variables in setting arrays         */
120 int         *activeParts;                               /* partitions changes should apply to            */
121 int         *linkTable[NUM_LINKED];                     /* how parameters are linked across parts        */
122 int         *tempLinkUnlink[NUM_LINKED];                /* for changing parameter linkage                */
123 int         *tempLinkUnlinkVec;                         /* for changing parameter linkage                */
124 MrBFlt      *tempNum;                                   /* vector of numbers used for setting arrays     */
125 
126 /* Aamodel parameters */
127 MrBFlt          aaJones[20][20];             /* rates for Jones model                        */
128 MrBFlt          aaDayhoff[20][20];           /* rates for Dayhoff model                      */
129 MrBFlt          aaMtrev24[20][20];           /* rates for mtrev24 model                      */
130 MrBFlt          aaMtmam[20][20];             /* rates for mtmam model                        */
131 MrBFlt          aartREV[20][20];             /* rates for rtREV model                        */
132 MrBFlt          aaWAG[20][20];               /* rates for WAG model                          */
133 MrBFlt          aacpREV[20][20];             /* rates for aacpREV model                      */
134 MrBFlt          aaVt[20][20];                /* rates for VT model                           */
135 MrBFlt          aaBlosum[20][20];            /* rates for Blosum62 model                     */
136 MrBFlt          aaLG[20][20];                /* rates for LG model                           */
137 MrBFlt          jonesPi[20];                 /* stationary frequencies for Jones model       */
138 MrBFlt          dayhoffPi[20];               /* stationary frequencies for Dayhoff model     */
139 MrBFlt          mtrev24Pi[20];               /* stationary frequencies for mtrev24 model     */
140 MrBFlt          mtmamPi[20];                 /* stationary frequencies for mtmam model       */
141 MrBFlt          rtrevPi[20];                 /* stationary frequencies for rtREV model       */
142 MrBFlt          wagPi[20];                   /* stationary frequencies for WAG model         */
143 MrBFlt          cprevPi[20];                 /* stationary frequencies for aacpREV model     */
144 MrBFlt          vtPi[20];                    /* stationary frequencies for VT model          */
145 MrBFlt          blosPi[20];                  /* stationary frequencies for Blosum62 model    */
146 MrBFlt          lgPi[20];                    /* stationary frequencies for LG model          */
147 
148 /* parser flags and variables only used in this file */
149 int         foundComma, foundBeta, foundAaSetting, modelIsFixed, linkNum, foundLeftPar, tempNumStates,
150             foundBSNum[999], foundDSNum[999], foundFSNum[999], foundBSTime[999], foundDSTime[999], foundFSTime[999];
151 MrBFlt      tempStateFreqs[200], tempAaModelPrs[10];
152 char        colonPr[100], clockPr[30];
153 
154 /* parser flags and variables shared with command.c */
155 extern int  fromI, toJ, foundDash, foundExp, foundEqual, isNegative;
156 
157 /* other local variables (this file) */
158 MrBFlt          empiricalFreqs[200];         /* emprical base frequencies for partition                 */
159 int             intValsRowSize = 0;          /* row size of intValues matrix                            */
160 int             *intValues = NULL;           /* stores int values of chain parameters                   */
161 Tree            **mcmcTree;                  /* pointers to trees for mcmc                              */
162 int             paramValsRowSize = 0;        /* row size of paramValues matrix                          */
163 MrBFlt          *paramValues = NULL;         /* stores actual values and subvalues of chain parameters  */
164 int             *relevantParts = NULL;       /* partitions that are affected by this move               */
165 Param           **subParamPtrs;              /* pointer to subparams for topology params                */
166 int             *stateSize;                  /* # states for each compressed char                       */
167 // int          foundCurly;
168 // char         *plotTokenP;                 /* plotToken[CMD_STRING_LENGTH];*/
169 
170 
171 /*-----------------------------------------------------------------------
172 |
173 |   AddDummyChars: Add dummy characters to relevant partitions
174 |
175 ------------------------------------------------------------------------*/
AddDummyChars(void)176 int AddDummyChars (void)
177 {
178     int         i, j, k, d, numIncompatible, numDeleted, numStdChars, oldRowSize,
179                 newRowSize, numDummyChars, newColumn, newChar, oldColumn, oldChar,
180                 isCompat, *tempChar, numIncompatibleChars;
181     BitsLong    *tempMatrix, bitsLongOne = 1;
182     CLFlt       *tempSitesOfPat;
183     ModelInfo   *m;
184     ModelParams *mp;
185     CharInfo    cinfo;
186     Matrix      matrix;
187 
188     /* set pointers to NULL */
189     tempMatrix = NULL;
190     tempSitesOfPat = NULL;
191     tempChar = NULL;
192 
193     /* check how many dummy characters needed in total */
194     numDummyChars = 0;
195     numStdChars = 0;
196     for (d=0; d<numCurrentDivisions; d++)
197         {
198         m = &modelSettings[d];
199         mp = &modelParams[d];
200 
201         m->numDummyChars = 0;
202 
203         if (mp->dataType == RESTRICTION && !strcmp(mp->parsModel,"No"))
204             {
205             if (mp->coding & NOABSENCESITES)
206                 m->numDummyChars++;
207             if (mp->coding & NOPRESENCESITES)
208                 m->numDummyChars++;
209             if (mp->coding & NOSINGLETONABSENCE)
210                 m->numDummyChars += numLocalTaxa;
211             if (mp->coding & NOSINGLETONPRESENCE)
212                 m->numDummyChars += numLocalTaxa;
213             }
214 
215         if (mp->dataType == STANDARD && !strcmp(mp->parsModel,"No"))
216             {
217             if (mp->coding & VARIABLE)
218                 m->numDummyChars += 2;
219             if (mp->coding & NOSINGLETONS)
220                 m->numDummyChars += 2*numLocalTaxa;
221             numStdChars += (m->numChars + m->numDummyChars);
222             }
223 
224         numDummyChars += m->numDummyChars;
225         m->numChars += m->numDummyChars;
226         }
227 
228     /* exit if dummy characters not needed */
229     if (numDummyChars == 0)
230         return NO_ERROR;
231 
232     /* print original compressed matrix */
233 #   if  defined (DEBUG_ADDDUMMYCHARS)
234     MrBayesPrint ("Compressed matrix before adding dummy characters...\n");
235     PrintCompMatrix();
236 #   endif
237 
238     /* set row sizes for old and new matrices */
239     oldRowSize = compMatrixRowSize;
240     compMatrixRowSize += numDummyChars;
241     newRowSize = compMatrixRowSize;
242     numCompressedChars += numDummyChars;
243 
244     /* allocate space for new data */
245     tempMatrix = (BitsLong *) SafeCalloc (numLocalTaxa * newRowSize, sizeof(BitsLong));
246     tempSitesOfPat = (CLFlt *) SafeCalloc (numCompressedChars, sizeof(CLFlt));
247     tempChar = (int *) SafeCalloc (compMatrixRowSize, sizeof(int));
248     if (!tempMatrix || !tempSitesOfPat || !tempChar)
249         {
250         MrBayesPrint ("%s   Problem allocating temporary variables in AddDummyChars\n", spacer);
251         goto errorExit;
252         }
253 
254     /* initialize indices */
255     oldChar = newChar = newColumn = numDeleted = 0;
256 
257     /* set up matrix struct */
258     matrix.origin = compMatrix;
259     matrix.nRows = numLocalTaxa;
260     matrix.rowSize = oldRowSize;
261 
262     /* loop over divisions */
263     for (d=0; d<numCurrentDivisions; d++)
264         {
265         m = &modelSettings[d];
266         mp = &modelParams[d];
267 
268         /* insert the dummy characters first for each division */
269         if (m->numDummyChars > 0)
270             {
271             // MrBayesPrint("%s   Adding dummy characters (unobserved site patterns) for division %d\n", spacer, d+1);
272             // do not print this every time
273 
274             for (k=0; k<2; k++)
275                 {
276                 if (((mp->coding & NOSINGLETONPRESENCE) && k == 0) || ((mp->coding & NOSINGLETONABSENCE) && k == 1))
277                     {
278                     for (i=0; i< numLocalTaxa; i++)
279                         {
280                         for (j=0; j<numLocalTaxa; j++)
281                             {
282                             if (j == i)
283                                 tempMatrix[pos(j,newColumn,newRowSize)] = (bitsLongOne << k) ^ 3;
284                             else
285                                 tempMatrix[pos(j,newColumn,newRowSize)] = bitsLongOne << k;
286                             }
287                         tempSitesOfPat[newChar] = 0;
288                         tempChar[newColumn] = -1;
289                         newChar++;
290                         newColumn++;
291                         }
292                     }
293                 }
294 
295             if (mp->coding & NOABSENCESITES)
296                 {
297                 for (i=0; i<numLocalTaxa; i++)
298                     tempMatrix[pos(i,newColumn,newRowSize)] = 1;
299                 tempSitesOfPat[newChar] = 0;
300                 tempChar[newColumn] = -1;
301                 newChar++;
302                 newColumn++;
303                 }
304 
305             if (mp->coding & NOPRESENCESITES)
306                 {
307                 for (i=0; i<numLocalTaxa; i++)
308                     tempMatrix[pos(i,newColumn,newRowSize)] = 2;
309                 tempSitesOfPat[newChar] = 0;
310                 tempChar[newColumn] = -1;
311                 newChar++;
312                 newColumn++;
313                 }
314             }
315 
316         /* add the normal characters */
317         numIncompatible = numIncompatibleChars = 0;
318         for (oldColumn=m->compMatrixStart; oldColumn<m->compMatrixStop; oldColumn++)
319             {
320             isCompat = YES;
321             /* first check if the character is supposed to be present */
322             if (m->numDummyChars > 0)
323                 {
324                 /* set up matrix struct */
325                 matrix.column = oldColumn;
326                 /* set up charinfo struct */
327                 cinfo.dType = mp->dataType;
328                 cinfo.cType = charInfo[origChar[oldChar]].ctype;
329                 cinfo.nStates = charInfo[origChar[oldChar]].numStates;
330                 CheckCharCodingType(&matrix, &cinfo);
331 
332                 if (mp->coding & VARIABLE)
333                     {
334                     if((mp->coding & VARIABLE) == VARIABLE && cinfo.variable == NO)
335                         {
336                         isCompat = NO;
337                         }
338                     else if((mp->coding & NOABSENCESITES) && cinfo.constant[0] == YES)
339                         {
340                         isCompat = NO;
341                         }
342                     else if((mp->coding & NOPRESENCESITES) && cinfo.constant[1] == YES)
343                         {
344                         isCompat = NO;
345                         }
346                     }
347                 if (mp->coding & NOSINGLETONS)
348                     {
349                     if((mp->coding & NOSINGLETONS) == NOSINGLETONS && cinfo.informative == NO && cinfo.variable == YES)
350                         {
351                         isCompat = NO;
352                         }
353                     else if((mp->coding & NOSINGLETONABSENCE) && cinfo.singleton[0] == YES && cinfo.informative == NO)
354                         {
355                         isCompat = NO;
356                         }
357                     else if((mp->coding & NOSINGLETONPRESENCE) && cinfo.singleton[1] == YES && cinfo.informative == NO)
358                         {
359                         isCompat = NO;
360                         }
361                     }
362                 }
363 
364             if (isCompat == NO)
365                 {
366                 numIncompatible++;
367                 numIncompatibleChars += (int) numSitesOfPat[oldChar];
368                 oldChar++;
369                 }
370             else
371                 {
372                 /* add character */
373                 for (i=0; i<numLocalTaxa; i++)
374                     tempMatrix[pos(i,newColumn,newRowSize)] = compMatrix[pos(i,oldColumn,oldRowSize)];
375                 /* set indices */
376                 compCharPos[origChar[oldColumn]] = newChar;
377                 compColPos[origChar[oldColumn]] = newColumn;
378                 tempSitesOfPat[newChar] = numSitesOfPat[oldChar];
379                 tempChar[newColumn] = origChar[oldColumn];
380                 newColumn++;
381                 if ((oldColumn-m->compMatrixStart+1) % m->nCharsPerSite == 0)
382                     {
383                     newChar++;
384                     oldChar++;
385                     }
386                 }
387             }
388 
389         /* print a warning if there are incompatible characters */
390         if (numIncompatible > 0)
391             {
392             m->numChars -= numIncompatible;
393             m->numUncompressedChars -= numIncompatibleChars;
394             numDeleted += numIncompatible;
395             if (numIncompatibleChars > 1)
396                 {
397                 MrBayesPrint ("%s   WARNING: There are %d characters incompatible with the specified\n", spacer, numIncompatibleChars);
398                 MrBayesPrint ("%s            coding bias. These characters will be excluded.\n", spacer);
399                 }
400             else
401                 {
402                 MrBayesPrint ("%s   WARNING: There is one character incompatible with the specified\n", spacer);
403                 MrBayesPrint ("%s            coding bias. This character will be excluded.\n", spacer);
404                 }
405             }
406 
407         /* update division comp matrix and comp char pointers */
408         m->compCharStop = newChar;
409         m->compMatrixStop = newColumn;
410         m->compCharStart = newChar - m->numChars;
411         m->compMatrixStart = newColumn - m->nCharsPerSite * m->numChars;
412 
413         }   /* next division */
414 
415     /* compress matrix if necessary */
416     if (numDeleted > 0)
417         {
418         for (i=k=0; i<numLocalTaxa; i++)
419             {
420             for (j=0; j<newRowSize-numDeleted; j++)
421                 {
422                 tempMatrix[k++] = tempMatrix[j+i*newRowSize];
423                 }
424             }
425         numCompressedChars -= numDeleted;
426         compMatrixRowSize -= numDeleted;
427         }
428 
429     /* free old data, set pointers to new data */
430     free (compMatrix);
431     free (numSitesOfPat);
432     free (origChar);
433 
434     compMatrix = tempMatrix;
435     numSitesOfPat = tempSitesOfPat;
436     origChar = tempChar;
437 
438     tempMatrix = NULL;
439     tempSitesOfPat = NULL;
440     tempChar = NULL;
441 
442     /* print new compressed matrix */
443 #   if  defined (DEBUG_ADDDUMMYCHARS)
444     MrBayesPrint ("After adding dummy characters...\n");
445     PrintCompMatrix();
446 #   endif
447 
448     return NO_ERROR;
449 
450     errorExit:
451         if (tempMatrix)
452             free (tempMatrix);
453         if (tempSitesOfPat)
454             free (tempSitesOfPat);
455         if (tempChar)
456             free (tempChar);
457 
458         return ERROR;
459 }
460 
461 
462 /* Allocate space for cpp events */
AllocateCppEvents(Param * p)463 void AllocateCppEvents (Param *p)
464 {
465     int     i;
466 
467     p->nEvents = (int **) SafeCalloc (2*numGlobalChains, sizeof (int *));
468     p->nEvents[0] = (int *) SafeCalloc (2*numGlobalChains*(2*numLocalTaxa), sizeof (int));
469     for (i=1; i<2*numGlobalChains; i++)
470         p->nEvents[i] = p->nEvents[i-1] + (2*numLocalTaxa);
471     p->position = (MrBFlt ***) SafeCalloc (2*numGlobalChains, sizeof (MrBFlt **));
472     p->position[0] = (MrBFlt **) SafeCalloc (2*numGlobalChains*(2*numLocalTaxa), sizeof (MrBFlt *));
473     for (i=1; i<2*numGlobalChains; i++)
474         p->position[i] = p->position[i-1] + (2*numLocalTaxa);
475     p->rateMult = (MrBFlt ***) SafeCalloc (2*numGlobalChains, sizeof (MrBFlt **));
476     p->rateMult[0] = (MrBFlt **) SafeCalloc (2*numGlobalChains*(2*numLocalTaxa), sizeof (MrBFlt *));
477     for (i=1; i<2*numGlobalChains; i++)
478         p->rateMult[i] = p->rateMult[i-1] + (2*numLocalTaxa);
479 
480 }
481 
482 
483 /*----------------------------------------------------------------------------
484 |
485 |   AllocateMove: Allocate space for and initialize one applicable move
486 |
487 -----------------------------------------------------------------------------*/
AllocateMove(MoveType * moveType,Param * param)488 MCMCMove *AllocateMove (MoveType *moveType, Param *param)
489 {
490     int         i, j, nameLength;
491     char        *partitionDescriptor = "";
492     MCMCMove    *temp;
493 
494     if ((temp = (MCMCMove *) SafeCalloc (1, sizeof (MCMCMove))) == NULL)
495         return (NULL);
496 
497     /* calculate length */
498     if (strcmp (moveType->paramName, "") == 0)
499         nameLength = (int) (strlen (moveType->shortName) + strlen (param->name)) + 10;
500     else
501         {
502         partitionDescriptor = param->name;
503         while (*partitionDescriptor != '\0')
504             {
505             if (*partitionDescriptor == '{')
506                 break;
507             partitionDescriptor++;
508             }
509         nameLength = (int) (strlen (moveType->shortName) + strlen (moveType->paramName) + strlen (partitionDescriptor)) + 10;
510         }
511     /* add length of names of subparams */
512     if (moveType->subParams == YES)
513         {
514         for (i=0; i<param->nSubParams; i++)
515             nameLength += (int)(strlen(param->subParams[i]->name)) + 1;
516         }
517 
518     if ((temp->name = (char *) SafeCalloc (nameLength, sizeof (char))) == NULL)
519         {
520         free (temp);
521         return NULL;
522         }
523 
524     if ((temp->nAccepted = (int *) SafeCalloc (5*numGlobalChains, sizeof (int))) == NULL)
525         {
526         free (temp->name);
527         free (temp);
528         return NULL;
529         }
530     temp->nTried       = temp->nAccepted + numGlobalChains;
531     temp->nBatches     = temp->nAccepted + 2*numGlobalChains;
532     temp->nTotAccepted = temp->nAccepted + 3*numGlobalChains;
533     temp->nTotTried    = temp->nAccepted + 4*numGlobalChains;
534 
535     if ((temp->relProposalProb = (MrBFlt *) SafeCalloc (4*numGlobalChains, sizeof (MrBFlt))) == NULL)
536         {
537         free (temp->nAccepted);
538         free (temp->name);
539         free (temp);
540         return NULL;
541         }
542     temp->cumProposalProb = temp->relProposalProb + numGlobalChains;
543     temp->targetRate = temp->relProposalProb + 2*numGlobalChains;
544     temp->lastAcceptanceRate = temp->relProposalProb + 3*numGlobalChains;
545 
546     if ((temp->tuningParam = (MrBFlt **) SafeCalloc (numGlobalChains, sizeof (MrBFlt *))) == NULL)
547         {
548         free (temp->relProposalProb);
549         free (temp->nAccepted);
550         free (temp->name);
551         free (temp);
552         return NULL;
553         }
554     if (moveType->numTuningParams > 0 && (temp->tuningParam[0] = (MrBFlt *) SafeCalloc (moveType->numTuningParams*numGlobalChains, sizeof (MrBFlt))) == NULL)
555         {
556         free (temp->tuningParam);
557         free (temp->relProposalProb);
558         free (temp->nAccepted);
559         free (temp->name);
560         free (temp);
561         return NULL;
562         }
563     for (i=1; i<numGlobalChains; i++)
564         temp->tuningParam[i] = temp->tuningParam[0] + (i * moveType->numTuningParams);
565 
566     /* set default values */
567     if (strcmp(moveType->paramName, "") != 0)
568         sprintf (temp->name, "%s(%s%s)", moveType->shortName, moveType->paramName, partitionDescriptor);
569     else
570         {
571         sprintf (temp->name, "%s(%s", moveType->shortName, param->name);
572         if (moveType->subParams == YES)
573             {
574             for (i=0; i<param->nSubParams; i++)
575                 {
576                 strcat(temp->name,",");
577                 strcat(temp->name,param->subParams[i]->name);
578                 }
579             }
580         strcat (temp->name,")");
581         }
582 
583     temp->moveType = moveType;
584     temp->moveFxn = moveType->moveFxn;
585     for (i=0; i<numGlobalChains; i++)
586         {
587         temp->relProposalProb[i] = moveType->relProposalProb;
588         temp->cumProposalProb[i] = 0.0;
589         temp->nAccepted[i] = 0;
590         temp->nTried[i] = 0;
591         temp->nBatches[i] = 0;
592         temp->nTotAccepted[i] = 0;
593         temp->nTotTried[i] = 0;
594         temp->targetRate[i] = moveType->targetRate;
595         temp->lastAcceptanceRate[i] = 0.0;
596         for (j=0; j<moveType->numTuningParams; j++)
597             temp->tuningParam[i][j] = moveType->tuningParam[j];
598         }
599     return (temp);
600 }
601 
602 
603 /*----------------------------------------------------------------------
604 |
605 |   AllocateNormalParams: Allocate space for normal parameters
606 |
607 -----------------------------------------------------------------------*/
AllocateNormalParams(void)608 int AllocateNormalParams (void)
609 {
610     int         i, k, nOfParams, nOfIntParams;
611     Param       *p;
612 
613     /* Count the number of param values and subvalues */
614     nOfParams = 0;
615     nOfIntParams = 0;
616     for (k=0; k<numParams; k++)
617         {
618         nOfParams += params[k].nValues;
619         nOfParams += params[k].nSubValues;
620         nOfIntParams += params[k].nIntValues;
621         }
622 
623     /* Set row size and find total number of values */
624     paramValsRowSize = nOfParams;
625     intValsRowSize = nOfIntParams;
626     nOfParams *= (2 * numGlobalChains);
627     nOfIntParams *= (2 * numGlobalChains);
628 
629     if (memAllocs[ALLOC_PARAMVALUES] == YES)
630         {
631         paramValues = (MrBFlt *) SafeRealloc ((void *) paramValues, nOfParams * sizeof (MrBFlt));
632         for (i=0; i<nOfParams; i++)
633             paramValues[i] = 0.0;
634         if (nOfIntParams > 0)
635             intValues = (int *) SafeRealloc ((void *) intValues, nOfIntParams * sizeof(int));
636         }
637     else
638         {
639         paramValues = (MrBFlt *) SafeCalloc (nOfParams, sizeof(MrBFlt));
640         if (nOfIntParams > 0)
641             intValues = (int *) SafeCalloc (nOfIntParams, sizeof(int));
642         else
643             intValues = NULL;
644         }
645     if (!paramValues || (nOfIntParams > 0 && !intValues))
646         {
647         MrBayesPrint ("%s   Problem allocating paramValues\n", spacer);
648         if (paramValues)
649             free (paramValues);
650         if (intValues)
651             free (intValues);
652         return ERROR;
653         }
654     else
655         memAllocs[ALLOC_PARAMVALUES] = YES;
656 
657     /* set pointers to values for chain 1 state 0            */
658     /* this scheme keeps the chain and state values together */
659     nOfParams = 0;
660     nOfIntParams = 0;
661     for (k=0; k<numParams; k++)
662         {
663         p = &params[k];
664         if (p->nValues > 0)
665             p->values = paramValues + nOfParams;
666         else
667             p->values = NULL;
668         nOfParams += p->nValues;
669         if (p->nSubValues > 0)
670             p->subValues = paramValues + nOfParams;
671         else
672             p->subValues = NULL;
673         nOfParams += p->nSubValues;
674         if (p->nIntValues > 0)
675             p->intValues = intValues + nOfIntParams;
676         else
677             p->intValues = NULL;
678         nOfIntParams += p->nIntValues;
679         }
680 
681     /* allocate space for cpp events */
682     for (k=0; k<numParams; k++)
683         {
684         p = &params[k];
685         if (p->paramType == P_CPPEVENTS)
686            AllocateCppEvents(p);
687         }
688 
689     return (NO_ERROR);
690 }
691 
692 
693 /*----------------------------------------------------------------------
694 |
695 |   AllocateTreeParams: Allocate space for tree parameters
696 |
697 -----------------------------------------------------------------------*/
AllocateTreeParams(void)698 int AllocateTreeParams (void)
699 {
700     int         i, j, k, n, nOfParams, nOfTrees, isRooted, numSubParamPtrs;
701     Param       *p, *q;
702 
703     /* Count the number of trees and dated trees */
704     /* based on branch length parameters */
705     /*  One tree is needed for each brlen parameter.
706         A topology may apply to several trees; a topology parameter
707         contains pointers to all trees it applies to */
708     numTrees = 0;
709     numTopologies = 0;
710     for (k=0; k<numParams; k++)
711         {
712         if (params[k].paramType == P_BRLENS)
713             numTrees++;
714         else if (params[k].paramType == P_TOPOLOGY)
715             numTopologies++;
716         }
717 
718     /* We need to add the trees that do not have any branch lengths */
719     /* that is, the pure parsimony model trees, and the species trees */
720     for (k=0; k<numParams; k++)
721         {
722         if (params[k].paramType == P_TOPOLOGY)
723             {
724             if (!strcmp(modelParams[params[k].relParts[0]].parsModel, "Yes"))
725                 numTrees++;
726             }
727         else if (params[k].paramType == P_SPECIESTREE)
728             {
729             numTopologies++;
730             numTrees++;
731             }
732         }
733 
734     /* Finally add subparam pointers for relaxed clock parameters and species trees */
735     numSubParamPtrs = 0;
736     for (k=0; k<numParams; k++)
737         {
738         if (params[k].paramType == P_TOPOLOGY && params[k].paramId == TOPOLOGY_SPECIESTREE)
739             numSubParamPtrs += 1;
740         else if (params[k].paramType == P_BRLENS)
741             numSubParamPtrs += 1;
742         else if (params[k].paramType == P_CPPEVENTS)
743             numSubParamPtrs += 3;
744         else if (params[k].paramType == P_TK02BRANCHRATES)
745             numSubParamPtrs += 2;
746         else if (params[k].paramType == P_IGRBRANCHRATES)
747             numSubParamPtrs += 2;
748         else if (params[k].paramType == P_MIXEDBRCHRATES)
749             numSubParamPtrs += 2;
750         }
751 
752     /* Allocate space for trees and subparam pointers */
753     if (memAllocs[ALLOC_MCMCTREES] == YES)
754         {
755         free (subParamPtrs);
756         free (mcmcTree);
757         subParamPtrs = NULL;
758         mcmcTree = NULL;
759         memAllocs[ALLOC_MCMCTREES] = NO;
760         }
761     subParamPtrs = (Param **) SafeCalloc (numSubParamPtrs, sizeof (Param *));
762     mcmcTree = (Tree **) SafeCalloc (numTrees * 2 * numGlobalChains, sizeof (Tree *));
763     if (!subParamPtrs || !mcmcTree)
764         {
765         if (subParamPtrs) free (subParamPtrs);
766         if (mcmcTree) free (mcmcTree);
767         subParamPtrs = NULL;
768         mcmcTree = NULL;
769         MrBayesPrint ("%s   Problem allocating mcmc trees\n", spacer);
770         return (ERROR);
771         }
772     else
773         memAllocs[ALLOC_MCMCTREES] = YES;
774 
775     /* Initialize number of subparams, just in case */
776     for (k=0; k<numParams; k++)
777         params[k].nSubParams = 0;
778 
779     /* Count number of trees (brlens) for each topology or species tree */
780     for (k=0; k<numParams; k++)
781         {
782         p = &params[k];
783         if (params[k].paramType == P_BRLENS)
784             {
785             q = modelSettings[p->relParts[0]].topology;
786             q->nSubParams++;
787             if (p->printParam == YES)
788                 q->nPrintSubParams++;
789             }
790         else if (params[k].paramType == P_TOPOLOGY)
791             {
792             q = modelSettings[p->relParts[0]].speciesTree;
793             if (q != NULL)
794                 q->nSubParams++;
795             }
796         }
797 
798     /* Make sure there is also one subparam for a parsimony tree */
799     for (k=0; k<numParams; k++)
800         if (params[k].paramType == P_TOPOLOGY)
801             {
802             p = &params[k];
803             if (p->nSubParams == 0)
804                 p->nSubParams = 1;
805             }
806 
807     /* Count subparams for relaxed clock parameters */
808     for (k=0; k<numParams; k++)
809         {
810         p = &params[k];
811         if (p->paramType == P_CPPEVENTS)
812             {
813             q = modelSettings[p->relParts[0]].cppRate;
814             q->nSubParams++;
815             q = modelSettings[p->relParts[0]].cppMultDev;
816             q->nSubParams++;
817             q = modelSettings[p->relParts[0]].brlens;
818             q->nSubParams++;
819             }
820         else if (p->paramType == P_TK02BRANCHRATES)
821             {
822             q = modelSettings[p->relParts[0]].tk02var;
823             q->nSubParams++;
824             q = modelSettings[p->relParts[0]].brlens;
825             q->nSubParams++;
826             }
827         else if (p->paramType == P_IGRBRANCHRATES)
828             {
829             q = modelSettings[p->relParts[0]].igrvar;
830             q->nSubParams++;
831             q = modelSettings[p->relParts[0]].brlens;
832             q->nSubParams++;
833             }
834         else if (p->paramType == P_MIXEDBRCHRATES)
835             {
836             q = modelSettings[p->relParts[0]].mixedvar;
837             q->nSubParams++;
838             q = modelSettings[p->relParts[0]].brlens;
839             q->nSubParams++;
840             }
841         }
842 
843     /* set pointers to subparams */
844     nOfParams = 0;
845     for (k=0; k<numParams; k++)
846         {
847         p = &params[k];
848         if (p->nSubParams > 0)
849             {
850             p->subParams = subParamPtrs + nOfParams;
851             nOfParams += p->nSubParams;
852             }
853         }
854     assert (nOfParams == numSubParamPtrs);
855 
856     /* Set brlens param pointers and tree values */
857     /* the scheme below keeps trees for the same state and chain together */
858     nOfTrees = 0;
859     for (k=0; k<numParams; k++)
860         {
861         p = &params[k];
862         if ((p->paramType == P_BRLENS) ||
863             (p->paramType == P_TOPOLOGY && p->paramId == TOPOLOGY_PARSIMONY_UNIFORM) ||
864             (p->paramType == P_TOPOLOGY && p->paramId == TOPOLOGY_PARSIMONY_CONSTRAINED) ||
865             (p->paramType == P_SPECIESTREE))
866             {
867             /* allocate space for trees and initialize trees */
868             p->treeIndex = nOfTrees;
869             p->tree = mcmcTree + nOfTrees;
870             nOfTrees++;
871             }
872         }
873 
874     /* Set topology params and associated brlen subparams */
875     for (k=0; k<numParams; k++)
876         {
877         p = &params[k];
878         if (p->paramType == P_TOPOLOGY)
879             {
880             if (p->paramId == TOPOLOGY_PARSIMONY_UNIFORM ||
881                 p->paramId == TOPOLOGY_PARSIMONY_CONSTRAINED)
882                 /* pure parsimony topology case */
883                 {
884                 /* there is no brlen subparam */
885                 /* so let subparam point to the param itself */
886                 q = p->subParams[0] = p; /* FIXME: Not used (from clang static anasyzer) */
887                 /* p->tree and p->treeIndex have been set above */
888                 }
889             else
890                 {
891                 /* first set brlens pointers for any parsimony partitions */
892                 for (i=j=0; i<p->nRelParts; i++)
893                     {
894                     if (modelSettings[p->relParts[i]].parsModelId == YES)
895                         {
896                         modelSettings[p->relParts[i]].brlens = p;
897                         }
898                     }
899 
900                 /* now proceed with pointer assignment */
901                 q = modelSettings[p->relParts[0]].brlens;
902                 n = 0;  /* number of stored subParams */
903                 i = 0;  /* relevant partition number  */
904                 while (i < p->nRelParts)
905                     {
906                     for (j=0; j<n; j++)
907                         if (q == p->subParams[j])
908                             break;
909 
910                     if (j == n && q != p)   /* a new tree (brlens) for this topology */
911                         {
912                         p->subParams[n++] = q;
913                         }
914                     q = modelSettings[p->relParts[++i]].brlens;
915                     }
916 
917                 p->tree = p->subParams[0]->tree;
918                 p->treeIndex = p->subParams[0]->treeIndex;
919                 }
920             }
921         else if (p->paramType == P_SPECIESTREE)
922             {
923             /* now proceed with pointer assignment */
924             q = modelSettings[p->relParts[0]].topology;
925             n = 0;  /* number of stored subParams */
926             i = 0;  /* relevant partition number  */
927             while (i < p->nRelParts)
928                 {
929                 for (j=0; j<n; j++)
930                     if (q == p->subParams[j])
931                         break;
932 
933                 if (j == n && q != p)   /* a new topology for this species tree */
934                     {
935                     p->subParams[n++] = q;
936                     }
937                 q = modelSettings[p->relParts[++i]].topology;
938                 }
939             }
940         }
941 
942     /* Check for constraints */
943     for (k=0; k<numParams; k++)
944         {
945         p = &params[k];
946         if (p->paramType == P_TOPOLOGY)
947             {
948             if (!strcmp(modelParams[p->relParts[0]].topologyPr, "Constraints"))
949                 {
950                 for (i=0; i<p->nSubParams; i++)
951                     {
952                     q = p->subParams[i];
953                     q->checkConstraints = YES;
954                     }
955                 }
956             else
957                 {
958                 for (i=0; i<p->nSubParams; i++)
959                     {
960                     q = p->subParams[i];
961                     q->checkConstraints = NO;
962                     }
963                 }
964             }
965         }
966 
967     /* update paramId */
968     for (k=0; k<numParams; k++)
969         {
970         p = &params[k];
971         if (p->paramType == P_TOPOLOGY)
972             {
973             if (p->nSubParams > 1)
974                 {
975                 if (p->paramId == TOPOLOGY_NCL_UNIFORM_HOMO)
976                     p->paramId = TOPOLOGY_NCL_UNIFORM_HETERO;
977                 else if (p->paramId == TOPOLOGY_NCL_CONSTRAINED_HOMO)
978                     p->paramId = TOPOLOGY_NCL_CONSTRAINED_HETERO;
979                 else if (p->paramId == TOPOLOGY_NCL_FIXED_HOMO)
980                     p->paramId = TOPOLOGY_NCL_FIXED_HETERO;
981                 else
982                     {
983                     MrBayesPrint ("%s   A clock tree cannot have more than one set of branch lengths\n", spacer);
984                     printf ("nparam:%d paramid:%d",p->nSubParams,p->paramId);
985                     return (ERROR);
986                     }
987                 }
988             }
989         }
990 
991     /* finally initialize trees */
992     for (k=0; k<numParams; k++)
993         {
994         p = &params[k];
995         if (p->paramType == P_BRLENS)
996             {
997             /* find type of tree */
998             if (!strcmp(modelParams[p->relParts[0]].brlensPr,"Clock"))
999                 isRooted = YES;
1000             else
1001                 isRooted = NO;
1002 
1003             if (InitializeChainTrees (p, 0, numGlobalChains, isRooted) == ERROR)
1004                 return (ERROR);
1005             }
1006         else if (p->paramType == P_SPECIESTREE)
1007             {
1008             if (InitializeChainTrees (p, 0, numGlobalChains, YES) == ERROR)
1009                 return (ERROR);
1010             }
1011         }
1012 
1013     /* now initialize subparam pointers for relaxed clock models */
1014     /* use nSubParams to point to the next available subParam by first
1015        resetting all nSubParams to 0 */
1016     for (k=0; k<numParams; k++)
1017         {
1018         p = &params[k];
1019         if (p->paramType == P_CPPRATE ||
1020             p->paramType == P_CPPMULTDEV ||
1021             p->paramType == P_BRLENS ||
1022             p->paramType == P_TK02VAR ||
1023             p->paramType == P_IGRVAR ||
1024             p->paramType == P_MIXEDVAR)
1025             p->nSubParams = 0;
1026         }
1027     for (k=0; k<numParams; k++)
1028         {
1029         p = &params[k];
1030         if (p->paramType == P_CPPEVENTS)
1031             {
1032             q = modelSettings[p->relParts[0]].cppRate;
1033             q->subParams[q->nSubParams++] = p;
1034             q = modelSettings[p->relParts[0]].cppMultDev;
1035             q->subParams[q->nSubParams++] = p;
1036             q = modelSettings[p->relParts[0]].brlens;
1037             q->subParams[q->nSubParams++] = p;
1038             p->treeIndex = q->treeIndex;
1039             p->tree = q->tree;
1040             if (p->printParam == YES)
1041                 q->nPrintSubParams++;
1042             }
1043         else if (p->paramType == P_TK02BRANCHRATES)
1044             {
1045             q = modelSettings[p->relParts[0]].tk02var;
1046             q->subParams[q->nSubParams++] = p;
1047             q = modelSettings[p->relParts[0]].brlens;
1048             q->subParams[q->nSubParams++] = p;
1049             p->treeIndex = q->treeIndex;
1050             p->tree = q->tree;
1051             if (p->printParam == YES)
1052                 q->nPrintSubParams++;
1053             }
1054         else if (p->paramType == P_IGRBRANCHRATES)
1055             {
1056             q = modelSettings[p->relParts[0]].igrvar;
1057             q->subParams[q->nSubParams++] = p;
1058             q = modelSettings[p->relParts[0]].brlens;
1059             q->subParams[q->nSubParams++] = p;
1060             p->treeIndex = q->treeIndex;
1061             p->tree = q->tree;
1062             if (p->printParam == YES)
1063                 q->nPrintSubParams++;
1064             }
1065         else if (p->paramType == P_MIXEDBRCHRATES)
1066             {
1067             q = modelSettings[p->relParts[0]].mixedvar;
1068             q->subParams[q->nSubParams++] = p;
1069             q = modelSettings[p->relParts[0]].brlens;
1070             q->subParams[q->nSubParams++] = p;
1071             p->treeIndex = q->treeIndex;
1072             p->tree = q->tree;
1073             if (p->printParam == YES)
1074                 q->nPrintSubParams++;
1075             }
1076         }
1077 
1078     return (NO_ERROR);
1079 }
1080 
1081 
AreDoublesEqual(MrBFlt x,MrBFlt y,MrBFlt tol)1082 int AreDoublesEqual (MrBFlt x, MrBFlt y, MrBFlt tol)
1083 {
1084     if ((x - y) < -tol || (x - y) > tol)
1085         return (NO);
1086     else
1087         return (YES);
1088 }
1089 
1090 
ChangeNumChains(int from,int to)1091 int ChangeNumChains (int from, int to)
1092 {
1093     int         i, i1, j, k, m, st, nRuns, fromIndex, toIndex, run, chn, *tempIntVals, nCppEventParams, *toEvents, *fromEvents;
1094     MCMCMove    **tempMoves, *fromMove, *toMove;
1095     Tree        **tempTrees;
1096     MrBFlt      *tempVals, **toRateMult, **toPosition, **fromRateMult, **fromPosition, *stdStateFreqsOld;
1097     Param       *p, *q, *cppEventParams = NULL;
1098     Tree        **oldMcmcTree, *tree;
1099 
1100     if (from == to)
1101         return (NO_ERROR);
1102 
1103     /* set new number of chains */
1104     chainParams.numChains = to;
1105     nRuns = chainParams.numRuns;
1106     numGlobalChains = chainParams.numRuns * chainParams.numChains;
1107 
1108     /* Do the normal parameters */
1109     /* first save old values */
1110     tempVals = paramValues;
1111     paramValues = NULL;
1112     tempIntVals = intValues;
1113     intValues = NULL;
1114     memAllocs[ALLOC_PARAMS] = NO;
1115     /* .. and old cpp events parameters */
1116     nCppEventParams = 0;
1117     for (i=0; i<numParams; i++)
1118         {
1119         p = &params[i];
1120         if (p->paramType == P_CPPEVENTS)
1121             nCppEventParams++;
1122         }
1123     cppEventParams = (Param *) SafeCalloc (nCppEventParams, sizeof(Param));
1124     for (i=0; i<nCppEventParams; i++)
1125         {
1126         cppEventParams[i].paramType = P_CPPEVENTS;
1127         AllocateCppEvents (&cppEventParams[i]);
1128         }
1129     for (i=j=0; i<numParams; i++)
1130         {
1131         p = &params[i];
1132         if (p->paramType == P_CPPEVENTS)
1133             {
1134             cppEventParams[j].nEvents = p->nEvents;
1135             p->nEvents = NULL;
1136             cppEventParams[j].position = p->position;
1137             p->position = NULL;
1138             cppEventParams[j].rateMult = p->rateMult;
1139             p->rateMult = NULL;
1140             j++;
1141             }
1142         }
1143     if (AllocateNormalParams () == ERROR)
1144         return (ERROR);
1145 
1146     /* then fill all params */
1147     FillNormalParams (&globalSeed, 0, numGlobalChains);
1148 
1149     /* finally overwrite with old values if present */
1150     for (run=0; run<nRuns; run++)
1151         {
1152         for (chn=0; chn<from; chn++)
1153             {
1154             if (chn < to)
1155                 {
1156                 fromIndex = (run*from + chn)*2*paramValsRowSize;
1157                 toIndex = (run*to + chn)*2*paramValsRowSize;
1158                 for (i=0; i<2*paramValsRowSize; i++)
1159                     paramValues[toIndex++] = tempVals[fromIndex++];
1160                 fromIndex = (run*from + chn)*2*intValsRowSize;
1161                 toIndex = (run*to + chn)*2*intValsRowSize;
1162                 for (i=0; i<2*intValsRowSize; i++)
1163                     intValues[toIndex++] = tempIntVals[fromIndex++];
1164                 for (i=i1=0; i<numParams; i++)
1165                     {
1166                     p = &params[i];
1167                     if (p->paramType == P_CPPEVENTS)
1168                         {
1169                         fromIndex = 2*(run*from + chn);
1170                         toIndex = 2*(run*to + chn);
1171                         fromEvents = cppEventParams[i1].nEvents[fromIndex];
1172                         toEvents = p->nEvents[toIndex];
1173                         fromPosition = cppEventParams[i1].position[fromIndex];
1174                         toPosition = p->position[toIndex];
1175                         fromRateMult = cppEventParams[i1].rateMult[fromIndex];
1176                         toRateMult = p->rateMult[toIndex];
1177                         for (j=0; j<2*numLocalTaxa; j++)
1178                             {
1179                             toEvents[j] = fromEvents[j];
1180                             toPosition[j] = (MrBFlt *) SafeRealloc ((void *)toPosition[j], toEvents[j]*sizeof(MrBFlt));
1181                             toRateMult[j] = (MrBFlt *) SafeRealloc ((void *)toRateMult[j], toEvents[j]*sizeof(MrBFlt));
1182                             for (k=0; k<toEvents[j]; k++)
1183                                 {
1184                                 toPosition[j][k] = fromPosition[j][k];
1185                                 toRateMult[j][k] = fromRateMult[j][k];
1186                                 }
1187                             }
1188                         i1++;
1189                         }
1190                     }
1191                 assert (nCppEventParams==i1);
1192                 }
1193             }
1194         }
1195 
1196     /* and free up space */
1197     free (tempVals);
1198     if (intValsRowSize > 0)
1199         free (tempIntVals);
1200     for (i=0; i<nCppEventParams; i++)
1201         {
1202         numGlobalChains = chainParams.numRuns * from; /* Revert to the old value to clean old Cpp events in FreeCppEvents() */
1203         FreeCppEvents(&cppEventParams[i]);
1204         numGlobalChains = chainParams.numRuns * chainParams.numChains; /*Set to proper value again*/
1205         }
1206     if (nCppEventParams > 0)
1207         free (cppEventParams);
1208 
1209     /* then do the trees (they cannot be done before the parameters because otherwise FillTreeParams will overwrite
1210        relaxed clock parameters that need to be saved) */
1211 
1212     /* reallocate trees */
1213     tempTrees = (Tree **) SafeCalloc (2*nRuns*from*numTrees, sizeof(Tree *));
1214     for (i=0; i<2*nRuns*from*numTrees; i++)
1215         tempTrees[i] = mcmcTree[i];
1216     oldMcmcTree = mcmcTree;
1217     mcmcTree = (Tree **) SafeRealloc ((void *)(mcmcTree), 2 * (size_t)numGlobalChains * (size_t)numTrees * sizeof(Tree*));
1218     for (i=0; i<2*nRuns*to*numTrees; i++)
1219         mcmcTree[i] = NULL;
1220 
1221     /* move the old trees over */
1222     for (run=0; run<nRuns; run++)
1223         {
1224         for (chn=0; chn<from; chn++)
1225             {
1226             if (chn >= to)
1227                 continue;
1228             /*Here we move only one tree per chain/state?! Should not we move numTrees??*/
1229             fromIndex = 2*(run*from + chn)  * numTrees;
1230             toIndex   = 2*(run*to   + chn)  * numTrees;
1231             for (k=0;k<2*numTrees;k++)
1232                 {
1233                 mcmcTree[toIndex+k]    = tempTrees[fromIndex+k];
1234                 tempTrees[fromIndex+k] = NULL;
1235                 }
1236             }
1237         }
1238 
1239     /* remove any remaining old trees */
1240     for (i=0; i<2*nRuns*from*numTrees; i++)
1241         if (tempTrees[i] != NULL)
1242             FreeTree (tempTrees[i]);
1243     free (tempTrees);
1244 
1245     /* now fill in the tree parameters */
1246     for (i=0; i<numParams; i++)
1247         {
1248         p = &params[i];
1249         if (p->paramType == P_TOPOLOGY)
1250             {
1251             p->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1252             for (j=0; j<p->nSubParams; j++)
1253                 {
1254                 q = p->subParams[j];
1255                 assert (q->paramType==P_BRLENS);
1256                 q->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1257                 if (to > from)
1258                     for (run=0; run<nRuns; run++)
1259                         {
1260                         /*rename old trees because each run has more chains*/
1261                         for (m=0; m<from; m++)
1262                             {
1263                             for (st=0; st<2; st++)
1264                                 {
1265                                 tree = GetTree (q,run*to + m, st);
1266                                 if (numTrees > 1)
1267                                     sprintf (tree->name, "mcmc.tree%d_%d", p->treeIndex+1, run*to + m +1);
1268                                 else /* if (numTrees == 1) */
1269                                     sprintf (tree->name, "mcmc.tree_%d", run*to + m +1);
1270                                 }
1271                             }
1272                         InitializeChainTrees (q, run*to + from, run*to + to , GetTree (q, 0, 0)->isRooted);
1273                         }
1274                 }
1275             }
1276         else if (p->paramType == P_CPPEVENTS || p->paramType == P_TK02BRANCHRATES || p->paramType == P_IGRBRANCHRATES || p->paramType == P_MIXEDBRCHRATES)
1277             p->tree += (mcmcTree - oldMcmcTree);
1278         else
1279             assert (p->paramType==P_BRLENS || p->tree==NULL);
1280         }
1281 
1282 
1283     /* fill new tree parameters */
1284     if (to > from)
1285         {
1286         for (run=0; run<nRuns; run++)
1287             {
1288             for (chn=from; chn<to; chn++)
1289                 {
1290                 toIndex = run*to + chn;
1291                 FillTreeParams (&globalSeed, toIndex, toIndex+1);
1292                 }
1293             }
1294         }
1295 
1296     /* fix stationary frequencies for standard data */
1297     if (stdStateFreqsRowSize > 0)
1298         {
1299         assert (memAllocs[ALLOC_STDSTATEFREQS] == YES);
1300         stdStateFreqsOld=stdStateFreqs;
1301         stdStateFreqs = (MrBFlt *) SafeMalloc (2 * (size_t)stdStateFreqsRowSize * (size_t)numGlobalChains * sizeof (MrBFlt));
1302         if (!stdStateFreqs)
1303             {
1304             MrBayesPrint ("%s   Problem reallocating stdStateFreqs\n", spacer);
1305             return (ERROR);
1306             }
1307 
1308         /* set pointers */
1309         for (k=0; k<numParams; k++)
1310             {
1311             p = &params[k];
1312             if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
1313                 continue;
1314             p->stdStateFreqs += stdStateFreqs-stdStateFreqsOld;
1315             }
1316 
1317         for (run=0; run<nRuns; run++)
1318             {
1319             /* copy old chains values*/
1320             for (chn=0; chn<from; chn++)
1321                 {
1322                 if (chn >= to)
1323                     break;
1324 
1325                 fromIndex = 2*(run*from + chn)*stdStateFreqsRowSize;
1326                 toIndex = 2*(run*to + chn)*stdStateFreqsRowSize;
1327                 for (k=0;k<2*stdStateFreqsRowSize;k++)
1328                     {
1329                     stdStateFreqs[toIndex+k]=stdStateFreqsOld[fromIndex+k];
1330                     }
1331                 }
1332             /* set new chains */
1333             FillStdStateFreqs (run*to+from, run*to+to, &globalSeed);
1334             }
1335         free(stdStateFreqsOld);
1336     }
1337 
1338     /* Do the moves */
1339     /* first allocate space and set up default moves */
1340     tempMoves = moves;
1341     moves = NULL;
1342     memAllocs[ALLOC_MOVES] = NO;
1343     SetMoves ();
1344 
1345     /* then overwrite with old values if present */
1346     for (i=0; i<numApplicableMoves; i++)
1347         {
1348         toMove = moves[i];
1349         fromMove = tempMoves[i];
1350         for (run=0; run<nRuns; run++)
1351             {
1352             for (chn=0; chn<from; chn++)
1353                 {
1354                 if (chn < to)
1355                     {
1356                     fromIndex = run*from + chn;
1357                     toIndex = run*to + chn;
1358                     toMove->relProposalProb[toIndex] = fromMove->relProposalProb[fromIndex];
1359                     for (j=0; j<toMove->moveType->numTuningParams; j++)
1360                         {
1361                         toMove->tuningParam[toIndex][j] = fromMove->tuningParam[fromIndex][j];
1362                         }
1363                     }
1364                 }
1365             }
1366         }
1367 
1368     /* and free up space */
1369     for (i=0; i<numApplicableMoves; i++)
1370         FreeMove (tempMoves[i]);
1371     free (tempMoves);
1372 
1373     return (NO_ERROR);
1374 }
1375 
1376 
ChangeNumRuns(int from,int to)1377 int ChangeNumRuns (int from, int to)
1378 {
1379     int         i, i1, j, k, n, nChains;
1380     Param       *p, *q;
1381     MoveType    *mvt;
1382     Tree        **oldMcmcTree;
1383     MrBFlt      *oldParamValues;
1384     MrBFlt      *stdStateFreqsOld;
1385     int         *oldintValues;
1386 
1387     if (from == to)
1388         return (NO_ERROR);
1389 
1390 #if 0
1391     for (i=0; i<numParams; i++)
1392         {
1393         p = &params[i];
1394         if (p->paramType == P_CPPEVENTS)
1395             {
1396             printf ("Trees before changing number of runs\n");
1397             for (j=0; j<numGlobalChains; j++)
1398                 {
1399                 printf ("Event tree for chain %d\n", j+1);
1400                 for (k=0; k<2*numLocalTaxa; k++)
1401                     {
1402                     printf ("%d -- %d:", k, p->nEvents[2*j][k]);
1403                     for (i1=0; i1<p->nEvents[2*j][k]; i1++)
1404                         {
1405                         if (i1 == 0)
1406                             printf (" (%lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1407                         else if (i1 == p->nEvents[2*j][k]-1)
1408                             printf (" %lf %lf)", p->position[2*j][k], p->rateMult[2*j][k]);
1409                         else
1410                             printf (" %lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1411                         }
1412                     printf ("\n");
1413                     }
1414                 for (k=0; k<2*numLocalTaxa; k++)
1415                     {
1416                     printf ("%d -- %d:", k, p->nEvents[2*j][k]);
1417                     for (i1=0; i1<p->nEvents[2*j+1][k]; i1++)
1418                         {
1419                         if (i1 == 0)
1420                             printf (" (%lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1421                         else if (i1 == p->nEvents[2*j][k]-1)
1422                             printf (" %lf %lf)", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1423                         else
1424                             printf (" %lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1425                         }
1426                     printf ("\n");
1427                     }
1428                 }
1429             }
1430         }
1431 #endif
1432 
1433     /* set new number of runs */
1434     chainParams.numRuns = to;
1435     nChains = chainParams.numChains;
1436     numGlobalChains = chainParams.numRuns * chainParams.numChains;
1437 
1438     /* do the trees, free tree's memory if we reduce number of trees. */
1439     for (i=to*2*nChains*numTrees; i<from*2*nChains*numTrees; i++)
1440         {
1441         FreeTree (mcmcTree[i]);
1442         }
1443     oldMcmcTree = mcmcTree;
1444     mcmcTree = (Tree **) SafeRealloc ((void *) mcmcTree, numTrees * 2 * numGlobalChains * sizeof (Tree *));
1445     if (mcmcTree == NULL)
1446         {
1447         memAllocs[ALLOC_MCMCTREES] = NO;
1448         MrBayesPrint ("%s   Problem reallocating mcmcTree\n", spacer);
1449         return (ERROR);
1450         }
1451 
1452     for (i=from*2*nChains*numTrees; i<to*2*nChains*numTrees; i++)
1453         {
1454         mcmcTree[i]=NULL;
1455         }
1456     /* then the cppevents parameters */
1457     for (i1=0; i1<numParams; i1++)
1458         {
1459         p = &params[i1];
1460         if (p->paramType == P_CPPEVENTS)
1461             {
1462             p->nEvents = (int **) SafeRealloc ((void *)p->nEvents, 2*numGlobalChains*sizeof (int *));
1463             p->nEvents[0] = (int *) SafeRealloc ((void *)p->nEvents[0], 2*numGlobalChains*(2*numLocalTaxa)*sizeof (int));
1464             for (i=1; i<2*numGlobalChains; i++)
1465                 p->nEvents[i] = p->nEvents[i-1] + (2*numLocalTaxa);
1466             if (from > to)
1467                 {
1468                 for (j=numGlobalChains; j<from*nChains; j++)
1469                     {
1470                     for (k=0; k<2*numLocalTaxa; k++)
1471                         {
1472                         free (p->position[2*j+0][k]);
1473                         p->position[2*j+0][k] = NULL;
1474                         free (p->rateMult[2*j+0][k]);
1475                         p->rateMult[2*j+0][k] = NULL;
1476                         }
1477                     }
1478                 }
1479             p->position = (MrBFlt ***) SafeRealloc ((void *)p->position, 2*numGlobalChains*sizeof (MrBFlt **));
1480             p->position[0] = (MrBFlt **) SafeRealloc ((void *)p->position[0], 2*numGlobalChains*(2*numLocalTaxa)*sizeof (MrBFlt *));
1481             for (i=1; i<2*numGlobalChains; i++)
1482                 p->position[i] = p->position[i-1] + (2*numLocalTaxa);
1483             p->rateMult = (MrBFlt ***) SafeRealloc ((void *)p->rateMult, 2*numGlobalChains*sizeof (MrBFlt **));
1484             p->rateMult[0] = (MrBFlt **) SafeRealloc ((void *)p->rateMult[0], 2*numGlobalChains*(2*numLocalTaxa)*sizeof (MrBFlt *));
1485             for (i=1; i<2*numGlobalChains; i++)
1486                 p->rateMult[i] = p->rateMult[i-1] + (2*numLocalTaxa);
1487             if (to > from)
1488                 {
1489                 for (j=from*nChains; j<numGlobalChains; j++)
1490                     {
1491                     for (k=0; k<2*numLocalTaxa; k++)
1492                         {
1493                         p->nEvents[2*j+0][k] = 0;
1494                         p->position[2*j+0][k] = NULL;
1495                         p->rateMult[2*j+0][k] = NULL;
1496                         p->nEvents[2*j+1][k] = 0;
1497                         p->position[2*j+1][k] = NULL;
1498                         p->rateMult[2*j+1][k] = NULL;
1499                         }
1500                     }
1501                 }
1502             }
1503         }
1504     /* and finally the normal parameters */
1505     oldParamValues = paramValues;
1506     paramValues = (MrBFlt *) SafeRealloc ((void *) paramValues, paramValsRowSize * 2 * numGlobalChains * sizeof (MrBFlt));
1507     oldintValues = intValues;
1508     intValues = (int *) SafeRealloc ((void *) intValues, intValsRowSize * 2 * numGlobalChains * sizeof (int));
1509     if (paramValues == NULL)
1510         {
1511         memAllocs[ALLOC_PARAMVALUES] = NO;
1512         MrBayesPrint ("%s   Problem reallocating paramValues\n", spacer);
1513         return (ERROR);
1514         }
1515     for (i=0; i<numParams; i++)
1516         {
1517         params[i].values += (paramValues - oldParamValues);
1518         params[i].subValues += (paramValues - oldParamValues);
1519         params[i].intValues += (intValues - oldintValues);
1520         }
1521 
1522     /* fill new chains paramiters with appropriate values */
1523     if (to > from)
1524         FillNormalParams (&globalSeed, from*nChains, to*nChains);
1525 
1526     /* now fill in the tree parameters */
1527     for (i=0; i<numParams; i++)
1528         {
1529         p = &params[i];
1530         if (p->paramType == P_TOPOLOGY)
1531             {
1532             p->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1533             for (j=0; j<p->nSubParams; j++)
1534                 {
1535                 q = p->subParams[j];
1536                 assert (q->paramType==P_BRLENS);
1537                 q->tree += (mcmcTree - oldMcmcTree);    /* calculate new address */
1538                 InitializeChainTrees (q, from*nChains, to*nChains, GetTree (q, 0, 0)->isRooted);
1539                 }
1540             }
1541         else if (p->paramType == P_CPPEVENTS || p->paramType == P_TK02BRANCHRATES || p->paramType == P_IGRBRANCHRATES || p->paramType == P_MIXEDBRCHRATES)
1542             p->tree += (mcmcTree - oldMcmcTree);
1543         }
1544 
1545     FillTreeParams (&globalSeed, from*nChains, to*nChains);
1546 
1547     /* fix stationary frequencies for standard data */
1548     if (stdStateFreqsRowSize > 0)
1549         {
1550         assert (memAllocs[ALLOC_STDSTATEFREQS] == YES);
1551         stdStateFreqsOld=stdStateFreqs;
1552         stdStateFreqs = (MrBFlt *) SafeRealloc ((void *) stdStateFreqs, stdStateFreqsRowSize * 2 * numGlobalChains * sizeof (MrBFlt));
1553         if (!stdStateFreqs)
1554             {
1555             MrBayesPrint ("%s   Problem reallocating stdStateFreqs\n", spacer);
1556             return (ERROR);
1557             }
1558 
1559         /* set pointers */
1560         for (k=n=0; k<numParams; k++)
1561             {
1562             p = &params[k];
1563             if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
1564                 continue;
1565             p->stdStateFreqs += stdStateFreqs-stdStateFreqsOld;
1566             }
1567 
1568         FillStdStateFreqs (from*nChains, to*nChains, &globalSeed);
1569         }
1570 
1571     /* do the moves */
1572     for (i=0; i<numApplicableMoves; i++)
1573         {
1574         mvt = moves[i]->moveType;
1575         moves[i]->tuningParam = (MrBFlt **) SafeRealloc ((void *) moves[i]->tuningParam, (size_t)numGlobalChains * sizeof (MrBFlt *));
1576         moves[i]->tuningParam[0] = (MrBFlt *) SafeRealloc ((void *) moves[i]->tuningParam[0], (size_t)numGlobalChains * (size_t)(mvt->numTuningParams) * sizeof (MrBFlt));
1577         for (j=1; j<numGlobalChains; j++)
1578             moves[i]->tuningParam[j] = moves[i]->tuningParam[0] + j * mvt->numTuningParams;
1579         moves[i]->relProposalProb = (MrBFlt *) SafeRealloc ((void *) moves[i]->relProposalProb, 4 * (size_t)numGlobalChains * sizeof (MrBFlt));
1580         moves[i]->cumProposalProb = moves[i]->relProposalProb + numGlobalChains;
1581         moves[i]->targetRate = moves[i]->relProposalProb + 2*numGlobalChains;
1582         moves[i]->lastAcceptanceRate = moves[i]->relProposalProb + 3*numGlobalChains;
1583         moves[i]->nAccepted = (int *) SafeRealloc ((void *) moves[i]->nAccepted, 5* (size_t)numGlobalChains * sizeof (int));
1584         moves[i]->nTried = moves[i]->nAccepted + numGlobalChains;
1585         moves[i]->nBatches = moves[i]->nAccepted + 2*numGlobalChains;
1586         moves[i]->nTotAccepted = moves[i]->nAccepted + 3*numGlobalChains;
1587         moves[i]->nTotTried    = moves[i]->nAccepted + 4*numGlobalChains;
1588         /* initialize all values to default */
1589         for (j=0; j<numGlobalChains; j++)
1590             {
1591             moves[i]->nAccepted[j] = 0;
1592             moves[i]->nTried[j] = 0;
1593             moves[i]->nBatches[j] = 0;
1594             moves[i]->nTotAccepted[j] = 0;
1595             moves[i]->nTotTried[j] = 0;
1596             moves[i]->relProposalProb[j] = mvt->relProposalProb;
1597             moves[i]->cumProposalProb[j] = 0.0;
1598             moves[i]->lastAcceptanceRate[j] = 0.0;
1599             for (k=0; k<mvt->numTuningParams; k++)
1600                 moves[i]->tuningParam[j][k] = mvt->tuningParam[k];
1601             moves[i]->targetRate[j] = mvt->targetRate;
1602             }
1603         }
1604 
1605 #if 0
1606     for (i=0; i<numParams; i++)
1607         {
1608         p = &params[i];
1609         if (p->paramType == P_CPPEVENTS)
1610             {
1611             printf ("Trees after changing number of runs\n");
1612             for (j=0; j<numGlobalChains; j++)
1613                 {
1614                 printf ("Event tree for chain %d\n", j+1);
1615                 for (k=0; k<2*numLocalTaxa; k++)
1616                     {
1617                     printf ("%d -- %d:", k, p->nEvents[2*j][k]);
1618                     assert (p->nEvents[2*j] >= 0);
1619                     for (i1=0; i1<p->nEvents[2*j][k]; i1++)
1620                         {
1621                         if (i1 == 0)
1622                             printf (" (%lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1623                         else if (i1 == p->nEvents[2*j][k]-1)
1624                             printf (" %lf %lf)", p->position[2*j][k], p->rateMult[2*j][k]);
1625                         else
1626                             printf (" %lf %lf,", p->position[2*j][k], p->rateMult[2*j][k]);
1627                         }
1628                     printf ("\n");
1629                     }
1630                 for (k=0; k<2*numLocalTaxa; k++)
1631                     {
1632                     printf ("%d -- %d:", k, p->nEvents[2*j+1][k]);
1633                     assert (p->nEvents[2*j+1] >= 0);
1634                     for (i1=0; i1<p->nEvents[2*j+1][k]; i1++)
1635                         {
1636                         if (i1 == 0)
1637                             printf (" (%lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1638                         else if (i1 == p->nEvents[2*j][k]-1)
1639                             printf (" %lf %lf)", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1640                         else
1641                             printf (" %lf %lf,", p->position[2*j+1][k], p->rateMult[2*j+1][k]);
1642                         }
1643                     printf ("\n");
1644                     }
1645                 }
1646             }
1647         }
1648 #endif
1649 
1650     return (NO_ERROR);
1651 }
1652 
1653 
1654 /*-----------------------------------------------------------
1655 |
1656 |   CheckCharCodingType: check if character is parsimony-
1657 |       informative, variable, or constant
1658 |
1659 -----------------------------------------------------------*/
CheckCharCodingType(Matrix * m,CharInfo * ci)1660 void CheckCharCodingType (Matrix *m, CharInfo *ci)
1661 {
1662     int         i, j, k, x, n1[10], n2[10], largest, smallest, numPartAmbig,
1663                 numConsidered, numInformative, lastInformative=0, uniqueBits,
1664                 newPoss, oldPoss;
1665     BitsLong    combinations[2048], *tempComb, *newComb, *oldComb, bitsLongOne=1;
1666 
1667     /* set up comb pointers */
1668     oldComb = combinations;
1669     newComb = oldComb + 1024;
1670 
1671     /* set counters to 0 */
1672     numPartAmbig = numConsidered = 0;
1673 
1674     /* set variable and informative to yes */
1675     ci->variable = ci->informative = YES;
1676 
1677     /* set constant to no and state counters to 0 for all states */
1678     for (i=0; i<10; i++)
1679         {
1680         ci->constant[i] = ci->singleton[i] = NO;
1681         n1[i] = n2[i] = 0;
1682         }
1683 
1684     for (i=0; i<m->nRows; i++)
1685         {
1686         /* retrieve character */
1687         x = (int) m->origin[m->column + i*m->rowSize];
1688 
1689         /* add it to counters if not all ambiguous */
1690         if (NBits(x) < ci->nStates)
1691             {
1692             numConsidered++;
1693             if (NBits(x) > 1)
1694                 numPartAmbig++;
1695             for (j=0; j<10; j++)
1696                 {
1697                 if (((bitsLongOne<<j) & x) != 0)
1698                     {
1699                     n1[j]++;
1700                     if (NBits(x) == 1)
1701                         n2[j]++;
1702                     }
1703                 }
1704             }
1705         }
1706 
1707     /* if the ambig counter for any state is equal to the number of considered
1708        states, then set constant for that state and set variable and informative to no */
1709     for (i=0; i<10; i++)
1710         {
1711         if (n1[i] == numConsidered)
1712             {
1713             ci->constant[i] = YES;
1714             ci->variable = ci->informative = NO;
1715             }
1716             else if (n1[i] == 1)
1717             {
1718             ci->singleton[i] = YES;
1719             }
1720         }
1721 
1722     /* return if variable is no */
1723     if (ci->variable == NO)
1724         return;
1725 
1726     /* the character is either (variable and uninformative) or informative */
1727 
1728     /* first consider unambiguous characters */
1729     /* find smallest and largest unambiguous state for this character */
1730     smallest = 9;
1731     largest = 0;
1732     for (i=0; i<10; i++)
1733         {
1734         if (n2[i] > 0)
1735             {
1736             if (i < smallest)
1737                 smallest = i;
1738             if (i > largest)
1739                 largest = i;
1740             }
1741         }
1742 
1743     /* count the number of informative states in the unambiguous codings */
1744     for (i=numInformative=0; i<10; i++)
1745         {
1746         if (ci->cType == ORD && n2[i] > 0 && i != smallest && i != largest)
1747             {
1748             numInformative++;
1749             lastInformative = i;
1750             }
1751         else if (n2[i] > 1)
1752             {
1753             numInformative++;
1754             lastInformative = i;
1755             }
1756         }
1757 
1758     /* set informative */
1759     if (numInformative > 1)
1760         ci->informative = YES;
1761     else
1762         ci->informative = NO;
1763 
1764 
1765     /* we can return now unless informative is no and numPartAmbig is not 0 */
1766     if (!(numPartAmbig > 0 && ci->informative == NO))
1767         return;
1768 
1769     /* check if partially ambiguous observations make this character informative
1770        after all */
1771 
1772     /* first set the bits for the taken states */
1773     x = 0;
1774     for (i=0; i<10; i++)
1775         {
1776         if (n2[i] > 0 && i != lastInformative)
1777             x |= (bitsLongOne<<i);
1778         }
1779     oldPoss = 1;
1780     oldComb[0] = x;
1781 
1782     /* now go through all partambig chars and see if we can add them without
1783        making the character informative */
1784     for (i=0; i<m->nRows; i++)
1785         {
1786         x = (int) m->origin[m->column + i*m->rowSize];
1787         /* if partambig */
1788         if (NBits(x) > 1 && NBits(x) < ci->nStates)
1789             {
1790             /* remove lastInformative */
1791             x &= !(bitsLongOne<<lastInformative);
1792             /* reset newPoss */
1793             newPoss = 0;
1794             /* see if we can add it, store all possible combinations */
1795             for (j=0; j<oldPoss; j++)
1796                 {
1797                 uniqueBits = x & (!oldComb[j]);
1798                 for (k=0; k<10; k++)
1799                     {
1800                     if (((bitsLongOne<<k) & uniqueBits) != 0)
1801                         newComb[newPoss++] = oldComb[j] | (bitsLongOne<<k);
1802                     }
1803                 }
1804             /* break out if we could not add it */
1805             if (newPoss == 0)
1806                 break;
1807 
1808             /* prepare for next partAmbig */
1809             oldPoss = newPoss;
1810             tempComb = oldComb;
1811             oldComb = newComb;
1812             newComb = tempComb;
1813             }
1814         }
1815 
1816     if (i < m->nRows)
1817         ci->informative = YES;
1818 
1819     return;
1820 }
1821 
1822 
1823 /*-----------------------------------------------------------
1824 |
1825 |   CheckModel: check model and warn user if strange things
1826 |      are discovered.
1827 |
1828 -------------------------------------------------------------*/
CheckModel(void)1829 int CheckModel (void)
1830 {
1831     int         i, j, k, answer;
1832     Tree        *t = NULL;
1833     TreeNode    *p;
1834 
1835     /* there should only be one calibrated tree */
1836     for (i=0; i<numTrees; i++)
1837         {
1838         t = GetTreeFromIndex(i,0,0);
1839         if (t->isCalibrated == YES)
1840             break;
1841         }
1842 
1843     if (i < numTrees)
1844         {
1845         if (!strcmp(modelParams[t->relParts[0]].clockRatePr, "Fixed") && AreDoublesEqual(modelParams[t->relParts[0]].clockRateFix, 1.0, 1E-6) == YES)
1846             {
1847             MrBayesPrint("%s   WARNING: You have calibrated the tree but the clock rate is fixed to 1.0.\n", spacer);
1848             MrBayesPrint("%s      This means that time is measured in expected changes per time unit. If\n", spacer);
1849             MrBayesPrint("%s      the calibrations use a different time scale, you need to modify the model\n", spacer);
1850             MrBayesPrint("%s      by introducing a prior for the clock rate ('prset clockratepr').\n", spacer);
1851 
1852             if (noWarn == NO)
1853                 {
1854                 answer = WantTo("Do you want to continue with the run regardless");
1855                 if (answer == YES)
1856                     {
1857                     MrBayesPrint("%s   Continuing with the run...\n\n", spacer);
1858                     }
1859                 else
1860                     {
1861                     MrBayesPrint("%s   Stopping the run...\n\n", spacer);
1862                     return (ERROR);
1863                     }
1864                 }
1865             }
1866         }
1867 
1868     /* check coalescence model */
1869     for (i=0; i<numTrees; i++)
1870         {
1871         t = GetTreeFromIndex(i, 0, 0);
1872         if ((!strcmp(modelParams[t->relParts[0]].clockPr,"Coalescence") || !strcmp(modelParams[t->relParts[0]].clockPr,"Speciestreecoalescence"))
1873             && !strcmp(modelParams[t->relParts[0]].clockRatePr, "Fixed") && AreDoublesEqual(modelParams[t->relParts[0]].clockRateFix, 1.0, 1E-6) == YES)
1874             {
1875             MrBayesPrint("%s   WARNING: You are using a coalescent model but the clock rate is fixed to 1.0.\n", spacer);
1876             MrBayesPrint("%s      This is likely to be incorrect unless you have set the population size prior\n", spacer);
1877             MrBayesPrint("%s      ('prset popsizepr') to reflect an appropriate prior on theta. \n", spacer);
1878 
1879             if (noWarn == NO)
1880                 {
1881                 answer = WantTo("Do you want to continue with the run regardless");
1882                 if (answer == YES)
1883                     {
1884                     MrBayesPrint("%s   Continuing with the run...\n\n", spacer);
1885                     }
1886                 else
1887                     {
1888                     MrBayesPrint("%s   Stopping the run...\n\n", spacer);
1889                     return (ERROR);
1890                     }
1891                 }
1892             }
1893         }
1894 
1895     /* Check consistency of best model. First we guarantee that if one topology has
1896        a species tree prior, then all topologies have the same prior. Then we make
1897        sure that all clock trees have a coalescence prior. */
1898 
1899     j = 0;
1900     for (i=0; i<numCurrentDivisions; i++)
1901         {
1902         if (!strcmp(modelParams[i].topologyPr, "Speciestree"))
1903             j++;
1904         }
1905 
1906     if (j > 0)
1907         {
1908         if (j != numCurrentDivisions)
1909             {
1910             MrBayesPrint("%s   ERROR: If one gene tree has a speciestree prior then all\n", spacer);
1911             MrBayesPrint("%s          gene trees must have the same prior.\n", spacer);
1912             return (ERROR);
1913             }
1914         for (i=0; i<numTrees-1; i++)
1915             {
1916             t = GetTreeFromIndex(i,0,0);
1917             if (strcmp(modelParams[t->relParts[0]].clockPr,"Speciestreecoalescence") != 0)
1918                 {
1919                 MrBayesPrint("%s   ERROR: All gene trees must have a speciestreecoalescence prior\n", spacer);
1920                 MrBayesPrint("%s          if they fold into a species tree.\n", spacer);
1921                 return (ERROR);
1922                 }
1923             if (t->isCalibrated == YES)
1924                 {
1925                 for (k=0; k<t->nNodes-1; k++)
1926                     {
1927                     p = t->allDownPass[k];
1928                     if (p->calibration != NULL)
1929                         {
1930                         MrBayesPrint("%s   ERROR: Gene trees cannot be individually calibrated\n", spacer);
1931                         MrBayesPrint("%s          if they fold into a species tree.\n", spacer);
1932                         return (ERROR);
1933                         }
1934                     }
1935                 }
1936             }
1937         }
1938 
1939     return NO_ERROR;
1940 }
1941 
1942 
1943 /*-----------------------------------------------------------
1944 |
1945 |   CheckExpandedModels: check data partitions that have
1946 |   the codon or doublet model specified
1947 |
1948 -------------------------------------------------------------*/
CheckExpandedModels(void)1949 int CheckExpandedModels (void)
1950 {
1951     int             c, d, i, t, s, s1, s2, s3, whichNuc, uniqueId, numCharsInPart,
1952                     firstChar, lastChar, contiguousPart, badBreak, badExclusion,
1953                     nGone, nuc1, nuc2, nuc3, foundStopCodon, posNucs1[4], posNucs2[4], posNucs3[4],
1954                     oneGoodCodon, foundUnpaired, nPair, allCheckedOut;
1955     char            *tempStr;
1956     int             tempStrSize=100;
1957     ModelParams     *mp;
1958 
1959     tempStr = (char *) SafeMalloc((size_t)tempStrSize * sizeof(char));
1960     if (!tempStr)
1961         {
1962         MrBayesPrint ("%s   Problem allocating tempString (%d)\n", spacer, tempStrSize * sizeof(char));
1963         return (ERROR);
1964         }
1965 
1966     /* first, set charId to 0 for all characters */
1967     for (i=0; i<numChar; i++)
1968         charInfo[i].charId = 0;
1969 
1970     /* loop over partitions */
1971     allCheckedOut = 0;
1972     uniqueId = 1;
1973     for (d=0; d<numCurrentDivisions; d++)
1974         {
1975         mp = &modelParams[d];
1976 
1977         if (mp->dataType == DNA || mp->dataType == RNA)
1978             {
1979             if (!strcmp(mp->nucModel,"Codon") || !strcmp(mp->nucModel,"Protein"))
1980                 {
1981                 /* start check that the codon model is appropriate for this partition */
1982 
1983                 /* find first character in this partition */
1984                 for (c=0; c<numChar; c++)
1985                     {
1986                     if (partitionId[c][partitionNum] == d+1)
1987                         break;
1988                     }
1989                 firstChar = c;
1990                 /*printf ("   first character = %d\n", firstChar);*/
1991 
1992                 /* find last character in this partition */
1993                 for (c=numChar-1; c>=0; c--)
1994                     {
1995                     if (partitionId[c][partitionNum] == d+1)
1996                         break;
1997                     }
1998                 lastChar = c;
1999                 /*printf ("   last character = %d\n", lastChar);*/
2000 
2001                 /* check that the number of characters in partition is divisible by 3 */
2002                 numCharsInPart = 0;
2003                 for (c=firstChar; c<=lastChar; c++)
2004                     {
2005                     if (charInfo[c].isExcluded == YES || partitionId[c][partitionNum] != d+1)
2006                         continue;
2007                     numCharsInPart++;
2008                     }
2009                 /*printf ("   numCharsInPart = %d\n", numCharsInPart);*/
2010                 if (numCharsInPart % 3 != 0)
2011                     {
2012                     if (numCurrentDivisions == 1)
2013                         {
2014                         MrBayesPrint ("%s   The number of characters is not divisible by three.\n", spacer);
2015                         MrBayesPrint ("%s   You specified a %s model which requires triplets\n", spacer, mp->nucModel);
2016                         MrBayesPrint ("%s   However, you have %d characters.\n", spacer, numCharsInPart);
2017                         }
2018                     else
2019                         {
2020                         MrBayesPrint ("%s   The number of characters in partition %d is not\n", spacer, d+1);
2021                         MrBayesPrint ("%s   divisible by three. You specified a %s model\n", spacer, mp->nucModel);
2022                         MrBayesPrint ("%s   which requires triplets. \n", spacer);
2023                         MrBayesPrint ("%s   However, you have %d characters in this partition\n", spacer, numCharsInPart);
2024                         }
2025                     free (tempStr);
2026                     return (ERROR);
2027                     }
2028 
2029                 /* check that all of the characters in the partition are contiguous */
2030                 contiguousPart = YES;
2031                 for (c=firstChar; c<=lastChar; c++)
2032                     {
2033                     if (charInfo[c].isExcluded == NO && partitionId[c][partitionNum] != d+1)
2034                         contiguousPart = NO;
2035                     }
2036                 if (contiguousPart == NO)
2037                     {
2038                     MrBayesPrint ("%s   Partition %d is not contiguous. You specified that\n", spacer, d+1);
2039                     MrBayesPrint ("%s   a %s model be used for this partition. However, there\n", spacer, mp->nucModel);
2040                     MrBayesPrint ("%s   is another partition that is between some of the characters\n", spacer);
2041                     MrBayesPrint ("%s   in this partition. \n", spacer);
2042                     free (tempStr);
2043                     return (ERROR);
2044                     }
2045 
2046                 /* check that there is not a break inside a triplet of characters */
2047                 badBreak = NO;
2048                 whichNuc = 0;
2049                 for (c=firstChar; c<=lastChar; c++)
2050                     {
2051                     if (charInfo[c].isExcluded == NO)
2052                         continue;
2053                     whichNuc++;
2054                     if (charInfo[c].bigBreakAfter == YES && whichNuc != 3)
2055                         badBreak = YES;
2056                     if (whichNuc == 3)
2057                         whichNuc = 0;
2058                     }
2059                 if (badBreak == YES)
2060                     {
2061                     MrBayesPrint ("%s   You specified a databreak inside of a coding triplet.\n", spacer);
2062                     MrBayesPrint ("%s   This is a problem, as you imply that part of the codon\n", spacer);
2063                     MrBayesPrint ("%s   lies in one gene and the remainder in another gene. \n", spacer);
2064                     free (tempStr);
2065                     return (ERROR);
2066                     }
2067 
2068                 /* make certain excluded characters are in triplets but allow frameshift exclusions first in sequence */
2069                 badExclusion = NO;
2070                 whichNuc = nGone = 0;
2071                 for (c=firstChar; c<=lastChar; c++)
2072                     if (charInfo[c].isExcluded == NO)
2073                         break;
2074                 for (; c<=lastChar; c++)
2075                     {
2076                     whichNuc++;
2077                     if (charInfo[c].isExcluded == YES)
2078                         nGone++;
2079                     if (whichNuc == 3)
2080                         {
2081                         if (nGone == 1 || nGone == 2)
2082                             badExclusion = YES;
2083                         whichNuc = nGone = 0;
2084                         }
2085                     }
2086                 if (badExclusion == YES)
2087                     {
2088                     MrBayesPrint ("%s   In excluding characters, you failed to remove all of the\n", spacer);
2089                     MrBayesPrint ("%s   sites of at least one codon. If you exclude sites, make \n", spacer);
2090                     MrBayesPrint ("%s   certain to exclude all of the sites in the codon(s). \n", spacer);
2091                     free (tempStr);
2092                     return (ERROR);
2093                     }
2094 
2095                 /* check that there are no stop codons */
2096                 foundStopCodon = NO;
2097                 /* allow frameshifting exclusions in the beginning */
2098                 for (c=firstChar; c<=lastChar; c++)
2099                     if (charInfo[c].isExcluded == NO)
2100                         break;
2101                 for (; c<=lastChar; c+=3)
2102                     {
2103                     if (charInfo[c].isExcluded == NO)
2104                         {
2105                         for (t=0; t<numTaxa; t++)
2106                             {
2107                             if (taxaInfo[t].isDeleted == YES)
2108                                 continue;
2109                             nuc1 = matrix[pos(t,c+0,numChar)];
2110                             nuc2 = matrix[pos(t,c+1,numChar)];
2111                             nuc3 = matrix[pos(t,c+2,numChar)];
2112                             /*nucX is in range 0-15 to represent any possible set of states that nucleatide could be in*/
2113                             GetPossibleNucs (nuc1, posNucs1);
2114                             GetPossibleNucs (nuc2, posNucs2);
2115                             GetPossibleNucs (nuc3, posNucs3);
2116 
2117                             oneGoodCodon = NO;
2118                             s = 0;
2119                             for (s1=0; s1<4; s1++)
2120                                 {
2121                                 for (s2=0; s2<4; s2++)
2122                                     {
2123                                     for (s3=0; s3<4; s3++)
2124                                         {
2125                                         if (posNucs1[s1] == 1 && posNucs2[s2] == 1 && posNucs3[s3] == 1)
2126                                             {
2127                                             if (mp->codon[s1*16 + s2*4 + s3] != 21)
2128                                                 oneGoodCodon = YES;
2129                                             }
2130                                         s++;
2131                                         }
2132                                     }
2133                                 }
2134                             if (oneGoodCodon == NO)
2135                                 {
2136                                 foundStopCodon = YES;
2137                                 MrBayesPrint ("%s   Stop codon: taxon %s, sites %d to %d (%c%c%c, %s code)\n", spacer,
2138                                     taxaNames[t], c+1, c+3, WhichNuc (nuc1), WhichNuc (nuc2), WhichNuc (nuc3), mp->geneticCode);
2139                                 }
2140                             }
2141                         }
2142                     }
2143                 if (foundStopCodon == YES)
2144                     {
2145                     MrBayesPrint ("%s   At least one stop codon was found. Stop codons are not\n", spacer);
2146                     MrBayesPrint ("%s   allowed under the codon models.  \n", spacer);
2147                     free (tempStr);
2148                     return (ERROR);
2149                     }
2150 
2151                 /* everything checks out. Now we can initialize charId */
2152                 whichNuc = 0;
2153                 for (c=firstChar; c<=lastChar; c++)
2154                     {
2155                     whichNuc++;
2156                     charInfo[c].charId = uniqueId;
2157                     if (whichNuc == 3)
2158                         {
2159                         whichNuc = 0;
2160                         uniqueId++;
2161                         }
2162                     }
2163 
2164                 allCheckedOut++;
2165                 /* end check that the codon model is appropriate for this partition */
2166                 }
2167             else if (!strcmp(mp->nucModel,"Doublet"))
2168                 {
2169                 /* start check that the doublet model is appropriate for this partition */
2170 
2171                 /* Check that pairsId does not equal 0 for any of the characters in
2172                    the partition. If it does, then this means that at least one
2173                    site was not appropriately paired. Remember, that pairsId is
2174                    initialized 1, 2, 3, ... for the first pair, second pair, etc.
2175                    Also, check that every pair is only represented two times. */
2176                 foundUnpaired = NO;
2177                 for (c=0; c<numChar; c++)
2178                     {
2179                     if (partitionId[c][partitionNum] == d+1 && charInfo[c].pairsId == 0 && charInfo[c].isExcluded == NO)
2180                         foundUnpaired = YES;
2181                     }
2182 
2183                 for (c=0; c<numChar; c++)
2184                     {
2185                     if (partitionId[c][partitionNum] == d+1 && charInfo[c].isExcluded == NO)
2186                         {
2187                         nPair = 1;
2188                         for (i=0; i<numChar; i++)
2189                             {
2190                             if (i != c && partitionId[i][partitionNum] == d+1 && charInfo[i].isExcluded == NO && charInfo[c].pairsId == charInfo[i].pairsId)
2191                                 nPair++;
2192                             }
2193                         if (nPair != 2)
2194                             foundUnpaired = YES;
2195                         }
2196                     }
2197                 if (foundUnpaired == YES)
2198                     {
2199                     if (numCurrentDivisions == 1)
2200                         {
2201                         MrBayesPrint ("%s   Found unpaired nucleotide sites. The doublet model\n", spacer);
2202                         MrBayesPrint ("%s   requires that all sites are paired. \n", spacer);
2203                         }
2204                     else
2205                         {
2206                         MrBayesPrint ("%s   Found unpaired nucleotide sites in partition %d.\n", spacer, d+1);
2207                         MrBayesPrint ("%s   The doublet model requires that all sites are paired. \n", spacer);
2208                         }
2209                     free (tempStr);
2210                     return (ERROR);
2211                     }
2212 
2213                 /* everything checks out. Now we can initialize charId */
2214                 for (c=0; c<numChar; c++)
2215                     {
2216                     nuc2 = -1;
2217                     if (partitionId[c][partitionNum] == d+1 && charInfo[c].charId == 0)
2218                         {
2219                         nuc1 = c;
2220                         for (i=0; i<numChar; i++)
2221                             {
2222                             if (i != c && charInfo[i].charId == 0 && charInfo[c].pairsId == charInfo[i].pairsId)
2223                                 nuc2 = i;
2224                             }
2225                         if (nuc1 >= 0 && nuc2 >= 0)
2226                             {
2227                             charInfo[nuc1].charId = charInfo[nuc2].charId = uniqueId;
2228                             uniqueId++;
2229                             }
2230                         else
2231                             {
2232                             MrBayesPrint ("%s   Weird doublet problem in partition %d.\n", spacer, d+1);
2233                             free (tempStr);
2234                             return (ERROR);
2235                             }
2236                         }
2237                     }
2238 
2239                 allCheckedOut++;
2240                 /* end check that the doublet model is appropriate for this partition */
2241                 }
2242             }
2243         }
2244 
2245     /*
2246     if (allCheckedOut > 0)
2247         MrBayesPrint ("%s   Codon/Doublet models successfully checked\n", spacer);
2248     */
2249 
2250 #   if 0
2251     for (c=0; c<numChar; c++)
2252             printf (" %d", charId[c]);
2253     printf ("\n");
2254 #   endif
2255 
2256     free (tempStr);
2257     return (NO_ERROR);
2258 }
2259 
CodingToString(int coding,char * string)2260 void CodingToString(int coding, char* string)
2261 {
2262     if(coding == ALL)
2263         strcpy(string, "All");
2264     else if(coding == INFORMATIVE)
2265         strcpy(string, "Informative");
2266     else if((coding & VARIABLE) == VARIABLE)
2267         {
2268         if (coding == VARIABLE)
2269             {
2270             strcpy(string, "Variable");
2271             }
2272         else if (coding & NOSINGLETONABSENCE)
2273             {
2274             strcpy(string, "Variable|Nosingletonabsence");
2275             }
2276         else if (coding & NOSINGLETONPRESENCE)
2277             {
2278             strcpy(string, "Variable|Nosingletonpresence");
2279             }
2280         }
2281     else if((coding & NOSINGLETONS) == NOSINGLETONS)
2282         {
2283         if (coding == NOSINGLETONS)
2284             {
2285             strcpy(string, "Nosingletons");
2286             }
2287         else if (coding & NOABSENCESITES)
2288             {
2289             strcpy(string, "Noabsencesites|Nosingletons");
2290             }
2291         else if (coding & NOPRESENCESITES)
2292             {
2293             strcpy(string, "Nopresencesites|Nosingletons");
2294             }
2295         }
2296     else if(coding == NOABSENCESITES)
2297         {
2298         strcpy(string, "Noabsencesites");
2299         }
2300     else if(coding == NOPRESENCESITES)
2301         {
2302         strcpy(string, "Nopresencesites");
2303         }
2304     else if(coding == NOSINGLETONABSENCE)
2305         {
2306         strcpy(string, "Nosingletonabsence");
2307         }
2308     else if(coding == NOSINGLETONPRESENCE)
2309         {
2310         strcpy(string, "Nosingletonpresence");
2311         }
2312     else if(coding == (NOABSENCESITES | NOSINGLETONABSENCE))
2313         {
2314         strcpy(string, "Noabsencesites|Nosingletonabsence");
2315         }
2316     else if(coding == (NOABSENCESITES | NOSINGLETONPRESENCE))
2317         {
2318         strcpy(string, "Noabsencesites|Nosingletonpresence");
2319         }
2320     else if(coding == (NOPRESENCESITES | NOSINGLETONABSENCE))
2321         {
2322         strcpy(string, "Nopresencesites|Nosingletonabsence");
2323         }
2324     else if(coding == (NOPRESENCESITES | NOSINGLETONPRESENCE))
2325         {
2326         strcpy(string, "Nopresencesites|Nosingletonpresence");
2327         }
2328 }
2329 
2330 
2331 /*-----------------------------------------------------------
2332 |
2333 |   CompressData: compress original data matrix
2334 |
2335 -------------------------------------------------------------*/
CompressData(void)2336 int CompressData (void)
2337 {
2338     int             a, c, d, i, j, k, t, col[3], isSame, newRow, newColumn,
2339                     *isTaken, *tempSitesOfPat, *tempChar;
2340     BitsLong        *tempMatrix;
2341     ModelInfo       *m;
2342     ModelParams     *mp;
2343 
2344 #   if defined DEBUG_COMPRESSDATA
2345     if (PrintMatrix() == ERROR)
2346         goto errorExit;
2347     getchar();
2348 #   endif
2349 
2350     /* set all pointers that will be allocated locally to NULL */
2351     isTaken = NULL;
2352     tempMatrix = NULL;
2353     tempSitesOfPat = NULL;
2354     tempChar = NULL;
2355 
2356     /* allocate indices pointing from original to compressed matrix */
2357     if (memAllocs[ALLOC_COMPCOLPOS] == YES)
2358         {
2359         free (compColPos);
2360         compColPos = NULL;
2361         memAllocs[ALLOC_COMPCOLPOS] = NO;
2362         }
2363     compColPos = (int *)SafeMalloc((size_t)numChar * sizeof(int));
2364     if (!compColPos)
2365         {
2366         MrBayesPrint ("%s   Problem allocating compColPos (%d)\n", spacer, numChar * sizeof(int));
2367         goto errorExit;
2368         }
2369     for (i=0; i<numChar; i++)
2370         compColPos[i] = 0;
2371     memAllocs[ALLOC_COMPCOLPOS] = YES;
2372 
2373     if (memAllocs[ALLOC_COMPCHARPOS] == YES)
2374         {
2375         free (compCharPos);
2376         compCharPos = NULL;
2377         memAllocs[ALLOC_COMPCHARPOS] = NO;
2378         }
2379     compCharPos = (int *)SafeMalloc((size_t)numChar * sizeof(int));
2380     if (!compCharPos)
2381         {
2382         MrBayesPrint ("%s   Problem allocating compCharPos (%d)\n", spacer, numChar * sizeof(int));
2383         goto errorExit;
2384         }
2385     for (i=0; i<numChar; i++)
2386         compCharPos[i] = 0;
2387     memAllocs[ALLOC_COMPCHARPOS] = YES;
2388 
2389     /* allocate space for temporary matrix, tempSitesOfPat,             */
2390     /* vector keeping track of whether a character has been compressed, */
2391     /* and vector indexing first original char for each compressed char */
2392     tempMatrix = (BitsLong *) SafeCalloc (numLocalTaxa * numLocalChar, sizeof(BitsLong));
2393     tempSitesOfPat = (int *) SafeCalloc (numLocalChar, sizeof(int));
2394     isTaken = (int *) SafeCalloc (numChar, sizeof(int));
2395     tempChar = (int *) SafeCalloc (numLocalChar, sizeof(int));
2396     if (!tempMatrix || !tempSitesOfPat || !isTaken || !tempChar)
2397         {
2398         MrBayesPrint ("%s   Problem allocating temporary variables in CompressData\n", spacer);
2399         goto errorExit;
2400         }
2401 
2402     /* initialize isTaken */
2403     for (c=0; c<numChar; c++)
2404         isTaken[c] = NO;
2405 
2406     /* set index to first empty column in temporary matrix */
2407     newColumn = 0;
2408 
2409     /* initialize number of compressed characters */
2410     numCompressedChars = 0;
2411 
2412     /* sort and compress data */
2413     for (d=0; d<numCurrentDivisions; d++)
2414         {
2415         /* set pointers to the model params and settings for this division */
2416         m = &modelSettings[d];
2417         mp = &modelParams[d];
2418 
2419         /* set column offset for this division in compressed matrix */
2420         m->compMatrixStart = newColumn;
2421 
2422         /* set compressed character offset for this division */
2423         m->compCharStart = numCompressedChars;
2424 
2425         /* set number of compressed characters to 0 for this division */
2426         m->numChars = 0;
2427 
2428         /* find the number of original characters per model site */
2429         m->nCharsPerSite = 1;
2430         if (mp->dataType == DNA || mp->dataType == RNA)
2431             {
2432             if (!strcmp(mp->nucModel, "Doublet"))
2433                 m->nCharsPerSite = 2;
2434             if (!strcmp(mp->nucModel, "Codon") || !strcmp(mp->nucModel, "Protein"))
2435                 m->nCharsPerSite = 3;
2436             }
2437 
2438         /* sort and compress the characters for this division */
2439         for (c=0; c<numChar; c++)
2440             {
2441             if (charInfo[c].isExcluded == YES || partitionId[c][partitionNum] != d+1 || isTaken[c] == YES)
2442                 continue;
2443 
2444             col[0] = c;
2445             isTaken[c] = YES;
2446 
2447             /* find additional columns if more than one character per model site      */
2448             /* return error if the number of matching characters is smaller or larger */
2449             /* than the actual number of characters per model site                    */
2450             if (m->nCharsPerSite > 1)
2451                 {
2452                 j = 1;
2453                 if (charInfo[c].charId == 0)
2454                     {
2455                     MrBayesPrint("%s   Character %d is not properly defined\n", spacer, c+1);
2456                     goto errorExit;
2457                     }
2458                 for (i=c+1; i<numChar; i++)
2459                     {
2460                     if (charInfo[i].charId == charInfo[c].charId)
2461                         {
2462                         if (j >= m->nCharsPerSite)
2463                             {
2464                             MrBayesPrint("%s   Too many matches in charId (division %d char %d)\n", spacer, d, numCompressedChars);
2465                             goto errorExit;
2466                             }
2467                         else
2468                             {
2469                             col[j++] = i;
2470                             isTaken[i] = YES;
2471                             }
2472                         }
2473                     }
2474                 if (j != m->nCharsPerSite)
2475                     {
2476                     MrBayesPrint ("%s   Too few matches in charId (division %d char %d)\n", spacer, d, numCompressedChars);
2477                     goto errorExit;
2478                     }
2479                 }
2480 
2481             /* add character to temporary matrix in column(s) at newColumn */
2482             for (t=newRow=0; t<numTaxa; t++)
2483                 {
2484                 if (taxaInfo[t].isDeleted == YES)
2485                     continue;
2486 
2487                 for (k=0; k<m->nCharsPerSite; k++)
2488                     {
2489                     tempMatrix[pos(newRow,newColumn+k,numLocalChar)] = matrix[pos(t,col[k],numChar)];
2490                     }
2491                 newRow++;
2492                 }
2493 
2494             /* is it unique? */
2495             isSame = NO;
2496             if (mp->dataType != CONTINUOUS)
2497                 {
2498                 for (i=m->compMatrixStart; i<newColumn; i+=m->nCharsPerSite)
2499                     {
2500                     isSame = YES;
2501                     for (j=0; j<numLocalTaxa; j++)
2502                         {
2503                         for (k=0; k<m->nCharsPerSite; k++)
2504                             if (tempMatrix[pos(j,newColumn+k,numLocalChar)] != tempMatrix[pos(j,i+k,numLocalChar)])
2505                                 {
2506                                 isSame = NO;
2507                                 break;
2508                                 }
2509                         if (isSame == NO)
2510                             break;
2511                         }
2512                     if (isSame == YES)
2513                         break;
2514                     }
2515                 }
2516 
2517             /* if subject to data augmentation, it is always unique */
2518             if (!strcmp(mp->augmentData, "Yes"))
2519                 {
2520                 for (k=0; k<m->nCharsPerSite; k++)
2521                     {
2522                     if (charInfo[col[k]].isMissAmbig == YES)
2523                         isSame = NO;
2524                     }
2525                 }
2526 
2527             if (isSame == NO)
2528                 {
2529                 /* if it is unique then it should be added */
2530                 tempSitesOfPat[numCompressedChars] = 1;
2531                 for (k=0; k<m->nCharsPerSite; k++)
2532                     {
2533                     compColPos[col[k]] = newColumn + k;
2534                     compCharPos[col[k]] = numCompressedChars;
2535                     tempChar[newColumn + k] = col[k];
2536                     }
2537                 newColumn+=m->nCharsPerSite;
2538                 m->numChars++;
2539                 numCompressedChars++;
2540                 }
2541             else
2542                 {
2543                 /* if it is not unique then simply update tempSitesOfPat     */
2544                 /* calculate compressed character position and put it into a */
2545                 /* (i points to compressed column position)                  */
2546                 a = m->compCharStart + ((i - m->compMatrixStart) / m->nCharsPerSite);
2547                 tempSitesOfPat[a]++;
2548                 for (k=0; k<m->nCharsPerSite; k++)
2549                     {
2550                     compColPos[col[k]] = i;
2551                     compCharPos[col[k]] = a;
2552                     /* tempChar (pointing from compressed to uncompresed) */
2553                     /* can only be set for first pattern */
2554                     }
2555                 }
2556             }   /* next character */
2557 
2558         /* check that the partition has at least a single character */
2559         if (m->numChars <= 0)
2560             {
2561             MrBayesPrint ("%s   You must have at least one site in a partition. Partition %d\n", spacer, d+1);
2562             MrBayesPrint ("%s   has %d site patterns.\n", spacer, m->numChars);
2563             goto errorExit;
2564             }
2565 
2566         m->compCharStop = m->compCharStart + m->numChars;
2567         m->compMatrixStop = newColumn;
2568 
2569         } /* next division */
2570 
2571     compMatrixRowSize = newColumn;
2572 
2573     /* now we know the size, so we can allocate space for the compressed matrix ... */
2574     if (memAllocs[ALLOC_COMPMATRIX] == YES)
2575         {
2576         free (compMatrix);
2577         compMatrix = NULL;
2578         memAllocs[ALLOC_COMPMATRIX] = NO;
2579         }
2580     compMatrix = (BitsLong *) SafeCalloc (compMatrixRowSize * numLocalTaxa, sizeof(BitsLong));
2581     if (!compMatrix)
2582         {
2583         MrBayesPrint ("%s   Problem allocating compMatrix (%d)\n", spacer, compMatrixRowSize * numLocalTaxa * sizeof(BitsLong));
2584         goto errorExit;
2585         }
2586     memAllocs[ALLOC_COMPMATRIX] = YES;
2587 
2588     if (memAllocs[ALLOC_NUMSITESOFPAT] == YES)
2589         {
2590         free (numSitesOfPat);
2591         numSitesOfPat = NULL;
2592         memAllocs[ALLOC_NUMSITESOFPAT] = NO;
2593         }
2594     numSitesOfPat = (CLFlt *) SafeCalloc (numCompressedChars, sizeof(CLFlt));
2595     if (!numSitesOfPat)
2596         {
2597         MrBayesPrint ("%s   Problem allocating numSitesOfPat (%d)\n", spacer, numCompressedChars * sizeof(MrBFlt));
2598         goto errorExit;
2599         }
2600     memAllocs[ALLOC_NUMSITESOFPAT] = YES;
2601 
2602     if (memAllocs[ALLOC_ORIGCHAR] == YES)
2603         {
2604         free (origChar);
2605         origChar = NULL;
2606         memAllocs[ALLOC_ORIGCHAR] = NO;
2607         }
2608     origChar = (int *)SafeMalloc((size_t)compMatrixRowSize * sizeof(int));
2609     if (!origChar)
2610         {
2611         MrBayesPrint ("%s   Problem allocating origChar (%d)\n", spacer, numCompressedChars * sizeof(int));
2612         goto errorExit;
2613         }
2614     memAllocs[ALLOC_ORIGCHAR] = YES;
2615 
2616     /* ... and copy the data there */
2617     for (i=0; i<numLocalTaxa; i++)
2618         for (j=0; j<compMatrixRowSize; j++)
2619             compMatrix[pos(i,j,compMatrixRowSize)] = tempMatrix[pos(i,j,numLocalChar)];
2620 
2621     for (i=0; i<numCompressedChars; i++)
2622         numSitesOfPat[i] = (CLFlt) tempSitesOfPat[i];
2623 
2624     for (i=0; i<compMatrixRowSize; i++)
2625         origChar[i] = tempChar[i];
2626 
2627 #   if defined (DEBUG_COMPRESSDATA)
2628     if (PrintCompMatrix() == ERROR)
2629         goto errorExit;
2630     getchar();
2631 #   endif
2632 
2633     /* free the temporary variables */
2634     free (tempSitesOfPat);
2635     free (tempMatrix);
2636     free (isTaken);
2637     free (tempChar);
2638 
2639     return NO_ERROR;
2640 
2641     errorExit:
2642         if (tempMatrix)
2643             free (tempMatrix);
2644         if (tempSitesOfPat)
2645             free (tempSitesOfPat);
2646         if (isTaken)
2647             free (isTaken);
2648         if (tempChar)
2649             free (tempChar);
2650 
2651         return ERROR;
2652 }
2653 
2654 
DataType(int part)2655 int DataType (int part)
2656 {
2657     int     i;
2658 
2659     for (i=0; i<numChar; i++)
2660         {
2661         if (partitionId[i][partitionNum] == part + 1)
2662             break;
2663         }
2664 
2665     return (charInfo[i].charType);
2666 }
2667 
2668 
DoLink(void)2669 int DoLink (void)
2670 {
2671     int         i, j, newLine;
2672 
2673     MrBayesPrint ("%s   Linking\n", spacer);
2674 
2675     /* update status of linkTable */
2676     for (j=0; j<NUM_LINKED; j++)
2677         {
2678         newLine = YES;
2679         for (i=0; i<numCurrentDivisions; i++)
2680             {
2681             if (tempLinkUnlink[j][i] == YES)
2682                 {
2683                 if (newLine == YES)
2684                     {
2685                     linkNum++;
2686                     newLine = NO;
2687                     }
2688                 linkTable[j][i] = linkNum;
2689                 }
2690             }
2691         }
2692 
2693 #   if 0
2694     for (j=0; j<NUM_LINKED; j++)
2695         {
2696         MrBayesPrint ("%s   ", spacer);
2697         for (i=0; i<numCurrentDivisions; i++)
2698             MrBayesPrint ("%d", linkTable[j][i]);
2699         MrBayesPrint ("\n");
2700         }
2701 #   endif
2702 
2703     /* reinitialize the temporary table */
2704     for (j=0; j<NUM_LINKED; j++)
2705         for (i=0; i<numCurrentDivisions; i++)
2706             tempLinkUnlink[j][i] = NO;
2707 
2708     /* set up parameters and moves */
2709     if (SetUpAnalysis (&globalSeed) == ERROR)
2710         return (ERROR);
2711 
2712     return (NO_ERROR);
2713 }
2714 
2715 
DoLinkParm(char * parmName,char * tkn)2716 int DoLinkParm (char *parmName, char *tkn)
2717 {
2718     int         i, j, tempInt;
2719 
2720     if (defMatrix == NO)
2721         {
2722         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
2723         return (ERROR);
2724         }
2725 
2726     if (inValidCommand == YES)
2727         {
2728         for (j=0; j<NUM_LINKED; j++)
2729             for (i=0; i<numCurrentDivisions; i++)
2730                 tempLinkUnlink[j][i] = NO;
2731         inValidCommand = NO;
2732         }
2733 
2734     if (expecting == Expecting(PARAMETER))
2735         {
2736         expecting = Expecting(EQUALSIGN);
2737         }
2738     else if (expecting == Expecting(EQUALSIGN))
2739         {
2740         expecting = Expecting(LEFTPAR);
2741         }
2742     else if (expecting == Expecting(LEFTPAR))
2743         {
2744         /* initialize tempLinkUnlinkVec to no */
2745         for (i=0; i<numCurrentDivisions; i++)
2746             tempLinkUnlinkVec[i] = NO;
2747         fromI = toJ = -1;
2748         foundDash = NO;
2749         expecting = Expecting(NUMBER) | Expecting(ALPHA);
2750         }
2751     else if (expecting == Expecting(RIGHTPAR))
2752         {
2753         if (fromI != -1)
2754             tempLinkUnlinkVec[fromI-1] = YES;
2755         /* now copy tempLinkUnlinkVec to appropriate row of tempLinkUnlink */
2756         if (!strcmp(parmName, "Tratio"))
2757             {
2758             for (i=0; i<numCurrentDivisions; i++)
2759                 tempLinkUnlink[P_TRATIO][i] = tempLinkUnlinkVec[i];
2760             }
2761         else if (!strcmp(parmName, "Revmat"))
2762             {
2763             for (i=0; i<numCurrentDivisions; i++)
2764                 tempLinkUnlink[P_REVMAT][i] = tempLinkUnlinkVec[i];
2765             }
2766         else if (!strcmp(parmName, "Omega"))
2767             {
2768             for (i=0; i<numCurrentDivisions; i++)
2769                 tempLinkUnlink[P_OMEGA][i] = tempLinkUnlinkVec[i];
2770             }
2771         else if (!strcmp(parmName, "Statefreq"))
2772             {
2773             for (i=0; i<numCurrentDivisions; i++)
2774                 tempLinkUnlink[P_PI][i] = tempLinkUnlinkVec[i];
2775             }
2776         else if (!strcmp(parmName, "Mixturerates"))
2777         {
2778             for (i=0; i<numCurrentDivisions; i++)
2779                 tempLinkUnlink[P_MIXTURE_RATES][i] = tempLinkUnlinkVec[i];
2780         }
2781         else if (!strcmp(parmName, "Shape"))
2782             {
2783             for (i=0; i<numCurrentDivisions; i++)
2784                 tempLinkUnlink[P_SHAPE][i] = tempLinkUnlinkVec[i];
2785             }
2786         else if (!strcmp(parmName, "Pinvar"))
2787             {
2788             for (i=0; i<numCurrentDivisions; i++)
2789                 tempLinkUnlink[P_PINVAR][i] = tempLinkUnlinkVec[i];
2790             }
2791         else if (!strcmp(parmName, "Correlation"))
2792             {
2793             for (i=0; i<numCurrentDivisions; i++)
2794                 tempLinkUnlink[P_CORREL][i] = tempLinkUnlinkVec[i];
2795             }
2796         else if (!strcmp(parmName, "Ratemultiplier"))
2797             {
2798             for (i=0; i<numCurrentDivisions; i++)
2799                 tempLinkUnlink[P_RATEMULT][i] = tempLinkUnlinkVec[i];
2800             }
2801         else if (!strcmp(parmName, "Switchrates"))
2802             {
2803             for (i=0; i<numCurrentDivisions; i++)
2804                 tempLinkUnlink[P_SWITCH][i] = tempLinkUnlinkVec[i];
2805             }
2806         else if (!strcmp(parmName, "Topology"))
2807             {
2808             for (i=0; i<numCurrentDivisions; i++)
2809                 tempLinkUnlink[P_TOPOLOGY][i] = tempLinkUnlinkVec[i];
2810             }
2811         else if (!strcmp(parmName, "Brlens"))
2812             {
2813             for (i=0; i<numCurrentDivisions; i++)
2814                 tempLinkUnlink[P_BRLENS][i] = tempLinkUnlinkVec[i];
2815             }
2816         else if (!strcmp(parmName, "Speciationrate"))
2817             {
2818             for (i=0; i<numCurrentDivisions; i++)
2819                 tempLinkUnlink[P_SPECRATE][i] = tempLinkUnlinkVec[i];
2820             }
2821         else if (!strcmp(parmName, "Extinctionrate"))
2822             {
2823             for (i=0; i<numCurrentDivisions; i++)
2824                 tempLinkUnlink[P_EXTRATE][i] = tempLinkUnlinkVec[i];
2825             }
2826         else if (!strcmp(parmName, "Fossilizationrate"))
2827             {
2828             for (i=0; i<numCurrentDivisions; i++)
2829                 tempLinkUnlink[P_FOSLRATE][i] = tempLinkUnlinkVec[i];
2830             }
2831         else if (!strcmp(parmName, "Popsize"))
2832             {
2833             for (i=0; i<numCurrentDivisions; i++)
2834                 tempLinkUnlink[P_POPSIZE][i] = tempLinkUnlinkVec[i];
2835             }
2836         else if (!strcmp(parmName, "Growthrate"))
2837             {
2838             for (i=0; i<numCurrentDivisions; i++)
2839                 tempLinkUnlink[P_GROWTH][i] = tempLinkUnlinkVec[i];
2840             }
2841         else if (!strcmp(parmName, "Aamodel"))
2842             {
2843             for (i=0; i<numCurrentDivisions; i++)
2844                 tempLinkUnlink[P_AAMODEL][i] = tempLinkUnlinkVec[i];
2845             }
2846         else if (!strcmp(parmName, "Cpprate"))
2847             {
2848             for (i=0; i<numCurrentDivisions; i++)
2849                 tempLinkUnlink[P_CPPRATE][i] = tempLinkUnlinkVec[i];
2850             }
2851         else if (!strcmp(parmName, "Cppmultdev"))
2852             {
2853             for (i=0; i<numCurrentDivisions; i++)
2854                 tempLinkUnlink[P_CPPMULTDEV][i] = tempLinkUnlinkVec[i];
2855             }
2856         else if (!strcmp(parmName, "Cppevents"))
2857             {
2858             for (i=0; i<numCurrentDivisions; i++)
2859                 tempLinkUnlink[P_CPPEVENTS][i] = tempLinkUnlinkVec[i];
2860             }
2861         else if (!strcmp(parmName, "TK02var") || !strcmp(parmName, "Bmvar"))
2862             {
2863             for (i=0; i<numCurrentDivisions; i++)
2864                 tempLinkUnlink[P_TK02VAR][i] = tempLinkUnlinkVec[i];
2865             }
2866         else if (!strcmp(parmName, "TK02branchrates") || !strcmp(parmName, "Bmbranchrates"))
2867             {
2868             for (i=0; i<numCurrentDivisions; i++)
2869                 tempLinkUnlink[P_TK02BRANCHRATES][i] = tempLinkUnlinkVec[i];
2870             }
2871         else if (!strcmp(parmName, "Igrvar") || !strcmp(parmName, "Ibrvar"))
2872             {
2873             for (i=0; i<numCurrentDivisions; i++)
2874                 tempLinkUnlink[P_IGRVAR][i] = tempLinkUnlinkVec[i];
2875             }
2876         else if (!strcmp(parmName, "Igrbranchrates") || !strcmp(parmName, "Ibrbranchlens"))
2877             {
2878             for (i=0; i<numCurrentDivisions; i++)
2879                 tempLinkUnlink[P_IGRBRANCHRATES][i] = tempLinkUnlinkVec[i];
2880             }
2881         else if (!strcmp(parmName, "Mixedvar"))
2882             {
2883             for (i=0; i<numCurrentDivisions; i++)
2884                 tempLinkUnlink[P_MIXEDVAR][i] = tempLinkUnlinkVec[i];
2885             }
2886         else if (!strcmp(parmName, "Mixedbrchrates"))
2887             {
2888             for (i=0; i<numCurrentDivisions; i++)
2889                 tempLinkUnlink[P_MIXEDBRCHRATES][i] = tempLinkUnlinkVec[i];
2890             }
2891         else
2892             {
2893             MrBayesPrint ("%s   Couldn't find parameter %s to link\n", spacer, parmName);
2894             }
2895 
2896         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
2897         }
2898     else if (expecting == Expecting(COMMA))
2899         {
2900         foundComma = YES;
2901         expecting = Expecting(NUMBER);
2902         }
2903     else if (expecting == Expecting(ALPHA))
2904         {
2905         if (IsSame ("All", tkn) == DIFFERENT)
2906             {
2907             MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
2908             return (ERROR);
2909             }
2910         for (i=0; i<numCurrentDivisions; i++)
2911             tempLinkUnlinkVec[i] = YES;
2912         expecting  = Expecting(RIGHTPAR);
2913         }
2914     else if (expecting == Expecting(NUMBER))
2915         {
2916         sscanf (tkn, "%d", &tempInt);
2917         if (tempInt > numCurrentDivisions)
2918             {
2919             MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
2920             return (ERROR);
2921             }
2922         if (fromI == -1)
2923             fromI = tempInt;
2924         else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
2925             {
2926             toJ = tempInt;
2927             for (i=fromI-1; i<toJ; i++)
2928                 tempLinkUnlinkVec[i] = YES;
2929             fromI = toJ = -1;
2930             foundDash = NO;
2931             }
2932         else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
2933             {
2934             tempLinkUnlinkVec[fromI-1] = YES;
2935             fromI = tempInt;
2936             foundComma = NO;
2937             }
2938         expecting  = Expecting(COMMA);
2939         expecting |= Expecting(DASH);
2940         expecting |= Expecting(RIGHTPAR);
2941         }
2942     else if (expecting == Expecting(DASH))
2943         {
2944         foundDash = YES;
2945         expecting = Expecting(NUMBER);
2946         }
2947     else
2948         return (ERROR);
2949 
2950     return (NO_ERROR);
2951 }
2952 
2953 
DoLset(void)2954 int DoLset (void)
2955 {
2956     int         i, nApplied, lastActive=0;
2957 
2958     nApplied = NumActiveParts ();
2959     for (i=numCurrentDivisions-1; i>=0; i--)
2960         {
2961         if (activeParts[i] == YES)
2962             {
2963             lastActive = i;
2964             break;
2965             }
2966         }
2967 
2968     /* MrBayesPrint ("\n"); */
2969     if (numCurrentDivisions == 1)
2970         MrBayesPrint ("%s   Successfully set likelihood model parameters\n", spacer);
2971     else
2972         {
2973         if (nApplied == numCurrentDivisions || nApplied == 0)
2974             {
2975             MrBayesPrint ("%s   Successfully set likelihood model parameters to all\n", spacer);
2976             MrBayesPrint ("%s      applicable data partitions \n", spacer);
2977             }
2978         else
2979             {
2980             MrBayesPrint ("%s   Successfully set likelihood model parameters to\n", spacer);
2981             if (nApplied == 1)
2982                 MrBayesPrint ("%s   partition", spacer);
2983             else
2984                 MrBayesPrint ("%s   partitions", spacer);
2985             for (i=0; i<numCurrentDivisions; i++)
2986                 {
2987                 if (activeParts[i] == YES)
2988                     {
2989                     if (i == lastActive && nApplied > 1)
2990                         MrBayesPrint (" and %d", i+1);
2991                     else
2992                         MrBayesPrint (" %d", i+1);
2993                     if (nApplied > 2 && i != lastActive)
2994                         MrBayesPrint (",");
2995                     }
2996                 }
2997             MrBayesPrint (" (if applicable)\n");
2998             }
2999         }
3000 
3001     if (SetUpAnalysis (&globalSeed) == ERROR)
3002         return (ERROR);
3003 
3004     return (NO_ERROR);
3005 }
3006 
3007 
DoLsetParm(char * parmName,char * tkn)3008 int DoLsetParm (char *parmName, char *tkn)
3009 {
3010     int         i, j, tempInt, nApplied;
3011     char        tempStr[100];
3012 
3013     if (defMatrix == NO)
3014         {
3015         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
3016         return (ERROR);
3017         }
3018     if (inValidCommand == YES)
3019         {
3020         for (i=0; i<numCurrentDivisions; i++)
3021             activeParts[i] = NO;
3022         inValidCommand = NO;
3023         }
3024 
3025     if (expecting == Expecting(PARAMETER))
3026         {
3027         expecting = Expecting(EQUALSIGN);
3028         }
3029     else
3030         {
3031         /* set Applyto (Applyto) *************************************************************/
3032         if (!strcmp(parmName, "Applyto"))
3033             {
3034             if (expecting == Expecting(EQUALSIGN))
3035                 expecting = Expecting(LEFTPAR);
3036             else if (expecting == Expecting(LEFTPAR))
3037                 {
3038                 for (i=0; i<numCurrentDivisions; i++)
3039                     activeParts[i] = NO;
3040                 fromI = toJ = -1;
3041                 foundDash = NO;
3042                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
3043                 }
3044             else if (expecting == Expecting(RIGHTPAR))
3045                 {
3046                 if (fromI != -1)
3047                     activeParts[fromI-1] = YES;
3048                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3049                 }
3050             else if (expecting == Expecting(COMMA))
3051                 {
3052                 foundComma = YES;
3053                 expecting = Expecting(NUMBER);
3054                 }
3055             else if (expecting == Expecting(ALPHA))
3056                 {
3057                 if (IsSame ("All", tkn) == DIFFERENT)
3058                     {
3059                     MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
3060                     return (ERROR);
3061                     }
3062                 for (i=0; i<numCurrentDivisions; i++)
3063                     activeParts[i] = YES;
3064                 expecting  = Expecting(RIGHTPAR);
3065                 }
3066             else if (expecting == Expecting(NUMBER))
3067                 {
3068                 sscanf (tkn, "%d", &tempInt);
3069                 if (tempInt > numCurrentDivisions)
3070                     {
3071                     MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
3072                     return (ERROR);
3073                     }
3074                 if (fromI == -1)
3075                     fromI = tempInt;
3076                 else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
3077                     {
3078                     toJ = tempInt;
3079                     for (i=fromI-1; i<toJ; i++)
3080                         activeParts[i] = YES;
3081                     fromI = toJ = -1;
3082                     foundDash = NO;
3083                     }
3084                 else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
3085                     {
3086                     activeParts[fromI-1] = YES;
3087                     fromI = tempInt;
3088                     foundComma = NO;
3089                     }
3090 
3091                 expecting  = Expecting(COMMA);
3092                 expecting |= Expecting(DASH);
3093                 expecting |= Expecting(RIGHTPAR);
3094                 }
3095             else if (expecting == Expecting(DASH))
3096                 {
3097                 foundDash = YES;
3098                 expecting = Expecting(NUMBER);
3099                 }
3100             else
3101                 return (ERROR);
3102             }
3103         /* set Nucmodel (nucModel) ************************************************************/
3104         else if (!strcmp(parmName, "Nucmodel"))
3105             {
3106             if (expecting == Expecting(EQUALSIGN))
3107                 expecting = Expecting(ALPHA);
3108             else if (expecting == Expecting(ALPHA))
3109                 {
3110                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3111                     {
3112                     nApplied = NumActiveParts ();
3113                     tempInt = NO;
3114                     for (i=0; i<numCurrentDivisions; i++)
3115                         {
3116                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3117                             {
3118                             strcpy(modelParams[i].nucModel, tempStr);
3119                             modelParams[i].nStates = NumStates (i);
3120 
3121                             /* set state frequencies back to default */
3122                             strcpy(modelParams[i].stateFreqPr, "Dirichlet");
3123                             strcpy(modelParams[i].stateFreqsFixType, "Equal");
3124                             for (j=0; j<200; j++)
3125                                 {
3126                                 modelParams[i].stateFreqsFix[j] = 0.0;
3127                                 modelParams[i].stateFreqsDir[j] = 1.0;
3128                                 }
3129                             tempInt = YES;
3130                             if (nApplied == 0 && numCurrentDivisions == 1)
3131                                 MrBayesPrint ("%s   Setting Nucmodel to %s\n", spacer, modelParams[i].nucModel);
3132                             else
3133                                 MrBayesPrint ("%s   Setting Nucmodel to %s for partition %d\n", spacer, modelParams[i].nucModel, i+1);
3134                             }
3135                         }
3136                     if (tempInt == YES)
3137                         MrBayesPrint ("%s   Set state frequency prior to default\n", spacer);
3138                     }
3139                 else
3140                     {
3141                     MrBayesPrint ("%s   Invalid DNA substitution model\n", spacer);
3142                     return (ERROR);
3143                     }
3144                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3145                 }
3146             else
3147                 return (ERROR);
3148             }
3149         /* set Nst (nst) **********************************************************************/
3150         else if (!strcmp(parmName, "Nst"))
3151             {
3152             if (expecting == Expecting(EQUALSIGN))
3153                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
3154             else if (expecting == Expecting(NUMBER) || expecting == Expecting(ALPHA))
3155                 {
3156                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3157                     {
3158                     nApplied = NumActiveParts ();
3159                     for (i=0; i<numCurrentDivisions; i++)
3160                         {
3161                         if (activeParts[i] == YES || nApplied == 0)
3162                             {
3163                             if (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA)
3164                                 {
3165                                 strcpy(modelParams[i].nst, tempStr);
3166                                 if (nApplied == 0 && numCurrentDivisions == 1)
3167                                     MrBayesPrint ("%s   Setting Nst to %s\n", spacer, modelParams[i].nst);
3168                                 else
3169                                     MrBayesPrint ("%s   Setting Nst to %s for partition %d\n", spacer, modelParams[i].nst, i+1);
3170                                 }
3171                             else {
3172                                 if (nApplied == 0 && numCurrentDivisions == 1)
3173                                     MrBayesPrint ("%s   Nst =%s unchanged ", spacer, modelParams[i].nst);
3174                                 else
3175                                     MrBayesPrint ("%s   Nst =%s unchanged for partition %d ", spacer, modelParams[i].nst, i+1);
3176                                 MrBayesPrint ("because dataType is not DNA or RNA\n");
3177                                 }
3178                             }
3179                         }
3180                     }
3181                 else
3182                     {
3183                     MrBayesPrint ("%s   Invalid Nst argument\n", spacer);
3184                     return (ERROR);
3185                     }
3186                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3187                 }
3188             else
3189                 return (ERROR);
3190             }
3191         /* set Ngammacat (numGammaCats) ************************************************************/
3192         else if (!strcmp(parmName, "Ngammacat"))
3193             {
3194             if (expecting == Expecting(EQUALSIGN))
3195                 expecting = Expecting(NUMBER);
3196             else if (expecting == Expecting(NUMBER))
3197                 {
3198                 sscanf (tkn, "%d", &tempInt);
3199                 if (tempInt >= 2 && tempInt < MAX_RATE_CATS)
3200                     {
3201                     nApplied = NumActiveParts ();
3202                     for (i=0; i<numCurrentDivisions; i++)
3203                         {
3204                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3205                             {
3206                             modelParams[i].numGammaCats = tempInt;
3207                             if (nApplied == 0 && numCurrentDivisions == 1)
3208                                 MrBayesPrint ("%s   Setting Ngammacat to %d\n", spacer, modelParams[i].numGammaCats);
3209                             else
3210                                 MrBayesPrint ("%s   Setting Ngammacat to %d for partition %d\n", spacer, modelParams[i].numGammaCats, i+1);
3211                             }
3212                         }
3213                     }
3214                 else
3215                     {
3216                     MrBayesPrint ("%s   Invalid Ngammacat argument (should be between 2 and %d)\n", spacer, MAX_RATE_CATS);
3217                     return (ERROR);
3218                     }
3219                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3220                 }
3221             else
3222                 return (ERROR);
3223             }
3224         /* set Nlnormcat (numLnormCats) ************************************************************/
3225         else if (!strcmp(parmName, "Nlnormcat"))
3226             {
3227             if (expecting == Expecting(EQUALSIGN))
3228                 expecting = Expecting(NUMBER);
3229             else if (expecting == Expecting(NUMBER))
3230                 {
3231                 sscanf (tkn, "%d", &tempInt);
3232                 if (tempInt >= 2 && tempInt < MAX_RATE_CATS)
3233                     {
3234                     nApplied = NumActiveParts ();
3235                     for (i=0; i<numCurrentDivisions; i++)
3236                         {
3237                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3238                             {
3239                             modelParams[i].numLnormCats = tempInt;
3240                             if (nApplied == 0 && numCurrentDivisions == 1)
3241                                 MrBayesPrint ("%s   Setting Nlnormcat to %d\n", spacer, modelParams[i].numLnormCats);
3242                             else
3243                                 MrBayesPrint ("%s   Setting Nlnormcat to %d for partition %d\n", spacer, modelParams[i].numLnormCats, i+1);
3244                             }
3245                         }
3246                     }
3247                 else
3248                     {
3249                     MrBayesPrint ("%s   Invalid Nlnormcat argument (should be between 2 and %d)\n", spacer, MAX_RATE_CATS);
3250                     return (ERROR);
3251                     }
3252                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3253                 }
3254             else
3255                 return (ERROR);
3256             }
3257         /* set Nmixtcat (numMixtCats) ************************************************************/
3258         else if (!strcmp(parmName, "Nmixtcat"))
3259             {
3260             if (expecting == Expecting(EQUALSIGN))
3261                 expecting = Expecting(NUMBER);
3262             else if (expecting == Expecting(NUMBER))
3263                 {
3264                 sscanf (tkn, "%d", &tempInt);
3265                 if (tempInt >= 2 && tempInt < MAX_RATE_CATS)
3266                     {
3267                     nApplied = NumActiveParts ();
3268                     for (i=0; i<numCurrentDivisions; i++)
3269                         {
3270                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3271                             {
3272                             modelParams[i].numMixtCats = tempInt;
3273                             if (nApplied == 0 && numCurrentDivisions == 1)
3274                                 MrBayesPrint ("%s   Setting Nmixtcat to %d\n", spacer, modelParams[i].numMixtCats);
3275                             else
3276                                 MrBayesPrint ("%s   Setting Nmixtcat to %d for partition %d\n", spacer, modelParams[i].numLnormCats, i+1);
3277                             }
3278                         }
3279                     }
3280                 else
3281                     {
3282                     MrBayesPrint ("%s   Invalid Nmixtcat argument (should be between 2 and %d)\n", spacer, MAX_RATE_CATS);
3283                     return (ERROR);
3284                     }
3285                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3286                 }
3287             else
3288                 return (ERROR);
3289             }
3290         /* set Usegibbs (useGibbs) *************************************************************/
3291         else if (!strcmp(parmName, "Usegibbs"))
3292             {
3293             if (expecting == Expecting(EQUALSIGN))
3294                 expecting = Expecting(ALPHA);
3295             else if (expecting == Expecting(ALPHA))
3296                 {
3297                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3298                     {
3299                     nApplied = NumActiveParts ();
3300                     for (i=0; i<numCurrentDivisions; i++)
3301                         {
3302                         if (activeParts[i] == YES || nApplied == 0)
3303                             {
3304                             if (!strcmp(tempStr, "Yes"))
3305                                 {
3306                                 MrBayesPrint ("%s   Downsampling of site rates ('usegibbs = yes') disabled temporarily because of conflict with likelihood calculators\n", spacer);
3307                                 return (ERROR);
3308                                 strcpy(modelParams[i].useGibbs, "Yes");
3309                                 }
3310                             else
3311                                 {
3312                                 strcpy(modelParams[i].useGibbs, "No");
3313                                 }
3314 
3315                             if (nApplied == 0 && numCurrentDivisions == 1)
3316                                 MrBayesPrint ("%s   Setting Usegibbs to %s (if applicable)\n", spacer, modelParams[i].useGibbs);
3317                             else
3318                                 MrBayesPrint ("%s   Setting Usegibbs to %s (if applicable) for partition %d\n", spacer, modelParams[i].useGibbs, i+1);
3319                             }
3320                         }
3321                     }
3322                 else
3323                     {
3324                     MrBayesPrint ("%s   Invalid argument for Usegibbs (using Gibbs sampling of discrete gamma)\n", spacer);
3325                     return (ERROR);
3326                     }
3327                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3328                 }
3329             else
3330                 return (ERROR);
3331             }
3332         /* set Gibbsfreq (gibbsFreq) ************************************************************/
3333         else if (!strcmp(parmName, "Gibbsfreq"))
3334             {
3335             if (expecting == Expecting(EQUALSIGN))
3336                 expecting = Expecting(NUMBER);
3337             else if (expecting == Expecting(NUMBER))
3338                 {
3339                 sscanf (tkn, "%d", &tempInt);
3340                 if (tempInt >= 1 && tempInt <= 1000)
3341                     {
3342                     nApplied = NumActiveParts ();
3343                     for (i=0; i<numCurrentDivisions; i++)
3344                         {
3345                         if (activeParts[i] == YES || nApplied == 0)
3346                             {
3347                             modelParams[i].gibbsFreq = tempInt;
3348                             if (nApplied == 0 && numCurrentDivisions == 1)
3349                                 MrBayesPrint ("%s   Setting Gibbsfreq to %d\n", spacer, modelParams[i].gibbsFreq);
3350                             else
3351                                 MrBayesPrint ("%s   Setting Gibbsfreq to %d for partition %d\n", spacer, modelParams[i].gibbsFreq, i+1);
3352                             }
3353                         }
3354                     }
3355                 else
3356                     {
3357                     MrBayesPrint ("%s   Invalid Gibbsgammafreq argument (should be between 1 and 1000)\n", spacer);
3358                     return (ERROR);
3359                     }
3360                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3361                 }
3362             else
3363                 return (ERROR);
3364             }
3365         /* set NumM10GammaCats (numM10GammaCats) ************************************************************/
3366         else if (!strcmp(parmName, "NumM10GammaCats"))
3367             {
3368             if (expecting == Expecting(EQUALSIGN))
3369                 expecting = Expecting(NUMBER);
3370             else if (expecting == Expecting(NUMBER))
3371                 {
3372                 sscanf (tkn, "%d", &tempInt);
3373                 if (tempInt >= 2 && tempInt < MAX_RATE_CATS)
3374                     {
3375                     nApplied = NumActiveParts ();
3376                     for (i=0; i<numCurrentDivisions; i++)
3377                         {
3378                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3379                             {
3380                             modelParams[i].numM10GammaCats = tempInt;
3381                             if (nApplied == 0 && numCurrentDivisions == 1)
3382                                 MrBayesPrint ("%s   Setting NumM10GammaCats to %d\n", spacer, modelParams[i].numM10GammaCats);
3383                             else
3384                                 MrBayesPrint ("%s   Setting NumM10GammaCats to %d for partition %d\n", spacer, modelParams[i].numM10GammaCats, i+1);
3385                             }
3386                         }
3387                     }
3388                 else
3389                     {
3390                     MrBayesPrint ("%s   Invalid NumM10GammaCats argument (should be between 2 and %d)\n", spacer, MAX_RATE_CATS);
3391                     return (ERROR);
3392                     }
3393                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3394                 }
3395             else
3396                 return (ERROR);
3397             }
3398         /* set NumM10BetaCats (numM10BetaCats) ************************************************************/
3399         else if (!strcmp(parmName, "NumM10BetaCats"))
3400             {
3401             if (expecting == Expecting(EQUALSIGN))
3402                 expecting = Expecting(NUMBER);
3403             else if (expecting == Expecting(NUMBER))
3404                 {
3405                 sscanf (tkn, "%d", &tempInt);
3406                 if (tempInt >= 2 && tempInt < MAX_RATE_CATS)
3407                     {
3408                     nApplied = NumActiveParts ();
3409                     for (i=0; i<numCurrentDivisions; i++)
3410                         {
3411                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType != CONTINUOUS))
3412                             {
3413                             modelParams[i].numM10BetaCats = tempInt;
3414                             if (nApplied == 0 && numCurrentDivisions == 1)
3415                                 MrBayesPrint ("%s   Setting NumM10BetaCats to %d\n", spacer, modelParams[i].numM10BetaCats);
3416                             else
3417                                 MrBayesPrint ("%s   Setting NumM10BetaCats to %d for partition %d\n", spacer, modelParams[i].numM10BetaCats, i+1);
3418                             }
3419                         }
3420                     }
3421                 else
3422                     {
3423                     MrBayesPrint ("%s   Invalid NumM10GammaCats argument (should be between 2 and %d)\n", spacer, MAX_RATE_CATS);
3424                     return (ERROR);
3425                     }
3426                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3427                 }
3428             else
3429                 return (ERROR);
3430             }
3431         /* set Nbetacat (numBetaCats) *****************************************************/
3432         else if (!strcmp(parmName, "Nbetacat"))
3433             {
3434             if (expecting == Expecting(EQUALSIGN))
3435                 expecting = Expecting(NUMBER);
3436             else if (expecting == Expecting(NUMBER))
3437                 {
3438                 sscanf (tkn, "%d", &tempInt);
3439                 if (tempInt >= 2 && tempInt < MAX_RATE_CATS)
3440                     {
3441                     nApplied = NumActiveParts ();
3442                     for (i=0; i<numCurrentDivisions; i++)
3443                         {
3444                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
3445                             {
3446                             modelParams[i].numBetaCats = tempInt;
3447                             if (nApplied == 0 && numCurrentDivisions == 1)
3448                                 MrBayesPrint ("%s   Setting Nbetacat to %d\n", spacer, modelParams[i].numBetaCats);
3449                             else
3450                                 MrBayesPrint ("%s   Setting Nbetacat to %d for partition %d\n", spacer, modelParams[i].numBetaCats, i+1);
3451                             }
3452                         }
3453                     }
3454                 else
3455                     {
3456                     MrBayesPrint ("%s   Invalid Nbetacat argument (should be between 2 and %d)\n", spacer, MAX_RATE_CATS);
3457                     return (ERROR);
3458                     }
3459                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3460                 }
3461             else
3462                 return (ERROR);
3463             }
3464         /* set Aamodel (aaModel) **************************************************************/
3465         else if (!strcmp(parmName, "Aamodel"))
3466             {
3467             MrBayesPrint ("%s   Aamodel argument for lset deprecated.\n", spacer);
3468             MrBayesPrint ("%s   Use 'prset aamodelpr=fixed(<aamodel>)' instead.\n", spacer);
3469             return (ERROR);
3470             }
3471         /* set Parsmodel (useParsModel) *******************************************************/
3472         else if (!strcmp(parmName, "Parsmodel"))
3473             {
3474             if (expecting == Expecting(EQUALSIGN))
3475                 expecting = Expecting(ALPHA);
3476             else if (expecting == Expecting(ALPHA))
3477                 {
3478                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3479                     {
3480                     nApplied = NumActiveParts ();
3481                     for (i=0; i<numCurrentDivisions; i++)
3482                         {
3483                         if (activeParts[i] == YES || nApplied == 0)
3484                             {
3485                             if (!strcmp(tempStr, "Yes"))
3486                                 strcpy(modelParams[i].parsModel, "Yes");
3487                             else
3488                                 strcpy(modelParams[i].parsModel, "No");
3489 
3490                             if (nApplied == 0 && numCurrentDivisions == 1)
3491                                 MrBayesPrint ("%s   Setting Parsmodel to %s\n", spacer, modelParams[i].parsModel);
3492                             else
3493                                 MrBayesPrint ("%s   Setting Parsmodel to %s for partition %d\n", spacer, modelParams[i].parsModel, i+1);
3494                             }
3495                         }
3496                     }
3497                 else
3498                     {
3499                     MrBayesPrint ("%s   Invalid argument for using (so-called) parsimony model\n", spacer);
3500                     return (ERROR);
3501                     }
3502                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3503                 }
3504             else
3505                 return (ERROR);
3506             }
3507         /* set Augment (augmentData) **********************************************************/
3508         else if (!strcmp(parmName, "Augment"))
3509             {
3510             if (expecting == Expecting(EQUALSIGN))
3511                 expecting = Expecting(ALPHA);
3512             else if (expecting == Expecting(ALPHA))
3513                 {
3514                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3515                     {
3516                     nApplied = NumActiveParts ();
3517                     for (i=0; i<numCurrentDivisions; i++)
3518                         {
3519                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
3520                             {
3521                             if (!strcmp(tempStr, "Yes"))
3522                                 strcpy(modelParams[i].augmentData, "Yes");
3523                             else
3524                                 strcpy(modelParams[i].augmentData, "No");
3525 
3526                             if (nApplied == 0 && numCurrentDivisions == 1)
3527                                 MrBayesPrint ("%s   Setting Augmentdata to %s\n", spacer, modelParams[i].augmentData);
3528                             else
3529                                 MrBayesPrint ("%s   Setting Augmentdata to %s for partition %d\n", spacer, modelParams[i].augmentData, i+1);
3530                             }
3531                         }
3532                     }
3533                 else
3534                     {
3535                     MrBayesPrint ("%s   Invalid argument for data augmentation\n", spacer);
3536                     return (ERROR);
3537                     }
3538                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3539                 }
3540             else
3541                 return (ERROR);
3542             }
3543         /* set Omegavar (wVarModel) ***********************************************************/
3544         else if (!strcmp(parmName, "Omegavar"))
3545             {
3546             if (expecting == Expecting(EQUALSIGN))
3547                 expecting = Expecting(ALPHA);
3548             else if (expecting == Expecting(ALPHA))
3549                 {
3550                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3551                     {
3552                     nApplied = NumActiveParts ();
3553                     for (i=0; i<numCurrentDivisions; i++)
3554                         {
3555                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3556                             {
3557                             strcpy(modelParams[i].omegaVar, tempStr);
3558                             if (nApplied == 0 && numCurrentDivisions == 1)
3559                                 MrBayesPrint ("%s   Setting Omegavar to %s\n", spacer, modelParams[i].omegaVar);
3560                             else
3561                                 MrBayesPrint ("%s   Setting Omegavar to %s for partition %d\n", spacer, modelParams[i].omegaVar, i+1);
3562                             }
3563                         }
3564                     }
3565                 else
3566                     {
3567                     MrBayesPrint ("%s   Invalid omega variation argument\n", spacer);
3568                     return (ERROR);
3569                     }
3570                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3571                 }
3572             else
3573                 return (ERROR);
3574             }
3575         /* set Code (codeModel) ***************************************************************/
3576         else if (!strcmp(parmName, "Code"))
3577             {
3578             if (expecting == Expecting(EQUALSIGN))
3579                 expecting = Expecting(ALPHA);
3580             else if (expecting == Expecting(ALPHA))
3581                 {
3582                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3583                     {
3584                     nApplied = NumActiveParts ();
3585                     for (i=0; i<numCurrentDivisions; i++)
3586                         {
3587                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3588                             {
3589                             strcpy(modelParams[i].geneticCode, tempStr);
3590                             SetCode (i);
3591                             modelParams[i].nStates = NumStates (i);
3592                             if (nApplied == 0 && numCurrentDivisions == 1)
3593                                 MrBayesPrint ("%s   Setting Code to %s\n", spacer, modelParams[i].geneticCode);
3594                             else
3595                                 MrBayesPrint ("%s   Setting Code to %s for partition %d\n", spacer, modelParams[i].geneticCode, i+1);
3596                             }
3597                         }
3598                     }
3599                 else
3600                     {
3601                     MrBayesPrint ("%s   Invalid genetic code argument\n", spacer);
3602                     return (ERROR);
3603                     }
3604                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3605                 }
3606             else
3607                 return (ERROR);
3608             }
3609         /* set Ploidy (ploidy) ***************************************************************/
3610         else if (!strcmp(parmName, "Ploidy"))
3611             {
3612             if (expecting == Expecting(EQUALSIGN))
3613                 expecting = Expecting(ALPHA);
3614             else if (expecting == Expecting(ALPHA))
3615                 {
3616                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3617                     {
3618                     nApplied = NumActiveParts ();
3619                     for (i=0; i<numCurrentDivisions; i++)
3620                         {
3621                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
3622                             {
3623                             strcpy(modelParams[i].ploidy, tempStr);
3624                             if (nApplied == 0 && numCurrentDivisions == 1)
3625                                 MrBayesPrint ("%s   Setting ploidy level to %s\n", spacer, modelParams[i].ploidy);
3626                             else
3627                                 MrBayesPrint ("%s   Setting ploidy level to %s for partition %d\n", spacer, modelParams[i].ploidy, i+1);
3628                             }
3629                         }
3630                     }
3631                 else
3632                     {
3633                     MrBayesPrint ("%s   Invalid ploidy level argument\n", spacer);
3634                     return (ERROR);
3635                     }
3636                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3637                 }
3638             else
3639                 return (ERROR);
3640             }
3641         /* set Rates (ratesModel) *************************************************************/
3642         else if (!strcmp(parmName, "Rates"))
3643             {
3644             if (expecting == Expecting(EQUALSIGN))
3645                 expecting = Expecting(ALPHA);
3646             else if (expecting == Expecting(ALPHA))
3647                 {
3648                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3649                     {
3650                     nApplied = NumActiveParts ();
3651                     for (i=0; i<numCurrentDivisions; i++)
3652                         {
3653                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
3654                             {
3655                             if (!strcmp(tempStr, "Adgamma") && (modelParams[i].dataType != DNA && modelParams[i].dataType != RNA && modelParams[i].dataType != PROTEIN))
3656                                 {
3657                                 /* we won't apply an adgamma model to anything but DNA, RNA, or PROTEIN data */
3658                                 }
3659                             else if ((!strcmp(tempStr, "Propinv") ||  !strcmp(tempStr, "Invgamma")) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
3660                                 {
3661                                 /* we will not apply pinvar to standard or restriction site data */
3662                                 }
3663                             else
3664                                 {
3665                                 strcpy(modelParams[i].ratesModel, tempStr);
3666                                 if (nApplied == 0 && numCurrentDivisions == 1)
3667                                     MrBayesPrint ("%s   Setting Rates to %s\n", spacer, modelParams[i].ratesModel);
3668                                 else
3669                                     MrBayesPrint ("%s   Setting Rates to %s for partition %d\n", spacer, modelParams[i].ratesModel, i+1);
3670                                 }
3671                             }
3672                         }
3673                     }
3674                 else
3675                     {
3676                     MrBayesPrint ("%s   Invalid Rates argument\n", spacer);
3677                     return (ERROR);
3678                     }
3679                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3680                 }
3681             else
3682                 return (ERROR);
3683             }
3684         /* set Covarion (covarionModel) *******************************************************/
3685         else if (!strcmp(parmName, "Covarion"))
3686             {
3687             if (expecting == Expecting(EQUALSIGN))
3688                 expecting = Expecting(ALPHA);
3689             else if (expecting == Expecting(ALPHA))
3690                 {
3691                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3692                     {
3693                     nApplied = NumActiveParts ();
3694                     for (i=0; i<numCurrentDivisions; i++)
3695                         {
3696                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
3697                             {
3698                             strcpy(modelParams[i].covarionModel, tempStr);
3699                             if (nApplied == 0 && numCurrentDivisions == 1)
3700                                 MrBayesPrint ("%s   Setting Covarion to %s\n", spacer, modelParams[i].covarionModel);
3701                             else
3702                                 MrBayesPrint ("%s   Setting Covarion to %s for partition %d\n", spacer, modelParams[i].covarionModel, i+1);
3703                             }
3704                         }
3705                     }
3706                 else
3707                     {
3708                     MrBayesPrint ("%s   Invalid Rates argument\n", spacer);
3709                     return (ERROR);
3710                     }
3711                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3712                 }
3713             else
3714                 return (ERROR);
3715             }
3716         /* set Coding (missingType) ***********************************************************/
3717         else if (!strcmp(parmName, "Coding"))
3718             {
3719             if (expecting == Expecting(EQUALSIGN))
3720                 {
3721                 for (i=0; i<numCurrentDivisions; i++)
3722                     modelParams[i].coding = ALL;
3723 
3724                 expecting = Expecting(ALPHA);
3725                 }
3726             else if (expecting == Expecting(VERTICALBAR))
3727                 expecting = Expecting(ALPHA);
3728             else if (expecting == Expecting(ALPHA))
3729                 {
3730                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3731                     {
3732                     nApplied = NumActiveParts ();
3733                     for (i=0; i<numCurrentDivisions; i++)
3734                         {
3735                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD))
3736                             {
3737                             if(!strcmp(tempStr, "All"))
3738                                 {
3739                                 modelParams[i].coding |= ALL; // Does nothing
3740                                 }
3741                             else if(!strcmp(tempStr, "Nosingletons"))
3742                                 {
3743                                 modelParams[i].coding |= NOSINGLETONS;
3744                                 }
3745                             else if(!strcmp(tempStr, "Variable"))
3746                                 {
3747                                 modelParams[i].coding |= VARIABLE;
3748                                 }
3749                             else if(!strcmp(tempStr, "Informative"))
3750                                 {
3751                                 modelParams[i].coding |= INFORMATIVE;
3752                                 }
3753                             else
3754                                 {
3755                                 if(modelParams[i].dataType != RESTRICTION)
3756                                     {
3757                                     MrBayesPrint ("%s   Invalid coding for standard characters: %s\n", spacer, tempStr);
3758                                     return (ERROR);
3759                                     }
3760 
3761                                 if(!strcmp(tempStr, "Noabsencesites"))
3762                                     {
3763                                     modelParams[i].coding |= NOABSENCESITES;
3764                                     }
3765                                 else if(!strcmp(tempStr, "Nopresencesites"))
3766                                     {
3767                                     modelParams[i].coding |= NOPRESENCESITES;
3768                                     }
3769                                 else if(!strcmp(tempStr, "Nosingletonpresence"))
3770                                     {
3771                                     modelParams[i].coding |= NOSINGLETONPRESENCE;
3772                                     }
3773                                 else if(!strcmp(tempStr, "Nosingletonabsence"))
3774                                     {
3775                                     modelParams[i].coding |= NOSINGLETONABSENCE;
3776                                     }
3777                                 }
3778 
3779                             CodingToString(modelParams[i].coding, modelParams[i].codingString);
3780 
3781                             if (nApplied == 0 && numCurrentDivisions == 1)
3782                                 MrBayesPrint ("%s   Enabling Coding %s\n", spacer, tempStr);
3783                             else
3784                                 MrBayesPrint ("%s   Enabling Coding %s for partition %d\n", spacer, tempStr, i+1);
3785                             }
3786                         }
3787                     }
3788                 else
3789                     {
3790                     MrBayesPrint ("%s   Invalid argument for missing patterns\n", spacer);
3791                     return (ERROR);
3792                     }
3793                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON) | Expecting(VERTICALBAR);
3794                 }
3795             else
3796                 return (ERROR);
3797             }
3798 
3799 
3800 
3801 
3802         else
3803             return (ERROR);
3804         }
3805 
3806     return (NO_ERROR);
3807 }
3808 
3809 
DoPlot(void)3810 int DoPlot (void)
3811 {
3812     int             i, n, nHeaders, burnin, len, longestHeader, whichIsX, whichIsY, numPlotted;
3813     char            temp[100], **headerNames = NULL;
3814     SumpFileInfo    fileInfo;
3815     ParameterSample *parameterSamples;
3816 
3817 #   if defined (MPI_ENABLED)
3818     if (proc_id != 0)
3819         return NO_ERROR;
3820 #   endif
3821 
3822     /* initialize values */
3823     headerNames = NULL;
3824     nHeaders = 0;
3825     parameterSamples = NULL;
3826 
3827     /* tell user we are ready to go */
3828     MrBayesPrint ("%s   Plotting parameters in file %s ...\n", spacer, plotParams.plotFileName);
3829 
3830     /* examine plot file */
3831     if (ExamineSumpFile (plotParams.plotFileName, &fileInfo, &headerNames, &nHeaders) == ERROR)
3832         return ERROR;
3833 
3834     /* Calculate burn in */
3835     burnin = fileInfo.firstParamLine - fileInfo.headerLine - 1;
3836 
3837     /* tell the user that everything is fine */
3838     MrBayesPrint ("%s   Found %d parameter lines in file \"%s\"\n", spacer, fileInfo.numRows + burnin, plotParams.plotFileName);
3839     if (burnin > 0)
3840         MrBayesPrint ("%s   Of the %d lines, %d of them will be summarized (starting at line %d)\n", spacer, fileInfo.numRows+burnin, fileInfo.numRows, fileInfo.firstParamLine);
3841     else
3842         MrBayesPrint ("%s   All %d lines will be summarized (starting at line %d)\n", spacer, fileInfo.numRows, fileInfo.firstParamLine);
3843     MrBayesPrint ("%s   (Only the last set of lines will be read, in case multiple\n", spacer);
3844     MrBayesPrint ("%s   parameter blocks are present in the same file.)\n", spacer);
3845 
3846     /* allocate space to hold parameter information */
3847     if (AllocateParameterSamples (&parameterSamples, 1, fileInfo.numRows, fileInfo.numColumns) == ERROR)
3848         goto errorExit;
3849 
3850     /* Now we read the file for real. First, rewind file pointer to beginning of file... */
3851     if (ReadParamSamples (plotParams.plotFileName, &fileInfo, parameterSamples, 0) == ERROR)
3852         goto errorExit;
3853 
3854     /* get length of longest header */
3855     longestHeader = 9; /* 9 is the length of the word "parameter" (for printing table) */
3856     for (i=0; i<nHeaders; i++)
3857         {
3858         len = (int) strlen(headerNames[i]);
3859         if (len > longestHeader)
3860             longestHeader = len;
3861         }
3862 
3863     /* print x-y plot of parameter vs. generation */
3864     whichIsX = -1;
3865     for (i=0; i<nHeaders; i++)
3866         {
3867         if (IsSame (headerNames[i], "Gen") == SAME)
3868             whichIsX = i;
3869         }
3870 
3871     if (whichIsX < 0)
3872         {
3873         MrBayesPrint ("%s   Could not find a column labelled \"Gen\" \n", spacer);
3874         goto errorExit;
3875         }
3876 
3877     numPlotted = 0;
3878     for (n=0; n<nHeaders; n++)
3879         {
3880         strcpy (temp, headerNames[n]);
3881         whichIsY = -1;
3882         if (!strcmp(plotParams.match, "Perfect"))
3883             {
3884             if (IsSame (temp, plotParams.parameter) == SAME)
3885                 whichIsY = n;
3886             }
3887         else if (!strcmp(plotParams.match, "All"))
3888             {
3889             whichIsY = n;
3890             }
3891         else
3892             {
3893             if (IsSame (temp, plotParams.parameter) == CONSISTENT_WITH)
3894                 whichIsY = n;
3895             }
3896 
3897         if (whichIsY >= 0 && whichIsX != whichIsY)
3898             {
3899             MrBayesPrint ("\n%s   Rough trace plot of parameter %s:\n", spacer, headerNames[whichIsY]);
3900             if (PrintPlot (parameterSamples[whichIsX].values[0], parameterSamples[whichIsY].values[0], fileInfo.numRows) == ERROR)
3901                 goto errorExit;
3902             numPlotted++;
3903             }
3904         }
3905 
3906     if (numPlotted == 0)
3907         {
3908         MrBayesPrint ("%s   Did not find any parameters matching \"%s\" to plot\n", spacer, plotParams.parameter);
3909         }
3910 
3911     /* free memory */
3912     for (i=0; i<nHeaders; i++)
3913         free (headerNames[i]);
3914     free(headerNames);
3915     FreeParameterSamples(parameterSamples);
3916 
3917     expecting = Expecting(COMMAND);
3918 
3919     return (NO_ERROR);
3920 
3921 errorExit:
3922 
3923     /* free memory */
3924     for (i=0; i<nHeaders; i++)
3925         free (headerNames[i]);
3926     free(headerNames);
3927     FreeParameterSamples(parameterSamples);
3928 
3929     expecting = Expecting(COMMAND);
3930 
3931     return (ERROR);
3932 }
3933 
3934 
DoPlotParm(char * parmName,char * tkn)3935 int DoPlotParm (char *parmName, char *tkn)
3936 {
3937     int         tempI;
3938     MrBFlt      tempD;
3939     char        tempStr[100];
3940 
3941     if (defMatrix == NO)
3942         {
3943         MrBayesPrint ("%s   A matrix must be specified before sumt can be used\n", spacer);
3944         return (ERROR);
3945         }
3946 
3947     if (expecting == Expecting(PARAMETER))
3948         {
3949         expecting = Expecting(EQUALSIGN);
3950         }
3951     else
3952         {
3953         if (!strcmp(parmName, "Xxxxxxxxxx"))
3954             {
3955             expecting  = Expecting(PARAMETER);
3956             expecting |= Expecting(SEMICOLON);
3957             }
3958         /* set Filename (plotParams.plotFileName) ***************************************************/
3959         else if (!strcmp(parmName, "Filename"))
3960             {
3961             if (expecting == Expecting(EQUALSIGN))
3962                 {
3963                 expecting = Expecting(ALPHA);
3964                 readWord = YES;
3965                 }
3966             else if (expecting == Expecting(ALPHA))
3967                 {
3968                 strcpy (plotParams.plotFileName, tkn);
3969                 MrBayesPrint ("%s   Setting plot filename to %s\n", spacer, plotParams.plotFileName);
3970                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3971                 }
3972             else
3973                 return (ERROR);
3974             }
3975         /* set Relburnin (chainParams.relativeBurnin) ********************************************************/
3976         else if (!strcmp(parmName, "Relburnin"))
3977             {
3978             if (expecting == Expecting(EQUALSIGN))
3979                 expecting = Expecting(ALPHA);
3980             else if (expecting == Expecting(ALPHA))
3981                 {
3982                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
3983                     {
3984                     if (!strcmp(tempStr, "Yes"))
3985                         chainParams.relativeBurnin = YES;
3986                     else
3987                         chainParams.relativeBurnin = NO;
3988                     }
3989                 else
3990                     {
3991                     MrBayesPrint ("%s   Invalid argument for Relburnin\n", spacer);
3992                     return (ERROR);
3993                     }
3994                 if (chainParams.relativeBurnin == YES)
3995                     MrBayesPrint ("%s   Using relative burnin (a fraction of samples discarded).\n", spacer);
3996                 else
3997                     MrBayesPrint ("%s   Using absolute burnin (a fixed number of samples discarded).\n", spacer);
3998                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
3999                 }
4000             else
4001                 {
4002                 return (ERROR);
4003                 }
4004             }
4005         /* set Burnin (chainParams.chainBurnIn) *******************************************************/
4006         else if (!strcmp(parmName, "Burnin"))
4007             {
4008             if (expecting == Expecting(EQUALSIGN))
4009                 expecting = Expecting(NUMBER);
4010             else if (expecting == Expecting(NUMBER))
4011                 {
4012                 sscanf (tkn, "%d", &tempI);
4013                 chainParams.chainBurnIn = tempI;
4014                 MrBayesPrint ("%s   Setting burnin to %d\n", spacer, chainParams.chainBurnIn);
4015                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4016                 }
4017             else
4018                 return (ERROR);
4019             }
4020         /* set Burninfrac (chainParams.burninFraction) ************************************************************/
4021         else if (!strcmp(parmName, "Burninfrac"))
4022             {
4023             if (expecting == Expecting(EQUALSIGN))
4024                 expecting = Expecting(NUMBER);
4025             else if (expecting == Expecting(NUMBER))
4026                 {
4027                 sscanf (tkn, "%lf", &tempD);
4028                 if (tempD < 0.01)
4029                     {
4030                     MrBayesPrint ("%s   Burnin fraction too low (< 0.01)\n", spacer);
4031                     return (ERROR);
4032                     }
4033                 if (tempD > 0.50)
4034                     {
4035                     MrBayesPrint ("%s   Burnin fraction too high (> 0.50)\n", spacer);
4036                     return (ERROR);
4037                     }
4038                 chainParams.burninFraction = tempD;
4039                 MrBayesPrint ("%s   Setting burnin fraction to %.2f\n", spacer, chainParams.burninFraction);
4040                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4041                 }
4042             else
4043                 {
4044                 return (ERROR);
4045                 }
4046             }
4047         /* set Parameter (plotParams.parameter) *******************************************************/
4048         else if (!strcmp(parmName, "Parameter"))
4049             {
4050             if (expecting == Expecting(EQUALSIGN))
4051                 {
4052                 expecting = Expecting(ALPHA);
4053                 readWord = YES;
4054                 }
4055             else if (expecting == Expecting(ALPHA))
4056                 {
4057                 strcpy (plotParams.parameter, tkn);
4058                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4059                 }
4060             else
4061                 return (ERROR);
4062             }
4063         /* set Parameter (plotParams.match) *******************************************************/
4064         else if (!strcmp(parmName, "Match"))
4065             {
4066             if (expecting == Expecting(EQUALSIGN))
4067                 expecting = Expecting(ALPHA);
4068             else if (expecting == Expecting(ALPHA))
4069                 {
4070                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4071                     strcpy (plotParams.match, tempStr);
4072                 else
4073                     return (ERROR);
4074 
4075                 MrBayesPrint ("%s   Setting plot matching to %s\n", spacer, plotParams.match);
4076                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4077                 }
4078             else
4079                 return (ERROR);
4080             }
4081 
4082         else
4083             return (ERROR);
4084         }
4085 
4086     return (NO_ERROR);
4087 }
4088 
4089 
DoPropset(void)4090 int DoPropset (void)
4091 {
4092     MrBayesPrint ("%s   Successfully set proposal parameters\n", spacer);
4093 
4094     return (NO_ERROR);
4095 }
4096 
4097 
DoPropsetParm(char * parmName,char * tkn)4098 int DoPropsetParm (char *parmName, char *tkn)
4099 {
4100     int                 i, j, k, nMatches, tempInt;
4101     MrBFlt              tempFloat;
4102     static MCMCMove     *mv = NULL;
4103     static MrBFlt       *theValue, theValueMin, theValueMax;
4104     static int          jump, runIndex, chainIndex;
4105     static char         *temp=NULL, *localTkn=NULL; /*freed at the end of the call*/
4106     static char         *tempName=NULL;         /*not freed at the end of the call*/
4107 
4108     if (defMatrix == NO)
4109         {
4110         MrBayesPrint ("%s   A matrix must be specified before proposal parameters can be changed\n", spacer);
4111         return (ERROR);
4112         }
4113 
4114     if (expecting == Expecting(PARAMETER))
4115         {
4116         if (!strcmp(parmName, "Xxxxxxxxxx"))
4117             {
4118             /* we expect a move name with possible run and chain specification as follows:
4119                <move_name>$<tuning_param_name>(<run>,<chain>)=<number>   -- apply to run <run> and chain <chain>
4120                <move_name>$<tuning_param_name>(,<chain>)=<number>        -- apply to chain <chain> for all runs
4121                <move_name>$<tuning_param_name>(<run>,)=<number>          -- apply to all chains of run <run>
4122                <move_name>$prob(<run>,<chain>)=<number>                  -- change relative proposal probability
4123                <move_name>$targetrate(<run>,<chain>)=<number>            -- change target acc rate for autotuning
4124 
4125                the parsing is complicated by the fact that the move name can look something like:
4126                eTBR(Tau{all})
4127                eTBR(Tau{1,4,5})
4128                so we need to assemble the move name from several tokens that are parsed out separately;
4129                here we receive only the first part (before the left parenthesis)
4130             */
4131 
4132             /* copy to local move name */
4133             SafeStrcpy(&tempName, tkn);
4134             mv = NULL;
4135             foundComma = foundEqual = NO;
4136             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4137                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4138                 Expecting(DOLLAR);
4139             }
4140         else
4141             return (ERROR);
4142         }
4143     else if (expecting == Expecting(ALPHA))
4144         {
4145         if (mv == NULL)
4146             {
4147             /* we are still assembling the move name */
4148             SafeStrcat(&tempName, tkn);
4149             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4150                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4151                 Expecting(DOLLAR);
4152             }
4153         else
4154             {
4155             /* we have a parameter name; now find the parameter name, case insensitive */
4156             SafeStrcpy(&localTkn, tkn);
4157             for (i=0; i<(int)strlen(localTkn); i++)
4158                 localTkn[i] = tolower(localTkn[i]);
4159             nMatches = j = 0;
4160             for (i=0; i<mv->moveType->numTuningParams; i++)
4161                 {
4162                 SafeStrcpy(&temp, mv->moveType->shortTuningName[i]);
4163                 for (k=0; k<(int)strlen(temp); k++)
4164                     temp[k] = tolower(temp[k]);
4165                 if (strncmp(localTkn,temp,strlen(localTkn)) == 0)
4166                     {
4167                     j = i;
4168                     nMatches++;
4169                     }
4170                 }
4171             if (strncmp(localTkn,"prob",strlen(localTkn)) == 0)
4172                 {
4173                 j = -1;
4174                 nMatches++;
4175                 }
4176             else if (strncmp(localTkn,"targetrate",strlen(localTkn)) == 0)
4177                 {
4178                 j = -2;
4179                 nMatches++;
4180                 }
4181             if (nMatches == 0)
4182                 {
4183                 MrBayesPrint ("%s   Could not find move parameter to change '%s'\n", spacer, localTkn);
4184                 return (ERROR);
4185                 }
4186             else if (nMatches > 1)
4187                 {
4188                 MrBayesPrint ("%s   Several move parameters matched the abbreviated name '%s'\n", spacer, localTkn);
4189                 return (ERROR);
4190                 }
4191 
4192             if (j == -1)
4193                 {
4194                 theValue = mv->relProposalProb;
4195                 theValueMin = 0.0;
4196                 theValueMax = 1000.0;
4197                 jump = 1;
4198                 }
4199             else if (j == -2)
4200                 {
4201                 theValue = mv->targetRate;
4202                 theValueMin = 0.10;
4203                 theValueMax = 0.70;
4204                 jump = 1;
4205                 }
4206             else
4207                 {
4208                 theValue = &mv->tuningParam[0][j];
4209                 theValueMin = mv->moveType->minimum[j];
4210                 theValueMax = mv->moveType->maximum[j];
4211                 jump = mv->moveType->numTuningParams;
4212                 }
4213             chainIndex = -1;
4214             runIndex = -1;
4215             expecting = Expecting(LEFTPAR) | Expecting(EQUALSIGN);
4216             }
4217         }
4218     else if (expecting == Expecting(LEFTCURL) || expecting == Expecting(RIGHTCURL))
4219         {
4220         /* we are still assembling the move name */
4221         SafeStrcat (&tempName, tkn);
4222         expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4223             Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4224             Expecting(DOLLAR);
4225         }
4226     else if (expecting == Expecting(DOLLAR))
4227         {
4228         /* we know that the name is complete now; find the move by its name,
4229            case insensitive */
4230         SafeStrcpy(&localTkn, tempName);
4231         j=(int)strlen(localTkn);
4232         for (i=0; i<j; i++)
4233             localTkn[i] = tolower(localTkn[i]);
4234 
4235         /* find the move */
4236         nMatches = j = 0;
4237         for (i=0; i<numApplicableMoves; i++)
4238             {
4239             mv = moves[i];
4240             SafeStrcpy(&temp,mv->name);
4241             for (k=0; k<(int)strlen(temp); k++)
4242                 temp[k] = tolower(temp[k]);
4243             if (strncmp(temp,localTkn,strlen(localTkn)) == 0)
4244                 {
4245                 j = i;
4246                 nMatches++;
4247                 }
4248             }
4249         if (nMatches == 0)
4250             {
4251             MrBayesPrint ("%s   Could not find move '%s'\n", spacer, localTkn);
4252             return (ERROR);
4253             }
4254         else if (nMatches > 1)
4255             {
4256             MrBayesPrint ("%s   Several moves matched the abbreviated name '%s'\n", spacer, localTkn);
4257             return (ERROR);
4258             }
4259         else
4260             mv = moves[j];
4261 
4262         foundComma = foundEqual = NO;
4263         expecting = Expecting(ALPHA);
4264         }
4265     else if (expecting == Expecting(LEFTPAR))
4266         {
4267         if (mv == NULL)
4268             {
4269             /* we are still assembling the move name */
4270             SafeStrcat (&tempName, tkn);
4271             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4272                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4273                 Expecting(DOLLAR);
4274             }
4275         else /* if (mv != NULL) */
4276             {
4277             /* we will be reading in run and chain indices */
4278             expecting = Expecting(NUMBER) | Expecting(COMMA);
4279             }
4280         }
4281     else if (expecting == Expecting(NUMBER))
4282         {
4283         if (mv == NULL)
4284             {
4285             /* we are still assembling the move name */
4286             SafeStrcat (&tempName, tkn);
4287             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4288                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4289                 Expecting(DOLLAR);
4290             }
4291         else if (foundEqual == YES)
4292             {
4293             sscanf (tkn, "%lf", &tempFloat);
4294             if (tempFloat < theValueMin || tempFloat > theValueMax)
4295                 {
4296                 MrBayesPrint ("%s   The value is out of range (min = %lf; max = %lf)\n", spacer, theValueMin, theValueMax);
4297                 return (ERROR);
4298                 }
4299             if (runIndex == -1 && chainIndex == -1)
4300                 {
4301                 for (i=0; i<chainParams.numRuns; i++)
4302                     {
4303                     for (j=0; j<chainParams.numChains; j++)
4304                         {
4305                         *theValue = tempFloat;
4306                         theValue += jump;
4307                         }
4308                     }
4309                 }
4310             else if (runIndex == -1 && chainIndex >= 0)
4311                 {
4312                 theValue += chainIndex*jump;
4313                 for (i=0; i<chainParams.numRuns; i++)
4314                     {
4315                     *theValue = tempFloat;
4316                     theValue += chainParams.numChains*jump;
4317                     }
4318                 }
4319             else if (runIndex >= 0 && chainIndex == -1)
4320                 {
4321                 theValue += runIndex*chainParams.numChains*jump;
4322                 for (i=0; i<chainParams.numChains; i++)
4323                     {
4324                     *theValue = tempFloat;
4325                     theValue += jump;
4326                     }
4327                 }
4328             else /* if (runIndex >= 0 && chainIndex >= 0) */
4329                 {
4330                 theValue[runIndex*chainParams.numChains*jump+chainIndex*jump] = tempFloat;
4331                 }
4332             expecting = Expecting (PARAMETER) | Expecting(SEMICOLON);
4333             }
4334         else /* if (foundEqual == NO) */
4335             {
4336             sscanf (tkn, "%d", &tempInt);
4337             if (foundComma == NO)
4338                 {
4339                 if (tempInt <= 0 || tempInt > chainParams.numRuns)
4340                     {
4341                     MrBayesPrint ("%s   Run index is out of range (min=1; max=%d)\n", spacer, chainParams.numRuns);
4342                     return (ERROR);
4343                     }
4344                 runIndex = tempInt - 1;
4345                 expecting = Expecting(COMMA);
4346                 }
4347             else
4348                 {
4349                 if (tempInt <= 0 || tempInt > chainParams.numChains)
4350                     {
4351                     MrBayesPrint ("%s   Chain index is out of range (min=1; max=%d)\n", spacer, chainParams.numChains);
4352                     return (ERROR);
4353                     }
4354                 chainIndex = tempInt - 1;
4355                 expecting = Expecting(RIGHTPAR);
4356                 }
4357             }
4358         }
4359     else if (expecting == Expecting(COMMA))
4360         {
4361         if (mv == NULL)
4362             {
4363             /* we are still assembling the move name */
4364             SafeStrcat (&tempName, tkn);
4365             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4366                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4367                 Expecting(DOLLAR);
4368             }
4369         else
4370             {
4371             /* we will be reading in chain index, if present */
4372             foundComma = YES;
4373             expecting = Expecting(RIGHTPAR) | Expecting(NUMBER);
4374             }
4375         }
4376     else if (expecting == Expecting(RIGHTPAR))
4377         {
4378         if (mv == NULL)
4379             {
4380             /* we are still assembling the move name */
4381             SafeStrcat (&tempName, tkn);
4382             expecting = Expecting(LEFTCURL) | Expecting(RIGHTCURL) | Expecting(COMMA) |
4383                 Expecting(LEFTPAR) | Expecting(RIGHTPAR) | Expecting(NUMBER) | Expecting(ALPHA) |
4384                 Expecting(DOLLAR);
4385             }
4386         else
4387             expecting = Expecting(EQUALSIGN);
4388         }
4389     else if (expecting == Expecting(EQUALSIGN))
4390         {
4391         foundEqual = YES;
4392         expecting = Expecting(NUMBER);
4393         }
4394     else
4395         return (ERROR);
4396 
4397     SAFEFREE (temp);
4398     SAFEFREE (localTkn);
4399     return (NO_ERROR);
4400 }
4401 
4402 
DoPrset(void)4403 int DoPrset (void)
4404 {
4405     int         i, nApplied, lastActive=0;
4406 
4407     nApplied = NumActiveParts ();
4408     for (i=numCurrentDivisions-1; i>=0; i--)
4409         {
4410         if (activeParts[i] == YES)
4411             {
4412             lastActive = i;
4413             break;
4414             }
4415         }
4416 
4417     if (numCurrentDivisions == 1)
4418         MrBayesPrint ("%s   Successfully set prior model parameters\n", spacer);
4419     else
4420         {
4421         if (nApplied == numCurrentDivisions || nApplied == 0)
4422             {
4423             MrBayesPrint ("%s   Successfully set prior model parameters to all\n", spacer);
4424             MrBayesPrint ("%s   applicable data partitions \n", spacer);
4425             }
4426         else
4427             {
4428             MrBayesPrint ("%s   Successfully set prior model parameters to\n", spacer);
4429             if (nApplied == 1)
4430                 MrBayesPrint ("%s   partition", spacer);
4431             else
4432                 MrBayesPrint ("%s   partitions", spacer);
4433             for (i=0; i<numCurrentDivisions; i++)
4434                 {
4435                 if (activeParts[i] == YES)
4436                     {
4437                     if (i == lastActive && nApplied > 1)
4438                         MrBayesPrint (" and %d", i+1);
4439                     else
4440                         MrBayesPrint (" %d", i+1);
4441                     if (nApplied > 2 && i != lastActive)
4442                         MrBayesPrint (",");
4443                     }
4444                 }
4445             MrBayesPrint (" (if applicable)\n");
4446             }
4447         }
4448 
4449     if (SetUpAnalysis (&globalSeed) == ERROR)
4450         return (ERROR);
4451 
4452     return (NO_ERROR);
4453 }
4454 
4455 
DoPrsetParm(char * parmName,char * tkn)4456 int DoPrsetParm (char *parmName, char *tkn)
4457 {
4458     int         i, j, k, tempInt, nApplied, index, ns, flag=0;
4459     MrBFlt      tempD, sum;
4460     char        tempStr[100];
4461 
4462     if (defMatrix == NO)
4463         {
4464         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
4465         return (ERROR);
4466         }
4467     if (inValidCommand == YES)
4468         {
4469         for (i=0; i<numCurrentDivisions; i++)
4470             activeParts[i] = NO;
4471         inValidCommand = NO;
4472         }
4473 
4474     if (expecting == Expecting(PARAMETER))
4475         {
4476         expecting = Expecting(EQUALSIGN);
4477         }
4478     else
4479         {
4480         /* set Applyto (Applyto) *************************************************************/
4481         if (!strcmp(parmName, "Applyto"))
4482             {
4483             if (expecting == Expecting(EQUALSIGN))
4484                 expecting = Expecting(LEFTPAR);
4485             else if (expecting == Expecting(LEFTPAR))
4486                 {
4487                 for (i=0; i<numCurrentDivisions; i++)
4488                     activeParts[i] = NO;
4489                 fromI = toJ = -1;
4490                 foundDash = NO;
4491                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
4492                 }
4493             else if (expecting == Expecting(RIGHTPAR))
4494                 {
4495                 if (fromI != -1)
4496                     activeParts[fromI-1] = YES;
4497 #               if 0
4498                 for (i=0; i<numCurrentDivisions; i++)
4499                     MrBayesPrint("%d ", activeParts[i]);
4500                 MrBayesPrint ("\n");
4501 #               endif
4502                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4503                 }
4504             else if (expecting == Expecting(COMMA))
4505                 {
4506                 foundComma = YES;
4507                 expecting = Expecting(NUMBER);
4508                 }
4509             else if (expecting == Expecting(ALPHA))
4510                 {
4511                 if (IsSame ("All", tkn) == DIFFERENT)
4512                     {
4513                     MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
4514                     return (ERROR);
4515                     }
4516                 for (i=0; i<numCurrentDivisions; i++)
4517                     activeParts[i] = YES;
4518                 expecting  = Expecting(RIGHTPAR);
4519                 }
4520             else if (expecting == Expecting(NUMBER))
4521                 {
4522                 sscanf (tkn, "%d", &tempInt);
4523                 if (tempInt > numCurrentDivisions)
4524                     {
4525                     MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
4526                     return (ERROR);
4527                     }
4528                 if (fromI == -1)
4529                     fromI = tempInt;
4530                 else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
4531                     {
4532                     toJ = tempInt;
4533                     for (i=fromI-1; i<toJ; i++)
4534                         activeParts[i] = YES;
4535                     fromI = toJ = -1;
4536                     foundDash = NO;
4537                     }
4538                 else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
4539                     {
4540                     activeParts[fromI-1] = YES;
4541                     fromI = tempInt;
4542                     foundComma = NO;
4543                     }
4544 
4545                 expecting  = Expecting(COMMA);
4546                 expecting |= Expecting(DASH);
4547                 expecting |= Expecting(RIGHTPAR);
4548                 }
4549             else if (expecting == Expecting(DASH))
4550                 {
4551                 foundDash = YES;
4552                 expecting = Expecting(NUMBER);
4553                 }
4554             else
4555                 return (ERROR);
4556             }
4557         /* set Tratiopr (tRatioPr) ************************************************************/
4558         else if (!strcmp(parmName, "Tratiopr"))
4559             {
4560             if (expecting == Expecting(EQUALSIGN))
4561                 expecting = Expecting(ALPHA);
4562             else if (expecting == Expecting(ALPHA))
4563                 {
4564                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4565                     {
4566                     nApplied = NumActiveParts ();
4567                     flag = 0;
4568                     for (i=0; i<numCurrentDivisions; i++)
4569                         {
4570                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4571                             {
4572                             strcpy(modelParams[i].tRatioPr, tempStr);
4573                             modelParams[i].tRatioDir[0] = modelParams[i].tRatioDir[1] = 1.0;
4574                             modelParams[i].tRatioFix = 1.0;
4575                             flag = 1;
4576                             }
4577                         }
4578                     if (flag == 0)
4579                         {
4580                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
4581                             Currently there is no active partition with such data.\n", spacer, parmName);
4582                         return (ERROR);
4583                         }
4584                     }
4585                 else
4586                     {
4587                     MrBayesPrint ("%s   Invalid Tratiopr argument \n", spacer);
4588                     return (ERROR);
4589                     }
4590                 expecting  = Expecting(LEFTPAR);
4591                 for (i=0; i<numCurrentDivisions; i++)
4592                     numVars[i] = 0;
4593                 }
4594             else if (expecting == Expecting(LEFTPAR))
4595                 {
4596                 expecting  = Expecting(NUMBER);
4597                 }
4598             else if (expecting == Expecting(NUMBER))
4599                 {
4600                 nApplied = NumActiveParts ();
4601                 for (i=0; i<numCurrentDivisions; i++)
4602                     {
4603                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4604                         {
4605                         if (!strcmp(modelParams[i].tRatioPr,"Beta"))
4606                             {
4607                             sscanf (tkn, "%lf", &tempD);
4608                             if (tempD > ALPHA_MAX)
4609                                 {
4610                                 MrBayesPrint ("%s   Beta parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
4611                                 return (ERROR);
4612                                 }
4613                             if (tempD < ALPHA_MIN)
4614                                 {
4615                                 MrBayesPrint ("%s   Beta parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
4616                                 return (ERROR);
4617                                 }
4618                             modelParams[i].tRatioDir[numVars[i]++] = tempD;
4619                             if (numVars[i] < 2)
4620                                 expecting = Expecting(COMMA);
4621                             else
4622                                 {
4623                                 if (nApplied == 0 && numCurrentDivisions == 1)
4624                                     MrBayesPrint ("%s   Setting Tratiopr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].tRatioDir[0], modelParams[i].tRatioDir[1]);
4625                                 else
4626                                     MrBayesPrint ("%s   Setting Tratiopr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].tRatioDir[0], modelParams[i].tRatioDir[1], i+1);
4627                                 expecting  = Expecting(RIGHTPAR);
4628                                 }
4629                             }
4630                         else if (!strcmp(modelParams[i].tRatioPr,"Fixed"))
4631                             {
4632                             sscanf (tkn, "%lf", &tempD);
4633                             modelParams[i].tRatioFix = tempD;
4634                             if (modelParams[i].tRatioFix > KAPPA_MAX)
4635                                 {
4636                                 MrBayesPrint ("%s   Tratio cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
4637                                 return (ERROR);
4638                                 }
4639                             if (modelParams[i].tRatioFix < 0.0)
4640                                 {
4641                                 MrBayesPrint ("%s   Tratio cannot be less than %1.2lf\n", spacer, 0.0);
4642                                 return (ERROR);
4643                                 }
4644                             if (nApplied == 0 && numCurrentDivisions == 1)
4645                                 MrBayesPrint ("%s   Setting Tratiopr to Fixed(%1.2lf)\n", spacer, modelParams[i].tRatioFix);
4646                             else
4647                                 MrBayesPrint ("%s   Setting Tratiopr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].tRatioFix, i+1);
4648                             expecting  = Expecting(RIGHTPAR);
4649                             }
4650                         }
4651                     }
4652                 }
4653             else if (expecting == Expecting(COMMA))
4654                 {
4655                 expecting  = Expecting(NUMBER);
4656                 }
4657             else if (expecting == Expecting(RIGHTPAR))
4658                 {
4659                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4660                 }
4661             else
4662                 return (ERROR);
4663             }
4664         /* set Revmatpr (revMatPr) ************************************************************/
4665         else if (!strcmp(parmName, "Revmatpr"))
4666             {
4667             if (expecting == Expecting(EQUALSIGN))
4668                 expecting = Expecting(ALPHA);
4669             else if (expecting == Expecting(ALPHA))
4670                 {
4671                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4672                     {
4673                     nApplied = NumActiveParts ();
4674                     flag = 0;
4675                     for (i=0; i<numCurrentDivisions; i++)
4676                         {
4677                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4678                             {
4679                             strcpy(modelParams[i].revMatPr, tempStr);
4680                             modelParams[i].revMatDir[0] = modelParams[i].revMatDir[1] = 1.0;
4681                             modelParams[i].revMatDir[2] = modelParams[i].revMatDir[3] = 1.0;
4682                             modelParams[i].revMatDir[4] = modelParams[i].revMatDir[5] = 1.0;
4683                             flag = 1;
4684                             }
4685                         }
4686                     if (flag == 0)
4687                         {
4688                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
4689                             Currently there is no active partition with such data.\n", spacer, parmName);
4690                         return (ERROR);
4691                         }
4692                     }
4693                 else
4694                     {
4695                     MrBayesPrint ("%s   Invalid Revmatpr argument\n", spacer);
4696                     return (ERROR);
4697                     }
4698                 expecting  = Expecting(LEFTPAR);
4699                 tempNumStates = 0;
4700                 }
4701             else if (expecting == Expecting(LEFTPAR))
4702                 {
4703                 expecting  = Expecting(NUMBER);
4704                 }
4705             else if (expecting == Expecting(NUMBER))
4706                 {
4707                 /* find out what type of prior is being set */
4708                 nApplied = NumActiveParts ();
4709                 for (i=0; i<numCurrentDivisions; i++)
4710                     {
4711                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4712                         strcpy (tempStr,modelParams[i].revMatPr);
4713                     }
4714                 /* find and store the number */
4715                 sscanf (tkn, "%lf", &tempD);
4716                 if (!strcmp(tempStr,"Dirichlet"))
4717                     {
4718                     if (tempD > ALPHA_MAX)
4719                         {
4720                         MrBayesPrint ("%s   Dirichlet parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
4721                         return (ERROR);
4722                         }
4723                     if (tempD < ALPHA_MIN)
4724                         {
4725                         MrBayesPrint ("%s   Dirichlet parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
4726                         return (ERROR);
4727                         }
4728                     }
4729                 else if (!strcmp(tempStr,"Fixed"))
4730                     {
4731                     if (tempD > KAPPA_MAX)
4732                         {
4733                         MrBayesPrint ("%s   Rate value cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
4734                         return (ERROR);
4735                         }
4736                     if (tempD < 0.0001)
4737                         {
4738                         MrBayesPrint ("%s   Rate value cannot be less than %1.2lf\n", spacer, 0.0001);
4739                         return (ERROR);
4740                         }
4741                     }
4742                 tempNum[tempNumStates++] = tempD;
4743                 if (tempNumStates == 1 && !strcmp(tempStr,"Dirichlet"))
4744                     expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
4745                 else if (tempNumStates < 6)
4746                     expecting  = Expecting(COMMA);
4747                 else
4748                     expecting = Expecting(RIGHTPAR);
4749                 }
4750             else if (expecting == Expecting(COMMA))
4751                 {
4752                 expecting  = Expecting(NUMBER);
4753                 }
4754             else if (expecting == Expecting(RIGHTPAR))
4755                 {
4756                 nApplied = NumActiveParts ();
4757                 for (i=0; i<numCurrentDivisions; i++)
4758                     {
4759                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
4760                         {
4761                         if (!strcmp(modelParams[i].revMatPr,"Dirichlet"))
4762                             {
4763                             for (j=0; j<6; j++)
4764                                 {
4765                                 if (tempNumStates == 1)
4766                                     modelParams[i].revMatDir[j] = tempNum[0] / (MrBFlt) 6.0;
4767                                 else
4768                                     modelParams[i].revMatDir[j] = tempNum[j];
4769                                 }
4770 
4771                             if (nApplied == 0 && numCurrentDivisions == 1)
4772                                 MrBayesPrint ("%s   Setting Revmatpr to Dirichlet(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
4773                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
4774                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5]);
4775                             else
4776                                 MrBayesPrint ("%s   Setting Revmatpr to Dirichlet(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf) for partition %d\n", spacer,
4777                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
4778                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5], i+1);
4779                             }
4780                         else if (!strcmp(modelParams[i].revMatPr,"Fixed"))
4781                             {
4782                             for (j=0; j<6; j++)
4783                                 modelParams[i].revMatFix[j] = tempNum[j];
4784                             if (nApplied == 0 && numCurrentDivisions == 1)
4785                                 MrBayesPrint ("%s   Setting Revmatpr to Fixed(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
4786                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
4787                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5]);
4788                             else
4789                                 MrBayesPrint ("%s   Setting Revmatpr to Fixed(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf) for partition %d\n", spacer,
4790                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
4791                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5], i+1);
4792                             }
4793                         }
4794                     }
4795                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
4796                 }
4797             else
4798                 return (ERROR);
4799             }
4800         /* set Aarevmatpr (aaRevMatPr) ********************************************************/
4801         else if (!strcmp(parmName, "Aarevmatpr"))
4802             {
4803             if (expecting == Expecting(EQUALSIGN))
4804                 expecting = Expecting(ALPHA);
4805             else if (expecting == Expecting(ALPHA))
4806                 {
4807                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
4808                     {
4809                     nApplied = NumActiveParts ();
4810                     flag = 0;
4811                     for (i=0; i<numCurrentDivisions; i++)
4812                         {
4813                         if ((activeParts[i] == YES || nApplied == 0) && modelSettings[i].dataType == PROTEIN)
4814                             {
4815                             strcpy(modelParams[i].aaRevMatPr, tempStr);
4816                             for (j=0; j<190; j++)
4817                                 modelParams[i].aaRevMatDir[j] = 1.0;
4818                             flag = 1;
4819                             }
4820                         }
4821                     if (flag == 0)
4822                         {
4823                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing PROTEIN.\
4824                             Currently there is no active partition with such data.\n", spacer, parmName);
4825                         return (ERROR);
4826                         }
4827                     }
4828                 else
4829                     {
4830                     MrBayesPrint ("%s   Invalid Aarevmatpr argument\n", spacer);
4831                     return (ERROR);
4832                     }
4833                 expecting  = Expecting(LEFTPAR);
4834                 tempNumStates = 0;
4835                 }
4836             else if (expecting == Expecting(LEFTPAR))
4837                 {
4838                 expecting  = Expecting(NUMBER);
4839                 }
4840             else if (expecting == Expecting(NUMBER))
4841                 {
4842                 /* find out what type of prior is being set */
4843                 nApplied = NumActiveParts ();
4844                 for (i=0; i<numCurrentDivisions; i++)
4845                     {
4846                     if ((activeParts[i] == YES || nApplied == 0) && modelSettings[i].dataType == PROTEIN)
4847                         strcpy (tempStr,modelParams[i].aaRevMatPr);
4848                     }
4849                 /* find and store the number */
4850                 sscanf (tkn, "%lf", &tempD);
4851                 if (!strcmp(tempStr,"Dirichlet"))
4852                     {
4853                     if (tempD > ALPHA_MAX)
4854                         {
4855                         MrBayesPrint ("%s   Dirichlet parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
4856                         return (ERROR);
4857                         }
4858                     if (tempD < ALPHA_MIN)
4859                         {
4860                         MrBayesPrint ("%s   Dirichlet parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
4861                         return (ERROR);
4862                         }
4863                     }
4864                 else if (!strcmp(tempStr,"Fixed"))
4865                     {
4866                     if (tempD > KAPPA_MAX)
4867                         {
4868                         MrBayesPrint ("%s   Rate value cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
4869                         return (ERROR);
4870                         }
4871                     if (tempD < 0.0001)
4872                         {
4873                         MrBayesPrint ("%s   Rate value cannot be less than %1.2lf\n", spacer, 0.0001);
4874                         return (ERROR);
4875                         }
4876                     }
4877                 tempStateFreqs[tempNumStates++] = tempD;
4878                 if (tempNumStates == 1 && !strcmp(tempStr,"Dirichlet"))
4879                     expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
4880                 else if (tempNumStates < 190)
4881                     expecting  = Expecting(COMMA);
4882                 else
4883                     expecting = Expecting(RIGHTPAR);
4884                 }
4885             else if (expecting == Expecting(COMMA))
4886                 {
4887                 expecting  = Expecting(NUMBER);
4888                 }
4889             else if (expecting == Expecting(RIGHTPAR))
4890                 {
4891                 nApplied = NumActiveParts ();
4892                 for (i=0; i<numCurrentDivisions; i++)
4893                     {
4894                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == PROTEIN)
4895                         {
4896                         if (!strcmp(modelParams[i].aaRevMatPr,"Dirichlet"))
4897                             {
4898                             for (j=0; j<190; j++)
4899                                 {
4900                                 if (tempNumStates == 1)
4901                                     modelParams[i].aaRevMatDir[j] = tempStateFreqs[0] / (MrBFlt) 190.0;
4902                                 else
4903                                     modelParams[i].aaRevMatDir[j] = tempStateFreqs[j];
4904                                 }
4905                             if (nApplied == 0 && numCurrentDivisions == 1)
4906                                 {
4907                                 for (j=0; j<190; j++)
4908                                     if (AreDoublesEqual(modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[j], 0.00001) == NO)
4909                                         break;
4910                                 if (j == 190)
4911                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(%1.2lf,%1.2lf,...)\n", spacer,
4912                                         modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[0]);
4913                                 else
4914                                     {
4915                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(\n", spacer);
4916                                     for (j=0; j<190; j++)
4917                                         {
4918                                         if (j % 10 == 0)
4919                                             MrBayesPrint ("%s      ", spacer);
4920                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatDir[j]);
4921                                         if (j == 189)
4922                                             MrBayesPrint (")\n");
4923                                         else if ((j+1) % 10 == 0)
4924                                             MrBayesPrint (",\n");
4925                                         else
4926                                             MrBayesPrint (",");
4927                                         }
4928                                     }
4929                                 }
4930                             else
4931                                 {
4932                                 for (j=0; j<190; j++)
4933                                     if (AreDoublesEqual(modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[j], 0.00001) == NO)
4934                                         break;
4935                                 if (j == 190)
4936                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(%1.2lf,%1.2lf,...) for partition %d\n",
4937                                         spacer, modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[0], i+1);
4938                                 else
4939                                     {
4940                                     MrBayesPrint ("%s   Setting Aarevmatpr to Dirichlet(\n", spacer);
4941                                     for (j=0; j<190; j++)
4942                                         {
4943                                         if (j % 10 == 0)
4944                                             MrBayesPrint ("%s      ", spacer);
4945                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatDir[j]);
4946                                         if (j == 189)
4947                                             MrBayesPrint (")\n");
4948                                         else if ((j+1) % 10 == 0)
4949                                             MrBayesPrint (",\n");
4950                                         else
4951                                             MrBayesPrint (",");
4952                                         }
4953                                     }
4954                                     MrBayesPrint ("%s      for partition %d\n", spacer, i+1);
4955                                 }
4956                             }
4957                         else if (!strcmp(modelParams[i].aaRevMatPr,"Fixed"))
4958                             {
4959                             for (j=0; j<190; j++)
4960                                 modelParams[i].aaRevMatFix[j] = tempStateFreqs[j];
4961                             if (nApplied == 0 && numCurrentDivisions == 1)
4962                                 {
4963                                 for (j=0; j<190; j++)
4964                                     if (AreDoublesEqual(modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[j], 0.00001) == NO)
4965                                         break;
4966                                 if (j == 190)
4967                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(%1.2lf,%1.2lf,...)\n", spacer, modelParams[i].aaRevMatFix[0],
4968                                         modelParams[i].aaRevMatFix[0]);
4969                                 else
4970                                     {
4971                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(\n", spacer);
4972                                     for (j=0; j<190; j++)
4973                                         {
4974                                         if (j % 10 == 0)
4975                                             MrBayesPrint ("%s      ", spacer);
4976                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatFix[j]);
4977                                         if (j == 189)
4978                                             MrBayesPrint (")\n");
4979                                         else if ((j+1) % 10 == 0)
4980                                             MrBayesPrint (",\n");
4981                                         else
4982                                             MrBayesPrint (",");
4983                                         }
4984                                     }
4985                                 }
4986                             else
4987                                 {
4988                                 for (j=0; j<190; j++)
4989                                     if (AreDoublesEqual(modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[j], 0.00001) == NO)
4990                                         break;
4991                                 if (j == 190)
4992                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(%1.2lf,%1.2lf,...) for partition %d\n", spacer,
4993                                         modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[0], i+1);
4994                                 else
4995                                     {
4996                                     MrBayesPrint ("%s   Setting Aarevmatpr to Fixed(\n", spacer);
4997                                     for (j=0; j<190; j++)
4998                                         {
4999                                         if (j % 10 == 0)
5000                                             MrBayesPrint ("%s      ", spacer);
5001                                         MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatFix[j]);
5002                                         if (j == 189)
5003                                             MrBayesPrint (")\n");
5004                                         else if ((j+1) % 10 == 0)
5005                                             MrBayesPrint (",\n");
5006                                         else
5007                                             MrBayesPrint (",");
5008                                         }
5009                                     }
5010                                     MrBayesPrint ("%s      for partition %d\n", spacer, i+1);
5011                                 }
5012                             }
5013                         }
5014                     }
5015                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5016                 }
5017             else
5018                 return (ERROR);
5019             }
5020         /* set Revratepr (revSymDirPr) ****************************************************/
5021         else if (!strcmp(parmName, "Revratepr"))
5022             {
5023             if (expecting == Expecting(EQUALSIGN))
5024                 expecting = Expecting(ALPHA);
5025             else if (expecting == Expecting(ALPHA))
5026                 {
5027                 if (IsArgValid(tkn, tempStr) == ERROR)  /* we only allow symmetric dirichlet prior, so no need to store the value */
5028                     {
5029                     MrBayesPrint ("%s   Invalid Revratepr argument\n", spacer);
5030                     return (ERROR);
5031                     }
5032                 expecting  = Expecting(LEFTPAR);
5033                 for (i=0; i<numCurrentDivisions; i++)
5034                     numVars[i] = 0;
5035                 }
5036             else if (expecting == Expecting(LEFTPAR))
5037                 {
5038                 expecting  = Expecting(NUMBER);
5039                 }
5040             else if (expecting == Expecting(NUMBER))
5041                 {
5042                 nApplied = NumActiveParts ();
5043                 for (i=0; i<numCurrentDivisions; i++)
5044                     {
5045                     if (activeParts[i] == YES || nApplied == 0)
5046                         {
5047                         sscanf (tkn, "%lf", &tempD);
5048                         if (tempD <= 0.0)
5049                             {
5050                             MrBayesPrint ("%s   Symmetric Dirichlet parameter must be positive\n", spacer);
5051                             return (ERROR);
5052                             }
5053                         modelParams[i].revMatSymDir = tempD;
5054                         if (nApplied == 0 && numCurrentDivisions == 1)
5055                             MrBayesPrint ("%s   Setting Revratepr to Symmetric Dirichlet(%1.2lf)\n", spacer, modelParams[i].revMatSymDir);
5056                         else
5057                             MrBayesPrint ("%s   Setting Revratepr to Symmetric Dirichlet(%1.2lf) for partition %d\n", spacer, modelParams[i].revMatSymDir, i+1);
5058                         expecting  = Expecting(RIGHTPAR);
5059                         }
5060                     }
5061                 }
5062             else if (expecting == Expecting(RIGHTPAR))
5063                 {
5064                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5065                 }
5066             else
5067                 return (ERROR);
5068             }
5069         /* set Omegapr (omegaPr) **************************************************************/
5070         else if (!strcmp(parmName, "Omegapr"))
5071             {
5072             if (expecting == Expecting(EQUALSIGN))
5073                 expecting = Expecting(ALPHA);
5074             else if (expecting == Expecting(ALPHA))
5075                 {
5076                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5077                     {
5078                     nApplied = NumActiveParts ();
5079                     flag = 0;
5080                     for (i=0; i<numCurrentDivisions; i++)
5081                         {
5082                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5083                             {
5084                             strcpy(modelParams[i].omegaPr, tempStr);
5085                             modelParams[i].omegaDir[0] = modelParams[i].omegaDir[1] = 1.0;
5086                             modelParams[i].omegaFix = 1.0;
5087                             flag = 1;
5088                             }
5089                         }
5090                     if (flag == 0)
5091                         {
5092                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5093                             Currently there is no active partition with such data.\n", spacer, parmName);
5094                         return (ERROR);
5095                         }
5096                     }
5097                 else
5098                     {
5099                     MrBayesPrint ("%s   Invalid Omegapr argument\n", spacer);
5100                     return (ERROR);
5101                     }
5102                 expecting  = Expecting(LEFTPAR);
5103                 for (i=0; i<numCurrentDivisions; i++)
5104                     numVars[i] = 0;
5105                 }
5106             else if (expecting == Expecting(LEFTPAR))
5107                 {
5108                 expecting  = Expecting(NUMBER);
5109                 }
5110             else if (expecting == Expecting(NUMBER))
5111                 {
5112                 nApplied = NumActiveParts ();
5113                 for (i=0; i<numCurrentDivisions; i++)
5114                     {
5115                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5116                         {
5117                         if (!strcmp(modelParams[i].omegaPr,"Dirichlet"))
5118                             {
5119                             sscanf (tkn, "%lf", &tempD);
5120                             if (tempD > ALPHA_MAX)
5121                                 {
5122                                 MrBayesPrint ("%s   Dirichlet parameter cannot be greater than %1.2lf\n", spacer, ALPHA_MAX);
5123                                 return (ERROR);
5124                                 }
5125                             if (tempD < ALPHA_MIN)
5126                                 {
5127                                 MrBayesPrint ("%s   Dirichlet parameter cannot be less than %1.2lf\n", spacer, ALPHA_MIN);
5128                                 return (ERROR);
5129                                 }
5130                             modelParams[i].omegaDir[numVars[i]++] = tempD;
5131                             if (numVars[i] == 1)
5132                                 expecting = Expecting(COMMA);
5133                             else
5134                                 {
5135                                 if (nApplied == 0 && numCurrentDivisions == 1)
5136                                     MrBayesPrint ("%s   Setting Omegapr to Dirichlet(%1.2lf,%1.2lf)\n", spacer, modelParams[i].omegaDir[0], modelParams[i].omegaDir[1]);
5137                                 else
5138                                     MrBayesPrint ("%s   Setting Omegapr to Dirichlet(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].omegaDir[0], modelParams[i].omegaDir[1], i+1);
5139                                 expecting  = Expecting(RIGHTPAR);
5140                                 }
5141                             }
5142                         else if (!strcmp(modelParams[i].omegaPr,"Fixed"))
5143                             {
5144                             sscanf (tkn, "%lf", &tempD);
5145                             modelParams[i].omegaFix = tempD;
5146                             if (modelParams[i].omegaFix > KAPPA_MAX)
5147                                 {
5148                                 MrBayesPrint ("%s   Omega ratio cannot be greater than %1.2lf\n", spacer, KAPPA_MAX);
5149                                 return (ERROR);
5150                                 }
5151                             if (modelParams[i].omegaFix < 0.0)
5152                                 {
5153                                 MrBayesPrint ("%s   Omega ratio cannot be less than %1.2lf\n", spacer, 0.0);
5154                                 return (ERROR);
5155                                 }
5156                             if (nApplied == 0 && numCurrentDivisions == 1)
5157                                 MrBayesPrint ("%s   Setting Omegapr to Fixed(%1.2lf)\n", spacer, modelParams[i].omegaFix);
5158                             else
5159                                 MrBayesPrint ("%s   Setting Omegapr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].omegaFix, i+1);
5160                             expecting  = Expecting(RIGHTPAR);
5161                             }
5162                         }
5163                     }
5164                 }
5165             else if (expecting == Expecting(COMMA))
5166                 {
5167                 expecting  = Expecting(NUMBER);
5168                 }
5169             else if (expecting == Expecting(RIGHTPAR))
5170                 {
5171                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5172                 }
5173             else
5174                 return (ERROR);
5175             }
5176         /* set Ny98omega1pr (ny98omega1pr) ********************************************************/
5177         else if (!strcmp(parmName, "Ny98omega1pr"))
5178             {
5179             if (expecting == Expecting(EQUALSIGN))
5180                 expecting = Expecting(ALPHA);
5181             else if (expecting == Expecting(ALPHA))
5182                 {
5183                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5184                     {
5185                     nApplied = NumActiveParts ();
5186                     flag = 0;
5187                     for (i=0; i<numCurrentDivisions; i++)
5188                         {
5189                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5190                             {
5191                             strcpy(modelParams[i].ny98omega1pr, tempStr);
5192                             flag = 1;
5193                             }
5194                         }
5195                     if (flag == 0)
5196                         {
5197                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5198                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5199                         return (ERROR);
5200                         }
5201                     }
5202                 else
5203                     {
5204                     MrBayesPrint ("%s   Invalid Ny98omega1pr argument\n", spacer);
5205                     return (ERROR);
5206                     }
5207                 expecting  = Expecting(LEFTPAR);
5208                 for (i=0; i<numCurrentDivisions; i++)
5209                     numVars[i] = 0;
5210                 }
5211             else if (expecting == Expecting(LEFTPAR))
5212                 {
5213                 expecting  = Expecting(NUMBER);
5214                 }
5215             else if (expecting == Expecting(NUMBER))
5216                 {
5217                 nApplied = NumActiveParts ();
5218                 for (i=0; i<numCurrentDivisions; i++)
5219                     {
5220                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5221                         {
5222                         if (!strcmp(modelParams[i].ny98omega1pr,"Beta"))
5223                             {
5224                             sscanf (tkn, "%lf", &tempD);
5225                             modelParams[i].ny98omega1Beta[numVars[i]++] = tempD;
5226                             if (numVars[i] == 1)
5227                                 expecting  = Expecting(COMMA);
5228                             else
5229                                 {
5230                                 if (modelParams[i].ny98omega1Beta[0] < 0 || modelParams[i].ny98omega1Beta[1] < 0)
5231                                     {
5232                                     MrBayesPrint ("%s   Beta parameter should be greater than 0\n", spacer);
5233                                     return (ERROR);
5234                                     }
5235                                 if (nApplied == 0 && numCurrentDivisions == 1)
5236                                     MrBayesPrint ("%s   Setting Ny98omega1pr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].ny98omega1Beta[0], modelParams[i].ny98omega1Beta[1]);
5237                                 else
5238                                     MrBayesPrint ("%s   Setting Ny98omega1pr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega1Beta[0], modelParams[i].ny98omega1Beta[1], i+1);
5239                                 expecting  = Expecting(RIGHTPAR);
5240                                 }
5241                             }
5242                         else if (!strcmp(modelParams[i].ny98omega1pr,"Fixed"))
5243                             {
5244                             sscanf (tkn, "%lf", &tempD);
5245                             modelParams[i].ny98omega1Fixed = tempD;
5246                             if (nApplied == 0 && numCurrentDivisions == 1)
5247                                 MrBayesPrint ("%s   Setting Ny98omega1pr to Fixed(%1.2lf)\n", spacer, modelParams[i].ny98omega1Fixed);
5248                             else
5249                                 MrBayesPrint ("%s   Setting Ny98omega1pr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega1Fixed, i+1);
5250                             expecting  = Expecting(RIGHTPAR);
5251                             }
5252                         }
5253                     }
5254                 }
5255             else if (expecting == Expecting(COMMA))
5256                 {
5257                 expecting  = Expecting(NUMBER);
5258                 }
5259             else if (expecting == Expecting(RIGHTPAR))
5260                 {
5261                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5262                 }
5263             else
5264                 return (ERROR);
5265             }
5266         /* set Ny98omega3pr (ny98omega3pr) ********************************************************/
5267         else if (!strcmp(parmName, "Ny98omega3pr"))
5268             {
5269             if (expecting == Expecting(EQUALSIGN))
5270                 expecting = Expecting(ALPHA);
5271             else if (expecting == Expecting(ALPHA))
5272                 {
5273                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5274                     {
5275                     nApplied = NumActiveParts ();
5276                     flag = 0;
5277                     for (i=0; i<numCurrentDivisions; i++)
5278                         {
5279                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5280                             {
5281                             strcpy(modelParams[i].ny98omega3pr, tempStr);
5282                             flag = 1;
5283                             }
5284                         }
5285                     if (flag == 0)
5286                         {
5287                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5288                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5289                         return (ERROR);
5290                         }
5291                     }
5292                 else
5293                     {
5294                     MrBayesPrint ("%s   Invalid Ny98omega3pr argument\n", spacer);
5295                     return (ERROR);
5296                     }
5297                 expecting  = Expecting(LEFTPAR);
5298                 for (i=0; i<numCurrentDivisions; i++)
5299                     numVars[i] = 0;
5300                 }
5301             else if (expecting == Expecting(LEFTPAR))
5302                 {
5303                 expecting  = Expecting(NUMBER);
5304                 }
5305             else if (expecting == Expecting(NUMBER))
5306                 {
5307                 nApplied = NumActiveParts ();
5308                 for (i=0; i<numCurrentDivisions; i++)
5309                     {
5310                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5311                         {
5312                         if (!strcmp(modelParams[i].ny98omega3pr,"Uniform"))
5313                             {
5314                             sscanf (tkn, "%lf", &tempD);
5315                             modelParams[i].ny98omega3Uni[numVars[i]++] = tempD;
5316                             if (numVars[i] == 1)
5317                                 expecting  = Expecting(COMMA);
5318                             else
5319                                 {
5320                                 if (modelParams[i].ny98omega3Uni[0] >= modelParams[i].ny98omega3Uni[1])
5321                                     {
5322                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5323                                     return (ERROR);
5324                                     }
5325                                 if (nApplied == 0 && numCurrentDivisions == 1)
5326                                     MrBayesPrint ("%s   Setting Ny98omega3pr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].ny98omega3Uni[0], modelParams[i].ny98omega3Uni[1]);
5327                                 else
5328                                     MrBayesPrint ("%s   Setting Ny98omega3pr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega3Uni[0], modelParams[i].ny98omega3Uni[1], i+1);
5329                                 expecting  = Expecting(RIGHTPAR);
5330                                 }
5331                             }
5332                         else if (!strcmp(modelParams[i].ny98omega3pr,"Exponential"))
5333                             {
5334                             sscanf (tkn, "%lf", &tempD);
5335                             modelParams[i].ny98omega3Exp = tempD;
5336                             if (nApplied == 0 && numCurrentDivisions == 1)
5337                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Exponential(%1.2lf)\n", spacer, modelParams[i].ny98omega3Exp);
5338                             else
5339                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega3Exp, i+1);
5340                             expecting  = Expecting(RIGHTPAR);
5341                             }
5342                         else if (!strcmp(modelParams[i].ny98omega3pr,"Fixed"))
5343                             {
5344                             sscanf (tkn, "%lf", &tempD);
5345                             modelParams[i].ny98omega3Fixed = tempD;
5346                             if (nApplied == 0 && numCurrentDivisions == 1)
5347                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Fixed(%1.2lf)\n", spacer, modelParams[i].ny98omega3Fixed);
5348                             else
5349                                 MrBayesPrint ("%s   Setting Ny98omega3pr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].ny98omega3Fixed, i+1);
5350                             expecting  = Expecting(RIGHTPAR);
5351                             }
5352                         }
5353                     }
5354                 }
5355             else if (expecting == Expecting(COMMA))
5356                 {
5357                 expecting  = Expecting(NUMBER);
5358                 }
5359             else if (expecting == Expecting(RIGHTPAR))
5360                 {
5361                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5362                 }
5363             else
5364                 return (ERROR);
5365             }
5366         /* set M3omegapr (m3omegapr) ********************************************************/
5367         else if (!strcmp(parmName, "M3omegapr"))
5368             {
5369             if (expecting == Expecting(EQUALSIGN))
5370                 expecting = Expecting(ALPHA);
5371             else if (expecting == Expecting(ALPHA))
5372                 {
5373                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5374                     {
5375                     nApplied = NumActiveParts ();
5376                     flag = 0;
5377                     for (i=0; i<numCurrentDivisions; i++)
5378                         {
5379                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5380                             {
5381                             strcpy(modelParams[i].m3omegapr, tempStr);
5382                             flag = 1;
5383                             }
5384                         }
5385                     if (flag == 0)
5386                         {
5387                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5388                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5389                         return (ERROR);
5390                         }
5391                     }
5392                 else
5393                     {
5394                     MrBayesPrint ("%s   Invalid M3omegapr argument\n", spacer);
5395                     return (ERROR);
5396                     }
5397                 for (i=0; i<numCurrentDivisions; i++)
5398                     {
5399                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5400                         {
5401                         if (!strcmp(modelParams[i].m3omegapr,"Exponential"))
5402                             {
5403                             if (nApplied == 0 && numCurrentDivisions == 1)
5404                                 MrBayesPrint ("%s   Setting M3omegapr to Exponential\n", spacer);
5405                             else
5406                                 MrBayesPrint ("%s   Setting M3omegapr to Exponential for partition %d\n", spacer, i+1);
5407                             expecting  = Expecting(RIGHTPAR);
5408                             }
5409                         }
5410                     }
5411                 if (!strcmp(tempStr,"Exponential"))
5412                     expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5413                 else
5414                     expecting  = Expecting(LEFTPAR);
5415                 for (i=0; i<numCurrentDivisions; i++)
5416                     numVars[i] = 0;
5417                 }
5418             else if (expecting == Expecting(LEFTPAR))
5419                 {
5420                 expecting  = Expecting(NUMBER);
5421                 }
5422             else if (expecting == Expecting(NUMBER))
5423                 {
5424                 nApplied = NumActiveParts ();
5425                 for (i=0; i<numCurrentDivisions; i++)
5426                     {
5427                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5428                         {
5429                         if (!strcmp(modelParams[i].m3omegapr,"Fixed"))
5430                             {
5431                             sscanf (tkn, "%lf", &tempD);
5432                             modelParams[i].m3omegaFixed[numVars[i]++] = tempD;
5433                             if (numVars[i] == 1 || numVars[i] == 2)
5434                                 expecting  = Expecting(COMMA);
5435                             else
5436                                 {
5437                                 if (modelParams[i].m3omegaFixed[0] >= modelParams[i].m3omegaFixed[1] || modelParams[i].m3omegaFixed[0] >= modelParams[i].m3omegaFixed[2] || modelParams[i].m3omegaFixed[1] >= modelParams[i].m3omegaFixed[2])
5438                                     {
5439                                     MrBayesPrint ("%s   The three omega values must be ordered, such that omega1 < omega2 < omega3\n", spacer);
5440                                     return (ERROR);
5441                                     }
5442                                 if (nApplied == 0 && numCurrentDivisions == 1)
5443                                     MrBayesPrint ("%s   Setting M3omegapr to Fixed(%1.2lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].m3omegaFixed[0], modelParams[i].m3omegaFixed[1], modelParams[i].m3omegaFixed[2]);
5444                                 else
5445                                     MrBayesPrint ("%s   Setting M3omegapr to Fixed(%1.2lf,%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m3omegaFixed[0], modelParams[i].m3omegaFixed[1], modelParams[i].m3omegaFixed[2], i+1);
5446                                 expecting  = Expecting(RIGHTPAR);
5447                                 }
5448                             }
5449                         }
5450                     }
5451                 }
5452             else if (expecting == Expecting(COMMA))
5453                 {
5454                 expecting  = Expecting(NUMBER);
5455                 }
5456             else if (expecting == Expecting(RIGHTPAR))
5457                 {
5458                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5459                 }
5460             else
5461                 return (ERROR);
5462             }
5463         /* set Codoncatfreqs (codonCatFreqPr) ********************************************************/
5464         else if (!strcmp(parmName, "Codoncatfreqs"))
5465             {
5466             if (expecting == Expecting(EQUALSIGN))
5467                 expecting = Expecting(ALPHA);
5468             else if (expecting == Expecting(ALPHA))
5469                 {
5470                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5471                     {
5472                     nApplied = NumActiveParts ();
5473                     flag = 0;
5474                     for (i=0; i<numCurrentDivisions; i++)
5475                         {
5476                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5477                             {
5478                             strcpy(modelParams[i].codonCatFreqPr, tempStr);
5479                             flag = 1;
5480                             }
5481                         }
5482                     if (flag == 0)
5483                         {
5484                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing either DNA or RNA data.\
5485                             Currently there is no active partition with such data. The setting is ignored.\n", spacer, parmName);
5486                         return (ERROR);
5487                         }
5488                     }
5489                 else
5490                     {
5491                     MrBayesPrint ("%s   Invalid Omegapurpr argument\n", spacer);
5492                     return (ERROR);
5493                     }
5494                 expecting  = Expecting(LEFTPAR);
5495                 for (i=0; i<numCurrentDivisions; i++)
5496                     numVars[i] = 0;
5497                 }
5498             else if (expecting == Expecting(LEFTPAR))
5499                 {
5500                 expecting  = Expecting(NUMBER);
5501                 }
5502             else if (expecting == Expecting(NUMBER))
5503                 {
5504                 nApplied = NumActiveParts ();
5505                 for (i=0; i<numCurrentDivisions; i++)
5506                     {
5507                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5508                         {
5509                         if (!strcmp(modelParams[i].codonCatFreqPr,"Dirichlet"))
5510                             {
5511                             sscanf (tkn, "%lf", &tempD);
5512                             modelParams[i].codonCatDir[numVars[i]++] = tempD;
5513                             if (numVars[i] == 1 || numVars[i] == 2)
5514                                 expecting  = Expecting(COMMA);
5515                             else
5516                                 {
5517                                 if (nApplied == 0 && numCurrentDivisions == 1)
5518                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Dirichlet(%1.2lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].codonCatDir[0], modelParams[i].codonCatDir[1], modelParams[i].codonCatDir[2]);
5519                                 else
5520                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Dirichlet(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].codonCatDir[0], modelParams[i].codonCatDir[1], modelParams[i].codonCatDir[2], i+1);
5521                                 expecting  = Expecting(RIGHTPAR);
5522                                 }
5523                             }
5524                         else if (!strcmp(modelParams[i].codonCatFreqPr,"Fixed"))
5525                             {
5526                             sscanf (tkn, "%lf", &tempD);
5527                             modelParams[i].codonCatFreqFix[numVars[i]++] = tempD;
5528                             if (numVars[i] == 1 || numVars[i] == 2)
5529                                 expecting  = Expecting(COMMA);
5530                             else
5531                                 {
5532                                 if (AreDoublesEqual (modelParams[i].codonCatFreqFix[0] + modelParams[i].codonCatFreqFix[1] + modelParams[i].codonCatFreqFix[2], (MrBFlt) 1.0, (MrBFlt) 0.001) == NO)
5533                                     {
5534                                     MrBayesPrint ("%s   Codon category frequencies must sum to 1\n", spacer);
5535                                     return (ERROR);
5536                                     }
5537 
5538                                 if (nApplied == 0 && numCurrentDivisions == 1)
5539                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Fixed(%1.2lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].codonCatFreqFix[0], modelParams[i].codonCatFreqFix[1], modelParams[i].codonCatFreqFix[2]);
5540                                 else
5541                                     MrBayesPrint ("%s   Setting Codoncatfreqs prior to Fixed(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].codonCatFreqFix[0], modelParams[i].codonCatFreqFix[1], modelParams[i].codonCatFreqFix[2], i+1);
5542                                 expecting  = Expecting(RIGHTPAR);
5543                                 }
5544                             }
5545                         }
5546                     }
5547                 }
5548             else if (expecting == Expecting(COMMA))
5549                 {
5550                 expecting  = Expecting(NUMBER);
5551                 }
5552             else if (expecting == Expecting(RIGHTPAR))
5553                 {
5554                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5555                 }
5556             else
5557                 return (ERROR);
5558             }
5559 
5560         /* set Shapepr (shapePr) **************************************************************/
5561         else if (!strcmp(parmName, "Shapepr"))
5562             {
5563             if (expecting == Expecting(EQUALSIGN))
5564                 expecting = Expecting(ALPHA);
5565             else if (expecting == Expecting(ALPHA))
5566                 {
5567                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5568                     {
5569                     nApplied = NumActiveParts ();
5570                     flag = 0;
5571                     for (i=0; i<numCurrentDivisions; i++)
5572                         {
5573                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN || modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD))
5574                             {
5575                             strcpy(modelParams[i].shapePr, tempStr);
5576                             flag = 1;
5577                             }
5578                         }
5579                     if (flag == 0)
5580                         {
5581                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of following type: DNA, RNA, PROTEIN, RESTRICTION, STANDARD.\
5582                             Currently there is no active partition with such data.\n", spacer, parmName);
5583                         return (ERROR);
5584                         }
5585                     }
5586                 else
5587                     {
5588                     MrBayesPrint ("%s   Invalid Shapepr argument\n", spacer);
5589                     return (ERROR);
5590                     }
5591                 expecting  = Expecting(LEFTPAR);
5592                 for (i=0; i<numCurrentDivisions; i++)
5593                     numVars[i] = 0;
5594                 }
5595             else if (expecting == Expecting(LEFTPAR))
5596                 {
5597                 expecting  = Expecting(NUMBER);
5598                 }
5599             else if (expecting == Expecting(NUMBER))
5600                 {
5601                 nApplied = NumActiveParts ();
5602                 for (i=0; i<numCurrentDivisions; i++)
5603                     {
5604                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN || modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD))
5605                         {
5606                         if (!strcmp(modelParams[i].shapePr,"Uniform"))
5607                             {
5608                             sscanf (tkn, "%lf", &tempD);
5609                             modelParams[i].shapeUni[numVars[i]++] = tempD;
5610                             if (numVars[i] == 1)
5611                                 expecting  = Expecting(COMMA);
5612                             else
5613                                 {
5614                                 if (modelParams[i].shapeUni[0] >= modelParams[i].shapeUni[1])
5615                                     {
5616                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5617                                     return (ERROR);
5618                                     }
5619                                 if (modelParams[i].shapeUni[1] > MAX_SHAPE_PARAM)
5620                                     {
5621                                     MrBayesPrint ("%s   Upper value for uniform cannot be greater than %1.2lf\n", spacer, MAX_SHAPE_PARAM);
5622                                     return (ERROR);
5623                                     }
5624                                 if (modelParams[i].shapeUni[0] < MIN_SHAPE_PARAM)
5625                                     {
5626                                     MrBayesPrint ("%s   Lower value for uniform cannot be less than %1.2lf\n", spacer, MIN_SHAPE_PARAM);
5627                                     return (ERROR);
5628                                     }
5629                                 if (nApplied == 0 && numCurrentDivisions == 1)
5630                                     MrBayesPrint ("%s   Setting Shapepr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].shapeUni[0], modelParams[i].shapeUni[1]);
5631                                 else
5632                                     MrBayesPrint ("%s   Setting Shapepr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].shapeUni[0], modelParams[i].shapeUni[1], i+1);
5633                                 expecting  = Expecting(RIGHTPAR);
5634                                 }
5635                             }
5636                         else if (!strcmp(modelParams[i].shapePr,"Exponential"))
5637                             {
5638                             sscanf (tkn, "%lf", &tempD);
5639                             modelParams[i].shapeExp = tempD;
5640                             if (nApplied == 0 && numCurrentDivisions == 1)
5641                                 MrBayesPrint ("%s   Setting Shapepr to Exponential(%1.2lf)\n", spacer, modelParams[i].shapeExp);
5642                             else
5643                                 MrBayesPrint ("%s   Setting Shapepr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].shapeExp, i+1);
5644                             expecting  = Expecting(RIGHTPAR);
5645                             }
5646                         else if (!strcmp(modelParams[i].shapePr,"Fixed"))
5647                             {
5648                             sscanf (tkn, "%lf", &tempD);
5649                             modelParams[i].shapeFix = tempD;
5650                             if (modelParams[i].shapeFix > MAX_SHAPE_PARAM)
5651                                 {
5652                                 MrBayesPrint ("%s   Shape parameter cannot be greater than %1.2lf\n", spacer, MAX_SHAPE_PARAM);
5653                                 return (ERROR);
5654                                 }
5655                             if (modelParams[i].shapeFix < MIN_SHAPE_PARAM)
5656                                 {
5657                                 MrBayesPrint ("%s   Shape parameter cannot be less than %1.2lf\n", spacer, MIN_SHAPE_PARAM);
5658                                 return (ERROR);
5659                                 }
5660                             if (nApplied == 0 && numCurrentDivisions == 1)
5661                                 MrBayesPrint ("%s   Setting Shapepr to Fixed(%1.2lf)\n", spacer, modelParams[i].shapeFix);
5662                             else
5663                                 MrBayesPrint ("%s   Setting Shapepr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].shapeFix, i+1);
5664                             expecting  = Expecting(RIGHTPAR);
5665                             }
5666                         }
5667                     }
5668                 }
5669             else if (expecting == Expecting(COMMA))
5670                 {
5671                 expecting  = Expecting(NUMBER);
5672                 }
5673             else if (expecting == Expecting(RIGHTPAR))
5674                 {
5675                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5676                 }
5677             else
5678                 return (ERROR);
5679             }
5680         /* set Pinvarpr (pInvarPr) ************************************************************/
5681         else if (!strcmp(parmName, "Pinvarpr"))
5682             {
5683             if (expecting == Expecting(EQUALSIGN))
5684                 expecting = Expecting(ALPHA);
5685             else if (expecting == Expecting(ALPHA))
5686                 {
5687                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5688                     {
5689                     nApplied = NumActiveParts ();
5690                     flag = 0;
5691                     for (i=0; i<numCurrentDivisions; i++)
5692                         {
5693                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
5694                             {
5695                             strcpy(modelParams[i].pInvarPr, tempStr);
5696                             flag = 1;
5697                             }
5698                         }
5699                     if (flag == 0)
5700                         {
5701                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA, PROTEIN.\
5702                             Currently there is no active partition with such data.\n", spacer, parmName);
5703                         return (ERROR);
5704                         }
5705                     }
5706                 else
5707                     {
5708                     MrBayesPrint ("%s   Invalid Pinvarpr argument\n", spacer);
5709                     return (ERROR);
5710                     }
5711                 expecting  = Expecting(LEFTPAR);
5712                 for (i=0; i<numCurrentDivisions; i++)
5713                     numVars[i] = 0;
5714                 }
5715             else if (expecting == Expecting(LEFTPAR))
5716                 {
5717                 expecting  = Expecting(NUMBER);
5718                 }
5719             else if (expecting == Expecting(NUMBER))
5720                 {
5721                 nApplied = NumActiveParts ();
5722                 for (i=0; i<numCurrentDivisions; i++)
5723                     {
5724                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
5725                         {
5726                         if (!strcmp(modelParams[i].pInvarPr,"Uniform"))
5727                             {
5728                             sscanf (tkn, "%lf", &tempD);
5729                             modelParams[i].pInvarUni[numVars[i]++] = tempD;
5730                             if (numVars[i] == 1)
5731                                 expecting  = Expecting(COMMA);
5732                             else
5733                                 {
5734                                 if (modelParams[i].pInvarUni[0] >= modelParams[i].pInvarUni[1])
5735                                     {
5736                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5737                                     return (ERROR);
5738                                     }
5739                                 if (modelParams[i].pInvarUni[1] > 1.0)
5740                                     {
5741                                     MrBayesPrint ("%s   Upper value for uniform should be less than or equal to 1.0\n", spacer);
5742                                     return (ERROR);
5743                                     }
5744                                 if (nApplied == 0 && numCurrentDivisions == 1)
5745                                     MrBayesPrint ("%s   Setting Pinvarpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].pInvarUni[0], modelParams[i].pInvarUni[1]);
5746                                 else
5747                                     MrBayesPrint ("%s   Setting Pinvarpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].pInvarUni[0], modelParams[i].pInvarUni[1], i+1);
5748                                 expecting  = Expecting(RIGHTPAR);
5749                                 }
5750                             }
5751                         else if (!strcmp(modelParams[i].pInvarPr,"Fixed"))
5752                             {
5753                             sscanf (tkn, "%lf", &tempD);
5754                             if (tempD > 1.0)
5755                                 {
5756                                 MrBayesPrint ("%s   Value for Pinvar should be in the interval (0, 1)\n", spacer);
5757                                 return (ERROR);
5758                                 }
5759                             modelParams[i].pInvarFix = tempD;
5760                             if (nApplied == 0 && numCurrentDivisions == 1)
5761                                 MrBayesPrint ("%s   Setting Pinvarpr to Fixed(%1.2lf)\n", spacer, modelParams[i].pInvarFix);
5762                             else
5763                                 MrBayesPrint ("%s   Setting Pinvarpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].pInvarFix, i+1);
5764                             expecting  = Expecting(RIGHTPAR);
5765                             }
5766                         }
5767                     }
5768                 }
5769             else if (expecting == Expecting(COMMA))
5770                 {
5771                 expecting  = Expecting(NUMBER);
5772                 }
5773             else if (expecting == Expecting(RIGHTPAR))
5774                 {
5775                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5776                 }
5777             else
5778                 return (ERROR);
5779             }
5780         /* set Ratecorrpr (adGammaCorPr) ******************************************************/
5781         else if (!strcmp(parmName, "Ratecorrpr"))
5782             {
5783             if (expecting == Expecting(EQUALSIGN))
5784                 expecting = Expecting(ALPHA);
5785             else if (expecting == Expecting(ALPHA))
5786                 {
5787                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5788                     {
5789                     nApplied = NumActiveParts ();
5790                     flag = 0;
5791                     for (i=0; i<numCurrentDivisions; i++)
5792                         {
5793                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5794                             {
5795                             strcpy(modelParams[i].adGammaCorPr, tempStr);
5796                             flag = 1;
5797                             }
5798                         }
5799                     if (flag == 0)
5800                         {
5801                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA.\
5802                             Currently there is no active partition with such data.\n", spacer, parmName);
5803                         return (ERROR);
5804                         }
5805                     }
5806                 else
5807                     {
5808                     MrBayesPrint ("%s   Invalid Ratecorrpr argument\n", spacer);
5809                     return (ERROR);
5810                     }
5811                 expecting  = Expecting(LEFTPAR);
5812                 for (i=0; i<numCurrentDivisions; i++)
5813                     numVars[i] = 0;
5814                 foundDash = NO;
5815                 }
5816             else if (expecting == Expecting(LEFTPAR))
5817                 {
5818                 expecting = Expecting(NUMBER) | Expecting(DASH);
5819                 }
5820             else if (expecting == Expecting(NUMBER))
5821                 {
5822                 nApplied = NumActiveParts ();
5823                 for (i=0; i<numCurrentDivisions; i++)
5824                     {
5825                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
5826                         {
5827                         if (!strcmp(modelParams[i].adGammaCorPr,"Uniform"))
5828                             {
5829                             sscanf (tkn, "%lf", &tempD);
5830                             if (foundDash == YES)
5831                             tempD *= -1.0;
5832                             modelParams[i].corrUni[numVars[i]++] = tempD;
5833                             if (numVars[i] == 1)
5834                                 expecting  = Expecting(COMMA);
5835                             else
5836                                 {
5837                                 if (modelParams[i].corrUni[0] >= modelParams[i].corrUni[1])
5838                                     {
5839                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5840                                     return (ERROR);
5841                                     }
5842                                 if (modelParams[i].corrUni[1] > 1.0)
5843                                     {
5844                                     MrBayesPrint ("%s   Upper value for uniform should be less than or equal to 1.0\n", spacer);
5845                                     return (ERROR);
5846                                     }
5847                                 if (modelParams[i].corrUni[0] < -1.0)
5848                                     {
5849                                     MrBayesPrint ("%s   Lower value for uniform should be greater than or equal to -1.0\n", spacer);
5850                                     return (ERROR);
5851                                     }
5852                                 if (nApplied == 0 && numCurrentDivisions == 1)
5853                                     MrBayesPrint ("%s   Setting Ratecorrpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].corrUni[0], modelParams[i].corrUni[1]);
5854                                 else
5855                                     MrBayesPrint ("%s   Setting Ratecorrpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].corrUni[0], modelParams[i].corrUni[1], i+1);
5856                                 expecting  = Expecting(RIGHTPAR);
5857                                 }
5858                             }
5859                         else if (!strcmp(modelParams[i].adGammaCorPr,"Fixed"))
5860                             {
5861                             sscanf (tkn, "%lf", &tempD);
5862                             if (foundDash == YES)
5863                                 tempD *= -1.0;
5864                             if (tempD > 1.0 || tempD < -1.0)
5865                                 {
5866                                 MrBayesPrint ("%s   Value for Ratecorrpr should be in the interval (-1, +1)\n", spacer);
5867                                 return (ERROR);
5868                                 }
5869                             modelParams[i].corrFix = tempD;
5870                             if (nApplied == 0 && numCurrentDivisions == 1)
5871                                 MrBayesPrint ("%s   Setting Ratecorrpr to Fixed(%1.2lf)\n", spacer, modelParams[i].corrFix);
5872                             else
5873                                 MrBayesPrint ("%s   Setting Ratecorrpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].corrFix, i+1);
5874                             expecting  = Expecting(RIGHTPAR);
5875                             }
5876                         }
5877                     }
5878                 foundDash = NO;
5879                 }
5880             else if (expecting == Expecting(DASH))
5881                 {
5882                 foundDash = YES;
5883                 expecting  = Expecting(NUMBER);
5884                 }
5885             else if (expecting == Expecting(COMMA))
5886                 {
5887                 expecting  = Expecting(NUMBER) | Expecting(DASH);
5888                 }
5889             else if (expecting == Expecting(RIGHTPAR))
5890                 {
5891                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
5892                 }
5893             else
5894                 return (ERROR);
5895             }
5896         /* set Browncorrpr (brownCorPr) ******************************************************/
5897         else if (!strcmp(parmName, "Browncorrpr"))
5898             {
5899             if (expecting == Expecting(EQUALSIGN))
5900                 expecting = Expecting(ALPHA);
5901             else if (expecting == Expecting(ALPHA))
5902                 {
5903                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
5904                     {
5905                     nApplied = NumActiveParts ();
5906                     flag = 0;
5907                     for (i=0; i<numCurrentDivisions; i++)
5908                         {
5909                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
5910                             {
5911                             strcpy(modelParams[i].brownCorPr, tempStr);
5912                             flag = 1;
5913                             }
5914                         }
5915                     if (flag == 0)
5916                         {
5917                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing CONTINUOUS data.\
5918                             Currently there is no active partition with such data.\n", spacer, parmName);
5919                         return (ERROR);
5920                         }
5921                     }
5922                 else
5923                     {
5924                     MrBayesPrint ("%s   Invalid Browncorrpr argument\n", spacer);
5925                     return (ERROR);
5926                     }
5927                 expecting  = Expecting(LEFTPAR);
5928                 for (i=0; i<numCurrentDivisions; i++)
5929                     numVars[i] = 0;
5930                 foundDash = NO;
5931                 }
5932             else if (expecting == Expecting(LEFTPAR))
5933                 {
5934                 expecting = Expecting(NUMBER) | Expecting(DASH);
5935                 }
5936             else if (expecting == Expecting(NUMBER))
5937                 {
5938                 nApplied = NumActiveParts ();
5939                 for (i=0; i<numCurrentDivisions; i++)
5940                     {
5941                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
5942                         {
5943                         if (!strcmp(modelParams[i].brownCorPr,"Uniform"))
5944                             {
5945                             sscanf (tkn, "%lf", &tempD);
5946                             if (foundDash == YES)
5947                             tempD *= -1.0;
5948                             modelParams[i].brownCorrUni[numVars[i]++] = tempD;
5949                             if (numVars[i] == 1)
5950                                 expecting  = Expecting(COMMA);
5951                             else
5952                                 {
5953                                 if (modelParams[i].brownCorrUni[0] >= modelParams[i].brownCorrUni[1])
5954                                     {
5955                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
5956                                     return (ERROR);
5957                                     }
5958                                 if (modelParams[i].brownCorrUni[1] > 1.0)
5959                                     {
5960                                     MrBayesPrint ("%s   Upper value for uniform should be less than or equal to 1.0\n", spacer);
5961                                     return (ERROR);
5962                                     }
5963                                 if (modelParams[i].brownCorrUni[0] < -1.0)
5964                                     {
5965                                     MrBayesPrint ("%s   Lower value for uniform should be greater than or equal to -1.0\n", spacer);
5966                                     return (ERROR);
5967                                     }
5968                                 if (nApplied == 0 && numCurrentDivisions == 1)
5969                                     MrBayesPrint ("%s   Setting Browncorrpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brownCorrUni[0], modelParams[i].brownCorrUni[1]);
5970                                 else
5971                                     MrBayesPrint ("%s   Setting Browncorrpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brownCorrUni[0], modelParams[i].brownCorrUni[1], i+1);
5972                                 expecting  = Expecting(RIGHTPAR);
5973                                 }
5974                             }
5975                         else if (!strcmp(modelParams[i].brownCorPr,"Fixed"))
5976                             {
5977                             sscanf (tkn, "%lf", &tempD);
5978                             if (foundDash == YES)
5979                                 tempD *= -1.0;
5980                             if (tempD > 1.0 || tempD < -1.0)
5981                                 {
5982                                 MrBayesPrint ("%s   Value for Browncorrpr should be in the interval (-1, +1)\n", spacer);
5983                                 return (ERROR);
5984                                 }
5985                             modelParams[i].brownCorrFix = tempD;
5986                             if (nApplied == 0 && numCurrentDivisions == 1)
5987                                 MrBayesPrint ("%s   Setting Browncorrpr to Fixed(%1.2lf)\n", spacer, modelParams[i].brownCorrFix);
5988                             else
5989                                 MrBayesPrint ("%s   Setting Browncorrpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].brownCorrFix, i+1);
5990                             expecting  = Expecting(RIGHTPAR);
5991                             }
5992                         }
5993                     }
5994                 foundDash = NO;
5995                 }
5996             else if (expecting == Expecting(DASH))
5997                 {
5998                 foundDash = YES;
5999                 expecting  = Expecting(NUMBER);
6000                 }
6001             else if (expecting == Expecting(COMMA))
6002                 {
6003                 expecting  = Expecting(NUMBER) | Expecting(DASH);
6004                 }
6005             else if (expecting == Expecting(RIGHTPAR))
6006                 {
6007                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6008                 }
6009             else
6010                 return (ERROR);
6011             }
6012         /* set Ratepr (ratePr) *****************************************************************/
6013         else if (!strcmp(parmName, "Ratepr"))
6014             {
6015             if (expecting == Expecting(EQUALSIGN))
6016                 expecting = Expecting(ALPHA);
6017             else if (expecting == Expecting(ALPHA))
6018                 {
6019                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6020                     {
6021                     nApplied = NumActiveParts ();
6022                     for (i=0; i<numCurrentDivisions; i++)
6023                         {
6024                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6025                             {
6026                             if (!strcmp(tempStr,"Variable"))
6027                                 strcpy(modelParams[i].ratePr, "Dirichlet");
6028                             else
6029                                 strcpy(modelParams[i].ratePr, tempStr);
6030                             modelParams[i].ratePrDir = 1.0;
6031                             if (!strcmp(tempStr,"Variable") || !strcmp(tempStr,"Fixed"))
6032                                 {
6033                                 if (tempStr[0]=='V')
6034                                     strcat (tempStr," [Dirichlet(..,1,..)]");
6035                                 if (nApplied == 0 && numCurrentDivisions == 1)
6036                                     MrBayesPrint ("%s   Setting Ratepr to %s\n", spacer, tempStr);
6037                                 else
6038                                     MrBayesPrint ("%s   Setting Ratepr to %s for partition %d\n", spacer, tempStr, i+1);
6039                                 if (tempStr[0]=='V')
6040                                     strcpy (tempStr,"Variable");
6041                                 }
6042                             }
6043                         }
6044                     }
6045                 else
6046                     {
6047                     MrBayesPrint ("%s   Invalid Ratepr argument\n", spacer);
6048                     return (ERROR);
6049                     }
6050                 if (!strcmp(tempStr,"Fixed") || !strcmp(tempStr,"Variable"))
6051                     expecting  = Expecting(PARAMETER) | Expecting(SEMICOLON);
6052                 else
6053                     expecting = Expecting(LEFTPAR);
6054                 for (i=0; i<numCurrentDivisions; i++)
6055                     numVars[i] = 0;
6056                 }
6057             else if (expecting == Expecting(LEFTPAR))
6058                 {
6059                 expecting = Expecting (NUMBER);
6060                 }
6061             else if (expecting == Expecting(NUMBER))
6062                 {
6063                 /* find next partition to fill in */
6064                 nApplied = NumActiveParts ();
6065                 for (i=0; i<numCurrentDivisions; i++)
6066                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
6067                         break;
6068                 if (i == numCurrentDivisions)
6069                     {
6070                     MrBayesPrint ("%s   Could not find first ratemultiplier partition\n", spacer);
6071                     return (ERROR);
6072                     }
6073                 numVars[i] = 1;
6074                 /* read in the parameter */
6075                 sscanf (tkn, "%lf", &tempD);
6076                 if (tempD < ALPHA_MIN || tempD > ALPHA_MAX)
6077                     {
6078                     MrBayesPrint ("%s   Ratemultiplier Dirichlet parameter %lf out of range\n", spacer, tempD);
6079                     return (ERROR);
6080                     }
6081                 /* set the parameter */
6082                 modelParams[i].ratePrDir = tempD;
6083                 /* check if all partitions have been filled in */
6084                 for (i=0; i<numCurrentDivisions; i++)
6085                     {
6086                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
6087                         break;
6088                     }
6089                 /* set expecting accordingly so that we know what should be coming next */
6090                 if (i == numCurrentDivisions)
6091                     expecting = Expecting (RIGHTPAR);
6092                 else
6093                     expecting = Expecting (COMMA);
6094                 }
6095             else if (expecting == Expecting (COMMA))
6096                 expecting = Expecting (NUMBER);
6097             else if (expecting == Expecting (RIGHTPAR))
6098                 {
6099                 /* print message */
6100                 for (i=j=0; i<numCurrentDivisions; i++)
6101                     {
6102                     if (numVars[i] == 1)
6103                         {
6104                         j++;
6105                         if (j == 1)
6106                             {
6107                             MrBayesPrint ("%s   Setting Ratepr to Dirichlet(%1.2f",
6108                                 spacer, modelParams[i].ratePrDir);
6109                             }
6110                         else
6111                             MrBayesPrint(",%1.2f", modelParams[i].ratePrDir);
6112                         }
6113                     }
6114                 if (numCurrentDivisions == 1)
6115                     MrBayesPrint (")\n");
6116                 else
6117                     {
6118                     MrBayesPrint (") for partition");
6119                     if (j > 1)
6120                         MrBayesPrint ("s");
6121                     for (i=k=0; i<numCurrentDivisions; i++)
6122                         {
6123                         if (numVars[i] == 1)
6124                             {
6125                             k++;
6126                             if (k == j && j > 1)
6127                                 MrBayesPrint (", and %d", i+1);
6128                             else if (k == 1)
6129                                 MrBayesPrint (" %d", i+1);
6130                             else
6131                                 MrBayesPrint (", %d", i+1);
6132                             }
6133                         }
6134                     MrBayesPrint ("\n");
6135                     }
6136                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6137                 }
6138             else
6139                 return (ERROR);
6140             }
6141         /* set Generatepr (generatePr) *****************************************************************/
6142         else if (!strcmp(parmName, "Generatepr"))
6143             {
6144             if (expecting == Expecting(EQUALSIGN))
6145                 expecting = Expecting(ALPHA);
6146             else if (expecting == Expecting(ALPHA))
6147                 {
6148                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6149                     {
6150                     nApplied = NumActiveParts ();
6151                     for (i=0; i<numCurrentDivisions; i++)
6152                         {
6153                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6154                             {
6155                             if (!strcmp(tempStr,"Variable"))
6156                                 strcpy(modelParams[i].generatePr, "Dirichlet");
6157                             else
6158                                 strcpy(modelParams[i].generatePr, tempStr);
6159                             modelParams[i].generatePrDir = 1.0;
6160                             if (!strcmp(tempStr,"Variable") || !strcmp(tempStr,"Fixed"))
6161                                 {
6162                                 if (tempStr[0]=='V')
6163                                     strcat (tempStr," [Dirichlet(..,1,..)]");
6164                                 if (nApplied == 0 && numCurrentDivisions == 1)
6165                                     MrBayesPrint ("%s   Setting Generatepr to %s\n", spacer, tempStr);
6166                                 else
6167                                     MrBayesPrint ("%s   Setting Generatepr to %s for partition %d\n", spacer, tempStr, i+1);
6168                                 if (tempStr[0]=='V')
6169                                     strcpy (tempStr,"Variable");
6170                                 }
6171                             }
6172                         }
6173                     }
6174                 else
6175                     {
6176                     MrBayesPrint ("%s   Invalid Generatepr argument\n", spacer);
6177                     return (ERROR);
6178                     }
6179                 if (!strcmp(tempStr,"Fixed") || !strcmp(tempStr,"Variable"))
6180                     expecting  = Expecting(PARAMETER) | Expecting(SEMICOLON);
6181                 else
6182                     expecting = Expecting(LEFTPAR);
6183                 for (i=0; i<numCurrentDivisions; i++)
6184                     numVars[i] = 0;
6185                 }
6186             else if (expecting == Expecting(LEFTPAR))
6187                 {
6188                 expecting = Expecting (NUMBER);
6189                 }
6190             else if (expecting == Expecting(NUMBER))
6191                 {
6192                 /* find next partition to fill in */
6193                 nApplied = NumActiveParts ();
6194                 for (i=0; i<numCurrentDivisions; i++)
6195                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
6196                         break;
6197                 if (i == numCurrentDivisions)
6198                     {
6199                     MrBayesPrint ("%s   Could not find first generate multiplier partition\n", spacer);
6200                     return (ERROR);
6201                     }
6202                 numVars[i] = 1;
6203                 /* read in the parameter */
6204                 sscanf (tkn, "%lf", &tempD);
6205                 if (tempD < ALPHA_MIN || tempD > ALPHA_MAX)
6206                     {
6207                     MrBayesPrint ("%s   Generate multiplier Dirichlet parameter %lf out of range\n", spacer, tempD);
6208                     return (ERROR);
6209                     }
6210                 /* set the parameter */
6211                 modelParams[i].generatePrDir = tempD;
6212                 /* check if all partitions have been filled in */
6213                 for (i=0; i<numCurrentDivisions; i++)
6214                     {
6215                     if ((activeParts[i] == YES || nApplied == 0) && numVars[i] == 0)
6216                         break;
6217                     }
6218                 /* set expecting accordingly so that we know what should be coming next */
6219                 if (i == numCurrentDivisions)
6220                     expecting = Expecting (RIGHTPAR);
6221                 else
6222                     expecting = Expecting (COMMA);
6223                 }
6224             else if (expecting == Expecting (COMMA))
6225                 expecting = Expecting (NUMBER);
6226             else if (expecting == Expecting (RIGHTPAR))
6227                 {
6228                 /* print message */
6229                 for (i=j=0; i<numCurrentDivisions; i++)
6230                     {
6231                     if (numVars[i] == 1)
6232                         {
6233                         j++;
6234                         if (j == 1)
6235                             {
6236                             MrBayesPrint ("%s   Setting Generatepr to Dirichlet(%1.2f",
6237                                           spacer, modelParams[i].generatePrDir);
6238                             }
6239                         else
6240                             MrBayesPrint(",%1.2f", modelParams[i].generatePrDir);
6241                         }
6242                     }
6243                 if (numCurrentDivisions == 1)
6244                     MrBayesPrint (")\n");
6245                 else
6246                     {
6247                     MrBayesPrint (") for partition");
6248                     if (j > 1)
6249                         MrBayesPrint ("s");
6250                     for (i=k=0; i<numCurrentDivisions; i++)
6251                         {
6252                         if (numVars[i] == 1)
6253                             {
6254                             k++;
6255                             if (k == j && j > 1)
6256                                 MrBayesPrint (", and %d", i+1);
6257                             else if (k == 1)
6258                                 MrBayesPrint (" %d", i+1);
6259                             else
6260                                 MrBayesPrint (", %d", i+1);
6261                             }
6262                         }
6263                     MrBayesPrint ("\n");
6264                     }
6265                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6266                 }
6267             else
6268                 return (ERROR);
6269             }
6270         /* set Covswitchpr (covSwitchPr) ******************************************************/
6271         else if (!strcmp(parmName, "Covswitchpr"))
6272             {
6273             if (expecting == Expecting(EQUALSIGN))
6274                 expecting = Expecting(ALPHA);
6275             else if (expecting == Expecting(ALPHA))
6276                 {
6277                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6278                     {
6279                     nApplied = NumActiveParts ();
6280                     flag = 0;
6281                     for (i=0; i<numCurrentDivisions; i++)
6282                         {
6283                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
6284                             {
6285                             strcpy(modelParams[i].covSwitchPr, tempStr);
6286                             flag = 1;
6287                             }
6288                         }
6289                     if (flag == 0)
6290                         {
6291                         MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA, PROTEIN.\
6292                             Currently there is no active partition with such data. ", spacer, parmName);
6293                         return (ERROR);
6294                         }
6295                     }
6296                 else
6297                     {
6298                     MrBayesPrint ("%s   Invalid Covswitchpr argument\n", spacer);
6299                     return (ERROR);
6300                     }
6301                 expecting  = Expecting(LEFTPAR);
6302                 for (i=0; i<numCurrentDivisions; i++)
6303                     numVars[i] = 0;
6304                 }
6305             else if (expecting == Expecting(LEFTPAR))
6306                 {
6307                 expecting  = Expecting(NUMBER);
6308                 }
6309             else if (expecting == Expecting(NUMBER))
6310                 {
6311                 nApplied = NumActiveParts ();
6312                 for (i=0; i<numCurrentDivisions; i++)
6313                     {
6314                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA || modelParams[i].dataType == PROTEIN))
6315                         {
6316                         if (!strcmp(modelParams[i].covSwitchPr,"Uniform"))
6317                             {
6318                             sscanf (tkn, "%lf", &tempD);
6319                             modelParams[i].covswitchUni[numVars[i]++] = tempD;
6320                             if (numVars[i] == 1)
6321                                 expecting  = Expecting(COMMA);
6322                             else
6323                                 {
6324                                 if (modelParams[i].covswitchUni[0] >= modelParams[i].covswitchUni[1])
6325                                     {
6326                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
6327                                     return (ERROR);
6328                                     }
6329                                 if (nApplied == 0 && numCurrentDivisions == 1)
6330                                     MrBayesPrint ("%s   Setting Covswitchpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].covswitchUni[0], modelParams[i].covswitchUni[1]);
6331                                 else
6332                                     MrBayesPrint ("%s   Setting Covswitchpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].covswitchUni[0], modelParams[i].covswitchUni[1], i+1);
6333                                 expecting  = Expecting(RIGHTPAR);
6334                                 }
6335                             }
6336                         else if (!strcmp(modelParams[i].covSwitchPr,"Exponential"))
6337                             {
6338                             sscanf (tkn, "%lf", &tempD);
6339                             modelParams[i].covswitchExp = tempD;
6340                             if (nApplied == 0 && numCurrentDivisions == 1)
6341                                 MrBayesPrint ("%s   Setting Covswitchpr to Exponential(%1.2lf)\n", spacer, modelParams[i].covswitchExp);
6342                             else
6343                                 MrBayesPrint ("%s   Setting Covswitchpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].covswitchExp, i+1);
6344                             expecting  = Expecting(RIGHTPAR);
6345                             }
6346                         else if (!strcmp(modelParams[i].covSwitchPr,"Fixed"))
6347                             {
6348                             sscanf (tkn, "%lf", &tempD);
6349                             modelParams[i].covswitchFix[numVars[i]++] = tempD;
6350                             if (numVars[i] == 1)
6351                                 expecting  = Expecting(COMMA);
6352                             else
6353                                 {
6354                                 if (nApplied == 0 && numCurrentDivisions == 1)
6355                                     MrBayesPrint ("%s   Setting Covswitchpr to Fixed(%1.4lf,%1.4lf)\n", spacer, modelParams[i].covswitchFix[0], modelParams[i].covswitchFix[1]);
6356                                 else
6357                                     MrBayesPrint ("%s   Setting Covswitchpr to Fixed(%1.4lf,%1.4lf) for partition %d\n", spacer, modelParams[i].covswitchFix[0], modelParams[i].covswitchFix[1], i+1);
6358                                 expecting  = Expecting(RIGHTPAR);
6359                                 }
6360                             }
6361                         }
6362                     }
6363                 }
6364             else if (expecting == Expecting(COMMA))
6365                 {
6366                 expecting  = Expecting(NUMBER);
6367                 }
6368             else if (expecting == Expecting(RIGHTPAR))
6369                 {
6370                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6371                 }
6372             else
6373                 return (ERROR);
6374             }
6375         /* set Symdirihyperpr (symPiPr) ******************************************************/
6376         else if (!strcmp(parmName, "Symdirihyperpr"))
6377             {
6378             if (expecting == Expecting(EQUALSIGN))
6379                 {
6380                 foundBeta = NO;
6381                 expecting = Expecting(ALPHA);
6382                 }
6383             else if (expecting == Expecting(ALPHA))
6384                 {
6385                 if (foundBeta == NO)
6386                     {
6387                     /* expecting to see Uniform, Exponential, or Fixed */
6388                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
6389                         {
6390                         nApplied = NumActiveParts ();
6391                         flag = 0;
6392                         for (i=0; i<numCurrentDivisions; i++)
6393                             {
6394                             if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
6395                                 {
6396                                 strcpy(modelParams[i].symPiPr, tempStr);
6397                                 flag = 1;
6398                                 }
6399                             }
6400                         if (flag == 0)
6401                             {
6402                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing data", spacer, parmName);
6403                             MrBayesPrint ("  of at least one of the following type: STANDARD, RESTRICTION.");
6404                             MrBayesPrint ("Currently there is no active partition with such data. ");
6405                             return (ERROR);
6406                             }
6407                         }
6408                     else
6409                         {
6410                         MrBayesPrint ("%s   Invalid Symdirihyperpr argument\n", spacer);
6411                         return (ERROR);
6412                         }
6413                     expecting  = Expecting(LEFTPAR);
6414                     for (i=0; i<numCurrentDivisions; i++)
6415                         numVars[i] = 0;
6416                     foundBeta = YES;
6417                     }
6418                 else
6419                     {
6420                     /* expecting infinity */
6421                     if (IsSame("Infinity", tkn) == SAME || IsSame("Infinity", tkn) == CONSISTENT_WITH)
6422                         {
6423                         nApplied = NumActiveParts ();
6424                         for (i=0; i<numCurrentDivisions; i++)
6425                             {
6426                             if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
6427                                 {
6428                                 if (!strcmp(modelParams[i].symPiPr, "Fixed"))
6429                                     {
6430                                     modelParams[i].symBetaFix = -1;
6431                                     if (nApplied == 0 && numCurrentDivisions == 1)
6432                                         MrBayesPrint ("%s   Setting Symdirihyperpr to Beta(Infinity)\n", spacer);
6433                                     else
6434                                         MrBayesPrint ("%s   Setting Symdirihyperpr to Beta(Infinity) for partition %d\n", spacer, i+1);
6435                                     expecting  = Expecting(RIGHTPAR);
6436                                     }
6437                                 else
6438                                     {
6439                                     MrBayesPrint ("%s   Problem setting Symdirihyperpr\n", spacer);
6440                                     return (ERROR);
6441                                     }
6442                                 }
6443                             }
6444                         expecting  = Expecting(RIGHTPAR);
6445                         }
6446                     }
6447                 }
6448             else if (expecting == Expecting(LEFTPAR))
6449                 {
6450                 expecting  = Expecting(NUMBER) | Expecting(ALPHA);
6451                 }
6452             else if (expecting == Expecting(NUMBER))
6453                 {
6454                 nApplied = NumActiveParts ();
6455                 for (i=0; i<numCurrentDivisions; i++)
6456                     {
6457                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == STANDARD || modelParams[i].dataType == RESTRICTION))
6458                         {
6459                         if (!strcmp(modelParams[i].symPiPr,"Fixed"))
6460                             {
6461                             sscanf (tkn, "%lf", &tempD);
6462                             modelParams[i].symBetaFix = tempD;
6463                             if (nApplied == 0 && numCurrentDivisions == 1)
6464                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Fixed(%1.2lf)\n", spacer, modelParams[i].symBetaFix);
6465                             else
6466                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].symBetaFix, i+1);
6467                             expecting  = Expecting(RIGHTPAR);
6468                             }
6469                         else if (!strcmp(modelParams[i].symPiPr,"Exponential"))
6470                             {
6471                             sscanf (tkn, "%lf", &tempD);
6472                             modelParams[i].symBetaExp = tempD;
6473                             if (nApplied == 0 && numCurrentDivisions == 1)
6474                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Exponential(%1.2lf)\n", spacer, modelParams[i].symBetaExp);
6475                             else
6476                                 MrBayesPrint ("%s   Setting Symdirihyperpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].symBetaExp, i+1);
6477                             expecting  = Expecting(RIGHTPAR);
6478                             }
6479                         else if (!strcmp(modelParams[i].symPiPr,"Uniform"))
6480                             {
6481                             sscanf (tkn, "%lf", &tempD);
6482                             modelParams[i].symBetaUni[numVars[i]++] = tempD;
6483                             if (numVars[i] == 1)
6484                                 expecting = Expecting(COMMA);
6485                             else
6486                                 {
6487                                 if (modelParams[i].symBetaUni[0] >= modelParams[i].symBetaUni[1])
6488                                     {
6489                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
6490                                     return (ERROR);
6491                                     }
6492                                 if (nApplied == 0 && numCurrentDivisions == 1)
6493                                     MrBayesPrint ("%s   Setting Symdirihyperpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].symBetaUni[0], modelParams[i].symBetaUni[1]);
6494                                 else
6495                                     MrBayesPrint ("%s   Setting Symdirihyperpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].symBetaUni[0], modelParams[i].symBetaUni[1], i+1);
6496                                 expecting  = Expecting(RIGHTPAR);
6497                                 }
6498                             }
6499                         else
6500                             {
6501                             MrBayesPrint ("%s   Problem setting Symdirihyperpr\n", spacer);
6502                             return (ERROR);
6503                             }
6504                         }
6505                     }
6506                 }
6507             else if (expecting == Expecting(COMMA))
6508                 {
6509                 expecting  = Expecting(NUMBER);
6510                 }
6511             else if (expecting == Expecting(RIGHTPAR))
6512                 {
6513                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6514                 }
6515             else
6516                 return (ERROR);
6517             }
6518         /* set Statefreqpr (stateFreqPr) ******************************************************/
6519         else if (!strcmp(parmName, "Statefreqpr"))
6520             {
6521             if (expecting == Expecting(EQUALSIGN))
6522                 expecting = Expecting(ALPHA);
6523             else if (expecting == Expecting(ALPHA))
6524                 {
6525                 if (IsSame ("Equal", tkn) == DIFFERENT && IsSame ("Empirical", tkn) == DIFFERENT)
6526                     {
6527                     /* the user wants to specify a dirichlet or fixed prior */
6528                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
6529                         {
6530                         nApplied = NumActiveParts ();
6531                         for (i=0; i<numCurrentDivisions; i++)
6532                             {
6533                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6534                                 strcpy(modelParams[i].stateFreqPr, tempStr);
6535                             }
6536                         /* if (flag == 0)
6537                             {
6538                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing CONTINUOUS data.\
6539                             Currently there is no active partition with such data. ", spacer, parmName);
6540                             return (ERROR);
6541                             } */
6542                         }
6543                     else
6544                         {
6545                         MrBayesPrint ("%s   Invalid Statefreqpr argument\n", spacer);
6546                         return (ERROR);
6547                         }
6548                     /* TODO: Here we set flat dirichlet parameters */
6549                     expecting  = Expecting(LEFTPAR);
6550                     }
6551                 else
6552                     {
6553                     /* the user wants equal or empirical state frequencies */
6554                     nApplied = NumActiveParts ();
6555                     if (IsSame ("Equal", tkn) == SAME || IsSame ("Equal", tkn) == CONSISTENT_WITH)
6556                         {
6557                         for (i=0; i<numCurrentDivisions; i++)
6558                             {
6559                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6560                                 strcpy(modelParams[i].stateFreqsFixType, "Equal");
6561                             }
6562                         }
6563                     else if (IsSame ("Empirical", tkn) == SAME || IsSame ("Empirical", tkn) == CONSISTENT_WITH)
6564                         {
6565                         for (i=0; i<numCurrentDivisions; i++)
6566                             {
6567                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6568                                 strcpy(modelParams[i].stateFreqsFixType, "Empirical");
6569                             }
6570                         }
6571                     else
6572                         {
6573                         MrBayesPrint ("%s   Invalid Statefreqpr delimiter\n", spacer);
6574                         return (ERROR);
6575                         }
6576                     expecting  = Expecting(RIGHTPAR);
6577                     }
6578                 }
6579             else if (expecting == Expecting(LEFTPAR))
6580                 {
6581                 tempNumStates = 0;
6582                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
6583                 }
6584             else if (expecting == Expecting(NUMBER))
6585                 {
6586                 nApplied = NumActiveParts ();
6587                 sscanf (tkn, "%lf", &tempD);
6588                 tempStateFreqs[tempNumStates++] = tempD;
6589                 for (i=0; i<numCurrentDivisions; i++)
6590                     {
6591                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6592                         if (!strcmp(modelParams[i].stateFreqPr,"Fixed"))
6593                             strcpy(modelParams[i].stateFreqsFixType, "User");
6594                     }
6595                 expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
6596                 }
6597             else if (expecting == Expecting(COMMA))
6598                 {
6599                 expecting  = Expecting(NUMBER);
6600                 }
6601             else if (expecting == Expecting(RIGHTPAR))
6602                 {
6603                 nApplied = NumActiveParts ();
6604                 for (i=0; i<numCurrentDivisions; i++)
6605                     {
6606                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType != CONTINUOUS)
6607                         {
6608                         ns = NumStates(i);
6609                         if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
6610                             {
6611                             if (tempNumStates == 1)
6612                                 {
6613                                 for (j=0; j<ns; j++)
6614                                     modelParams[i].stateFreqsDir[j] = tempStateFreqs[0] / ns;
6615                                 MrBayesPrint ("%s   Setting Statefreqpr to Dirichlet(", spacer);
6616                                 for (j=0; j<ns; j++)
6617                                     {
6618                                     MrBayesPrint("%1.2lf", modelParams[i].stateFreqsDir[j]);
6619                                     if (j == ns - 1)
6620                                         MrBayesPrint (")");
6621                                     else
6622                                         MrBayesPrint (",");
6623                                     }
6624                                 if (nApplied == 0 && numCurrentDivisions == 1)
6625                                     MrBayesPrint ("\n");
6626                                 else
6627                                     MrBayesPrint (" for partition %d\n", i+1);
6628                                 modelParams[i].numDirParams = ns;
6629                                 }
6630                             else
6631                                 {
6632                                 if (tempNumStates != ns)
6633                                     {
6634                                     MrBayesPrint ("%s   Found %d dirichlet parameters but expecting %d\n", spacer, tempNumStates, modelParams[i].nStates);
6635                                     return (ERROR);
6636                                     }
6637                                 else
6638                                     {
6639                                     modelParams[i].numDirParams = ns;
6640                                     for (j=0; j<ns; j++)
6641                                         modelParams[i].stateFreqsDir[j] = tempStateFreqs[j];
6642                                     MrBayesPrint ("%s   Setting Statefreqpr to Dirichlet(", spacer);
6643                                     for (j=0; j<ns; j++)
6644                                         {
6645                                         MrBayesPrint("%1.2lf", modelParams[i].stateFreqsDir[j]);
6646                                         if (j == ns - 1)
6647                                             MrBayesPrint (")");
6648                                         else
6649                                             MrBayesPrint (",");
6650                                         }
6651                                     if (nApplied == 0 && numCurrentDivisions == 1)
6652                                         MrBayesPrint ("\n");
6653                                     else
6654                                         MrBayesPrint (" for partition %d\n", i+1);
6655                                     }
6656                                 }
6657                             }
6658                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed"))
6659                             {
6660                             if (tempNumStates == 0)
6661                                 {
6662                                 if (!strcmp(modelParams[i].stateFreqsFixType, "Equal"))
6663                                     MrBayesPrint ("%s   Setting Statefreqpr to Fixed(Equal)", spacer);
6664                                 else if (!strcmp(modelParams[i].stateFreqsFixType, "Empirical"))
6665                                     MrBayesPrint ("%s   Setting Statefreqpr to Fixed(Empirical)", spacer);
6666                                 if (nApplied == 0 && numCurrentDivisions == 1)
6667                                     MrBayesPrint ("\n");
6668                                 else
6669                                     MrBayesPrint (" for partition %d\n", i+1);
6670                                 }
6671                             else
6672                                 {
6673                                 if (tempNumStates == ns)
6674                                     {
6675                                     sum = 0.0;
6676                                     for (j=0; j<ns; j++)
6677                                         sum += tempStateFreqs[j];
6678                                     if (AreDoublesEqual (sum, (MrBFlt) 1.0, (MrBFlt) 0.001) == NO)
6679                                         {
6680                                         MrBayesPrint ("%s   State frequencies do not sum to 1.0\n", spacer);
6681                                         return (ERROR);
6682                                         }
6683                                     strcpy(modelParams[i].stateFreqsFixType, "User");
6684                                     for (j=0; j<ns; j++)
6685                                         modelParams[i].stateFreqsFix[j] = tempStateFreqs[j];
6686                                     MrBayesPrint ("%s   Setting Statefreqpr to Fixed(", spacer);
6687                                     for (j=0; j<ns; j++)
6688                                         {
6689                                         MrBayesPrint("%1.2lf", modelParams[i].stateFreqsFix[j]);
6690                                         if (j == ns - 1)
6691                                             MrBayesPrint (")");
6692                                         else
6693                                             MrBayesPrint (",");
6694                                         }
6695                                     if (nApplied == 0 && numCurrentDivisions == 1)
6696                                         MrBayesPrint ("\n");
6697                                     else
6698                                         MrBayesPrint (" for partition %d\n", i+1);
6699                                     }
6700                                 else
6701                                     {
6702                                     MrBayesPrint ("%s   Found %d state frequencies but expecting %d\n", spacer, tempNumStates, modelParams[i].nStates);
6703                                     return (ERROR);
6704                                     }
6705                                 }
6706 
6707                             }
6708                         }
6709                     }
6710                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6711                 }
6712             else
6713                 return (ERROR);
6714             }
6715         /* set Topologypr (topologyPr) ********************************************************/
6716         else if (!strcmp(parmName, "Topologypr"))
6717             {
6718             if (expecting == Expecting(EQUALSIGN))
6719                 {
6720                 foundEqual = YES;
6721                 expecting = Expecting(ALPHA);
6722                 }
6723             else if (expecting == Expecting(ALPHA))
6724                 {
6725                 if (foundEqual == YES)
6726                     {
6727                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
6728                         {
6729                         /* set topology prior */
6730                         nApplied = NumActiveParts ();
6731                         for (i=0; i<numCurrentDivisions; i++)
6732                             {
6733                             if (activeParts[i] == YES || nApplied == 0)
6734                                 {
6735                                 strcpy(modelParams[i].topologyPr, tempStr);
6736                                 /* erase previous constraints, if any */
6737                                 for (j=0; j<numDefinedConstraints; j++)
6738                                     modelParams[i].activeConstraints[j] = NO;
6739                                 if (nApplied == 0 && numCurrentDivisions == 1)
6740                                     MrBayesPrint ("%s   Setting Topologypr to %s\n", spacer, modelParams[i].topologyPr);
6741                                 else
6742                                     MrBayesPrint ("%s   Setting Topologypr to %s for partition %d\n", spacer, modelParams[i].topologyPr, i+1);
6743                                 /* adjust branch length prior if necessary */
6744                                 if (strcmp(modelParams[i].topologyPr,"Fixed") != 0 && strcmp(modelParams[i].brlensPr,"Fixed") == 0)
6745                                     {
6746                                     MrBayesPrint ("%s   Resetting Brlenspr to default\n", spacer);
6747                                     if (strcmp(modelParams[i].clockPr,"Clock") == 0)
6748                                         strcpy(modelParams[i].brlensPr, "Uniform");
6749                                     else
6750                                         strcpy(modelParams[i].brlensPr, defaultModel.brlensPr);
6751                                     }
6752                                 }
6753                             }
6754                         }
6755                     else
6756                         {
6757                         MrBayesPrint ("%s   Invalid Topologypr argument\n", spacer);
6758                         return (ERROR);
6759                         }
6760                     /* make sure we know what to do next */
6761                     if (!strcmp(tempStr, "Uniform") || !strcmp(tempStr, "Speciestree"))
6762                         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6763                     else
6764                         expecting = Expecting(LEFTPAR);
6765                     foundEqual = NO;
6766                     }
6767                 else
6768                     {
6769                     /* find out whether we need a tree name or constraint name */
6770                     nApplied = NumActiveParts ();
6771                     for (i=0; i<numCurrentDivisions; i++)
6772                         if (activeParts[i] == YES || nApplied == 0)
6773                             break;
6774 
6775                     if (foundDash == YES)   /* we must be collecting constraint numbers */
6776                         {
6777                         MrBayesPrint ("%s   Expecting a number\n", spacer);
6778                         return (ERROR);
6779                         }
6780                     if (!strcmp(modelParams[i].topologyPr,"Constraints"))
6781                         {
6782                         /* find constraint number */
6783                         if (CheckString (constraintNames, numDefinedConstraints, tkn, &index) == ERROR)
6784                             {
6785                             MrBayesPrint ("%s   Could not find constraint named %s\n", spacer, tkn);
6786                             return (ERROR);
6787                             }
6788                         tempActiveConstraints[index] = YES;
6789                         expecting = Expecting(RIGHTPAR);
6790                         expecting |= Expecting(COMMA);
6791                         }
6792                     else
6793                         {
6794                         /* find tree number */
6795                         if (GetUserTreeFromName (&index, tkn) == ERROR)
6796                             {
6797                             MrBayesPrint ("%s   Could not set fixed topology from user tree '%s'\n", spacer, tkn);
6798                             return (ERROR);
6799                             }
6800                         fromI = index + 1;        /* fromI is used to hold the index of the user tree, 1-based */
6801                         expecting = Expecting(RIGHTPAR);
6802                         }
6803                     }
6804                 }
6805             else if (expecting == Expecting(LEFTPAR))
6806                 {
6807                 for (i=0; i<numDefinedConstraints; i++)
6808                     tempActiveConstraints[i] = NO;
6809                 fromI = toJ = -1;
6810                 foundDash = foundComma = NO;
6811                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
6812                 }
6813             else if (expecting == Expecting(NUMBER))
6814                 {
6815                 /* find out whether we need a tree number or constraint number */
6816                 nApplied = NumActiveParts ();
6817                 for (i=0; i<numCurrentDivisions; i++)
6818                     if (activeParts[i] == YES || nApplied == 0)
6819                         break;
6820 
6821                 if (!strcmp(modelParams[i].topologyPr,"Constraints"))
6822                     {
6823                     if (numDefinedConstraints == 0)
6824                         {
6825                         MrBayesPrint ("%s   No constraints have been defined\n", spacer);
6826                         return (ERROR);
6827                         }
6828                     sscanf (tkn, "%d", &tempInt);
6829                     if (tempInt > numDefinedConstraints)
6830                         {
6831                         MrBayesPrint ("%s   Constraint number is too large\n", spacer);
6832                         return (ERROR);
6833                         }
6834                     if (fromI == -1)
6835                         {
6836                         if (foundDash == YES)
6837                             {
6838                             MrBayesPrint ("%s   Unexpected dash\n", spacer);
6839                             return (ERROR);
6840                             }
6841                         fromI = tempInt;
6842                         tempActiveConstraints[fromI-1] = YES;
6843                         }
6844                     else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
6845                         {
6846                         toJ = tempInt;
6847                         //for (i=fromI-1; i<toJ; i++)
6848                         for (i=fromI; i<toJ; i++)
6849                             tempActiveConstraints[i] = YES;
6850                         fromI = toJ = -1;
6851                         foundDash = NO;
6852                         }
6853                     else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
6854                         {
6855                         fromI = tempInt;
6856                         tempActiveConstraints[fromI-1] = YES;
6857                         foundComma = NO;
6858                         }
6859                     expecting  = Expecting(COMMA);
6860                     expecting |= Expecting(DASH);
6861                     expecting |= Expecting(RIGHTPAR);
6862                     }
6863                 else /* if (!strcmp(modelParams[i].topologyPr,"Fixed")) */
6864                     {
6865                     if (numUserTrees == 0)
6866                         {
6867                         MrBayesPrint ("%s   No user trees have been defined\n", spacer);
6868                         return (ERROR);
6869                         }
6870                     sscanf (tkn, "%d", &tempInt);
6871                     if (tempInt > numUserTrees)
6872                         {
6873                         MrBayesPrint ("%s   Tree number is too large\n", spacer);
6874                         return (ERROR);
6875                         }
6876                     if (tempInt < 1)
6877                         {
6878                         MrBayesPrint ("%s   Tree number is too small\n", spacer);
6879                         return (ERROR);
6880                         }
6881                     fromI = tempInt;
6882                     expecting = Expecting(RIGHTPAR);    /* only one tree number acceptable */
6883                     }
6884                 }
6885             else if (expecting == Expecting(COMMA))
6886                 {
6887                 foundComma = YES;
6888                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
6889                 }
6890             else if (expecting == Expecting(DASH))
6891                 {
6892                 foundDash = YES;
6893                 expecting = Expecting(NUMBER);
6894                 }
6895             else if (expecting == Expecting(RIGHTPAR))
6896                 {
6897                 /* find out whether we need a tree number or constraint number(s) */
6898                 nApplied = NumActiveParts ();
6899                 for (i=0; i<numCurrentDivisions; i++)
6900                     if (activeParts[i] == YES || nApplied == 0)
6901                         break;
6902 
6903                 if (!strcmp(modelParams[i].topologyPr,"Constraints"))
6904                     {
6905                     /* set constraints */
6906                     for (i=0; i<numCurrentDivisions; i++)
6907                         {
6908                         if (activeParts[i] == YES || nApplied == 0)
6909                             {
6910                             modelParams[i].numActiveConstraints = 0;
6911                             for (j=0; j<numDefinedConstraints; j++)
6912                                 {
6913                                 if (tempActiveConstraints[j] == YES)
6914                                     {
6915                                     modelParams[i].activeConstraints[j] = YES;
6916                                     modelParams[i].numActiveConstraints++;
6917                                     }
6918                                 else
6919                                     modelParams[i].activeConstraints[j] = NO;
6920                                 }
6921                             if (modelParams[i].numActiveConstraints == 0)
6922                                 {
6923                                 MrBayesPrint ("%s   No constraints have been defined\n", spacer);
6924                                 return (ERROR);
6925                                 }
6926                             }
6927                         }
6928                     }
6929                 else /* if (!strcmp(modelParams[i].topologyPr,"Constraints")) */
6930                     {
6931                     /* set start tree index */
6932                     for (i=0; i<numCurrentDivisions; i++)
6933                         {
6934                         if (activeParts[i] == YES || nApplied == 0)
6935                             modelParams[i].topologyFix = fromI-1;
6936                         }
6937                     }
6938 #               if 0
6939                 for (i=0; i<numCurrentDivisions; i++)
6940                     {
6941                     MrBayesPrint ("%4d -- ", i+1);
6942                     for (j=0; j<numDefinedConstraints; j++)
6943                         MrBayesPrint (" %d", modelParams[i].activeConstraints[j]);
6944                     MrBayesPrint ("\n");
6945                     }
6946 #               endif
6947                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6948                 }
6949             else
6950                 return (ERROR);
6951             }
6952         /* set Nodeagepr (nodeAgePr) ********************************************************/
6953         else if (!strcmp(parmName, "Nodeagepr"))
6954             {
6955             if (expecting == Expecting(EQUALSIGN))
6956                 expecting = Expecting(ALPHA);
6957             else if (expecting == Expecting(ALPHA))
6958                 {
6959                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6960                     {
6961                     nApplied = NumActiveParts ();
6962                     for (i=0; i<numCurrentDivisions; i++)
6963                         {
6964                         if (activeParts[i] == YES || nApplied == 0)
6965                             {
6966                             strcpy(modelParams[i].nodeAgePr, tempStr);
6967                             if (nApplied == 0 && numCurrentDivisions == 1)
6968                                 MrBayesPrint ("%s   Setting Nodeagepr to %s\n", spacer, modelParams[i].nodeAgePr);
6969                             else
6970                                 MrBayesPrint ("%s   Setting Nodeagepr to %s for partition %d\n", spacer, modelParams[i].nodeAgePr, i+1);
6971                             }
6972                         }
6973                     }
6974                 else
6975                     {
6976                     MrBayesPrint ("%s   Invalid Nodeagepr argument\n", spacer);
6977                     return (ERROR);
6978                     }
6979                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
6980                 }
6981             else
6982                 return (ERROR);
6983             }
6984         /* set Clockvarpr (clockVarPr) ********************************************************/
6985         else if (!strcmp(parmName, "Clockvarpr"))
6986             {
6987             if (expecting == Expecting(EQUALSIGN))
6988                 expecting = Expecting(ALPHA);
6989             else if (expecting == Expecting(ALPHA))
6990                 {
6991                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
6992                     {
6993                     if (strcmp(tempStr, "Bm") == 0)
6994                         strcpy(tempStr, "TK02");
6995                     else if (strcmp(tempStr, "Ibr") == 0)
6996                         strcpy(tempStr, "Igr");
6997                     nApplied = NumActiveParts ();
6998                     for (i=0; i<numCurrentDivisions; i++)
6999                         {
7000                         if (activeParts[i] == YES || nApplied == 0)
7001                             {
7002                             strcpy(modelParams[i].clockVarPr, tempStr);
7003                             if (nApplied == 0 && numCurrentDivisions == 1)
7004                                 MrBayesPrint ("%s   Setting Clockvarpr to %s\n", spacer, modelParams[i].clockVarPr);
7005                             else
7006                                 MrBayesPrint ("%s   Setting Clockvarpr to %s for partition %d\n", spacer, modelParams[i].clockVarPr, i+1);
7007                             }
7008                         }
7009                     }
7010                 else
7011                     {
7012                     MrBayesPrint ("%s   Invalid Clockvarpr argument\n", spacer);
7013                     return (ERROR);
7014                     }
7015                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7016                 }
7017             else
7018                 return (ERROR);
7019             }
7020         /* set Brlenspr (brlensPr) ************************************************************/
7021         else if (!strcmp(parmName, "Brlenspr"))
7022             {
7023             if (expecting == Expecting(EQUALSIGN))
7024                 {
7025                 for (i=0; i<numCurrentDivisions; i++)
7026                     numVars[i] = NO;
7027                 foundEqual = YES;
7028                 foundLeftPar = NO;
7029                 expecting = Expecting(ALPHA);
7030                 }
7031             else if (expecting == Expecting(ALPHA))
7032                 {
7033                 if (foundEqual == YES)
7034                     {
7035                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
7036                         {
7037                         strcpy (colonPr, tempStr);
7038                         nApplied = NumActiveParts ();
7039                         for (i=0; i<numCurrentDivisions; i++)
7040                             if (activeParts[i] == YES || nApplied == 0)
7041                                 strcpy(modelParams[i].brlensPr, tempStr);
7042                         }
7043                     else
7044                         {
7045                         MrBayesPrint ("%s   Invalid Brlenspr argument\n", spacer);
7046                         return (ERROR);
7047                         }
7048                     foundEqual = NO;
7049                     if (!strcmp(colonPr,"Fixed"))
7050                         expecting = Expecting(LEFTPAR);
7051                     else
7052                         expecting = Expecting(COLON);
7053                     }
7054                 else if (foundLeftPar == YES)
7055                     {
7056                     /*process argument of fixed() prior*/
7057                     /* find tree number */
7058                     if (GetUserTreeFromName (&tempInt, tkn) == ERROR)
7059                         {
7060                         MrBayesPrint ("%s   Could not set fixed branch lengths from the user tree '%s'\n", spacer, tkn);
7061                         return (ERROR);
7062                         }
7063                     fromI = tempInt + 1;        /* fromI is used to hold the index of the user tree, 1-based */
7064                     expecting = Expecting(RIGHTPAR);
7065                     foundLeftPar = NO;
7066                     }
7067                 else
7068                     {
7069                     if (!strcmp(colonPr, "Unconstrained"))
7070                         {
7071                         /* have unconstrained branch lengths, which we expect to have a uniform or exponential distribution */
7072                         nApplied = NumActiveParts ();
7073                         if (IsSame ("Uniform", tkn) == SAME || IsSame ("Uniform", tkn) == CONSISTENT_WITH)
7074                             {
7075                             for (i=0; i<numCurrentDivisions; i++)
7076                                 if (activeParts[i] == YES || nApplied == 0)
7077                                     strcpy(modelParams[i].unconstrainedPr, "Uniform");
7078                             }
7079                         else if (IsSame ("Exponential", tkn) == SAME || IsSame ("Exponential", tkn) == CONSISTENT_WITH)
7080                             {
7081                             for (i=0; i<numCurrentDivisions; i++)
7082                                 if (activeParts[i] == YES || nApplied == 0)
7083                                     strcpy(modelParams[i].unconstrainedPr, "Exponential");
7084                             }
7085                         else if (IsSame ("GammaDirichlet", tkn) == SAME || IsSame ("GammaDirichlet", tkn) == CONSISTENT_WITH)
7086                             {
7087                             for (i=0; i<numCurrentDivisions; i++)
7088                                 if (activeParts[i] == YES || nApplied == 0)
7089                                     strcpy(modelParams[i].unconstrainedPr, "GammaDir");
7090                             }
7091                         else if (IsSame ("invGamDirichlet", tkn) == SAME || IsSame ("invGamDirichlet", tkn) == CONSISTENT_WITH)
7092                             {
7093                             for (i=0; i<numCurrentDivisions; i++)
7094                                 if (activeParts[i] == YES || nApplied == 0)
7095                                     strcpy(modelParams[i].unconstrainedPr, "invGamDir");
7096                             }
7097                         else if (IsSame ("twoExponential", tkn) == SAME || IsSame ("twoExponential", tkn) == CONSISTENT_WITH)
7098                             {
7099                             for (i=0; i<numCurrentDivisions; i++)
7100                                 if (activeParts[i] == YES || nApplied == 0)
7101                                     strcpy(modelParams[i].unconstrainedPr, "twoExp");
7102                             }
7103                         else
7104                             {
7105                             MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
7106                             return (ERROR);
7107                             }
7108                         expecting  = Expecting(LEFTPAR);
7109                         }
7110                     else if (!strcmp(colonPr, "Clock"))
7111                         {
7112                         /* otherwise we have a clock constraint and expect uniform, birthdeath, coalescence or fixed prior */
7113                         nApplied = NumActiveParts ();
7114                         if (IsSame ("Uniform", tkn) == SAME || IsSame ("Uniform", tkn) == CONSISTENT_WITH)
7115                             {
7116                             strcpy (clockPr, "Uniform");
7117                             for (i=0; i<numCurrentDivisions; i++)
7118                                 {
7119                                 if (activeParts[i] == YES || nApplied == 0)
7120                                     strcpy(modelParams[i].clockPr, "Uniform");
7121                                 if (nApplied == 0 && numCurrentDivisions == 1)
7122                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Uniform\n", spacer);
7123                                 else
7124                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Uniform for partition %d\n", spacer, i+1);
7125                                 }
7126                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7127                             }
7128                         else if (IsSame ("Birthdeath", tkn) == SAME || IsSame ("Birthdeath", tkn) == CONSISTENT_WITH)
7129                             {
7130                             strcpy (clockPr, "Birthdeath");
7131                             for (i=0; i<numCurrentDivisions; i++)
7132                                 {
7133                                 if (activeParts[i] == YES || nApplied == 0)
7134                                     strcpy(modelParams[i].clockPr, "Birthdeath");
7135                                 if (nApplied == 0 && numCurrentDivisions == 1)
7136                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Birthdeath\n", spacer);
7137                                 else
7138                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Birthdeath for partition %d\n", spacer, i+1);
7139                                 }
7140                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7141                             }
7142                         else if (IsSame ("Coalescence", tkn) == SAME || IsSame ("Coalescence", tkn) == CONSISTENT_WITH)
7143                             {
7144                             strcpy (clockPr, "Coalescence");
7145                             for (i=0; i<numCurrentDivisions; i++)
7146                                 {
7147                                 if (activeParts[i] == YES || nApplied == 0)
7148                                     strcpy(modelParams[i].clockPr, "Coalescence");
7149                                 if (nApplied == 0 && numCurrentDivisions == 1)
7150                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Coalescence\n", spacer);
7151                                 else
7152                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Coalescence for partition %d\n", spacer, i+1);
7153                                 }
7154                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7155                             }
7156                         else if (IsSame ("Speciestreecoalescence", tkn) == SAME || IsSame ("Speciestreecoalescence", tkn) == CONSISTENT_WITH)
7157                             {
7158                             strcpy (clockPr, "Speciestreecoalescence");
7159                             for (i=0; i<numCurrentDivisions; i++)
7160                                 {
7161                                 if (activeParts[i] == YES || nApplied == 0)
7162                                     strcpy(modelParams[i].clockPr, "Speciestreecoalescence");
7163                                 if (nApplied == 0 && numCurrentDivisions == 1)
7164                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Speciestreecoalescence\n", spacer);
7165                                 else
7166                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Speciestreecoalescence for partition %d\n", spacer, i+1);
7167                                 }
7168                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7169                             }
7170                         else if (IsSame ("Fossilization", tkn) == SAME || IsSame ("Fossilization", tkn) == CONSISTENT_WITH)
7171                             {
7172                             strcpy (clockPr, "Fossilization");
7173                             for (i=0; i<numCurrentDivisions; i++)
7174                                 {
7175                                 if (activeParts[i] == YES || nApplied == 0)
7176                                     strcpy(modelParams[i].clockPr, "Fossilization");
7177                                 if (nApplied == 0 && numCurrentDivisions == 1)
7178                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Fossilization\n", spacer);
7179                                 else
7180                                     MrBayesPrint ("%s   Setting Brlenspr to Clock:Fossilization for partition %d\n", spacer, i+1);
7181                                 }
7182                             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7183                             }
7184                         else if (IsSame ("Fixed", tkn) == SAME || IsSame ("Fixed", tkn) == CONSISTENT_WITH)
7185                             {
7186                             strcpy (clockPr, "Fixed");
7187                             for (i=0; i<numCurrentDivisions; i++)
7188                                 {
7189                                 if (activeParts[i] == YES || nApplied == 0)
7190                                     strcpy(modelParams[i].clockPr, "Fixed");
7191                                 }
7192                             expecting = Expecting(LEFTPAR);     /* Proceed with tree name */
7193                             }
7194                         else
7195                             {
7196                             MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
7197                             return (ERROR);
7198                             }
7199                         }
7200                     else
7201                         {
7202                         MrBayesPrint ("%s   Do not understand %s\n", spacer, tkn);
7203                         return (ERROR);
7204                         }
7205                     }
7206                 }
7207             else if (expecting == Expecting(LEFTPAR))
7208                 {
7209                 foundLeftPar = YES;
7210                 expecting  = Expecting(NUMBER);
7211                 if (!strcmp(colonPr,"Fixed") || (!strcmp(colonPr,"Clock") && !strcmp(clockPr,"Fixed")))
7212                     {
7213                     expecting |= Expecting(ALPHA);
7214                     }
7215                 else
7216                     {
7217                     for (i=0; i<numCurrentDivisions; i++)
7218                         numVars[i] = 0;
7219                     }
7220                 }
7221             else if (expecting == Expecting(NUMBER))
7222                 {
7223                 if (!strcmp(colonPr, "Unconstrained"))
7224                     {
7225                     /* have unconstrained branch lengths */
7226                     nApplied = NumActiveParts ();
7227                     for (i=0; i<numCurrentDivisions; i++)
7228                         {
7229                         if (activeParts[i] == YES || nApplied == 0)
7230                             {
7231                             if (!strcmp(modelParams[i].unconstrainedPr,"Uniform"))
7232                                 {
7233                                 sscanf (tkn, "%lf", &tempD);
7234                                 modelParams[i].brlensUni[numVars[i]++] = tempD;
7235                                 if (numVars[i] == 1)
7236                                     expecting  = Expecting(COMMA);
7237                                 else
7238                                     {
7239                                     if (modelParams[i].brlensUni[0] > 0.000001)
7240                                         {
7241                                         MrBayesPrint ("%s   Lower value for uniform must equal 0.0\n", spacer);
7242                                         return (ERROR);
7243                                         }
7244                                     if (modelParams[i].brlensUni[0] >= modelParams[i].brlensUni[1])
7245                                         {
7246                                         MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
7247                                         return (ERROR);
7248                                         }
7249                                     if (nApplied == 0 && numCurrentDivisions == 1)
7250                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlensUni[0], modelParams[i].brlensUni[1]);
7251                                     else
7252                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlensUni[0], modelParams[i].brlensUni[1], i+1);
7253                                     expecting  = Expecting(RIGHTPAR);
7254                                     }
7255                                 }
7256                             else if (!strcmp(modelParams[i].unconstrainedPr,"Exponential"))
7257                                 {
7258                                 sscanf (tkn, "%lf", &tempD);
7259                                 modelParams[i].brlensExp = tempD;
7260                                 if (modelParams[i].brlensExp <= 0.0)
7261                                     {
7262                                     MrBayesPrint ("%s   Value for exponential must > 0.0\n", spacer);
7263                                     return (ERROR);
7264                                     }
7265                                 if (nApplied == 0 && numCurrentDivisions == 1)
7266                                     MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Exponential(%1.2lf)\n", spacer, modelParams[i].brlensExp);
7267                                 else
7268                                     MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].brlensExp, i+1);
7269                                 expecting  = Expecting(RIGHTPAR);
7270                                 }
7271                             else if (!strcmp(modelParams[i].unconstrainedPr,"GammaDir"))
7272                                 {
7273                                 sscanf (tkn, "%lf", &tempD);
7274                                 modelParams[i].brlensDir[numVars[i]++] = tempD;
7275                                 if (numVars[i] == 1 || numVars[i] == 2 || numVars[i] == 3)
7276                                     expecting  = Expecting(COMMA);
7277                                 else
7278                                     {
7279                                     if (modelParams[i].brlensDir[0] <= 0.0 || modelParams[i].brlensDir[1] <= 0.0 || modelParams[i].brlensDir[2] <= 0.0 || modelParams[i].brlensDir[3] <= 0.0)
7280                                         {
7281                                         MrBayesPrint ("%s   alphaT & betaT & a & c for GammaDir prior must > 0.0\n", spacer);
7282                                         return (ERROR);
7283                                         }
7284                                     if (nApplied == 0 && numCurrentDivisions == 1)
7285                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:GammaDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3]);
7286                                     else
7287                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:GammaDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3], i+1);
7288                                     expecting  = Expecting(RIGHTPAR);
7289                                     }
7290                                 }
7291                             else if (!strcmp(modelParams[i].unconstrainedPr,"invGamDir"))
7292                                 {
7293                                 sscanf (tkn, "%lf", &tempD);
7294                                 modelParams[i].brlensDir[numVars[i]++] = tempD;
7295                                 if (numVars[i] == 1 || numVars[i] == 2 || numVars[i] == 3)
7296                                     expecting  = Expecting(COMMA);
7297                                 else
7298                                     {
7299                                     if (modelParams[i].brlensDir[0] <= 2.0 || modelParams[i].brlensDir[1] <= 0.0 || modelParams[i].brlensDir[2] <= 0.0 || modelParams[i].brlensDir[3] <= 0.0)
7300                                         {
7301                                         MrBayesPrint ("%s   alphaT must > 2.0, betaT & a & c for invGamDir prior must > 0.0\n", spacer);
7302                                         return (ERROR);
7303                                         }
7304                                     if (nApplied == 0 && numCurrentDivisions == 1)
7305                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:invGamDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3]);
7306                                     else
7307                                         MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:invGamDir(%1.2lf,%1.4lf,%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlensDir[0], modelParams[i].brlensDir[1], modelParams[i].brlensDir[2], modelParams[i].brlensDir[3], i+1);
7308                                     expecting  = Expecting(RIGHTPAR);
7309                                     }
7310                                 }
7311                             else if (!strcmp(modelParams[i].unconstrainedPr,"twoExp"))
7312                                 {
7313                                     sscanf (tkn, "%lf", &tempD);
7314                                     modelParams[i].brlens2Exp[numVars[i]++] = tempD;
7315                                     if (numVars[i] == 1)
7316                                         expecting  = Expecting(COMMA);
7317                                     else
7318                                     {
7319                                         if (modelParams[i].brlens2Exp[0] <= 0.0 || modelParams[i].brlens2Exp[1] <= 0.0)
7320                                             {
7321                                             MrBayesPrint ("%s   Values for the two exponentials must > 0.0\n", spacer);
7322                                             return (ERROR);
7323                                             }
7324                                         if (nApplied == 0 && numCurrentDivisions == 1)
7325                                             MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:twoExp(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brlens2Exp[0], modelParams[i].brlens2Exp[1]);
7326                                         else
7327                                             MrBayesPrint ("%s   Setting Brlenspr to Unconstrained:twoExp(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brlens2Exp[0], modelParams[i].brlens2Exp[1], i+1);
7328                                         expecting  = Expecting(RIGHTPAR);
7329                                     }
7330                                 }
7331                             }
7332                         }
7333                     }
7334                 else if (!strcmp(colonPr,"Fixed") || !strcmp(colonPr,"Clock"))
7335                     {
7336                     sscanf (tkn, "%d", &tempInt);
7337                     if (tempInt < 1 || tempInt > numUserTrees)
7338                         {
7339                         MrBayesPrint ("%s   Tree needs to be in the range %d to %d\n", spacer, 1, numUserTrees);
7340                         return (ERROR);
7341                         }
7342                     fromI = tempInt;
7343                     expecting = Expecting(RIGHTPAR);
7344                     }
7345                 foundLeftPar = NO;
7346                 }
7347             else if (expecting == Expecting(COLON))
7348                 {
7349                 expecting  = Expecting(ALPHA);
7350                 }
7351             else if (expecting == Expecting(COMMA))
7352                 {
7353                 expecting  = Expecting(NUMBER);
7354                 }
7355             else if (expecting == Expecting(RIGHTPAR))
7356                 {
7357                 if (!strcmp(colonPr,"Fixed") || (!strcmp(colonPr,"Clock") && !strcmp(clockPr,"Fixed")))
7358                     {
7359                     /* index of a tree which set up branch lengths*/
7360                     nApplied = NumActiveParts ();
7361                     for (i=0; i<numCurrentDivisions; i++)
7362                         {
7363                         if (activeParts[i] == YES || nApplied == 0)
7364                             modelParams[i].brlensFix = fromI-1;
7365                         if (!strcmp(colonPr,"Fixed"))
7366                             {
7367                             if (nApplied == 0 && numCurrentDivisions == 1)
7368                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s)\n", spacer, userTree[fromI-1]->name);
7369                             else
7370                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s) for partition %d\n", spacer, userTree[fromI-1]->name, i+1);
7371                             }
7372                         else
7373                             {
7374                             if (nApplied == 0 && numCurrentDivisions == 1)
7375                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s)\n", spacer, userTree[fromI-1]->name);
7376                             else
7377                                 MrBayesPrint ("%s   Setting Brlenspr to Fixed(%s) for partition %d\n", spacer, userTree[fromI-1]->name, i+1);
7378                             }
7379                         }
7380                     }
7381                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7382                 }
7383             else
7384                 return (ERROR);
7385             }
7386         /* set Speciationpr (speciationPr) *************************************************/
7387         else if (!strcmp(parmName, "Speciationpr"))
7388             {
7389             if (expecting == Expecting(EQUALSIGN))
7390                 expecting = Expecting(ALPHA);
7391             else if (expecting == Expecting(ALPHA))
7392                 {
7393                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7394                     {
7395                     nApplied = NumActiveParts ();
7396                     for (i=0; i<numCurrentDivisions; i++)
7397                         if (activeParts[i] == YES || nApplied == 0)
7398                             strcpy(modelParams[i].speciationPr, tempStr);
7399                     }
7400                 else
7401                     {
7402                     MrBayesPrint ("%s   Invalid Speciationpr argument\n", spacer);
7403                     return (ERROR);
7404                     }
7405                 expecting  = Expecting(LEFTPAR);
7406                 for (i=0; i<numCurrentDivisions; i++)
7407                     numVars[i] = 0;
7408                 }
7409             else if (expecting == Expecting(LEFTPAR))
7410                 {
7411                 expecting  = Expecting(NUMBER);
7412                 }
7413             else if (expecting == Expecting(NUMBER))
7414                 {
7415                 nApplied = NumActiveParts ();
7416                 for (i=0; i<numCurrentDivisions; i++)
7417                     {
7418                     if (activeParts[i] == YES || nApplied == 0)
7419                         {
7420                         if (!strcmp(modelParams[i].speciationPr,"Uniform"))
7421                             {
7422                             sscanf (tkn, "%lf", &tempD);
7423                             modelParams[i].speciationUni[numVars[i]++] = tempD;
7424                             if (numVars[i] == 1)
7425                                 expecting  = Expecting(COMMA);
7426                             else
7427                                 {
7428                                 if (modelParams[i].speciationUni[0] >= modelParams[i].speciationUni[1])
7429                                     {
7430                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
7431                                     return (ERROR);
7432                                     }
7433                                 if (nApplied == 0 && numCurrentDivisions == 1)
7434                                     MrBayesPrint ("%s   Setting Speciationpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].speciationUni[0], modelParams[i].speciationUni[1]);
7435                                 else
7436                                     MrBayesPrint ("%s   Setting Speciationpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].speciationUni[0], modelParams[i].speciationUni[1], i+1);
7437                                 expecting  = Expecting(RIGHTPAR);
7438                                 }
7439                             }
7440                         else if (!strcmp(modelParams[i].speciationPr,"Exponential"))
7441                             {
7442                             sscanf (tkn, "%lf", &tempD);
7443                             if (tempD <= 0.0)
7444                                 {
7445                                 MrBayesPrint ("%s   Exponential parameter must be positive\n", spacer);
7446                                 return (ERROR);
7447                                 }
7448                             modelParams[i].speciationExp = tempD;
7449                             if (nApplied == 0 && numCurrentDivisions == 1)
7450                                 MrBayesPrint ("%s   Setting Speciationpr to Exponential(%1.2lf)\n", spacer, modelParams[i].speciationExp);
7451                             else
7452                                 MrBayesPrint ("%s   Setting Speciationpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].speciationExp, i+1);
7453                             expecting  = Expecting(RIGHTPAR);
7454                             }
7455                         else if (!strcmp(modelParams[i].speciationPr,"Fixed"))
7456                             {
7457                             sscanf (tkn, "%lf", &tempD);
7458                             if (tempD <= 0.0)
7459                                 {
7460                                 MrBayesPrint ("%s   Net speciation rate must be positive\n", spacer);
7461                                 return (ERROR);
7462                                 }
7463                             modelParams[i].speciationFix = tempD;
7464                             if (nApplied == 0 && numCurrentDivisions == 1)
7465                                 MrBayesPrint ("%s   Setting Speciationpr to Fixed(%1.2lf)\n", spacer, modelParams[i].speciationFix);
7466                             else
7467                                 MrBayesPrint ("%s   Setting Speciationpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].speciationFix, i+1);
7468                             expecting  = Expecting(RIGHTPAR);
7469                             }
7470                         }
7471                     }
7472                 }
7473             else if (expecting == Expecting(COMMA))
7474                 {
7475                 expecting  = Expecting(NUMBER);
7476                 }
7477             else if (expecting == Expecting(RIGHTPAR))
7478                 {
7479                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7480                 }
7481             else
7482                 return (ERROR);
7483             }
7484         /* set Extinctionpr (extinctionPr) *************************************************/
7485         else if (!strcmp(parmName, "Extinctionpr"))
7486             {
7487             if (expecting == Expecting(EQUALSIGN))
7488                 expecting = Expecting(ALPHA);
7489             else if (expecting == Expecting(ALPHA))
7490                 {
7491                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7492                     {
7493                     nApplied = NumActiveParts ();
7494                     for (i=0; i<numCurrentDivisions; i++)
7495                         if (activeParts[i] == YES || nApplied == 0)
7496                             strcpy(modelParams[i].extinctionPr, tempStr);
7497                     }
7498                 else
7499                     {
7500                     MrBayesPrint ("%s   Invalid Extinctionpr argument\n", spacer);
7501                     return (ERROR);
7502                     }
7503                 expecting  = Expecting(LEFTPAR);
7504                 for (i=0; i<numCurrentDivisions; i++)
7505                     numVars[i] = 0;
7506                 }
7507             else if (expecting == Expecting(LEFTPAR))
7508                 {
7509                 expecting  = Expecting(NUMBER);
7510                 }
7511             else if (expecting == Expecting(NUMBER))
7512                 {
7513                 nApplied = NumActiveParts ();
7514                 for (i=0; i<numCurrentDivisions; i++)
7515                     {
7516                     if (activeParts[i] == YES || nApplied == 0)
7517                         {
7518                         if (!strcmp(modelParams[i].extinctionPr,"Beta"))
7519                             {
7520                             sscanf (tkn, "%lf", &tempD);
7521                             if (tempD <= 0.0)
7522                                 {
7523                                 MrBayesPrint ("%s   Beta parameter must be positive\n", spacer);
7524                                 return (ERROR);
7525                                 }
7526                             modelParams[i].extinctionBeta[numVars[i]++] = tempD;
7527                             if (numVars[i] == 1)
7528                                 expecting  = Expecting(COMMA);
7529                             else
7530                                 {
7531                                 if (nApplied == 0 && numCurrentDivisions == 1)
7532                                     MrBayesPrint ("%s   Setting Extinctionpr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].extinctionBeta[0], modelParams[i].extinctionBeta[1]);
7533                                 else
7534                                     MrBayesPrint ("%s   Setting Extinctionpr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].extinctionBeta[0], modelParams[i].extinctionBeta[1], i+1);
7535                                 expecting  = Expecting(RIGHTPAR);
7536                                 }
7537                             }
7538                         else if (!strcmp(modelParams[i].extinctionPr,"Fixed"))
7539                             {
7540                             sscanf (tkn, "%lf", &tempD);
7541                             if (tempD < 0.0 || tempD >= 1.0)
7542                                 {
7543                                 MrBayesPrint ("%s   Relative extinction rate must be in range [0,1)\n", spacer);
7544                                 return (ERROR);
7545                                 }
7546                             modelParams[i].extinctionFix = tempD;
7547                             if (nApplied == 0 && numCurrentDivisions == 1)
7548                                 MrBayesPrint ("%s   Setting Extinctionpr to Fixed(%1.2lf)\n", spacer, modelParams[i].extinctionFix);
7549                             else
7550                                 MrBayesPrint ("%s   Setting Extinctionpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].extinctionFix, i+1);
7551                             expecting  = Expecting(RIGHTPAR);
7552                             }
7553                         }
7554                     }
7555                 }
7556             else if (expecting == Expecting(COMMA))
7557                 {
7558                 expecting  = Expecting(NUMBER);
7559                 }
7560             else if (expecting == Expecting(RIGHTPAR))
7561                 {
7562                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7563                 }
7564             else
7565                 return (ERROR);
7566             }
7567         /* set Fossilizationpr (fossilizationPr) */
7568         else if (!strcmp(parmName, "Fossilizationpr"))
7569             {
7570             if (expecting == Expecting(EQUALSIGN))
7571                 expecting = Expecting(ALPHA);
7572             else if (expecting == Expecting(ALPHA))
7573                 {
7574                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7575                     {
7576                     nApplied = NumActiveParts ();
7577                     for (i=0; i<numCurrentDivisions; i++)
7578                         if (activeParts[i] == YES || nApplied == 0)
7579                             strcpy(modelParams[i].fossilizationPr, tempStr);
7580                     }
7581                 else
7582                     {
7583                     MrBayesPrint ("%s   Invalid Fossilization argument\n", spacer);
7584                     return (ERROR);
7585                     }
7586                 expecting  = Expecting(LEFTPAR);
7587                 for (i=0; i<numCurrentDivisions; i++)
7588                     numVars[i] = 0;
7589                 }
7590             else if (expecting == Expecting(LEFTPAR))
7591                 {
7592                 expecting  = Expecting(NUMBER);
7593                 }
7594             else if (expecting == Expecting(NUMBER))
7595                 {
7596                 nApplied = NumActiveParts ();
7597                 for (i=0; i<numCurrentDivisions; i++)
7598                     {
7599                     if (activeParts[i] == YES || nApplied == 0)
7600                         {
7601                         if (!strcmp(modelParams[i].fossilizationPr,"Beta"))
7602                             {
7603                             sscanf (tkn, "%lf", &tempD);
7604                             if (tempD <= 0.0)
7605                                 {
7606                                 MrBayesPrint ("%s   Beta parameter must be positive\n", spacer);
7607                                 return (ERROR);
7608                                 }
7609                             modelParams[i].fossilizationBeta[numVars[i]++] = tempD;
7610                             if (numVars[i] == 1)
7611                                 expecting  = Expecting(COMMA);
7612                             else
7613                                 {
7614                                 if (nApplied == 0 && numCurrentDivisions == 1)
7615                                     MrBayesPrint ("%s   Setting Fossilizationpr to Beta(%1.2lf,%1.2lf)\n", spacer, modelParams[i].fossilizationBeta[0], modelParams[i].fossilizationBeta[1]);
7616                                 else
7617                                     MrBayesPrint ("%s   Setting Fossilizationpr to Beta(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].fossilizationBeta[0], modelParams[i].fossilizationBeta[1], i+1);
7618                                 expecting  = Expecting(RIGHTPAR);
7619                                 }
7620                             }
7621                         else if (!strcmp(modelParams[i].fossilizationPr,"Fixed"))
7622                             {
7623                             sscanf (tkn, "%lf", &tempD);
7624                             if (tempD < 0.0 || tempD > 1.0)
7625                                 {
7626                                 MrBayesPrint ("%s   Relative fossilization rate must be in the range (0,1]\n", spacer);
7627                                 return (ERROR);
7628                                 }
7629                             modelParams[i].fossilizationFix = tempD;
7630                             if (nApplied == 0 && numCurrentDivisions == 1)
7631                                 MrBayesPrint ("%s   Setting Fossilizationpr to Fixed(%1.2lf)\n", spacer, modelParams[i].fossilizationFix);
7632                             else
7633                                 MrBayesPrint ("%s   Setting Fossilizationpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].fossilizationFix, i+1);
7634                             expecting  = Expecting(RIGHTPAR);
7635                             }
7636                         }
7637                     }
7638                 }
7639             else if (expecting == Expecting(COMMA))
7640                 {
7641                 expecting  = Expecting(NUMBER);
7642                 }
7643             else if (expecting == Expecting(RIGHTPAR))
7644                 {
7645                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7646                 }
7647             else
7648                 return (ERROR);
7649             }
7650         /* set SampleStrat (sampleStrat) ***************************************************/
7651         else if (!strcmp(parmName, "Samplestrat"))  // prset samplestrat = random 3: 250 100 60 [fossil sampling], 1: 150 [birth], 2: 200 100 [death];
7652             {
7653             if (expecting == Expecting(EQUALSIGN))
7654                 {
7655                 expecting = Expecting(ALPHA);
7656                 }
7657             else if (expecting == Expecting(ALPHA))
7658                 {
7659                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7660                     {
7661                     nApplied = NumActiveParts ();
7662                     for (i=0; i<numCurrentDivisions; i++)
7663                         {
7664                         if (activeParts[i] == YES || nApplied == 0)
7665                             {
7666                             strcpy(modelParams[i].sampleStrat, tempStr);
7667                             if (nApplied == 0 && numCurrentDivisions == 1)
7668                                 MrBayesPrint ("%s   Setting SampleStrat to %s\n", spacer, modelParams[i].sampleStrat);
7669                             else
7670                                 MrBayesPrint ("%s   Setting SampleStrat to %s for partition %d\n", spacer, modelParams[i].sampleStrat, i+1);
7671                             if (!strcmp(modelParams[i].sampleStrat,"Random") || !strcmp(modelParams[i].sampleStrat,"Diversity"))
7672                                 {
7673                                 foundFSNum[i]  = foundBSNum[i]  = foundDSNum[i]  = NO;
7674                                 foundFSTime[i] = foundBSTime[i] = foundDSTime[i] = NO;
7675                                 modelParams[i].fossilSamplingNum = 0;
7676                                 modelParams[i].birthRateShiftNum = 0;
7677                                 modelParams[i].deathRateShiftNum = 0;
7678                                 numVars[i] = 0;
7679                                 expecting  = Expecting(NUMBER);
7680                                 expecting |= Expecting(PARAMETER);
7681                                 expecting |= Expecting(SEMICOLON);
7682                                 }
7683                             else
7684                                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7685                             }
7686                         }
7687                     }
7688                 else
7689                     {
7690                     MrBayesPrint ("%s   Invalid Samplestrat argument\n", spacer);
7691                     return (ERROR);
7692                     }
7693                 }
7694             else if (expecting == Expecting(NUMBER))
7695                 {
7696                 nApplied = NumActiveParts ();
7697                 for (i=0; i<numCurrentDivisions; i++)
7698                     {
7699                     if (activeParts[i] == YES || nApplied == 0)
7700                         {
7701                         if (foundFSNum[i] == NO)  // fossil sampling rate shift times
7702                             {
7703                             sscanf (tkn, "%d", &tempInt);
7704                             if (tempInt < 0 || tempInt > 99)
7705                                 {
7706                                 MrBayesPrint ("%s   Number of fossil sampling rate shift must be between 0 and 100\n", spacer);
7707                                 return (ERROR);
7708                                 }
7709                             modelParams[i].fossilSamplingNum = tempInt;
7710                             foundFSNum[i] = YES;
7711                             if (tempInt == 0)
7712                                 {
7713                                 foundFSTime[i] = YES;
7714                                 expecting  = Expecting(COMMA);
7715                                 expecting |= Expecting(PARAMETER);
7716                                 expecting |= Expecting(SEMICOLON);
7717                                 }
7718                             else
7719                                 expecting = Expecting(COLON);
7720                             }
7721                         else if (foundFSTime[i] == NO)
7722                             {
7723                             sscanf (tkn, "%lf", &tempD);
7724                             if (tempD <= 0.0)
7725                                 {
7726                                 MrBayesPrint ("%s   Time of fossil sampling rate shift must be > 0.\n", spacer);
7727                                 return (ERROR);
7728                                 }
7729                             if (numVars[i] > 0 && modelParams[i].fossilSamplingTime[numVars[i]-1] < tempD)
7730                                 {
7731                                 MrBayesPrint ("%s   Time of fossil sampling rate shift must be in decreasing order\n", spacer);
7732                                 return (ERROR);
7733                                 }
7734                             modelParams[i].fossilSamplingTime[numVars[i]] = tempD;
7735                             if (nApplied == 0 && numCurrentDivisions == 1)
7736                                 MrBayesPrint ("%s   Setting %d fossil sampling rate shift time to %1.2lf\n", spacer, numVars[i]+1,
7737                                               modelParams[i].fossilSamplingTime[numVars[i]]);
7738                             else
7739                                 MrBayesPrint ("%s   Setting %d fossil sampling rate shift time to %1.2lf for partition %d\n", spacer, numVars[i]+1,
7740                                               modelParams[i].fossilSamplingTime[numVars[i]], i+1);
7741                             numVars[i]++;
7742                             expecting = Expecting(NUMBER);
7743                             if (numVars[i] == modelParams[i].fossilSamplingNum) {
7744                                 foundFSTime[i] = YES;
7745                                 numVars[i] = 0;
7746                                 expecting  = Expecting(COMMA);
7747                                 expecting |= Expecting(PARAMETER);
7748                                 expecting |= Expecting(SEMICOLON);
7749                                 }
7750                             }
7751                         else if (foundBSNum[i] == NO)  // birth rate shift times
7752                             {
7753                             sscanf (tkn, "%d", &tempInt);
7754                             if (tempInt < 0 || tempInt > 99)
7755                                 {
7756                                 MrBayesPrint ("%s   Number of birth rate shift must be between 0 and 100\n", spacer);
7757                                 return (ERROR);
7758                                 }
7759                             modelParams[i].birthRateShiftNum = tempInt;
7760                             foundBSNum[i] = YES;
7761                             if (tempInt == 0)
7762                                 {
7763                                 foundBSTime[i] = YES;
7764                                 expecting  = Expecting(COMMA);
7765                                 expecting |= Expecting(PARAMETER);
7766                                 expecting |= Expecting(SEMICOLON);
7767                                 }
7768                             else
7769                                 expecting = Expecting(COLON);
7770                             }
7771                         else if (foundBSTime[i] == NO)
7772                             {
7773                             sscanf (tkn, "%lf", &tempD);
7774                             if (tempD <= 0.0)
7775                                 {
7776                                 MrBayesPrint ("%s   Time of birth rate shift must be > 0.\n", spacer);
7777                                 return (ERROR);
7778                                 }
7779                             if (numVars[i] > 0 && modelParams[i].birthRateShiftTime[numVars[i]-1] < tempD)
7780                                 {
7781                                 MrBayesPrint ("%s   Time of birth rate shift must be in decreasing order\n", spacer);
7782                                 return (ERROR);
7783                                 }
7784                             modelParams[i].birthRateShiftTime[numVars[i]] = tempD;
7785                             if (nApplied == 0 && numCurrentDivisions == 1)
7786                                 MrBayesPrint ("%s   Setting %d birth rate shift time to %1.2lf\n", spacer, numVars[i]+1,
7787                                               modelParams[i].birthRateShiftTime[numVars[i]]);
7788                             else
7789                                 MrBayesPrint ("%s   Setting %d birth rate shift time to %1.2lf for partition %d\n", spacer, numVars[i]+1,
7790                                               modelParams[i].birthRateShiftTime[numVars[i]], i+1);
7791                             numVars[i]++;
7792                             expecting = Expecting(NUMBER);
7793                             if (numVars[i] == modelParams[i].birthRateShiftNum) {
7794                                 foundBSTime[i] = YES;
7795                                 numVars[i] = 0;
7796                                 expecting  = Expecting(COMMA);
7797                                 expecting |= Expecting(PARAMETER);
7798                                 expecting |= Expecting(SEMICOLON);
7799                                 }
7800                             }
7801                         else if (foundDSNum[i] == NO)  // death rate shift times
7802                             {
7803                             sscanf (tkn, "%d", &tempInt);
7804                             if (tempInt < 0 || tempInt > 99)
7805                                 {
7806                                 MrBayesPrint ("%s   Number of death rate shift must be between 0 and 100\n", spacer);
7807                                 return (ERROR);
7808                                 }
7809                             modelParams[i].deathRateShiftNum = tempInt;
7810                             foundDSNum[i] = YES;
7811                             if (tempInt == 0)
7812                                 {
7813                                 foundDSTime[i] = YES;
7814                                 expecting  = Expecting(COMMA);
7815                                 expecting |= Expecting(PARAMETER);
7816                                 expecting |= Expecting(SEMICOLON);
7817                                 }
7818                             else
7819                                 expecting = Expecting(COLON);
7820                             }
7821                         else if (foundDSTime[i] == NO)
7822                             {
7823                             sscanf (tkn, "%lf", &tempD);
7824                             if (tempD <= 0.0)
7825                                 {
7826                                 MrBayesPrint ("%s   Time of death rate shift must be > 0.\n", spacer);
7827                                 return (ERROR);
7828                                 }
7829                             if (numVars[i] > 0 && modelParams[i].deathRateShiftTime[numVars[i]-1] < tempD)
7830                                 {
7831                                 MrBayesPrint ("%s   Time of death rate shift must be in decreasing order\n", spacer);
7832                                 return (ERROR);
7833                                 }
7834                             modelParams[i].deathRateShiftTime[numVars[i]] = tempD;
7835                             if (nApplied == 0 && numCurrentDivisions == 1)
7836                                 MrBayesPrint ("%s   Setting %d death rate shift time to %1.2lf\n", spacer, numVars[i]+1,
7837                                               modelParams[i].deathRateShiftTime[numVars[i]]);
7838                             else
7839                                 MrBayesPrint ("%s   Setting %d death rate shift time to %1.2lf for partition %d\n", spacer, numVars[i]+1,
7840                                               modelParams[i].deathRateShiftTime[numVars[i]], i+1);
7841                             numVars[i]++;
7842                             expecting = Expecting(NUMBER);
7843                             if (numVars[i] == modelParams[i].deathRateShiftNum)
7844                                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7845                             }
7846                         }
7847                     }
7848                 }
7849             else if (expecting == Expecting(COLON) || expecting == Expecting(COMMA))
7850                 {
7851                 expecting  = Expecting(NUMBER);
7852                 }
7853             else
7854                 {
7855                 return (ERROR);
7856                 }
7857             }
7858         /* set Sampleprob (sampleProb) *****************************************************/
7859         else if (!strcmp(parmName, "Sampleprob"))
7860             {
7861             if (expecting == Expecting(EQUALSIGN))
7862                 expecting = Expecting(NUMBER);
7863             else if (expecting == Expecting(NUMBER))
7864                 {
7865                 nApplied = NumActiveParts ();
7866                 for (i=0; i<numCurrentDivisions; i++)
7867                     {
7868                     if ((activeParts[i] == YES || nApplied == 0))
7869                         {
7870                         sscanf (tkn, "%lf", &tempD);
7871                         if (tempD < 0.0 || tempD > 1.0)
7872                             {
7873                             MrBayesPrint ("%s   Sampleprob should be in range [0,1]\n", spacer);
7874                             return (ERROR);
7875                             }
7876                         modelParams[i].sampleProb = tempD;
7877                         if (nApplied == 0 && numCurrentDivisions == 1)
7878                             MrBayesPrint ("%s   Setting Sampleprob to %1.8lf\n", spacer, modelParams[i].sampleProb);
7879                         else
7880                             MrBayesPrint ("%s   Setting Sampleprob to %1.8lf for partition %d\n", spacer, modelParams[i].sampleProb, i+1);
7881                         }
7882                     }
7883                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
7884                 }
7885             else
7886                 return (ERROR);
7887             }
7888         /* set Treeagepr (treeAgePr) *******************************************************/
7889         else if (!strcmp(parmName, "Treeagepr"))
7890             {
7891             if (expecting == Expecting(EQUALSIGN))
7892                 expecting = Expecting(ALPHA);
7893             else if (expecting == Expecting(ALPHA))
7894                 {
7895                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
7896                     {
7897                     nApplied = NumActiveParts ();
7898                     for (i=0; i<numCurrentDivisions; i++)
7899                         if (activeParts[i] == YES || nApplied == 0)
7900                             {
7901                             strcpy(modelParams[i].treeAgePr.name, tempStr);
7902                             if (!strcmp(tempStr,"Fixed"))
7903                                 modelParams[i].treeAgePr.prior = fixed;
7904                             else if (!strcmp(tempStr,"Uniform"))
7905                                 modelParams[i].treeAgePr.prior = uniform;
7906                             else if (!strcmp(tempStr,"Offsetexponential"))
7907                                 modelParams[i].treeAgePr.prior = offsetExponential;
7908                             else if (!strcmp(tempStr,"Truncatednormal"))
7909                                 modelParams[i].treeAgePr.prior = truncatedNormal;
7910                             else if (!strcmp(tempStr,"Lognormal"))
7911                                 modelParams[i].treeAgePr.prior = logNormal;
7912                             else if (!strcmp(tempStr,"Offsetlognormal"))
7913                                 modelParams[i].treeAgePr.prior = offsetLogNormal;
7914                             else if (!strcmp(tempStr,"Gamma"))
7915                                 modelParams[i].treeAgePr.prior = standardGamma;
7916                             else if (!strcmp(tempStr,"Offsetgamma"))
7917                                 modelParams[i].treeAgePr.prior = offsetGamma;
7918                             }
7919                     }
7920                 else
7921                     {
7922                     MrBayesPrint ("%s   Invalid Treeagepr argument\n", spacer);
7923                     return (ERROR);
7924                     }
7925                 expecting  = Expecting(LEFTPAR);
7926                 for (i=0; i<numCurrentDivisions; i++)
7927                     numVars[i] = 0;
7928                 }
7929             else if (expecting == Expecting(LEFTPAR))
7930                 {
7931                 nApplied = NumActiveParts ();
7932                 for (i=0; i<numCurrentDivisions; i++)
7933                     if (activeParts[i] == YES || nApplied == 0)
7934                         strcat(modelParams[i].treeAgePr.name, "(");
7935                 expecting  = Expecting(NUMBER);
7936                 }
7937             else if (expecting == Expecting(NUMBER))
7938                 {
7939                 sscanf (tkn, "%lf", &tempD);
7940                 sprintf (tempStr, "%1.2lf", tempD);
7941                 nApplied = NumActiveParts ();
7942                 for (i=0; i<numCurrentDivisions; i++)
7943                     {
7944                     if (activeParts[i] == YES || nApplied == 0)
7945                         {
7946                         if (numVars[i] == 0 && tempD < 0.0)
7947                             {
7948                             if (modelParams[i].treeAgePr.prior == uniform ||
7949                                 modelParams[i].treeAgePr.prior == offsetExponential ||
7950                                 modelParams[i].treeAgePr.prior == truncatedNormal ||
7951                                 modelParams[i].treeAgePr.prior == offsetLogNormal ||
7952                                 modelParams[i].treeAgePr.prior == offsetGamma)
7953                                 MrBayesPrint("%s   Minimum, offset or truncation point must be nonnegative\n", spacer);
7954                             else if (modelParams[i].treeAgePr.prior == fixed)
7955                                 MrBayesPrint("%s   Fixed age must be nonnegative\n", spacer);
7956                             else
7957                                 MrBayesPrint("%s   Mean must be nonnegative\n", spacer);
7958                             break;
7959                             }
7960                         else if (numVars[i] == 1)
7961                             {
7962                             if (modelParams[i].treeAgePr.prior == uniform && tempD <= modelParams[i].treeAgePr.priorParams[0])
7963                                 {
7964                                 MrBayesPrint("%s   Max of uniform distribution must be larger than min\n", spacer);
7965                                 break;
7966                                 }
7967                             else if ((modelParams[i].treeAgePr.prior == standardGamma || modelParams[i].treeAgePr.prior == logNormal) && tempD <= 0.0)
7968                                 {
7969                                 MrBayesPrint("%s   Standard deviation must be positive\n", spacer);
7970                                 break;
7971                                 }
7972                             else if ((modelParams[i].treeAgePr.prior == offsetExponential ||
7973                                       modelParams[i].treeAgePr.prior == offsetGamma ||
7974                                       modelParams[i].treeAgePr.prior == offsetLogNormal) && tempD <= modelParams[i].treeAgePr.priorParams[0])
7975                                 {
7976                                 MrBayesPrint("%s   Mean must be larger than offset\n", spacer);
7977                                 break;
7978                                 }
7979                             }
7980                         else if (numVars[i] == 2 && tempD <= 0.0)
7981                             {
7982                             MrBayesPrint("%s   Standard deviation must be positive\n", spacer);
7983                             break;
7984                             }
7985                         modelParams[i].treeAgePr.priorParams[numVars[i]++] = tempD;
7986                         sprintf (tempStr, "%1.2lf", tempD);
7987                         strcat(modelParams[i].treeAgePr.name, tempStr);
7988                         if (modelParams[i].treeAgePr.prior == fixed || numVars[i] == 3)
7989                             expecting = Expecting(RIGHTPAR);
7990                         else if (numVars[i] == 1)
7991                             expecting = Expecting(COMMA);
7992                         else if (modelParams[i].treeAgePr.prior == standardGamma ||
7993                                  modelParams[i].treeAgePr.prior == uniform ||
7994                                  modelParams[i].treeAgePr.prior == offsetExponential ||
7995                                  modelParams[i].treeAgePr.prior == logNormal)
7996                             expecting = Expecting(RIGHTPAR);
7997                         else
7998                             expecting = Expecting(COMMA);
7999                         }
8000                     }
8001                 if (i < numCurrentDivisions)
8002                     {
8003                     /* An error occurred. Reset calibrations and bail out */
8004                     nApplied = NumActiveParts ();
8005                     for (i=0; i<numCurrentDivisions; i++)
8006                         {
8007                         if (activeParts[i] == YES || nApplied == 0)
8008                             {
8009                             strcpy(modelParams[i].treeAgePr.name, "Gamma(1.00,1.00)");
8010                             modelParams[i].treeAgePr.prior = standardGamma;
8011                             modelParams[i].treeAgePr.priorParams[0] = 1.0;
8012                             modelParams[i].treeAgePr.priorParams[1] = 1.0;
8013                             modelParams[i].treeAgePr.priorParams[2] = -1.0;
8014                             modelParams[i].treeAgePr.min = 0.0;
8015                             modelParams[i].treeAgePr.max = POS_INFINITY;
8016                             }
8017                         }
8018                     return (ERROR);
8019                     }
8020                 }
8021             else if (expecting == Expecting(COMMA))
8022                 {
8023                 nApplied = NumActiveParts ();
8024                 for (i=0; i<numCurrentDivisions; i++)
8025                     if (activeParts[i] == YES || nApplied == 0)
8026                         strcat(modelParams[i].treeAgePr.name, ",");
8027                 expecting  = Expecting(NUMBER);
8028                 }
8029             else if (expecting == Expecting(RIGHTPAR))
8030                 {
8031                 nApplied = NumActiveParts ();
8032                 for (i=0; i<numCurrentDivisions; i++)
8033                     {
8034                     if (activeParts[i] == YES || nApplied == 0)
8035                         {
8036                         strcat(modelParams[i].treeAgePr.name, ")");
8037                         MrBayesPrint ("%s   Setting Treeagepr to %s\n", spacer, modelParams[i].treeAgePr.name);
8038 
8039                         if (modelParams[i].treeAgePr.prior == fixed)
8040                             {
8041                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbFix;
8042                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioFix;
8043                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
8044                             modelParams[i].treeAgePr.max           = modelParams[i].treeAgePr.priorParams[0];
8045                             }
8046                         else if (modelParams[i].treeAgePr.prior == uniform)
8047                             {
8048                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbUniform;
8049                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioUniform;
8050                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
8051                             modelParams[i].treeAgePr.max           = modelParams[i].treeAgePr.priorParams[1];
8052                             }
8053                         else if (modelParams[i].treeAgePr.prior == offsetExponential)
8054                             {
8055                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbOffsetExponential_Param_Offset_Mean;
8056                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioOffsetExponential_Param_Offset_Mean;
8057                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
8058                             modelParams[i].treeAgePr.max           = POS_INFINITY;
8059                             }
8060                         else if (modelParams[i].treeAgePr.prior == truncatedNormal)
8061                             {
8062                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbTruncatedNormal_Param_Trunc_Mean_Sd;
8063                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioTruncatedNormal_Param_Trunc_Mean_Sd;
8064                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
8065                             modelParams[i].treeAgePr.max           = POS_INFINITY;
8066                             }
8067                         else if (modelParams[i].treeAgePr.prior == logNormal)
8068                             {
8069                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbLognormal_Param_Mean_Sd;
8070                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioLognormal_Param_Mean_Sd;
8071                             modelParams[i].treeAgePr.min           = 0.0;
8072                             modelParams[i].treeAgePr.max           = POS_INFINITY;
8073                             }
8074                         else if (modelParams[i].treeAgePr.prior == offsetLogNormal)
8075                             {
8076                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbOffsetLognormal_Param_Offset_Mean_Sd;
8077                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioOffsetLognormal_Param_Offset_Mean_Sd;
8078                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
8079                             modelParams[i].treeAgePr.max           = POS_INFINITY;
8080                             }
8081                         else if (modelParams[i].treeAgePr.prior == standardGamma)
8082                             {
8083                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbGamma_Param_Mean_Sd;
8084                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioGamma_Param_Mean_Sd;
8085                             modelParams[i].treeAgePr.min           = 0.0;
8086                             modelParams[i].treeAgePr.max           = POS_INFINITY;
8087                             }
8088                         else if (modelParams[i].treeAgePr.prior == offsetGamma)
8089                             {
8090                             modelParams[i].treeAgePr.LnPriorProb   = &LnPriorProbOffsetGamma_Param_Offset_Mean_Sd;
8091                             modelParams[i].treeAgePr.LnPriorRatio  = &LnProbRatioOffsetGamma_Param_Offset_Mean_Sd;
8092                             modelParams[i].treeAgePr.min           = modelParams[i].treeAgePr.priorParams[0];
8093                             modelParams[i].treeAgePr.max           = POS_INFINITY;
8094                             }
8095                         }
8096                     }
8097                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8098                 }
8099             else
8100                 return (ERROR);
8101             }
8102         /* set Clockratepr (clockRatePr) ****************************************************/
8103         else if (!strcmp(parmName, "Clockratepr"))
8104             {
8105             if (expecting == Expecting(EQUALSIGN))
8106                 {
8107                 foundDash = NO;
8108                 expecting = Expecting(ALPHA);
8109                 }
8110             else if (expecting == Expecting(ALPHA))
8111                 {
8112                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8113                     {
8114                     nApplied = NumActiveParts ();
8115                     for (i=0; i<numCurrentDivisions; i++)
8116                         {
8117                         if (activeParts[i] == YES || nApplied == 0)
8118                             strcpy(modelParams[i].clockRatePr, tempStr);
8119                         }
8120                     }
8121                 else
8122                     {
8123                     MrBayesPrint ("%s   Invalid Clockratepr argument\n", spacer);
8124                     return (ERROR);
8125                     }
8126                 expecting  = Expecting(LEFTPAR);
8127                 for (i=0; i<numCurrentDivisions; i++)
8128                     numVars[i] = 0;
8129                 }
8130             else if (expecting == Expecting(LEFTPAR))
8131                 {
8132                 expecting  = Expecting(NUMBER);
8133                 expecting |= Expecting(DASH);   /* negative numbers possible */
8134                 }
8135             else if (expecting == Expecting(DASH))
8136                 {
8137                 foundDash = YES;
8138                 expecting = Expecting(NUMBER);
8139                 }
8140             else if (expecting == Expecting(NUMBER))
8141                 {
8142                 sscanf (tkn, "%lf", &tempD);
8143                 if (foundDash == YES)
8144                     {
8145                     foundDash = NO;
8146                     tempD *= -1.0;
8147                     }
8148                 nApplied = NumActiveParts ();
8149                 for (i=0; i<numCurrentDivisions; i++)
8150                     {
8151                     if (activeParts[i] == YES || nApplied == 0)
8152                         {
8153                         if (!strcmp(modelParams[i].clockRatePr,"Normal"))
8154                             {
8155                             if (tempD <= 0.0)
8156                                 {
8157                                 if (numVars[i] == 0)
8158                                     MrBayesPrint ("%s   Mean of the normal must be positive\n", spacer);
8159                                 else if (numVars[i] == 1)
8160                                     MrBayesPrint ("%s   Standard deviation of the normal must be positive\n", spacer);
8161                                 return (ERROR);
8162                                 }
8163                             modelParams[i].clockRateNormal[numVars[i]] = tempD;
8164                             numVars[i]++;
8165                             if (numVars[i] == 1)
8166                                 expecting  = Expecting(COMMA);
8167                             else
8168                                 {
8169                                 if (nApplied == 0 || numCurrentDivisions == 1)
8170                                     MrBayesPrint ("%s   Setting Clockratepr to Normal(%1.6lf,%1.6lf)\n", spacer, modelParams[i].clockRateNormal[0], modelParams[i].clockRateNormal[1]);
8171                                 else
8172                                     MrBayesPrint ("%s   Setting Clockratepr to Normal(%1.6lf,%1.6lf) for partition %d\n", spacer, modelParams[i].clockRateNormal[0], modelParams[i].clockRateNormal[1], i+1);
8173                                 expecting  = Expecting(RIGHTPAR);
8174                                 }
8175                             }
8176                         else if (!strcmp(modelParams[i].clockRatePr,"Lognormal"))
8177                             {
8178                             modelParams[i].clockRateLognormal[numVars[i]] = tempD;
8179                             numVars[i]++;
8180                             if (numVars[i] == 1)
8181                                 expecting  = Expecting(COMMA);
8182                             else
8183                                 {
8184                                 if (nApplied == 0 || numCurrentDivisions == 1)
8185                                     MrBayesPrint ("%s   Setting Clockratepr to Lognormal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].clockRateLognormal[0], modelParams[i].clockRateLognormal[1]);
8186                                 else
8187                                     MrBayesPrint ("%s   Setting Clockratepr to Lognormal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].clockRateLognormal[0], modelParams[i].clockRateLognormal[1], i+1);
8188                                 expecting  = Expecting(RIGHTPAR);
8189                                 }
8190                             }
8191                         else if (!strcmp(modelParams[i].clockRatePr,"Exponential"))
8192                             {
8193                             if (tempD <= 0.0)
8194                                 {
8195                                 MrBayesPrint ("%s   Rate of the exponential must be positive\n", spacer);
8196                                 return (ERROR);
8197                                 }
8198                             modelParams[i].clockRateExp = tempD;
8199                             numVars[i]++;
8200                             if (nApplied == 0 || numCurrentDivisions == 1)
8201                                 MrBayesPrint ("%s   Setting Clockratepr to Exponential(%1.2lf)\n", spacer, modelParams[i].clockRateExp);
8202                             else
8203                                 MrBayesPrint ("%s   Setting Clockratepr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].clockRateExp, i+1);
8204                             expecting  = Expecting(RIGHTPAR);
8205                             }
8206                         else if (!strcmp(modelParams[i].clockRatePr,"Gamma"))
8207                             {
8208                             if (tempD <= 0.0)
8209                                 {
8210                                 if (numVars[i] == 0)
8211                                     MrBayesPrint ("%s   Shape of the gamma must be positive\n", spacer);
8212                                 else if (numVars[i] == 1)
8213                                     MrBayesPrint ("%s   Rate (inverse scale) of the gamma must be positive\n", spacer);
8214                                 return (ERROR);
8215                                 }
8216                             modelParams[i].clockRateGamma[numVars[i]] = tempD;
8217                             numVars[i]++;
8218                             if (numVars[i] == 1)
8219                                 expecting  = Expecting(COMMA);
8220                             else
8221                                 {
8222                                 if (nApplied == 0 || numCurrentDivisions == 1)
8223                                     MrBayesPrint ("%s   Setting Clockratepr to Gamma(%1.2lf,%1.2lf)\n", spacer, modelParams[i].clockRateGamma[0], modelParams[i].clockRateGamma[1]);
8224                                 else
8225                                     MrBayesPrint ("%s   Setting Clockratepr to Gamma(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].clockRateGamma[0], modelParams[i].clockRateGamma[1], i+1);
8226                                 expecting  = Expecting(RIGHTPAR);
8227                                 }
8228                             }
8229                         else if (!strcmp(modelParams[i].clockRatePr,"Fixed"))
8230                             {
8231                             if (tempD <= 0.0)
8232                                 {
8233                                 MrBayesPrint ("%s   Fixed clock rate must be positive\n", spacer);
8234                                 return (ERROR);
8235                                 }
8236                             modelParams[i].clockRateFix = tempD;
8237                             numVars[i]++;
8238                             if (nApplied == 0 || numCurrentDivisions == 1)
8239                                 MrBayesPrint ("%s   Setting Clockratepr to Fixed(%1.6lf)\n", spacer, modelParams[i].clockRateFix);
8240                             else
8241                                 MrBayesPrint ("%s   Setting Clockratepr to Fixed(%1.6lf) for partition %d\n", spacer, modelParams[i].clockRateFix, i+1);
8242                             for (k=0; k<numGlobalChains; k++)
8243                                 {
8244                                 if (UpdateClockRate(tempD, k) == ERROR)
8245                                     return (ERROR);
8246                                 }
8247                             expecting  = Expecting(RIGHTPAR);
8248                             }
8249                         }
8250                     }
8251                 }
8252             else if (expecting == Expecting(COMMA))
8253                 {
8254                 expecting  = Expecting(NUMBER);
8255                 }
8256             else if (expecting == Expecting(RIGHTPAR))
8257                 {
8258                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8259                 }
8260             else
8261                 return (ERROR);
8262             }
8263         /* set Popsizepr (popSizePr) **************************************************************/
8264         else if (!strcmp(parmName, "Popsizepr"))
8265             {
8266             if (expecting == Expecting(EQUALSIGN))
8267                 expecting = Expecting(ALPHA);
8268             else if (expecting == Expecting(ALPHA))
8269                 {
8270                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8271                     {
8272                     nApplied = NumActiveParts ();
8273                     for (i=0; i<numCurrentDivisions; i++)
8274                         {
8275                         if (activeParts[i] == YES || nApplied == 0)
8276                             strcpy(modelParams[i].popSizePr, tempStr);
8277                         }
8278                     }
8279                 else
8280                     {
8281                     MrBayesPrint ("%s   Invalid Popsizepr argument\n", spacer);
8282                     return (ERROR);
8283                     }
8284                 expecting  = Expecting(LEFTPAR);
8285                 for (i=0; i<numCurrentDivisions; i++)
8286                     numVars[i] = 0;
8287                 }
8288             else if (expecting == Expecting(LEFTPAR))
8289                 {
8290                 expecting  = Expecting(NUMBER);
8291                 }
8292             else if (expecting == Expecting(NUMBER))
8293                 {
8294                 nApplied = NumActiveParts ();
8295                 for (i=0; i<numCurrentDivisions; i++)
8296                     {
8297                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
8298                         {
8299                         if (!strcmp(modelParams[i].popSizePr,"Uniform"))
8300                             {
8301                             sscanf (tkn, "%lf", &tempD);
8302                             modelParams[i].popSizeUni[numVars[i]++] = tempD;
8303                             if (numVars[i] == 1)
8304                                 {
8305                                 if (tempD <= 0.0)
8306                                     {
8307                                     MrBayesPrint ("%s   Lower value for Uniform must be a positive number\n", spacer);
8308                                     return (ERROR);
8309                                     }
8310                                 expecting  = Expecting(COMMA);
8311                                 }
8312                             else
8313                                 {
8314                                 if (modelParams[i].popSizeUni[0] >= modelParams[i].popSizeUni[1])
8315                                     {
8316                                     MrBayesPrint ("%s   Lower value for Uniform should be greater than upper value\n", spacer);
8317                                     return (ERROR);
8318                                     }
8319                                 if (nApplied == 0 && numCurrentDivisions == 1)
8320                                     MrBayesPrint ("%s   Setting Popsizepr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeUni[0], modelParams[i].popSizeUni[1]);
8321                                 else
8322                                     MrBayesPrint ("%s   Setting Popsizepr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeUni[0], modelParams[i].popSizeUni[1], i+1);
8323                                 expecting  = Expecting(RIGHTPAR);
8324                                 }
8325                             }
8326                         else if (!strcmp(modelParams[i].popSizePr,"Lognormal"))
8327                             {
8328                             sscanf (tkn, "%lf", &tempD);
8329                             modelParams[i].popSizeLognormal[numVars[i]++] = tempD;
8330                             if (numVars[i] == 1)
8331                                 {
8332                                 expecting  = Expecting(COMMA);
8333                                 }
8334                             else
8335                                 {
8336                                 if (modelParams[i].popSizeLognormal[1] <= 0.0)
8337                                     {
8338                                     MrBayesPrint ("%s   Standard deviation of Lognormal must be a positive number\n", spacer);
8339                                     return (ERROR);
8340                                     }
8341                                 if (nApplied == 0 && numCurrentDivisions == 1)
8342                                     MrBayesPrint ("%s   Setting Popsizepr to Lognormal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeLognormal[0], modelParams[i].popSizeLognormal[1]);
8343                                 else
8344                                     MrBayesPrint ("%s   Setting Popsizepr to Lognormal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeLognormal[0], modelParams[i].popSizeLognormal[1], i+1);
8345                                 expecting  = Expecting(RIGHTPAR);
8346                                 }
8347                             }
8348                         else if (!strcmp(modelParams[i].popSizePr,"Normal"))
8349                             {
8350                             sscanf (tkn, "%lf", &tempD);
8351                             modelParams[i].popSizeNormal[numVars[i]++] = tempD;
8352                             if (numVars[i] == 1)
8353                                 {
8354                                 if (modelParams[i].popSizeNormal[0] <= 0.0)
8355                                     {
8356                                     MrBayesPrint ("%s   Mean of Truncated Normal must be a positive number\n", spacer);
8357                                     return (ERROR);
8358                                     }
8359                                 expecting  = Expecting(COMMA);
8360                                 }
8361                             else
8362                                 {
8363                                 if (modelParams[i].popSizeNormal[1] <= 0.0)
8364                                     {
8365                                     MrBayesPrint ("%s   Standard deviation of Truncated Normal must be a positive number\n", spacer);
8366                                     return (ERROR);
8367                                     }
8368                                 if (nApplied == 0 && numCurrentDivisions == 1)
8369                                     MrBayesPrint ("%s   Setting Popsizepr to Truncated Normal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeNormal[0], modelParams[i].popSizeNormal[1]);
8370                                 else
8371                                     MrBayesPrint ("%s   Setting Popsizepr to Truncated Normal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeNormal[0], modelParams[i].popSizeNormal[1], i+1);
8372                                 expecting  = Expecting(RIGHTPAR);
8373                                 }
8374                             }
8375                         else if (!strcmp(modelParams[i].popSizePr,"Gamma"))
8376                             {
8377                             sscanf (tkn, "%lf", &tempD);
8378                             modelParams[i].popSizeGamma[numVars[i]++] = tempD;
8379                             if (numVars[i] == 1)
8380                                 {
8381                                 if (modelParams[i].popSizeGamma[0] <= 0.0)
8382                                     {
8383                                     MrBayesPrint ("%s   Shape (alpha) of Gamma must be a positive number\n", spacer);
8384                                     return (ERROR);
8385                                     }
8386                                 expecting  = Expecting(COMMA);
8387                                 }
8388                             else
8389                                 {
8390                                 if (modelParams[i].popSizeGamma[1] <= 0.0)
8391                                     {
8392                                     MrBayesPrint ("%s   Rate (beta) of Gamma must be a positive number\n", spacer);
8393                                     return (ERROR);
8394                                     }
8395                                 if (nApplied == 0 && numCurrentDivisions == 1)
8396                                     MrBayesPrint ("%s   Setting Popsizepr to Gamma(%1.2lf,%1.2lf)\n", spacer, modelParams[i].popSizeGamma[0], modelParams[i].popSizeGamma[1]);
8397                                 else
8398                                     MrBayesPrint ("%s   Setting Popsizepr to Gamma(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].popSizeGamma[0], modelParams[i].popSizeGamma[1], i+1);
8399                                 expecting  = Expecting(RIGHTPAR);
8400                                 }
8401                             }
8402                         else if (!strcmp(modelParams[i].popSizePr,"Fixed"))
8403                             {
8404                             sscanf (tkn, "%lf", &tempD);
8405                             if (AreDoublesEqual(tempD, 0.0, ETA)==YES)
8406                                 {
8407                                 MrBayesPrint ("%s   Popsizepr cannot be fixed to 0.0\n", spacer);
8408                                 return (ERROR);
8409                                 }
8410                             modelParams[i].popSizeFix = tempD;
8411                             if (nApplied == 0 && numCurrentDivisions == 1)
8412                                 MrBayesPrint ("%s   Setting Popsizepr to Fixed(%1.5lf)\n", spacer, modelParams[i].popSizeFix);
8413                             else
8414                                 MrBayesPrint ("%s   Setting Popsizepr to Fixed(%1.5lf) for partition %d\n", spacer, modelParams[i].popSizeFix, i+1);
8415                             expecting  = Expecting(RIGHTPAR);
8416                             }
8417                         }
8418                     }
8419                 }
8420             else if (expecting == Expecting(COMMA))
8421                 {
8422                 expecting  = Expecting(NUMBER);
8423                 }
8424             else if (expecting == Expecting(RIGHTPAR))
8425                 {
8426                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8427                 }
8428             else
8429                 return (ERROR);
8430             }
8431         /* set Popvarpr (popVarPr) **************************************************************/
8432         else if (!strcmp(parmName, "Popvarpr"))
8433             {
8434             if (expecting == Expecting(EQUALSIGN))
8435                 expecting = Expecting(ALPHA);
8436             else if (expecting == Expecting(ALPHA))
8437                 {
8438                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8439                     {
8440                     nApplied = NumActiveParts ();
8441                     for (i=0; i<numCurrentDivisions; i++)
8442                         {
8443                         if (activeParts[i] == YES || nApplied == 0)
8444                             {
8445                             strcpy(modelParams[i].popVarPr, tempStr);
8446 
8447                             if (nApplied == 0 && numCurrentDivisions == 1)
8448                                 MrBayesPrint ("%s   Setting Popvarpr to %s\n", spacer, modelParams[i].popVarPr);
8449                             else
8450                                 MrBayesPrint ("%s   Setting Popvarpr to %s for partition %d\n", spacer, modelParams[i].popVarPr, i+1);
8451                             }
8452                         }
8453                     expecting  = Expecting(PARAMETER) | Expecting(SEMICOLON);
8454                     }
8455                 else
8456                     {
8457                     MrBayesPrint ("%s   Invalid Popvarpr argument\n", spacer);
8458                     return (ERROR);
8459                     }
8460                 }
8461             else
8462                 return (ERROR);
8463             }
8464         /* set Compound Poisson Process rate prior (cppRatePr) *********************************************************/
8465         else if (!strcmp(parmName, "Cppratepr"))
8466             {
8467             if (expecting == Expecting(EQUALSIGN))
8468                 expecting = Expecting(ALPHA);
8469             else if (expecting == Expecting(ALPHA))
8470                 {
8471                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8472                     {
8473                     nApplied = NumActiveParts ();
8474                     for (i=0; i<numCurrentDivisions; i++)
8475                         {
8476                         if (activeParts[i] == YES || nApplied == 0)
8477                             strcpy(modelParams[i].cppRatePr, tempStr);
8478                         }
8479                     }
8480                 else
8481                     {
8482                     MrBayesPrint ("%s   Invalid Cppratepr argument\n", spacer);
8483                     return (ERROR);
8484                     }
8485                 expecting  = Expecting(LEFTPAR);
8486                 for (i=0; i<numCurrentDivisions; i++)
8487                     numVars[i] = 0;
8488                 }
8489             else if (expecting == Expecting(LEFTPAR))
8490                 {
8491                 expecting  = Expecting(NUMBER);
8492                 }
8493             else if (expecting == Expecting(NUMBER))
8494                 {
8495                 nApplied = NumActiveParts ();
8496                 for (i=0; i<numCurrentDivisions; i++)
8497                     {
8498                     if (activeParts[i] == YES || nApplied == 0)
8499                         {
8500                         if (!strcmp(modelParams[i].cppRatePr,"Exponential"))
8501                             {
8502                             sscanf (tkn, "%lf", &tempD);
8503                             modelParams[i].cppRateExp = tempD;
8504                             if (nApplied == 0 && numCurrentDivisions == 1)
8505                                 MrBayesPrint ("%s   Setting Cppratepr to Exponential(%1.2lf)\n", spacer, modelParams[i].cppRateExp);
8506                             else
8507                                 MrBayesPrint ("%s   Setting Cppratepr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].cppRateExp, i+1);
8508                             expecting  = Expecting(RIGHTPAR);
8509                             }
8510                         else if (!strcmp(modelParams[i].cppRatePr,"Fixed"))
8511                             {
8512                             sscanf (tkn, "%lf", &tempD);
8513                             if (tempD < CPPLAMBDA_MIN || tempD > CPPLAMBDA_MAX)
8514                                 {
8515                                 MrBayesPrint ("%s   CPP rate must be in the range %f - %f\n", spacer, CPPLAMBDA_MIN, CPPLAMBDA_MAX);
8516                                 return (ERROR);
8517                                 }
8518                             modelParams[i].cppRateFix = tempD;
8519                             if (nApplied == 0 && numCurrentDivisions == 1)
8520                                 MrBayesPrint ("%s   Setting Cppratepr to Fixed(%1.2lf)\n", spacer, modelParams[i].cppRateFix);
8521                             else
8522                                 MrBayesPrint ("%s   Setting Cppratepr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].cppRateFix, i+1);
8523                             expecting  = Expecting(RIGHTPAR);
8524                             }
8525                         }
8526                     }
8527                 }
8528             else if (expecting == Expecting(COMMA))
8529                 {
8530                 expecting  = Expecting(NUMBER);
8531                 }
8532             else if (expecting == Expecting(RIGHTPAR))
8533                 {
8534                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8535                 }
8536             else
8537                 return (ERROR);
8538             }
8539         /* set Compound Poisson Process rate multiplier standard deviation (log scale) ***********************/
8540         else if (!strcmp(parmName, "Cppmultdevpr"))
8541             {
8542             if (expecting == Expecting(EQUALSIGN))
8543                 expecting = Expecting(ALPHA);
8544             else if (expecting == Expecting(ALPHA))
8545                 {
8546                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8547                     {
8548                     nApplied = NumActiveParts ();
8549                     for (i=0; i<numCurrentDivisions; i++)
8550                         {
8551                         if (activeParts[i] == YES || nApplied == 0)
8552                             strcpy(modelParams[i].cppMultDevPr, tempStr);
8553                         }
8554                     }
8555                 else
8556                     {
8557                     MrBayesPrint ("%s   Invalid Cppmultdevpr argument\n", spacer);
8558                     return (ERROR);
8559                     }
8560                 expecting  = Expecting(LEFTPAR);
8561                 for (i=0; i<numCurrentDivisions; i++)
8562                     numVars[i] = 0;
8563                 }
8564             else if (expecting == Expecting(LEFTPAR))
8565                 {
8566                 expecting  = Expecting(NUMBER);
8567                 }
8568             else if (expecting == Expecting(NUMBER))
8569                 {
8570                 nApplied = NumActiveParts ();
8571                 for (i=0; i<numCurrentDivisions; i++)
8572                     {
8573                     if (activeParts[i] == YES || nApplied == 0)
8574                         {
8575                         if (!strcmp(modelParams[i].cppMultDevPr,"Fixed"))
8576                             {
8577                             sscanf (tkn, "%lf", &tempD);
8578                             if (tempD < POSREAL_MIN || tempD > POSREAL_MAX)
8579                                 {
8580                                 MrBayesPrint ("%s   The log standard deviation of rate multipliers must be in the range %f - %f\n", spacer, POSREAL_MIN, POSREAL_MAX);
8581                                 return (ERROR);
8582                                 }
8583                             modelParams[i].cppMultDevFix = tempD;
8584                             if (nApplied == 0 && numCurrentDivisions == 1)
8585                                 MrBayesPrint ("%s   Setting Cppmultdevpr to Fixed(%1.2lf)\n", spacer, modelParams[i].cppMultDevFix);
8586                             else
8587                                 MrBayesPrint ("%s   Setting Cppmultdevpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].cppMultDevFix, i+1);
8588                             expecting  = Expecting(RIGHTPAR);
8589                             }
8590                         }
8591                     }
8592                 }
8593             else if (expecting == Expecting(COMMA))
8594                 {
8595                 expecting  = Expecting(NUMBER);
8596                 }
8597             else if (expecting == Expecting(RIGHTPAR))
8598                 {
8599                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8600                 }
8601             else
8602                 return (ERROR);
8603             }
8604         /* set prior for variance of lognormal of autocorrelated rates (tk02varPr) ***********************/
8605         else if (!strcmp(parmName, "TK02varpr") || !strcmp(parmName,"Bmvarpr"))
8606             {
8607             if (expecting == Expecting(EQUALSIGN))
8608                 expecting = Expecting(ALPHA);
8609             else if (expecting == Expecting(ALPHA))
8610                 {
8611                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8612                     {
8613                     nApplied = NumActiveParts ();
8614                     for (i=0; i<numCurrentDivisions; i++)
8615                         {
8616                         if (activeParts[i] == YES || nApplied == 0)
8617                             strcpy(modelParams[i].tk02varPr, tempStr);
8618                         }
8619                     }
8620                 else
8621                     {
8622                     MrBayesPrint ("%s   Invalid TK02varpr argument\n", spacer);
8623                     return (ERROR);
8624                     }
8625                 expecting  = Expecting(LEFTPAR);
8626                 for (i=0; i<numCurrentDivisions; i++)
8627                     numVars[i] = 0;
8628                 }
8629             else if (expecting == Expecting(LEFTPAR))
8630                 {
8631                 expecting  = Expecting(NUMBER);
8632                 }
8633             else if (expecting == Expecting(NUMBER))
8634                 {
8635                 nApplied = NumActiveParts ();
8636                 for (i=0; i<numCurrentDivisions; i++)
8637                     {
8638                     if (activeParts[i] == YES || nApplied == 0)
8639                         {
8640                         if (!strcmp(modelParams[i].tk02varPr,"Uniform"))
8641                             {
8642                             sscanf (tkn, "%lf", &tempD);
8643                             modelParams[i].tk02varUni[numVars[i]++] = tempD;
8644                             if (numVars[i] == 1)
8645                                 expecting  = Expecting(COMMA);
8646                             else
8647                                 {
8648                                 if (modelParams[i].tk02varUni[0] >= modelParams[i].tk02varUni[1])
8649                                     {
8650                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8651                                     return (ERROR);
8652                                     }
8653                                 if (nApplied == 0 && numCurrentDivisions == 1)
8654                                     MrBayesPrint ("%s   Setting TK02varpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].tk02varUni[0], modelParams[i].tk02varUni[1]);
8655                                 else
8656                                     MrBayesPrint ("%s   Setting TK02varpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].tk02varUni[0], modelParams[i].tk02varUni[1], i+1);
8657                                 expecting  = Expecting(RIGHTPAR);
8658                                 }
8659                             }
8660                         else if (!strcmp(modelParams[i].tk02varPr,"Exponential"))
8661                             {
8662                             sscanf (tkn, "%lf", &tempD);
8663                             modelParams[i].tk02varExp = tempD;
8664                             if (nApplied == 0 && numCurrentDivisions == 1)
8665                                 MrBayesPrint ("%s   Setting TK02varpr to Exponential(%1.2lf)\n", spacer, modelParams[i].tk02varExp);
8666                             else
8667                                 MrBayesPrint ("%s   Setting TK02varpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].tk02varExp, i+1);
8668                             expecting  = Expecting(RIGHTPAR);
8669                             }
8670                         else if (!strcmp(modelParams[i].tk02varPr,"Fixed"))
8671                             {
8672                             sscanf (tkn, "%lf", &tempD);
8673                             if (tempD < TK02VAR_MIN || tempD > TK02VAR_MAX)
8674                                 {
8675                                 MrBayesPrint ("%s   Ratevar (nu) must be in the range %f - %f\n", spacer, TK02VAR_MIN, TK02VAR_MAX);
8676                                 return (ERROR);
8677                                 }
8678                             modelParams[i].tk02varFix = tempD;
8679                             if (nApplied == 0 && numCurrentDivisions == 1)
8680                                 MrBayesPrint ("%s   Setting TK02varpr to Fixed(%1.2lf)\n", spacer, modelParams[i].tk02varFix);
8681                             else
8682                                 MrBayesPrint ("%s   Setting TK02varpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].tk02varFix, i+1);
8683                             expecting  = Expecting(RIGHTPAR);
8684                             }
8685                         }
8686                     }
8687                 }
8688             else if (expecting == Expecting(COMMA))
8689                 {
8690                 expecting  = Expecting(NUMBER);
8691                 }
8692             else if (expecting == Expecting(RIGHTPAR))
8693                 {
8694                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8695                 }
8696             else
8697                 return (ERROR);
8698             }
8699         /* set prior for shape of independent branch rate gamma distribution (igrvarPr) ***********************/
8700         else if (!strcmp(parmName, "Igrvarpr") || !strcmp(parmName, "Ibrvarpr"))
8701             {
8702             if (expecting == Expecting(EQUALSIGN))
8703                 expecting = Expecting(ALPHA);
8704             else if (expecting == Expecting(ALPHA))
8705                 {
8706                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8707                     {
8708                     nApplied = NumActiveParts ();
8709                     for (i=0; i<numCurrentDivisions; i++)
8710                         {
8711                         if (activeParts[i] == YES || nApplied == 0)
8712                             strcpy(modelParams[i].igrvarPr, tempStr);
8713                         }
8714                     }
8715                 else
8716                     {
8717                     MrBayesPrint ("%s   Invalid Igrvarpr argument\n", spacer);
8718                     return (ERROR);
8719                     }
8720                 expecting  = Expecting(LEFTPAR);
8721                 for (i=0; i<numCurrentDivisions; i++)
8722                     numVars[i] = 0;
8723                 }
8724             else if (expecting == Expecting(LEFTPAR))
8725                 {
8726                 expecting  = Expecting(NUMBER);
8727                 }
8728             else if (expecting == Expecting(NUMBER))
8729                 {
8730                 nApplied = NumActiveParts ();
8731                 for (i=0; i<numCurrentDivisions; i++)
8732                     {
8733                     if (activeParts[i] == YES || nApplied == 0)
8734                         {
8735                         if (!strcmp(modelParams[i].igrvarPr,"Uniform"))
8736                             {
8737                             sscanf (tkn, "%lf", &tempD);
8738                             modelParams[i].igrvarUni[numVars[i]++] = tempD;
8739                             if (numVars[i] == 1)
8740                                 expecting  = Expecting(COMMA);
8741                             else
8742                                 {
8743                                 if (modelParams[i].igrvarUni[0] >= modelParams[i].igrvarUni[1])
8744                                     {
8745                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8746                                     return (ERROR);
8747                                     }
8748                                 if (nApplied == 0 && numCurrentDivisions == 1)
8749                                     MrBayesPrint ("%s   Setting Igrvarpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].igrvarUni[0], modelParams[i].igrvarUni[1]);
8750                                 else
8751                                     MrBayesPrint ("%s   Setting Igrvarpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].igrvarUni[0], modelParams[i].igrvarUni[1], i+1);
8752                                 expecting  = Expecting(RIGHTPAR);
8753                                 }
8754                             }
8755                         else if (!strcmp(modelParams[i].igrvarPr,"Exponential"))
8756                             {
8757                             sscanf (tkn, "%lf", &tempD);
8758                             modelParams[i].igrvarExp = tempD;
8759                             if (nApplied == 0 && numCurrentDivisions == 1)
8760                                 MrBayesPrint ("%s   Setting Igrvarpr to Exponential(%1.2lf)\n", spacer, modelParams[i].igrvarExp);
8761                             else
8762                                 MrBayesPrint ("%s   Setting Igrvarpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].igrvarExp, i+1);
8763                             expecting  = Expecting(RIGHTPAR);
8764                             }
8765                         else if (!strcmp(modelParams[i].igrvarPr,"Fixed"))
8766                             {
8767                             sscanf (tkn, "%lf", &tempD);
8768                             if (tempD < IGRVAR_MIN || tempD > IGRVAR_MAX)
8769                                 {
8770                                 MrBayesPrint ("%s   Igrvar must be in the range %f - %f\n", spacer, IGRVAR_MIN, IGRVAR_MAX);
8771                                 return (ERROR);
8772                                 }
8773                             modelParams[i].igrvarFix = tempD;
8774                             if (nApplied == 0 && numCurrentDivisions == 1)
8775                                 MrBayesPrint ("%s   Setting Igrvarpr to Fixed(%1.2lf)\n", spacer, modelParams[i].igrvarFix);
8776                             else
8777                                 MrBayesPrint ("%s   Setting Igrvarpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].igrvarFix, i+1);
8778                             expecting  = Expecting(RIGHTPAR);
8779                             }
8780                         }
8781                     }
8782                 }
8783             else if (expecting == Expecting(COMMA))
8784                 {
8785                 expecting  = Expecting(NUMBER);
8786                 }
8787             else if (expecting == Expecting(RIGHTPAR))
8788                 {
8789                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8790                 }
8791             else
8792                 return (ERROR);
8793             }
8794         /* set prior for variance of mixed relaxed clock model (mixedvarPr) ***********************/
8795         else if (!strcmp(parmName, "Mixedvarpr"))
8796             {
8797             if (expecting == Expecting(EQUALSIGN))
8798                 expecting = Expecting(ALPHA);
8799             else if (expecting == Expecting(ALPHA))
8800                 {
8801                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8802                     {
8803                     nApplied = NumActiveParts ();
8804                     for (i=0; i<numCurrentDivisions; i++)
8805                         {
8806                         if (activeParts[i] == YES || nApplied == 0)
8807                             strcpy(modelParams[i].mixedvarPr, tempStr);
8808                         }
8809                     }
8810                 else
8811                     {
8812                     MrBayesPrint ("%s   Invalid Mixedvarpr argument\n", spacer);
8813                     return (ERROR);
8814                     }
8815                 expecting  = Expecting(LEFTPAR);
8816                 for (i=0; i<numCurrentDivisions; i++)
8817                     numVars[i] = 0;
8818                 }
8819             else if (expecting == Expecting(LEFTPAR))
8820                 {
8821                 expecting  = Expecting(NUMBER);
8822                 }
8823             else if (expecting == Expecting(NUMBER))
8824                 {
8825                 nApplied = NumActiveParts ();
8826                 for (i=0; i<numCurrentDivisions; i++)
8827                     {
8828                     if (activeParts[i] == YES || nApplied == 0)
8829                         {
8830                         if (!strcmp(modelParams[i].mixedvarPr,"Uniform"))
8831                             {
8832                             sscanf (tkn, "%lf", &tempD);
8833                             modelParams[i].mixedvarUni[numVars[i]++] = tempD;
8834                             if (numVars[i] == 1)
8835                                 expecting  = Expecting(COMMA);
8836                             else
8837                                 {
8838                                 if (modelParams[i].mixedvarUni[0] >= modelParams[i].mixedvarUni[1])
8839                                     {
8840                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8841                                     return (ERROR);
8842                                     }
8843                                 if (nApplied == 0 && numCurrentDivisions == 1)
8844                                     MrBayesPrint ("%s   Setting Mixedvarpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].mixedvarUni[0], modelParams[i].mixedvarUni[1]);
8845                                 else
8846                                     MrBayesPrint ("%s   Setting Mixedvarpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].mixedvarUni[0], modelParams[i].mixedvarUni[1], i+1);
8847                                 expecting  = Expecting(RIGHTPAR);
8848                                 }
8849                             }
8850                         else if (!strcmp(modelParams[i].mixedvarPr,"Exponential"))
8851                             {
8852                             sscanf (tkn, "%lf", &tempD);
8853                             modelParams[i].mixedvarExp = tempD;
8854                             if (nApplied == 0 && numCurrentDivisions == 1)
8855                                 MrBayesPrint ("%s   Setting Mixedvarpr to Exponential(%1.2lf)\n", spacer, modelParams[i].mixedvarExp);
8856                             else
8857                                 MrBayesPrint ("%s   Setting Mixedvarpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].mixedvarExp, i+1);
8858                             expecting  = Expecting(RIGHTPAR);
8859                             }
8860                         else if (!strcmp(modelParams[i].mixedvarPr,"Fixed"))
8861                             {
8862                             sscanf (tkn, "%lf", &tempD);
8863                             if (tempD < IGRVAR_MIN || tempD > IGRVAR_MAX || tempD < TK02VAR_MIN || tempD > TK02VAR_MAX)
8864                                 {
8865                                 MrBayesPrint ("%s   Mixedvar must be in the range %f - %f\n", spacer, IGRVAR_MIN, IGRVAR_MAX);
8866                                 return (ERROR);
8867                                 }
8868                             modelParams[i].mixedvarFix = tempD;
8869                             if (nApplied == 0 && numCurrentDivisions == 1)
8870                                 MrBayesPrint ("%s   Setting Mixedvarpr to Fixed(%1.2lf)\n", spacer, modelParams[i].mixedvarFix);
8871                             else
8872                                 MrBayesPrint ("%s   Setting Mixedvarpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].mixedvarFix, i+1);
8873                             expecting  = Expecting(RIGHTPAR);
8874                             }
8875                         }
8876                     }
8877                 }
8878             else if (expecting == Expecting(COMMA))
8879                 {
8880                 expecting  = Expecting(NUMBER);
8881                 }
8882             else if (expecting == Expecting(RIGHTPAR))
8883                 {
8884                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
8885                 }
8886             else
8887                 return (ERROR);
8888             }
8889         /* set Growthpr (growthPr) **************************************************************/
8890         else if (!strcmp(parmName, "Growthpr"))
8891             {
8892             if (expecting == Expecting(EQUALSIGN))
8893                 {
8894                 expecting = Expecting(ALPHA);
8895                 isNegative = NO;
8896                 }
8897             else if (expecting == Expecting(ALPHA))
8898                 {
8899                 isNegative = NO;
8900                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
8901                     {
8902                     nApplied = NumActiveParts ();
8903                     for (i=0; i<numCurrentDivisions; i++)
8904                         {
8905                         if (activeParts[i] == YES || nApplied == 0)
8906                             strcpy(modelParams[i].growthPr, tempStr);
8907                         }
8908                     }
8909                 else
8910                     {
8911                     MrBayesPrint ("%s   Invalid Growthpr argument\n", spacer);
8912                     return (ERROR);
8913                     }
8914                 expecting  = Expecting(LEFTPAR);
8915                 for (i=0; i<numCurrentDivisions; i++)
8916                     numVars[i] = 0;
8917                 }
8918             else if (expecting == Expecting(LEFTPAR))
8919                 {
8920                 expecting  = Expecting(NUMBER) | Expecting(DASH);
8921                 }
8922             else if (expecting == Expecting(DASH))
8923                 {
8924                 expecting  = Expecting(NUMBER);
8925                 isNegative = YES;
8926                 }
8927             else if (expecting == Expecting(NUMBER))
8928                 {
8929                 nApplied = NumActiveParts ();
8930                 for (i=0; i<numCurrentDivisions; i++)
8931                     {
8932                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
8933                         {
8934                         if (!strcmp(modelParams[i].growthPr,"Uniform"))
8935                             {
8936                             sscanf (tkn, "%lf", &tempD);
8937                             if (isNegative == YES)
8938                                 tempD *= -1.0;
8939                             modelParams[i].growthUni[numVars[i]++] = tempD;
8940                             if (numVars[i] == 1)
8941                                 expecting  = Expecting(COMMA);
8942                             else
8943                                 {
8944                                 if (modelParams[i].growthUni[0] >= modelParams[i].growthUni[1])
8945                                     {
8946                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
8947                                     return (ERROR);
8948                                     }
8949                                 if (nApplied == 0 && numCurrentDivisions == 1)
8950                                     MrBayesPrint ("%s   Setting Growthpr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].growthUni[0], modelParams[i].growthUni[1]);
8951                                 else
8952                                     MrBayesPrint ("%s   Setting Growthpr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].growthUni[0], modelParams[i].growthUni[1], i+1);
8953                                 expecting  = Expecting(RIGHTPAR);
8954                                 }
8955                             }
8956                         else if (!strcmp(modelParams[i].growthPr,"Normal"))
8957                             {
8958                             sscanf (tkn, "%lf", &tempD);
8959                             if (isNegative == YES)
8960                                 tempD *= -1.0;
8961                             modelParams[i].growthNorm[numVars[i]++] = tempD;
8962                             if (numVars[i] == 1)
8963                                 expecting  = Expecting(COMMA);
8964                             else
8965                                 {
8966                                 if (modelParams[i].growthNorm[1] < 0.0)
8967                                     {
8968                                     MrBayesPrint ("%s   Variance for normal distribution should be greater than zero\n", spacer);
8969                                     return (ERROR);
8970                                     }
8971                                 if (nApplied == 0 && numCurrentDivisions == 1)
8972                                     MrBayesPrint ("%s   Setting Growthpr to Normal(%1.2lf,%1.2lf)\n", spacer, modelParams[i].growthNorm[0], modelParams[i].growthNorm[1]);
8973                                 else
8974                                     MrBayesPrint ("%s   Setting Growthpr to Normal(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].growthNorm[0], modelParams[i].growthNorm[1], i+1);
8975                                 expecting  = Expecting(RIGHTPAR);
8976                                 }
8977                             }
8978                         else if (!strcmp(modelParams[i].growthPr,"Exponential"))
8979                             {
8980                             sscanf (tkn, "%lf", &tempD);
8981                             modelParams[i].growthExp = tempD;
8982                             if (nApplied == 0 && numCurrentDivisions == 1)
8983                                 MrBayesPrint ("%s   Setting Growthpr to Exponential(%1.2lf)\n", spacer, modelParams[i].growthExp);
8984                             else
8985                                 MrBayesPrint ("%s   Setting Growthpr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].growthExp, i+1);
8986                             expecting  = Expecting(RIGHTPAR);
8987                             }
8988                         else if (!strcmp(modelParams[i].growthPr,"Fixed"))
8989                             {
8990                             sscanf (tkn, "%lf", &tempD);
8991                             if (isNegative == YES)
8992                                 tempD *= -1.0;
8993                             modelParams[i].growthFix = tempD;
8994                             if (nApplied == 0 && numCurrentDivisions == 1)
8995                                 MrBayesPrint ("%s   Setting Growthpr to Fixed(%1.2lf)\n", spacer, modelParams[i].growthFix);
8996                             else
8997                                 MrBayesPrint ("%s   Setting Growthpr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].growthFix, i+1);
8998                             expecting  = Expecting(RIGHTPAR);
8999                             }
9000                         }
9001                     }
9002                 isNegative = NO;
9003                 }
9004             else if (expecting == Expecting(COMMA))
9005                 {
9006                 expecting  = Expecting(NUMBER);
9007                 }
9008             else if (expecting == Expecting(RIGHTPAR))
9009                 {
9010                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9011                 }
9012             else
9013                 return (ERROR);
9014             }
9015         /* set Aamodelpr (aaModelPr) **************************************************************/
9016         else if (!strcmp(parmName, "Aamodelpr"))
9017             {
9018             if (expecting == Expecting(EQUALSIGN))
9019                 {
9020                 expecting = Expecting(ALPHA);
9021                 foundAaSetting = foundExp = modelIsFixed = foundDash = NO;
9022                 fromI = 0;
9023                 for (i=0; i<10; i++)
9024                     tempAaModelPrs[i] = 0.0;
9025                 }
9026             else if (expecting == Expecting(ALPHA))
9027                 {
9028                 if (foundAaSetting == NO)
9029                     {
9030                     if (IsArgValid(tkn, tempStr) == NO_ERROR)
9031                         {
9032                         nApplied = NumActiveParts ();
9033                         for (i=0; i<numCurrentDivisions; i++)
9034                             {
9035                             if ((activeParts[i] == YES || nApplied == 0))
9036                                 {
9037                                 strcpy(modelParams[i].aaModelPr, tempStr);
9038                                 if (!strcmp(modelParams[i].aaModelPr, "Mixed"))
9039                                     {
9040                                     if (nApplied == 0 && numCurrentDivisions == 1)
9041                                         MrBayesPrint ("%s   Setting Aamodelpr to %s\n", spacer, modelParams[i].aaModelPr);
9042                                     else
9043                                         MrBayesPrint ("%s   Setting Aamodelpr to %s for partition %d\n", spacer, modelParams[i].aaModelPr, i+1);
9044                                     }
9045                                 }
9046                             }
9047                         }
9048                     else
9049                         {
9050                         MrBayesPrint ("%s   Invalid Aamodelpr argument\n", spacer);
9051                         return (ERROR);
9052                         }
9053                     foundAaSetting = YES;
9054                     if (!strcmp(tempStr, "Fixed"))
9055                         {
9056                         modelIsFixed = YES;
9057                         expecting = Expecting(LEFTPAR);
9058                         }
9059                     else
9060                         {
9061                         expecting = Expecting(LEFTPAR) | Expecting(PARAMETER) | Expecting(SEMICOLON);
9062                         }
9063                     }
9064                 else
9065                     {
9066                     if (modelIsFixed == YES)
9067                         {
9068                         if (IsSame ("Poisson", tkn) == SAME      || IsSame ("Poisson", tkn) == CONSISTENT_WITH)
9069                             strcpy (tempStr, "Poisson");
9070                         else if (IsSame ("Equalin", tkn) == SAME || IsSame ("Equalin", tkn) == CONSISTENT_WITH)
9071                             strcpy (tempStr, "Equalin");
9072                         else if (IsSame ("Jones", tkn) == SAME   || IsSame ("Jones", tkn) == CONSISTENT_WITH)
9073                             strcpy (tempStr, "Jones");
9074                         else if (IsSame ("Dayhoff", tkn) == SAME || IsSame ("Dayhoff", tkn) == CONSISTENT_WITH)
9075                             strcpy (tempStr, "Dayhoff");
9076                         else if (IsSame ("Mtrev", tkn) == SAME   || IsSame ("Mtrev", tkn) == CONSISTENT_WITH)
9077                             strcpy (tempStr, "Mtrev");
9078                         else if (IsSame ("Mtmam", tkn) == SAME   || IsSame ("Mtmam", tkn) == CONSISTENT_WITH)
9079                             strcpy (tempStr, "Mtmam");
9080                         else if (IsSame ("Wag", tkn) == SAME     || IsSame ("Wag", tkn) == CONSISTENT_WITH)
9081                             strcpy (tempStr, "Wag");
9082                         else if (IsSame ("Rtrev", tkn) == SAME   || IsSame ("Rtrev", tkn) == CONSISTENT_WITH)
9083                             strcpy (tempStr, "Rtrev");
9084                         else if (IsSame ("Cprev", tkn) == SAME   || IsSame ("Cprev", tkn) == CONSISTENT_WITH)
9085                             strcpy (tempStr, "Cprev");
9086                         else if (IsSame ("Vt", tkn) == SAME      || IsSame ("Vt", tkn) == CONSISTENT_WITH)
9087                             strcpy (tempStr, "Vt");
9088                         else if (IsSame ("Blosum", tkn) == SAME  || IsSame ("Blosum", tkn) == CONSISTENT_WITH)
9089                             strcpy (tempStr, "Blosum");
9090                         else if (IsSame ("Blossum", tkn) == SAME || IsSame ("Blossum", tkn) == CONSISTENT_WITH)
9091                             strcpy (tempStr, "Blosum");
9092                         else if (IsSame ("LG", tkn) == SAME      || IsSame ("LG", tkn) == CONSISTENT_WITH)
9093                             strcpy (tempStr, "LG");
9094                         else if (IsSame ("Gtr", tkn) == SAME     || IsSame ("Gtr", tkn) == CONSISTENT_WITH)
9095                             strcpy (tempStr, "Gtr");
9096                         else
9097                             {
9098                             MrBayesPrint ("%s   Invalid amino acid model\n", spacer);
9099                             return (ERROR);
9100                             }
9101                         nApplied = NumActiveParts ();
9102                         for (i=0; i<numCurrentDivisions; i++)
9103                             {
9104                             if ((activeParts[i] == YES || nApplied == 0))
9105                                 {
9106                                 if (!strcmp(modelParams[i].aaModelPr, "Fixed"))
9107                                     {
9108                                     strcpy(modelParams[i].aaModel, tempStr);
9109                                     if (nApplied == 0 && numCurrentDivisions == 1)
9110                                         MrBayesPrint ("%s   Setting Aamodelpr to Fixed(%s)\n", spacer, modelParams[i].aaModel);
9111                                     else
9112                                         MrBayesPrint ("%s   Setting Aamodelpr to Fixed(%s) for partition %d\n", spacer, modelParams[i].aaModel, i+1);
9113                                     }
9114                                 else
9115                                     {
9116                                     MrBayesPrint ("%s   You cannot assign an amino acid matrix for mixed models\n", spacer);
9117                                     return (ERROR);
9118                                     }
9119                                 }
9120                             }
9121                         expecting = Expecting(RIGHTPAR);
9122                         }
9123                     else
9124                         {
9125                         if (IsSame ("Exponential", tkn) == SAME || IsSame ("Exponential", tkn) == CONSISTENT_WITH)
9126                             {
9127                             foundExp = YES;
9128                             expecting = Expecting(LEFTPAR);
9129                             }
9130                         else
9131                             {
9132                             MrBayesPrint ("%s   Invalid argument \"%s\"\n", spacer, tkn);
9133                             return (ERROR);
9134                             }
9135                         }
9136 
9137                     }
9138                 }
9139             else if (expecting == Expecting(NUMBER))
9140                 {
9141                 sscanf (tkn, "%lf", &tempD);
9142                 if (fromI >= 10)
9143                     {
9144                     MrBayesPrint ("%s   Too many arguments in Aamodelpr\n", spacer);
9145                     return (ERROR);
9146                     }
9147                 if (modelIsFixed == NO)
9148                     {
9149                     if (foundExp == YES)
9150                         {
9151                         if (foundDash == YES)
9152                             tempAaModelPrs[fromI++] = -tempD;
9153                         else
9154                             tempAaModelPrs[fromI++] = tempD;
9155                         expecting  = Expecting(RIGHTPAR);
9156                         }
9157                     else
9158                         {
9159                         if (foundDash == YES)
9160                             {
9161                             MrBayesPrint ("%s   Unexpected \"-\" in Aamodelpr\n", spacer);
9162                             return (ERROR);
9163                             }
9164                         else
9165                             {
9166                             if (tempD <= 0.000000000001)
9167                                 tempAaModelPrs[fromI++] = -1000000000;
9168                             else
9169                                 tempAaModelPrs[fromI++] = (MrBFlt) log(tempD);
9170                             }
9171                         expecting  = Expecting(COMMA) | Expecting(RIGHTPAR);
9172                         }
9173                     foundDash = NO;
9174                     }
9175                 else
9176                     {
9177                     MrBayesPrint ("%s   Not expecting a number\n", spacer);
9178                     return (ERROR);
9179                     }
9180                 }
9181             else if (expecting == Expecting(LEFTPAR))
9182                 {
9183                 if (modelIsFixed == YES)
9184                     expecting  = Expecting(ALPHA);
9185                 else
9186                     {
9187                     if (foundExp == YES)
9188                         expecting  = Expecting(NUMBER) | Expecting(DASH);
9189                     else
9190                         expecting  = Expecting(NUMBER) | Expecting(ALPHA);
9191                     }
9192                 }
9193             else if (expecting == Expecting(RIGHTPAR))
9194                 {
9195                 if (modelIsFixed == YES)
9196                     expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9197                 else
9198                     {
9199                     if (foundExp == YES)
9200                         {
9201                         foundExp = NO;
9202                         expecting = Expecting(COMMA) | Expecting(RIGHTPAR);
9203                         }
9204                     else
9205                         {
9206                         if (fromI < 10)
9207                             {
9208                             MrBayesPrint ("%s   Too few arguments in Aamodelpr\n", spacer);
9209                             return (ERROR);
9210                             }
9211                         nApplied = NumActiveParts ();
9212                         for (i=0; i<numCurrentDivisions; i++)
9213                             {
9214                             if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == PROTEIN)
9215                                 {
9216                                 if (!strcmp(modelParams[i].aaModelPr, "Fixed"))
9217                                     {
9218                                     MrBayesPrint ("%s   You cannot assign model prior probabilities for a fixed amino acid model\n", spacer);
9219                                     return (ERROR);
9220                                     }
9221                                 else
9222                                     {
9223                                     for (j=0; j<10; j++)
9224                                         modelParams[i].aaModelPrProbs[j] = tempAaModelPrs[j];
9225                                     }
9226                                 }
9227                             }
9228                         expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9229                         }
9230                     }
9231                 }
9232             else if (expecting == Expecting(DASH))
9233                 {
9234                 if (foundExp == YES)
9235                     {
9236                     foundDash = YES;
9237                     expecting  = Expecting(NUMBER);
9238                     }
9239                 else
9240                     {
9241                     MrBayesPrint ("%s   Invalid argument \"%s\"\n", spacer, tkn);
9242                     return (ERROR);
9243                     }
9244                 }
9245             else if (expecting == Expecting(COMMA))
9246                 {
9247                 if (modelIsFixed == YES)
9248                     {
9249                     MrBayesPrint ("%s   Not expecting \"%s\"\n", spacer, tkn);
9250                     return (ERROR);
9251                     }
9252                 else
9253                     expecting  = Expecting(NUMBER) | Expecting(ALPHA);
9254                 }
9255             else
9256                 return (ERROR);
9257             }
9258         /* set Brownscalepr (brownScalesPr) ****************************************************/
9259         else if (!strcmp(parmName, "Brownscalepr"))
9260             {
9261             if (expecting == Expecting(EQUALSIGN))
9262                 expecting = Expecting(ALPHA);
9263             else if (expecting == Expecting(ALPHA))
9264                 {
9265                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9266                     {
9267                     nApplied = NumActiveParts ();
9268                     flag = 0;
9269                     for (i=0; i<numCurrentDivisions; i++)
9270                         {
9271                         if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
9272                             {
9273                             strcpy(modelParams[i].brownScalesPr, tempStr);
9274                             flag = 1;
9275                             }
9276                         }
9277                     if (flag == 0)
9278                             {
9279                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing CONTINUOUS data.\
9280                             Currently there is no active partition with such data. ", spacer, parmName);
9281                             return (ERROR);
9282                             }
9283                     }
9284                 else
9285                     {
9286                     MrBayesPrint ("%s   Invalid Brownscalepr argument\n", spacer);
9287                     return (ERROR);
9288                     }
9289                 expecting  = Expecting(LEFTPAR);
9290                 for (i=0; i<numCurrentDivisions; i++)
9291                     numVars[i] = 0;
9292                 }
9293             else if (expecting == Expecting(LEFTPAR))
9294                 {
9295                 expecting  = Expecting(NUMBER);
9296                 }
9297             else if (expecting == Expecting(NUMBER))
9298                 {
9299                 nApplied = NumActiveParts ();
9300                 for (i=0; i<numCurrentDivisions; i++)
9301                     {
9302                     if ((activeParts[i] == YES || nApplied == 0) && modelParams[i].dataType == CONTINUOUS)
9303                         {
9304                         if (!strcmp(modelParams[i].brownScalesPr,"Uniform"))
9305                             {
9306                             sscanf (tkn, "%lf", &tempD);
9307                             modelParams[i].brownScalesUni[numVars[i]++] = tempD;
9308                             if (numVars[i] == 1)
9309                                 expecting  = Expecting(COMMA);
9310                             else
9311                                 {
9312                                 if (modelParams[i].brownScalesUni[0] >= modelParams[i].brownScalesUni[1])
9313                                     {
9314                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
9315                                     return (ERROR);
9316                                     }
9317                                 if (nApplied == 0 && numCurrentDivisions == 1)
9318                                     MrBayesPrint ("%s   Setting Brownscalepr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].brownScalesUni[0], modelParams[i].brownScalesUni[1]);
9319                                 else
9320                                     MrBayesPrint ("%s   Setting Brownscalepr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].brownScalesUni[0], modelParams[i].brownScalesUni[1], i+1);
9321                                 expecting  = Expecting(RIGHTPAR);
9322                                 }
9323                             }
9324                         else if (!strcmp(modelParams[i].brownScalesPr,"Gamma"))
9325                             {
9326                             sscanf (tkn, "%lf", &tempD);
9327                             modelParams[i].brownScalesGamma[numVars[i]++] = tempD;
9328                             if (numVars[i] == 1)
9329                                 expecting  = Expecting(COMMA);
9330                             else
9331                                 {
9332                                 if (nApplied == 0 && numCurrentDivisions == 1)
9333                                     MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=%1.2lf Var=%1.2lf\n", spacer, modelParams[i].brownScalesGamma[0], modelParams[i].brownScalesGamma[1]);
9334                                 else
9335                                     MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=%1.2lf Var=%1.2lf for partition %d\n", spacer, modelParams[i].brownScalesGamma[0], modelParams[i].brownScalesGamma[1], i+1);
9336                                 expecting  = Expecting(RIGHTPAR);
9337                                 }
9338                             }
9339                         else if (!strcmp(modelParams[i].brownScalesPr,"Gammamean"))
9340                             {
9341                             sscanf (tkn, "%lf", &tempD);
9342                             modelParams[i].brownScalesGammaMean = tempD;
9343                             if (nApplied == 0 && numCurrentDivisions == 1)
9344                                 MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=<char. ave.> Var=%1.2lf\n", spacer, modelParams[i].brownScalesGammaMean);
9345                             else
9346                                 MrBayesPrint ("%s   Setting Brownscalepr to Gamma Mean=<char.ave.> Var=%1.2lf for partition %d\n", spacer, modelParams[i].brownScalesGammaMean, i+1);
9347                             expecting  = Expecting(RIGHTPAR);
9348                             }
9349                         else if (!strcmp(modelParams[i].brownScalesPr,"Fixed"))
9350                             {
9351                             sscanf (tkn, "%lf", &tempD);
9352                             modelParams[i].brownScalesFix = tempD;
9353                             if (nApplied == 0 && numCurrentDivisions == 1)
9354                                 MrBayesPrint ("%s   Setting Brownscalepr to Fixed(%1.2lf)\n", spacer, modelParams[i].brownScalesFix);
9355                             else
9356                                 MrBayesPrint ("%s   Setting Brownscalepr to Fixed(%1.2lf) for partition %d\n", spacer, modelParams[i].brownScalesFix, i+1);
9357                             expecting  = Expecting(RIGHTPAR);
9358                             }
9359                         }
9360                     }
9361                 }
9362             else if (expecting == Expecting(COMMA))
9363                 {
9364                 expecting  = Expecting(NUMBER);
9365                 }
9366             else if (expecting == Expecting(RIGHTPAR))
9367                 {
9368                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9369                 }
9370             else
9371                 return (ERROR);
9372             }
9373         /* set M10betapr (m10betapr) ********************************************************/
9374         else if (!strcmp(parmName, "M10betapr"))
9375             {
9376             if (expecting == Expecting(EQUALSIGN))
9377                 expecting = Expecting(ALPHA);
9378             else if (expecting == Expecting(ALPHA))
9379                 {
9380                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9381                     {
9382                     nApplied = NumActiveParts ();
9383                     flag = 0;
9384                     for (i=0; i<numCurrentDivisions; i++)
9385                         {
9386                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9387                             {
9388                             strcpy(modelParams[i].m10betapr, tempStr);
9389                             flag = 1;
9390                             }
9391                         }
9392                     if (flag == 0)
9393                             {
9394                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA.\
9395                             Currently there is no active partition with such data. ", spacer, parmName);
9396                             return (ERROR);
9397                             }
9398                     }
9399                 else
9400                     {
9401                     MrBayesPrint ("%s   Invalid M10betapr argument\n", spacer);
9402                     return (ERROR);
9403                     }
9404                 expecting  = Expecting(LEFTPAR);
9405                 for (i=0; i<numCurrentDivisions; i++)
9406                     numVars[i] = 0;
9407                 }
9408             else if (expecting == Expecting(LEFTPAR))
9409                 {
9410                 expecting  = Expecting(NUMBER);
9411                 }
9412             else if (expecting == Expecting(NUMBER))
9413                 {
9414                 nApplied = NumActiveParts ();
9415                 for (i=0; i<numCurrentDivisions; i++)
9416                     {
9417                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9418                         {
9419                         if (!strcmp(modelParams[i].m10betapr,"Uniform"))
9420                             {
9421                             sscanf (tkn, "%lf", &tempD);
9422                             modelParams[i].m10betaUni[numVars[i]++] = tempD;
9423                             if (numVars[i] == 1)
9424                                 expecting  = Expecting(COMMA);
9425                             else
9426                                 {
9427                                 if (modelParams[i].m10betaUni[0] >= modelParams[i].m10betaUni[1])
9428                                     {
9429                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
9430                                     return (ERROR);
9431                                     }
9432                                 if (nApplied == 0 && numCurrentDivisions == 1)
9433                                     MrBayesPrint ("%s   Setting M10betapr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10betaUni[0], modelParams[i].m10betaUni[1]);
9434                                 else
9435                                     MrBayesPrint ("%s   Setting M10betapr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10betaUni[0], modelParams[i].m10betaUni[1], i+1);
9436                                 expecting  = Expecting(RIGHTPAR);
9437                                 }
9438                             }
9439                         else if (!strcmp(modelParams[i].m10betapr,"Exponential"))
9440                             {
9441                             sscanf (tkn, "%lf", &tempD);
9442                             modelParams[i].m10betaExp = tempD;
9443                             if (nApplied == 0 && numCurrentDivisions == 1)
9444                                 MrBayesPrint ("%s   Setting M10betapr to Exponential(%1.2lf)\n", spacer, modelParams[i].m10betaExp);
9445                             else
9446                                 MrBayesPrint ("%s   Setting M10betapr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].m10betaExp, i+1);
9447                             expecting  = Expecting(RIGHTPAR);
9448                             }
9449                         else if (!strcmp(modelParams[i].m10betapr,"Fixed"))
9450                             {
9451                             sscanf (tkn, "%lf", &tempD);
9452                             modelParams[i].m10betaFix[numVars[i]++] = tempD;
9453                             if (numVars[i] == 1)
9454                                 expecting  = Expecting(COMMA);
9455                             else
9456                                 {
9457                                 if (nApplied == 0 && numCurrentDivisions == 1)
9458                                     MrBayesPrint ("%s   Setting M10betapr to Fixed(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10betaFix[0], modelParams[i].m10betaFix[1]);
9459                                 else
9460                                     MrBayesPrint ("%s   Setting M10betapr to Fixed(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10betaFix[0], modelParams[i].m10betaFix[1], i+1);
9461                                 expecting  = Expecting(RIGHTPAR);
9462                                 }
9463                             }
9464                         }
9465                     }
9466                 }
9467             else if (expecting == Expecting(COMMA))
9468                 {
9469                 expecting  = Expecting(NUMBER);
9470                 }
9471             else if (expecting == Expecting(RIGHTPAR))
9472                 {
9473                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9474                 }
9475             else
9476                 return (ERROR);
9477             }
9478         /* set M10gammapr (m10gammapr) ********************************************************/
9479         else if (!strcmp(parmName, "M10gammapr"))
9480             {
9481             if (expecting == Expecting(EQUALSIGN))
9482                 expecting = Expecting(ALPHA);
9483             else if (expecting == Expecting(ALPHA))
9484                 {
9485                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9486                     {
9487                     nApplied = NumActiveParts ();
9488                     flag = 0;
9489                     for (i=0; i<numCurrentDivisions; i++)
9490                         {
9491                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9492                             {
9493                             strcpy(modelParams[i].m10gammapr, tempStr);
9494                             flag = 1;
9495                             }
9496                         }
9497                     if (flag == 0)
9498                             {
9499                             MrBayesPrint ("%s   Warning: %s can be set only for partition containing data of at least one of the following type: DNA, RNA.\
9500                             Currently there is no active partition with such data. ", spacer, parmName);
9501                             return (ERROR);
9502                             }
9503                     }
9504                 else
9505                     {
9506                     MrBayesPrint ("%s   Invalid M10gammapr argument\n", spacer);
9507                     return (ERROR);
9508                     }
9509                 expecting  = Expecting(LEFTPAR);
9510                 for (i=0; i<numCurrentDivisions; i++)
9511                     numVars[i] = 0;
9512                 }
9513             else if (expecting == Expecting(LEFTPAR))
9514                 {
9515                 expecting  = Expecting(NUMBER);
9516                 }
9517             else if (expecting == Expecting(NUMBER))
9518                 {
9519                 nApplied = NumActiveParts ();
9520                 for (i=0; i<numCurrentDivisions; i++)
9521                     {
9522                     if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9523                         {
9524                         if (!strcmp(modelParams[i].m10gammapr,"Uniform"))
9525                             {
9526                             sscanf (tkn, "%lf", &tempD);
9527                             modelParams[i].m10gammaUni[numVars[i]++] = tempD;
9528                             if (numVars[i] == 1)
9529                                 expecting  = Expecting(COMMA);
9530                             else
9531                                 {
9532                                 if (modelParams[i].m10gammaUni[0] >= modelParams[i].m10gammaUni[1])
9533                                     {
9534                                     MrBayesPrint ("%s   Lower value for uniform should be greater than upper value\n", spacer);
9535                                     return (ERROR);
9536                                     }
9537                                 if (nApplied == 0 && numCurrentDivisions == 1)
9538                                     MrBayesPrint ("%s   Setting M10gammapr to Uniform(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10gammaUni[0], modelParams[i].m10gammaUni[1]);
9539                                 else
9540                                     MrBayesPrint ("%s   Setting M10gammapr to Uniform(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10gammaUni[0], modelParams[i].m10gammaUni[1], i+1);
9541                                 expecting  = Expecting(RIGHTPAR);
9542                                 }
9543                             }
9544                         else if (!strcmp(modelParams[i].m10gammapr,"Exponential"))
9545                             {
9546                             sscanf (tkn, "%lf", &tempD);
9547                             modelParams[i].m10gammaExp = tempD;
9548                             if (nApplied == 0 && numCurrentDivisions == 1)
9549                                 MrBayesPrint ("%s   Setting M10gammapr to Exponential(%1.2lf)\n", spacer, modelParams[i].m10gammaExp);
9550                             else
9551                                 MrBayesPrint ("%s   Setting M10gammapr to Exponential(%1.2lf) for partition %d\n", spacer, modelParams[i].m10gammaExp, i+1);
9552                             expecting  = Expecting(RIGHTPAR);
9553                             }
9554                         else if (!strcmp(modelParams[i].m10gammapr,"Fixed"))
9555                             {
9556                             sscanf (tkn, "%lf", &tempD);
9557                             modelParams[i].m10gammaFix[numVars[i]++] = tempD;
9558                             if (numVars[i] == 1)
9559                                 expecting  = Expecting(COMMA);
9560                             else
9561                                 {
9562                                 if (nApplied == 0 && numCurrentDivisions == 1)
9563                                     MrBayesPrint ("%s   Setting M10gammapr to Fixed(%1.2lf,%1.2lf)\n", spacer, modelParams[i].m10gammaFix[0], modelParams[i].m10gammaFix[1]);
9564                                 else
9565                                     MrBayesPrint ("%s   Setting M10gammapr to Fixed(%1.2lf,%1.2lf) for partition %d\n", spacer, modelParams[i].m10gammaFix[0], modelParams[i].m10gammaFix[1], i+1);
9566                                 expecting  = Expecting(RIGHTPAR);
9567                                 }
9568                             }
9569                         }
9570                     }
9571                 }
9572             else if (expecting == Expecting(COMMA))
9573                 {
9574                 expecting  = Expecting(NUMBER);
9575                 }
9576             else if (expecting == Expecting(RIGHTPAR))
9577                 {
9578                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9579                 }
9580             else
9581                 return (ERROR);
9582             }
9583 
9584         else
9585             return (ERROR);
9586         }
9587 
9588     return (NO_ERROR);
9589 }
9590 
9591 
DoQuit(void)9592 int DoQuit (void)
9593 {
9594     int         i;
9595     char        tempName[100];
9596 
9597     /* free information for model and matrix */
9598     FreeModel ();
9599     FreeMatrix ();
9600 
9601     SafeFclose (&logFileFp);
9602     logToFile = NO;
9603 
9604     /* check to see if any memory has not been freed */
9605     for (i=0; i<NUM_ALLOCS; i++)
9606         {
9607         if (memAllocs[i] == YES)
9608             {
9609             MrBayesPrint ("   WARNING: Memory (%d) has not been freed\n", i);
9610             if (mode == INTERACTIVE && quitOnError == NO)
9611                 {
9612                 MrBayesPrint ("%s   Hit return key to continue  ", spacer);
9613                 fflush (stdin);
9614                 if (fgets (tempName, 100, stdin) == NULL)
9615                     {
9616                     printf ("Error in function: %s at line: %d in file: %s", __func__, __LINE__, __FILE__);
9617                     }
9618                 }
9619             }
9620         }
9621 
9622     /* free modelIndicatorParams and modelElementNames */
9623     for (i=0; i<203; i++)
9624         free (modelElementNames[1][i]);
9625     for (i=0; i<3; i++)
9626         free (modelElementNames[i]);
9627     free (modelElementNames);
9628     free (modelIndicatorParams);
9629 
9630     MrBayesPrint ("   Quitting program\n\n");
9631 
9632     /* If we quit while reading a mrbayes block, then we need to make certain
9633      that we return a NO_ERROR_QUIT so we can break out of DoExecute cleanly,
9634      and dealloc "s" there. */
9635     if (inMrbayesBlock == YES)
9636         {
9637         inMrbayesBlock = NO;
9638         return (NO_ERROR_QUIT);
9639         }
9640 
9641     return (NO_ERROR);
9642 }
9643 
9644 
DoReport(void)9645 int DoReport (void)
9646 {
9647     /* TODO: smart update */
9648     if (SetUpAnalysis (&globalSeed) == ERROR)
9649         return (ERROR);
9650     return (NO_ERROR);
9651 }
9652 
9653 
DoReportParm(char * parmName,char * tkn)9654 int DoReportParm (char *parmName, char *tkn)
9655 {
9656     int         i, tempInt, nApplied;
9657     char        tempStr[100];
9658 
9659     if (defMatrix == NO)
9660         {
9661         MrBayesPrint ("%s   A matrix must be specified before the report settings can be altered\n", spacer);
9662         return (ERROR);
9663         }
9664     if (inValidCommand == YES)
9665         {
9666         for (i=0; i<numCurrentDivisions; i++)
9667             activeParts[i] = NO;
9668         inValidCommand = NO;
9669         }
9670 
9671     if (expecting == Expecting(PARAMETER))
9672         {
9673         expecting = Expecting(EQUALSIGN);
9674         }
9675     else
9676         {
9677         /* set Applyto (Applyto) *************************************************************/
9678         if (!strcmp(parmName, "Applyto"))
9679             {
9680             if (expecting == Expecting(EQUALSIGN))
9681                 expecting = Expecting(LEFTPAR);
9682             else if (expecting == Expecting(LEFTPAR))
9683                 {
9684                 for (i=0; i<numCurrentDivisions; i++)
9685                     activeParts[i] = NO;
9686                 fromI = toJ = -1;
9687                 foundDash = NO;
9688                 expecting = Expecting(NUMBER) | Expecting(ALPHA);
9689                 }
9690             else if (expecting == Expecting(RIGHTPAR))
9691                 {
9692                 if (fromI != -1)
9693                     activeParts[fromI-1] = YES;
9694                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9695                 }
9696             else if (expecting == Expecting(COMMA))
9697                 {
9698                 foundComma = YES;
9699                 expecting = Expecting(NUMBER);
9700                 }
9701             else if (expecting == Expecting(ALPHA))
9702                 {
9703                 if (IsSame ("All", tkn) == DIFFERENT)
9704                     {
9705                     MrBayesPrint ("%s   Do not understand delimiter \"%s\"\n", spacer, tkn);
9706                     return (ERROR);
9707                     }
9708                 for (i=0; i<numCurrentDivisions; i++)
9709                     activeParts[i] = YES;
9710                 expecting  = Expecting(RIGHTPAR);
9711                 }
9712             else if (expecting == Expecting(NUMBER))
9713                 {
9714                 sscanf (tkn, "%d", &tempInt);
9715                 if (tempInt > numCurrentDivisions)
9716                     {
9717                     MrBayesPrint ("%s   Partition delimiter is too large\n", spacer);
9718                     return (ERROR);
9719                     }
9720                 if (fromI == -1)
9721                     fromI = tempInt;
9722                 else if (fromI != -1 && toJ == -1 && foundDash == YES && foundComma == NO)
9723                     {
9724                     toJ = tempInt;
9725                     for (i=fromI-1; i<toJ; i++)
9726                         activeParts[i] = YES;
9727                     fromI = toJ = -1;
9728                     foundDash = NO;
9729                     }
9730                 else if (fromI != -1 && toJ == -1 && foundDash == NO && foundComma == YES)
9731                     {
9732                     activeParts[fromI-1] = YES;
9733                     fromI = tempInt;
9734                     foundComma = NO;
9735                     }
9736 
9737                 expecting  = Expecting(COMMA);
9738                 expecting |= Expecting(DASH);
9739                 expecting |= Expecting(RIGHTPAR);
9740                 }
9741             else if (expecting == Expecting(DASH))
9742                 {
9743                 foundDash = YES;
9744                 expecting = Expecting(NUMBER);
9745                 }
9746             else
9747                 return (ERROR);
9748             }
9749         /* set report format of tratio ***************************************************/
9750         else if (!strcmp(parmName, "Tratio"))
9751             {
9752             if (expecting == Expecting(EQUALSIGN))
9753                 expecting = Expecting (ALPHA);
9754             else if (expecting == Expecting(ALPHA))
9755                 {
9756                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9757                     {
9758                     nApplied = NumActiveParts ();
9759                     tempInt = NO;
9760                     for (i=0; i<numCurrentDivisions; i++)
9761                         {
9762                         /* check that data type is correct; we do not know yet if the user will specify
9763                         a nst=2 model so we cannot check that tratio is an active parameter */
9764                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9765                             {
9766                             strcpy(modelParams[i].tratioFormat, tempStr);
9767                             if (nApplied == 0 && numCurrentDivisions == 1)
9768                                 MrBayesPrint ("%s   Setting transition/transversion rate ratio (tratio) format to %s\n", spacer, modelParams[i].tratioFormat);
9769                             else
9770                                 MrBayesPrint ("%s   Setting transition/transversion rate ratio (tratio) format to %s for partition %d\n", spacer, modelParams[i].tratioFormat, i+1);
9771                             }
9772                         }
9773                     }
9774                 else
9775                     {
9776                     MrBayesPrint ("%s   Invalid transition/transversion rate ratio (tratio) format \n", spacer);
9777                     return (ERROR);
9778                     }
9779                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9780                 }
9781             else
9782                 return (ERROR);
9783             }
9784         /* set report format of revmat ***************************************************/
9785         else if (!strcmp(parmName, "Revmat"))
9786             {
9787             if (expecting == Expecting(EQUALSIGN))
9788                 expecting = Expecting (ALPHA);
9789             else if (expecting == Expecting(ALPHA))
9790                 {
9791                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9792                     {
9793                     nApplied = NumActiveParts ();
9794                     tempInt = NO;
9795                     for (i=0; i<numCurrentDivisions; i++)
9796                         {
9797                         /* check that data type is correct; we do not know yet if the user will specify
9798                            a nst=6 model so we cannot check that revmat is an active parameter */
9799                         if ((activeParts[i] == YES || nApplied == 0) && (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA))
9800                             {
9801                             strcpy(modelParams[i].revmatFormat, tempStr);
9802                             if (nApplied == 0 && numCurrentDivisions == 1)
9803                                 MrBayesPrint ("%s   Setting reversible rate matrix (revmat) format to %s\n", spacer, modelParams[i].revmatFormat);
9804                             else
9805                                 MrBayesPrint ("%s   Setting reversible rate matrix (revmat) format to %s for partition %d\n", spacer, modelParams[i].revmatFormat, i+1);
9806                             }
9807                         }
9808                     }
9809                 else
9810                     {
9811                     MrBayesPrint ("%s   Invalid reversible rate matrix (revmat) format \n", spacer);
9812                     return (ERROR);
9813                     }
9814                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9815                 }
9816             else
9817                 return (ERROR);
9818             }
9819         /* set report format of ratemult *************************************************/
9820         else if (!strcmp(parmName, "Ratemult"))
9821             {
9822             if (expecting == Expecting(EQUALSIGN))
9823                 expecting = Expecting (ALPHA);
9824             else if (expecting == Expecting(ALPHA))
9825                 {
9826                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9827                     {
9828                     nApplied = NumActiveParts ();
9829                     tempInt = NO;
9830                     for (i=0; i<numCurrentDivisions; i++)
9831                         {
9832                         /* we do not know yet if the user will specify variable rates across partitions
9833                            so only check that we have more than one partition in the model */
9834                         if ((activeParts[i] == YES || nApplied == 0) && numCurrentDivisions > 1)
9835                             {
9836                             strcpy(modelParams[i].ratemultFormat, tempStr);
9837                             if (nApplied == 0 && numCurrentDivisions == 1)
9838                                 MrBayesPrint ("%s   Setting rate multiplier (ratemult) format to %s\n", spacer, modelParams[i].ratemultFormat);
9839                             else
9840                                 MrBayesPrint ("%s   Setting rate multiplier (ratemult) format to %s for partition %d\n", spacer, modelParams[i].ratemultFormat, i+1);
9841                             }
9842                         }
9843                     }
9844                 else
9845                     {
9846                     MrBayesPrint ("%s   Invalid rate multiplier (ratemult) format \n", spacer);
9847                     return (ERROR);
9848                     }
9849                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9850                 }
9851             else
9852                 return (ERROR);
9853             }
9854         /* set report format of tree ***************************************************/
9855         else if (!strcmp(parmName, "Tree"))
9856             {
9857             if (expecting == Expecting(EQUALSIGN))
9858                 expecting = Expecting (ALPHA);
9859             else if (expecting == Expecting(ALPHA))
9860                 {
9861                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9862                     {
9863                     nApplied = NumActiveParts ();
9864                     tempInt = NO;
9865                     for (i=0; i<numCurrentDivisions; i++)
9866                         {
9867                         strcpy(modelParams[i].treeFormat, tempStr);
9868                         if (nApplied == 0 && numCurrentDivisions == 1)
9869                             MrBayesPrint ("%s   Setting tree report format to %s\n", spacer, modelParams[i].treeFormat);
9870                         else
9871                             MrBayesPrint ("%s   Setting tree report format to %s for partition %d\n", spacer, modelParams[i].treeFormat, i+1);
9872                         }
9873                     }
9874                 else
9875                     {
9876                     MrBayesPrint ("%s   Invalid tree report format \n", spacer);
9877                     return (ERROR);
9878                     }
9879                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9880                 }
9881             else
9882                 return (ERROR);
9883             }
9884         /* set inferancstates ***********************************************************/
9885         else if (!strcmp(parmName, "Ancstates"))
9886             {
9887             if (expecting == Expecting(EQUALSIGN))
9888                 expecting = Expecting (ALPHA);
9889             else if (expecting == Expecting(ALPHA))
9890                 {
9891                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9892                     {
9893                     nApplied = NumActiveParts ();
9894                     for (i=0; i<numCurrentDivisions; i++)
9895                         {
9896                         if (activeParts[i] == YES || nApplied == 0)
9897                             {
9898                             strcpy(modelParams[i].inferAncStates,tempStr);
9899                             if (!strcmp(tempStr,"Yes"))
9900                                 {
9901                                 if (nApplied == 0 && numCurrentDivisions == 1)
9902                                     MrBayesPrint ("%s   Reporting ancestral states (if applicable)\n", spacer);
9903                                 else
9904                                     MrBayesPrint ("%s   Reporting ancestral states for partition %d (if applicable)\n", spacer, i+1);
9905                                 }
9906                             else
9907                                 {
9908                                 if (nApplied == 0 && numCurrentDivisions == 1)
9909                                     MrBayesPrint ("%s   Not reporting ancestral states\n", spacer);
9910                                 else
9911                                     MrBayesPrint ("%s   Not reporting ancestral states for partition %d\n", spacer, i+1);
9912                                 }
9913                             }
9914                         }
9915                     }
9916                 else
9917                     {
9918                     MrBayesPrint ("%s   Invalid ancstates option\n", spacer);
9919                     return (ERROR);
9920                     }
9921                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9922                 }
9923             else
9924                 return (ERROR);
9925             }
9926         /* set inferSiteRates ***************************************************************/
9927         else if (!strcmp(parmName, "Siterates"))
9928             {
9929             if (expecting == Expecting(EQUALSIGN))
9930                 expecting = Expecting (ALPHA);
9931             else if (expecting == Expecting(ALPHA))
9932                 {
9933                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9934                     {
9935                     nApplied = NumActiveParts ();
9936                     for (i=0; i<numCurrentDivisions; i++)
9937                         {
9938                         if (activeParts[i] == YES || nApplied == 0)
9939                             {
9940                             strcpy (modelParams[i].inferSiteRates, tempStr);
9941                             if (!strcmp(tempStr,"Yes"))
9942                                 {
9943                                 if (nApplied == 0 && numCurrentDivisions == 1)
9944                                     MrBayesPrint ("%s   Reporting site rates (if applicable)\n", spacer);
9945                                 else
9946                                     MrBayesPrint ("%s   Reporting site rates for partition %d (if applicable)\n", spacer, i+1);
9947                                 }
9948                             else
9949                                 {
9950                                 if (nApplied == 0 && numCurrentDivisions == 1)
9951                                     MrBayesPrint ("%s   Not reporting site rates\n", spacer);
9952                                 else
9953                                     MrBayesPrint ("%s   Not reporting site rates for partition %d\n", spacer, i+1);
9954                                 }
9955                             }
9956                         }
9957                     }
9958                 else
9959                     {
9960                     MrBayesPrint ("%s   Invalid siterates option\n", spacer);
9961                     return (ERROR);
9962                     }
9963                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
9964                 }
9965             else
9966                 return (ERROR);
9967             }
9968         /* set inferpossel *************************************************************/
9969         else if (!strcmp(parmName, "Possel"))
9970             {
9971             if (expecting == Expecting(EQUALSIGN))
9972                 expecting = Expecting (ALPHA);
9973             else if (expecting == Expecting(ALPHA))
9974                 {
9975                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
9976                     {
9977                     nApplied = NumActiveParts ();
9978                     for (i=0; i<numCurrentDivisions; i++)
9979                         {
9980                         if (activeParts[i] == YES || nApplied == 0)
9981                             {
9982                             strcpy (modelParams[i].inferPosSel, tempStr);
9983                             if (!strcmp(tempStr, "Yes"))
9984                                 {
9985                                 if (nApplied == 0 && numCurrentDivisions == 1)
9986                                     MrBayesPrint ("%s   Reporting positive selection (if applicable)\n", spacer);
9987                                 else
9988                                     MrBayesPrint ("%s   Reporting positive selection for partition %d (if applicable)\n", spacer, i+1);
9989                                 }
9990                             else
9991                                 {
9992                                 if (nApplied == 0 && numCurrentDivisions == 1)
9993                                     MrBayesPrint ("%s   Not reporting positive selection\n", spacer);
9994                                 else
9995                                     MrBayesPrint ("%s   Not reporting positive selection for partition %d\n", spacer, i+1);
9996                                 }
9997                             }
9998                         }
9999                     }
10000                 else
10001                     {
10002                     MrBayesPrint ("%s   Invalid possel option\n", spacer);
10003                     return (ERROR);
10004                     }
10005                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10006                 }
10007             else
10008                 return (ERROR);
10009             }
10010         /* set inferSiteOmegas *************************************************************/
10011         else if (!strcmp(parmName, "Siteomega"))
10012             {
10013             if (expecting == Expecting(EQUALSIGN))
10014                 expecting = Expecting (ALPHA);
10015             else if (expecting == Expecting(ALPHA))
10016                 {
10017                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
10018                     {
10019                     nApplied = NumActiveParts ();
10020                     for (i=0; i<numCurrentDivisions; i++)
10021                         {
10022                         if (activeParts[i] == YES || nApplied == 0)
10023                             {
10024                             strcpy (modelParams[i].inferSiteOmegas, tempStr);
10025                             if (!strcmp(tempStr, "Yes"))
10026                                 {
10027                                 if (nApplied == 0 && numCurrentDivisions == 1)
10028                                     MrBayesPrint ("%s   Reporting site omega values (if applicable)\n", spacer);
10029                                 else
10030                                     MrBayesPrint ("%s   Reporting site omega values for partition %d (if applicable)\n", spacer, i+1);
10031                                 }
10032                             else
10033                                 {
10034                                 if (nApplied == 0 && numCurrentDivisions == 1)
10035                                     MrBayesPrint ("%s   Not reporting site omega values\n", spacer);
10036                                 else
10037                                     MrBayesPrint ("%s   Not reporting site omega values for partition %d\n", spacer, i+1);
10038                                 }
10039                             }
10040                         }
10041                     }
10042                 else
10043                     {
10044                     MrBayesPrint ("%s   Invalid siteomega option\n", spacer);
10045                     return (ERROR);
10046                     }
10047                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10048                 }
10049             else
10050                 return (ERROR);
10051             }
10052         else
10053             {
10054             return (ERROR);
10055             }
10056         }
10057 
10058     return (NO_ERROR);
10059 }
10060 
10061 
DoStartvals(void)10062 int DoStartvals (void)
10063 {
10064     MrBayesPrint ("%s   Successfully set starting values\n", spacer);
10065     /*
10066     for (i=0; i<numParams; i++)
10067         assert (IsTreeConsistent(&params[i], 0, 0) == YES);
10068     */
10069     return (NO_ERROR);
10070 }
10071 
10072 
DoStartvalsParm(char * parmName,char * tkn)10073 int DoStartvalsParm (char *parmName, char *tkn)
10074 {
10075     int                 i, j, k, nMatches, tempInt=0, treeIndex, chainId, ret;
10076     MrBFlt              tempFloat=0.0, *value, *subValue;
10077     Tree                *theTree, *usrTree;
10078     PolyTree            *thePolyTree;
10079     MrBFlt              minRate=0.0, maxRate=0.0, clockRate;
10080     static Param        *param = NULL;
10081     static MrBFlt       *theValue, theValueMin, theValueMax;
10082     static int          useSubvalues, useStdStateFreqs, useIntValues, numExpectedValues, nValuesRead, runIndex, chainIndex, foundName, foundDash;
10083     static char         *temp=NULL, *tempName=NULL;
10084 
10085     if (defMatrix == NO)
10086         {
10087         MrBayesPrint ("%s   A matrix must be specified before starting values can be changed\n", spacer);
10088         return (ERROR);
10089         }
10090 
10091     if (expecting == Expecting(PARAMETER))
10092         {
10093         if (!strcmp(parmName, "Xxxxxxxxxx"))
10094             {
10095             /* we expect a parameter name with possible run and chain specification as follows:
10096                <param_name>(<run>,<chain>)=(<number>,...)   -- apply to run <run> and chain <chain>
10097                <param_name>(,<chain>)=(<number>,...)        -- apply to chain <chain> for all runs
10098                <param_name>(<run>,)=(<number>,...)          -- apply to run <run> for all chains
10099 
10100                topology and branch length parameters are specified like
10101                <param_name>(<run>,<chain>)=<tree_name>|<Newick_tree_spec>
10102 
10103                parameter names will often be followed by partition specifiers like:
10104                pi{all}
10105                pinvar{1,4,5}
10106                so we need to assemble the parameter name from several tokens that are parsed out separately;
10107                here we receive only the first part (before the left curly, if present)
10108             */
10109 
10110             /* copy to local parameter name */
10111             SafeStrcpy (&tempName, tkn);
10112             param = NULL;
10113             runIndex = chainIndex = -1;
10114             useSubvalues = NO;
10115             useIntValues = NO;
10116             useStdStateFreqs = NO;
10117             foundComma = foundEqual = foundName = foundDash = NO;
10118             expecting = Expecting(LEFTCURL) | Expecting(LEFTPAR) |  Expecting(EQUALSIGN);
10119             }
10120         else
10121             return (ERROR);
10122         }
10123     else if (expecting == Expecting(ALPHA))
10124         {
10125         if (param == NULL)
10126             {
10127             /* we are still assembling the parameter name */
10128             SafeStrcat (&tempName, tkn);
10129             expecting = Expecting(RIGHTCURL) | Expecting(COMMA) | Expecting(LEFTPAR) | Expecting(EQUALSIGN);
10130             }
10131         else
10132             {
10133             /* we have a tree name; now find the tree based on name, case insensitive */
10134             if (GetUserTreeFromName (&treeIndex, tkn) == ERROR || treeIndex == -1)
10135                 {
10136                 MrBayesPrint ("%s   Error in finding user tree\n", spacer);
10137                 return (ERROR);
10138                 }
10139 
10140             /* set the tree parameter */
10141             for (i=0; i<chainParams.numRuns; i++)
10142                 {
10143                 if (runIndex != -1 && i != runIndex)
10144                     continue;
10145                 for (j=0; j<chainParams.numChains; j++)
10146                     {
10147                     if (chainIndex != -1 && j != chainIndex)
10148                         continue;
10149                     chainId = i*chainParams.numChains + j;
10150                     if (param->paramType != P_POPSIZE)
10151                         {
10152                         if (param->paramType == P_TOPOLOGY || param->paramType == P_BRLENS || param->paramType == P_SPECIESTREE)
10153                             {
10154                             /* topology or brlens or speciestree params */
10155                             theTree = GetTree (param, chainId, 0);
10156                             usrTree = GetTree (param, chainId, 1); /* use as scratch space */
10157                             }
10158                         else
10159                             {
10160                             /* relaxed clock params */
10161                             theTree = GetTree (modelSettings[param->relParts[0]].brlens, chainId, 0);
10162                             usrTree = GetTree (modelSettings[param->relParts[0]].brlens, chainId, 1);
10163                             }
10164                         CopyToTreeFromTree (usrTree, theTree);
10165                         if (param->paramType == P_SPECIESTREE)
10166                             thePolyTree = AllocatePolyTree(numSpecies);
10167                         else
10168                             thePolyTree = AllocatePolyTree (numTaxa);
10169                         CopyToPolyTreeFromPolyTree (thePolyTree, userTree[treeIndex]);
10170                         if (param->paramType == P_SPECIESTREE)
10171                             {
10172                             ResetIntNodeIndices(thePolyTree);
10173                             }
10174                         else
10175                             {
10176                             PrunePolyTree (thePolyTree);
10177                             ResetTipIndices(thePolyTree);
10178                             }
10179                         RandResolve (NULL, thePolyTree, &globalSeed, theTree->isRooted);
10180                         GetPolyDownPass(thePolyTree);
10181                         ResetIntNodeIndices(thePolyTree);
10182                         if (param->paramType == P_SPECIESTREE)
10183                             {
10184                             ret=CopyToSpeciesTreeFromPolyTree (usrTree, thePolyTree);
10185                             }
10186                         else
10187                             ret=CopyToTreeFromPolyTree (usrTree, thePolyTree);
10188                         FreePolyTree (thePolyTree);
10189                         if (ret==ERROR)
10190                             return ERROR;
10191                         }
10192                     else
10193                         {
10194                         /* param->paramType == P_POPSIZE */
10195                         theTree = GetTree (modelSettings[param->relParts[0]].speciesTree, chainId, 0);
10196                         usrTree = GetTree (modelSettings[param->relParts[0]].speciesTree, chainId, 1);
10197                         CopyToTreeFromTree (usrTree, theTree);
10198                         thePolyTree = AllocatePolyTree(numSpecies);
10199                         CopyToPolyTreeFromPolyTree (thePolyTree, userTree[treeIndex]);
10200                         ResetIntNodeIndices(thePolyTree);
10201                         RandResolve (NULL, thePolyTree, &globalSeed, theTree->isRooted);
10202                         CopyToSpeciesTreeFromPolyTree (usrTree, thePolyTree);
10203                         FreePolyTree (thePolyTree);
10204                         }
10205                     if (param->paramType == P_TOPOLOGY)
10206                         {
10207                         if (theTree->checkConstraints == YES && CheckSetConstraints (usrTree) == ERROR)
10208                             {
10209                             MrBayesPrint ("%s   Could not set the constraints for topology parameter '%s'\n", spacer, param->name);
10210                             return (ERROR);
10211                             }
10212                         if (ResetTopologyFromTree (theTree, usrTree) == ERROR)
10213                             {
10214                             MrBayesPrint ("%s   Could not set the topology parameter '%s'\n", spacer, param->name);
10215                             return (ERROR);
10216                             }
10217                         if (theTree->checkConstraints == YES && CheckSetConstraints (theTree)==ERROR)
10218                             {
10219                             MrBayesPrint ("%s   Could not set the constraints for topology parameter '%s'\n", spacer, param->name);
10220                             return (ERROR);
10221                             }
10222                         FillTopologySubParams (param, chainId, 0, &globalSeed);
10223                         //MrBayesPrint ("%s   Branch lengths and relaxed clock subparameters of a parameter '%s' are reset.\n", spacer, param->name);
10224                         if (param->paramId == TOPOLOGY_SPECIESTREE)
10225                             FillSpeciesTreeParams(&globalSeed, chainId, chainId+1);
10226                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10227                         }
10228                     else if (param->paramType == P_BRLENS)
10229                         {
10230                         if (usrTree->allDownPass[0]->length == 0.0 && param->paramId != BRLENS_CLOCK_FOSSIL)
10231                             {
10232                             MrBayesPrint ("%s   User tree '%s' does not have branch lengths so it cannot be used in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10233                             return (ERROR);
10234                             }
10235                         if (AreTopologiesSame (theTree, usrTree) == NO)
10236                             {
10237                             MrBayesPrint ("%s   Topology of user tree '%s' wrong in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10238                             return (ERROR);
10239                             }
10240                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10241                         /* reset node depths to ensure that non-dated tips have node depth 0.0 */
10242                         /* if (usrTree->isClock == YES)
10243                             SetNodeDepths(usrTree);  */
10244                         if (ResetBrlensFromTree (theTree, usrTree) == ERROR)
10245                             {
10246                             MrBayesPrint ("%s   Could not set parameter '%s' from user tree '%s'\n", spacer, param->name, userTree[treeIndex]->name);
10247                             return (ERROR);
10248                             }
10249                         if (theTree->isClock == YES && modelParams[theTree->relParts[0]].treeAgePr.prior == fixed)
10250                             {
10251                             if (!strcmp(modelParams[theTree->relParts[0]].clockPr,"Uniform") ||
10252                                 !strcmp(modelParams[theTree->relParts[0]].clockPr,"Birthdeath") ||
10253                                 !strcmp(modelParams[theTree->relParts[0]].clockPr,"Fossilization"))
10254                                 ResetRootHeight (theTree, modelParams[theTree->relParts[0]].treeAgePr.priorParams[0]);
10255                             }
10256                         /* the test will find suitable clock rate and ages of nodes in theTree */
10257                         if (theTree->isClock == YES && IsClockSatisfied (theTree,0.001) == NO)
10258                             {
10259                             MrBayesPrint ("%s   Non-calibrated tips are not at the same level after setting up starting tree branch lengths(%s) from user tree '%s'.\n",
10260                                           spacer, param->name, userTree[treeIndex]->name);
10261                             ShowNodes(theTree->root,0,YES);
10262                             return (ERROR);
10263                             }
10264                         if (theTree->isCalibrated == YES && IsCalibratedClockSatisfied (theTree, &minRate,&maxRate, 0.001) == NO)
10265                             {
10266                             MrBayesPrint ("%s   Problem setting calibrated tree parameters\n", spacer);
10267                             return (ERROR);
10268                             }
10269                         if (theTree->isCalibrated == YES && !strcmp(modelParams[theTree->relParts[0]].clockRatePr, "Fixed"))
10270                             {
10271                             clockRate = modelParams[theTree->relParts[0]].clockRateFix;
10272                             if ((clockRate < minRate && AreDoublesEqual (clockRate, minRate , 0.001) == NO) || (clockRate > maxRate && AreDoublesEqual (clockRate, maxRate , 0.001) == NO))
10273                                 {
10274                                 MrBayesPrint("%s   Fixed branch lengths do not satisfy fixed clockrate\n", spacer);
10275                                 return (ERROR);
10276                                 }
10277                             }
10278                         theTree->fromUserTree=YES;
10279 
10280                         FillBrlensSubParams (param, chainId, 0);
10281                         //MrBayesPrint ("%s   Rrelaxed clock subparamiters of a parameter '%s' are reset.\n", spacer, param->name);
10282                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10283                         if (param->paramId == BRLENS_CLOCK_SPCOAL)
10284                             FillSpeciesTreeParams(&globalSeed, chainId, chainId+1);
10285                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10286                         }
10287                     else if (param->paramType == P_CPPEVENTS || param->paramType == P_TK02BRANCHRATES ||
10288                              param->paramType == P_IGRBRANCHRATES || param->paramType == P_MIXEDBRCHRATES)
10289                         {
10290                         if (theTree->isCalibrated == YES && theTree->fromUserTree == NO)
10291                             { /* if theTree is not set from user tree then we can not garanty that branch lengths will stay the same
10292                                  by the time we start mcmc run because of clockrate adjustment. */
10293                             MrBayesPrint ("%s    Set starting values for branch lengths first before setting starting values of relaxed parameters!\n", spacer);
10294                             return (ERROR);
10295                             }
10296                         if (theTree->isCalibrated == NO && IsClockSatisfied (usrTree, 0.001) == NO) // user tree is not calibrated so do not check it if calibration is in place
10297                             {
10298                             MrBayesPrint ("%s   Branch lengths of the user tree '%s' do not satisfy clock in setting parameter '%s'\n", spacer, userTree[treeIndex], param->name);
10299                             ShowNodes(usrTree->root,0,YES);
10300                             return (ERROR);
10301                             }
10302                         if (AreTopologiesSame (theTree, usrTree) == NO)
10303                             {
10304                             MrBayesPrint ("%s   Topology of user tree '%s' is wrong in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10305                             return (ERROR);
10306                             }
10307                         if (SetRelaxedClockParam (param, chainId, 0, userTree[treeIndex]) == ERROR)
10308                             {
10309                             MrBayesPrint ("%s   Could not set parameter '%s' from user tree '%s'\n", spacer, param->name, userTree[treeIndex]->name);
10310                             return (ERROR);
10311                             }
10312                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10313                         }
10314                     else if (param->paramType == P_POPSIZE)
10315                         {
10316                         if (AreTopologiesSame (theTree, usrTree) == NO)
10317                             {
10318                             MrBayesPrint ("%s   Topology of user tree '%s' is wrong in setting parameter '%s'\n", spacer, userTree[treeIndex]->name, param->name);
10319                             return (ERROR);
10320                             }
10321                         if (SetPopSizeParam (param, chainId, 0, userTree[treeIndex]) == ERROR)
10322                             {
10323                             MrBayesPrint ("%s   Could not set parameter '%s' from user tree '%s'\n", spacer, param->name, userTree[treeIndex]->name);
10324                             return (ERROR);
10325                             }
10326                         }
10327                     else if (param->paramType == P_SPECIESTREE)
10328                         {
10329                         if (IsSpeciesTreeConsistent (usrTree, chainId) == NO)
10330                             {
10331                             MrBayesPrint ("%s   User-specified species tree '%s' is inconsistent with gene trees\n", spacer, userTree[treeIndex]->name);
10332                             return (ERROR);
10333                             }
10334                         if (CopyToTreeFromTree (theTree, usrTree) == ERROR)
10335                             {
10336                             MrBayesPrint ("%s   Could not set the species tree parameter '%s'\n", spacer, param->name);
10337                             return (ERROR);
10338                             }
10339                         //assert (IsTreeConsistent(param, chainId, 0) == YES);
10340                         }
10341                     }
10342                 }
10343             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10344             }
10345         }
10346     else if (expecting == Expecting(LEFTCURL))
10347         {
10348         /* we are still assembling the parameter name */
10349         SafeStrcat (&tempName, tkn);
10350         expecting = Expecting(NUMBER) | Expecting(ALPHA) | Expecting(LEFTPAR) | Expecting(EQUALSIGN);
10351         }
10352     else if (expecting == Expecting(RIGHTCURL))
10353         {
10354         /* we are still assembling the parameter name */
10355         SafeStrcat (&tempName, tkn);
10356         foundComma = NO; /*! if there was a comma in the partition part, we should reset this variable. Otherwise we can't parse something like A{1,2}(3,4) */
10357         expecting = Expecting(LEFTPAR) | Expecting(EQUALSIGN);
10358         }
10359     else if (expecting == Expecting(LEFTPAR))
10360         {
10361         if (foundEqual == NO)
10362             {
10363             foundName = YES;    /* we found the name */
10364             /* we will be reading in run and chain indices */
10365             expecting = Expecting(NUMBER) | Expecting(COMMA);
10366             }
10367         else
10368             {
10369             expecting = Expecting(NUMBER);
10370             expecting |= Expecting(DASH);
10371             }
10372         }
10373     else if (expecting == Expecting(DASH))
10374         {
10375         foundDash = YES;
10376         expecting = Expecting(NUMBER);
10377         }
10378     else if (expecting == Expecting(NUMBER))
10379         {
10380         if (foundName == NO)
10381             {
10382             /* we are still assembling the parameter name */
10383             SafeStrcat (&tempName, tkn);
10384             expecting = Expecting(COMMA) | Expecting(LEFTPAR) | Expecting(RIGHTCURL) | Expecting(EQUALSIGN);
10385             }
10386         else if (foundEqual == YES)
10387             {
10388             theValueMin = param->min;
10389             theValueMax = param->max;
10390 
10391             /* we are reading in a parameter value */
10392             if (param->paramType==P_OMEGA && nValuesRead==numExpectedValues && useSubvalues == NO)
10393                 {
10394                 /* continue with subvalues */
10395                 nValuesRead = 0;
10396                 numExpectedValues = param->nSubValues/2;
10397                 useSubvalues = YES;
10398                 theValueMin = ETA;
10399                 theValueMax = 1.0;
10400                 }
10401             if (param->paramType==P_OMEGA && nValuesRead==numExpectedValues && useSubvalues == NO)
10402                 {
10403                 /* continue with subvalues */
10404                 nValuesRead = 0;
10405                 numExpectedValues = param->nSubValues/2;
10406                 useSubvalues = YES;
10407                 theValueMin = ETA;
10408                 theValueMax = 1.0;
10409                 }
10410             if (param->nIntValues > 0 && nValuesRead==numExpectedValues && useIntValues == NO)
10411                 {
10412                 /* continue with intValues */
10413                 nValuesRead = 0;
10414                 numExpectedValues = param->nIntValues;
10415                 useIntValues = YES;
10416                 }
10417             if (param->paramType==P_PI && modelSettings[param->relParts[0]].dataType == STANDARD && param->paramId != SYMPI_EQUAL
10418                 && nValuesRead==numExpectedValues && useStdStateFreqs == NO)
10419                 {
10420                 /* we have read alpha_symdir, continue with multistate char state freqs */
10421                 nValuesRead = 0;
10422                 numExpectedValues = param->nStdStateFreqs;
10423                 if (param->hasBinaryStd == YES)
10424                     numExpectedValues -= 2 * modelSettings[param->relParts[0]].numBetaCats;
10425                 useStdStateFreqs = YES;
10426                 theValueMin = ETA;
10427                 theValueMax = 1.0;
10428                 }
10429             nValuesRead++;
10430             if (nValuesRead > numExpectedValues)
10431                 {
10432                 if (param->paramType == P_OMEGA)
10433                     MrBayesPrint ("%s   Only %d values were expected for parameter '%s'\n", spacer, param->nValues+param->nSubValues/2, param->name);
10434                 else if (param->nIntValues > 0)
10435                     MrBayesPrint ("%s   Only %d values were expected for parameter '%s'\n", spacer, param->nValues+param->nIntValues, param->name);
10436                 else
10437                     MrBayesPrint ("%s   Only %d values were expected for parameter '%s'\n", spacer, numExpectedValues, param->name);
10438                 return (ERROR);
10439                 }
10440             if (useIntValues == YES)
10441                 sscanf (tkn, "%d", &tempInt);
10442             else
10443                 sscanf (tkn, "%lf", &tempFloat);
10444             if (foundDash == YES)
10445                 {
10446                 if (useIntValues == YES)
10447                     tempInt = -tempInt;
10448                 else
10449                     tempFloat = -tempFloat;
10450                 foundDash = NO;
10451                 }
10452             if (useIntValues == NO && (tempFloat < theValueMin || tempFloat > theValueMax))
10453                 {
10454                 MrBayesPrint ("%s   The value is out of range (min = %lf; max = %lf)\n", spacer, theValueMin, theValueMax);
10455                 return (ERROR);
10456                 }
10457             for (i=0; i<chainParams.numRuns; i++)
10458                 {
10459                 if (runIndex != -1 && runIndex != i)
10460                     continue;
10461                 for (j=0; j<chainParams.numChains; j++)
10462                     {
10463                     if (chainIndex != -1 && chainIndex != j)
10464                         continue;
10465                     if (useIntValues == YES)
10466                         {
10467                         GetParamIntVals (param, i*chainParams.numChains+j, 0)[nValuesRead-1] = tempInt;
10468                         }
10469                     else
10470                         {
10471                         if (useSubvalues == NO && useStdStateFreqs == NO)
10472                             theValue = GetParamVals (param, i*chainParams.numChains+j, 0);
10473                         else if (useSubvalues == YES)
10474                             theValue = GetParamSubVals (param, i*chainParams.numChains+j, 0);
10475                         else if (useStdStateFreqs == YES)
10476                             {
10477                             theValue = GetParamStdStateFreqs (param, i*chainParams.numChains+j, 0);
10478                             if (param->hasBinaryStd == YES)
10479                                 theValue += 2 * modelSettings[param->relParts[0]].numBetaCats;
10480                             }
10481                         else
10482                             return (ERROR);
10483                         if (param->paramType == P_CLOCKRATE)
10484                             {
10485                             if (UpdateClockRate(tempFloat, i*chainParams.numChains+j) == ERROR)
10486                                 {
10487                                 return (ERROR);
10488                                 }
10489                             }
10490                         theValue[nValuesRead-1] = tempFloat;
10491                         }
10492                     }
10493                 }
10494             expecting = Expecting (COMMA) | Expecting(RIGHTPAR);
10495             }
10496         else /* if (foundEqual == NO) */
10497             {
10498             sscanf (tkn, "%d", &tempInt);
10499             if (foundComma == NO)
10500                 {
10501                 if (tempInt <= 0 || tempInt > chainParams.numRuns)
10502                     {
10503                     MrBayesPrint ("%s   Run index is out of range (min=1; max=%d)\n", spacer, chainParams.numRuns);
10504                     return (ERROR);
10505                     }
10506                 runIndex = tempInt - 1;
10507                 expecting = Expecting(COMMA);
10508                 }
10509             else
10510                 {
10511                 if (tempInt <= 0 || tempInt > chainParams.numChains)
10512                     {
10513                     MrBayesPrint ("%s   Chain index is out of range (min=1; max=%d)\n", spacer, chainParams.numChains);
10514                     return (ERROR);
10515                     }
10516                 chainIndex = tempInt - 1;
10517                 foundComma = NO;
10518                 expecting = Expecting(RIGHTPAR);
10519                 }
10520             }
10521         }
10522     else if (expecting == Expecting(COMMA))
10523         {
10524         if (foundEqual == YES)
10525             {
10526             /* we expect another parameter value */
10527             expecting = Expecting(NUMBER);
10528             }
10529         else /* if (foundEqual == NO) */
10530             {
10531             /* we will be reading in chain index, if present */
10532             foundComma = YES;
10533             expecting = Expecting(RIGHTPAR) | Expecting(NUMBER);
10534             /* if the comma is in a list of partitions (so between { and }) we have to add the comma to the parameter name */
10535             if (param == NULL && strchr(tempName, '}')==NULL && strchr(tempName, '{')!=NULL)
10536               SafeStrcat (&tempName, ",");
10537             }
10538         }
10539     else if (expecting == Expecting(RIGHTPAR))
10540         {
10541         if (foundEqual == NO)
10542             {
10543             /* this is the end of the run and chain specification */
10544             expecting = Expecting(EQUALSIGN);
10545             }
10546         else /* if (foundEqual == YES) */
10547             {
10548             /* this is the end of the parameter values */
10549             if (nValuesRead != numExpectedValues)
10550                 {
10551                 MrBayesPrint ("%s   Expected %d values but only found %d values for parameter '%s'\n", spacer, numExpectedValues, nValuesRead, param->name);
10552                 return (ERROR);
10553                 }
10554             /* Post processing needed for some parameters */
10555             /* FIXME: param is NULL here (from clang static analyzer) */
10556             if (param->paramType == P_SHAPE || param->paramType == P_CORREL)
10557                 {
10558                 for (i=0; i<chainParams.numRuns; i++)
10559                     {
10560                     if (runIndex != -1 && runIndex != i)
10561                         continue;
10562                     for (j=0; j<chainParams.numChains; j++)
10563                         {
10564                         if (chainIndex != -1 && chainIndex != j)
10565                             continue;
10566                         value = GetParamVals(param,i*chainParams.numChains+j,0);
10567                         subValue = GetParamSubVals(param,i*chainParams.numChains+j,0);
10568                         if (param->paramType == P_SHAPE && !strncmp(param->name, "Alpha", 5))
10569                             {
10570                             if (DiscreteGamma (subValue, value[0], value[0], param->nSubValues, 0) == ERROR)
10571                                 return (ERROR);
10572                             }
10573                         else if (param->paramType == P_SHAPE && !strncmp(param->name, "Sigma", 5))
10574                             {
10575                             if( DiscreteLogNormal(subValue, value[0], param->nSubValues, 1) == ERROR)
10576                                 return (ERROR);
10577                             }
10578                         else if (param->paramType == P_CORREL)
10579                             {
10580                             if (AutodGamma (subValue, value[0], (int)(sqrt(param->nSubValues) + 0.5)) == ERROR)
10581                                 return (ERROR);
10582                             }
10583                         }
10584                     }
10585                 }
10586             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10587             }
10588         }
10589     else if (expecting == Expecting(EQUALSIGN))
10590         {
10591         foundEqual = YES;
10592         foundName = YES;
10593 
10594         /* we now know that the name is complete; try to find the parameter with this name (case insensitive) */
10595         /* FIXME: tempName is NULL? (from clang static analyzer) */
10596         for (i=0; i<(int)strlen(tempName); i++)
10597             tempName[i] = (char)(tolower(tempName[i]));
10598 
10599         /* first check exact matches */
10600         nMatches = j = 0;
10601         for (i=0; i<numParams; i++)
10602             {
10603             param = &params[i];
10604             SafeStrcpy (&temp, param->name);
10605             for (k=0; k<(int)(strlen(temp)); k++)
10606                 temp[k] = (char)(tolower(temp[k]));
10607             if (strcmp(tempName,temp) == 0)
10608                 {
10609                 j = i;
10610                 nMatches++;
10611                 }
10612             }
10613         /* now check unambiguous abbreviation matches */
10614         if (nMatches == 0)
10615             {
10616             nMatches = j = 0;
10617             for (i=0; i<numParams; i++)
10618                 {
10619                 param = &params[i];
10620                 SafeStrcpy (&temp, param->name);
10621                 for (k=0; k<(int)strlen(temp); k++)
10622                     temp[k] = (char)(tolower(temp[k]));
10623                 if (strncmp(tempName,temp,strlen(tempName)) == 0)
10624                     {
10625                     j = i;
10626                     nMatches++;
10627                     }
10628                 }
10629             }
10630 
10631         if (nMatches == 0)
10632             {
10633             extern char *tokenP;
10634             MrBayesPrint ("%s   Could not find parameter '%s': ignoring values\n", spacer, tempName);
10635             while (*tokenP && *tokenP++!=')') {};
10636             expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10637             return (*tokenP ? NO_ERROR:ERROR);
10638             }
10639         else if (nMatches > 1)
10640             {
10641             MrBayesPrint ("%s   Several parameters matched the abbreviated name '%s'\n", spacer, tempName);
10642             return (ERROR);
10643             }
10644 
10645         param = &params[j];
10646         if (param->printParam == NO && !(param->paramType == P_TOPOLOGY && strcmp(modelParams[param->relParts[0]].topologyPr,"Fixed")!=0)
10647                                     && !(param->paramType == P_CPPEVENTS)
10648                                     && !(param->paramType == P_TK02BRANCHRATES)
10649                                     && !(param->paramType == P_IGRBRANCHRATES)
10650                                     && !(param->paramType == P_MIXEDBRCHRATES)
10651                                     && !(param->paramType == P_POPSIZE && param->nValues > 1))
10652             {
10653             MrBayesPrint ("%s   The parameter '%s' is fixed so the starting value cannot be set\n", spacer, param->name);
10654             return (ERROR);
10655             }
10656         if (param->paramType == P_BRLENS || param->paramType == P_TOPOLOGY || param->paramType == P_CPPEVENTS ||
10657             param->paramType == P_TK02BRANCHRATES || param->paramType == P_IGRBRANCHRATES || param->paramType == P_MIXEDBRCHRATES ||
10658             param->paramType == P_SPECIESTREE || (param->paramType == P_POPSIZE && param->nValues > 1))
10659             {
10660             /* all these parameters are set from a tree */
10661             expecting = Expecting (ALPHA);
10662             }
10663         else
10664             /* run of the mill character */
10665             {
10666             theValueMin = param->min;
10667             theValueMax = param->max;
10668             if ((param->paramType == P_PI && modelParams[param->relParts[0]].dataType != STANDARD) ||
10669                 param->paramType == P_MIXTURE_RATES)
10670                 {
10671                 useSubvalues = YES;
10672                 useIntValues = NO;
10673                 numExpectedValues = param->nSubValues;
10674                 }
10675             else if (param->nValues == 0 && param->nIntValues > 0)
10676                 {
10677                 useSubvalues = NO;
10678                 useIntValues = YES;
10679                 numExpectedValues = param->nIntValues;
10680                 }
10681             else if (param->nValues > 0)
10682                 {
10683                 useSubvalues = NO;
10684                 useIntValues = NO;
10685                 numExpectedValues = param->nValues;
10686                 }
10687             else
10688                 {
10689                 MrBayesPrint ("%s   Not expecting any values for parameter '%s'\n", spacer, param->name);
10690                 return (ERROR);
10691                 }
10692             nValuesRead = 0;
10693             expecting = Expecting(LEFTPAR);
10694             }
10695         }
10696     else
10697         return (ERROR);
10698 
10699     SAFEFREE (temp);
10700     return (NO_ERROR);
10701 }
10702 
10703 
DoUnlink(void)10704 int DoUnlink (void)
10705 {
10706     int         i, j;
10707 
10708     MrBayesPrint ("%s   Unlinking\n", spacer);
10709 
10710     /* update status of linkTable */
10711     for (j=0; j<NUM_LINKED; j++)
10712         {
10713         for (i=0; i<numCurrentDivisions; i++)
10714             {
10715             if (tempLinkUnlink[j][i] == YES)
10716                 {
10717                 linkTable[j][i] = ++linkNum;
10718                 }
10719             }
10720         }
10721 
10722 #   if 0
10723     for (j=0; j<NUM_LINKED; j++)
10724         {
10725         MrBayesPrint ("%s   ", spacer);
10726         for (i=0; i<numCurrentDivisions; i++)
10727             MrBayesPrint ("%d", linkTable[j][i]);
10728         MrBayesPrint ("\n");
10729         }
10730 #   endif
10731 
10732     /* reinitialize the temporary table */
10733     for (j=0; j<NUM_LINKED; j++)
10734         for (i=0; i<numCurrentDivisions; i++)
10735             tempLinkUnlink[j][i] = NO;
10736 
10737     /* set up parameters and moves */
10738     if (SetUpAnalysis (&globalSeed) == ERROR)
10739         return (ERROR);
10740 
10741     return (NO_ERROR);
10742 }
10743 
10744 
DoShowMcmcTrees(void)10745 int DoShowMcmcTrees (void)
10746 {
10747     int         run, chain, chainIndex, i;
10748     Tree        *t;
10749 
10750     for (run=0; run<chainParams.numRuns; run++)
10751         {
10752         for (chain=0; chain<chainParams.numChains; chain++)
10753             {
10754             chainIndex = run*chainParams.numChains + chain;
10755             for (i=0; i<numTrees; i++)
10756                 {
10757                 t = GetTreeFromIndex (i, chainIndex, 0);
10758                 if (t->isRooted == YES)
10759                     MrBayesPrint ("\n   Tree '%s' [rooted]:\n\n", t->name);
10760                 else
10761                     MrBayesPrint ("\n   Tree '%s' [unrooted]:\n\n", t->name);
10762                 if (ShowTree (t) == ERROR)
10763                     return (ERROR);
10764                 else
10765                     MrBayesPrint ("\n");
10766                 }
10767             }
10768         }
10769 
10770     return (NO_ERROR);
10771 }
10772 
10773 
DoShowModel(void)10774 int DoShowModel (void)
10775 {
10776     if (defMatrix == NO)
10777         {
10778         MrBayesPrint ("%s   A matrix must be specified before the model can be defined\n", spacer);
10779         return (ERROR);
10780         }
10781 
10782     if (ShowModel() == ERROR)
10783         return (ERROR);
10784 
10785     return (NO_ERROR);
10786 }
10787 
10788 
DoShowMoves(void)10789 int DoShowMoves (void)
10790 {
10791     if (defMatrix == NO)
10792         {
10793         MrBayesPrint ("%s   A matrix must be specified before moves can be assigned\n", spacer);
10794         return (ERROR);
10795         }
10796 
10797     MrBayesPrint ("%s   Moves that will be used by MCMC sampler (rel. proposal prob. > 0.0):\n\n", spacer);
10798     if (ShowMoves(YES) == ERROR)
10799         return (ERROR);
10800 
10801     if (showmovesParams.allavailable == YES)
10802         {
10803         MrBayesPrint ("%s   Other available moves (rel. proposal prob. = 0.0):\n\n", spacer);
10804         if (ShowMoves(NO) == ERROR)
10805             return (ERROR);
10806         }
10807     else
10808         MrBayesPrint ("%s   Use 'Showmoves allavailable=yes' to see a list of all available moves\n", spacer);
10809 
10810     return (NO_ERROR);
10811 }
10812 
10813 
DoShowmovesParm(char * parmName,char * tkn)10814 int DoShowmovesParm (char *parmName, char *tkn)
10815 {
10816     char    tempStr[100];
10817 
10818     if (expecting == Expecting(PARAMETER))
10819         {
10820         expecting = Expecting(EQUALSIGN);
10821         }
10822     else
10823         {
10824         /* set Allavailable **********************************************************/
10825         if (!strcmp(parmName, "Allavailable"))
10826             {
10827             if (expecting == Expecting(EQUALSIGN))
10828                 expecting = Expecting(ALPHA);
10829             else if (expecting == Expecting(ALPHA))
10830                 {
10831                 if (IsArgValid(tkn, tempStr) == NO_ERROR)
10832                     {
10833                     if (!strcmp(tempStr, "Yes"))
10834                         showmovesParams.allavailable = YES;
10835                     else
10836                         showmovesParams.allavailable = NO;
10837                     }
10838                 else
10839                     {
10840                     MrBayesPrint ("%s   Invalid argument for allavailable\n", spacer);
10841                     return (ERROR);
10842                     }
10843                 expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
10844                 }
10845             else
10846                 return (ERROR);
10847             }
10848         else
10849             return (ERROR);
10850 
10851         }
10852 
10853     return (NO_ERROR);
10854 }
10855 
10856 
DoShowParams(void)10857 int DoShowParams (void)
10858 {
10859     if (defMatrix == NO)
10860         {
10861         MrBayesPrint ("%s   A matrix must be specified before model parameters can be shown\n", spacer);
10862         return (ERROR);
10863         }
10864 
10865     if (ShowParameters(YES, YES, YES) == ERROR)
10866         return (ERROR);
10867 
10868     return (NO_ERROR);
10869 }
10870 
10871 
10872 /*------------------------------------------------------------------------
10873 |
10874 |   FillNormalParams: Allocate and fill in non-tree parameters
10875 |
10876 -------------------------------------------------------------------------*/
FillNormalParams(RandLong * seed,int fromChain,int toChain)10877 int FillNormalParams (RandLong *seed, int fromChain, int toChain)
10878 {
10879     int         i, j, k, chn, tempInt, *intValue;
10880     MrBFlt      *bs, *value, *subValue, scaler;
10881     Tree        *tree;
10882     Param       *p;
10883     ModelInfo   *m;
10884     ModelParams *mp;
10885 
10886     /* fill in values for nontree params for state 0 of chains */
10887     for (chn=fromChain; chn<toChain; chn++)
10888         {
10889         for (k=0; k<numParams; k++)
10890             {
10891             p  = &params[k];
10892             mp = &modelParams[p->relParts[0]];
10893             m  = &modelSettings[p->relParts[0]];
10894 
10895             /* find model settings and nStates, pInvar, invar cond likes */
10896 
10897             value = GetParamVals (p, chn, 0);
10898             subValue = GetParamSubVals (p, chn, 0);
10899             intValue = GetParamIntVals (p, chn, 0);
10900 
10901             if (p->paramType == P_TRATIO)
10902                 {
10903                 /* Fill in tratios **************************************************************************************/
10904                 if (p->paramId == TRATIO_DIR)
10905                     value[0] = 1.0;
10906                 else if (p->paramId == TRATIO_FIX)
10907                     value[0] = mp->tRatioFix;
10908                 }
10909             else if (p->paramType == P_REVMAT)
10910                 {
10911                 /* Fill in revMat ***************************************************************************************/
10912                 /* rates are stored in order, AC or AR first, using the Dirichlet parameterization */
10913                 if (p->paramId == REVMAT_DIR)
10914                     {
10915                     for (j=0; j<p->nValues; j++)
10916                         value[j] = 1.0 / (MrBFlt) (p->nValues);
10917                     }
10918                 else if (p->paramId == REVMAT_FIX)
10919                     {
10920                     scaler = 0.0;
10921                     if (m->dataType == PROTEIN)
10922                         {
10923                         for (j=0; j<190; j++)
10924                             scaler += (value[j] = mp->aaRevMatFix[j]);
10925                         for (j=0; j<190; j++)
10926                             value[j] /= scaler;
10927                         }
10928                     else
10929                         {
10930                         for (j=0; j<6; j++)
10931                             scaler += (value[j] = mp->revMatFix[j]);
10932                         for (j=0; j<6; j++)
10933                             value[j] /= scaler;
10934                         }
10935                     }
10936                 else if (p->paramId == REVMAT_MIX)
10937                     {
10938                     for (j=0; j<6; j++)
10939                         {
10940                         value[j] = 1.0 / 6.0;
10941                         intValue[j] = 0;
10942                         }
10943                     }
10944                 }
10945             else if (p->paramType == P_OMEGA)
10946                 {
10947                 /* Fill in omega ****************************************************************************************/
10948                 if (p->nValues == 1)
10949                     {
10950                     if (p->paramId == OMEGA_DIR)
10951                         value[0] = 1.0;
10952                     else if (p->paramId == OMEGA_FIX)
10953                         value[0] = mp->omegaFix;
10954                     }
10955                 else
10956                     {
10957                     if (!strcmp(mp->omegaVar, "Ny98"))
10958                         {
10959                         if (p->paramId == OMEGA_BUD || p->paramId == OMEGA_BUF || p->paramId == OMEGA_BED ||
10960                             p->paramId == OMEGA_BEF || p->paramId == OMEGA_BFD || p->paramId == OMEGA_BFF)
10961                             value[0] = RandomNumber(seed);
10962                         else if (p->paramId == OMEGA_FUD || p->paramId == OMEGA_FUF || p->paramId == OMEGA_FED ||
10963                                  p->paramId == OMEGA_FEF || p->paramId == OMEGA_FFD || p->paramId == OMEGA_FFF)
10964                             value[0] = mp->ny98omega1Fixed;
10965                         value[1] = 1.0;
10966                         if (p->paramId == OMEGA_BUD || p->paramId == OMEGA_BUF || p->paramId == OMEGA_FUD ||
10967                             p->paramId == OMEGA_FUF)
10968                             value[2] = mp->ny98omega3Uni[0] + RandomNumber(seed) * (mp->ny98omega3Uni[1] - mp->ny98omega3Uni[0]);
10969                         else if (p->paramId == OMEGA_BED || p->paramId == OMEGA_BEF || p->paramId == OMEGA_FED ||
10970                                  p->paramId == OMEGA_FEF)
10971                             value[2] =  (1.0 - (1.0/mp->ny98omega3Exp) * log(RandomNumber(seed)));
10972                         else
10973                             value[2] = mp->ny98omega3Fixed;
10974                         if (p->paramId == OMEGA_BUD || p->paramId == OMEGA_BED || p->paramId == OMEGA_BFD ||
10975                             p->paramId == OMEGA_FUD || p->paramId == OMEGA_FED || p->paramId == OMEGA_FFD)
10976                             {
10977                             subValue[3] = mp->codonCatDir[0];
10978                             subValue[4] = mp->codonCatDir[1];
10979                             subValue[5] = mp->codonCatDir[2];
10980                             DirichletRandomVariable (&subValue[3], &subValue[0], 3, seed);
10981                             }
10982                         else
10983                             {
10984                             subValue[0] = mp->codonCatFreqFix[0];
10985                             subValue[1] = mp->codonCatFreqFix[1];
10986                             subValue[2] = mp->codonCatFreqFix[2];
10987                             subValue[3] = 0.0;
10988                             subValue[4] = 0.0;
10989                             subValue[5] = 0.0;
10990                             }
10991                         }
10992                     else if (!strcmp(mp->omegaVar, "M3"))
10993                         {
10994                         if (p->paramId == OMEGA_FD || p->paramId == OMEGA_FF)
10995                             {
10996                             value[0] = mp->m3omegaFixed[0];
10997                             value[1] = mp->m3omegaFixed[1];
10998                             value[2] = mp->m3omegaFixed[2];
10999                             }
11000                         else
11001                             {
11002                             value[0] =  0.1;
11003                             value[1] =  1.0;
11004                             value[2] =  3.0;
11005                             }
11006                         if (p->paramId == OMEGA_ED || p->paramId == OMEGA_FD)
11007                             {
11008                             subValue[3] = mp->codonCatDir[0];
11009                             subValue[4] = mp->codonCatDir[1];
11010                             subValue[5] = mp->codonCatDir[2];
11011                             DirichletRandomVariable (&subValue[3], &subValue[0], 3, seed);
11012                             }
11013                         else
11014                             {
11015                             subValue[0] = mp->codonCatFreqFix[0];
11016                             subValue[1] = mp->codonCatFreqFix[1];
11017                             subValue[2] = mp->codonCatFreqFix[2];
11018                             subValue[3] = 0.0;
11019                             subValue[4] = 0.0;
11020                             subValue[5] = 0.0;
11021                             }
11022                         }
11023                     else if (!strcmp(mp->omegaVar, "M10"))
11024                         {
11025                         if (p->paramId == OMEGA_10UUB || p->paramId == OMEGA_10UEB || p->paramId == OMEGA_10UFB ||
11026                             p->paramId == OMEGA_10EUB || p->paramId == OMEGA_10EEB || p->paramId == OMEGA_10EFB ||
11027                             p->paramId == OMEGA_10FUB || p->paramId == OMEGA_10FEB || p->paramId == OMEGA_10FFB)
11028                             {
11029                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 2] = mp->codonCatDir[0];
11030                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 3] = mp->codonCatDir[1];
11031                             DirichletRandomVariable (&subValue[mp->numM10BetaCats + mp->numM10GammaCats + 2], &subValue[mp->numM10BetaCats + mp->numM10GammaCats + 0], 2, seed);
11032                             }
11033                         else
11034                             {
11035                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 0] = mp->codonCatFreqFix[0];
11036                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 1] = mp->codonCatFreqFix[1];
11037                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 2] = 0.0;
11038                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 3] = 0.0;
11039                             }
11040 
11041                         for (i=0; i<mp->numM10BetaCats; i++)
11042                             subValue[i] = subValue[mp->numM10BetaCats + mp->numM10GammaCats + 0] / mp->numM10BetaCats;
11043                         for (i=mp->numM10BetaCats; i<mp->numM10BetaCats+mp->numM10GammaCats; i++)
11044                             subValue[i] = subValue[mp->numM10BetaCats + mp->numM10GammaCats + 1] / mp->numM10GammaCats;
11045 
11046                         if (p->paramId == OMEGA_10FUB || p->paramId == OMEGA_10FUF || p->paramId == OMEGA_10FEB ||
11047                             p->paramId == OMEGA_10FEF || p->paramId == OMEGA_10FFB || p->paramId == OMEGA_10FFF)
11048                             {
11049                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 4] = mp->m10betaFix[0];
11050                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 5] = mp->m10betaFix[1];
11051                             }
11052                         else
11053                             {
11054                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 4] = 1.0;
11055                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 5] = 1.0;
11056                             }
11057 
11058                         if (p->paramId == OMEGA_10UFB || p->paramId == OMEGA_10UFF || p->paramId == OMEGA_10EFB ||
11059                             p->paramId == OMEGA_10EFF || p->paramId == OMEGA_10FFB || p->paramId == OMEGA_10FFF)
11060                             {
11061                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 6] = mp->m10gammaFix[0];
11062                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 7] = mp->m10gammaFix[1];
11063                             }
11064                         else
11065                             {
11066                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 6] = 1.0;
11067                             subValue[mp->numM10BetaCats + mp->numM10GammaCats + 7] = 1.0;
11068                             }
11069 
11070                         BetaBreaks (subValue[mp->numM10BetaCats + mp->numM10GammaCats + 4], subValue[mp->numM10BetaCats + mp->numM10GammaCats + 5], &value[0], mp->numM10BetaCats);
11071                         if (DiscreteGamma (&value[mp->numM10BetaCats], subValue[mp->numM10BetaCats + mp->numM10GammaCats + 6],
11072                                            subValue[mp->numM10BetaCats + mp->numM10GammaCats + 7], mp->numM10GammaCats, 0) == ERROR)
11073                             return (ERROR);
11074                         for (i=0; i<mp->numM10GammaCats; i++)
11075                             value[mp->numM10BetaCats + i] += 1.0;
11076                         }
11077                     }
11078                 }
11079             else if (p->paramType == P_PI)
11080                 {
11081                 /* Fill in state frequencies ****************************************************************************/
11082                 /* note that standard chars are mainly dealt with in ProcessStdChars in mcmc.c */
11083                 if (p->paramId == SYMPI_UNI || p->paramId == SYMPI_UNI_MS)
11084                     value[0] = 1.0;
11085                 else if (p->paramId == SYMPI_EXP || p->paramId == SYMPI_EXP_MS)
11086                     value[0] = 1.0;
11087 
11088                 else if (p->paramId == SYMPI_FIX || p->paramId == SYMPI_FIX_MS)
11089                     value[0] = mp->symBetaFix;
11090 
11091                 else if (p->paramId == PI_DIR)
11092                     {
11093                     if (mp->numDirParams != mp->nStates && mp->numDirParams != 0)
11094                         {
11095                         MrBayesPrint ("%s   Mismatch between number of dirichlet parameters (%d) and the number of states (%d)\n", spacer, mp->numDirParams, m->numStates);
11096                         return ERROR;
11097                         }
11098 
11099                     /* if user has not set dirichlet parameters, go with default */
11100                     /* overall variance equals number of states */
11101                     if (mp->numDirParams == 0)
11102                         for (i=0; i<mp->nStates; i++)
11103                             value[i] = mp->stateFreqsDir[i] = 1.0;
11104                     else
11105                         for (i=0; i<m->numStates; i++)
11106                             value[i] = mp->stateFreqsDir[i];
11107 
11108                     /* now fill in subvalues */
11109                     for (i=0; i<m->numStates; i++)
11110                         subValue[i] = 1.0 / mp->nStates;
11111                     }
11112 
11113                 else if (p->paramId == PI_USER)
11114                     {
11115                     for (i=0; i<m->numStates; i++)
11116                         subValue[i] =  mp->stateFreqsFix[i];
11117                     }
11118 
11119                 else if (p->paramId == PI_FIXED)
11120                     {
11121                     if (!strcmp(mp->aaModelPr, "Fixed"))
11122                         {
11123                         if (!strcmp(mp->aaModel, "Jones"))
11124                             {
11125                             for (i=0; i<mp->nStates; i++)
11126                                 subValue[i] = jonesPi[i];
11127                             }
11128                         else if (!strcmp(mp->aaModel, "Dayhoff"))
11129                             {
11130                             for (i=0; i<mp->nStates; i++)
11131                                 subValue[i] = dayhoffPi[i];
11132                             }
11133                         else if (!strcmp(mp->aaModel, "Mtrev"))
11134                             {
11135                             for (i=0; i<mp->nStates; i++)
11136                                 subValue[i] = mtrev24Pi[i];
11137                             }
11138                         else if (!strcmp(mp->aaModel, "Mtmam"))
11139                             {
11140                             for (i=0; i<mp->nStates; i++)
11141                                 subValue[i] = mtmamPi[i];
11142                             }
11143                         else if (!strcmp(mp->aaModel, "Wag"))
11144                             {
11145                             for (i=0; i<mp->nStates; i++)
11146                                 subValue[i] = wagPi[i];
11147                             }
11148                         else if (!strcmp(mp->aaModel, "Rtrev"))
11149                             {
11150                             for (i=0; i<mp->nStates; i++)
11151                                 subValue[i] = rtrevPi[i];
11152                             }
11153                         else if (!strcmp(mp->aaModel, "Cprev"))
11154                             {
11155                             for (i=0; i<mp->nStates; i++)
11156                                 subValue[i] = cprevPi[i];
11157                             }
11158                         else if (!strcmp(mp->aaModel, "Vt"))
11159                             {
11160                             for (i=0; i<mp->nStates; i++)
11161                                 subValue[i] = vtPi[i];
11162                             }
11163                         else if (!strcmp(mp->aaModel, "Blosum"))
11164                             {
11165                             for (i=0; i<mp->nStates; i++)
11166                                 subValue[i] = blosPi[i];
11167                             }
11168                         else if (!strcmp(mp->aaModel, "LG"))
11169                             {
11170                             for (i=0; i<mp->nStates; i++)
11171                                 subValue[i] = lgPi[i];
11172                             }
11173                         }
11174                     }
11175 
11176                 else if (p->paramId == PI_EMPIRICAL)
11177                     {
11178                     if (GetEmpiricalFreqs (p->relParts, p->nRelParts) == ERROR)
11179                         return (ERROR);
11180                     for (i=0; i<mp->nStates; i++)
11181                         subValue[i] = empiricalFreqs[i];
11182                     }
11183 
11184                 else if (p->paramId == PI_EQUAL)
11185                     {
11186                     for (i=0; i<mp->nStates; i++)
11187                         subValue[i] = 1.0 / mp->nStates;
11188                     }
11189                 }
11190             else if (p->paramType == P_MIXTURE_RATES)
11191                 {
11192                 /* Fill in rates of site rate mixture ****************************************************************************/
11193 
11194                 /* We use value array for dirichlet prior parameters. We use a flat prior, so this will be a series of 1.0 values */
11195                 for (i=0; i<m->numRateCats; ++i)
11196                     value[i] = 1.0;
11197 
11198                 /* Now fill in subvalues by setting them to be equal, Note that we use rates and not rate proportions. */
11199                 for (i=0; i<m->numRateCats; ++i)
11200                     subValue[i] = 1.0;
11201                 }
11202             else if (p->paramType == P_SHAPE)
11203                 {
11204                 /* Fill in shape values ********************************************************************************/
11205                 /* first get hyperprior */
11206                 if (p->paramId == SHAPE_UNI)
11207                     {
11208                     value[0] = 1.0;
11209                     if (value[0] < mp->shapeUni[0] || value[0] > mp->shapeUni[1])
11210                         value[0] = mp->shapeUni[0] + (mp->shapeUni[1] - mp->shapeUni[0]) *  0.5;
11211                     }
11212                 else if (p->paramId == SHAPE_EXP)
11213                     value[0] = 1.0;  // was 100.0
11214                 else if (p->paramId == SHAPE_FIX)
11215                     value[0] = mp->shapeFix;
11216                 /* now fill in rates */
11217                 if (!strcmp(mp->ratesModel, "LNorm"))
11218                     {
11219                     if (DiscreteLogNormal (subValue, value[0], mp->numGammaCats, 1) == ERROR)
11220                         return (ERROR);
11221                     }
11222                 else  /* gamma rate */
11223                     {
11224                     if (DiscreteGamma (subValue, value[0], value[0], mp->numGammaCats, 0) == ERROR)
11225                         return (ERROR);
11226                     }
11227                 }
11228             else if (p->paramType == P_PINVAR)
11229                 {
11230                 /* Fill in pInvar ***************************************************************************************/
11231                 if (p->paramId == PINVAR_UNI)
11232                     value[0] = 0.0;
11233 
11234                 else if (p->paramId == PINVAR_FIX)
11235                     value[0] =  mp->pInvarFix;
11236                 }
11237             else if (p->paramType == P_CORREL)
11238                 {
11239                 /* Fill in correlation parameter of adgamma model *******************************************************/
11240                 if (p->paramId == CORREL_UNI)
11241                     value[0] = 0.0;
11242 
11243                 else if (p->paramId == CORREL_FIX)
11244                     value[0] =  mp->corrFix;
11245 
11246                 /* Fill in correlation matrices */
11247                 AutodGamma (subValue, value[0], mp->numGammaCats);
11248                 }
11249             else if (p->paramType == P_SWITCH)
11250                 {
11251                 /* Fill in switchRates for covarion model ***************************************************************/
11252                 for (j=0; j<2; j++)
11253                     {
11254                     if (p->paramId == SWITCH_UNI)
11255                         value[j] = RandomNumber(seed) * (mp->covswitchUni[1] - mp->covswitchUni[0]) + mp->covswitchUni[0];
11256 
11257                     else if (p->paramId == SWITCH_EXP)
11258                         value[j] = -(1.0/mp->covswitchExp) * log(RandomNumber(seed));
11259 
11260                     else if (p->paramId == SWITCH_FIX)
11261                         value[j] = mp->covswitchFix[j];
11262                     }
11263                 }
11264             else if (p->paramType == P_RATEMULT)
11265                 {
11266                 /* Fill in division rates *****************************************************************************/
11267                 for (j=0; j<p->nValues; j++)
11268                     {
11269                     value[j] = 1.0;
11270                     /* fill in more info about the divisions if this is a true rate multiplier
11271                        and not a base rate */
11272                     if (p->nSubValues > 0)
11273                         {
11274                         /* num uncompressed chars */
11275                         subValue[j] = (modelSettings[p->relParts[j]].numUncompressedChars);
11276                         /* Dirichlet parameters */
11277                         subValue[p->nValues + j] = modelParams[p->relParts[j]].ratePrDir;
11278                         }
11279                     }
11280                 }
11281             else if (p->paramType == P_GENETREERATE)
11282                 {
11283                 /* Fill in division rates *****************************************************************************/
11284                 for (j=0; j<p->nValues; j++)
11285                     {
11286                     value[j] = 1.0;
11287                     /* Dirichlet parameters fixed to 1.0 for now; ignored if the rate is fixed */
11288                     subValue[p->nValues + j] = 1.0;
11289                     /* Get number of uncompressed chars from tree */
11290                     tree = GetTreeFromIndex(j, 0, 0);
11291                     subValue[j] = 0.0;
11292                     for (i=0; i<tree->nRelParts; i++)  /* num uncompressed chars */
11293                         subValue[j] += modelSettings[tree->relParts[i]].numUncompressedChars;
11294                     }
11295                 }
11296             else if (p->paramType == P_SPECRATE)
11297                 {
11298                 /* Fill in speciation rates *****************************************************************************/
11299                 for (j=0; j<p->nValues; j++)
11300                     {
11301                     if (p->paramId == SPECRATE_FIX)
11302                         value[j] = mp->speciationFix;
11303                     else
11304                         value[j] = 0.1;
11305                     }
11306                 }
11307             else if (p->paramType == P_EXTRATE)
11308                 {
11309                 /* Fill in extinction rates *****************************************************************************/
11310                 for (j=0; j<p->nValues; j++)
11311                     {
11312                     if (p->paramId == EXTRATE_FIX)
11313                         value[j] = mp->extinctionFix;
11314                     else
11315                         value[j] = 0.9;
11316                     }
11317                 }
11318             else if (p->paramType == P_FOSLRATE)
11319                 {
11320                 /* Fill in fossilization rates */
11321                 for (j=0; j<p->nValues; j++)
11322                     {
11323                     if (p->paramId == FOSLRATE_FIX)
11324                         value[j] = mp->fossilizationFix;
11325                     else
11326                         value[j] = 0.1;
11327                     }
11328                 }
11329             else if (p->paramType == P_GROWTH)
11330                 {
11331                 /* Fill in growth rate ****************************************************************************************/
11332                 if (p->paramId == GROWTH_FIX)
11333                     value[0] = mp->growthFix;
11334                 else
11335                     value[0] = 1.0;
11336                 }
11337             else if (p->paramType == P_POPSIZE)
11338                 {
11339                 /* Fill in population size ****************************************************************************************/
11340                 for (j=0; j<p->nValues; j++)
11341                     {
11342                     if (p->paramId == POPSIZE_UNI)
11343                         value[j] = RandomNumber(seed) * (mp->popSizeUni[1] - mp->popSizeUni[0]) + mp->popSizeUni[0];
11344                     else if (p->paramId == POPSIZE_LOGNORMAL)
11345                         value[j] = exp(mp->popSizeLognormal[0]);
11346                     else if (p->paramId == POPSIZE_NORMAL)
11347                         value[j] = mp->popSizeNormal[0];
11348                     else if (p->paramId == POPSIZE_GAMMA)
11349                         value[j] = mp->popSizeGamma[0] / mp->popSizeGamma[1];
11350                     else if (p->paramId == POPSIZE_FIX)
11351                         value[j] = mp->popSizeFix;
11352                     }
11353                 }
11354             else if (p->paramType == P_AAMODEL)
11355                 {
11356                 /* Fill in theta ****************************************************************************************/
11357                 if (p->paramId == AAMODEL_MIX)
11358                     {
11359                     /* amino acid model ID's
11360                         AAMODEL_POISSON         0
11361                         AAMODEL_JONES           1
11362                         AAMODEL_DAY             2
11363                         AAMODEL_MTREV           3
11364                         AAMODEL_MTMAM           4
11365                         AAMODEL_WAG             5
11366                         AAMODEL_RTREV           6
11367                         AAMODEL_CPREV           7
11368                         AAMODEL_VT              8
11369                         AAMODEL_BLOSUM          9 */
11370 
11371                     /* set the amino acid model  (the meaning of the numbers is defined) */
11372                     tempInt = (int)(RandomNumber(seed) * 10);
11373                     value[0] = tempInt;
11374 
11375                     /* we need to make certain that the aa frequencies are filled in correctly */
11376                     bs = GetParamSubVals (m->stateFreq, chn, 0);
11377                     if (tempInt == AAMODEL_POISSON)
11378                         {
11379                         for (i=0; i<mp->nStates; i++)
11380                             bs[i] =  (1.0 / 20.0);
11381                         }
11382                     else if (tempInt == AAMODEL_JONES)
11383                         {
11384                         for (i=0; i<mp->nStates; i++)
11385                             bs[i] = jonesPi[i];
11386                         }
11387                     else if (tempInt == AAMODEL_DAY)
11388                         {
11389                         for (i=0; i<mp->nStates; i++)
11390                             bs[i] = dayhoffPi[i];
11391                         }
11392                     else if (tempInt == AAMODEL_MTREV)
11393                         {
11394                         for (i=0; i<mp->nStates; i++)
11395                             bs[i] = mtrev24Pi[i];
11396                         }
11397                     else if (tempInt == AAMODEL_MTMAM)
11398                         {
11399                         for (i=0; i<mp->nStates; i++)
11400                             bs[i] = mtmamPi[i];
11401                         }
11402                     else if (tempInt == AAMODEL_WAG)
11403                         {
11404                         for (i=0; i<mp->nStates; i++)
11405                             bs[i] = wagPi[i];
11406                         }
11407                     else if (tempInt == AAMODEL_RTREV)
11408                         {
11409                         for (i=0; i<mp->nStates; i++)
11410                             bs[i] = rtrevPi[i];
11411                         }
11412                     else if (tempInt == AAMODEL_CPREV)
11413                         {
11414                         for (i=0; i<mp->nStates; i++)
11415                             bs[i] = cprevPi[i];
11416                         }
11417                     else if (tempInt == AAMODEL_VT)
11418                         {
11419                         for (i=0; i<mp->nStates; i++)
11420                             bs[i] = vtPi[i];
11421                         }
11422                     else if (tempInt == AAMODEL_BLOSUM)
11423                         {
11424                         for (i=0; i<mp->nStates; i++)
11425                             bs[i] = blosPi[i];
11426                         }
11427 
11428                     for (i=0; i<p->nSubValues; i++)
11429                         {
11430                         subValue[i] = mp->aaModelPrProbs[i];
11431                         }
11432                     }
11433                 }
11434             else if (p->paramType == P_CPPRATE)
11435                 {
11436                 /* Fill in lambda (cpp rate) ********************************************************************************************/
11437                 if (p->paramId == CPPRATE_EXP)
11438                     value[0] = -(1.0/mp->cppRateExp) * log(RandomNumber(seed));
11439                 else if (p->paramId == CPPRATE_FIX)
11440                     value[0] = mp->cppRateFix;
11441                 }
11442             else if (p->paramType == P_CPPMULTDEV)
11443                 {
11444                 /* Fill in log standard deviation (for relaxed clock rate multiplier) ***********************************************************/
11445                 if (p->paramId == CPPMULTDEV_FIX)
11446                     value[0] = mp->cppMultDevFix;
11447                 }
11448             else if (p->paramType == P_CPPEVENTS)
11449                 {
11450                 /* We fill in these when we fill in tree params **************************************************************************/
11451                 }
11452             else if (p->paramType == P_TK02VAR)
11453                 {
11454                 /* Fill in variance of relaxed clock lognormal **************************************************************************/
11455                 if (p->paramId == TK02VAR_UNI)
11456                     value[0] = RandomNumber(seed) * (mp->tk02varUni[1] - mp->tk02varUni[0]) + mp->tk02varUni[0];
11457                 else if (p->paramId == TK02VAR_EXP)
11458                     value[0] = 2.0/(mp->tk02varExp);
11459                 else if (p->paramId == TK02VAR_FIX)
11460                     value[0] = mp->tk02varFix;
11461                 }
11462             else if (p->paramType == P_TK02BRANCHRATES)
11463                 {
11464                 /* We fill in these when we fill in tree params **************************************************************************/
11465                 }
11466             else if (p->paramType == P_IGRVAR)
11467                 {
11468                 /* Fill in variance of relaxed clock lognormal **************************************************************************/
11469                 if (p->paramId == IGRVAR_UNI)
11470                     value[0] = RandomNumber(seed) * (mp->igrvarUni[1] - mp->igrvarUni[0]) + mp->igrvarUni[0];
11471                 else if (p->paramId == IGRVAR_EXP)
11472                     value[0] = 1.0/(mp->igrvarExp);
11473                 else if (p->paramId == IGRVAR_FIX)
11474                     value[0] = mp->igrvarFix;
11475                 }
11476             else if (p->paramType == P_IGRBRANCHRATES)
11477                 {
11478                 /* We fill in these when we fill in tree params **************************************************************************/
11479                 }
11480             else if (p->paramType == P_MIXEDVAR)
11481                 {
11482                 /* Fill in variance of mixed relaxed clock **************************************************************************/
11483                 if (p->paramId == MIXEDVAR_UNI)
11484                     value[0] = RandomNumber(seed) * (mp->mixedvarUni[1] - mp->mixedvarUni[0]) + mp->mixedvarUni[0];
11485                 else if (p->paramId == MIXEDVAR_EXP)
11486                     value[0] = 1.0/(mp->mixedvarExp);
11487                 else if (p->paramId == MIXEDVAR_FIX)
11488                     value[0] = mp->mixedvarFix;
11489                 }
11490             else if (p->paramType == P_MIXEDBRCHRATES)
11491                 {
11492                 /* initialize the mixed relaxed clock model to TK02 or IGR */
11493                 intValue[0] = (RandomNumber(seed) <0.5) ? RCL_TK02 : RCL_IGR;
11494                 /* We fill in the rest when we fill in tree params **************************************************************************/
11495                 }
11496             else if (p->paramType == P_CLOCKRATE)
11497                 {
11498                 /* Fill in base rate of molecular clock **************************************************************************/
11499                 if (p->paramId == CLOCKRATE_FIX)
11500                     value[0] = mp->clockRateFix;
11501                 else if (p->paramId == CLOCKRATE_NORMAL)
11502                     value[0] = mp->clockRateNormal[0];
11503                 else if (p->paramId == CLOCKRATE_LOGNORMAL)
11504                     value[0] = exp(mp->clockRateLognormal[0]);
11505                 else if (p->paramId == CLOCKRATE_EXP)
11506                     value[0] = 1.0/(mp->clockRateExp);
11507                 else if (p->paramId == CLOCKRATE_GAMMA)
11508                     value[0] = mp->clockRateGamma[0]/mp->clockRateGamma[1];
11509                 }
11510             }   /* next param */
11511         }   /* next chain */
11512 
11513     return NO_ERROR;
11514 }
11515 
11516 
FillRelPartsString(Param * p,char ** relPartString)11517 int FillRelPartsString (Param *p, char **relPartString)
11518 {
11519     int         i, n, filledString;
11520     char        *tempStr;
11521     int             tempStrSize=50;
11522 
11523     tempStr = (char *) SafeMalloc((size_t)tempStrSize * sizeof(char));
11524     if (!tempStr)
11525         {
11526         MrBayesPrint ("%s   Problem allocating tempString (%d)\n", spacer, tempStrSize * sizeof(char));
11527         return (ERROR);
11528         }
11529 
11530     if (numCurrentDivisions == 1)
11531         {
11532         filledString = NO;
11533         SafeStrcpy (relPartString, "");
11534         }
11535     else
11536         {
11537         filledString = YES;
11538         if (p->nRelParts == numCurrentDivisions)
11539             {
11540             SafeStrcpy (relPartString, "{all}");
11541             }
11542         else
11543             {
11544             SafeStrcpy (relPartString, "{");
11545             for (i=n=0; i<p->nRelParts; i++)
11546                 {
11547                 n++;
11548                 SafeSprintf (&tempStr, &tempStrSize, "%d", p->relParts[i] + 1);
11549                 SafeStrcat (relPartString, tempStr);
11550                 if (n < p->nRelParts)
11551                     SafeStrcat (relPartString, ",");
11552                 }
11553             SafeStrcat (relPartString, "}");
11554             }
11555         }
11556     free (tempStr);
11557     return (filledString);
11558 }
11559 
11560 
11561 /*--------------------------------------------------------------
11562  |
11563  |  FillStdStateFreqs: fills stationary frequencies for standard data divisions of chains in range [chfrom, chto)
11564  |
11565  ---------------------------------------------------------------*/
FillStdStateFreqs(int chfrom,int chto,RandLong * seed)11566 void FillStdStateFreqs (int chfrom, int chto, RandLong *seed)
11567 {
11568     int     chn, n, i, j, k, b, c, nb, index;
11569     MrBFlt  *subValue, sum, symDir[10];
11570     Param   *p;
11571 
11572     for (chn=chfrom; chn<chto; chn++)
11573         {
11574         for (k=0; k<numParams; k++)
11575             {
11576             p = &params[k];
11577             if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
11578                 continue;
11579             subValue = GetParamStdStateFreqs (p, chn, 0);
11580             if (p->paramId == SYMPI_EQUAL)
11581                 {
11582                 for (n=index=0; n<9; n++)
11583                     {
11584                     for (i=0; i<p->nRelParts; i++)
11585                         if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
11586                             break;
11587                     if (i < p->nRelParts)
11588                         {
11589                         for (j=0; j<(n+2); j++)
11590                             {
11591                             subValue[index++] = (1.0 / (n + 2));
11592                             }
11593                         }
11594                     }
11595                 for (n=9; n<13; n++)
11596                     {
11597                     for (i=0; i<p->nRelParts; i++)
11598                         if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
11599                             break;
11600                     if (i < p->nRelParts)
11601                         {
11602                         for (j=0; j<(n-6); j++)
11603                             {
11604                             subValue[index++] = (1.0 / (n - 6));
11605                             }
11606                         }
11607                     }
11608                 }
11609 
11610             /* Deal with transition asymmetry for standard characters */
11611             /* First, fill in stationary frequencies for beta categories if needed; */
11612             /* discard category frequencies (assume equal) */
11613             if (p->paramId == SYMPI_FIX || p->paramId == SYMPI_UNI || p->paramId == SYMPI_EXP ||
11614                 p->paramId == SYMPI_FIX_MS || p->paramId == SYMPI_UNI_MS || p->paramId == SYMPI_EXP_MS)
11615                 {
11616                 if (p->hasBinaryStd == YES)
11617                     {
11618                     nb=modelParams[p->relParts[0]].numBetaCats;
11619                     BetaBreaks (p->values[0], p->values[0], subValue, nb);
11620                     b = 2*nb;
11621                     for (i=b-2; i>0; i-=2)
11622                         {
11623                         subValue[i] = subValue[i/2];
11624                         }
11625                     for (i=1; i<b; i+=2)
11626                         {
11627                         subValue[i] = (1.0 - subValue[i-1]);
11628                         }
11629                     subValue += (2 * nb);
11630                     }
11631 
11632                 /* Then fill in state frequencies for multistate chars, one set for each */
11633                 for (i=0; i<10; i++)
11634                     symDir[i] = p->values[0];
11635 
11636                 for (c=0; c<p->nSympi; c++)
11637                     {
11638                     /* now fill in subvalues */
11639                     DirichletRandomVariable (symDir, subValue, p->sympinStates[c], seed);
11640                     sum = 0.0;
11641                     for (i=0; i<p->sympinStates[c]; i++)
11642                         {
11643                         if (subValue[i] < 0.0001)
11644                             subValue[i] = 0.0001;
11645                         sum += subValue[i];
11646                         }
11647                     for (i=0; i<modelParams[p->relParts[0]].nStates; i++)
11648                         subValue[i] /= sum;
11649                     subValue += p->sympinStates[c];
11650                     }
11651                 }
11652             }   /* next parameter */
11653         }   /* next chain */
11654 }
11655 
11656 
11657 /* FillTopologySubParams: Fill subparams (brlens) for a topology */
FillTopologySubParams(Param * param,int chn,int state,RandLong * seed)11658 int FillTopologySubParams (Param *param, int chn, int state, RandLong *seed)
11659 {
11660     int         i,returnVal;
11661     Tree        *tree, *tree1;
11662     Param       *q;
11663     MrBFlt      clockRate;
11664     PolyTree    *sourceTree;
11665     MrBFlt      minRate=0.0, maxRate=0.0;
11666 
11667     tree = GetTree (param, chn, state);
11668 
11669     for (i=1; i<param->nSubParams; i++)
11670         {
11671         q = param->subParams[i];
11672         tree1 = GetTree (q, chn, state);
11673         if (CopyToTreeFromTree(tree1, tree) == ERROR)
11674             return (ERROR);
11675         }
11676     for (i=0; i<param->nSubParams; i++)
11677         {
11678         q = param->subParams[i];
11679         tree = GetTree (q, chn, state);
11680         if (q->paramId == BRLENS_FIXED || q->paramId == BRLENS_CLOCK_FIXED)
11681             {
11682             if (param->paramId == TOPOLOGY_NCL_FIXED ||
11683                 param->paramId == TOPOLOGY_NCL_FIXED_HOMO ||
11684                 param->paramId == TOPOLOGY_NCL_FIXED_HETERO ||
11685                 param->paramId == TOPOLOGY_CL_FIXED  ||
11686                 param->paramId == TOPOLOGY_RCL_FIXED ||
11687                 param->paramId == TOPOLOGY_CCL_FIXED ||
11688                 param->paramId == TOPOLOGY_RCCL_FIXED||
11689                 param->paramId == TOPOLOGY_FIXED)
11690                 {
11691                 sourceTree = AllocatePolyTree(numTaxa);
11692                 CopyToPolyTreeFromPolyTree (sourceTree, userTree[modelParams[q->relParts[0]].brlensFix]);
11693                 PrunePolyTree (sourceTree);
11694                 ResetTipIndices (sourceTree);
11695                 ResetIntNodeIndices (sourceTree);
11696                 if (tree->isRooted != sourceTree->isRooted)
11697                     {
11698                     MrBayesPrint("%s   Cannot set fixed branch lengths because of mismatch in rootedness", spacer);
11699                     FreePolyTree (sourceTree);
11700                     return (ERROR);
11701                     }
11702                 if (CopyToTreeFromPolyTree(tree,sourceTree) == ERROR)
11703                     {
11704                     MrBayesPrint("%s   Problem setting fixed branch lengths", spacer);
11705                     FreePolyTree (sourceTree);
11706                     return (ERROR);
11707                     }
11708                 FreePolyTree (sourceTree);
11709                 if (tree->isClock == YES && IsClockSatisfied(tree, 0.0001) == NO)
11710                     {
11711                     MrBayesPrint("%s   Fixed branch lengths do not satisfy clock", spacer);
11712                     return (ERROR);
11713                     }
11714                 if (tree->isCalibrated == YES && IsCalibratedClockSatisfied(tree,&minRate,&maxRate, 0.0001) == NO)
11715                     {
11716                     MrBayesPrint("%s   Fixed branch lengths do not satisfy calibrations", spacer);
11717                     return (ERROR);
11718                     }
11719                 if (tree->isCalibrated == YES && !strcmp(modelParams[tree->relParts[0]].clockRatePr, "Fixed"))
11720                     {
11721                     clockRate = modelParams[tree->relParts[0]].clockRateFix;
11722                     if ((clockRate < minRate && AreDoublesEqual (clockRate, minRate , 0.0001) == NO) ||
11723                         (clockRate > maxRate && AreDoublesEqual (clockRate, maxRate , 0.0001) == NO))
11724                         {
11725                         MrBayesPrint("%s   Fixed branch lengths do not satisfy fixed clockrate", spacer);
11726                         return (ERROR);
11727                         }
11728                     }
11729 
11730                 tree->fromUserTree=YES;
11731                 returnVal = NO_ERROR;
11732                 }
11733             else
11734                 {
11735                 MrBayesPrint("%s   Fixed branch lengths can only be used for a fixed topology\n", spacer);
11736                 return (ERROR);
11737                 }
11738             }
11739         else if (tree->isCalibrated == YES || (tree->isClock == YES && (!strcmp(modelParams[tree->relParts[0]].clockPr,"Uniform") ||
11740                                                                         !strcmp(modelParams[tree->relParts[0]].clockPr,"Birthdeath") ||
11741                                                                         !strcmp(modelParams[tree->relParts[0]].clockPr,"Fossilization"))))
11742             {
11743             assert (tree->isClock == YES);
11744             clockRate = *GetParamVals(modelSettings[tree->relParts[0]].clockRate, chn, state);
11745             returnVal = InitCalibratedBrlens (tree, clockRate, seed);
11746             if (IsClockSatisfied (tree, 0.0001) == NO)
11747                 {
11748                 MrBayesPrint ("%s   Branch lengths of the tree does not satisfy clock\n",  spacer);
11749                 return (ERROR);
11750                 }
11751             tree->fromUserTree=NO;
11752             }
11753         else if (tree->isClock == YES)
11754             returnVal = InitClockBrlens (tree);
11755         else
11756             returnVal = InitBrlens (tree, 0.02);
11757 
11758         if (returnVal == ERROR)
11759             return (ERROR);
11760 
11761         if (FillBrlensSubParams (q, chn, state) == ERROR)
11762             return (ERROR);
11763         }
11764 
11765     return (NO_ERROR);
11766 }
11767 
11768 
11769 /* FillBrlensSubParams: Fill any relaxed clock subparams of a brlens param */
FillBrlensSubParams(Param * param,int chn,int state)11770 int FillBrlensSubParams (Param *param, int chn, int state)
11771 {
11772     int         i, j, *nEvents;
11773     MrBFlt      *brlen, *branchRate, **position, **rateMult;
11774     Tree        *tree;
11775     TreeNode    *p;
11776     Param       *q;
11777 
11778     tree = GetTree (param, chn, state);
11779 
11780     for (i=0; i<param->nSubParams; i++)
11781         {
11782         q = param->subParams[i];
11783         if (q->paramType == P_CPPEVENTS)
11784             {
11785             nEvents = q->nEvents[2*chn+state];
11786             position = q->position[2*chn+state];
11787             rateMult = q->rateMult[2*chn+state];
11788             brlen = GetParamSubVals (q, chn, state);
11789             for (j=0; j<tree->nNodes-1; j++)
11790                 {
11791                 p = tree->allDownPass[j];
11792                 if (nEvents[p->index] != 0)
11793                     {
11794                     free (position[p->index]);
11795                     position[p->index] = NULL;
11796                     free (rateMult[p->index]);
11797                     rateMult[p->index] = NULL;
11798                     }
11799                 nEvents[p->index] = 0;
11800                 assert (j==tree->nNodes-2 || fabs(p->length - (p->anc->nodeDepth - p->nodeDepth)) < 0.000001);
11801                 brlen[p->index] = p->length;
11802                 }
11803             }
11804         else if (q->paramType == P_TK02BRANCHRATES || q->paramType == P_IGRBRANCHRATES || q->paramType == P_MIXEDBRCHRATES)
11805             {
11806             branchRate = GetParamVals (q, chn, state);
11807             brlen = GetParamSubVals (q, chn, state);
11808             for (j=0; j<tree->nNodes-1; j++)
11809                 {
11810                 p = tree->allDownPass[j];
11811                 assert (j==tree->nNodes-2 || fabs(p->length - (p->anc->nodeDepth - p->nodeDepth)) < 0.000001);
11812                 branchRate[p->index] = 1.0;
11813                 brlen[p->index] = p->length;
11814                 }
11815             }
11816         }
11817 
11818     return (NO_ERROR);
11819 }
11820 
11821 
11822 /* Note: In PruneConstraintPartitions() we can not relay on specific rootnes of a tree since different partitions
11823    may theoreticly have different clock models, while constraints apply to all partitions/trees */
PruneConstraintPartitions()11824 int PruneConstraintPartitions()
11825 {
11826     int             i, j, constraintId, nLongsNeeded;
11827 
11828     nLongsNeeded = (numLocalTaxa - 1) / nBitsInALong + 1;
11829 
11830     for (constraintId=0; constraintId<numDefinedConstraints; constraintId++)
11831         {
11832         definedConstraintPruned[constraintId] = (BitsLong *) SafeRealloc ((void *)definedConstraintPruned[constraintId], nLongsNeeded*sizeof(BitsLong));
11833         if (!definedConstraintPruned[constraintId])
11834             {
11835             MrBayesPrint ("%s   Problems allocating constraintPartition in PruneConstraintPartitions", spacer);
11836             return (ERROR);
11837             }
11838 
11839         /* initialize bits in partition to add; get rid of deleted taxa in the process */
11840         ClearBits(definedConstraintPruned[constraintId], nLongsNeeded);
11841         for (i=j=0; i<numTaxa; i++)
11842             {
11843             if (taxaInfo[i].isDeleted == YES)
11844                 continue;
11845             if (IsBitSet(i, definedConstraint[constraintId]) == YES)
11846                 SetBit(j, definedConstraintPruned[constraintId]);
11847             j++;
11848             }
11849         assert (j == numLocalTaxa);
11850 
11851         if (definedConstraintsType[constraintId] == PARTIAL)
11852             {
11853             definedConstraintTwoPruned[constraintId] = (BitsLong *) SafeRealloc ((void *)definedConstraintTwoPruned[constraintId], nLongsNeeded*sizeof(BitsLong));
11854             if (!definedConstraintTwoPruned[constraintId])
11855                 {
11856                 MrBayesPrint ("%s   Problems allocating constraintPartition in PruneConstraintPartitions", spacer);
11857                 return (ERROR);
11858                 }
11859 
11860             /* initialize bits in partition to add; get rid of deleted taxa in the process */
11861             ClearBits(definedConstraintTwoPruned[constraintId], nLongsNeeded);
11862             for (i=j=0; i<numTaxa; i++)
11863                 {
11864                 if (taxaInfo[i].isDeleted == YES)
11865                     continue;
11866                 if (IsBitSet(i, definedConstraintTwo[constraintId]) == YES)
11867                     SetBit(j, definedConstraintTwoPruned[constraintId]);
11868                 j++;
11869                 }
11870             assert (j == numLocalTaxa);
11871             }
11872         else if (definedConstraintsType[constraintId] == NEGATIVE || (definedConstraintsType[constraintId] == HARD))
11873             {
11874             /* Here we create definedConstraintTwoPruned[constraintId] which is complemente of definedConstraintPruned[constraintId] */
11875             definedConstraintTwoPruned[constraintId] = (BitsLong *) SafeRealloc ((void *)definedConstraintTwoPruned[constraintId], nLongsNeeded*sizeof(BitsLong));
11876             if (!definedConstraintTwoPruned[constraintId])
11877                 {
11878                 MrBayesPrint ("%s   Problems allocating constraintPartition in PruneConstraintPartitions", spacer);
11879                 return (ERROR);
11880                 }
11881 
11882             /* initialize bits in partition to add; get rid of deleted taxa in the process */
11883             ClearBits(definedConstraintTwoPruned[constraintId], nLongsNeeded);
11884             for (i=j=0; i<numTaxa; i++)
11885                 {
11886                 if (taxaInfo[i].isDeleted == YES)
11887                     continue;
11888                 if (IsBitSet(i, definedConstraint[constraintId]) == NO)
11889                     SetBit(j, definedConstraintTwoPruned[constraintId]);
11890                 j++;
11891                 }
11892             assert (j == numLocalTaxa);
11893             }
11894     }
11895 
11896     return NO_ERROR;
11897 }
11898 
11899 
DoesTreeSatisfyConstraints(Tree * t)11900 int DoesTreeSatisfyConstraints(Tree *t)
11901 {
11902     int         i, k, numTaxa, nLongsNeeded;
11903     TreeNode    *p;
11904     int         CheckFirst, CheckSecond; /*Flag indicating wheather corresponding set(first/second) of partial constraint has to be checked*/
11905 #   if defined (DEBUG_CONSTRAINTS)
11906     int         locks_count=0;
11907 #   endif
11908 
11909     if (t->checkConstraints == NO)
11910         return YES;
11911     /* get some handy numbers */
11912     numTaxa = t->nNodes - t->nIntNodes - (t->isRooted == YES ? 1 : 0);
11913     nLongsNeeded = (numTaxa - 1) / nBitsInALong + 1;
11914 
11915     if (t->bitsets == NULL)
11916         {
11917         AllocateTreePartitions(t);
11918         }
11919     else
11920         {
11921         ResetTreePartitions(t);  /*Inefficient function, rewrite faster version*/
11922         }
11923 #   if defined (DEBUG_CONSTRAINTS)
11924     for (i=0; i<t->nIntNodes; i++)
11925         {
11926         p = t->intDownPass[i];
11927         if (p->isLocked == YES)
11928             {
11929             if (IsUnionEqThird (definedConstraintPruned[p->lockID], definedConstraintPruned[p->lockID], p->partition, nLongsNeeded) == NO && IsUnionEqThird (definedConstraintTwoPruned[p->lockID], definedConstraintTwoPruned[p->lockID], p->partition, nLongsNeeded) == NO)
11930                 {
11931                 printf ("DEBUG ERROR: Locked node does not represent right partition. \n");
11932                 return ABORT;
11933                 }
11934             else
11935                 {
11936                 locks_count++;
11937                 }
11938             }
11939         }
11940 
11941     if (locks_count != t->nLocks)
11942         {
11943         printf ("DEBUG ERROR: locks_count:%d should be locks_count:%d\n", locks_count, t->nLocks);
11944         return ABORT;
11945         }
11946 #   endif
11947 
11948     for (k=0; k<numDefinedConstraints; k++)
11949         {
11950 #   if defined (DEBUG_CONSTRAINTS)
11951         if (t->constraints[k] == YES && definedConstraintsType[k] == HARD)
11952             {
11953             if (t->isRooted == YES)
11954                 {
11955                 CheckFirst = YES;
11956                 CheckSecond = NO;
11957                 }
11958             else
11959                 {
11960                 /*exactly one of next two will be YES*/
11961                 CheckFirst = IsBitSet(localOutGroup, definedConstraintPruned[k])==YES ? NO : YES;
11962                 CheckSecond = IsBitSet(localOutGroup, definedConstraintTwoPruned[k])==YES ? NO : YES;
11963                 assert ((CheckFirst^CheckSecond)==1);
11964                 }
11965 
11966             for (i=0; i<t->nIntNodes; i++)
11967                 {
11968                 p = t->intDownPass[i];
11969                 if (p->anc != NULL)
11970                     {
11971                     if (CheckFirst==YES &&  IsPartNested(definedConstraintPruned[k], p->partition, nLongsNeeded) && IsPartNested(p->partition,definedConstraintPruned[k], nLongsNeeded))
11972                         break;
11973                     if (CheckSecond==YES &&  IsPartNested(definedConstraintTwoPruned[k], p->partition, nLongsNeeded) && IsPartNested(p->partition, definedConstraintTwoPruned[k], nLongsNeeded))
11974                         break;
11975                     }
11976                 }
11977 
11978             if (i==t->nIntNodes)
11979                 {
11980                 printf ("DEBUG ERROR: Hard constraint is not satisfied. \n");
11981                 return ABORT;
11982                 //assert (0);
11983                 }
11984             }
11985 #   endif
11986 
11987         if (t->constraints[k] == NO || definedConstraintsType[k] == HARD)
11988             continue;
11989 
11990         if (definedConstraintsType[k] == PARTIAL)
11991             {
11992             /* alternative way
11993             if (t->isRooted == NO && !IsBitSet(localOutGroup, definedConstraintPruned[k]))
11994                 {
11995                 m = FirstTaxonInPartition (constraintPartition, nLongsNeeded);
11996                 for (i=0; t->nodes[i].index != m; i++)
11997                     ;
11998                 p = &t->nodes[i];
11999 
12000                 p=p->anc;
12001                 while (!IsPartNested(definedConstraintPruned[k], p->partition, nLongsNeeded))
12002                     p=p->anc;
12003 
12004                 if (IsSectionEmpty(definedConstraintTwoPruned[k], p->partition, nLongsNeeded))
12005                     continue;
12006                 }
12007             */
12008             if (t->isRooted == YES)
12009                 {
12010                 CheckFirst = YES;
12011                 CheckSecond = NO; /* In rooted case even if we have a node with partition fully containing second set and not containing the first set it would not satisfy the constraint */
12012                 }
12013             else
12014                 {
12015                 if (NumBits(definedConstraintPruned[k], nLongsNeeded) == 1 || NumBits(definedConstraintTwoPruned[k], nLongsNeeded) == 1)
12016                     continue;
12017                 /*one or two of the next two statments will be YES*/
12018                 CheckFirst = IsBitSet(localOutGroup, definedConstraintPruned[k])==YES ? NO : YES;
12019                 CheckSecond = IsBitSet(localOutGroup, definedConstraintTwoPruned[k])==YES ? NO : YES;
12020                 assert ((CheckFirst|CheckSecond)==1);
12021                 }
12022             for (i=0; i<t->nIntNodes; i++)
12023                 {
12024                 p = t->intDownPass[i];
12025                 if (p->anc != NULL)
12026                     {
12027                     if (CheckFirst== YES && IsPartNested(definedConstraintPruned[k], p->partition, nLongsNeeded) && IsSectionEmpty(definedConstraintTwoPruned[k], p->partition, nLongsNeeded))
12028                         break;
12029                     if (CheckSecond==YES && IsPartNested(definedConstraintTwoPruned[k], p->partition, nLongsNeeded) && IsSectionEmpty(definedConstraintPruned[k], p->partition, nLongsNeeded))
12030                         break;
12031                     }
12032                 }
12033             if (i==t->nIntNodes)
12034                 return NO;
12035             }
12036         else
12037             {
12038             assert (definedConstraintsType[k] == NEGATIVE);
12039             if (t->isRooted == YES)
12040                 {
12041                 CheckFirst = YES;
12042                 CheckSecond = NO;
12043                 }
12044             else
12045                 {
12046                 /*exactly one of next two will be YES*/
12047                 CheckFirst = IsBitSet(localOutGroup, definedConstraintPruned[k])==YES ? NO : YES;
12048                 CheckSecond = IsBitSet(localOutGroup, definedConstraintTwoPruned[k])==YES ? NO : YES;
12049                 assert ((CheckFirst^CheckSecond)==1);
12050                 }
12051 
12052             for (i=0; i<t->nIntNodes; i++)
12053                 {
12054                 p = t->intDownPass[i];
12055                 if (p->anc != NULL)
12056                     {
12057                     if (CheckFirst==YES && AreBitfieldsEqual(definedConstraintPruned[k], p->partition, nLongsNeeded))
12058                         break;
12059                     if (CheckSecond==YES && AreBitfieldsEqual(definedConstraintTwoPruned[k], p->partition, nLongsNeeded))
12060                         break;
12061                     }
12062                 }
12063             if (i!=t->nIntNodes)
12064                 return NO;
12065             }
12066         }
12067 
12068     return YES;
12069 }
12070 
12071 
12072 /*------------------------------------------------------------------
12073 |
12074 |   FillTreeParams: Fill in trees and branch lengths
12075 |
12076 |   Note: Should be run after FillNormalParams because
12077 |   clockrate needs to be set if calibrated tree needs
12078 |   to be filled.
12079 |
12080 ------------------------------------------------------------------*/
FillTreeParams(RandLong * seed,int fromChain,int toChain)12081 int FillTreeParams (RandLong *seed, int fromChain, int toChain)
12082 {
12083     int         i, k, chn, nTaxa, tmp;
12084     Param       *p, *q;
12085     Tree        *tree;
12086     PolyTree    *constraintTree;
12087     PolyTree    *constraintTreeRef;
12088 
12089     if (PruneConstraintPartitions() == ERROR)
12090         return ERROR;
12091 
12092     /* Build starting trees for state 0 */
12093     for (chn=fromChain; chn<toChain; chn++)
12094         {
12095         for (k=0; k<numParams; k++)
12096             {
12097             p = &params[k];
12098             if (p->paramType == P_TOPOLOGY)
12099                 {
12100                 q = p->subParams[0];
12101                 tree = GetTree (q, chn, 0);
12102                 if (tree->isRooted == YES)
12103                     nTaxa = tree->nNodes - tree->nIntNodes - 1;
12104                 else
12105                     nTaxa = tree->nNodes - tree->nIntNodes;
12106 
12107                 /* fixed topology */
12108                 if (p->paramId == TOPOLOGY_NCL_FIXED ||
12109                     p->paramId == TOPOLOGY_NCL_FIXED_HOMO ||
12110                     p->paramId == TOPOLOGY_NCL_FIXED_HETERO ||
12111                     p->paramId == TOPOLOGY_CL_FIXED  ||
12112                     p->paramId == TOPOLOGY_RCL_FIXED ||
12113                     p->paramId == TOPOLOGY_CCL_FIXED ||
12114                     p->paramId == TOPOLOGY_RCCL_FIXED||
12115                     p->paramId == TOPOLOGY_FIXED     ||
12116                     p->paramId == TOPOLOGY_PARSIMONY_FIXED)
12117                     {
12118                     constraintTree = AllocatePolyTree (numTaxa);
12119                     CopyToPolyTreeFromPolyTree (constraintTree, userTree[modelParams[p->relParts[0]].topologyFix]);
12120                     PrunePolyTree (constraintTree);
12121                     ResetTipIndices(constraintTree);
12122                     ResetIntNodeIndices(constraintTree);
12123                     RandResolve (NULL, constraintTree, seed, constraintTree->isRooted);
12124                     if (tree->nIntNodes != constraintTree->nIntNodes)
12125                         {
12126                         if (tree->isRooted != constraintTree->isRooted)
12127                             {
12128                             MrBayesPrint ("%s   Could not fix topology because user tree '%s' differs in rootedness with the model tree.\n", spacer,
12129                                           userTree[modelParams[p->relParts[0]].topologyFix]->name);
12130                             MrBayesPrint ("%s   The user tree %s is%srooted, while expected model tree is%srooted.\n", spacer,
12131                                           userTree[modelParams[p->relParts[0]].topologyFix]->name, (constraintTree->isRooted?" ":" not "), (tree->isRooted?" ":" not "));
12132                             MrBayesPrint ("%s   Check brlenspr is set correctly before fixing topology.\n", spacer);
12133                             }
12134                         else
12135                             MrBayesPrint ("%s   Could not fix topology because user tree '%s' is not fully resolved.\n",
12136                                                 spacer, userTree[modelParams[p->relParts[0]].topologyFix]->name);
12137                         FreePolyTree (constraintTree);
12138                         return (ERROR);
12139                         }
12140                     if (CopyToTreeFromPolyTree(tree, constraintTree) == ERROR)
12141                         {
12142                         MrBayesPrint ("%s   Could not fix topology according to user tree '%s'\n", spacer, userTree[modelParams[p->relParts[0]].topologyFix]->name);
12143                         FreePolyTree (constraintTree);
12144                         return (ERROR);
12145                         }
12146                     FreePolyTree (constraintTree);
12147                     }
12148                 /* constrained topology */
12149                 else if (tree->nConstraints > 0)
12150                     {
12151                     constraintTreeRef = AllocatePolyTree (nTaxa);
12152                     if (!constraintTreeRef)
12153                         return (ERROR);
12154                     if (BuildConstraintTree (tree, constraintTreeRef, localTaxonNames) == ERROR)
12155                         {
12156                         FreePolyTree (constraintTreeRef);
12157                         return (ERROR);
12158                         }
12159                     if (AllocatePolyTreePartitions (constraintTreeRef) == ERROR)
12160                         return (ERROR);
12161 
12162                     constraintTree = AllocatePolyTree (nTaxa);
12163                     if (!constraintTree)
12164                         return (ERROR);
12165                     if (AllocatePolyTreePartitions (constraintTree) == ERROR)
12166                         return (ERROR);
12167 
12168                     for (i=0;i<100;i++)
12169                         {
12170                         CopyToPolyTreeFromPolyTree(constraintTree,constraintTreeRef);
12171                         tmp = RandResolve (tree, constraintTree, &globalSeed, tree->isRooted);
12172                         if (tmp != NO_ERROR)
12173                             {
12174                             if (tmp  == ERROR)
12175                                 {
12176                                 FreePolyTree (constraintTree);
12177                                 return (ERROR);
12178                                 }
12179                             else
12180                                 {
12181                                 assert (tmp  == ABORT);
12182                                 continue;
12183                                 }
12184                             }
12185 
12186                         CopyToTreeFromPolyTree(tree, constraintTree);
12187                         if (DoesTreeSatisfyConstraints(tree)==YES)
12188                             break;
12189                         }
12190 #   if defined (DEBUG_CONSTRAINTS)
12191                     if (theTree->checkConstraints == YES && CheckConstraints (tree) == ERROR)
12192                         {
12193                         printf ("Error in constraints of starting tree\n");
12194                         getchar();
12195                         }
12196 #   endif
12197                     FreePolyTree (constraintTree);
12198                     FreePolyTree (constraintTreeRef);
12199                     if (i==100)
12200                         {
12201                         MrBayesPrint ("%s   Could not build a starting tree satisfying all constraints\n", spacer);
12202                         return (ERROR);
12203                         }
12204                     }
12205                 /* random topology */
12206                 else
12207                     {
12208                     if (tree->isRooted == YES)
12209                         {
12210                         if (BuildRandomRTopology (tree, &globalSeed) == ERROR)
12211                             return (ERROR);
12212                         }
12213                     else
12214                         {
12215                         if (BuildRandomUTopology (tree, &globalSeed) == ERROR)
12216                             return (ERROR);
12217                         if (MoveCalculationRoot (tree, localOutGroup) == ERROR)
12218                             return (ERROR);
12219                         }
12220                     }
12221 
12222                 if (LabelTree (tree, localTaxonNames) == ERROR)
12223                     return (ERROR);
12224                 if (q == p)
12225                     continue;   /* this is a parsimony tree without branch lengths */
12226                 if (InitializeTreeCalibrations (tree) == ERROR)
12227                     return (ERROR);
12228                 if (FillTopologySubParams(p, chn, 0, seed)== ERROR)
12229                     return (ERROR);
12230                 }
12231             }
12232         }
12233 
12234     if (numTopologies > 1 && !strcmp(modelParams[0].topologyPr,"Speciestree"))
12235         {
12236         if (FillSpeciesTreeParams(seed, fromChain, toChain) == ERROR)
12237             return (ERROR);
12238         }
12239 
12240     return (NO_ERROR);
12241 }
12242 
12243 
FreeCppEvents(Param * p)12244 void FreeCppEvents (Param *p)
12245 {
12246     int i, j;
12247 
12248     if (p->paramType != P_CPPEVENTS)
12249         return;
12250 
12251     if (p->nEvents != NULL)
12252         {
12253         free (p->nEvents[0]);
12254         free (p->nEvents);
12255         for (i=0; i<numGlobalChains; i++)
12256             {
12257             for (j=0; j<2*numLocalTaxa; j++)
12258                 {
12259                 free (p->position[2*i][j]);
12260                 free (p->rateMult[2*i][j]);
12261                 free (p->position[2*i+1][j]);
12262                 free (p->rateMult[2*i+1][j]);
12263                 }
12264             }
12265         free (p->position[0]);
12266         free (p->position);
12267         free (p->rateMult[0]);
12268         free (p->rateMult);
12269         p->nEvents = NULL;
12270         p->position = NULL;
12271         p->rateMult = NULL;
12272         }
12273 }
12274 
12275 
FreeModel(void)12276 int FreeModel (void)
12277 {
12278     int             i;
12279     Param          *p;
12280 
12281     if (memAllocs[ALLOC_MODEL] == YES)
12282         {
12283         for (i = 0; i < numCurrentDivisions; i++)
12284             free (modelParams[i].activeConstraints);
12285 
12286         free (modelParams);
12287         free (modelSettings);
12288         memAllocs[ALLOC_MODEL] = NO;
12289         }
12290 
12291     if (memAllocs[ALLOC_MOVES] == YES)
12292         {
12293         for (i = 0; i < numApplicableMoves; i++)
12294             FreeMove (moves[i]);
12295 
12296         SAFEFREE (moves);
12297         numApplicableMoves = 0;
12298         memAllocs[ALLOC_MOVES] = NO;
12299         }
12300 
12301     if (memAllocs[ALLOC_COMPMATRIX] == YES)
12302         {
12303         free (compMatrix);
12304         memAllocs[ALLOC_COMPMATRIX] = NO;
12305         }
12306 
12307     if (memAllocs[ALLOC_NUMSITESOFPAT] == YES)
12308         {
12309         free (numSitesOfPat);
12310         memAllocs[ALLOC_NUMSITESOFPAT] = NO;
12311         }
12312 
12313     if (memAllocs[ALLOC_COMPCOLPOS] == YES)
12314         {
12315         free (compColPos);
12316         memAllocs[ALLOC_COMPCOLPOS] = NO;
12317         }
12318 
12319     if (memAllocs[ALLOC_COMPCHARPOS] == YES)
12320         {
12321         free (compCharPos);
12322         memAllocs[ALLOC_COMPCHARPOS] = NO;
12323         }
12324 
12325     if (memAllocs[ALLOC_ORIGCHAR] == YES)
12326         {
12327         free (origChar);
12328         memAllocs[ALLOC_ORIGCHAR] = NO;
12329         }
12330 
12331     if (memAllocs[ALLOC_STDTYPE] == YES)
12332         {
12333         free (stdType);
12334         memAllocs[ALLOC_STDTYPE] = NO;
12335         }
12336 
12337     if (memAllocs[ALLOC_STDSTATEFREQS] == YES)
12338         {
12339         SAFEFREE (stdStateFreqs);
12340         memAllocs[ALLOC_STDSTATEFREQS] = NO;
12341         }
12342 
12343     if (memAllocs[ALLOC_PARAMVALUES] == YES)
12344         {
12345         for (i = 0; i < numParams; i++)
12346             {
12347             p = &params[i];
12348 
12349             if (p->paramType == P_CPPEVENTS)
12350                 FreeCppEvents (p);
12351             }
12352 
12353         SAFEFREE (paramValues);
12354         SAFEFREE (intValues);
12355         paramValsRowSize = intValsRowSize = 0;
12356         memAllocs[ALLOC_PARAMVALUES] = NO;
12357         }
12358 
12359     if (memAllocs[ALLOC_PARAMS] == YES)
12360         {
12361         for (i = 0; i < numParams; i++)
12362             {
12363             SAFEFREE (params[i].name);
12364 
12365             if (params[i].paramHeader)
12366                 SAFEFREE (params[i].paramHeader);
12367             }
12368 
12369         SAFEFREE (params);
12370         SAFEFREE (relevantParts);
12371         numParams = 0;
12372         memAllocs[ALLOC_PARAMS] = NO;
12373         }
12374 
12375     if (memAllocs[ALLOC_MCMCTREES] == YES)
12376         {
12377             /* FIXME: Trees needs to be deallocated, but I can't figure
12378                 out how many there are.  The loop below tries te free
12379                 unallocated memory...
12380              */
12381             /*
12382         for (i = 0; i < numParams; ++i)
12383             {
12384             p = &params[i];
12385 
12386             for (j = 0; j < numGlobalChains; ++j)
12387                 FreeTree (GetTree (p, j, 0));
12388             }
12389             */
12390 
12391         SAFEFREE (mcmcTree);
12392         SAFEFREE (subParamPtrs);
12393         memAllocs[ALLOC_MCMCTREES] = NO;
12394         }
12395 
12396     if (memAllocs[ALLOC_SYMPIINDEX] == YES)
12397         {
12398         free (sympiIndex);
12399         memAllocs[ALLOC_SYMPIINDEX] = NO;
12400         }
12401 
12402     if (memAllocs[ALLOC_LOCTAXANAMES] == YES)
12403         {
12404         free (localTaxonNames);
12405         memAllocs[ALLOC_LOCTAXANAMES] = NO;
12406         }
12407 
12408     if (memAllocs[ALLOC_LOCALTAXONCALIBRATION] == YES)
12409         {
12410         free (localTaxonCalibration);
12411         memAllocs[ALLOC_LOCALTAXONCALIBRATION] = NO;
12412         }
12413 
12414     return (NO_ERROR);
12415 }
12416 
12417 
FreeMove(MCMCMove * mv)12418 void FreeMove (MCMCMove *mv)
12419 {
12420     free (mv->tuningParam[0]);
12421     free (mv->tuningParam);
12422     free (mv->relProposalProb);
12423     free (mv->nAccepted);
12424     free (mv->name);
12425     free (mv);
12426 }
12427 
12428 
12429 /* Compute empirical state freq are return it in global array empiricalFreqs[] */
GetEmpiricalFreqs(int * relParts,int nRelParts)12430 int GetEmpiricalFreqs (int *relParts, int nRelParts)
12431 {
12432     int             i, j, k, m, n, thePartition, nuc[20], ns, temp, isDNA, isProtein, firstRel;
12433     MrBFlt          freqN[20], sum, sumN[20]/*, rawCounts[20]*/;
12434 
12435     isDNA = isProtein = NO;
12436     ns = 0;
12437     firstRel = 0;
12438     for (i=0; i<nRelParts; i++)
12439         {
12440         thePartition = relParts[i];
12441         if (i == 0)
12442             {
12443             if (modelParams[thePartition].dataType == DNA || modelParams[i].dataType == RNA)
12444                 {
12445                 isDNA = YES;
12446                 ns = 4;
12447                 }
12448             else if (modelParams[thePartition].dataType == PROTEIN)
12449                 {
12450                 isProtein = YES;
12451                 ns = 20;
12452                 }
12453             else if (modelParams[thePartition].dataType == RESTRICTION)
12454                 {
12455                 ns = 2;
12456                 }
12457             else
12458                 {
12459                 MrBayesPrint ("%s   Cannot get empirical state frequencies for this datatype (%d)\n", spacer, modelSettings[i].dataType);
12460                 return (ERROR);
12461                 }
12462             firstRel = thePartition;
12463             }
12464         else
12465             {
12466             if (modelParams[thePartition].dataType == DNA || modelParams[i].dataType == RNA)
12467                 temp = 4;
12468             else if (modelParams[thePartition].dataType == PROTEIN)
12469                 temp = 20;
12470             else if (modelParams[thePartition].dataType == RESTRICTION)
12471                 temp = 2;
12472             else
12473                 {
12474                 MrBayesPrint ("%s   Unknown data type in GetEmpiricalFreqs\n", spacer);
12475                 return (ERROR);
12476                 }
12477             if (ns != temp)
12478                 {
12479                 MrBayesPrint ("%s   Averaging state frequencies over partitions with different data types\n", spacer);
12480                 return (ERROR);
12481                 }
12482             }
12483         }
12484     if (ns == 0)
12485         {
12486         MrBayesPrint ("%s   Could not find a relevant partition\n", spacer);
12487         return (ERROR);
12488         }
12489 
12490     for (i=0; i<200; i++)
12491         empiricalFreqs[i] = 0.0;
12492 
12493     for (m=0; m<ns; m++)
12494         freqN[m] =  1.0 / ns;
12495 
12496     /* for (m=0; m<ns; m++)
12497        rawCounts[m] = 0.0; NEVER USED */
12498 
12499     for (m=0; m<ns; m++)
12500         sumN[m] = 0.0;
12501     for (k=0; k<nRelParts; k++)
12502         {
12503         thePartition = relParts[k];
12504         for (i=0; i<numTaxa; i++)
12505             {
12506             if (taxaInfo[i].isDeleted == NO)
12507                 {
12508                 for (j=0; j<numChar; j++)
12509                     {
12510                     if (charInfo[j].isExcluded == NO && partitionId[j][partitionNum] - 1 == thePartition)
12511                         {
12512                         if (isDNA == YES)
12513                             GetPossibleNucs (matrix[pos(i,j,numChar)], nuc);
12514                         else if (isProtein == YES)
12515                             GetPossibleAAs (matrix[pos(i,j,numChar)], nuc);
12516                         else
12517                             GetPossibleRestrictionSites (matrix[pos(i,j,numChar)], nuc);
12518                         sum = 0.0;
12519                         for (m=0; m<ns; m++)
12520                             sum += freqN[m] * nuc[m];
12521                         for (m=0; m<ns; m++)
12522                             sumN[m] += freqN[m] * nuc[m] / sum;
12523                         }
12524                     }
12525                 }
12526             }
12527         }
12528     sum = 0.0;
12529     for (m=0; m<ns; m++)
12530         sum += sumN[m];
12531     for (m=0; m<ns; m++)
12532         freqN[m] = sumN[m] / sum;
12533 
12534     if (modelParams[firstRel].dataType == DNA || modelParams[firstRel].dataType == RNA)
12535         {
12536         if (!strcmp(modelParams[firstRel].nucModel, "4by4"))
12537             {
12538             for (m=0; m<ns; m++)
12539                 empiricalFreqs[m] = freqN[m];
12540             }
12541         else if (!strcmp(modelParams[firstRel].nucModel, "Doublet"))
12542             {
12543             i = 0;
12544             for (m=0; m<ns; m++)
12545                 for (n=0; n<ns; n++)
12546                     empiricalFreqs[i++] = freqN[m] * freqN[n];
12547             }
12548         else
12549             {
12550             if (!strcmp(modelParams[firstRel].geneticCode, "Universal"))
12551                 {
12552                 for (i=0; i<61; i++)
12553                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12554                 }
12555             else if (!strcmp(modelParams[firstRel].geneticCode, "Vertmt"))
12556                 {
12557                 for (i=0; i<60; i++)
12558                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12559                 }
12560             else if (!strcmp(modelParams[firstRel].geneticCode, "Invermt"))
12561                 {
12562                 for (i=0; i<62; i++)
12563                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12564                 }
12565             else if (!strcmp(modelParams[firstRel].geneticCode, "Mycoplasma"))
12566                 {
12567                 for (i=0; i<62; i++)
12568                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12569                 }
12570             else if (!strcmp(modelParams[firstRel].geneticCode, "Yeast"))
12571                 {
12572                 for (i=0; i<62; i++)
12573                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12574                 }
12575             else if (!strcmp(modelParams[firstRel].geneticCode, "Ciliate"))
12576                 {
12577                 for (i=0; i<63; i++)
12578                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12579                 }
12580             else if (!strcmp(modelParams[firstRel].geneticCode, "Echinoderm"))
12581                 {
12582                 for (i=0; i<62; i++)
12583                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12584                 }
12585             else if (!strcmp(modelParams[firstRel].geneticCode, "Euplotid"))
12586                 {
12587                 for (i=0; i<62; i++)
12588                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12589                 }
12590             else if (!strcmp(modelParams[firstRel].geneticCode, "Metmt"))
12591                 {
12592                 for (i=0; i<62; i++)
12593                     empiricalFreqs[i] = freqN[modelParams[firstRel].codonNucs[i][0]] * freqN[modelParams[firstRel].codonNucs[i][1]] * freqN[modelParams[firstRel].codonNucs[i][2]];
12594                 }
12595             sum = 0.0;
12596             for (i=0; i<64; i++)
12597                 sum += empiricalFreqs[i];
12598             for (i=0; i<64; i++)
12599                 empiricalFreqs[i] /= sum;
12600 
12601             }
12602         }
12603     else
12604         {
12605         for (m=0; m<ns; m++)
12606             empiricalFreqs[m] = freqN[m];
12607         }
12608 
12609     return (NO_ERROR);
12610 }
12611 
12612 
GetNumDivisionChars(void)12613 int GetNumDivisionChars (void)
12614 {
12615     int         c, d, n;
12616     ModelInfo   *m;
12617 
12618     /* count number of characters in each division */
12619     for (d=0; d<numCurrentDivisions; d++)
12620         {
12621         m = &modelSettings[d];
12622 
12623         n = 0;
12624         for (c=0; c<numChar; c++)
12625             {
12626             if (charInfo[c].isExcluded == NO && partitionId[c][partitionNum] == d+1)
12627                 n++;
12628             }
12629         if (m->dataType == DNA || m->dataType == RNA)
12630             {
12631             if (m->nucModelId == NUCMODEL_DOUBLET)
12632                 n *= 2;
12633             else if (m->nucModelId == NUCMODEL_CODON)
12634                 n *= 3;
12635             }
12636 
12637         m->numUncompressedChars = n;
12638         }
12639 
12640     return (NO_ERROR);
12641 }
12642 
12643 
GetParamIntVals(Param * parm,int chain,int state)12644 int *GetParamIntVals (Param *parm, int chain, int state)
12645 {
12646     return parm->intValues + (2 * chain + state) * intValsRowSize;
12647 }
12648 
12649 
GetParamStdStateFreqs(Param * parm,int chain,int state)12650 MrBFlt  *GetParamStdStateFreqs (Param *parm, int chain, int state)
12651 {
12652     return parm->stdStateFreqs + (2 * chain + state) * stdStateFreqsRowSize;
12653 }
12654 
12655 
GetParamSubVals(Param * parm,int chain,int state)12656 MrBFlt  *GetParamSubVals (Param *parm, int chain, int state)
12657 {
12658     return parm->subValues + (2 * chain + state) * paramValsRowSize;
12659 }
12660 
12661 
GetParamVals(Param * parm,int chain,int state)12662 MrBFlt  *GetParamVals (Param *parm, int chain, int state)
12663 {
12664     return parm->values + (2 * chain + state) * paramValsRowSize;
12665 }
12666 
12667 
GetPossibleAAs(int aaCode,int aa[])12668 void GetPossibleAAs (int aaCode, int aa[])
12669 {
12670     int     m;
12671 
12672     for (m=0; m<20; m++)
12673         aa[m] = 0;
12674 
12675     if (aaCode > 0 && aaCode <= 20)
12676         aa[aaCode-1] = 1;
12677     else
12678         {
12679         for (m=0; m<20; m++)
12680             aa[m] = 1;
12681         }
12682 
12683 #   if 0
12684     printf ("%2d -- ", aaCode);
12685     for (m=0; m<20; m++)
12686         printf ("%d", aa[m]);
12687     printf ("\n");
12688 #   endif
12689 }
12690 
12691 
GetPossibleNucs(int nucCode,int nuc[])12692 void GetPossibleNucs (int nucCode, int nuc[])
12693 {
12694     if (nucCode == 1)
12695         {
12696         nuc[0] = 1;
12697         nuc[1] = 0;
12698         nuc[2] = 0;
12699         nuc[3] = 0;
12700         }
12701     else if (nucCode == 2)
12702         {
12703         nuc[0] = 0;
12704         nuc[1] = 1;
12705         nuc[2] = 0;
12706         nuc[3] = 0;
12707         }
12708     else if (nucCode == 3)
12709         {
12710         nuc[0] = 1;
12711         nuc[1] = 1;
12712         nuc[2] = 0;
12713         nuc[3] = 0;
12714         }
12715     else if (nucCode == 4)
12716         {
12717         nuc[0] = 0;
12718         nuc[1] = 0;
12719         nuc[2] = 1;
12720         nuc[3] = 0;
12721         }
12722     else if (nucCode == 5)
12723         {
12724         nuc[0] = 1;
12725         nuc[1] = 0;
12726         nuc[2] = 1;
12727         nuc[3] = 0;
12728         }
12729     else if (nucCode == 6)
12730         {
12731         nuc[0] = 0;
12732         nuc[1] = 1;
12733         nuc[2] = 1;
12734         nuc[3] = 0;
12735         }
12736     else if (nucCode == 7)
12737         {
12738         nuc[0] = 1;
12739         nuc[1] = 1;
12740         nuc[2] = 1;
12741         nuc[3] = 0;
12742         }
12743     else if (nucCode == 8)
12744         {
12745         nuc[0] = 0;
12746         nuc[1] = 0;
12747         nuc[2] = 0;
12748         nuc[3] = 1;
12749         }
12750     else if (nucCode == 9)
12751         {
12752         nuc[0] = 1;
12753         nuc[1] = 0;
12754         nuc[2] = 0;
12755         nuc[3] = 1;
12756         }
12757     else if (nucCode == 10)
12758         {
12759         nuc[0] = 0;
12760         nuc[1] = 1;
12761         nuc[2] = 0;
12762         nuc[3] = 1;
12763         }
12764     else if (nucCode == 11)
12765         {
12766         nuc[0] = 1;
12767         nuc[1] = 1;
12768         nuc[2] = 0;
12769         nuc[3] = 1;
12770         }
12771     else if (nucCode == 12)
12772         {
12773         nuc[0] = 0;
12774         nuc[1] = 0;
12775         nuc[2] = 1;
12776         nuc[3] = 1;
12777         }
12778     else if (nucCode == 13)
12779         {
12780         nuc[0] = 1;
12781         nuc[1] = 0;
12782         nuc[2] = 1;
12783         nuc[3] = 1;
12784         }
12785     else if (nucCode == 14)
12786         {
12787         nuc[0] = 0;
12788         nuc[1] = 1;
12789         nuc[2] = 1;
12790         nuc[3] = 1;
12791         }
12792     else
12793         {
12794         nuc[0] = 1;
12795         nuc[1] = 1;
12796         nuc[2] = 1;
12797         nuc[3] = 1;
12798         }
12799 }
12800 
12801 
GetPossibleRestrictionSites(int resSiteCode,int * sites)12802 void GetPossibleRestrictionSites (int resSiteCode, int *sites)
12803 {
12804     int     m;
12805 
12806     for (m=0; m<2; m++)
12807         sites[m] = 0;
12808 
12809     if (resSiteCode == 1)
12810         sites[0] = 1;
12811     else if (resSiteCode == 2)
12812         sites[1] = 1;
12813     else
12814         sites[0] = sites[1] = 1;
12815 
12816 #   if 0
12817     printf ("%2d -- ", aaCode);
12818     for (m=0; m<20; m++)
12819         printf ("%d", aa[m]);
12820     printf ("\n");
12821 #   endif
12822 }
12823 
12824 
GetTree(Param * parm,int chain,int state)12825 Tree *GetTree (Param *parm, int chain, int state)
12826 {
12827     return mcmcTree[parm->treeIndex + ((2 * chain + state) * numTrees)];
12828 }
12829 
12830 
GetTreeFromIndex(int index,int chain,int state)12831 Tree *GetTreeFromIndex (int index, int chain, int state)
12832 {
12833     return mcmcTree[index + ((2 * chain + state) * numTrees)];
12834 }
12835 
12836 
12837 /*-----------------------------------------------------------
12838 |
12839 |   GetUserTreeFromName: Do case-insensitive search for user
12840 |      tree, return index if match, -1 and ERROR if error
12841 |
12842 ------------------------------------------------------------*/
GetUserTreeFromName(int * index,char * treeName)12843 int GetUserTreeFromName (int *index, char *treeName)
12844 {
12845     int     i, j, k, nMatches;
12846     char    localName[100], temp[100];
12847 
12848     (*index) = -1;  /* appropriate return if no match */
12849 
12850     if ((int)strlen(treeName) > 99)
12851         {
12852         MrBayesPrint ("%s   Too many characters in tree name\n", spacer);
12853         return (ERROR);
12854         }
12855 
12856     strcpy (localName, treeName);
12857     for (i=0; i<(int)strlen(localName); i++)
12858         localName[i] = tolower(localName[i]);
12859 
12860     nMatches = j = 0;
12861     for (i=0; i<numUserTrees; i++)
12862         {
12863         strcpy (temp, userTree[i]->name);
12864         for (k=0; k<(int)strlen(temp); k++)
12865             temp[k] = tolower(temp[k]);
12866         if (strcmp(localName,temp) == 0)
12867             {
12868             j = i;
12869             nMatches++;
12870             }
12871         }
12872     if (nMatches==0)
12873         {
12874         for (i=0; i<numUserTrees; i++)
12875             {
12876             strcpy (temp, userTree[i]->name);
12877             for (k=0; k<(int)strlen(temp); k++)
12878                 temp[k] = tolower(temp[k]);
12879             if (strncmp(localName,temp,strlen(localName)) == 0)
12880                 {
12881                 j = i;
12882                 nMatches++;
12883                 }
12884             }
12885         }
12886     if (nMatches == 0)
12887         {
12888         MrBayesPrint ("%s   Could not find tree '%s'\n", spacer, localName);
12889         return (ERROR);
12890         }
12891     else if (nMatches > 1)
12892         {
12893         MrBayesPrint ("%s   Several trees matched the abbreviated name '%s'\n", spacer, localName);
12894         return (ERROR);
12895         }
12896     else
12897         {
12898         (*index) = j;
12899         return (NO_ERROR);
12900         }
12901 }
12902 
12903 
12904 /*----------------------------------------------------------------------
12905  |
12906  |   InitializeChainTrees: 'Constructor' for chain trees
12907  |
12908  -----------------------------------------------------------------------*/
InitializeChainTrees(Param * p,int from,int to,int isRooted)12909 int InitializeChainTrees (Param *p, int from, int to, int isRooted)
12910 {
12911     int             i, st, isCalibrated, isClock, nTaxa,
12912                     numActiveHardConstraints = 0;
12913     Tree           *tree, **treeHandle;
12914     Model          *mp;
12915 
12916     mp = &modelParams[p->relParts[0]];
12917 
12918     if (p->paramType == P_SPECIESTREE)
12919         nTaxa = numSpecies;
12920     else
12921         nTaxa = numLocalTaxa;
12922 
12923     /* figure out whether the trees are clock */
12924     if (!strcmp (mp->brlensPr, "Clock"))
12925         isClock = YES;
12926     else
12927         isClock = NO;
12928 
12929     /* figure out whether the trees are calibrated */
12930     if (!strcmp (mp->brlensPr, "Clock")
12931             && (strcmp (mp->nodeAgePr, "Calibrated") == 0
12932                 || strcmp (mp->clockRatePr, "Fixed") != 0
12933                 || (strcmp (mp->clockRatePr, "Fixed") == 0
12934                     && AreDoublesEqual (mp->clockRateFix, 1.0, 1E-6) == NO)))
12935         isCalibrated = YES;
12936     else
12937         isCalibrated = NO;
12938 
12939     if (p->checkConstraints == YES)
12940         {
12941         for (i = 0; i < numDefinedConstraints; i++)
12942             {
12943             if (mp->activeConstraints[i] == YES
12944                     && definedConstraintsType[i] == HARD)
12945                 numActiveHardConstraints++;
12946             }
12947         }
12948 
12949     /* allocate space for and construct the trees */
12950     /* NOTE: The memory allocation scheme used here must match GetTree
12951              and GetTreeFromIndex */
12952     for (i = from; i < to; i++)
12953         {
12954         treeHandle = mcmcTree + p->treeIndex + 2 * i * numTrees;
12955 
12956         if (*treeHandle)
12957             free (*treeHandle);
12958 
12959         if ((*treeHandle = AllocateTree (nTaxa)) == NULL)
12960             {
12961             MrBayesPrint ("%s   Problem allocating mcmc trees\n",
12962                           spacer);
12963             return (ERROR);
12964             }
12965 
12966         treeHandle = mcmcTree + p->treeIndex + (2 * i + 1) * numTrees;
12967 
12968         if (*treeHandle)
12969             free (*treeHandle);
12970 
12971         if ((*treeHandle = AllocateTree (nTaxa)) == NULL)
12972             {
12973             MrBayesPrint ("%s   Problem allocating mcmc trees\n",
12974                           spacer);
12975             return (ERROR);
12976             }
12977         }
12978 
12979     /* initialize the trees */
12980     for (i = from; i < to; i++)
12981         {
12982         for (st = 0; st < 2; st++)
12983             {
12984             tree = GetTree (p, i, st);
12985 
12986             if (numTrees > 1)
12987                 sprintf (tree->name, "mcmc.tree%d_%d",
12988                          p->treeIndex + 1, i + 1);
12989             else        /* if (numTrees == 1) */
12990                 sprintf (tree->name, "mcmc.tree_%d", i + 1);
12991 
12992             tree->nRelParts = p->nRelParts;
12993             tree->relParts = p->relParts;
12994             tree->isRooted = isRooted;
12995             tree->isClock = isClock;
12996             tree->isCalibrated = isCalibrated;
12997 
12998             if (p->paramType == P_SPECIESTREE)
12999                 {
13000                 tree->nNodes = 2 * numSpecies;
13001                 tree->nIntNodes = numSpecies - 1;
13002                 }
13003             else if (tree->isRooted == YES)
13004                 {
13005                 tree->nNodes = 2 * numLocalTaxa;
13006                 tree->nIntNodes = numLocalTaxa - 1;
13007                 }
13008             else        /* if (tree->isRooted == NO) */
13009                 {
13010                 tree->nNodes = 2 * numLocalTaxa - 2;
13011                 tree->nIntNodes = numLocalTaxa - 2;
13012                 }
13013 
13014             if (p->checkConstraints == YES)
13015                 {
13016                 tree->checkConstraints = YES;
13017                 tree->nLocks = NumInformativeHardConstraints (mp);
13018                 tree->nConstraints = mp->numActiveConstraints;      /* nConstraints is number of constraints to check */
13019                 tree->constraints = mp->activeConstraints;
13020                 }
13021             else
13022                 {
13023                 tree->checkConstraints = NO;
13024                 tree->nConstraints = tree->nLocks = 0;
13025                 tree->constraints = NULL;
13026                 }
13027             }
13028         }
13029 
13030     return (NO_ERROR);
13031 }
13032 
13033 
InitializeLinks(void)13034 int InitializeLinks (void)
13035 {
13036     int         i, j;
13037 
13038     linkNum = 0;
13039     for (i=0; i<NUM_LINKED; i++)
13040         {
13041         for (j=0; j<numCurrentDivisions; j++)
13042             linkTable[i][j] = linkNum;
13043         }
13044 
13045     return (NO_ERROR);
13046 }
13047 
13048 
13049 /* InitializeTreeCalibrations: Set calibrations for tree nodes */
InitializeTreeCalibrations(Tree * t)13050 int InitializeTreeCalibrations (Tree *t)
13051 {
13052     int         i;
13053     TreeNode    *p;
13054 
13055     if (t->isCalibrated == NO)
13056         return (NO_ERROR);
13057 
13058     /* Set tip calibrations */
13059     for (i=0; i<t->nNodes; i++)
13060         {
13061         p = t->allDownPass[i];
13062         if (p->left == NULL && p->right == NULL && localTaxonCalibration[p->index]->prior != unconstrained)
13063             {
13064             p->isDated = YES;
13065             p->calibration = localTaxonCalibration[p->index];
13066             p->age = p->calibration->min;
13067             }
13068         else if (p->left == NULL && p->right == NULL)
13069             {
13070             p->isDated = NO;
13071             p->calibration = NULL;
13072             p->age = -1.0;
13073             }
13074         }
13075 
13076     /* Initialize interior calibrations */
13077     if (CheckSetConstraints(t) == ERROR)
13078         return (ERROR);
13079 
13080     return (NO_ERROR);
13081 }
13082 
13083 
IsApplicable(Param * param)13084 int IsApplicable (Param *param)
13085 {
13086     if (param == NULL)
13087         return NO;
13088 
13089     return YES;
13090 }
13091 
13092 
IsApplicable_ThreeTaxaOrMore(Param * param)13093 int IsApplicable_ThreeTaxaOrMore (Param *param)
13094 {
13095     if (param->paramType != P_TOPOLOGY )
13096         return NO;
13097 
13098     if (LargestMovableSubtree (param) >= 3)
13099         return YES;
13100     else
13101         return NO;
13102 }
13103 
13104 
IsApplicable_FourTaxaOrMore(Param * param)13105 int IsApplicable_FourTaxaOrMore (Param *param)
13106 {
13107     if (param->paramType != P_TOPOLOGY )
13108         return NO;
13109 
13110     if (LargestMovableSubtree (param) >= 4)
13111         return YES;
13112     else
13113         return NO;
13114 }
13115 
13116 
IsApplicable_FiveTaxaOrMore(Param * param)13117 int IsApplicable_FiveTaxaOrMore (Param *param)
13118 {
13119     if (param->paramType != P_TOPOLOGY )
13120         return NO;
13121 
13122     if (LargestMovableSubtree (param) >= 5)
13123         return YES;
13124     else
13125         return NO;
13126 }
13127 
13128 
IsApplicable_TreeAgeMove(Param * param)13129 int IsApplicable_TreeAgeMove (Param *param)
13130 {
13131     Tree        *t;
13132     TreeNode    *p;
13133 
13134     if (param == NULL)
13135         return NO;
13136 
13137     if (param->paramType != P_BRLENS)
13138         return NO;
13139 
13140     t = GetTree (param, 0, 0);
13141 
13142     p = t->root->left;
13143     if (p->isDated == NO)
13144         return NO;
13145     if (p->calibration->prior == fixed)
13146         return NO;
13147     else
13148         return YES;
13149 }
13150 
13151 
IsApplicable_AncestralFossil(Param * param)13152 int IsApplicable_AncestralFossil (Param *param)
13153 {
13154     ModelParams *mp = &modelParams[param->relParts[0]];
13155 
13156     if (!strcmp(mp->sampleStrat, "FossilTip"))
13157         return NO;
13158     else if (mp->fossilizationFix == 0.0)
13159         return NO;
13160     else  /* fossils may be ancestors of other fossils or extant species */
13161         return YES;
13162 }
13163 
13164 
IsModelSame(int whichParam,int part1,int part2,int * isApplic1,int * isApplic2)13165 int IsModelSame (int whichParam, int part1, int part2, int *isApplic1, int *isApplic2)
13166 {
13167     int         i, isSame, isFirstNucleotide, isSecondNucleotide, isFirstProtein, isSecondProtein, nDiff, temp1, temp2;
13168 
13169     isSame = YES;
13170     *isApplic1 = YES;
13171     *isApplic2 = YES;
13172 
13173     /* We cannot rely on SetModelInfo being called first so we need to be smart in figuring out model data type by looking at several model params */
13174     isFirstNucleotide = isSecondNucleotide = NO;
13175     if ((modelParams[part1].dataType == DNA || modelParams[part1].dataType == RNA) && strcmp(modelParams[part1].nucModel,"Protein") != 0)
13176         isFirstNucleotide = YES;
13177     if ((modelParams[part2].dataType == DNA || modelParams[part2].dataType == RNA) && strcmp(modelParams[part2].nucModel,"Protein") != 0)
13178         isSecondNucleotide = YES;
13179     isFirstProtein = isSecondProtein = NO;
13180     if (modelParams[part1].dataType == PROTEIN || ((modelParams[part1].dataType == DNA || modelParams[part1].dataType == RNA) && !strcmp(modelParams[part1].nucModel,"Protein")))
13181         isFirstProtein = YES;
13182     if (modelParams[part2].dataType == PROTEIN || ((modelParams[part2].dataType == DNA || modelParams[part2].dataType == RNA) && !strcmp(modelParams[part2].nucModel,"Protein")))
13183         isSecondProtein = YES;
13184 
13185     if (whichParam == P_TRATIO)
13186         {
13187         /* Check the ti/tv rate ratio for partitions 1 and 2. */
13188 
13189         /* Check if the model is parsimony for either partition */
13190         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13191             *isApplic1 = NO; /* part1 has a parsimony model and tratio does not apply */
13192         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13193             *isApplic2 = NO; /* part2 has a parsimony model and tratio does not apply */
13194 
13195         /* Check that the data are nucleotide for both partitions 1 and 2 */
13196         if (isFirstNucleotide == NO)
13197             *isApplic1 = NO; /* part1 is not nucleotide data so tratio does not apply */
13198         if (isSecondNucleotide == NO)
13199             *isApplic2 = NO; /* part2 is not nucleotide data so tratio does not apply */
13200 
13201         /* check that nst=2 for both partitions */
13202         if (strcmp(modelParams[part1].nst, "2"))
13203             *isApplic1 = NO; /* part1 does not have nst=2 and tratio does not apply */
13204         if (strcmp(modelParams[part2].nst, "2"))
13205             *isApplic2 = NO; /* part2 does not have nst=2 and tratio does not apply */
13206 
13207         /* Check if part1 & part2 are restriction */
13208         if (modelParams[part1].dataType == RESTRICTION)
13209             *isApplic1 = NO;
13210         if (modelParams[part2].dataType == RESTRICTION)
13211             *isApplic2 = NO;
13212 
13213         /* If Nst = 2 for both part1 and part2, we now need to check if the prior is the same for both. */
13214         if (!strcmp(modelParams[part1].tRatioPr,"Beta") && !strcmp(modelParams[part2].tRatioPr,"Beta"))
13215             {
13216             if (AreDoublesEqual (modelParams[part1].tRatioDir[0], modelParams[part2].tRatioDir[0], (MrBFlt) 0.00001) == NO)
13217                 isSame = NO;
13218             if (AreDoublesEqual (modelParams[part1].tRatioDir[1], modelParams[part2].tRatioDir[1], (MrBFlt) 0.00001) == NO)
13219                 isSame = NO;
13220             }
13221         else if (!strcmp(modelParams[part1].tRatioPr,"Fixed") && !strcmp(modelParams[part2].tRatioPr,"Fixed"))
13222             {
13223             if (AreDoublesEqual (modelParams[part1].tRatioFix, modelParams[part2].tRatioFix, (MrBFlt) 0.00001) == NO)
13224                 isSame = NO;
13225             }
13226         else
13227             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13228 
13229         /* Check to see if tratio is inapplicable for either partition. */
13230         if ((*isApplic1) == NO || (*isApplic2) == NO)
13231             isSame = NO; /* if tratio is inapplicable for either partition, then the parameter cannot be the same */
13232         }
13233     else if (whichParam == P_REVMAT)
13234         {
13235         /* Check the GTR rates for partitions 1 and 2. */
13236 
13237         /* Check if the model is parsimony for either partition */
13238         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13239             *isApplic1 = NO; /* part1 has a parsimony model and GTR rates do not apply */
13240         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13241             *isApplic2 = NO; /* part2 has a parsimony model and GTR rates do not apply */
13242 
13243         /* Check that the data are nucleotide or protein for both partitions 1 and 2 */
13244         if (isFirstNucleotide == NO && isFirstProtein == NO)
13245             *isApplic1 = NO; /* part1 is not nucleotide or protein data so GTR rates do not apply */
13246         if (isSecondNucleotide == NO && isSecondProtein == NO)
13247             *isApplic2 = NO; /* part2 is not nucleotide or protein data so GTR rates do not apply */
13248 
13249         /* check that nst=6 or mixed for both partitions if nucleotide */
13250         if (isFirstNucleotide == YES && strcmp(modelParams[part1].nst, "6") && strcmp(modelParams[part1].nst, "Mixed"))
13251             *isApplic1 = NO; /* part1 does not have nst=6/Mixed and GTR rates do not apply */
13252         if (isSecondNucleotide == YES && strcmp(modelParams[part2].nst, "6") && strcmp(modelParams[part2].nst, "Mixed"))
13253             *isApplic2 = NO; /* part2 does not have nst=6/Mixed and GTR rates do not apply */
13254 
13255         /* check that model is GTR for both partitions if protein */
13256         if (isFirstProtein == YES && (strcmp(modelParams[part1].aaModel,"Gtr")!=0 || strcmp(modelParams[part1].aaModelPr,"Fixed")!=0))
13257             *isApplic1 = NO;
13258         if (isSecondProtein == YES && (strcmp(modelParams[part2].aaModel,"Gtr")!=0 || strcmp(modelParams[part2].aaModelPr,"Fixed")!=0))
13259             *isApplic2 = NO;
13260 
13261         /* check that data type is the same for both partitions */
13262         if (isFirstNucleotide == YES && isSecondNucleotide == NO)
13263             isSame = NO;
13264         if (isFirstProtein == YES && isSecondProtein == NO)
13265             isSame = NO;
13266 
13267         /* GTR applies to both part1 and part2. We now need to check if the prior is the same for both. */
13268         if (isFirstNucleotide == YES)
13269             {
13270             if (strcmp(modelParams[part1].nst, modelParams[part2].nst) != 0)
13271                 isSame = NO;
13272             if (!strcmp(modelParams[part1].nst,"Mixed"))
13273                 {
13274                 if (AreDoublesEqual (modelParams[part1].revMatSymDir, modelParams[part2].revMatSymDir, (MrBFlt) 0.00001) == NO)
13275                     isSame = NO;
13276                 }
13277             else if (!strcmp(modelParams[part1].nst,"6") && !strcmp(modelParams[part1].revMatPr,"Dirichlet") && !strcmp(modelParams[part2].revMatPr,"Dirichlet"))
13278                 {
13279                 for (i=0; i<6; i++)
13280                     {
13281                     if (AreDoublesEqual (modelParams[part1].revMatDir[i], modelParams[part2].revMatDir[i], (MrBFlt) 0.00001) == NO)
13282                         isSame = NO;
13283                     }
13284                 }
13285             else if (!strcmp(modelParams[part1].nst,"6") && !strcmp(modelParams[part1].revMatPr,"Fixed") && !strcmp(modelParams[part2].revMatPr,"Fixed"))
13286                 {
13287                 for (i=0; i<6; i++)
13288                     {
13289                     if (AreDoublesEqual (modelParams[part1].revMatFix[i], modelParams[part2].revMatFix[i], (MrBFlt) 0.00001) == NO)
13290                         isSame = NO;
13291                     }
13292                 }
13293             else
13294                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13295             }
13296         else /* if (isFirstProtein == YES) */
13297             {
13298             if (!strcmp(modelParams[part1].aaRevMatPr,"Dirichlet") && !strcmp(modelParams[part2].aaRevMatPr,"Dirichlet"))
13299                 {
13300                 for (i=0; i<190; i++)
13301                     {
13302                     if (AreDoublesEqual (modelParams[part1].aaRevMatDir[i], modelParams[part2].aaRevMatDir[i], (MrBFlt) 0.00001) == NO)
13303                         isSame = NO;
13304                     }
13305                 }
13306             else if (!strcmp(modelParams[part1].aaRevMatPr,"Fixed") && !strcmp(modelParams[part2].aaRevMatPr,"Fixed"))
13307                 {
13308                 for (i=0; i<190; i++)
13309                     {
13310                     if (AreDoublesEqual (modelParams[part1].aaRevMatFix[i], modelParams[part2].aaRevMatFix[i], (MrBFlt) 0.00001) == NO)
13311                         isSame = NO;
13312                     }
13313                 }
13314             else
13315                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13316             }
13317 
13318         /* Check to see if the GTR rates are inapplicable for either partition. */
13319         if ((*isApplic1) == NO || (*isApplic2) == NO)
13320             isSame = NO; /* if GTR rates are inapplicable for either partition, then the parameter cannot be the same */
13321         }
13322     else if (whichParam == P_OMEGA)
13323         {
13324         /* Check the nonsynonymous/synonymous rate ratio for partitions 1 and 2. */
13325 
13326         /* Check if the model is parsimony for either partition */
13327         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13328             *isApplic1 = NO; /* part1 has a parsimony model and nonsynonymous/synonymous rate ratio does not apply */
13329         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13330             *isApplic2 = NO; /* part2 has a parsimony model and nonsynonymous/synonymous rate ratio does not apply */
13331 
13332         /* Check that the data are nucleotide for both partitions 1 and 2 */
13333         if (isFirstNucleotide == NO)
13334             *isApplic1 = NO; /* part1 is not nucleotide data so a nonsynonymous/synonymous rate ratio does not apply */
13335         if (isSecondNucleotide == NO)
13336             *isApplic2 = NO; /* part2 is not nucleotide data so a nonsynonymous/synonymous rate ratio does not apply */
13337 
13338         /* Check that the model structure is the same for both. The nucmodel should be "codon". */
13339         if (strcmp(modelParams[part1].nucModel, "Codon"))
13340             *isApplic1 = NO; /* part1 does not have Nucmodel = Codon and nonsynonymous/synonymous rate ratio does not apply */
13341         if (strcmp(modelParams[part2].nucModel, "Codon"))
13342             *isApplic2 = NO; /* part2 does not have Nucmodel = Codon and nonsynonymous/synonymous rate ratio does not apply */
13343 
13344         /* Assuming that Nucmodel = Codon for both part1 and part2, we now need to check if the prior is the
13345            same for both. */
13346         if (!strcmp(modelParams[part1].omegaVar, "M3") && !strcmp(modelParams[part2].omegaVar, "M3"))
13347             {
13348             if (!strcmp(modelParams[part1].m3omegapr, "Exponential") && !strcmp(modelParams[part2].m3omegapr, "Exponential"))
13349                 {
13350                 }
13351             else if (!strcmp(modelParams[part1].m3omegapr, "Fixed") && !strcmp(modelParams[part1].m3omegapr, "Fixed"))
13352                 {
13353                 if (AreDoublesEqual (modelParams[part1].m3omegaFixed[0], modelParams[part2].m3omegaFixed[0], (MrBFlt) 0.00001) == NO)
13354                     isSame = NO;
13355                 if (AreDoublesEqual (modelParams[part1].m3omegaFixed[1], modelParams[part2].m3omegaFixed[1], (MrBFlt) 0.00001) == NO)
13356                     isSame = NO;
13357                 }
13358             else
13359                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13360 
13361             if (!strcmp(modelParams[part1].codonCatFreqPr, "Dirichlet") && !strcmp(modelParams[part2].codonCatFreqPr, "Dirichlet"))
13362                 {
13363                 if (AreDoublesEqual (modelParams[part1].codonCatDir[0], modelParams[part2].codonCatDir[0], (MrBFlt) 0.00001) == NO)
13364                     isSame = NO;
13365                 if (AreDoublesEqual (modelParams[part1].codonCatDir[1], modelParams[part2].codonCatDir[1], (MrBFlt) 0.00001) == NO)
13366                     isSame = NO;
13367                 if (AreDoublesEqual (modelParams[part1].codonCatDir[2], modelParams[part2].codonCatDir[2], (MrBFlt) 0.00001) == NO)
13368                     isSame = NO;
13369                 }
13370             else if (!strcmp(modelParams[part1].codonCatFreqPr, "Fixed") && !strcmp(modelParams[part1].codonCatFreqPr, "Fixed"))
13371                 {
13372                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[0], modelParams[part2].codonCatFreqFix[0], (MrBFlt) 0.00001) == NO)
13373                     isSame = NO;
13374                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[1], modelParams[part2].codonCatFreqFix[1], (MrBFlt) 0.00001) == NO)
13375                     isSame = NO;
13376                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[2], modelParams[part2].codonCatFreqFix[2], (MrBFlt) 0.00001) == NO)
13377                     isSame = NO;
13378                 }
13379             else
13380                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13381             }
13382         else if (!strcmp(modelParams[part1].omegaVar, "M10") && !strcmp(modelParams[part2].omegaVar, "M10"))
13383             {
13384             if (!strcmp(modelParams[part1].codonCatFreqPr, "Dirichlet") && !strcmp(modelParams[part2].codonCatFreqPr, "Dirichlet"))
13385                 {
13386                 if (AreDoublesEqual (modelParams[part1].codonCatDir[0], modelParams[part2].codonCatDir[0], (MrBFlt) 0.00001) == NO)
13387                     isSame = NO;
13388                 if (AreDoublesEqual (modelParams[part1].codonCatDir[1], modelParams[part2].codonCatDir[1], (MrBFlt) 0.00001) == NO)
13389                     isSame = NO;
13390                 }
13391             else if (!strcmp(modelParams[part1].codonCatFreqPr, "Fixed") && !strcmp(modelParams[part1].codonCatFreqPr, "Fixed"))
13392                 {
13393                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[0], modelParams[part2].codonCatFreqFix[0], (MrBFlt) 0.00001) == NO)
13394                     isSame = NO;
13395                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[1], modelParams[part2].codonCatFreqFix[1], (MrBFlt) 0.00001) == NO)
13396                     isSame = NO;
13397                 }
13398             else
13399                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13400             }
13401         else if (!strcmp(modelParams[part1].omegaVar, "Ny98") && !strcmp(modelParams[part2].omegaVar, "Ny98"))
13402             {
13403             if (!strcmp(modelParams[part1].ny98omega1pr, "Beta") && !strcmp(modelParams[part2].ny98omega1pr, "Beta"))
13404                 {
13405                 if (AreDoublesEqual (modelParams[part1].ny98omega1Beta[0], modelParams[part2].ny98omega1Beta[0], (MrBFlt) 0.00001) == NO)
13406                     isSame = NO;
13407                 if (AreDoublesEqual (modelParams[part1].ny98omega1Beta[1], modelParams[part2].ny98omega1Beta[1], (MrBFlt) 0.00001) == NO)
13408                     isSame = NO;
13409                 }
13410             else if (!strcmp(modelParams[part1].ny98omega1pr, "Fixed") && !strcmp(modelParams[part1].ny98omega1pr, "Fixed"))
13411                 {
13412                 if (AreDoublesEqual (modelParams[part1].ny98omega1Fixed, modelParams[part2].ny98omega1Fixed, (MrBFlt) 0.00001) == NO)
13413                     isSame = NO;
13414                 }
13415             else
13416                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13417             if (!strcmp(modelParams[part1].ny98omega3pr, "Uniform") && !strcmp(modelParams[part2].ny98omega3pr, "Uniform"))
13418                 {
13419                 if (AreDoublesEqual (modelParams[part1].ny98omega3Uni[0], modelParams[part2].ny98omega3Uni[0], (MrBFlt) 0.00001) == NO)
13420                     isSame = NO;
13421                 if (AreDoublesEqual (modelParams[part1].ny98omega3Uni[1], modelParams[part2].ny98omega3Uni[1], (MrBFlt) 0.00001) == NO)
13422                     isSame = NO;
13423                 }
13424             else if (!strcmp(modelParams[part1].ny98omega3pr, "Exponential") && !strcmp(modelParams[part1].ny98omega3pr, "Exponential"))
13425                 {
13426                 if (AreDoublesEqual (modelParams[part1].ny98omega3Exp, modelParams[part2].ny98omega3Exp, (MrBFlt) 0.00001) == NO)
13427                     isSame = NO;
13428                 }
13429             else if (!strcmp(modelParams[part1].ny98omega3pr, "Fixed") && !strcmp(modelParams[part1].ny98omega3pr, "Fixed"))
13430                 {
13431                 if (AreDoublesEqual (modelParams[part1].ny98omega3Fixed, modelParams[part2].ny98omega3Fixed, (MrBFlt) 0.00001) == NO)
13432                     isSame = NO;
13433                 }
13434             else
13435                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13436             if (!strcmp(modelParams[part1].codonCatFreqPr, "Dirichlet") && !strcmp(modelParams[part2].codonCatFreqPr, "Dirichlet"))
13437                 {
13438                 if (AreDoublesEqual (modelParams[part1].codonCatDir[0], modelParams[part2].codonCatDir[0], (MrBFlt) 0.00001) == NO)
13439                     isSame = NO;
13440                 if (AreDoublesEqual (modelParams[part1].codonCatDir[1], modelParams[part2].codonCatDir[1], (MrBFlt) 0.00001) == NO)
13441                     isSame = NO;
13442                 if (AreDoublesEqual (modelParams[part1].codonCatDir[2], modelParams[part2].codonCatDir[2], (MrBFlt) 0.00001) == NO)
13443                     isSame = NO;
13444                 }
13445             else if (!strcmp(modelParams[part1].codonCatFreqPr, "Fixed") && !strcmp(modelParams[part1].codonCatFreqPr, "Fixed"))
13446                 {
13447                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[0], modelParams[part2].codonCatFreqFix[0], (MrBFlt) 0.00001) == NO)
13448                     isSame = NO;
13449                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[1], modelParams[part2].codonCatFreqFix[1], (MrBFlt) 0.00001) == NO)
13450                     isSame = NO;
13451                 if (AreDoublesEqual (modelParams[part1].codonCatFreqFix[2], modelParams[part2].codonCatFreqFix[2], (MrBFlt) 0.00001) == NO)
13452                     isSame = NO;
13453                 }
13454             else
13455                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13456             }
13457         else if (!strcmp(modelParams[part1].omegaVar, "Equal") && !strcmp(modelParams[part2].omegaVar, "Equal"))
13458             {
13459             if (!strcmp(modelParams[part1].omegaPr,"Dirichlet") && !strcmp(modelParams[part2].omegaPr,"Dirichlet"))
13460                 {
13461                 if (AreDoublesEqual (modelParams[part1].omegaDir[0], modelParams[part2].omegaDir[0], (MrBFlt) 0.00001) == NO)
13462                     isSame = NO;
13463                 if (AreDoublesEqual (modelParams[part1].omegaDir[1], modelParams[part2].omegaDir[1], (MrBFlt) 0.00001) == NO)
13464                     isSame = NO;
13465                 }
13466             else if (!strcmp(modelParams[part1].omegaPr,"Fixed") && !strcmp(modelParams[part2].omegaPr,"Fixed"))
13467                 {
13468                 if (AreDoublesEqual (modelParams[part1].omegaFix, modelParams[part2].omegaFix, (MrBFlt) 0.00001) == NO)
13469                     isSame = NO;
13470                 }
13471             else
13472                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13473             }
13474         else
13475             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13476 
13477         /* Check to see if omega is inapplicable for either partition. */
13478         if ((*isApplic1) == NO || (*isApplic2) == NO)
13479             isSame = NO; /* if omega is inapplicable for either partition, then the parameter cannot be the same */
13480         }
13481     else if (whichParam == P_PI)
13482         {
13483         /* Check the state frequencies for partitions 1 and 2. */
13484 
13485         /* Check if the model is parsimony for either partition */
13486         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13487             *isApplic1 = NO; /* part1 has a parsimony model and state frequencies do not apply */
13488         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13489             *isApplic2 = NO; /* part2 has a parsimony model and state frequencies do not apply */
13490 
13491         /* Check that the data are not CONTINUOUS for partitions 1 and 2 */
13492         if (modelParams[part1].dataType == CONTINUOUS)
13493             *isApplic1 = NO; /* state frequencies do not make sense for part1 */
13494         if (modelParams[part2].dataType == CONTINUOUS)
13495             *isApplic2 = NO; /* state frequencies do not make sense for part2 */
13496 
13497         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid, or whatever). */
13498         if (isFirstNucleotide != isSecondNucleotide)
13499             isSame = NO; /* data are not both nucleotide or both note nucleotide */
13500         else if (modelParams[part1].dataType != modelParams[part2].dataType && isFirstNucleotide == NO)
13501             isSame = NO; /* data are not the same */
13502 
13503         /* Check that the model structure is the same for both partitions */
13504         if (strcmp(modelParams[part1].nucModel, modelParams[part2].nucModel))
13505             isSame = NO; /* the nucleotide models are different */
13506         if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel) && !(!strcmp(modelParams[part1].nucModel, "Codon") && !strcmp(modelParams[part2].nucModel, "Codon")))
13507             isSame = NO; /* the models have different covarion struture */
13508 
13509         /* If both partitions have nucmodel=codon, then we also have to make certain that the same genetic code is used. */
13510         if (!strcmp(modelParams[part1].nucModel, "Codon") && !strcmp(modelParams[part2].nucModel, "Codon"))
13511             {
13512             if (strcmp(modelParams[part1].geneticCode, modelParams[part2].geneticCode))
13513                 isSame = NO; /* the models have different genetic codes */
13514             }
13515 
13516         /* Let's see if the prior is the same. */
13517         if (modelParams[part1].dataType == STANDARD && modelParams[part2].dataType == STANDARD)
13518             {
13519             /* The data are morphological (STANDARD). The state frequencies are specified by a
13520                symmetric beta distribution, the parameter of which needs to be the same to apply to both
13521                partitions. Note that symPiPr = -1 is equivalent to setting the variance to 0.0. */
13522             if (!strcmp(modelParams[part1].symPiPr,"Uniform") && !strcmp(modelParams[part2].symPiPr,"Uniform"))
13523                 {
13524                 if (AreDoublesEqual (modelParams[part1].symBetaUni[0], modelParams[part2].symBetaUni[0], (MrBFlt) 0.00001) == NO)
13525                     isSame = NO;
13526                 if (AreDoublesEqual (modelParams[part1].symBetaUni[1], modelParams[part2].symBetaUni[1], (MrBFlt) 0.00001) == NO)
13527                     isSame = NO;
13528                 if (modelParams[part1].numBetaCats != modelParams[part2].numBetaCats)
13529                     isSame = NO;    /* can't link because the discrete beta approximation is different */
13530                 }
13531             else if (!strcmp(modelParams[part1].symPiPr,"Exponential") && !strcmp(modelParams[part2].symPiPr,"Exponential"))
13532                 {
13533                 if (AreDoublesEqual (modelParams[part1].symBetaExp, modelParams[part2].symBetaExp, (MrBFlt) 0.00001) == NO)
13534                     isSame = NO;
13535                 if (modelParams[part1].numBetaCats != modelParams[part2].numBetaCats)
13536                     isSame = NO;    /* can't link because the discrete beta approximation is different */
13537                 }
13538             else if (!strcmp(modelParams[part1].symPiPr,"Fixed") && !strcmp(modelParams[part2].symPiPr,"Fixed"))
13539                 {
13540                 if (AreDoublesEqual (modelParams[part1].symBetaFix, modelParams[part2].symBetaFix, (MrBFlt) 0.00001) == NO)
13541                     isSame = NO;
13542                 if (AreDoublesEqual (modelParams[part1].symBetaFix, (MrBFlt) -1.0, (MrBFlt) 0.00001) == NO && modelParams[part1].numBetaCats != modelParams[part2].numBetaCats)
13543                     isSame = NO;    /* can't link because the discrete beta approximation is different */
13544                 }
13545             else
13546                 isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13547             }
13548         if (modelSettings[part1].dataType == PROTEIN && modelSettings[part2].dataType == PROTEIN)
13549             {
13550             /* We are dealing with protein data. */
13551             if (!strcmp(modelParams[part1].aaModelPr, modelParams[part2].aaModelPr))
13552                 {
13553                 if (!strcmp(modelParams[part1].aaModelPr, "Fixed"))
13554                     {
13555                     /* only have a single, fixed, amino acid rate matrix */
13556                     if (!strcmp(modelParams[part1].aaModel, modelParams[part2].aaModel))
13557                         {}
13558                     else
13559                         isSame = NO; /* we have different amino acid models, and the state frequencies must be different */
13560                     /* if we have an equalin model or Gtr model, then we need to check the prior on the state frequencies */
13561                     if (!strcmp(modelParams[part1].aaModel, "Equalin") || !strcmp(modelParams[part1].aaModel, "Gtr"))
13562                         {
13563                         if (!strcmp(modelParams[part1].stateFreqPr, modelParams[part2].stateFreqPr))
13564                             {
13565                             /* the prior form is the same */
13566                             if (!strcmp(modelParams[part1].stateFreqPr, "Dirichlet")) /* both prior models must be dirichlet */
13567                                 {
13568                                 for (i=0; i<modelParams[part1].nStates; i++)
13569                                     if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13570                                         isSame = NO; /* the dirichlet parameters are different */
13571                                 }
13572                             else /* both prior models must be fixed */
13573                                 {
13574                                 if (!strcmp(modelParams[part1].stateFreqsFixType, modelParams[part2].stateFreqsFixType))
13575                                     {
13576                                     /* if (!strcmp(modelParams[part1].stateFreqsFixType, "Empirical"))
13577                                         isSame = NO;     Even though it is unlikely that the empirical values for both partitions are exactly the same, we will
13578                                                          allow isSame to equal YES. This means pooled base frequencies are used to determine the empirical
13579                                                          base frequencies. The user can still unlink this parameter. */
13580                                     if (!strcmp(modelParams[part1].stateFreqsFixType, "User"))
13581                                         {
13582                                         for (i=0; i<modelParams[part1].nStates; i++)
13583                                             if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13584                                                 isSame = NO; /* the user-specified base frequencies are different */
13585                                         }
13586                                     /* if the frequencies were both fixed to "equal", we are golden, and they are the same */
13587                                     }
13588                                 else
13589                                     isSame = NO; /* the fixed parameters must be the same. The only other possibility is that the
13590                                                     user specified equal or empirical for one partition and then specified specific
13591                                                     numbers (user) for the other _and_ happened to set the user values to the equal
13592                                                     or empirical values. We ignore this possibility. */
13593                                 }
13594                             }
13595                         }
13596                     }
13597                 else
13598                     {
13599                     /* averaging over models */
13600                     if (linkTable[P_AAMODEL][part1] != linkTable[P_AAMODEL][part2])
13601                         isSame = NO; /* the amino acid model is mixed, but independently estimated */
13602                     }
13603                 }
13604             }
13605         else
13606             {
13607             /* Otherwise, we are dealing with RESTRICTION or NUCLEOTIDE data. The dirichlet should be the same
13608                for both partitions. */
13609             if (!strcmp(modelParams[part1].stateFreqPr, modelParams[part2].stateFreqPr))
13610                 {
13611                 /* the prior form is the same */
13612                 if (!strcmp(modelParams[part1].stateFreqPr, "Dirichlet")) /* both prior models must be dirichlet */
13613                     {
13614                     for (i=0; i<modelParams[part1].nStates; i++)
13615                         if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13616                             isSame = NO; /* the dirichlet parameters are different */
13617                     }
13618                 else /* both prior models must be fixed */
13619                     {
13620                     if (!strcmp(modelParams[part1].stateFreqsFixType, modelParams[part2].stateFreqsFixType))
13621                         {
13622                         /* if (!strcmp(modelParams[part1].stateFreqsFixType, "Empirical"))
13623                             isSame = NO;     Even though it is unlikely that the empirical values for both partitions are exactly the same, we will
13624                                              allow isSame to equal YES. This means pooled base frequencies are used to determine the empirical
13625                                              base frequencies. The user can still unlink this parameter. */
13626                         if (!strcmp(modelParams[part1].stateFreqsFixType, "User"))
13627                             {
13628                             for (i=0; i<modelParams[part1].nStates; i++)
13629                                 if (AreDoublesEqual (modelParams[part1].stateFreqsDir[i], modelParams[part2].stateFreqsDir[i], (MrBFlt) 0.00001) == NO)
13630                                     isSame = NO; /* the user-specified base frequencies are different */
13631                             }
13632                         /* if the frequencies were both fixed to "equal", we are golden, and they are the same */
13633                         }
13634                     else
13635                         isSame = NO; /* the fixed parameters must be the same. The only other possibility is that the
13636                                         user specified equal or empirical for one partition and then specified specific
13637                                         numbers (user) for the other _and_ happened to set the user values to the equal
13638                                         or empirical values. We ignore this possibility. */
13639                     }
13640                 }
13641             }
13642 
13643         /* Check to see if the state frequencies are inapplicable for either partition. */
13644         if ((*isApplic1) == NO || (*isApplic2) == NO)
13645             isSame = NO; /* if the state frequencies are inapplicable for either partition, then the parameter cannot be the same */
13646         }
13647     else if (whichParam == P_MIXTURE_RATES)
13648         {
13649         /* Check the mixture rate parameter for partitions 1 and 2. */
13650 
13651         /* Check if the model is parsimony for either partition */
13652         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13653             *isApplic1 = NO; /* part1 has a parsimony model and mixture rate parameter does not apply */
13654         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13655             *isApplic2 = NO; /* part2 has a parsimony model and mixture rate parameter does not apply */
13656 
13657         /* Check that the data are not CONTINUOUS for partitions 1 and 2 */
13658         if (modelParams[part1].dataType == CONTINUOUS)
13659             *isApplic1 = NO; /* the mixture rate parameter does not make sense for part1 */
13660         if (modelParams[part2].dataType == CONTINUOUS)
13661             *isApplic2 = NO; /* the mixture rate parameter does not make sense for part2 */
13662 
13663         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid, or whatever). */
13664         if (isFirstNucleotide != isSecondNucleotide)
13665             isSame = NO; /* data are not both nucleotide */
13666         else if (modelParams[part1].dataType != modelParams[part2].dataType && isFirstNucleotide == NO)
13667             isSame = NO; /* data are not the same */
13668 
13669         /* Let's check that the mixture rate parameter is relevant for the two partitions */
13670         if (strcmp(modelParams[part1].ratesModel, "Kmixture") != 0)
13671             *isApplic1 = NO; /* the rate mixture parameter does not apply to part1 */
13672         if (strcmp(modelParams[part2].ratesModel, "Kmixture") != 0)
13673             *isApplic2 = NO; /* the rate mixture parameter does not apply to part2 */
13674 
13675         /* We may have a nucleotide model. Make certain the models are not of type codon. */
13676         if (!strcmp(modelParams[part1].nucModel, "Codon"))
13677             *isApplic1 = NO; /* we have a codon model for part1, and a shape parameter does not apply */
13678         if (!strcmp(modelParams[part2].nucModel, "Codon"))
13679             *isApplic2 = NO;/* we have a codon model for part2, and a shape parameter does not apply */
13680 
13681         /* Check that the model structure is the same for both partitions */
13682         if ((!strcmp(modelParams[part1].nucModel, "4by4") || !strcmp(modelParams[part1].nucModel, "Doublet")) && !strcmp(modelParams[part2].nucModel, "Codon"))
13683             isSame = NO; /* the nucleotide models are incompatible with the same rate mixture parameter */
13684         if ((!strcmp(modelParams[part2].nucModel, "4by4") || !strcmp(modelParams[part2].nucModel, "Doublet")) && !strcmp(modelParams[part1].nucModel, "Codon"))
13685             isSame = NO; /* the nucleotide models are incompatible with the same rate mixture parameter */
13686 
13687         /* if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel))
13688          isSame = NO; */ /* the models have different covarion struture */
13689         /* NOTE: Perhaps we should allow the possiblity that the shape parameter is the same for the case
13690          where one partition has a covarion model but the other does not and both datatypes are the same. */
13691 
13692         /* Check that the number of rate components is the same */
13693         if (modelParams[part1].numMixtCats != modelParams[part2].numMixtCats)
13694             isSame = NO; /* the number of rate components is not the same, so we cannot set the parameter to be equal for both partitions */
13695 
13696         /* Check that the priors are the same. */
13697         /* For now we only allow a flat Dirichlet prior, so this is not needed */
13698 
13699         /* Check to see if the rate mixture parameter is inapplicable for either partition. */
13700         if ((*isApplic1) == NO || (*isApplic2) == NO)
13701             isSame = NO; /* if the rate mixture parameter is inapplicable for either partition, then the parameter cannot be the same */
13702         }
13703     else if (whichParam == P_SHAPE)
13704         {
13705         /* Check the shape parameter for partitions 1 and 2 (this applies to the lnorm as well as various gamma models of rate variation across sites) */
13706 
13707         /* Check if the model is parsimony for either partition */
13708         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13709             *isApplic1 = NO; /* part1 has a parsimony model and shape parameter does not apply */
13710         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13711             *isApplic2 = NO; /* part2 has a parsimony model and shape parameter does not apply */
13712 
13713         /* Check that the data are not CONTINUOUS for partitions 1 and 2 */
13714         if (modelParams[part1].dataType == CONTINUOUS)
13715             *isApplic1 = NO; /* the shape parameter does not make sense for part1 */
13716         if (modelParams[part2].dataType == CONTINUOUS)
13717             *isApplic2 = NO; /* the shape parameter does not make sense for part2 */
13718 
13719         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid, or whatever). */
13720         if (isFirstNucleotide != isSecondNucleotide)
13721             isSame = NO; /* data are not both nucleotide */
13722         else if (modelParams[part1].dataType != modelParams[part2].dataType && isFirstNucleotide == NO)
13723             isSame = NO; /* data are not the same */
13724 
13725         /* Let's check that the shape parameter is even relevant for the two partitions */
13726         if (!strcmp(modelParams[part1].ratesModel, "Equal") || !strcmp(modelParams[part1].ratesModel, "Propinv")
13727             || !strcmp(modelParams[part1].ratesModel, "Kmixture"))
13728             *isApplic1 = NO; /* the shape parameter does not make sense for part1 */
13729         if (!strcmp(modelParams[part2].ratesModel, "Equal") || !strcmp(modelParams[part2].ratesModel, "Propinv")
13730             || !strcmp(modelParams[part2].ratesModel, "Kmixture"))
13731             *isApplic2 = NO; /* the shape parameter does not make sense for part2 */
13732 
13733         /* Check that the model is either lnorm or gamma for both partitions */
13734         if (!strcmp(modelParams[part1].ratesModel, "Lnorm") && strcmp(modelParams[part1].ratesModel, "Lnorm") != 0)
13735             isSame = NO;    /* if the first is lnorm, the second must be lnorm */
13736         if (strcmp(modelParams[part1].ratesModel, "Lnorm") != 0 && !strcmp(modelParams[part1].ratesModel, "Lnorm"))
13737             isSame = NO;    /* if the first is not lnorm, the second cannot be lnorm */
13738 
13739         /* We may have a nucleotide model. Make certain the models are not of type codon. */
13740         if (!strcmp(modelParams[part1].nucModel, "Codon"))
13741             *isApplic1 = NO; /* we have a codon model for part1, and a shape parameter does not apply */
13742         if (!strcmp(modelParams[part2].nucModel, "Codon"))
13743             *isApplic2 = NO;/* we have a codon model for part2, and a shape parameter does not apply */
13744 
13745         /* Check that the model structure is the same for both partitions */
13746         if ((!strcmp(modelParams[part1].nucModel, "4by4") || !strcmp(modelParams[part1].nucModel, "Doublet")) && !strcmp(modelParams[part2].nucModel, "Codon"))
13747             isSame = NO; /* the nucleotide models are incompatible with the same shape parameter */
13748         if ((!strcmp(modelParams[part2].nucModel, "4by4") || !strcmp(modelParams[part2].nucModel, "Doublet")) && !strcmp(modelParams[part1].nucModel, "Codon"))
13749             isSame = NO; /* the nucleotide models are incompatible with the same shape parameter */
13750         /* if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel))
13751             isSame = NO; */ /* the models have different covarion struture */
13752         /* NOTE: Perhaps we should allow the possiblity that the shape parameter is the same for the case
13753                  where one partition has a covarion model but the other does not and both datatypes are the same. */
13754 
13755         /* Check that the number of rate categories is the same */
13756         if (!strcmp(modelParams[part1].ratesModel, "Lnorm") && (modelParams[part1].numLnormCats != modelParams[part2].numLnormCats))
13757             isSame = NO; /* the number of rate categories is not the same, so we cannot set the parameter to be equal for both partitions */
13758         else if (modelParams[part1].numGammaCats != modelParams[part2].numGammaCats)
13759             isSame = NO; /* the number of rate categories is not the same, so we cannot set the parameter to be equal for both partitions */
13760 
13761         /* Check that the priors are the same. */
13762         if (!strcmp(modelParams[part1].shapePr,"Uniform") && !strcmp(modelParams[part2].shapePr,"Uniform"))
13763             {
13764             if (AreDoublesEqual (modelParams[part1].shapeUni[0], modelParams[part2].shapeUni[0], (MrBFlt) 0.00001) == NO)
13765                 isSame = NO;
13766             if (AreDoublesEqual (modelParams[part1].shapeUni[1], modelParams[part2].shapeUni[1], (MrBFlt) 0.00001) == NO)
13767                 isSame = NO;
13768             }
13769         else if (!strcmp(modelParams[part1].shapePr,"Exponential") && !strcmp(modelParams[part2].shapePr,"Exponential"))
13770             {
13771             if (AreDoublesEqual (modelParams[part1].shapeExp, modelParams[part2].shapeExp, (MrBFlt) 0.00001) == NO)
13772                 isSame = NO;
13773             }
13774         else if (!strcmp(modelParams[part1].shapePr,"Fixed") && !strcmp(modelParams[part2].shapePr,"Fixed"))
13775             {
13776             if (AreDoublesEqual (modelParams[part1].shapeFix, modelParams[part2].shapeFix, (MrBFlt) 0.00001) == NO)
13777                 isSame = NO;
13778             }
13779         else
13780             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13781 
13782         /* Check to see if the shape parameter is inapplicable for either partition. */
13783         if ((*isApplic1) == NO || (*isApplic2) == NO)
13784             isSame = NO; /* if the shape parameter is inapplicable for either partition, then the parameter cannot be the same */
13785         }
13786     else if (whichParam == P_PINVAR)
13787         {
13788         /* Check the proportion of invariable sites parameter for partitions 1 and 2. */
13789 
13790         /* Check if the model is parsimony for either partition */
13791         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13792             *isApplic1 = NO; /* part1 has a parsimony model and proportion of invariable sites parameter does not apply */
13793         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13794             *isApplic2 = NO; /* part2 has a parsimony model and proportion of invariable sites parameter does not apply */
13795 
13796         /* Check that the data are not CONTINUOUS for partitions 1 and 2 */
13797         if (modelParams[part1].dataType == CONTINUOUS)
13798             *isApplic1 = NO; /* the proportion of invariable sites parameter does not make sense for part1 */
13799         if (modelParams[part2].dataType == CONTINUOUS)
13800             *isApplic2 = NO; /* the proportion of invariable sites parameter does not make sense for part2 */
13801 
13802         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid, or whatever). */
13803         if (isFirstNucleotide != isSecondNucleotide)
13804             isSame = NO; /* data are not both nucleotide */
13805         else if (modelParams[part1].dataType != modelParams[part2].dataType && isFirstNucleotide == NO)
13806             isSame = NO; /* data are not the same */
13807 
13808         /* Let's check that proportion of invariable sites parameter is even relevant for the two partitions */
13809         if (!strcmp(modelParams[part1].ratesModel, "Equal") || !strcmp(modelParams[part1].ratesModel, "Gamma") ||
13810             !strcmp(modelParams[part1].ratesModel, "LNorm") || !strcmp(modelParams[part1].ratesModel, "Adgamma") ||
13811             !strcmp(modelParams[part1].ratesModel, "Kmixture"))
13812             *isApplic1 = NO; /* the proportion of invariable sites parameter does not make sense for part1 */
13813         if (!strcmp(modelParams[part2].ratesModel, "Equal") || !strcmp(modelParams[part2].ratesModel, "Gamma") ||
13814             !strcmp(modelParams[part2].ratesModel, "LNorm") || !strcmp(modelParams[part2].ratesModel, "Adgamma") ||
13815             !strcmp(modelParams[part1].ratesModel, "Kmixture"))
13816             *isApplic2 = NO; /* the proportion of invariable sites parameter does not make sense for part2 */
13817 
13818         /* It is not sensible to have a covarion model and a proportion of invariable sites */
13819         if (!strcmp(modelParams[part1].covarionModel, "Yes"))
13820             *isApplic1 = NO;
13821         if (!strcmp(modelParams[part2].covarionModel, "Yes"))
13822             *isApplic2 = NO;
13823 
13824         /* We have a nucleotide model. Make certain the models are not of type codon. */
13825         if (!strcmp(modelParams[part1].nucModel, "Codon"))
13826             *isApplic1 = NO; /* we have a codon model for part1, and a proportion of invariable sites parameter does not apply */
13827         if (!strcmp(modelParams[part2].nucModel, "Codon"))
13828             *isApplic2 = NO;/* we have a codon model for part2, and a proportion of invariable sites parameter does not apply */
13829 
13830         /* Check that the model structure is the same for both partitions */
13831         if (strcmp(modelParams[part1].nucModel, modelParams[part2].nucModel))
13832             isSame = NO; /* the nucleotide models are different */
13833         if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel))
13834             isSame = NO; /* the models have different covarion struture */
13835 
13836         /* check the priors */
13837         if (!strcmp(modelParams[part1].pInvarPr,"Uniform") && !strcmp(modelParams[part2].pInvarPr,"Uniform"))
13838             {
13839             if (AreDoublesEqual (modelParams[part1].pInvarUni[0], modelParams[part2].pInvarUni[0], (MrBFlt) 0.00001) == NO)
13840                 isSame = NO;
13841             if (AreDoublesEqual (modelParams[part1].pInvarUni[1], modelParams[part2].pInvarUni[1], (MrBFlt) 0.00001) == NO)
13842                 isSame = NO;
13843             }
13844         else if (!strcmp(modelParams[part1].pInvarPr,"Fixed") && !strcmp(modelParams[part2].pInvarPr,"Fixed"))
13845             {
13846             if (AreDoublesEqual (modelParams[part1].pInvarFix, modelParams[part2].pInvarFix, (MrBFlt) 0.00001) == NO)
13847                 isSame = NO;
13848             }
13849         else
13850             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13851 
13852         /* Check to see if the switching rates are inapplicable for either partition. */
13853         if ((*isApplic1) == NO || (*isApplic2) == NO)
13854             isSame = NO; /* if the switching rates are inapplicable for either partition, then the parameter cannot be the same */
13855         }
13856     else if (whichParam == P_CORREL)
13857         {
13858         /* Check the autocorrelation parameter for gamma rates on partitions 1 and 2. */
13859 
13860         /* Check if the model is parsimony for either partition */
13861         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13862             *isApplic1 = NO; /* part1 has a parsimony model and autocorrelation parameter does not apply */
13863         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13864             *isApplic2 = NO; /* part2 has a parsimony model and autocorrelation parameter does not apply */
13865 
13866         /* Check that the data are either DNA, RNA, or PROTEIN for partitions 1 and 2 */
13867         if (modelSettings[part1].dataType != DNA && modelSettings[part1].dataType != RNA && modelSettings[part1].dataType != PROTEIN)
13868             *isApplic1 = NO; /* the switching rates do not make sense for part1 */
13869         if (modelSettings[part2].dataType != DNA && modelSettings[part2].dataType != RNA && modelSettings[part2].dataType != PROTEIN)
13870             *isApplic2 = NO; /* the switching rates do not make sense for part2 */
13871 
13872         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid). */
13873         if (isFirstNucleotide != isSecondNucleotide)
13874             isSame = NO; /* one or the other is nucleotide, so they cannot be the same */
13875         else if (modelSettings[part1].dataType != modelSettings[part2].dataType && isFirstNucleotide == NO)
13876             isSame = NO; /* data are not both nucleotide or both amino acid */
13877 
13878         /* Let's check that autocorrelation parameter is even relevant for the two partitions */
13879         if (strcmp(modelParams[part1].ratesModel, "Adgamma"))
13880             *isApplic1 = NO; /* the autocorrelation parameter does not make sense for part1 */
13881         if (strcmp(modelParams[part2].ratesModel, "Adgamma"))
13882             *isApplic2 = NO; /* the autocorrelation parameter does not make sense for part2 */
13883 
13884         /* Assuming that we have a nucleotide model, make certain the models are not of type codon. */
13885         if (!strcmp(modelParams[part1].nucModel, "Codon"))
13886             *isApplic1 = NO; /* we have a codon model for part1, and a autocorrelation parameter does not apply */
13887         if (!strcmp(modelParams[part2].nucModel, "Codon"))
13888             *isApplic2 = NO; /* we have a codon model for part2, and a autocorrelation parameter does not apply */
13889 
13890         /* Check that the model structure is the same for both partitions */
13891         if (strcmp(modelParams[part1].nucModel, modelParams[part2].nucModel))
13892             isSame = NO; /* the nucleotide models are different */
13893         if (strcmp(modelParams[part1].covarionModel, modelParams[part2].covarionModel))
13894             isSame = NO; /* the models have different covarion struture */
13895 
13896         /* Check the priors for both partitions. */
13897         if (!strcmp(modelParams[part1].adGammaCorPr,"Uniform") && !strcmp(modelParams[part2].adGammaCorPr,"Uniform"))
13898             {
13899             if (AreDoublesEqual (modelParams[part1].corrUni[0], modelParams[part2].corrUni[0], (MrBFlt) 0.00001) == NO)
13900                 isSame = NO;
13901             if (AreDoublesEqual (modelParams[part1].corrUni[1], modelParams[part2].corrUni[1], (MrBFlt) 0.00001) == NO)
13902                 isSame = NO;
13903             }
13904         else if (!strcmp(modelParams[part1].adGammaCorPr,"Fixed") && !strcmp(modelParams[part2].adGammaCorPr,"Fixed"))
13905             {
13906             if (AreDoublesEqual (modelParams[part1].corrFix, modelParams[part2].corrFix, (MrBFlt) 0.00001) == NO)
13907                 isSame = NO;
13908             }
13909         else
13910             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13911 
13912         /* Check to see if the switching rates are inapplicable for either partition. */
13913         if ((*isApplic1) == NO || (*isApplic2) == NO)
13914             isSame = NO; /* if the switching rates are inapplicable for either partition, then the parameter cannot be the same */
13915         }
13916     else if (whichParam == P_SWITCH)
13917         {
13918         /* Check the covarion switching rates on partitions 1 and 2. */
13919 
13920         /* Check if the model is parsimony for either partition */
13921         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13922             *isApplic1 = NO; /* part1 has a parsimony model and switching rates do not apply */
13923         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13924             *isApplic2 = NO; /* part2 has a parsimony model and switching rates do not apply */
13925 
13926         /* Check that the data are either DNA, RNA, or PROTEIN for partitions 1 and 2 */
13927         if (modelSettings[part1].dataType != DNA && modelSettings[part1].dataType != RNA && modelSettings[part1].dataType != PROTEIN)
13928             *isApplic1 = NO; /* the switching rates do not make sense for part1 */
13929         if (modelSettings[part2].dataType != DNA && modelSettings[part2].dataType != RNA && modelSettings[part2].dataType != PROTEIN)
13930             *isApplic2 = NO; /* the switching rates do not make sense for part2 */
13931 
13932         /* Now, check that the data are the same (i.e., both nucleotide or both amino acid). */
13933         if (isFirstNucleotide != isSecondNucleotide)
13934             isSame = NO; /* one or the other is nucleotide, so they cannot be the same */
13935         else if (modelSettings[part1].dataType != modelSettings[part2].dataType && isFirstNucleotide == NO)
13936             isSame = NO; /* data are not both nucleotide or both amino acid */
13937 
13938         /* Lets check that covarion model has been selected for partitions 1 and 2 */
13939         if (!strcmp(modelParams[part1].covarionModel, "No"))
13940             *isApplic1 = NO; /* the switching rates do not make sense for part1 */
13941         if (!strcmp(modelParams[part2].covarionModel, "No"))
13942             *isApplic2 = NO; /* the switching rates do not make sense for part2 */
13943 
13944         /* If we have a nucleotide model make certain the models are not of type codon or doublet. */
13945         if (!strcmp(modelParams[part1].nucModel, "Codon") || !strcmp(modelParams[part1].nucModel, "Doublet"))
13946             *isApplic1 = NO; /* we have a codon model for part1, and a covarion switch parameter does not apply */
13947         if (!strcmp(modelParams[part2].nucModel, "Codon") || !strcmp(modelParams[part2].nucModel, "Doublet"))
13948             *isApplic2 = NO; /* we have a codon model for part2, and a covarion switch parameter does not apply */
13949 
13950         /* Check that the priors are the same. */
13951         if (!strcmp(modelParams[part1].covSwitchPr,"Uniform") && !strcmp(modelParams[part2].covSwitchPr,"Uniform"))
13952             {
13953             if (AreDoublesEqual (modelParams[part1].covswitchUni[0], modelParams[part2].covswitchUni[0], (MrBFlt) 0.00001) == NO)
13954                 isSame = NO;
13955             if (AreDoublesEqual (modelParams[part1].covswitchUni[1], modelParams[part2].covswitchUni[1], (MrBFlt) 0.00001) == NO)
13956                 isSame = NO;
13957             }
13958         else if (!strcmp(modelParams[part1].covSwitchPr,"Exponential") && !strcmp(modelParams[part2].covSwitchPr,"Exponential"))
13959             {
13960             if (AreDoublesEqual (modelParams[part1].covswitchExp, modelParams[part2].covswitchExp, (MrBFlt) 0.00001) == NO)
13961                 isSame = NO;
13962             }
13963         else if (!strcmp(modelParams[part1].covSwitchPr,"Fixed") && !strcmp(modelParams[part2].covSwitchPr,"Fixed"))
13964             {
13965             if (AreDoublesEqual (modelParams[part1].covswitchFix[0], modelParams[part2].covswitchFix[0], (MrBFlt) 0.00001) == NO)
13966                 isSame = NO;
13967             if (AreDoublesEqual (modelParams[part1].covswitchFix[1], modelParams[part2].covswitchFix[1], (MrBFlt) 0.00001) == NO)
13968                 isSame = NO;
13969             }
13970         else
13971             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
13972 
13973         /* Check to see if the switching rates are inapplicable for either partition. */
13974         if ((*isApplic1) == NO || (*isApplic2) == NO)
13975             isSame = NO; /* if the switching rates are inapplicable for either partition, then the parameter cannot be the same */
13976         }
13977     else if (whichParam == P_RATEMULT)
13978         {
13979         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
13980            silly and doesn't take this information into account) and a rate multiplier is nonsensical. */
13981         if (!strcmp(modelParams[part1].parsModel, "Yes"))
13982             *isApplic1 = NO;
13983         if (!strcmp(modelParams[part2].parsModel, "Yes"))
13984             *isApplic2 = NO;
13985 
13986         /* Check that the branch lengths are at least proportional. */
13987         if (IsModelSame (P_BRLENS, part1, part2, &temp1, &temp2) == NO)
13988             isSame = NO;
13989         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
13990             isSame = NO;
13991 
13992         /* See if the rate prior is the same for the partitions */
13993         if (strcmp(modelParams[part1].ratePr, modelParams[part2].ratePr) != 0)
13994             isSame = NO;
13995 
13996         /* Check to see if rate multipliers are inapplicable for either partition. */
13997         if ((*isApplic1) == NO || (*isApplic2) == NO)
13998             isSame = NO;
13999 
14000         }
14001     else if (whichParam == P_TOPOLOGY)
14002         {
14003         /* Check the topology for partitions 1 and 2. */
14004 
14005         /* If the prior is different, then the topologies cannot be the same. */
14006         if (strcmp(modelParams[part1].topologyPr, modelParams[part2].topologyPr))
14007             isSame = NO;
14008 
14009         /* If both partitions have topologies constrained, then we need to make certain that the constraints are the same. */
14010         /* This also guarantees that any calibrations will be the same. */
14011         if (!strcmp(modelParams[part1].topologyPr, "Constraints") && !strcmp(modelParams[part2].topologyPr, "Constraints"))
14012             {
14013             if (modelParams[part1].numActiveConstraints != modelParams[part2].numActiveConstraints)
14014                 isSame = NO;
14015             else
14016                 {
14017                 nDiff = 0;
14018                 for (i=0; i<numDefinedConstraints; i++)
14019                     if (modelParams[part1].activeConstraints[i] != modelParams[part2].activeConstraints[i])
14020                         nDiff++;
14021                 if (nDiff != 0)
14022                     isSame = NO;
14023                 }
14024             }
14025         }
14026     else if (whichParam == P_BRLENS)
14027         {
14028         /* Check the branch lengths for partitions 1 and 2. */
14029 
14030         /* First, if the topologies are different, the same branch lengths cannot apply. */
14031         if (IsModelSame (P_TOPOLOGY, part1, part2, &temp1, &temp2) == NO)
14032             isSame = NO;
14033         if (linkTable[P_TOPOLOGY][part1] != linkTable[P_TOPOLOGY][part2])
14034             isSame = NO;
14035 
14036         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14037            silly and doesn't take this information into account). */
14038         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14039             *isApplic1 = NO;
14040         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14041             *isApplic2 = NO;
14042 
14043         /* Check to see if the branch lengths are inapplicable for either partition. */
14044         if ((*isApplic1) == NO || (*isApplic2) == NO)
14045             isSame = NO;
14046 
14047         /* Make sure the branch lengths have the same priors and are not unlinked */
14048         if (*isApplic1 == YES && *isApplic2 == YES)
14049             {
14050             /* We are dealing with real branch lengths (not parsimony) for both partitions */
14051 
14052             /* The branch length prior should be the same */
14053             if (strcmp(modelParams[part1].brlensPr, modelParams[part2].brlensPr))
14054                 isSame = NO;
14055 
14056             /* if both partitions have unconstrained brlens, then we need to check that the priors on the branch lengths are the same */
14057             if (!strcmp(modelParams[part1].brlensPr, "Unconstrained") && !strcmp(modelParams[part2].brlensPr, "Unconstrained"))
14058                 {
14059                 if (strcmp(modelParams[part1].unconstrainedPr, modelParams[part2].unconstrainedPr))
14060                     isSame = NO;
14061                 else
14062                     {
14063                     if (!strcmp(modelParams[part1].unconstrainedPr, "Uniform"))
14064                         {
14065                         if (AreDoublesEqual (modelParams[part1].brlensUni[0], modelParams[part2].brlensUni[0], (MrBFlt) 0.00001) == NO)
14066                             isSame = NO;
14067                         if (AreDoublesEqual (modelParams[part1].brlensUni[1], modelParams[part2].brlensUni[1], (MrBFlt) 0.00001) == NO)
14068                             isSame = NO;
14069                         }
14070                     else if (!strcmp(modelParams[part1].unconstrainedPr, "Exponential"))
14071                         {
14072                         if (AreDoublesEqual (modelParams[part1].brlensExp, modelParams[part2].brlensExp, (MrBFlt) 0.00001) == NO)
14073                             isSame = NO;
14074                         }
14075                     else if (!strcmp(modelParams[part1].unconstrainedPr, "twoExp"))
14076                         {
14077                             if (AreDoublesEqual (modelParams[part1].brlens2Exp[0], modelParams[part2].brlens2Exp[0], (MrBFlt) 0.00001) == NO)
14078                                 isSame = NO;
14079                             if (AreDoublesEqual (modelParams[part1].brlens2Exp[1], modelParams[part2].brlens2Exp[1], (MrBFlt) 0.00001) == NO)
14080                                 isSame = NO;
14081                         }
14082                     else
14083                         {
14084                         if (AreDoublesEqual (modelParams[part1].brlensDir[0], modelParams[part2].brlensDir[0], (MrBFlt) 0.00001) == NO)
14085                             isSame = NO;
14086                         if (AreDoublesEqual (modelParams[part1].brlensDir[1], modelParams[part2].brlensDir[1], (MrBFlt) 0.00001) == NO)
14087                             isSame = NO;
14088                         if (AreDoublesEqual (modelParams[part1].brlensDir[2], modelParams[part2].brlensDir[2], (MrBFlt) 0.00001) == NO)
14089                             isSame = NO;
14090                         if (AreDoublesEqual (modelParams[part1].brlensDir[3], modelParams[part2].brlensDir[3], (MrBFlt) 0.00001) == NO)
14091                             isSame = NO;
14092                         }
14093                     }
14094                 }
14095 
14096             /* if both partitions have clock brlens, then we need to check that the priors on the clock are the same */
14097             if (!strcmp(modelParams[part1].brlensPr, "Clock") && !strcmp(modelParams[part2].brlensPr, "Clock"))
14098                 {
14099                 if (strcmp(modelParams[part1].clockPr, modelParams[part2].clockPr))
14100                     isSame = NO;
14101                 else
14102                     {
14103                     if (!strcmp(modelParams[part1].clockPr, "Birthdeath"))
14104                         {
14105                         if (!strcmp(modelParams[part1].speciationPr,"Uniform") && !strcmp(modelParams[part2].speciationPr,"Uniform"))
14106                             {
14107                             if (AreDoublesEqual (modelParams[part1].speciationUni[0], modelParams[part2].speciationUni[0], (MrBFlt) 0.00001) == NO)
14108                                 isSame = NO;
14109                             if (AreDoublesEqual (modelParams[part1].speciationUni[1], modelParams[part2].speciationUni[1], (MrBFlt) 0.00001) == NO)
14110                                 isSame = NO;
14111                             }
14112                         else if (!strcmp(modelParams[part1].speciationPr,"Exponential") && !strcmp(modelParams[part2].speciationPr,"Exponential"))
14113                             {
14114                             if (AreDoublesEqual (modelParams[part1].speciationExp, modelParams[part2].speciationExp, (MrBFlt) 0.00001) == NO)
14115                                 isSame = NO;
14116                             }
14117                         else if (!strcmp(modelParams[part1].speciationPr,"Fixed") && !strcmp(modelParams[part2].speciationPr,"Fixed"))
14118                             {
14119                             if (AreDoublesEqual (modelParams[part1].speciationFix, modelParams[part2].speciationFix, (MrBFlt) 0.00001) == NO)
14120                                 isSame = NO;
14121                             }
14122                         else
14123                             isSame = NO;
14124 
14125                         if (!strcmp(modelParams[part1].extinctionPr,"Beta") && !strcmp(modelParams[part2].extinctionPr,"Beta"))
14126                             {
14127                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[0], modelParams[part2].extinctionBeta[0], (MrBFlt) 0.00001) == NO)
14128                                 isSame = NO;
14129                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[1], modelParams[part2].extinctionBeta[1], (MrBFlt) 0.00001) == NO)
14130                                 isSame = NO;
14131                             }
14132                         else if (!strcmp(modelParams[part1].extinctionPr,"Fixed") && !strcmp(modelParams[part2].extinctionPr,"Fixed"))
14133                             {
14134                             if (AreDoublesEqual (modelParams[part1].extinctionFix, modelParams[part2].extinctionFix, (MrBFlt) 0.00001) == NO)
14135                                 isSame = NO;
14136                             }
14137                         else
14138                             isSame = NO;
14139 
14140                         if (AreDoublesEqual (modelParams[part1].sampleProb, modelParams[part2].sampleProb, 0.00001) == NO)
14141                             isSame = NO;
14142                         if (strcmp(modelParams[part1].sampleStrat,modelParams[part2].sampleStrat))
14143                             isSame = NO;
14144                         }
14145                     else if (!strcmp(modelParams[part1].clockPr, "Coalescence") || !strcmp(modelParams[part1].clockPr, "Speciestreecoalescence"))
14146                         {
14147                         if (!strcmp(modelParams[part1].popSizePr,"Uniform") && !strcmp(modelParams[part2].popSizePr,"Uniform"))
14148                             {
14149                             if (AreDoublesEqual (modelParams[part1].popSizeUni[0], modelParams[part2].popSizeUni[0], (MrBFlt) 0.00001) == NO)
14150                                 isSame = NO;
14151                             if (AreDoublesEqual (modelParams[part1].popSizeUni[1], modelParams[part2].popSizeUni[1], (MrBFlt) 0.00001) == NO)
14152                                 isSame = NO;
14153                             }
14154                         else if (!strcmp(modelParams[part1].popSizePr,"Lognormal") && !strcmp(modelParams[part2].popSizePr,"Lognormal"))
14155                             {
14156                             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[0], modelParams[part2].popSizeLognormal[0], (MrBFlt) 0.00001) == NO)
14157                                 isSame = NO;
14158                             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[1], modelParams[part2].popSizeLognormal[1], (MrBFlt) 0.00001) == NO)
14159                                 isSame = NO;
14160                             }
14161                         else if (!strcmp(modelParams[part1].popSizePr,"Normal") && !strcmp(modelParams[part2].popSizePr,"Normal"))
14162                             {
14163                             if (AreDoublesEqual (modelParams[part1].popSizeNormal[0], modelParams[part2].popSizeNormal[0], (MrBFlt) 0.00001) == NO)
14164                                 isSame = NO;
14165                             if (AreDoublesEqual (modelParams[part1].popSizeNormal[1], modelParams[part2].popSizeNormal[1], (MrBFlt) 0.00001) == NO)
14166                                 isSame = NO;
14167                             }
14168                         else if (!strcmp(modelParams[part1].popSizePr,"Gamma") && !strcmp(modelParams[part2].popSizePr,"Gamma"))
14169                             {
14170                             if (AreDoublesEqual (modelParams[part1].popSizeGamma[0], modelParams[part2].popSizeGamma[0], (MrBFlt) 0.00001) == NO)
14171                                 isSame = NO;
14172                             if (AreDoublesEqual (modelParams[part1].popSizeGamma[1], modelParams[part2].popSizeGamma[1], (MrBFlt) 0.00001) == NO)
14173                                 isSame = NO;
14174                             }
14175                         else if (!strcmp(modelParams[part1].popSizePr,"Fixed") && !strcmp(modelParams[part2].popSizePr,"Fixed"))
14176                             {
14177                             if (AreDoublesEqual (modelParams[part1].popSizeFix, modelParams[part2].popSizeFix, (MrBFlt) 0.00001) == NO)
14178                                 isSame = NO;
14179                             }
14180                         else
14181                             isSame = NO;
14182 
14183                         if (strcmp(modelParams[part1].ploidy, modelParams[part2].ploidy) != 0)
14184                             isSame = NO;
14185                         }
14186                     if (strcmp(modelParams[part1].clockPr, "Uniform") == 0 && strcmp(modelParams[part1].nodeAgePr, "Calibrated") != 0)
14187                         {
14188                         if (modelParams[part1].treeAgePr.prior != modelParams[part2].treeAgePr.prior)
14189                             isSame = NO;
14190                         if (modelParams[part1].treeAgePr.prior == fixed)
14191                             {
14192                             if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[0], modelParams[part2].treeAgePr.priorParams[0], (MrBFlt) 0.00001) == NO)
14193                                 isSame = NO;
14194                             }
14195                         else if (modelParams[part1].treeAgePr.prior == offsetLogNormal ||
14196                             modelParams[part1].treeAgePr.prior == truncatedNormal ||
14197                             modelParams[part1].treeAgePr.prior == offsetGamma)
14198                             {
14199                             for (i=0; i<3; i++)
14200                                 {
14201                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
14202                                     isSame = NO;
14203                                 }
14204                             }
14205                         else
14206                             {
14207                             for (i=0; i<2; i++)
14208                                 {
14209                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
14210                                     isSame = NO;
14211                                 }
14212                             }
14213                         }
14214                     else if (strcmp(modelParams[part1].clockPr, "Fossilization") == 0)
14215                         {
14216                         if (modelParams[part1].treeAgePr.prior != modelParams[part2].treeAgePr.prior)
14217                             isSame = NO;
14218                         if (modelParams[part1].treeAgePr.prior == fixed)
14219                             {
14220                             if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[0], modelParams[part2].treeAgePr.priorParams[0], (MrBFlt) 0.00001) == NO)
14221                                 isSame = NO;
14222                             }
14223                         else if (modelParams[part1].treeAgePr.prior == offsetLogNormal ||
14224                             modelParams[part1].treeAgePr.prior == truncatedNormal ||
14225                             modelParams[part1].treeAgePr.prior == offsetGamma)
14226                             {
14227                             for (i=0; i<3; i++)
14228                                 {
14229                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
14230                                     isSame = NO;
14231                                 }
14232                             }
14233                         else
14234                             {
14235                             for (i=0; i<2; i++)
14236                                 {
14237                                 if (AreDoublesEqual (modelParams[part1].treeAgePr.priorParams[i], modelParams[part2].treeAgePr.priorParams[i], (MrBFlt) 0.00001) == NO)
14238                                     isSame = NO;
14239                                 }
14240                             }
14241 
14242                         if (!strcmp(modelParams[part1].speciationPr,"Uniform") && !strcmp(modelParams[part2].speciationPr,"Uniform"))
14243                             {
14244                             if (AreDoublesEqual (modelParams[part1].speciationUni[0], modelParams[part2].speciationUni[0], (MrBFlt) 0.00001) == NO)
14245                                 isSame = NO;
14246                             if (AreDoublesEqual (modelParams[part1].speciationUni[1], modelParams[part2].speciationUni[1], (MrBFlt) 0.00001) == NO)
14247                                 isSame = NO;
14248                             }
14249                         else if (!strcmp(modelParams[part1].speciationPr,"Exponential") && !strcmp(modelParams[part2].speciationPr,"Exponential"))
14250                             {
14251                             if (AreDoublesEqual (modelParams[part1].speciationExp, modelParams[part2].speciationExp, (MrBFlt) 0.00001) == NO)
14252                                 isSame = NO;
14253                             }
14254                         else if (!strcmp(modelParams[part1].speciationPr,"Fixed") && !strcmp(modelParams[part2].speciationPr,"Fixed"))
14255                             {
14256                             if (AreDoublesEqual (modelParams[part1].speciationFix, modelParams[part2].speciationFix, (MrBFlt) 0.00001) == NO)
14257                                 isSame = NO;
14258                             }
14259                         else
14260                             isSame = NO;
14261 
14262                         if (!strcmp(modelParams[part1].extinctionPr,"Beta") && !strcmp(modelParams[part2].extinctionPr,"Beta"))
14263                             {
14264                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[0], modelParams[part2].extinctionBeta[0], (MrBFlt) 0.00001) == NO)
14265                                 isSame = NO;
14266                             if (AreDoublesEqual (modelParams[part1].extinctionBeta[1], modelParams[part2].extinctionBeta[1], (MrBFlt) 0.00001) == NO)
14267                                 isSame = NO;
14268                             }
14269                         else if (!strcmp(modelParams[part1].extinctionPr,"Fixed") && !strcmp(modelParams[part2].extinctionPr,"Fixed"))
14270                             {
14271                             if (AreDoublesEqual (modelParams[part1].extinctionFix, modelParams[part2].extinctionFix, (MrBFlt) 0.00001) == NO)
14272                                 isSame = NO;
14273                             }
14274                         else
14275                             isSame = NO;
14276 
14277                         if (!strcmp(modelParams[part1].fossilizationPr,"Beta") && !strcmp(modelParams[part2].fossilizationPr,"Beta"))
14278                             {
14279                             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[0], modelParams[part2].fossilizationBeta[0], (MrBFlt) 0.00001) == NO)
14280                                 isSame = NO;
14281                             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[1], modelParams[part2].fossilizationBeta[1], (MrBFlt) 0.00001) == NO)
14282                                 isSame = NO;
14283                             }
14284                         else if (!strcmp(modelParams[part1].fossilizationPr,"Fixed") && !strcmp(modelParams[part2].fossilizationPr,"Fixed"))
14285                             {
14286                             if (AreDoublesEqual (modelParams[part1].fossilizationFix, modelParams[part2].fossilizationFix, (MrBFlt) 0.00001) == NO)
14287                                 isSame = NO;
14288                             }
14289                         else
14290                             isSame = NO;
14291 
14292                         if (AreDoublesEqual (modelParams[part1].sampleProb, modelParams[part2].sampleProb, 0.00001) == NO)
14293                             isSame = NO;
14294                         if (strcmp(modelParams[part1].sampleStrat,modelParams[part2].sampleStrat))
14295                             isSame = NO;
14296                         }
14297                     }
14298 
14299                 /* if the same clock prior, we need to check calibrations */
14300                 if (strcmp(modelParams[part1].nodeAgePr,modelParams[part2].nodeAgePr) != 0)
14301                     isSame = NO;
14302 
14303                 /* If fixed clock brlens, check if the brlens come from the same tree */
14304                 if (!strcmp(modelParams[part1].clockPr, "Fixed") && !strcmp(modelParams[part2].clockPr, "Fixed"))
14305                     {
14306                     if (modelParams[part1].brlensFix != modelParams[part2].brlensFix)
14307                         isSame = NO;
14308                     }
14309                 }
14310             /* If fixed brlens, check if the brlens come from the same tree */
14311             if (!strcmp(modelParams[part1].brlensPr, "Fixed") && !strcmp(modelParams[part2].brlensPr, "Fixed"))
14312                 {
14313                 if (modelParams[part1].brlensFix != modelParams[part2].brlensFix)
14314                     isSame = NO;
14315                 }
14316             }
14317         }
14318     else if (whichParam == P_SPECRATE)
14319         {
14320         /* Check the speciation rates for partitions 1 and 2. */
14321 
14322         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14323            silly and doesn't take this information into account) and a speciation rate cannot be estimated. */
14324         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14325             *isApplic1 = NO;
14326         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14327             *isApplic2 = NO;
14328 
14329         /* Check that the branch length prior is a clock:birthdeath or clock:fossilization for both partitions. */
14330         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14331             *isApplic1 = NO;
14332         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14333             *isApplic2 = NO;
14334         if (strcmp(modelParams[part1].clockPr, "Birthdeath") != 0 && strcmp(modelParams[part1].clockPr, "Fossilization") != 0)
14335             *isApplic1 = NO;
14336         if (strcmp(modelParams[part2].clockPr, "Birthdeath") != 0 && strcmp(modelParams[part2].clockPr, "Fossilization") != 0)
14337             *isApplic2 = NO;
14338 
14339         /* Now, check that the prior on the speciation rates are the same. */
14340         if (!strcmp(modelParams[part1].speciationPr,"Uniform") && !strcmp(modelParams[part2].speciationPr,"Uniform"))
14341             {
14342             if (AreDoublesEqual (modelParams[part1].speciationUni[0], modelParams[part2].speciationUni[0], (MrBFlt) 0.00001) == NO)
14343                 isSame = NO;
14344             if (AreDoublesEqual (modelParams[part1].speciationUni[1], modelParams[part2].speciationUni[1], (MrBFlt) 0.00001) == NO)
14345                 isSame = NO;
14346             }
14347         else if (!strcmp(modelParams[part1].speciationPr,"Exponential") && !strcmp(modelParams[part2].speciationPr,"Exponential"))
14348             {
14349             if (AreDoublesEqual (modelParams[part1].speciationExp, modelParams[part2].speciationExp, (MrBFlt) 0.00001) == NO)
14350                 isSame = NO;
14351             }
14352         else if (!strcmp(modelParams[part1].speciationPr,"Fixed") && !strcmp(modelParams[part2].speciationPr,"Fixed"))
14353             {
14354             if (AreDoublesEqual (modelParams[part1].speciationFix, modelParams[part2].speciationFix, (MrBFlt) 0.00001) == NO)
14355                 isSame = NO;
14356             }
14357         else
14358             isSame = NO;
14359 
14360         /* Check to see if the speciation rates are inapplicable for either partition. */
14361         if ((*isApplic1) == NO || (*isApplic2) == NO)
14362             isSame = NO;
14363         }
14364     else if (whichParam == P_EXTRATE)
14365         {
14366         /* Check the extinction rates for partitions 1 and 2. */
14367 
14368         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14369            silly and doesn't take this information into account) and a extinction rate cannot be estimated. */
14370         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14371             *isApplic1 = NO;
14372         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14373             *isApplic2 = NO;
14374 
14375         /* Check that the branch length prior is a clock:birthdeath or clock:fossilization for both partitions. */
14376         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14377             *isApplic1 = NO;
14378         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14379             *isApplic2 = NO;
14380         if (strcmp(modelParams[part1].clockPr, "Birthdeath")!= 0 && strcmp(modelParams[part1].clockPr, "Fossilization") != 0)
14381             *isApplic1 = NO;
14382         if (strcmp(modelParams[part2].clockPr, "Birthdeath")!= 0 && strcmp(modelParams[part2].clockPr, "Fossilization") != 0)
14383             *isApplic2 = NO;
14384 
14385         /* Now, check that the prior on the extinction rates are the same. */
14386         if (!strcmp(modelParams[part1].extinctionPr,"Beta") && !strcmp(modelParams[part2].extinctionPr,"Beta"))
14387             {
14388             if (AreDoublesEqual (modelParams[part1].extinctionBeta[0], modelParams[part2].extinctionBeta[0], (MrBFlt) 0.00001) == NO)
14389                 isSame = NO;
14390             if (AreDoublesEqual (modelParams[part1].extinctionBeta[1], modelParams[part2].extinctionBeta[1], (MrBFlt) 0.00001) == NO)
14391                 isSame = NO;
14392             }
14393         else if (!strcmp(modelParams[part1].extinctionPr,"Fixed") && !strcmp(modelParams[part2].extinctionPr,"Fixed"))
14394             {
14395             if (AreDoublesEqual (modelParams[part1].extinctionFix, modelParams[part2].extinctionFix, (MrBFlt) 0.00001) == NO)
14396                 isSame = NO;
14397             }
14398         else
14399             isSame = NO;
14400 
14401         /* Check to see if the extinction rates are inapplicable for either partition. */
14402         if ((*isApplic1) == NO || (*isApplic2) == NO)
14403             isSame = NO;
14404         }
14405     else if (whichParam == P_FOSLRATE)
14406         {
14407         /* Check the fossilization rates for partitions 1 and 2. */
14408 
14409         /* Check if the model is parsimony for either partition. */
14410         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14411             *isApplic1 = NO;
14412         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14413             *isApplic2 = NO;
14414 
14415         /* Check that the branch length prior is a clock:fossilization for both partitions. */
14416         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14417             *isApplic1 = NO;
14418         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14419             *isApplic2 = NO;
14420         if (strcmp(modelParams[part1].clockPr, "Fossilization") != 0)
14421             *isApplic1 = NO;
14422         if (strcmp(modelParams[part2].clockPr, "Fossilization") != 0)
14423             *isApplic2 = NO;
14424 
14425         /* Now, check that the prior on the fossilization rates are the same. */
14426         if (!strcmp(modelParams[part1].fossilizationPr,"Beta") && !strcmp(modelParams[part2].fossilizationPr,"Beta"))
14427             {
14428             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[0], modelParams[part2].fossilizationBeta[0], (MrBFlt) 0.00001) == NO)
14429                 isSame = NO;
14430             if (AreDoublesEqual (modelParams[part1].fossilizationBeta[1], modelParams[part2].fossilizationBeta[1], (MrBFlt) 0.00001) == NO)
14431                 isSame = NO;
14432             }
14433         else if (!strcmp(modelParams[part1].fossilizationPr,"Fixed") && !strcmp(modelParams[part2].fossilizationPr,"Fixed"))
14434             {
14435             if (AreDoublesEqual (modelParams[part1].fossilizationFix, modelParams[part2].fossilizationFix, (MrBFlt) 0.00001) == NO)
14436                 isSame = NO;
14437             }
14438         else
14439             isSame = NO;
14440 
14441         /* Check to see if the fossilization rates are inapplicable for either partition. */
14442         if ((*isApplic1) == NO || (*isApplic2) == NO)
14443             isSame = NO;
14444         }
14445     else if (whichParam == P_POPSIZE)
14446         {
14447         /* Check population size for partitions 1 and 2. */
14448 
14449         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14450            silly and doesn't take this information into account) and population size cannot be estimated. */
14451         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14452             *isApplic1 = NO;
14453         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14454             *isApplic2 = NO;
14455 
14456         /* Check that the branch length prior is a clock:coalescence or clock:speciestreecoalescence for both partitions. */
14457         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14458             *isApplic1 = NO;
14459         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14460             *isApplic2 = NO;
14461         if (strcmp(modelParams[part1].clockPr, "Coalescence") != 0 && strcmp(modelParams[part1].clockPr, "Speciestreecoalescence") != 0)
14462             *isApplic1 = NO;
14463         if (strcmp(modelParams[part2].clockPr, "Coalescence") != 0 && strcmp(modelParams[part2].clockPr, "Speciestreecoalescence") != 0)
14464             *isApplic2 = NO;
14465 
14466         /* Now, check that the prior on population size is the same. */
14467         if (!strcmp(modelParams[part1].popSizePr,"Uniform") && !strcmp(modelParams[part2].popSizePr,"Uniform"))
14468             {
14469             if (AreDoublesEqual (modelParams[part1].popSizeUni[0], modelParams[part2].popSizeUni[0], (MrBFlt) 0.00001) == NO)
14470                 isSame = NO;
14471             if (AreDoublesEqual (modelParams[part1].popSizeUni[1], modelParams[part2].popSizeUni[1], (MrBFlt) 0.00001) == NO)
14472                 isSame = NO;
14473             }
14474         else if (!strcmp(modelParams[part1].popSizePr,"Lognormal") && !strcmp(modelParams[part2].popSizePr,"Lognormal"))
14475             {
14476             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[0], modelParams[part2].popSizeLognormal[0], (MrBFlt) 0.00001) == NO)
14477                 isSame = NO;
14478             if (AreDoublesEqual (modelParams[part1].popSizeLognormal[1], modelParams[part2].popSizeLognormal[1], (MrBFlt) 0.00001) == NO)
14479                 isSame = NO;
14480             }
14481         else if (!strcmp(modelParams[part1].popSizePr,"Normal") && !strcmp(modelParams[part2].popSizePr,"Normal"))
14482             {
14483             if (AreDoublesEqual (modelParams[part1].popSizeNormal[0], modelParams[part2].popSizeNormal[0], (MrBFlt) 0.00001) == NO)
14484                 isSame = NO;
14485             if (AreDoublesEqual (modelParams[part1].popSizeNormal[1], modelParams[part2].popSizeNormal[1], (MrBFlt) 0.00001) == NO)
14486                 isSame = NO;
14487             }
14488         else if (!strcmp(modelParams[part1].popSizePr,"Gamma") && !strcmp(modelParams[part2].popSizePr,"Gamma"))
14489             {
14490             if (AreDoublesEqual (modelParams[part1].popSizeGamma[0], modelParams[part2].popSizeGamma[0], (MrBFlt) 0.00001) == NO)
14491                 isSame = NO;
14492             if (AreDoublesEqual (modelParams[part1].popSizeGamma[1], modelParams[part2].popSizeGamma[1], (MrBFlt) 0.00001) == NO)
14493                 isSame = NO;
14494             }
14495         else if (!strcmp(modelParams[part1].popSizePr,"Fixed") && !strcmp(modelParams[part2].popSizePr,"Fixed"))
14496             {
14497             if (AreDoublesEqual (modelParams[part1].popSizeFix, modelParams[part2].popSizeFix, (MrBFlt) 0.00001) == NO)
14498                 isSame = NO;
14499             }
14500         else
14501             isSame = NO;
14502 
14503         /* Check to see if population size is inapplicable for either partition. */
14504         if ((*isApplic1) == NO || (*isApplic2) == NO)
14505             isSame = NO;
14506         }
14507     else if (whichParam == P_GROWTH)
14508         {
14509         /* Check growth rate for partitions 1 and 2. */
14510 
14511         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14512            silly and doesn't take this information into account) and growth rate cannot be estimated. */
14513         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14514             *isApplic1 = NO;
14515         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14516             *isApplic2 = NO;
14517 
14518         /* Check that the branch length prior is a clock:coalescence for both partitions. */
14519         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14520             *isApplic1 = NO;
14521         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14522             *isApplic2 = NO;
14523         if (strcmp(modelParams[part1].clockPr, "Coalescence"))
14524             *isApplic1 = NO;
14525         if (strcmp(modelParams[part2].clockPr, "Coalescence"))
14526             *isApplic2 = NO;
14527 
14528         /* Now, check that the prior on growth rate is the same. */
14529         if (!strcmp(modelParams[part1].growthPr,"Uniform") && !strcmp(modelParams[part2].growthPr,"Uniform"))
14530             {
14531             if (AreDoublesEqual (modelParams[part1].growthUni[0], modelParams[part2].growthUni[0], (MrBFlt) 0.00001) == NO)
14532                 isSame = NO;
14533             if (AreDoublesEqual (modelParams[part1].growthUni[1], modelParams[part2].growthUni[1], (MrBFlt) 0.00001) == NO)
14534                 isSame = NO;
14535             }
14536         else if (!strcmp(modelParams[part1].growthPr,"Exponential") && !strcmp(modelParams[part2].growthPr,"Exponential"))
14537             {
14538             if (AreDoublesEqual (modelParams[part1].growthExp, modelParams[part2].growthExp, (MrBFlt) 0.00001) == NO)
14539                 isSame = NO;
14540             }
14541         else if (!strcmp(modelParams[part1].growthPr,"Fixed") && !strcmp(modelParams[part2].growthPr,"Fixed"))
14542             {
14543             if (AreDoublesEqual (modelParams[part1].growthFix, modelParams[part2].growthFix, (MrBFlt) 0.00001) == NO)
14544                 isSame = NO;
14545             }
14546         else
14547             isSame = NO;
14548 
14549         /* Check to see if growth rate is inapplicable for either partition. */
14550         if ((*isApplic1) == NO || (*isApplic2) == NO)
14551             isSame = NO;
14552         }
14553     else if (whichParam == P_AAMODEL)
14554         {
14555         /* Check the amino acid model settings for partitions 1 and 2. */
14556 
14557         /* Check if the model is parsimony for either partition */
14558         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14559             *isApplic1 = NO; /* part1 has a parsimony model and aamodel does not apply */
14560         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14561             *isApplic2 = NO; /* part2 has a parsimony model and aamodel does not apply */
14562 
14563         /* Check that the data are protein for both partitions 1 and 2 */
14564         if (isFirstProtein == NO)
14565             *isApplic1 = NO; /* part1 is not amino acid data so tratio does not apply */
14566         if (isSecondProtein == NO)
14567             *isApplic2 = NO; /* part2 is not amino acid data so tratio does not apply */
14568 
14569         /* If the model is fixed for a partition, then it is not a free parameter and
14570            we set it to isApplic = NO */
14571         if (!strcmp(modelParams[part1].aaModelPr,"Fixed"))
14572             *isApplic1 = NO;
14573         if (!strcmp(modelParams[part2].aaModelPr,"Fixed"))
14574             *isApplic2 = NO;
14575 
14576         /* We now need to check if the prior is the same for both. */
14577         if (!strcmp(modelParams[part1].aaModelPr,"Mixed") && !strcmp(modelParams[part2].aaModelPr,"Mixed"))
14578             {
14579             }
14580         else if (!strcmp(modelParams[part1].aaModelPr,"Fixed") && !strcmp(modelParams[part2].aaModelPr,"Fixed"))
14581             {
14582             if (strcmp(modelParams[part1].aaModel,modelParams[part2].aaModel))
14583                 isSame = NO;
14584             }
14585         else
14586             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
14587 
14588         /* Check to see if amino acid model is inapplicable for either partition. */
14589         if ((*isApplic1) == NO || (*isApplic2) == NO)
14590             isSame = NO; /* if tratio is inapplicable for either partition, then the parameter cannot be the same */
14591         }
14592     else if (whichParam == P_BRCORR)
14593         {
14594         /* Check the correlation parameter for brownian motion 1 and 2. */
14595 
14596         /* Check that the data are either CONTINUOUS for partitions 1 and 2 */
14597         if (modelParams[part1].dataType != CONTINUOUS)
14598             *isApplic1 = NO; /* the correlation parameter does not make sense for part1 */
14599         if (modelParams[part2].dataType != CONTINUOUS)
14600             *isApplic2 = NO; /* the correlation parameter does not make sense for part2 */
14601 
14602         /* Now, check that the data are the same. */
14603         if (modelParams[part1].dataType != modelParams[part2].dataType)
14604             isSame = NO; /* data are not both continuous */
14605 
14606         /* Check the priors for both partitions. */
14607         if (!strcmp(modelParams[part1].brownCorPr,"Uniform") && !strcmp(modelParams[part2].brownCorPr,"Uniform"))
14608             {
14609             if (AreDoublesEqual (modelParams[part1].brownCorrUni[0], modelParams[part2].brownCorrUni[0], (MrBFlt) 0.00001) == NO)
14610                 isSame = NO;
14611             if (AreDoublesEqual (modelParams[part1].brownCorrUni[1], modelParams[part2].brownCorrUni[1], (MrBFlt) 0.00001) == NO)
14612                 isSame = NO;
14613             }
14614         else if (!strcmp(modelParams[part1].brownCorPr,"Fixed") && !strcmp(modelParams[part2].brownCorPr,"Fixed"))
14615             {
14616             if (AreDoublesEqual (modelParams[part1].brownCorrFix, modelParams[part2].brownCorrFix, (MrBFlt) 0.00001) == NO)
14617                 isSame = NO;
14618             }
14619         else
14620             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
14621 
14622         /* Check to see if the correlation parameters are inapplicable for either partition. */
14623         if ((*isApplic1) == NO || (*isApplic2) == NO)
14624             isSame = NO; /* if the correlation parameters are inapplicable for either partition, then the parameter cannot be the same */
14625         }
14626     else if (whichParam == P_BRSIGMA)
14627         {
14628         /* Check the sigma parameter for brownian motion 1 and 2. */
14629 
14630         /* Check that the data are either CONTINUOUS for partitions 1 and 2 */
14631         if (modelParams[part1].dataType != CONTINUOUS)
14632             *isApplic1 = NO; /* the sigma parameter does not make sense for part1 */
14633         if (modelParams[part2].dataType != CONTINUOUS)
14634             *isApplic2 = NO; /* the sigma parameter does not make sense for part2 */
14635 
14636         /* Now, check that the data are the same. */
14637         if (modelParams[part1].dataType != modelParams[part2].dataType)
14638             isSame = NO; /* data are not both continuous */
14639 
14640         /* Check the priors for both partitions. */
14641         if (!strcmp(modelParams[part1].brownScalesPr,"Uniform") && !strcmp(modelParams[part2].brownScalesPr,"Uniform"))
14642             {
14643             if (AreDoublesEqual (modelParams[part1].brownScalesUni[0], modelParams[part2].brownScalesUni[0], (MrBFlt) 0.00001) == NO)
14644                 isSame = NO;
14645             if (AreDoublesEqual (modelParams[part1].brownScalesUni[1], modelParams[part2].brownScalesUni[1], (MrBFlt) 0.00001) == NO)
14646                 isSame = NO;
14647             }
14648         else if (!strcmp(modelParams[part1].brownScalesPr,"Fixed") && !strcmp(modelParams[part2].brownScalesPr,"Fixed"))
14649             {
14650             if (AreDoublesEqual (modelParams[part1].brownScalesFix, modelParams[part2].brownScalesFix, (MrBFlt) 0.00001) == NO)
14651                 isSame = NO;
14652             }
14653         else if (!strcmp(modelParams[part1].brownScalesPr,"Gamma") && !strcmp(modelParams[part2].brownScalesPr,"Gamma"))
14654             {
14655             if (AreDoublesEqual (modelParams[part1].brownScalesGamma[0], modelParams[part2].brownScalesGamma[0], (MrBFlt) 0.00001) == NO)
14656                 isSame = NO;
14657             if (AreDoublesEqual (modelParams[part1].brownScalesGamma[1], modelParams[part2].brownScalesGamma[1], (MrBFlt) 0.00001) == NO)
14658                 isSame = NO;
14659             }
14660         else if (!strcmp(modelParams[part1].brownScalesPr,"Gammamean") && !strcmp(modelParams[part2].brownScalesPr,"Gammamean"))
14661             {
14662             if (AreDoublesEqual (modelParams[part1].brownScalesGammaMean, modelParams[part2].brownScalesGammaMean, (MrBFlt) 0.00001) == NO)
14663                 isSame = NO;
14664             }
14665         else
14666             isSame = NO; /* the priors are not the same, so we cannot set the parameter to be equal for both partitions */
14667 
14668         /* Check to see if the sigma parameters are inapplicable for either partition. */
14669         if ((*isApplic1) == NO || (*isApplic2) == NO)
14670             isSame = NO; /* if the sigma parameters are inapplicable for either partition, then the parameter cannot be the same */
14671         }
14672     else if (whichParam == P_CPPRATE)
14673         {
14674         /* Check cpp rate for partitions 1 and 2. */
14675 
14676         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14677         silly and doesn't take this information into account) and cpp rate cannot be estimated. */
14678         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14679             *isApplic1 = NO;
14680         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14681             *isApplic2 = NO;
14682 
14683         /* Check that the branch length prior is clock for both partitions. */
14684         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14685             *isApplic1 = NO;
14686         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14687             *isApplic2 = NO;
14688 
14689         /* Check that the clock rate prior is cpp for both partitions */
14690         if (strcmp(modelParams[part1].clockVarPr, "Cpp"))
14691             *isApplic1 = NO;
14692         if (strcmp(modelParams[part2].clockVarPr, "Cpp"))
14693             *isApplic2 = NO;
14694 
14695         /* Now, check that the prior on cpp rate is the same. */
14696         if (!strcmp(modelParams[part1].cppRatePr,"Exponential") && !strcmp(modelParams[part2].cppRatePr,"Exponential"))
14697             {
14698             if (AreDoublesEqual (modelParams[part1].cppRateExp, modelParams[part2].cppRateExp, (MrBFlt) 0.00001) == NO)
14699                 isSame = NO;
14700             }
14701         else if (!strcmp(modelParams[part1].cppRatePr,"Fixed") && !strcmp(modelParams[part2].cppRatePr,"Fixed"))
14702             {
14703             if (AreDoublesEqual (modelParams[part1].cppRateFix, modelParams[part2].cppRateFix, (MrBFlt) 0.00001) == NO)
14704                 isSame = NO;
14705             }
14706         else
14707             isSame = NO;
14708 
14709         /* Check to see if cpp rate is inapplicable for either partition. */
14710         if ((*isApplic1) == NO || (*isApplic2) == NO)
14711             isSame = NO;
14712         }
14713     else if (whichParam == P_CPPMULTDEV)
14714         {
14715         /* Check cpp multiplier deviation prior for partitions 1 and 2. */
14716 
14717         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14718         silly and doesn't take this information into account) and this parameter is inapplicable. */
14719         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14720             *isApplic1 = NO;
14721         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14722             *isApplic2 = NO;
14723 
14724         /* Check that the branch length prior is clock for both partitions. */
14725         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14726             *isApplic1 = NO;
14727         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14728             *isApplic2 = NO;
14729 
14730         /* Check that the clock rate prior is cpp for both partitions */
14731         if (strcmp(modelParams[part1].clockVarPr, "Cpp"))
14732             *isApplic1 = NO;
14733         if (strcmp(modelParams[part2].clockVarPr, "Cpp"))
14734             *isApplic2 = NO;
14735 
14736         /* Now, check that the prior on sigma is the same. */
14737         if (!strcmp(modelParams[part1].cppMultDevPr,"Fixed") && !strcmp(modelParams[part2].cppMultDevPr,"Fixed"))
14738             {
14739             if (AreDoublesEqual (modelParams[part1].cppMultDevFix, modelParams[part2].cppMultDevFix, (MrBFlt) 0.00001) == NO)
14740                 isSame = NO;
14741             }
14742         else
14743             isSame = NO;
14744 
14745         /* Check to see if cpp multiplier sigma is inapplicable for either partition. */
14746         if ((*isApplic1) == NO || (*isApplic2) == NO)
14747             isSame = NO;
14748         }
14749     else if (whichParam == P_CPPEVENTS)
14750         {
14751         /* Check cpp events for partitions 1 and 2. */
14752 
14753         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14754         silly and doesn't take this information into account) and cpp events are inapplicable. */
14755         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14756             *isApplic1 = NO;
14757         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14758             *isApplic2 = NO;
14759 
14760         /* Check that the branch length prior is clock for both partitions. */
14761         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14762             *isApplic1 = NO;
14763         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14764             *isApplic2 = NO;
14765 
14766         /* Check that the clock rate prior is cpp for both partitions */
14767         if (strcmp(modelParams[part1].clockVarPr, "Cpp"))
14768             *isApplic1 = NO;
14769         if (strcmp(modelParams[part2].clockVarPr, "Cpp"))
14770             *isApplic2 = NO;
14771 
14772         /* Now, check that the cpp parameter is the same */
14773         if (IsModelSame (P_CPPRATE, part1, part2, &temp1, &temp2) == NO)
14774             isSame = NO;
14775         if (linkTable[P_CPPRATE][part1] != linkTable[P_CPPRATE][part2])
14776             isSame = NO;
14777 
14778         /* ... and that the psigamma parameter is the same */
14779         if (IsModelSame (P_CPPMULTDEV, part1, part2, &temp1, &temp2) == NO)
14780             isSame = NO;
14781         if (linkTable[P_CPPMULTDEV][part1] != linkTable[P_CPPRATE][part2])
14782             isSame = NO;
14783 
14784         /* Not same if branch lengths are not the same */
14785         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
14786             isSame = NO;
14787         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
14788             isSame = NO;
14789 
14790         /* Set isSame to NO if cpp events are inapplicable for either partition. */
14791         if ((*isApplic1) == NO || (*isApplic2) == NO)
14792             isSame = NO;
14793         }
14794     else if (whichParam == P_TK02VAR)
14795         {
14796         /* Check prior for variance of rate autocorrelation for partitions 1 and 2. */
14797 
14798         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14799         silly and doesn't take this information into account) and ratevar is inapplicable. */
14800         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14801             *isApplic1 = NO;
14802         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14803             *isApplic2 = NO;
14804 
14805         /* Check that the branch length prior is clock for both partitions. */
14806         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14807             *isApplic1 = NO;
14808         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14809             *isApplic2 = NO;
14810 
14811         /* Check that the clock rate prior is tk02 for both partitions */
14812         if (strcmp(modelParams[part1].clockVarPr, "TK02"))
14813             *isApplic1 = NO;
14814         if (strcmp(modelParams[part2].clockVarPr, "TK02"))
14815             *isApplic2 = NO;
14816 
14817         /* Now, check that the prior on tk02 variance is the same. */
14818         if (!strcmp(modelParams[part1].tk02varPr,"Uniform") && !strcmp(modelParams[part2].tk02varPr,"Uniform"))
14819             {
14820             if (AreDoublesEqual (modelParams[part1].tk02varUni[0], modelParams[part2].tk02varUni[0], (MrBFlt) 0.00001) == NO)
14821                 isSame = NO;
14822             if (AreDoublesEqual (modelParams[part1].tk02varUni[1], modelParams[part2].tk02varUni[1], (MrBFlt) 0.00001) == NO)
14823                 isSame = NO;
14824             }
14825         else if (!strcmp(modelParams[part1].tk02varPr,"Exponential") && !strcmp(modelParams[part2].tk02varPr,"Exponential"))
14826             {
14827             if (AreDoublesEqual (modelParams[part1].tk02varExp, modelParams[part2].tk02varExp, (MrBFlt) 0.00001) == NO)
14828                 isSame = NO;
14829             }
14830         else if (!strcmp(modelParams[part1].tk02varPr,"Fixed") && !strcmp(modelParams[part2].tk02varPr,"Fixed"))
14831             {
14832             if (AreDoublesEqual (modelParams[part1].tk02varFix, modelParams[part2].tk02varFix, (MrBFlt) 0.00001) == NO)
14833                 isSame = NO;
14834             }
14835         else
14836             isSame = NO;
14837 
14838         /* Check to see if tk02 variance is inapplicable for either partition. */
14839         if ((*isApplic1) == NO || (*isApplic2) == NO)
14840             isSame = NO;
14841         }
14842     else if (whichParam == P_TK02BRANCHRATES)
14843         {
14844         /* Check TK02 relaxed clock branch rates for partitions 1 and 2. */
14845 
14846         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14847         silly and doesn't take this information into account) and tk02 relaxed clock branch rates are inapplicable. */
14848         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14849             *isApplic1 = NO;
14850         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14851             *isApplic2 = NO;
14852 
14853         /* Check that the branch length prior is clock for both partitions. */
14854         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14855             *isApplic1 = NO;
14856         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14857             *isApplic2 = NO;
14858 
14859         /* Check that the clock rate prior is tk02 for both partitions */
14860         if (strcmp(modelParams[part1].clockVarPr, "TK02"))
14861             *isApplic1 = NO;
14862         if (strcmp(modelParams[part2].clockVarPr, "TK02"))
14863             *isApplic2 = NO;
14864 
14865         /* Now, check that the tk02 variance parameter is the same */
14866         if (IsModelSame (P_TK02VAR, part1, part2, &temp1, &temp2) == NO)
14867             isSame = NO;
14868         if (linkTable[P_TK02VAR][part1] != linkTable[P_TK02VAR][part2])
14869             isSame = NO;
14870 
14871         /* Not same if branch lengths are not the same */
14872         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
14873             isSame = NO;
14874         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
14875             isSame = NO;
14876 
14877         /* Set isSame to NO if tk02 branch rates are inapplicable for either partition. */
14878         if ((*isApplic1) == NO || (*isApplic2) == NO)
14879             isSame = NO;
14880         }
14881     else if (whichParam == P_IGRVAR)
14882         {
14883         /* Check prior for igr shape for partitions 1 and 2. */
14884 
14885         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14886         silly and doesn't take this information into account) and igr shape is inapplicable. */
14887         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14888             *isApplic1 = NO;
14889         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14890             *isApplic2 = NO;
14891 
14892         /* Check that the branch length prior is clock for both partitions. */
14893         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14894             *isApplic1 = NO;
14895         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14896             *isApplic2 = NO;
14897 
14898         /* Check that the clock rate prior is igr for both partitions */
14899         if (strcmp(modelParams[part1].clockVarPr, "Igr"))
14900             *isApplic1 = NO;
14901         if (strcmp(modelParams[part2].clockVarPr, "Igr"))
14902             *isApplic2 = NO;
14903 
14904         /* Now, check that the prior on igr shape is the same. */
14905         if (!strcmp(modelParams[part1].igrvarPr,"Uniform") && !strcmp(modelParams[part2].igrvarPr,"Uniform"))
14906             {
14907             if (AreDoublesEqual (modelParams[part1].igrvarUni[0], modelParams[part2].igrvarUni[0], (MrBFlt) 0.00001) == NO)
14908                 isSame = NO;
14909             if (AreDoublesEqual (modelParams[part1].igrvarUni[1], modelParams[part2].igrvarUni[1], (MrBFlt) 0.00001) == NO)
14910                 isSame = NO;
14911             }
14912         else if (!strcmp(modelParams[part1].igrvarPr,"Exponential") && !strcmp(modelParams[part2].igrvarPr,"Exponential"))
14913             {
14914             if (AreDoublesEqual (modelParams[part1].igrvarExp, modelParams[part2].igrvarExp, (MrBFlt) 0.00001) == NO)
14915                 isSame = NO;
14916             }
14917         else if (!strcmp(modelParams[part1].igrvarPr,"Fixed") && !strcmp(modelParams[part2].igrvarPr,"Fixed"))
14918             {
14919             if (AreDoublesEqual (modelParams[part1].igrvarFix, modelParams[part2].igrvarFix, (MrBFlt) 0.00001) == NO)
14920                 isSame = NO;
14921             }
14922         else
14923             isSame = NO;
14924 
14925         /* Check to see if igr variance is inapplicable for either partition. */
14926         if ((*isApplic1) == NO || (*isApplic2) == NO)
14927             isSame = NO;
14928         }
14929     else if (whichParam == P_IGRBRANCHRATES)
14930         {
14931         /* Check IGR relaxed clock branch rates for partitions 1 and 2. */
14932 
14933         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
14934         silly and doesn't take this information into account) and igr relaxed clock branch rates are inapplicable. */
14935         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14936             *isApplic1 = NO;
14937         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14938             *isApplic2 = NO;
14939 
14940         /* Check that the branch length prior is clock for both partitions. */
14941         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14942             *isApplic1 = NO;
14943         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14944             *isApplic2 = NO;
14945 
14946         /* Check that the clock rate prior is igr for both partitions */
14947         if (strcmp(modelParams[part1].clockVarPr, "Igr"))
14948             *isApplic1 = NO;
14949         if (strcmp(modelParams[part2].clockVarPr, "Igr"))
14950             *isApplic2 = NO;
14951 
14952         /* Now, check that the igr shape parameter is the same */
14953         if (IsModelSame (P_IGRVAR, part1, part2, &temp1, &temp2) == NO)
14954             isSame = NO;
14955         if (linkTable[P_IGRVAR][part1] != linkTable[P_IGRVAR][part2])
14956             isSame = NO;
14957 
14958         /* Not same if branch lengths are not the same */
14959         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
14960             isSame = NO;
14961         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
14962             isSame = NO;
14963 
14964         /* Set isSame to NO if igr branch rates are inapplicable for either partition. */
14965         if ((*isApplic1) == NO || (*isApplic2) == NO)
14966             isSame = NO;
14967         }
14968     else if (whichParam == P_MIXEDVAR)
14969         {
14970         /* Check prior for mixed var for partitions 1 and 2. */
14971 
14972         /* Check if the model is parsimony for either partition. If so, then the branch lengths cannot apply (as parsimony is very
14973          silly and doesn't take this information into account) and variance is inapplicable. */
14974         if (!strcmp(modelParams[part1].parsModel, "Yes"))
14975             *isApplic1 = NO;
14976         if (!strcmp(modelParams[part2].parsModel, "Yes"))
14977             *isApplic2 = NO;
14978 
14979         /* Check that the branch length prior is clock for both partitions. */
14980         if (strcmp(modelParams[part1].brlensPr, "Clock"))
14981             *isApplic1 = NO;
14982         if (strcmp(modelParams[part2].brlensPr, "Clock"))
14983             *isApplic2 = NO;
14984 
14985         /* Check that the clock rate prior is mixed for both partitions */
14986         if (strcmp(modelParams[part1].clockVarPr, "Mixed"))
14987             *isApplic1 = NO;
14988         if (strcmp(modelParams[part2].clockVarPr, "Mixed"))
14989             *isApplic2 = NO;
14990 
14991         /* Now, check that the prior on var mixed is the same. */
14992         if (!strcmp(modelParams[part1].mixedvarPr,"Uniform") && !strcmp(modelParams[part2].mixedvarPr,"Uniform"))
14993             {
14994             if (AreDoublesEqual (modelParams[part1].mixedvarUni[0], modelParams[part2].mixedvarUni[0], (MrBFlt) 0.00001) == NO)
14995                 isSame = NO;
14996             if (AreDoublesEqual (modelParams[part1].mixedvarUni[1], modelParams[part2].mixedvarUni[1], (MrBFlt) 0.00001) == NO)
14997                 isSame = NO;
14998             }
14999         else if (!strcmp(modelParams[part1].mixedvarPr,"Exponential") && !strcmp(modelParams[part2].mixedvarPr,"Exponential"))
15000             {
15001             if (AreDoublesEqual (modelParams[part1].mixedvarExp, modelParams[part2].mixedvarExp, (MrBFlt) 0.00001) == NO)
15002                 isSame = NO;
15003             }
15004         else if (!strcmp(modelParams[part1].mixedvarPr,"Fixed") && !strcmp(modelParams[part2].mixedvarPr,"Fixed"))
15005             {
15006             if (AreDoublesEqual (modelParams[part1].mixedvarFix, modelParams[part2].mixedvarFix, (MrBFlt) 0.00001) == NO)
15007                 isSame = NO;
15008             }
15009         else
15010             isSame = NO;
15011 
15012         /* Check to see if variance is inapplicable for either partition. */
15013         if ((*isApplic1) == NO || (*isApplic2) == NO)
15014             isSame = NO;
15015         }
15016     else if (whichParam == P_MIXEDBRCHRATES)
15017         {
15018         /* Check mixed relaxed clock branch rates for partitions 1 and 2. */
15019 
15020         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
15021          silly and doesn't take this information into account) and relaxed clock branch rates are inapplicable. */
15022         if (!strcmp(modelParams[part1].parsModel, "Yes"))
15023             *isApplic1 = NO;
15024         if (!strcmp(modelParams[part2].parsModel, "Yes"))
15025             *isApplic2 = NO;
15026 
15027         /* Check that the branch length prior is clock for both partitions. */
15028         if (strcmp(modelParams[part1].brlensPr, "Clock"))
15029             *isApplic1 = NO;
15030         if (strcmp(modelParams[part2].brlensPr, "Clock"))
15031             *isApplic2 = NO;
15032 
15033         /* Check that the clock rate prior is mixed for both partitions */
15034         if (strcmp(modelParams[part1].clockVarPr, "Mixed"))
15035             *isApplic1 = NO;
15036         if (strcmp(modelParams[part2].clockVarPr, "Mixed"))
15037             *isApplic2 = NO;
15038 
15039         /* Now, check that the var parameter is the same */
15040         if (IsModelSame (P_MIXEDVAR, part1, part2, &temp1, &temp2) == NO)
15041             isSame = NO;
15042         if (linkTable[P_MIXEDVAR][part1] != linkTable[P_MIXEDVAR][part2])
15043             isSame = NO;
15044 
15045         /* Not same if branch lengths are not the same */
15046         if (IsModelSame(P_BRLENS, part1, part2, &temp1, &temp2) == NO)
15047             isSame = NO;
15048         if (linkTable[P_BRLENS][part1] != linkTable[P_BRLENS][part2])
15049             isSame = NO;
15050 
15051         /* Set isSame to NO if mixed branch rates are inapplicable for either partition. */
15052         if ((*isApplic1) == NO || (*isApplic2) == NO)
15053             isSame = NO;
15054         }
15055     else if (whichParam == P_CLOCKRATE)
15056         {
15057         /* Check base substitution rates of clock tree for partitions 1 and 2. */
15058 
15059         /* Check if the model is parsimony for either partition. If so, then branch lengths do not apply (as parsimony is very
15060         silly and doesn't take this information into account) and clock branch rates are inapplicable. */
15061         if (!strcmp(modelParams[part1].parsModel, "Yes"))
15062             *isApplic1 = NO;
15063         if (!strcmp(modelParams[part2].parsModel, "Yes"))
15064             *isApplic2 = NO;
15065 
15066         /* Check that the branch length prior is clock for both partitions. */
15067         if (strcmp(modelParams[part1].brlensPr, "Clock"))
15068             *isApplic1 = NO;
15069         if (strcmp(modelParams[part2].brlensPr, "Clock"))
15070             *isApplic2 = NO;
15071 
15072         /* Set isSame to NO if base substitution rate parameter is inapplicable for either partition. */
15073         if ((*isApplic1) == NO || (*isApplic2) == NO)
15074             isSame = NO;
15075         }
15076     else if (whichParam == P_SPECIESTREE)
15077         {
15078         /* Species tree; check that it is used in both partitions */
15079         if (strcmp(modelParams[part1].topologyPr, "Speciestree") != 0)
15080             *isApplic1 = NO;
15081         if (strcmp(modelParams[part2].topologyPr, "Speciestree") != 0)
15082             *isApplic2 = NO;
15083 
15084         /* Not same if inapplicable to either partition */
15085         if ((*isApplic1) == NO || (*isApplic2) == NO)
15086             isSame = NO;
15087         }
15088     else if (whichParam == P_GENETREERATE)
15089         {
15090         /* Gene tree rate; check that it is used in both partitions */
15091         if (strcmp(modelParams[part1].topologyPr, "Speciestree") != 0)
15092             *isApplic1 = NO;
15093         if (strcmp(modelParams[part2].topologyPr, "Speciestree") != 0)
15094             *isApplic2 = NO;
15095 
15096         /* Not same if inapplicable to either partition */
15097         if ((*isApplic1) == NO || (*isApplic2) == NO)
15098             isSame = NO;
15099         }
15100     else
15101         {
15102         MrBayesPrint ("%s   Could not find parameter in IsModelSame\n", spacer);
15103         return (NO);
15104         }
15105 
15106     return (isSame);
15107 }
15108 
15109 
LargestMovableSubtree(Param * treeParam)15110 int LargestMovableSubtree(Param *treeParam)
15111 {
15112     int         i, j, k, a, nLongsNeeded, numPartitions, largestSubtree;
15113     BitsLong    **constraintPartition, *subtreePartition, *testPartition, *mask;
15114     ModelParams *mp;
15115     int         foundAllSpeciesPartition;
15116 
15117     mp = &modelParams[treeParam->relParts[0]];
15118 
15119     if (treeParam->paramType == P_SPECIESTREE)
15120         return numLocalTaxa;    /* no constraints allowed in species tree; set constraints in gene trees instead */
15121 
15122     /* This is difficult because we cannot rely on the tree being initialized.
15123        We need to retrieve the bitfields ourselves and figure out what they mean. */
15124     nLongsNeeded = ((numLocalTaxa - 1) / nBitsInALong) + 1;
15125     subtreePartition = (BitsLong *) SafeCalloc(3*nLongsNeeded, sizeof(BitsLong));
15126     constraintPartition = (BitsLong **) SafeCalloc (numDefinedConstraints+1, sizeof(BitsLong *));
15127     constraintPartition[0] = (BitsLong *) SafeCalloc ((numDefinedConstraints+1)*nLongsNeeded, sizeof(BitsLong));
15128     for (i=1; i<numDefinedConstraints+1; i++)
15129         constraintPartition[i] = constraintPartition[i-1] + nLongsNeeded;
15130     testPartition = subtreePartition + nLongsNeeded;
15131     mask = testPartition + nLongsNeeded;
15132 
15133     /* set mask (needed to take care of unused bits when flipping partitions) */
15134     for (i=0; i<numLocalTaxa; i++)
15135         SetBit (i, mask);
15136 
15137     /* retrieve partitions */
15138     numPartitions = 0;
15139     foundAllSpeciesPartition = NO;
15140     for (a=0; a<numDefinedConstraints; a++)
15141         {
15142         if (mp->activeConstraints[a] == NO || definedConstraintsType[a] != HARD)
15143             continue;
15144 
15145         /* set bits in partition under consideration */
15146         ClearBits(constraintPartition[numPartitions], nLongsNeeded);
15147         for (i=j=0; i<numTaxa; i++)
15148             {
15149             if (taxaInfo[i].isDeleted == YES)
15150                 continue;
15151             if (IsBitSet(i, definedConstraint[a]) == YES)
15152                 SetBit(j, constraintPartition[numPartitions]);
15153             j++;
15154             }
15155 
15156         /* make sure outgroup is outside constrained partition (marked 0) */
15157         if (strcmp(mp->brlensPr,"Clock") != 0 && IsBitSet(localOutGroup, constraintPartition[numPartitions]) == YES)
15158             FlipBits(constraintPartition[numPartitions], nLongsNeeded, mask);
15159 
15160         /* skip partition if uninformative */
15161         k = NumBits(constraintPartition[numPartitions], nLongsNeeded);
15162         if (k == 0 || k == 1)
15163             continue;
15164 
15165         /* record if we hit an all-species partition */
15166         if (k == numLocalTaxa)
15167             foundAllSpeciesPartition = YES;
15168 
15169         numPartitions++;
15170         }
15171 
15172     /* Add all-species partition if not already present */
15173     if (foundAllSpeciesPartition == NO)
15174     {
15175         ClearBits(constraintPartition[numPartitions], nLongsNeeded);
15176         for (i=j=0; i<numTaxa; i++)
15177         {
15178             if (taxaInfo[i].isDeleted == YES)
15179                 continue;
15180             SetBit(j, constraintPartition[numPartitions]);
15181             j++;
15182         }
15183         numPartitions++;
15184     }
15185 
15186     /* Now we have all constraints. Calculate the movable subtree for each */
15187     largestSubtree = 0;
15188     for (i=0; i<numPartitions; i++)
15189         {
15190         CopyBits (subtreePartition, constraintPartition[i], nLongsNeeded);
15191         k = 0;
15192         for (j=0; j<numPartitions; j++)
15193             {
15194             if (j==i)
15195                 continue;
15196             if (IsPartNested(constraintPartition[j], constraintPartition[i], nLongsNeeded))
15197                 {
15198                 k++;    /* add one for clade we are removing from subtreePartition */
15199                 CopyBits (testPartition, constraintPartition[j], nLongsNeeded);
15200                 FlipBits (testPartition, nLongsNeeded, mask);
15201                 for (k=0; k<nLongsNeeded; k++)
15202                     subtreePartition[k] = subtreePartition[k] & testPartition[k];
15203                 }
15204             }
15205         k += NumBits (subtreePartition, nLongsNeeded);  /* add remaming free tips in subtreePartition */
15206         /* add calculation root if an unrooted tree and we are dealing with the root partition */
15207         if (strcmp(mp->brlensPr,"Clock") != 0 && NumBits (constraintPartition[i], nLongsNeeded) == numLocalTaxa - 1)
15208             k++;
15209         if (k > largestSubtree)
15210             largestSubtree = k;
15211         }
15212 
15213     free(subtreePartition);
15214     free(constraintPartition[0]);
15215     free(constraintPartition);
15216 
15217     return largestSubtree;
15218 }
15219 
15220 
Link(void)15221 int Link (void)
15222 {
15223     int         i, j;
15224 
15225     for (j=0; j<NUM_LINKED; j++)
15226         {
15227         MrBayesPrint ("%4d -- ", j+1);
15228         for (i=0; i<numCurrentDivisions; i++)
15229             MrBayesPrint (" %2d", tempLinkUnlink[j][i]);
15230         MrBayesPrint ("\n");
15231         }
15232 
15233     return (NO_ERROR);
15234 }
15235 
15236 
NumActiveParts(void)15237 int NumActiveParts (void)
15238 {
15239     int     i, nApplied;
15240 
15241     nApplied = 0;
15242     for (i=0; i<numCurrentDivisions; i++)
15243         if (activeParts[i] == YES)
15244             nApplied++;
15245 
15246     return (nApplied);
15247 }
15248 
15249 
NumInformativeHardConstraints(ModelParams * mp)15250 int NumInformativeHardConstraints (ModelParams *mp)
15251 {
15252     int             i, j, k, a, numInformativeHardConstraints, nLongsNeeded;
15253     BitsLong        *constraintPartition, *mask;
15254 
15255     numInformativeHardConstraints = 0;
15256 
15257     nLongsNeeded = ((numLocalTaxa - 1) / nBitsInALong) + 1;
15258     constraintPartition = (BitsLong *) SafeCalloc (2*nLongsNeeded, sizeof(BitsLong));
15259     if (!constraintPartition)
15260         {
15261             MrBayesPrint ("%s   Problems allocating constraintPartition", spacer);
15262             return ERROR;
15263         }
15264     mask = constraintPartition + nLongsNeeded;
15265 
15266     /* set mask (needed to take care of unused bits when flipping partitions) */
15267     for (i=0; i<numLocalTaxa; i++)
15268         SetBit (i, mask);
15269 
15270     for (a=0; a<numDefinedConstraints; a++)
15271         {
15272         if (mp->activeConstraints[a] == NO || definedConstraintsType[a] != HARD)
15273             continue;
15274 
15275         /* set bits in partition to add */
15276         ClearBits(constraintPartition, nLongsNeeded);
15277         for (i=j=0; i<numTaxa; i++)
15278             {
15279                 if (taxaInfo[i].isDeleted == YES)
15280                     continue;
15281                 if (IsBitSet(i, definedConstraint[a]) == YES)
15282                     SetBit(j, constraintPartition);
15283                 j++;
15284             }
15285 
15286         /* make sure outgroup is outside constrained partition (marked 0) */
15287         if (strcmp(mp->brlensPr,"Clock") != 0 && IsBitSet(localOutGroup, constraintPartition) == YES)
15288             FlipBits(constraintPartition, nLongsNeeded, mask);
15289 
15290         /* skip partition if uninformative */
15291         k = NumBits(constraintPartition, nLongsNeeded);
15292         if (k == 0 || k == 1)
15293             continue;
15294 
15295         numInformativeHardConstraints++;
15296         }
15297 
15298     return numInformativeHardConstraints;
15299 }
15300 
15301 
NumNonExcludedChar(void)15302 int NumNonExcludedChar (void)
15303 {
15304     int     i, n;
15305 
15306     /* count number of non-excluded characters */
15307     n = 0;
15308     for (i=0; i<numChar; i++)
15309         {
15310         if (charInfo[i].isExcluded == NO)
15311             {
15312             n++;
15313             }
15314         }
15315 
15316     return n;
15317 }
15318 
15319 
NumStates(int part)15320 int NumStates (int part)
15321 {
15322     if (modelParams[part].dataType == DNA || modelParams[part].dataType == RNA)
15323         {
15324         if (!strcmp(modelParams[part].nucModel, "4by4"))
15325             return (4);
15326         else if (!strcmp(modelParams[part].nucModel, "Doublet"))
15327             return (16);
15328         else if (!strcmp(modelParams[part].nucModel, "Protein"))
15329             return (20);
15330         else
15331             {
15332             if (!strcmp(modelParams[part].geneticCode, "Universal"))
15333                 return (61);
15334             else if (!strcmp(modelParams[part].geneticCode, "Vertmt"))
15335                 return (60);
15336             else if (!strcmp(modelParams[part].geneticCode, "Invermt"))
15337                 return (62);
15338             else if (!strcmp(modelParams[part].geneticCode, "Mycoplasma"))
15339                 return (62);
15340             else if (!strcmp(modelParams[part].geneticCode, "Yeast"))
15341                 return (62);
15342             else if (!strcmp(modelParams[part].geneticCode, "Ciliate"))
15343                 return (63);
15344             else if (!strcmp(modelParams[part].geneticCode, "Echinoderm"))
15345                 return (62);
15346             else if (!strcmp(modelParams[part].geneticCode, "Euplotid"))
15347                 return (62);
15348             else if (!strcmp(modelParams[part].geneticCode, "Metmt"))
15349                 return (62);
15350             }
15351         }
15352     else if (modelParams[part].dataType == PROTEIN)
15353         {
15354         return (20);
15355         }
15356     else if (modelParams[part].dataType == RESTRICTION)
15357         {
15358         return (2);
15359         }
15360     else if (modelParams[part].dataType == STANDARD)
15361         {
15362         return (10);
15363         }
15364 
15365     return (-1);
15366 }
15367 
15368 
15369 /*-----------------------------------------------------------------------
15370 |
15371 |   PrintCompMatrix: Print compressed matrix
15372 |
15373 ------------------------------------------------------------------------*/
PrintCompMatrix(void)15374 int PrintCompMatrix (void)
15375 {
15376     int             i, j, k, c, d;
15377     ModelInfo       *m;
15378     ModelParams     *mp;
15379     char            tempName[100];
15380     char            (*whichChar)(int);
15381 
15382     if (!compMatrix)
15383         return ERROR;
15384 
15385     whichChar = &WhichNuc;
15386 
15387     for (d=0; d<numCurrentDivisions; d++)
15388         {
15389         m = &modelSettings[d];
15390         mp = &modelParams[d];
15391 
15392         if (mp->dataType == DNA || mp->dataType == RNA)
15393             whichChar = &WhichNuc;
15394         if (mp->dataType == PROTEIN)
15395             whichChar = &WhichAA;
15396         if (mp->dataType == RESTRICTION)
15397             whichChar = &WhichRes;
15398         if (mp->dataType == STANDARD)
15399             whichChar = &WhichStand;
15400 
15401         MrBayesPrint ("\nCompressed matrix for division %d\n\n", d+1);
15402 
15403         k = 66;
15404         if (mp->dataType == CONTINUOUS)
15405             k /= 4;
15406 
15407         for (c=m->compMatrixStart; c<m->compMatrixStop; c+=k)
15408             {
15409             for (i=0; i<numLocalTaxa; i++)
15410                 {
15411                 strcpy (tempName, localTaxonNames[i]);
15412                 MrBayesPrint ("%-10.10s   ", tempName);
15413                 for (j=c; j<c+k; j++)
15414                     {
15415                     if (j >= m->compMatrixStop)
15416                         break;
15417                     if (mp->dataType == CONTINUOUS)
15418                         MrBayesPrint ("%3d ", compMatrix[pos(i,j,compMatrixRowSize)]);
15419                     else
15420                         MrBayesPrint ("%c", whichChar((int)compMatrix[pos(i,j,compMatrixRowSize)]));
15421                     }
15422                 MrBayesPrint("\n");
15423                 }
15424             MrBayesPrint("\nNo. sites    ");
15425             for (j=c; j<c+k; j++)
15426                 {
15427                 if (j >= m->compMatrixStop)
15428                     break;
15429                 i = (int) numSitesOfPat[m->compCharStart + (0*numCompressedChars) + (j - m->compMatrixStart)/m->nCharsPerSite]; /* NOTE: We are printing the unadulterated site pat nums */
15430                 if (i>9)
15431                     i = 'A' + i - 10;
15432                 else
15433                     i = '0' + i;
15434                 if (mp->dataType == CONTINUOUS)
15435                     MrBayesPrint("   %c ", i);
15436                 else
15437                     {
15438                     if ((j-m->compMatrixStart) % m->nCharsPerSite == 0)
15439                         MrBayesPrint ("%c", i);
15440                     else
15441                         MrBayesPrint(" ");
15442                     }
15443                 }
15444             MrBayesPrint ("\nOrig. char   ");
15445             for (j=c; j<c+k; j++)
15446                 {
15447                 if (j >= m->compMatrixStop)
15448                     break;
15449                 i = origChar[j];
15450                 if (i>9)
15451                     i = '0' + (i % 10);
15452                 else
15453                     i = '0' +i;
15454                 if (mp->dataType == CONTINUOUS)
15455                     MrBayesPrint("   %c ", i);
15456                 else
15457                     MrBayesPrint ("%c", i);
15458                 }
15459 
15460             if (mp->dataType == STANDARD && m->nStates != NULL)
15461                 {
15462                 MrBayesPrint ("\nNo. states   ");
15463                 for (j=c; j<c+k; j++)
15464                     {
15465                     if (j >= m->compMatrixStop)
15466                         break;
15467                     i = m->nStates[j-m->compCharStart];
15468                     MrBayesPrint ("%d", i);
15469                     }
15470                 MrBayesPrint ("\nCharType     ");
15471                 for (j=c; j<c+k; j++)
15472                     {
15473                     if (j >= m->compMatrixStop)
15474                         break;
15475                     i = m->cType[j-m->compMatrixStart];
15476                     if (i == ORD)
15477                         MrBayesPrint ("%c", 'O');
15478                     else if (i == UNORD)
15479                         MrBayesPrint ("%c", 'U');
15480                     else
15481                         MrBayesPrint ("%c", 'I');
15482                     }
15483                 MrBayesPrint ("\ntiIndex      ");
15484                 for (j=c; j<c+k; j++)
15485                     {
15486                     if (j >= m->compMatrixStop)
15487                         break;
15488                     i = m->tiIndex[j-m->compCharStart];
15489                     MrBayesPrint ("%d", i % 10);
15490                     }
15491                 MrBayesPrint ("\nbsIndex      ");
15492                 for (j=c; j<c+k; j++)
15493                     {
15494                     if (j >= m->compMatrixStop)
15495                         break;
15496                     i = m->bsIndex[j-m->compCharStart];
15497                     MrBayesPrint ("%d", i % 10);
15498                     }
15499                 }
15500             MrBayesPrint ("\n\n");
15501             }
15502         MrBayesPrint ("Press return to continue\n");
15503         getchar();
15504         }   /* next division */
15505 
15506     return NO_ERROR;
15507 }
15508 
15509 
15510 /*----------------------------------------------------------------------
15511 |
15512 |   PrintMatrix: Print data matrix
15513 |
15514 |
15515 ------------------------------------------------------------------------*/
PrintMatrix(void)15516 int PrintMatrix (void)
15517 {
15518     int             i, j=0, c, printWidth, nextColumn;
15519 
15520     if (!matrix)
15521         return ERROR;
15522 
15523     MrBayesPrint ("\nData matrix\n\n");
15524 
15525     printWidth = 79;
15526 
15527     for (c=0; c<numChar; c=j)
15528         {
15529         for (i=0; i<numTaxa; i++)
15530             {
15531             MrBayesPrint ("%-10.10s   ", taxaNames[i]);
15532             j = c;
15533             for (nextColumn=13; nextColumn < printWidth; nextColumn++)
15534                 {
15535                 if (j >= numChar)
15536                     break;
15537                 if (charInfo[j].charType == CONTINUOUS && nextColumn < printWidth - 3)
15538                     break;
15539                 if (charInfo[j].charType == CONTINUOUS)
15540                     {
15541                     MrBayesPrint ("%3d ", matrix[pos(i,j,numChar)]);
15542                     nextColumn += 3;
15543                     }
15544                 else if (charInfo[j].charType == DNA || charInfo[j].charType == RNA)
15545                     MrBayesPrint ("%c", WhichNuc(matrix[pos(i,j,numChar)]));
15546                 else if (charInfo[j].charType == PROTEIN)
15547                     MrBayesPrint ("%c", WhichAA(matrix[pos(i,j,numChar)]));
15548                 else if (charInfo[j].charType == RESTRICTION)
15549                     MrBayesPrint ("%c", WhichRes(matrix[pos(i,j,numChar)]));
15550                 else if (charInfo[j].charType == STANDARD)
15551                     MrBayesPrint ("%c", WhichStand(matrix[pos(i,j,numChar)]));
15552                 j++;
15553                 }
15554             MrBayesPrint("\n");
15555             }
15556         MrBayesPrint ("\n");
15557         }
15558 
15559     return NO_ERROR;
15560 }
15561 
15562 
15563 /*--------------------------------------------------------------
15564 |
15565 |   ProcessStdChars: process standard characters
15566 |
15567 ---------------------------------------------------------------*/
ProcessStdChars(RandLong * seed)15568 int ProcessStdChars (RandLong *seed)
15569 {
15570     int             c, d, i, j, k, n, ts, index, numStandardChars, origCharPos, *bsIndex;
15571     char            piHeader[30];
15572     ModelInfo       *m;
15573     ModelParams     *mp=NULL;
15574     Param           *p;
15575 
15576     /* set character type, no. states, ti index and bs index for standard characters */
15577     /* first calculate how many standard characters we have */
15578     numStandardChars = 0;
15579     for (d=0; d<numCurrentDivisions; d++)
15580         {
15581         mp = &modelParams[d];
15582         m = &modelSettings[d];
15583 
15584         if (mp->dataType != STANDARD)
15585             continue;
15586 
15587         numStandardChars += m->numChars;
15588         }
15589 
15590     /* return if there are no standard characters */
15591     if (numStandardChars == 0)
15592         return (NO_ERROR);
15593 
15594     /* we are still here so we have standard characters and need to deal with them */
15595 
15596     /* first allocate space for stdType, stateSize, tiIndex, bsIndex */
15597     if (memAllocs[ALLOC_STDTYPE] == YES)
15598         {
15599         free (stdType);
15600         stdType = NULL;
15601         memAllocs[ALLOC_STDTYPE] = NO;
15602         }
15603     stdType = (int *)SafeCalloc(4 * (size_t)numStandardChars, sizeof(int));
15604     if (!stdType)
15605         {
15606         MrBayesPrint ("%s   Problem allocating stdType (%d ints)\n", 4 * numStandardChars);
15607         return ERROR;
15608         }
15609     memAllocs[ALLOC_STDTYPE] = YES;
15610     stateSize = stdType + numStandardChars;
15611     tiIndex = stateSize + numStandardChars;
15612     bsIndex = tiIndex + numStandardChars;
15613 
15614     /* then fill in stdType and stateSize, set pointers */
15615     /* also fill in isTiNeeded for each division and tiIndex for each character */
15616     for (d=j=0; d<numCurrentDivisions; d++)
15617         {
15618         mp = &modelParams[d];
15619         m = &modelSettings[d];
15620 
15621         if (mp->dataType != STANDARD)
15622             continue;
15623 
15624         m->cType = stdType + j;
15625         m->nStates = stateSize + j;
15626         m->tiIndex = tiIndex + j;
15627         m->bsIndex = bsIndex + j;
15628 
15629         m->cijkLength = 0;
15630         m->nCijkParts = 0;
15631         for (c=0; c<m->numChars; c++)
15632             {
15633             if (origChar[c+m->compMatrixStart] < 0)
15634                 {
15635                 /* this is a dummy character */
15636                 m->cType[c] = UNORD;
15637                 m->nStates[c] = 2;
15638                 }
15639             else
15640                 {
15641                 /* this is an ordinary character */
15642                 m->cType[c] = charInfo[origChar[c + m->compMatrixStart]].ctype;
15643                 m->nStates[c] = charInfo[origChar[c + m->compMatrixStart]].numStates;
15644                 }
15645 
15646             /* check ctype settings */
15647             if (m->nStates[c] < 2)
15648                 {
15649                 MrBayesPrint ("%s   WARNING: Compressed character %d (original character %d) of division %d has less \n", spacer, c+m->compCharStart,origChar[c+m->compCharStart]+1, d+1);
15650                 MrBayesPrint ("%s            than two observed states; it will be assumed to have two states.\n", spacer);
15651                 m->nStates[c] = 2;
15652                 }
15653             if (m->nStates[c] > 6 && m->cType[c] != UNORD)
15654                 {
15655                 MrBayesPrint ("%s   Only unordered model supported for characters with more than 6 states\n", spacer);
15656                 return ERROR;
15657                 }
15658             if (m->nStates[c] == 2 && m->cType[c] == ORD)
15659                 m->cType[c] = UNORD;
15660             if (m->cType[c] == IRREV)
15661                 {
15662                 MrBayesPrint ("%s   Irreversible model not yet supported\n", spacer);
15663                 return ERROR;
15664                 }
15665 
15666             /* find max number of states */
15667             if (m->nStates[c] > m->numModelStates)
15668                 m->numModelStates = m->nStates[c];
15669 
15670             /* update Cijk info */
15671             if (strcmp(mp->symPiPr,"Fixed") != 0 || AreDoublesEqual(mp->symBetaFix, -1.0, 0.00001) == NO)
15672                 {
15673                 /* Asymmetry between stationary state frequencies -- we need one cijk and eigenvalue
15674                     set for each multistate character */
15675                 if (m->nStates[c] > 2 && (m->cType[c] == UNORD || m->cType[c] == ORD))
15676                     {
15677                     ts = m->nStates[c];
15678                     m->cijkLength += (ts * ts * ts) + (2 * ts);
15679                     m->nCijkParts++;
15680                     }
15681                 }
15682 
15683             /* set the ti probs needed */
15684             if (m->stateFreq->nValues == 0 || m->nStates[c] == 2)
15685                 {
15686                 if (m->cType[c] == UNORD)
15687                     m->isTiNeeded[m->nStates[c]-2] = YES;
15688                 if (m->cType[c] == ORD)
15689                     m->isTiNeeded[m->nStates[c]+6] = YES;
15690                 if (m->cType[c] == IRREV)
15691                     m->isTiNeeded[m->nStates[c]+11] = YES;
15692                 }
15693             }
15694 
15695         /* set ti index for each compressed character first         */
15696         /* set bs index later (below)                               */
15697 
15698         /* set base index, valid for binary chars */
15699         m->tiIndex[c] = 0;
15700 
15701         /* first adjust for unordered characters */
15702         for (k=0; k<9; k++)
15703             {
15704             if (m->isTiNeeded [k] == NO)
15705                 continue;
15706 
15707             for (c=0; c<m->numChars; c++)
15708                 {
15709                 if (m->cType[c] != UNORD || m->nStates[c] > k + 2)
15710                     {
15711                     m->tiIndex[c] += (k + 2) * (k + 2) * m->numRateCats;
15712                     }
15713                 }
15714             }
15715 
15716         /* second for ordered characters */
15717         for (k=9; k<13; k++)
15718             {
15719             if (m->isTiNeeded [k] == NO)
15720                 continue;
15721 
15722             for (c=0; c<m->numChars; c++)
15723                 {
15724                 if (m->cType[c] == IRREV || (m->cType[c] == ORD && m->nStates[c] > k - 6))
15725                     {
15726                     m->tiIndex[c] += (k - 6) * (k - 6) * m->numRateCats;
15727                     }
15728                 }
15729             }
15730 
15731         /* third for irrev characters */
15732         for (k=13; k<18; k++)
15733             {
15734             if (m->isTiNeeded [k] == NO)
15735                 continue;
15736 
15737             for (c=0; c<m->numChars; c++)
15738                 {
15739                 if (m->cType[c] == IRREV && m->nStates[c] > k - 11)
15740                     {
15741                     m->tiIndex[c] += (k - 11) * (k - 11) * m->numRateCats;
15742                     }
15743                 }
15744             }
15745 
15746         /* finally take beta cats into account in tiIndex        */
15747         /* the beta cats will only be used for binary characters */
15748         /* multistate characters get their ti indices reset here */
15749         if (m->numBetaCats > 1 && m->isTiNeeded[0] == YES)
15750             {
15751             k = 4 * m->numBetaCats * m->numRateCats;   /* offset for binary character ti probs */
15752             for (c=0; c<m->numChars; c++)
15753                 {
15754                 if (m->nStates[c] > 2)
15755                     {
15756                     m->tiIndex[c] = k;
15757                     k += m->nStates[c] * m->nStates[c] * m->numRateCats;
15758                     }
15759                 }
15760             }
15761         j += m->numChars;
15762         }
15763 
15764     /* deal with bsIndex */
15765     for (k=0; k<numParams; k++)
15766         {
15767         p = &params[k];
15768         if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
15769             continue;
15770         p->nSympi = 0;
15771         p->hasBinaryStd = NO;
15772         for (i=0; i<p->nRelParts; i++)
15773             if (modelSettings[p->relParts[i]].isTiNeeded[0] == YES)
15774                 break;
15775         if (i < p->nRelParts)
15776             p->hasBinaryStd = YES;
15777         if (p->paramId == SYMPI_EQUAL)
15778             {
15779             /* calculate the number of state frequencies needed */
15780             /* also set bsIndex appropriately                   */
15781             for (n=index=0; n<9; n++)
15782                 {
15783                 for (i=0; i<p->nRelParts; i++)
15784                     if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
15785                         break;
15786                 if (i < p->nRelParts)
15787                     {
15788                     for (i=0; i<p->nRelParts; i++)
15789                         {
15790                         m = &modelSettings[p->relParts[i]];
15791                         for (c=0; c<m->numChars; c++)
15792                             {
15793                             if (m->cType[c] != UNORD || m->nStates[c] > n + 2)
15794                                 {
15795                                 m->bsIndex[c] += (n + 2);
15796                                 }
15797                             }
15798                         }
15799                     index += (n + 2);
15800                     }
15801                 }
15802             for (n=9; n<13; n++)
15803                 {
15804                 for (i=0; i<p->nRelParts; i++)
15805                     if (modelSettings[p->relParts[i]].isTiNeeded[n] == YES)
15806                         break;
15807                 if (i < p->nRelParts)
15808                     {
15809                     for (i=0; i<p->nRelParts; i++)
15810                         {
15811                         m = &modelSettings[p->relParts[i]];
15812                         for (c=0; c<m->numChars; c++)
15813                             {
15814                             if (m->cType[c] == ORD && m->nStates[c] > n - 6)
15815                                 {
15816                                 m->bsIndex[c] += (n - 6);
15817                                 }
15818                             }
15819                         }
15820                     index += (n - 6);
15821                     }
15822                 }
15823             p->nStdStateFreqs = index;
15824             }
15825         else
15826             {
15827             /* if not equal we need space for beta category frequencies */
15828             index = 0;
15829             if (p->hasBinaryStd == YES)
15830                 index += (2 * modelSettings[p->relParts[0]].numBetaCats);
15831             /* as well as one set of frequencies for each multistate character */
15832             for (i=0; i<p->nRelParts; i++)
15833                 {
15834                 m = &modelSettings[p->relParts[i]];
15835                 for (c=0; c<m->numChars; c++)
15836                     {
15837                     if (m->nStates[c] > 2 && (m->cType[c] == UNORD || m->cType[c] == ORD))
15838                         {
15839                         m->bsIndex[c] = index;
15840                         index += m->nStates[c];
15841                         p->nSympi++;
15842                         }
15843                     }
15844                 }
15845             }
15846         p->nStdStateFreqs = index;
15847         }
15848 
15849     /* allocate space for bsIndex, sympiIndex, stdStateFreqs; then fill */
15850 
15851     /* first count number of sympis needed */
15852     for (k=n=i=0; k<numParams; k++)
15853         {
15854         p = &params[k];
15855         n += p->nSympi;     /* nsympi calculated above */
15856         }
15857 
15858     /* then allocate and fill in */
15859     if (n > 0)
15860         {
15861         if (memAllocs[ALLOC_SYMPIINDEX] == YES)
15862             {
15863             sympiIndex = (int *) SafeRealloc ((void *) sympiIndex, 3*n * sizeof (int));
15864             for (i=0; i<3*n; i++)
15865                 sympiIndex[i] = 0;
15866             }
15867         else
15868             sympiIndex = (int *) SafeCalloc (3*n, sizeof (int));
15869         if (!sympiIndex)
15870             {
15871             MrBayesPrint ("%s   Problem allocating sympiIndex\n", spacer);
15872             return (ERROR);
15873             }
15874         else
15875             memAllocs[ALLOC_SYMPIINDEX] = YES;
15876 
15877         /* set up sympi pointers and fill sympiIndex */
15878         for (k=i=0; k<numParams; k++)
15879             {
15880             p = &params[k];
15881             if (p->nSympi > 0)
15882                 {
15883                 p->printParam = YES;    /* print even if fixed alpha_symdir */
15884                 index = 0;
15885                 p->sympiBsIndex = sympiIndex + i;
15886                 p->sympinStates = sympiIndex + i + n;
15887                 p->sympiCType = sympiIndex + i + (2 * n);
15888                 for (j=0; j<p->nRelParts; j++)
15889                     {
15890                     m = &modelSettings[p->relParts[j]];
15891                     for (c=0; c<m->numChars; c++)
15892                         {
15893                         if (m->nStates[c] > 2 && (m->cType[c] == UNORD || m->cType[c] == ORD))
15894                             {
15895                             p->sympinStates[index] = m->nStates[c];
15896                             p->sympiBsIndex[index] = m->bsIndex[c];
15897                             p->sympiCType[index] = m->cType[c];
15898                             origCharPos = origChar[m->compCharStart + c];
15899                             for (ts=0; ts<m->nStates[c]; ts++)
15900                                 {
15901                                 sprintf (piHeader, "\tpi_%d(%d)", origCharPos+1, ts);
15902                                 SafeStrcat(&p->paramHeader, piHeader);
15903                                 }
15904                             index++;
15905                             }
15906                         }
15907                     }
15908                 assert (index == p->nSympi);
15909                 i += p->nSympi;
15910                 }
15911             }
15912         assert (i == n);
15913         }
15914 
15915     /* count space needed for state frequencies */
15916     for (k=n=0; k<numParams; k++)
15917         {
15918         p = &params[k];
15919         if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
15920             continue;
15921         n += p->nStdStateFreqs;
15922         }
15923 
15924     stdStateFreqsRowSize = n;
15925 
15926     /* allocate space */
15927     if (memAllocs[ALLOC_STDSTATEFREQS] == YES)
15928         {
15929         free (stdStateFreqs);
15930         stdStateFreqs = NULL;
15931         memAllocs[ALLOC_STDSTATEFREQS] = NO;
15932         }
15933     stdStateFreqs = (MrBFlt *) SafeCalloc (n * 2 * numGlobalChains, sizeof (MrBFlt));
15934     if (!stdStateFreqs)
15935         {
15936         MrBayesPrint ("%s   Problem allocating stdStateFreqs in ProcessStdChars\n", spacer);
15937         return (ERROR);
15938         }
15939     else
15940         memAllocs[ALLOC_STDSTATEFREQS] = YES;
15941 
15942     /* set pointers */
15943     for (k=n=0; k<numParams; k++)
15944         {
15945         p = &params[k];
15946         if (p->paramType != P_PI || modelParams[p->relParts[0]].dataType != STANDARD)
15947             continue;
15948         p->stdStateFreqs = stdStateFreqs + n;
15949         n += p->nStdStateFreqs;
15950         }
15951 
15952     FillStdStateFreqs (0 , numGlobalChains, seed);
15953 
15954     return (NO_ERROR);
15955 }
15956 
15957 
SetAARates(void)15958 int SetAARates (void)
15959 {
15960     int         i, j;
15961     MrBFlt      diff, sum, scaler;
15962 
15963     /* A R N D C Q E G H I L K M F P S T W Y V */
15964 
15965     /* jones */
15966     aaJones[ 0][ 0] =   0; aaJones[ 0][ 1] =  58; aaJones[ 0][ 2] =  54; aaJones[ 0][ 3] =  81; aaJones[ 0][ 4] =  56;
15967     aaJones[ 0][ 5] =  57; aaJones[ 0][ 6] = 105; aaJones[ 0][ 7] = 179; aaJones[ 0][ 8] =  27; aaJones[ 0][ 9] =  36;
15968     aaJones[ 0][10] =  30; aaJones[ 0][11] =  35; aaJones[ 0][12] =  54; aaJones[ 0][13] =  15; aaJones[ 0][14] = 194;
15969     aaJones[ 0][15] = 378; aaJones[ 0][16] = 475; aaJones[ 0][17] =   9; aaJones[ 0][18] =  11; aaJones[ 0][19] = 298;
15970     aaJones[ 1][ 0] =  58; aaJones[ 1][ 1] =   0; aaJones[ 1][ 2] =  45; aaJones[ 1][ 3] =  16; aaJones[ 1][ 4] = 113;
15971     aaJones[ 1][ 5] = 310; aaJones[ 1][ 6] =  29; aaJones[ 1][ 7] = 137; aaJones[ 1][ 8] = 328; aaJones[ 1][ 9] =  22;
15972     aaJones[ 1][10] =  38; aaJones[ 1][11] = 646; aaJones[ 1][12] =  44; aaJones[ 1][13] =   5; aaJones[ 1][14] =  74;
15973     aaJones[ 1][15] = 101; aaJones[ 1][16] =  64; aaJones[ 1][17] = 126; aaJones[ 1][18] =  20; aaJones[ 1][19] =  17;
15974     aaJones[ 2][ 0] =  54; aaJones[ 2][ 1] =  45; aaJones[ 2][ 2] =   0; aaJones[ 2][ 3] = 528; aaJones[ 2][ 4] =  34;
15975     aaJones[ 2][ 5] =  86; aaJones[ 2][ 6] =  58; aaJones[ 2][ 7] =  81; aaJones[ 2][ 8] = 391; aaJones[ 2][ 9] =  47;
15976     aaJones[ 2][10] =  12; aaJones[ 2][11] = 263; aaJones[ 2][12] =  30; aaJones[ 2][13] =  10; aaJones[ 2][14] =  15;
15977     aaJones[ 2][15] = 503; aaJones[ 2][16] = 232; aaJones[ 2][17] =   8; aaJones[ 2][18] =  70; aaJones[ 2][19] =  16;
15978     aaJones[ 3][ 0] =  81; aaJones[ 3][ 1] =  16; aaJones[ 3][ 2] = 528; aaJones[ 3][ 3] =   0; aaJones[ 3][ 4] =  10;
15979     aaJones[ 3][ 5] =  49; aaJones[ 3][ 6] = 767; aaJones[ 3][ 7] = 130; aaJones[ 3][ 8] = 112; aaJones[ 3][ 9] =  11;
15980     aaJones[ 3][10] =   7; aaJones[ 3][11] =  26; aaJones[ 3][12] =  15; aaJones[ 3][13] =   4; aaJones[ 3][14] =  15;
15981     aaJones[ 3][15] =  59; aaJones[ 3][16] =  38; aaJones[ 3][17] =   4; aaJones[ 3][18] =  46; aaJones[ 3][19] =  31;
15982     aaJones[ 4][ 0] =  56; aaJones[ 4][ 1] = 113; aaJones[ 4][ 2] =  34; aaJones[ 4][ 3] =  10; aaJones[ 4][ 4] =   0;
15983     aaJones[ 4][ 5] =   9; aaJones[ 4][ 6] =   5; aaJones[ 4][ 7] =  59; aaJones[ 4][ 8] =  69; aaJones[ 4][ 9] =  17;
15984     aaJones[ 4][10] =  23; aaJones[ 4][11] =   7; aaJones[ 4][12] =  31; aaJones[ 4][13] =  78; aaJones[ 4][14] =  14;
15985     aaJones[ 4][15] = 223; aaJones[ 4][16] =  42; aaJones[ 4][17] = 115; aaJones[ 4][18] = 209; aaJones[ 4][19] =  62;
15986     aaJones[ 5][ 0] =  57; aaJones[ 5][ 1] = 310; aaJones[ 5][ 2] =  86; aaJones[ 5][ 3] =  49; aaJones[ 5][ 4] =   9;
15987     aaJones[ 5][ 5] =   0; aaJones[ 5][ 6] = 323; aaJones[ 5][ 7] =  26; aaJones[ 5][ 8] = 597; aaJones[ 5][ 9] =   9;
15988     aaJones[ 5][10] =  72; aaJones[ 5][11] = 292; aaJones[ 5][12] =  43; aaJones[ 5][13] =   4; aaJones[ 5][14] = 164;
15989     aaJones[ 5][15] =  53; aaJones[ 5][16] =  51; aaJones[ 5][17] =  18; aaJones[ 5][18] =  24; aaJones[ 5][19] =  20;
15990     aaJones[ 6][ 0] = 105; aaJones[ 6][ 1] =  29; aaJones[ 6][ 2] =  58; aaJones[ 6][ 3] = 767; aaJones[ 6][ 4] =   5;
15991     aaJones[ 6][ 5] = 323; aaJones[ 6][ 6] =   0; aaJones[ 6][ 7] = 119; aaJones[ 6][ 8] =  26; aaJones[ 6][ 9] =  12;
15992     aaJones[ 6][10] =   9; aaJones[ 6][11] = 181; aaJones[ 6][12] =  18; aaJones[ 6][13] =   5; aaJones[ 6][14] =  18;
15993     aaJones[ 6][15] =  30; aaJones[ 6][16] =  32; aaJones[ 6][17] =  10; aaJones[ 6][18] =   7; aaJones[ 6][19] =  45;
15994     aaJones[ 7][ 0] = 179; aaJones[ 7][ 1] = 137; aaJones[ 7][ 2] =  81; aaJones[ 7][ 3] = 130; aaJones[ 7][ 4] =  59;
15995     aaJones[ 7][ 5] =  26; aaJones[ 7][ 6] = 119; aaJones[ 7][ 7] =   0; aaJones[ 7][ 8] =  23; aaJones[ 7][ 9] =   6;
15996     aaJones[ 7][10] =   6; aaJones[ 7][11] =  27; aaJones[ 7][12] =  14; aaJones[ 7][13] =   5; aaJones[ 7][14] =  24;
15997     aaJones[ 7][15] = 201; aaJones[ 7][16] =  33; aaJones[ 7][17] =  55; aaJones[ 7][18] =   8; aaJones[ 7][19] =  47;
15998     aaJones[ 8][ 0] =  27; aaJones[ 8][ 1] = 328; aaJones[ 8][ 2] = 391; aaJones[ 8][ 3] = 112; aaJones[ 8][ 4] =  69;
15999     aaJones[ 8][ 5] = 597; aaJones[ 8][ 6] =  26; aaJones[ 8][ 7] =  23; aaJones[ 8][ 8] =   0; aaJones[ 8][ 9] =  16;
16000     aaJones[ 8][10] =  56; aaJones[ 8][11] =  45; aaJones[ 8][12] =  33; aaJones[ 8][13] =  40; aaJones[ 8][14] = 115;
16001     aaJones[ 8][15] =  73; aaJones[ 8][16] =  46; aaJones[ 8][17] =   8; aaJones[ 8][18] = 573; aaJones[ 8][19] =  11;
16002     aaJones[ 9][ 0] =  36; aaJones[ 9][ 1] =  22; aaJones[ 9][ 2] =  47; aaJones[ 9][ 3] =  11; aaJones[ 9][ 4] =  17;
16003     aaJones[ 9][ 5] =   9; aaJones[ 9][ 6] =  12; aaJones[ 9][ 7] =   6; aaJones[ 9][ 8] =  16; aaJones[ 9][ 9] =   0;
16004     aaJones[ 9][10] = 229; aaJones[ 9][11] =  21; aaJones[ 9][12] = 479; aaJones[ 9][13] =  89; aaJones[ 9][14] =  10;
16005     aaJones[ 9][15] =  40; aaJones[ 9][16] = 245; aaJones[ 9][17] =   9; aaJones[ 9][18] =  32; aaJones[ 9][19] = 961;
16006     aaJones[10][ 0] =  30; aaJones[10][ 1] =  38; aaJones[10][ 2] =  12; aaJones[10][ 3] =   7; aaJones[10][ 4] =  23;
16007     aaJones[10][ 5] =  72; aaJones[10][ 6] =   9; aaJones[10][ 7] =   6; aaJones[10][ 8] =  56; aaJones[10][ 9] = 229;
16008     aaJones[10][10] =   0; aaJones[10][11] =  14; aaJones[10][12] = 388; aaJones[10][13] = 248; aaJones[10][14] = 102;
16009     aaJones[10][15] =  59; aaJones[10][16] =  25; aaJones[10][17] =  52; aaJones[10][18] =  24; aaJones[10][19] = 180;
16010     aaJones[11][ 0] =  35; aaJones[11][ 1] = 646; aaJones[11][ 2] = 263; aaJones[11][ 3] =  26; aaJones[11][ 4] =   7;
16011     aaJones[11][ 5] = 292; aaJones[11][ 6] = 181; aaJones[11][ 7] =  27; aaJones[11][ 8] =  45; aaJones[11][ 9] =  21;
16012     aaJones[11][10] =  14; aaJones[11][11] =   0; aaJones[11][12] =  65; aaJones[11][13] =   4; aaJones[11][14] =  21;
16013     aaJones[11][15] =  47; aaJones[11][16] = 103; aaJones[11][17] =  10; aaJones[11][18] =   8; aaJones[11][19] =  14;
16014     aaJones[12][ 0] =  54; aaJones[12][ 1] =  44; aaJones[12][ 2] =  30; aaJones[12][ 3] =  15; aaJones[12][ 4] =  31;
16015     aaJones[12][ 5] =  43; aaJones[12][ 6] =  18; aaJones[12][ 7] =  14; aaJones[12][ 8] =  33; aaJones[12][ 9] = 479;
16016     aaJones[12][10] = 388; aaJones[12][11] =  65; aaJones[12][12] =   0; aaJones[12][13] =  43; aaJones[12][14] =  16;
16017     aaJones[12][15] =  29; aaJones[12][16] = 226; aaJones[12][17] =  24; aaJones[12][18] =  18; aaJones[12][19] = 323;
16018     aaJones[13][ 0] =  15; aaJones[13][ 1] =   5; aaJones[13][ 2] =  10; aaJones[13][ 3] =   4; aaJones[13][ 4] =  78;
16019     aaJones[13][ 5] =   4; aaJones[13][ 6] =   5; aaJones[13][ 7] =   5; aaJones[13][ 8] =  40; aaJones[13][ 9] =  89;
16020     aaJones[13][10] = 248; aaJones[13][11] =   4; aaJones[13][12] =  43; aaJones[13][13] =   0; aaJones[13][14] =  17;
16021     aaJones[13][15] =  92; aaJones[13][16] =  12; aaJones[13][17] =  53; aaJones[13][18] = 536; aaJones[13][19] =  62;
16022     aaJones[14][ 0] = 194; aaJones[14][ 1] =  74; aaJones[14][ 2] =  15; aaJones[14][ 3] =  15; aaJones[14][ 4] =  14;
16023     aaJones[14][ 5] = 164; aaJones[14][ 6] =  18; aaJones[14][ 7] =  24; aaJones[14][ 8] = 115; aaJones[14][ 9] =  10;
16024     aaJones[14][10] = 102; aaJones[14][11] =  21; aaJones[14][12] =  16; aaJones[14][13] =  17; aaJones[14][14] =   0;
16025     aaJones[14][15] = 285; aaJones[14][16] = 118; aaJones[14][17] =   6; aaJones[14][18] =  10; aaJones[14][19] =  23;
16026     aaJones[15][ 0] = 378; aaJones[15][ 1] = 101; aaJones[15][ 2] = 503; aaJones[15][ 3] =  59; aaJones[15][ 4] = 223;
16027     aaJones[15][ 5] =  53; aaJones[15][ 6] =  30; aaJones[15][ 7] = 201; aaJones[15][ 8] =  73; aaJones[15][ 9] =  40;
16028     aaJones[15][10] =  59; aaJones[15][11] =  47; aaJones[15][12] =  29; aaJones[15][13] =  92; aaJones[15][14] = 285;
16029     aaJones[15][15] =   0; aaJones[15][16] = 477; aaJones[15][17] =  35; aaJones[15][18] =  63; aaJones[15][19] =  38;
16030     aaJones[16][ 0] = 475; aaJones[16][ 1] =  64; aaJones[16][ 2] = 232; aaJones[16][ 3] =  38; aaJones[16][ 4] =  42;
16031     aaJones[16][ 5] =  51; aaJones[16][ 6] =  32; aaJones[16][ 7] =  33; aaJones[16][ 8] =  46; aaJones[16][ 9] = 245;
16032     aaJones[16][10] =  25; aaJones[16][11] = 103; aaJones[16][12] = 226; aaJones[16][13] =  12; aaJones[16][14] = 118;
16033     aaJones[16][15] = 477; aaJones[16][16] =   0; aaJones[16][17] =  12; aaJones[16][18] =  21; aaJones[16][19] = 112;
16034     aaJones[17][ 0] =   9; aaJones[17][ 1] = 126; aaJones[17][ 2] =   8; aaJones[17][ 3] =   4; aaJones[17][ 4] = 115;
16035     aaJones[17][ 5] =  18; aaJones[17][ 6] =  10; aaJones[17][ 7] =  55; aaJones[17][ 8] =   8; aaJones[17][ 9] =   9;
16036     aaJones[17][10] =  52; aaJones[17][11] =  10; aaJones[17][12] =  24; aaJones[17][13] =  53; aaJones[17][14] =   6;
16037     aaJones[17][15] =  35; aaJones[17][16] =  12; aaJones[17][17] =   0; aaJones[17][18] =  71; aaJones[17][19] =  25;
16038     aaJones[18][ 0] =  11; aaJones[18][ 1] =  20; aaJones[18][ 2] =  70; aaJones[18][ 3] =  46; aaJones[18][ 4] = 209;
16039     aaJones[18][ 5] =  24; aaJones[18][ 6] =   7; aaJones[18][ 7] =   8; aaJones[18][ 8] = 573; aaJones[18][ 9] =  32;
16040     aaJones[18][10] =  24; aaJones[18][11] =   8; aaJones[18][12] =  18; aaJones[18][13] = 536; aaJones[18][14] =  10;
16041     aaJones[18][15] =  63; aaJones[18][16] =  21; aaJones[18][17] =  71; aaJones[18][18] =   0; aaJones[18][19] =  16;
16042     aaJones[19][ 0] = 298; aaJones[19][ 1] =  17; aaJones[19][ 2] =  16; aaJones[19][ 3] =  31; aaJones[19][ 4] =  62;
16043     aaJones[19][ 5] =  20; aaJones[19][ 6] =  45; aaJones[19][ 7] =  47; aaJones[19][ 8] =  11; aaJones[19][ 9] = 961;
16044     aaJones[19][10] = 180; aaJones[19][11] =  14; aaJones[19][12] = 323; aaJones[19][13] =  62; aaJones[19][14] =  23;
16045     aaJones[19][15] =  38; aaJones[19][16] = 112; aaJones[19][17] =  25; aaJones[19][18] =  16; aaJones[19][19] =   0;
16046 
16047     jonesPi[ 0] = 0.076748;
16048     jonesPi[ 1] = 0.051691;
16049     jonesPi[ 2] = 0.042645;
16050     jonesPi[ 3] = 0.051544;
16051     jonesPi[ 4] = 0.019803;
16052     jonesPi[ 5] = 0.040752;
16053     jonesPi[ 6] = 0.061830;
16054     jonesPi[ 7] = 0.073152;
16055     jonesPi[ 8] = 0.022944;
16056     jonesPi[ 9] = 0.053761;
16057     jonesPi[10] = 0.091904;
16058     jonesPi[11] = 0.058676;
16059     jonesPi[12] = 0.023826;
16060     jonesPi[13] = 0.040126;
16061     jonesPi[14] = 0.050901;
16062     jonesPi[15] = 0.068765;
16063     jonesPi[16] = 0.058565;
16064     jonesPi[17] = 0.014261;
16065     jonesPi[18] = 0.032102;
16066     jonesPi[19] = 0.066005;
16067 
16068     /* dayhoff */
16069     aaDayhoff[ 0][ 0] =   0; aaDayhoff[ 0][ 1] =  27; aaDayhoff[ 0][ 2] =  98; aaDayhoff[ 0][ 3] = 120; aaDayhoff[ 0][ 4] =  36;
16070     aaDayhoff[ 0][ 5] =  89; aaDayhoff[ 0][ 6] = 198; aaDayhoff[ 0][ 7] = 240; aaDayhoff[ 0][ 8] =  23; aaDayhoff[ 0][ 9] =  65;
16071     aaDayhoff[ 0][10] =  41; aaDayhoff[ 0][11] =  26; aaDayhoff[ 0][12] =  72; aaDayhoff[ 0][13] =  18; aaDayhoff[ 0][14] = 250;
16072     aaDayhoff[ 0][15] = 409; aaDayhoff[ 0][16] = 371; aaDayhoff[ 0][17] =   0; aaDayhoff[ 0][18] =  24; aaDayhoff[ 0][19] = 208;
16073     aaDayhoff[ 1][ 0] =  27; aaDayhoff[ 1][ 1] =   0; aaDayhoff[ 1][ 2] =  32; aaDayhoff[ 1][ 3] =   0; aaDayhoff[ 1][ 4] =  23;
16074     aaDayhoff[ 1][ 5] = 246; aaDayhoff[ 1][ 6] =   1; aaDayhoff[ 1][ 7] =   9; aaDayhoff[ 1][ 8] = 240; aaDayhoff[ 1][ 9] =  64;
16075     aaDayhoff[ 1][10] =  15; aaDayhoff[ 1][11] = 464; aaDayhoff[ 1][12] =  90; aaDayhoff[ 1][13] =  14; aaDayhoff[ 1][14] = 103;
16076     aaDayhoff[ 1][15] = 154; aaDayhoff[ 1][16] =  26; aaDayhoff[ 1][17] = 201; aaDayhoff[ 1][18] =   8; aaDayhoff[ 1][19] =  24;
16077     aaDayhoff[ 2][ 0] =  98; aaDayhoff[ 2][ 1] =  32; aaDayhoff[ 2][ 2] =   0; aaDayhoff[ 2][ 3] = 905; aaDayhoff[ 2][ 4] =   0;
16078     aaDayhoff[ 2][ 5] = 103; aaDayhoff[ 2][ 6] = 148; aaDayhoff[ 2][ 7] = 139; aaDayhoff[ 2][ 8] = 535; aaDayhoff[ 2][ 9] =  77;
16079     aaDayhoff[ 2][10] =  34; aaDayhoff[ 2][11] = 318; aaDayhoff[ 2][12] =   1; aaDayhoff[ 2][13] =  14; aaDayhoff[ 2][14] =  42;
16080     aaDayhoff[ 2][15] = 495; aaDayhoff[ 2][16] = 229; aaDayhoff[ 2][17] =  23; aaDayhoff[ 2][18] =  95; aaDayhoff[ 2][19] =  15;
16081     aaDayhoff[ 3][ 0] = 120; aaDayhoff[ 3][ 1] =   0; aaDayhoff[ 3][ 2] = 905; aaDayhoff[ 3][ 3] =   0; aaDayhoff[ 3][ 4] =   0;
16082     aaDayhoff[ 3][ 5] = 134; aaDayhoff[ 3][ 6] = 1153; aaDayhoff[ 3][ 7] = 125; aaDayhoff[ 3][ 8] =  86; aaDayhoff[ 3][ 9] =  24;
16083     aaDayhoff[ 3][10] =   0; aaDayhoff[ 3][11] =  71; aaDayhoff[ 3][12] =   0; aaDayhoff[ 3][13] =   0; aaDayhoff[ 3][14] =  13;
16084     aaDayhoff[ 3][15] =  95; aaDayhoff[ 3][16] =  66; aaDayhoff[ 3][17] =   0; aaDayhoff[ 3][18] =   0; aaDayhoff[ 3][19] =  18;
16085     aaDayhoff[ 4][ 0] =  36; aaDayhoff[ 4][ 1] =  23; aaDayhoff[ 4][ 2] =   0; aaDayhoff[ 4][ 3] =   0; aaDayhoff[ 4][ 4] =   0;
16086     aaDayhoff[ 4][ 5] =   0; aaDayhoff[ 4][ 6] =   0; aaDayhoff[ 4][ 7] =  11; aaDayhoff[ 4][ 8] =  28; aaDayhoff[ 4][ 9] =  44;
16087     aaDayhoff[ 4][10] =   0; aaDayhoff[ 4][11] =   0; aaDayhoff[ 4][12] =   0; aaDayhoff[ 4][13] =   0; aaDayhoff[ 4][14] =  19;
16088     aaDayhoff[ 4][15] = 161; aaDayhoff[ 4][16] =  16; aaDayhoff[ 4][17] =   0; aaDayhoff[ 4][18] =  96; aaDayhoff[ 4][19] =  49;
16089     aaDayhoff[ 5][ 0] =  89; aaDayhoff[ 5][ 1] = 246; aaDayhoff[ 5][ 2] = 103; aaDayhoff[ 5][ 3] = 134; aaDayhoff[ 5][ 4] =   0;
16090     aaDayhoff[ 5][ 5] =   0; aaDayhoff[ 5][ 6] = 716; aaDayhoff[ 5][ 7] =  28; aaDayhoff[ 5][ 8] = 606; aaDayhoff[ 5][ 9] =  18;
16091     aaDayhoff[ 5][10] =  73; aaDayhoff[ 5][11] = 153; aaDayhoff[ 5][12] = 114; aaDayhoff[ 5][13] =   0; aaDayhoff[ 5][14] = 153;
16092     aaDayhoff[ 5][15] =  56; aaDayhoff[ 5][16] =  53; aaDayhoff[ 5][17] =   0; aaDayhoff[ 5][18] =   0; aaDayhoff[ 5][19] =  35;
16093     aaDayhoff[ 6][ 0] = 198; aaDayhoff[ 6][ 1] =   1; aaDayhoff[ 6][ 2] = 148; aaDayhoff[ 6][ 3] = 1153; aaDayhoff[ 6][ 4] =   0;
16094     aaDayhoff[ 6][ 5] = 716; aaDayhoff[ 6][ 6] =   0; aaDayhoff[ 6][ 7] =  81; aaDayhoff[ 6][ 8] =  43; aaDayhoff[ 6][ 9] =  61;
16095     aaDayhoff[ 6][10] =  11; aaDayhoff[ 6][11] =  83; aaDayhoff[ 6][12] =  30; aaDayhoff[ 6][13] =   0; aaDayhoff[ 6][14] =  51;
16096     aaDayhoff[ 6][15] =  79; aaDayhoff[ 6][16] =  34; aaDayhoff[ 6][17] =   0; aaDayhoff[ 6][18] =  22; aaDayhoff[ 6][19] =  37;
16097     aaDayhoff[ 7][ 0] = 240; aaDayhoff[ 7][ 1] =   9; aaDayhoff[ 7][ 2] = 139; aaDayhoff[ 7][ 3] = 125; aaDayhoff[ 7][ 4] =  11;
16098     aaDayhoff[ 7][ 5] =  28; aaDayhoff[ 7][ 6] =  81; aaDayhoff[ 7][ 7] =   0; aaDayhoff[ 7][ 8] =  10; aaDayhoff[ 7][ 9] =   0;
16099     aaDayhoff[ 7][10] =   7; aaDayhoff[ 7][11] =  27; aaDayhoff[ 7][12] =  17; aaDayhoff[ 7][13] =  15; aaDayhoff[ 7][14] =  34;
16100     aaDayhoff[ 7][15] = 234; aaDayhoff[ 7][16] =  30; aaDayhoff[ 7][17] =   0; aaDayhoff[ 7][18] =   0; aaDayhoff[ 7][19] =  54;
16101     aaDayhoff[ 8][ 0] =  23; aaDayhoff[ 8][ 1] = 240; aaDayhoff[ 8][ 2] = 535; aaDayhoff[ 8][ 3] =  86; aaDayhoff[ 8][ 4] =  28;
16102     aaDayhoff[ 8][ 5] = 606; aaDayhoff[ 8][ 6] =  43; aaDayhoff[ 8][ 7] =  10; aaDayhoff[ 8][ 8] =   0; aaDayhoff[ 8][ 9] =   7;
16103     aaDayhoff[ 8][10] =  44; aaDayhoff[ 8][11] =  26; aaDayhoff[ 8][12] =   0; aaDayhoff[ 8][13] =  48; aaDayhoff[ 8][14] =  94;
16104     aaDayhoff[ 8][15] =  35; aaDayhoff[ 8][16] =  22; aaDayhoff[ 8][17] =  27; aaDayhoff[ 8][18] = 127; aaDayhoff[ 8][19] =  44;
16105     aaDayhoff[ 9][ 0] =  65; aaDayhoff[ 9][ 1] =  64; aaDayhoff[ 9][ 2] =  77; aaDayhoff[ 9][ 3] =  24; aaDayhoff[ 9][ 4] =  44;
16106     aaDayhoff[ 9][ 5] =  18; aaDayhoff[ 9][ 6] =  61; aaDayhoff[ 9][ 7] =   0; aaDayhoff[ 9][ 8] =   7; aaDayhoff[ 9][ 9] =   0;
16107     aaDayhoff[ 9][10] = 257; aaDayhoff[ 9][11] =  46; aaDayhoff[ 9][12] = 336; aaDayhoff[ 9][13] = 196; aaDayhoff[ 9][14] =  12;
16108     aaDayhoff[ 9][15] =  24; aaDayhoff[ 9][16] = 192; aaDayhoff[ 9][17] =   0; aaDayhoff[ 9][18] =  37; aaDayhoff[ 9][19] = 889;
16109     aaDayhoff[10][ 0] =  41; aaDayhoff[10][ 1] =  15; aaDayhoff[10][ 2] =  34; aaDayhoff[10][ 3] =   0; aaDayhoff[10][ 4] =   0;
16110     aaDayhoff[10][ 5] =  73; aaDayhoff[10][ 6] =  11; aaDayhoff[10][ 7] =   7; aaDayhoff[10][ 8] =  44; aaDayhoff[10][ 9] = 257;
16111     aaDayhoff[10][10] =   0; aaDayhoff[10][11] =  18; aaDayhoff[10][12] = 527; aaDayhoff[10][13] = 157; aaDayhoff[10][14] =  32;
16112     aaDayhoff[10][15] =  17; aaDayhoff[10][16] =  33; aaDayhoff[10][17] =  46; aaDayhoff[10][18] =  28; aaDayhoff[10][19] = 175;
16113     aaDayhoff[11][ 0] =  26; aaDayhoff[11][ 1] = 464; aaDayhoff[11][ 2] = 318; aaDayhoff[11][ 3] =  71; aaDayhoff[11][ 4] =   0;
16114     aaDayhoff[11][ 5] = 153; aaDayhoff[11][ 6] =  83; aaDayhoff[11][ 7] =  27; aaDayhoff[11][ 8] =  26; aaDayhoff[11][ 9] =  46;
16115     aaDayhoff[11][10] =  18; aaDayhoff[11][11] =   0; aaDayhoff[11][12] = 243; aaDayhoff[11][13] =   0; aaDayhoff[11][14] =  33;
16116     aaDayhoff[11][15] =  96; aaDayhoff[11][16] = 136; aaDayhoff[11][17] =   0; aaDayhoff[11][18] =  13; aaDayhoff[11][19] =  10;
16117     aaDayhoff[12][ 0] =  72; aaDayhoff[12][ 1] =  90; aaDayhoff[12][ 2] =   1; aaDayhoff[12][ 3] =   0; aaDayhoff[12][ 4] =   0;
16118     aaDayhoff[12][ 5] = 114; aaDayhoff[12][ 6] =  30; aaDayhoff[12][ 7] =  17; aaDayhoff[12][ 8] =   0; aaDayhoff[12][ 9] = 336;
16119     aaDayhoff[12][10] = 527; aaDayhoff[12][11] = 243; aaDayhoff[12][12] =   0; aaDayhoff[12][13] =  92; aaDayhoff[12][14] =  17;
16120     aaDayhoff[12][15] =  62; aaDayhoff[12][16] = 104; aaDayhoff[12][17] =   0; aaDayhoff[12][18] =   0; aaDayhoff[12][19] = 258;
16121     aaDayhoff[13][ 0] =  18; aaDayhoff[13][ 1] =  14; aaDayhoff[13][ 2] =  14; aaDayhoff[13][ 3] =   0; aaDayhoff[13][ 4] =   0;
16122     aaDayhoff[13][ 5] =   0; aaDayhoff[13][ 6] =   0; aaDayhoff[13][ 7] =  15; aaDayhoff[13][ 8] =  48; aaDayhoff[13][ 9] = 196;
16123     aaDayhoff[13][10] = 157; aaDayhoff[13][11] =   0; aaDayhoff[13][12] =  92; aaDayhoff[13][13] =   0; aaDayhoff[13][14] =  11;
16124     aaDayhoff[13][15] =  46; aaDayhoff[13][16] =  13; aaDayhoff[13][17] =  76; aaDayhoff[13][18] = 698; aaDayhoff[13][19] =  12;
16125     aaDayhoff[14][ 0] = 250; aaDayhoff[14][ 1] = 103; aaDayhoff[14][ 2] =  42; aaDayhoff[14][ 3] =  13; aaDayhoff[14][ 4] =  19;
16126     aaDayhoff[14][ 5] = 153; aaDayhoff[14][ 6] =  51; aaDayhoff[14][ 7] =  34; aaDayhoff[14][ 8] =  94; aaDayhoff[14][ 9] =  12;
16127     aaDayhoff[14][10] =  32; aaDayhoff[14][11] =  33; aaDayhoff[14][12] =  17; aaDayhoff[14][13] =  11; aaDayhoff[14][14] =   0;
16128     aaDayhoff[14][15] = 245; aaDayhoff[14][16] =  78; aaDayhoff[14][17] =   0; aaDayhoff[14][18] =   0; aaDayhoff[14][19] =  48;
16129     aaDayhoff[15][ 0] = 409; aaDayhoff[15][ 1] = 154; aaDayhoff[15][ 2] = 495; aaDayhoff[15][ 3] =  95; aaDayhoff[15][ 4] = 161;
16130     aaDayhoff[15][ 5] =  56; aaDayhoff[15][ 6] =  79; aaDayhoff[15][ 7] = 234; aaDayhoff[15][ 8] =  35; aaDayhoff[15][ 9] =  24;
16131     aaDayhoff[15][10] =  17; aaDayhoff[15][11] =  96; aaDayhoff[15][12] =  62; aaDayhoff[15][13] =  46; aaDayhoff[15][14] = 245;
16132     aaDayhoff[15][15] =   0; aaDayhoff[15][16] = 550; aaDayhoff[15][17] =  75; aaDayhoff[15][18] =  34; aaDayhoff[15][19] =  30;
16133     aaDayhoff[16][ 0] = 371; aaDayhoff[16][ 1] =  26; aaDayhoff[16][ 2] = 229; aaDayhoff[16][ 3] =  66; aaDayhoff[16][ 4] =  16;
16134     aaDayhoff[16][ 5] =  53; aaDayhoff[16][ 6] =  34; aaDayhoff[16][ 7] =  30; aaDayhoff[16][ 8] =  22; aaDayhoff[16][ 9] = 192;
16135     aaDayhoff[16][10] =  33; aaDayhoff[16][11] = 136; aaDayhoff[16][12] = 104; aaDayhoff[16][13] =  13; aaDayhoff[16][14] =  78;
16136     aaDayhoff[16][15] = 550; aaDayhoff[16][16] =   0; aaDayhoff[16][17] =   0; aaDayhoff[16][18] =  42; aaDayhoff[16][19] = 157;
16137     aaDayhoff[17][ 0] =   0; aaDayhoff[17][ 1] = 201; aaDayhoff[17][ 2] =  23; aaDayhoff[17][ 3] =   0; aaDayhoff[17][ 4] =   0;
16138     aaDayhoff[17][ 5] =   0; aaDayhoff[17][ 6] =   0; aaDayhoff[17][ 7] =   0; aaDayhoff[17][ 8] =  27; aaDayhoff[17][ 9] =   0;
16139     aaDayhoff[17][10] =  46; aaDayhoff[17][11] =   0; aaDayhoff[17][12] =   0; aaDayhoff[17][13] =  76; aaDayhoff[17][14] =   0;
16140     aaDayhoff[17][15] =  75; aaDayhoff[17][16] =   0; aaDayhoff[17][17] =   0; aaDayhoff[17][18] =  61; aaDayhoff[17][19] =   0;
16141     aaDayhoff[18][ 0] =  24; aaDayhoff[18][ 1] =   8; aaDayhoff[18][ 2] =  95; aaDayhoff[18][ 3] =   0; aaDayhoff[18][ 4] =  96;
16142     aaDayhoff[18][ 5] =   0; aaDayhoff[18][ 6] =  22; aaDayhoff[18][ 7] =   0; aaDayhoff[18][ 8] = 127; aaDayhoff[18][ 9] =  37;
16143     aaDayhoff[18][10] =  28; aaDayhoff[18][11] =  13; aaDayhoff[18][12] =   0; aaDayhoff[18][13] = 698; aaDayhoff[18][14] =   0;
16144     aaDayhoff[18][15] =  34; aaDayhoff[18][16] =  42; aaDayhoff[18][17] =  61; aaDayhoff[18][18] =   0; aaDayhoff[18][19] =  28;
16145     aaDayhoff[19][ 0] = 208; aaDayhoff[19][ 1] =  24; aaDayhoff[19][ 2] =  15; aaDayhoff[19][ 3] =  18; aaDayhoff[19][ 4] =  49;
16146     aaDayhoff[19][ 5] =  35; aaDayhoff[19][ 6] =  37; aaDayhoff[19][ 7] =  54; aaDayhoff[19][ 8] =  44; aaDayhoff[19][ 9] = 889;
16147     aaDayhoff[19][10] = 175; aaDayhoff[19][11] =  10; aaDayhoff[19][12] = 258; aaDayhoff[19][13] =  12; aaDayhoff[19][14] =  48;
16148     aaDayhoff[19][15] =  30; aaDayhoff[19][16] = 157; aaDayhoff[19][17] =   0; aaDayhoff[19][18] =  28; aaDayhoff[19][19] =   0;
16149 
16150     dayhoffPi[ 0] = 0.087127;
16151     dayhoffPi[ 1] = 0.040904;
16152     dayhoffPi[ 2] = 0.040432;
16153     dayhoffPi[ 3] = 0.046872;
16154     dayhoffPi[ 4] = 0.033474;
16155     dayhoffPi[ 5] = 0.038255;
16156     dayhoffPi[ 6] = 0.049530;
16157     dayhoffPi[ 7] = 0.088612;
16158     dayhoffPi[ 8] = 0.033618;
16159     dayhoffPi[ 9] = 0.036886;
16160     dayhoffPi[10] = 0.085357;
16161     dayhoffPi[11] = 0.080482;
16162     dayhoffPi[12] = 0.014753;
16163     dayhoffPi[13] = 0.039772;
16164     dayhoffPi[14] = 0.050680;
16165     dayhoffPi[15] = 0.069577;
16166     dayhoffPi[16] = 0.058542;
16167     dayhoffPi[17] = 0.010494;
16168     dayhoffPi[18] = 0.029916;
16169     dayhoffPi[19] = 0.064718;
16170 
16171     /* mtrev24 */
16172     aaMtrev24[ 0][ 0] =   0.00; aaMtrev24[ 0][ 1] =  23.18; aaMtrev24[ 0][ 2] =  26.95; aaMtrev24[ 0][ 3] =  17.67; aaMtrev24[ 0][ 4] =  59.93;
16173     aaMtrev24[ 0][ 5] =   1.90; aaMtrev24[ 0][ 6] =   9.77; aaMtrev24[ 0][ 7] = 120.71; aaMtrev24[ 0][ 8] =  13.90; aaMtrev24[ 0][ 9] =  96.49;
16174     aaMtrev24[ 0][10] =  25.46; aaMtrev24[ 0][11] =   8.36; aaMtrev24[ 0][12] = 141.88; aaMtrev24[ 0][13] =   6.37; aaMtrev24[ 0][14] =  54.31;
16175     aaMtrev24[ 0][15] = 387.86; aaMtrev24[ 0][16] = 480.72; aaMtrev24[ 0][17] =   1.90; aaMtrev24[ 0][18] =   6.48; aaMtrev24[ 0][19] = 195.06;
16176     aaMtrev24[ 1][ 0] =  23.18; aaMtrev24[ 1][ 1] =   0.00; aaMtrev24[ 1][ 2] =  13.24; aaMtrev24[ 1][ 3] =   1.90; aaMtrev24[ 1][ 4] = 103.33;
16177     aaMtrev24[ 1][ 5] = 220.99; aaMtrev24[ 1][ 6] =   1.90; aaMtrev24[ 1][ 7] =  23.03; aaMtrev24[ 1][ 8] = 165.23; aaMtrev24[ 1][ 9] =   1.90;
16178     aaMtrev24[ 1][10] =  15.58; aaMtrev24[ 1][11] = 141.40; aaMtrev24[ 1][12] =   1.90; aaMtrev24[ 1][13] =   4.69; aaMtrev24[ 1][14] =  23.64;
16179     aaMtrev24[ 1][15] =   6.04; aaMtrev24[ 1][16] =   2.08; aaMtrev24[ 1][17] =  21.95; aaMtrev24[ 1][18] =   1.90; aaMtrev24[ 1][19] =   7.64;
16180     aaMtrev24[ 2][ 0] =  26.95; aaMtrev24[ 2][ 1] =  13.24; aaMtrev24[ 2][ 2] =   0.00; aaMtrev24[ 2][ 3] = 794.38; aaMtrev24[ 2][ 4] =  58.94;
16181     aaMtrev24[ 2][ 5] = 173.56; aaMtrev24[ 2][ 6] =  63.05; aaMtrev24[ 2][ 7] =  53.30; aaMtrev24[ 2][ 8] = 496.13; aaMtrev24[ 2][ 9] =  27.10;
16182     aaMtrev24[ 2][10] =  15.16; aaMtrev24[ 2][11] = 608.70; aaMtrev24[ 2][12] =  65.41; aaMtrev24[ 2][13] =  15.20; aaMtrev24[ 2][14] =  73.31;
16183     aaMtrev24[ 2][15] = 494.39; aaMtrev24[ 2][16] = 238.46; aaMtrev24[ 2][17] =  10.68; aaMtrev24[ 2][18] = 191.36; aaMtrev24[ 2][19] =   1.90;
16184     aaMtrev24[ 3][ 0] =  17.67; aaMtrev24[ 3][ 1] =   1.90; aaMtrev24[ 3][ 2] = 794.38; aaMtrev24[ 3][ 3] =   0.00; aaMtrev24[ 3][ 4] =   1.90;
16185     aaMtrev24[ 3][ 5] =  55.28; aaMtrev24[ 3][ 6] = 583.55; aaMtrev24[ 3][ 7] =  56.77; aaMtrev24[ 3][ 8] = 113.99; aaMtrev24[ 3][ 9] =   4.34;
16186     aaMtrev24[ 3][10] =   1.90; aaMtrev24[ 3][11] =   2.31; aaMtrev24[ 3][12] =   1.90; aaMtrev24[ 3][13] =   4.98; aaMtrev24[ 3][14] =  13.43;
16187     aaMtrev24[ 3][15] =  69.02; aaMtrev24[ 3][16] =  28.01; aaMtrev24[ 3][17] =  19.86; aaMtrev24[ 3][18] =  21.21; aaMtrev24[ 3][19] =   1.90;
16188     aaMtrev24[ 4][ 0] =  59.93; aaMtrev24[ 4][ 1] = 103.33; aaMtrev24[ 4][ 2] =  58.94; aaMtrev24[ 4][ 3] =   1.90; aaMtrev24[ 4][ 4] =   0.00;
16189     aaMtrev24[ 4][ 5] =  75.24; aaMtrev24[ 4][ 6] =   1.90; aaMtrev24[ 4][ 7] =  30.71; aaMtrev24[ 4][ 8] = 141.49; aaMtrev24[ 4][ 9] =  62.73;
16190     aaMtrev24[ 4][10] =  25.65; aaMtrev24[ 4][11] =   1.90; aaMtrev24[ 4][12] =   6.18; aaMtrev24[ 4][13] =  70.80; aaMtrev24[ 4][14] =  31.26;
16191     aaMtrev24[ 4][15] = 277.05; aaMtrev24[ 4][16] = 179.97; aaMtrev24[ 4][17] =  33.60; aaMtrev24[ 4][18] = 254.77; aaMtrev24[ 4][19] =   1.90;
16192     aaMtrev24[ 5][ 0] =   1.90; aaMtrev24[ 5][ 1] = 220.99; aaMtrev24[ 5][ 2] = 173.56; aaMtrev24[ 5][ 3] =  55.28; aaMtrev24[ 5][ 4] =  75.24;
16193     aaMtrev24[ 5][ 5] =   0.00; aaMtrev24[ 5][ 6] = 313.56; aaMtrev24[ 5][ 7] =   6.75; aaMtrev24[ 5][ 8] = 582.40; aaMtrev24[ 5][ 9] =   8.34;
16194     aaMtrev24[ 5][10] =  39.70; aaMtrev24[ 5][11] = 465.58; aaMtrev24[ 5][12] =  47.37; aaMtrev24[ 5][13] =  19.11; aaMtrev24[ 5][14] = 137.29;
16195     aaMtrev24[ 5][15] =  54.11; aaMtrev24[ 5][16] =  94.93; aaMtrev24[ 5][17] =   1.90; aaMtrev24[ 5][18] =  38.82; aaMtrev24[ 5][19] =  19.00;
16196     aaMtrev24[ 6][ 0] =   9.77; aaMtrev24[ 6][ 1] =   1.90; aaMtrev24[ 6][ 2] =  63.05; aaMtrev24[ 6][ 3] = 583.55; aaMtrev24[ 6][ 4] =   1.90;
16197     aaMtrev24[ 6][ 5] = 313.56; aaMtrev24[ 6][ 6] =   0.00; aaMtrev24[ 6][ 7] =  28.28; aaMtrev24[ 6][ 8] =  49.12; aaMtrev24[ 6][ 9] =   3.31;
16198     aaMtrev24[ 6][10] =   1.90; aaMtrev24[ 6][11] = 313.86; aaMtrev24[ 6][12] =   1.90; aaMtrev24[ 6][13] =   2.67; aaMtrev24[ 6][14] =  12.83;
16199     aaMtrev24[ 6][15] =  54.71; aaMtrev24[ 6][16] =  14.82; aaMtrev24[ 6][17] =   1.90; aaMtrev24[ 6][18] =  13.12; aaMtrev24[ 6][19] =  21.14;
16200     aaMtrev24[ 7][ 0] = 120.71; aaMtrev24[ 7][ 1] =  23.03; aaMtrev24[ 7][ 2] =  53.30; aaMtrev24[ 7][ 3] =  56.77; aaMtrev24[ 7][ 4] =  30.71;
16201     aaMtrev24[ 7][ 5] =   6.75; aaMtrev24[ 7][ 6] =  28.28; aaMtrev24[ 7][ 7] =   0.00; aaMtrev24[ 7][ 8] =   1.90; aaMtrev24[ 7][ 9] =   5.98;
16202     aaMtrev24[ 7][10] =   2.41; aaMtrev24[ 7][11] =  22.73; aaMtrev24[ 7][12] =   1.90; aaMtrev24[ 7][13] =   1.90; aaMtrev24[ 7][14] =   1.90;
16203     aaMtrev24[ 7][15] = 125.93; aaMtrev24[ 7][16] =  11.17; aaMtrev24[ 7][17] =  10.92; aaMtrev24[ 7][18] =   3.21; aaMtrev24[ 7][19] =   2.53;
16204     aaMtrev24[ 8][ 0] =  13.90; aaMtrev24[ 8][ 1] = 165.23; aaMtrev24[ 8][ 2] = 496.13; aaMtrev24[ 8][ 3] = 113.99; aaMtrev24[ 8][ 4] = 141.49;
16205     aaMtrev24[ 8][ 5] = 582.40; aaMtrev24[ 8][ 6] =  49.12; aaMtrev24[ 8][ 7] =   1.90; aaMtrev24[ 8][ 8] =   0.00; aaMtrev24[ 8][ 9] =  12.26;
16206     aaMtrev24[ 8][10] =  11.49; aaMtrev24[ 8][11] = 127.67; aaMtrev24[ 8][12] =  11.97; aaMtrev24[ 8][13] =  48.16; aaMtrev24[ 8][14] =  60.97;
16207     aaMtrev24[ 8][15] =  77.46; aaMtrev24[ 8][16] =  44.78; aaMtrev24[ 8][17] =   7.08; aaMtrev24[ 8][18] = 670.14; aaMtrev24[ 8][19] =   1.90;
16208     aaMtrev24[ 9][ 0] =  96.49; aaMtrev24[ 9][ 1] =   1.90; aaMtrev24[ 9][ 2] =  27.10; aaMtrev24[ 9][ 3] =   4.34; aaMtrev24[ 9][ 4] =  62.73;
16209     aaMtrev24[ 9][ 5] =   8.34; aaMtrev24[ 9][ 6] =   3.31; aaMtrev24[ 9][ 7] =   5.98; aaMtrev24[ 9][ 8] =  12.26; aaMtrev24[ 9][ 9] =   0.00;
16210     aaMtrev24[ 9][10] = 329.09; aaMtrev24[ 9][11] =  19.57; aaMtrev24[ 9][12] = 517.98; aaMtrev24[ 9][13] =  84.67; aaMtrev24[ 9][14] =  20.63;
16211     aaMtrev24[ 9][15] =  47.70; aaMtrev24[ 9][16] = 368.43; aaMtrev24[ 9][17] =   1.90; aaMtrev24[ 9][18] =  25.01; aaMtrev24[ 9][19] =1222.94;
16212     aaMtrev24[10][ 0] =  25.46; aaMtrev24[10][ 1] =  15.58; aaMtrev24[10][ 2] =  15.16; aaMtrev24[10][ 3] =   1.90; aaMtrev24[10][ 4] =  25.65;
16213     aaMtrev24[10][ 5] =  39.70; aaMtrev24[10][ 6] =   1.90; aaMtrev24[10][ 7] =   2.41; aaMtrev24[10][ 8] =  11.49; aaMtrev24[10][ 9] = 329.09;
16214     aaMtrev24[10][10] =   0.00; aaMtrev24[10][11] =  14.88; aaMtrev24[10][12] = 537.53; aaMtrev24[10][13] = 216.06; aaMtrev24[10][14] =  40.10;
16215     aaMtrev24[10][15] =  73.61; aaMtrev24[10][16] = 126.40; aaMtrev24[10][17] =  32.44; aaMtrev24[10][18] =  44.15; aaMtrev24[10][19] =  91.67;
16216     aaMtrev24[11][ 0] =   8.36; aaMtrev24[11][ 1] = 141.40; aaMtrev24[11][ 2] = 608.70; aaMtrev24[11][ 3] =   2.31; aaMtrev24[11][ 4] =   1.90;
16217     aaMtrev24[11][ 5] = 465.58; aaMtrev24[11][ 6] = 313.86; aaMtrev24[11][ 7] =  22.73; aaMtrev24[11][ 8] = 127.67; aaMtrev24[11][ 9] =  19.57;
16218     aaMtrev24[11][10] =  14.88; aaMtrev24[11][11] =   0.00; aaMtrev24[11][12] =  91.37; aaMtrev24[11][13] =   6.44; aaMtrev24[11][14] =  50.10;
16219     aaMtrev24[11][15] = 105.79; aaMtrev24[11][16] = 136.33; aaMtrev24[11][17] =  24.00; aaMtrev24[11][18] =  51.17; aaMtrev24[11][19] =   1.90;
16220     aaMtrev24[12][ 0] = 141.88; aaMtrev24[12][ 1] =   1.90; aaMtrev24[12][ 2] =  65.41; aaMtrev24[12][ 3] =   1.90; aaMtrev24[12][ 4] =   6.18;
16221     aaMtrev24[12][ 5] =  47.37; aaMtrev24[12][ 6] =   1.90; aaMtrev24[12][ 7] =   1.90; aaMtrev24[12][ 8] =  11.97; aaMtrev24[12][ 9] = 517.98;
16222     aaMtrev24[12][10] = 537.53; aaMtrev24[12][11] =  91.37; aaMtrev24[12][12] =   0.00; aaMtrev24[12][13] =  90.82; aaMtrev24[12][14] =  18.84;
16223     aaMtrev24[12][15] = 111.16; aaMtrev24[12][16] = 528.17; aaMtrev24[12][17] =  21.71; aaMtrev24[12][18] =  39.96; aaMtrev24[12][19] = 387.54;
16224     aaMtrev24[13][ 0] =   6.37; aaMtrev24[13][ 1] =   4.69; aaMtrev24[13][ 2] =  15.20; aaMtrev24[13][ 3] =   4.98; aaMtrev24[13][ 4] =  70.80;
16225     aaMtrev24[13][ 5] =  19.11; aaMtrev24[13][ 6] =   2.67; aaMtrev24[13][ 7] =   1.90; aaMtrev24[13][ 8] =  48.16; aaMtrev24[13][ 9] =  84.67;
16226     aaMtrev24[13][10] = 216.06; aaMtrev24[13][11] =   6.44; aaMtrev24[13][12] =  90.82; aaMtrev24[13][13] =   0.00; aaMtrev24[13][14] =  17.31;
16227     aaMtrev24[13][15] =  64.29; aaMtrev24[13][16] =  33.85; aaMtrev24[13][17] =   7.84; aaMtrev24[13][18] = 465.58; aaMtrev24[13][19] =   6.35;
16228     aaMtrev24[14][ 0] =  54.31; aaMtrev24[14][ 1] =  23.64; aaMtrev24[14][ 2] =  73.31; aaMtrev24[14][ 3] =  13.43; aaMtrev24[14][ 4] =  31.26;
16229     aaMtrev24[14][ 5] = 137.29; aaMtrev24[14][ 6] =  12.83; aaMtrev24[14][ 7] =   1.90; aaMtrev24[14][ 8] =  60.97; aaMtrev24[14][ 9] =  20.63;
16230     aaMtrev24[14][10] =  40.10; aaMtrev24[14][11] =  50.10; aaMtrev24[14][12] =  18.84; aaMtrev24[14][13] =  17.31; aaMtrev24[14][14] =   0.00;
16231     aaMtrev24[14][15] = 169.90; aaMtrev24[14][16] = 128.22; aaMtrev24[14][17] =   4.21; aaMtrev24[14][18] =  16.21; aaMtrev24[14][19] =   8.23;
16232     aaMtrev24[15][ 0] = 387.86; aaMtrev24[15][ 1] =   6.04; aaMtrev24[15][ 2] = 494.39; aaMtrev24[15][ 3] =  69.02; aaMtrev24[15][ 4] = 277.05;
16233     aaMtrev24[15][ 5] =  54.11; aaMtrev24[15][ 6] =  54.71; aaMtrev24[15][ 7] = 125.93; aaMtrev24[15][ 8] =  77.46; aaMtrev24[15][ 9] =  47.70;
16234     aaMtrev24[15][10] =  73.61; aaMtrev24[15][11] = 105.79; aaMtrev24[15][12] = 111.16; aaMtrev24[15][13] =  64.29; aaMtrev24[15][14] = 169.90;
16235     aaMtrev24[15][15] =   0.00; aaMtrev24[15][16] = 597.21; aaMtrev24[15][17] =  38.58; aaMtrev24[15][18] =  64.92; aaMtrev24[15][19] =   1.90;
16236     aaMtrev24[16][ 0] = 480.72; aaMtrev24[16][ 1] =   2.08; aaMtrev24[16][ 2] = 238.46; aaMtrev24[16][ 3] =  28.01; aaMtrev24[16][ 4] = 179.97;
16237     aaMtrev24[16][ 5] =  94.93; aaMtrev24[16][ 6] =  14.82; aaMtrev24[16][ 7] =  11.17; aaMtrev24[16][ 8] =  44.78; aaMtrev24[16][ 9] = 368.43;
16238     aaMtrev24[16][10] = 126.40; aaMtrev24[16][11] = 136.33; aaMtrev24[16][12] = 528.17; aaMtrev24[16][13] =  33.85; aaMtrev24[16][14] = 128.22;
16239     aaMtrev24[16][15] = 597.21; aaMtrev24[16][16] =   0.00; aaMtrev24[16][17] =   9.99; aaMtrev24[16][18] =  38.73; aaMtrev24[16][19] = 204.54;
16240     aaMtrev24[17][ 0] =   1.90; aaMtrev24[17][ 1] =  21.95; aaMtrev24[17][ 2] =  10.68; aaMtrev24[17][ 3] =  19.86; aaMtrev24[17][ 4] =  33.60;
16241     aaMtrev24[17][ 5] =   1.90; aaMtrev24[17][ 6] =   1.90; aaMtrev24[17][ 7] =  10.92; aaMtrev24[17][ 8] =   7.08; aaMtrev24[17][ 9] =   1.90;
16242     aaMtrev24[17][10] =  32.44; aaMtrev24[17][11] =  24.00; aaMtrev24[17][12] =  21.71; aaMtrev24[17][13] =   7.84; aaMtrev24[17][14] =   4.21;
16243     aaMtrev24[17][15] =  38.58; aaMtrev24[17][16] =   9.99; aaMtrev24[17][17] =   0.00; aaMtrev24[17][18] =  26.25; aaMtrev24[17][19] =   5.37;
16244     aaMtrev24[18][ 0] =   6.48; aaMtrev24[18][ 1] =   1.90; aaMtrev24[18][ 2] = 191.36; aaMtrev24[18][ 3] =  21.21; aaMtrev24[18][ 4] = 254.77;
16245     aaMtrev24[18][ 5] =  38.82; aaMtrev24[18][ 6] =  13.12; aaMtrev24[18][ 7] =   3.21; aaMtrev24[18][ 8] = 670.14; aaMtrev24[18][ 9] =  25.01;
16246     aaMtrev24[18][10] =  44.15; aaMtrev24[18][11] =  51.17; aaMtrev24[18][12] =  39.96; aaMtrev24[18][13] = 465.58; aaMtrev24[18][14] =  16.21;
16247     aaMtrev24[18][15] =  64.92; aaMtrev24[18][16] =  38.73; aaMtrev24[18][17] =  26.25; aaMtrev24[18][18] =   0.00; aaMtrev24[18][19] =   1.90;
16248     aaMtrev24[19][ 0] = 195.06; aaMtrev24[19][ 1] =   7.64; aaMtrev24[19][ 2] =   1.90; aaMtrev24[19][ 3] =   1.90; aaMtrev24[19][ 4] =   1.90;
16249     aaMtrev24[19][ 5] =  19.00; aaMtrev24[19][ 6] =  21.14; aaMtrev24[19][ 7] =   2.53; aaMtrev24[19][ 8] =   1.90; aaMtrev24[19][ 9] =1222.94;
16250     aaMtrev24[19][10] =  91.67; aaMtrev24[19][11] =   1.90; aaMtrev24[19][12] = 387.54; aaMtrev24[19][13] =   6.35; aaMtrev24[19][14] =   8.23;
16251     aaMtrev24[19][15] =   1.90; aaMtrev24[19][16] = 204.54; aaMtrev24[19][17] =   5.37; aaMtrev24[19][18] =   1.90; aaMtrev24[19][19] =   0.00;
16252 
16253     mtrev24Pi[ 0] = 0.072;
16254     mtrev24Pi[ 1] = 0.019;
16255     mtrev24Pi[ 2] = 0.039;
16256     mtrev24Pi[ 3] = 0.019;
16257     mtrev24Pi[ 4] = 0.006;
16258     mtrev24Pi[ 5] = 0.025;
16259     mtrev24Pi[ 6] = 0.024;
16260     mtrev24Pi[ 7] = 0.056;
16261     mtrev24Pi[ 8] = 0.028;
16262     mtrev24Pi[ 9] = 0.088;
16263     mtrev24Pi[10] = 0.168;
16264     mtrev24Pi[11] = 0.023;
16265     mtrev24Pi[12] = 0.054;
16266     mtrev24Pi[13] = 0.061;
16267     mtrev24Pi[14] = 0.054;
16268     mtrev24Pi[15] = 0.072;
16269     mtrev24Pi[16] = 0.086;
16270     mtrev24Pi[17] = 0.029;
16271     mtrev24Pi[18] = 0.033;
16272     mtrev24Pi[19] = 0.043;
16273 
16274     /* mtmam */
16275     aaMtmam[ 0][ 0] =   0; aaMtmam[ 0][ 1] =  32; aaMtmam[ 0][ 2] =   2; aaMtmam[ 0][ 3] =  11; aaMtmam[ 0][ 4] =   0;
16276     aaMtmam[ 0][ 5] =   0; aaMtmam[ 0][ 6] =   0; aaMtmam[ 0][ 7] =  78; aaMtmam[ 0][ 8] =   8; aaMtmam[ 0][ 9] =  75;
16277     aaMtmam[ 0][10] =  21; aaMtmam[ 0][11] =   0; aaMtmam[ 0][12] =  76; aaMtmam[ 0][13] =   0; aaMtmam[ 0][14] =  53;
16278     aaMtmam[ 0][15] = 342; aaMtmam[ 0][16] = 681; aaMtmam[ 0][17] =   5; aaMtmam[ 0][18] =   0; aaMtmam[ 0][19] = 398;
16279     aaMtmam[ 1][ 0] =  32; aaMtmam[ 1][ 1] =   0; aaMtmam[ 1][ 2] =   4; aaMtmam[ 1][ 3] =   0; aaMtmam[ 1][ 4] = 186;
16280     aaMtmam[ 1][ 5] = 246; aaMtmam[ 1][ 6] =   0; aaMtmam[ 1][ 7] =  18; aaMtmam[ 1][ 8] = 232; aaMtmam[ 1][ 9] =   0;
16281     aaMtmam[ 1][10] =   6; aaMtmam[ 1][11] =  50; aaMtmam[ 1][12] =   0; aaMtmam[ 1][13] =   0; aaMtmam[ 1][14] =   9;
16282     aaMtmam[ 1][15] =   3; aaMtmam[ 1][16] =   0; aaMtmam[ 1][17] =  16; aaMtmam[ 1][18] =   0; aaMtmam[ 1][19] =   0;
16283     aaMtmam[ 2][ 0] =   2; aaMtmam[ 2][ 1] =   4; aaMtmam[ 2][ 2] =   0; aaMtmam[ 2][ 3] = 864; aaMtmam[ 2][ 4] =   0;
16284     aaMtmam[ 2][ 5] =   8; aaMtmam[ 2][ 6] =   0; aaMtmam[ 2][ 7] =  47; aaMtmam[ 2][ 8] = 458; aaMtmam[ 2][ 9] =  19;
16285     aaMtmam[ 2][10] =   0; aaMtmam[ 2][11] = 408; aaMtmam[ 2][12] =  21; aaMtmam[ 2][13] =   6; aaMtmam[ 2][14] =  33;
16286     aaMtmam[ 2][15] = 446; aaMtmam[ 2][16] = 110; aaMtmam[ 2][17] =   6; aaMtmam[ 2][18] = 156; aaMtmam[ 2][19] =   0;
16287     aaMtmam[ 3][ 0] =  11; aaMtmam[ 3][ 1] =   0; aaMtmam[ 3][ 2] = 864; aaMtmam[ 3][ 3] =   0; aaMtmam[ 3][ 4] =   0;
16288     aaMtmam[ 3][ 5] =  49; aaMtmam[ 3][ 6] = 569; aaMtmam[ 3][ 7] =  79; aaMtmam[ 3][ 8] =  11; aaMtmam[ 3][ 9] =   0;
16289     aaMtmam[ 3][10] =   0; aaMtmam[ 3][11] =   0; aaMtmam[ 3][12] =   0; aaMtmam[ 3][13] =   5; aaMtmam[ 3][14] =   2;
16290     aaMtmam[ 3][15] =  16; aaMtmam[ 3][16] =   0; aaMtmam[ 3][17] =   0; aaMtmam[ 3][18] =   0; aaMtmam[ 3][19] =  10;
16291     aaMtmam[ 4][ 0] =   0; aaMtmam[ 4][ 1] = 186; aaMtmam[ 4][ 2] =   0; aaMtmam[ 4][ 3] =   0; aaMtmam[ 4][ 4] =   0;
16292     aaMtmam[ 4][ 5] =   0; aaMtmam[ 4][ 6] =   0; aaMtmam[ 4][ 7] =   0; aaMtmam[ 4][ 8] = 305; aaMtmam[ 4][ 9] =  41;
16293     aaMtmam[ 4][10] =  27; aaMtmam[ 4][11] =   0; aaMtmam[ 4][12] =   0; aaMtmam[ 4][13] =   7; aaMtmam[ 4][14] =   0;
16294     aaMtmam[ 4][15] = 347; aaMtmam[ 4][16] = 114; aaMtmam[ 4][17] =  65; aaMtmam[ 4][18] = 530; aaMtmam[ 4][19] =   0;
16295     aaMtmam[ 5][ 0] =   0; aaMtmam[ 5][ 1] = 246; aaMtmam[ 5][ 2] =   8; aaMtmam[ 5][ 3] =  49; aaMtmam[ 5][ 4] =   0;
16296     aaMtmam[ 5][ 5] =   0; aaMtmam[ 5][ 6] = 274; aaMtmam[ 5][ 7] =   0; aaMtmam[ 5][ 8] = 550; aaMtmam[ 5][ 9] =   0;
16297     aaMtmam[ 5][10] =  20; aaMtmam[ 5][11] = 242; aaMtmam[ 5][12] =  22; aaMtmam[ 5][13] =   0; aaMtmam[ 5][14] =  51;
16298     aaMtmam[ 5][15] =  30; aaMtmam[ 5][16] =   0; aaMtmam[ 5][17] =   0; aaMtmam[ 5][18] =  54; aaMtmam[ 5][19] =  33;
16299     aaMtmam[ 6][ 0] =   0; aaMtmam[ 6][ 1] =   0; aaMtmam[ 6][ 2] =   0; aaMtmam[ 6][ 3] = 569; aaMtmam[ 6][ 4] =   0;
16300     aaMtmam[ 6][ 5] = 274; aaMtmam[ 6][ 6] =   0; aaMtmam[ 6][ 7] =  22; aaMtmam[ 6][ 8] =  22; aaMtmam[ 6][ 9] =   0;
16301     aaMtmam[ 6][10] =   0; aaMtmam[ 6][11] = 215; aaMtmam[ 6][12] =   0; aaMtmam[ 6][13] =   0; aaMtmam[ 6][14] =   0;
16302     aaMtmam[ 6][15] =  21; aaMtmam[ 6][16] =   4; aaMtmam[ 6][17] =   0; aaMtmam[ 6][18] =   0; aaMtmam[ 6][19] =  20;
16303     aaMtmam[ 7][ 0] =  78; aaMtmam[ 7][ 1] =  18; aaMtmam[ 7][ 2] =  47; aaMtmam[ 7][ 3] =  79; aaMtmam[ 7][ 4] =   0;
16304     aaMtmam[ 7][ 5] =   0; aaMtmam[ 7][ 6] =  22; aaMtmam[ 7][ 7] =   0; aaMtmam[ 7][ 8] =   0; aaMtmam[ 7][ 9] =   0;
16305     aaMtmam[ 7][10] =   0; aaMtmam[ 7][11] =   0; aaMtmam[ 7][12] =   0; aaMtmam[ 7][13] =   0; aaMtmam[ 7][14] =   0;
16306     aaMtmam[ 7][15] = 112; aaMtmam[ 7][16] =   0; aaMtmam[ 7][17] =   0; aaMtmam[ 7][18] =   1; aaMtmam[ 7][19] =   5;
16307     aaMtmam[ 8][ 0] =   8; aaMtmam[ 8][ 1] = 232; aaMtmam[ 8][ 2] = 458; aaMtmam[ 8][ 3] =  11; aaMtmam[ 8][ 4] = 305;
16308     aaMtmam[ 8][ 5] = 550; aaMtmam[ 8][ 6] =  22; aaMtmam[ 8][ 7] =   0; aaMtmam[ 8][ 8] =   0; aaMtmam[ 8][ 9] =   0;
16309     aaMtmam[ 8][10] =  26; aaMtmam[ 8][11] =   0; aaMtmam[ 8][12] =   0; aaMtmam[ 8][13] =   0; aaMtmam[ 8][14] =  53;
16310     aaMtmam[ 8][15] =  20; aaMtmam[ 8][16] =   1; aaMtmam[ 8][17] =   0; aaMtmam[ 8][18] =1525; aaMtmam[ 8][19] =   0;
16311     aaMtmam[ 9][ 0] =  75; aaMtmam[ 9][ 1] =   0; aaMtmam[ 9][ 2] =  19; aaMtmam[ 9][ 3] =   0; aaMtmam[ 9][ 4] =  41;
16312     aaMtmam[ 9][ 5] =   0; aaMtmam[ 9][ 6] =   0; aaMtmam[ 9][ 7] =   0; aaMtmam[ 9][ 8] =   0; aaMtmam[ 9][ 9] =   0;
16313     aaMtmam[ 9][10] = 232; aaMtmam[ 9][11] =   6; aaMtmam[ 9][12] = 378; aaMtmam[ 9][13] =  57; aaMtmam[ 9][14] =   5;
16314     aaMtmam[ 9][15] =   0; aaMtmam[ 9][16] = 360; aaMtmam[ 9][17] =   0; aaMtmam[ 9][18] =  16; aaMtmam[ 9][19] =2220;
16315     aaMtmam[10][ 0] =  21; aaMtmam[10][ 1] =   6; aaMtmam[10][ 2] =   0; aaMtmam[10][ 3] =   0; aaMtmam[10][ 4] =  27;
16316     aaMtmam[10][ 5] =  20; aaMtmam[10][ 6] =   0; aaMtmam[10][ 7] =   0; aaMtmam[10][ 8] =  26; aaMtmam[10][ 9] = 232;
16317     aaMtmam[10][10] =   0; aaMtmam[10][11] =   4; aaMtmam[10][12] = 609; aaMtmam[10][13] = 246; aaMtmam[10][14] =  43;
16318     aaMtmam[10][15] =  74; aaMtmam[10][16] =  34; aaMtmam[10][17] =  12; aaMtmam[10][18] =  25; aaMtmam[10][19] = 100;
16319     aaMtmam[11][ 0] =   0; aaMtmam[11][ 1] =  50; aaMtmam[11][ 2] = 408; aaMtmam[11][ 3] =   0; aaMtmam[11][ 4] =   0;
16320     aaMtmam[11][ 5] = 242; aaMtmam[11][ 6] = 215; aaMtmam[11][ 7] =   0; aaMtmam[11][ 8] =   0; aaMtmam[11][ 9] =   6;
16321     aaMtmam[11][10] =   4; aaMtmam[11][11] =   0; aaMtmam[11][12] =  59; aaMtmam[11][13] =   0; aaMtmam[11][14] =  18;
16322     aaMtmam[11][15] =  65; aaMtmam[11][16] =  50; aaMtmam[11][17] =   0; aaMtmam[11][18] =  67; aaMtmam[11][19] =   0;
16323     aaMtmam[12][ 0] =  76; aaMtmam[12][ 1] =   0; aaMtmam[12][ 2] =  21; aaMtmam[12][ 3] =   0; aaMtmam[12][ 4] =   0;
16324     aaMtmam[12][ 5] =  22; aaMtmam[12][ 6] =   0; aaMtmam[12][ 7] =   0; aaMtmam[12][ 8] =   0; aaMtmam[12][ 9] = 378;
16325     aaMtmam[12][10] = 609; aaMtmam[12][11] =  59; aaMtmam[12][12] =   0; aaMtmam[12][13] =  11; aaMtmam[12][14] =   0;
16326     aaMtmam[12][15] =  47; aaMtmam[12][16] = 691; aaMtmam[12][17] =  13; aaMtmam[12][18] =   0; aaMtmam[12][19] = 832;
16327     aaMtmam[13][ 0] =   0; aaMtmam[13][ 1] =   0; aaMtmam[13][ 2] =   6; aaMtmam[13][ 3] =   5; aaMtmam[13][ 4] =   7;
16328     aaMtmam[13][ 5] =   0; aaMtmam[13][ 6] =   0; aaMtmam[13][ 7] =   0; aaMtmam[13][ 8] =   0; aaMtmam[13][ 9] =  57;
16329     aaMtmam[13][10] = 246; aaMtmam[13][11] =   0; aaMtmam[13][12] =  11; aaMtmam[13][13] =   0; aaMtmam[13][14] =  17;
16330     aaMtmam[13][15] =  90; aaMtmam[13][16] =   8; aaMtmam[13][17] =   0; aaMtmam[13][18] = 682; aaMtmam[13][19] =   6;
16331     aaMtmam[14][ 0] =  53; aaMtmam[14][ 1] =   9; aaMtmam[14][ 2] =  33; aaMtmam[14][ 3] =   2; aaMtmam[14][ 4] =   0;
16332     aaMtmam[14][ 5] =  51; aaMtmam[14][ 6] =   0; aaMtmam[14][ 7] =   0; aaMtmam[14][ 8] =  53; aaMtmam[14][ 9] =   5;
16333     aaMtmam[14][10] =  43; aaMtmam[14][11] =  18; aaMtmam[14][12] =   0; aaMtmam[14][13] =  17; aaMtmam[14][14] =   0;
16334     aaMtmam[14][15] = 202; aaMtmam[14][16] =  78; aaMtmam[14][17] =   7; aaMtmam[14][18] =   8; aaMtmam[14][19] =   0;
16335     aaMtmam[15][ 0] = 342; aaMtmam[15][ 1] =   3; aaMtmam[15][ 2] = 446; aaMtmam[15][ 3] =  16; aaMtmam[15][ 4] = 347;
16336     aaMtmam[15][ 5] =  30; aaMtmam[15][ 6] =  21; aaMtmam[15][ 7] = 112; aaMtmam[15][ 8] =  20; aaMtmam[15][ 9] =   0;
16337     aaMtmam[15][10] =  74; aaMtmam[15][11] =  65; aaMtmam[15][12] =  47; aaMtmam[15][13] =  90; aaMtmam[15][14] = 202;
16338     aaMtmam[15][15] =   0; aaMtmam[15][16] = 614; aaMtmam[15][17] =  17; aaMtmam[15][18] = 107; aaMtmam[15][19] =   0;
16339     aaMtmam[16][ 0] = 681; aaMtmam[16][ 1] =   0; aaMtmam[16][ 2] = 110; aaMtmam[16][ 3] =   0; aaMtmam[16][ 4] = 114;
16340     aaMtmam[16][ 5] =   0; aaMtmam[16][ 6] =   4; aaMtmam[16][ 7] =   0; aaMtmam[16][ 8] =   1; aaMtmam[16][ 9] = 360;
16341     aaMtmam[16][10] =  34; aaMtmam[16][11] =  50; aaMtmam[16][12] = 691; aaMtmam[16][13] =   8; aaMtmam[16][14] =  78;
16342     aaMtmam[16][15] = 614; aaMtmam[16][16] =   0; aaMtmam[16][17] =   0; aaMtmam[16][18] =   0; aaMtmam[16][19] = 237;
16343     aaMtmam[17][ 0] =   5; aaMtmam[17][ 1] =  16; aaMtmam[17][ 2] =   6; aaMtmam[17][ 3] =   0; aaMtmam[17][ 4] =  65;
16344     aaMtmam[17][ 5] =   0; aaMtmam[17][ 6] =   0; aaMtmam[17][ 7] =   0; aaMtmam[17][ 8] =   0; aaMtmam[17][ 9] =   0;
16345     aaMtmam[17][10] =  12; aaMtmam[17][11] =   0; aaMtmam[17][12] =  13; aaMtmam[17][13] =   0; aaMtmam[17][14] =   7;
16346     aaMtmam[17][15] =  17; aaMtmam[17][16] =   0; aaMtmam[17][17] =   0; aaMtmam[17][18] =  14; aaMtmam[17][19] =   0;
16347     aaMtmam[18][ 0] =   0; aaMtmam[18][ 1] =   0; aaMtmam[18][ 2] = 156; aaMtmam[18][ 3] =   0; aaMtmam[18][ 4] = 530;
16348     aaMtmam[18][ 5] =  54; aaMtmam[18][ 6] =   0; aaMtmam[18][ 7] =   1; aaMtmam[18][ 8] =1525; aaMtmam[18][ 9] =  16;
16349     aaMtmam[18][10] =  25; aaMtmam[18][11] =  67; aaMtmam[18][12] =   0; aaMtmam[18][13] = 682; aaMtmam[18][14] =   8;
16350     aaMtmam[18][15] = 107; aaMtmam[18][16] =   0; aaMtmam[18][17] =  14; aaMtmam[18][18] =   0; aaMtmam[18][19] =   0;
16351     aaMtmam[19][ 0] = 398; aaMtmam[19][ 1] =   0; aaMtmam[19][ 2] =   0; aaMtmam[19][ 3] =  10; aaMtmam[19][ 4] =   0;
16352     aaMtmam[19][ 5] =  33; aaMtmam[19][ 6] =  20; aaMtmam[19][ 7] =   5; aaMtmam[19][ 8] =   0; aaMtmam[19][ 9] =2220;
16353     aaMtmam[19][10] = 100; aaMtmam[19][11] =   0; aaMtmam[19][12] = 832; aaMtmam[19][13] =   6; aaMtmam[19][14] =   0;
16354     aaMtmam[19][15] =   0; aaMtmam[19][16] = 237; aaMtmam[19][17] =   0; aaMtmam[19][18] =   0; aaMtmam[19][19] =   0;
16355 
16356     mtmamPi[ 0] = 0.0692;
16357     mtmamPi[ 1] = 0.0184;
16358     mtmamPi[ 2] = 0.0400;
16359     mtmamPi[ 3] = 0.0186;
16360     mtmamPi[ 4] = 0.0065;
16361     mtmamPi[ 5] = 0.0238;
16362     mtmamPi[ 6] = 0.0236;
16363     mtmamPi[ 7] = 0.0557;
16364     mtmamPi[ 8] = 0.0277;
16365     mtmamPi[ 9] = 0.0905;
16366     mtmamPi[10] = 0.1675;
16367     mtmamPi[11] = 0.0221;
16368     mtmamPi[12] = 0.0561;
16369     mtmamPi[13] = 0.0611;
16370     mtmamPi[14] = 0.0536;
16371     mtmamPi[15] = 0.0725;
16372     mtmamPi[16] = 0.0870;
16373     mtmamPi[17] = 0.0293;
16374     mtmamPi[18] = 0.0340;
16375     mtmamPi[19] = 0.0428;
16376 
16377     /* rtRev */
16378     aartREV[ 0][ 0] =   0; aartREV[ 1][ 0] =  34; aartREV[ 2][ 0] =  51; aartREV[ 3][ 0] =  10; aartREV[ 4][ 0] = 439;
16379     aartREV[ 5][ 0] =  32; aartREV[ 6][ 0] =  81; aartREV[ 7][ 0] = 135; aartREV[ 8][ 0] =  30; aartREV[ 9][ 0] =   1;
16380     aartREV[10][ 0] =  45; aartREV[11][ 0] =  38; aartREV[12][ 0] = 235; aartREV[13][ 0] =   1; aartREV[14][ 0] =  97;
16381     aartREV[15][ 0] = 460; aartREV[16][ 0] = 258; aartREV[17][ 0] =   5; aartREV[18][ 0] =  55; aartREV[19][ 0] = 197;
16382     aartREV[ 0][ 1] =  34; aartREV[ 1][ 1] =   0; aartREV[ 2][ 1] =  35; aartREV[ 3][ 1] =  30; aartREV[ 4][ 1] =  92;
16383     aartREV[ 5][ 1] = 221; aartREV[ 6][ 1] =  10; aartREV[ 7][ 1] =  41; aartREV[ 8][ 1] =  90; aartREV[ 9][ 1] =  24;
16384     aartREV[10][ 1] =  18; aartREV[11][ 1] = 593; aartREV[12][ 1] =  57; aartREV[13][ 1] =   7; aartREV[14][ 1] =  24;
16385     aartREV[15][ 1] = 102; aartREV[16][ 1] =  64; aartREV[17][ 1] =  13; aartREV[18][ 1] =  47; aartREV[19][ 1] =  29;
16386     aartREV[ 0][ 2] =  51; aartREV[ 1][ 2] =  35; aartREV[ 2][ 2] =   0; aartREV[ 3][ 2] = 384; aartREV[ 4][ 2] = 128;
16387     aartREV[ 5][ 2] = 236; aartREV[ 6][ 2] =  79; aartREV[ 7][ 2] =  94; aartREV[ 8][ 2] = 320; aartREV[ 9][ 2] =  35;
16388     aartREV[10][ 2] =  15; aartREV[11][ 2] = 123; aartREV[12][ 2] =   1; aartREV[13][ 2] =  49; aartREV[14][ 2] =  33;
16389     aartREV[15][ 2] = 294; aartREV[16][ 2] = 148; aartREV[17][ 2] =  16; aartREV[18][ 2] =  28; aartREV[19][ 2] =  21;
16390     aartREV[ 0][ 3] =  10; aartREV[ 1][ 3] =  30; aartREV[ 2][ 3] = 384; aartREV[ 3][ 3] =   0; aartREV[ 4][ 3] =   1;
16391     aartREV[ 5][ 3] =  78; aartREV[ 6][ 3] = 542; aartREV[ 7][ 3] =  61; aartREV[ 8][ 3] =  91; aartREV[ 9][ 3] =   1;
16392     aartREV[10][ 3] =   5; aartREV[11][ 3] =  20; aartREV[12][ 3] =   1; aartREV[13][ 3] =   1; aartREV[14][ 3] =  55;
16393     aartREV[15][ 3] = 136; aartREV[16][ 3] =  55; aartREV[17][ 3] =   1; aartREV[18][ 3] =   1; aartREV[19][ 3] =   6;
16394     aartREV[ 0][ 4] = 439; aartREV[ 1][ 4] =  92; aartREV[ 2][ 4] = 128; aartREV[ 3][ 4] =   1; aartREV[ 4][ 4] =   0;
16395     aartREV[ 5][ 4] =  70; aartREV[ 6][ 4] =   1; aartREV[ 7][ 4] =  48; aartREV[ 8][ 4] = 124; aartREV[ 9][ 4] = 104;
16396     aartREV[10][ 4] = 110; aartREV[11][ 4] =  16; aartREV[12][ 4] = 156; aartREV[13][ 4] =  70; aartREV[14][ 4] =   1;
16397     aartREV[15][ 4] =  75; aartREV[16][ 4] = 117; aartREV[17][ 4] =  55; aartREV[18][ 4] = 131; aartREV[19][ 4] = 295;
16398     aartREV[ 0][ 5] =  32; aartREV[ 1][ 5] = 221; aartREV[ 2][ 5] = 236; aartREV[ 3][ 5] =  78; aartREV[ 4][ 5] =  70;
16399     aartREV[ 5][ 5] =   0; aartREV[ 6][ 5] = 372; aartREV[ 7][ 5] =  18; aartREV[ 8][ 5] = 387; aartREV[ 9][ 5] =  33;
16400     aartREV[10][ 5] =  54; aartREV[11][ 5] = 309; aartREV[12][ 5] = 158; aartREV[13][ 5] =   1; aartREV[14][ 5] =  68;
16401     aartREV[15][ 5] = 225; aartREV[16][ 5] = 146; aartREV[17][ 5] =  10; aartREV[18][ 5] =  45; aartREV[19][ 5] =  36;
16402     aartREV[ 0][ 6] =  81; aartREV[ 1][ 6] =  10; aartREV[ 2][ 6] =  79; aartREV[ 3][ 6] = 542; aartREV[ 4][ 6] =   1;
16403     aartREV[ 5][ 6] = 372; aartREV[ 6][ 6] =   0; aartREV[ 7][ 6] =  70; aartREV[ 8][ 6] =  34; aartREV[ 9][ 6] =   1;
16404     aartREV[10][ 6] =  21; aartREV[11][ 6] = 141; aartREV[12][ 6] =   1; aartREV[13][ 6] =   1; aartREV[14][ 6] =  52;
16405     aartREV[15][ 6] =  95; aartREV[16][ 6] =  82; aartREV[17][ 6] =  17; aartREV[18][ 6] =   1; aartREV[19][ 6] =  35;
16406     aartREV[ 0][ 7] = 135; aartREV[ 1][ 7] =  41; aartREV[ 2][ 7] =  94; aartREV[ 3][ 7] =  61; aartREV[ 4][ 7] =  48;
16407     aartREV[ 5][ 7] =  18; aartREV[ 6][ 7] =  70; aartREV[ 7][ 7] =   0; aartREV[ 8][ 7] =  68; aartREV[ 9][ 7] =   1;
16408     aartREV[10][ 7] =   3; aartREV[11][ 7] =  30; aartREV[12][ 7] =  37; aartREV[13][ 7] =   7; aartREV[14][ 7] =  17;
16409     aartREV[15][ 7] = 152; aartREV[16][ 7] =   7; aartREV[17][ 7] =  23; aartREV[18][ 7] =  21; aartREV[19][ 7] =   3;
16410     aartREV[ 0][ 8] =  30; aartREV[ 1][ 8] =  90; aartREV[ 2][ 8] = 320; aartREV[ 3][ 8] =  91; aartREV[ 4][ 8] = 124;
16411     aartREV[ 5][ 8] = 387; aartREV[ 6][ 8] =  34; aartREV[ 7][ 8] =  68; aartREV[ 8][ 8] =   0; aartREV[ 9][ 8] =  34;
16412     aartREV[10][ 8] =  51; aartREV[11][ 8] =  76; aartREV[12][ 8] = 116; aartREV[13][ 8] = 141; aartREV[14][ 8] =  44;
16413     aartREV[15][ 8] = 183; aartREV[16][ 8] =  49; aartREV[17][ 8] =  48; aartREV[18][ 8] = 307; aartREV[19][ 8] =   1;
16414     aartREV[ 0][ 9] =   1; aartREV[ 1][ 9] =  24; aartREV[ 2][ 9] =  35; aartREV[ 3][ 9] =   1; aartREV[ 4][ 9] = 104;
16415     aartREV[ 5][ 9] =  33; aartREV[ 6][ 9] =   1; aartREV[ 7][ 9] =   1; aartREV[ 8][ 9] =  34; aartREV[ 9][ 9] =   0;
16416     aartREV[10][ 9] = 385; aartREV[11][ 9] =  34; aartREV[12][ 9] = 375; aartREV[13][ 9] =  64; aartREV[14][ 9] =  10;
16417     aartREV[15][ 9] =   4; aartREV[16][ 9] =  72; aartREV[17][ 9] =  39; aartREV[18][ 9] =  26; aartREV[19][ 9] =1048;
16418     aartREV[ 0][10] =  45; aartREV[ 1][10] =  18; aartREV[ 2][10] =  15; aartREV[ 3][10] =   5; aartREV[ 4][10] = 110;
16419     aartREV[ 5][10] =  54; aartREV[ 6][10] =  21; aartREV[ 7][10] =   3; aartREV[ 8][10] =  51; aartREV[ 9][10] = 385;
16420     aartREV[10][10] =   0; aartREV[11][10] =  23; aartREV[12][10] = 581; aartREV[13][10] = 179; aartREV[14][10] =  22;
16421     aartREV[15][10] =  24; aartREV[16][10] =  25; aartREV[17][10] =  47; aartREV[18][10] =  64; aartREV[19][10] = 112;
16422     aartREV[ 0][11] =  38; aartREV[ 1][11] = 593; aartREV[ 2][11] = 123; aartREV[ 3][11] =  20; aartREV[ 4][11] =  16;
16423     aartREV[ 5][11] = 309; aartREV[ 6][11] = 141; aartREV[ 7][11] =  30; aartREV[ 8][11] =  76; aartREV[ 9][11] =  34;
16424     aartREV[10][11] =  23; aartREV[11][11] =   0; aartREV[12][11] = 134; aartREV[13][11] =  14; aartREV[14][11] =  43;
16425     aartREV[15][11] =  77; aartREV[16][11] = 110; aartREV[17][11] =   6; aartREV[18][11] =   1; aartREV[19][11] =  19;
16426     aartREV[ 0][12] = 235; aartREV[ 1][12] =  57; aartREV[ 2][12] =   1; aartREV[ 3][12] =   1; aartREV[ 4][12] = 156;
16427     aartREV[ 5][12] = 158; aartREV[ 6][12] =   1; aartREV[ 7][12] =  37; aartREV[ 8][12] = 116; aartREV[ 9][12] = 375;
16428     aartREV[10][12] = 581; aartREV[11][12] = 134; aartREV[12][12] =   0; aartREV[13][12] = 247; aartREV[14][12] =   1;
16429     aartREV[15][12] =   1; aartREV[16][12] = 131; aartREV[17][12] = 111; aartREV[18][12] =  74; aartREV[19][12] = 236;
16430     aartREV[ 0][13] =   1; aartREV[ 1][13] =   7; aartREV[ 2][13] =  49; aartREV[ 3][13] =   1; aartREV[ 4][13] =  70;
16431     aartREV[ 5][13] =   1; aartREV[ 6][13] =   1; aartREV[ 7][13] =   7; aartREV[ 8][13] = 141; aartREV[ 9][13] =  64;
16432     aartREV[10][13] = 179; aartREV[11][13] =  14; aartREV[12][13] = 247; aartREV[13][13] =   0; aartREV[14][13] =  11;
16433     aartREV[15][13] =  20; aartREV[16][13] =  69; aartREV[17][13] = 182; aartREV[18][13] =1017; aartREV[19][13] =  92;
16434     aartREV[ 0][14] =  97; aartREV[ 1][14] =  24; aartREV[ 2][14] =  33; aartREV[ 3][14] =  55; aartREV[ 4][14] =   1;
16435     aartREV[ 5][14] =  68; aartREV[ 6][14] =  52; aartREV[ 7][14] =  17; aartREV[ 8][14] =  44; aartREV[ 9][14] =  10;
16436     aartREV[10][14] =  22; aartREV[11][14] =  43; aartREV[12][14] =   1; aartREV[13][14] =  11; aartREV[14][14] =   0;
16437     aartREV[15][14] = 134; aartREV[16][14] =  62; aartREV[17][14] =   9; aartREV[18][14] =  14; aartREV[19][14] =  25;
16438     aartREV[ 0][15] = 460; aartREV[ 1][15] = 102; aartREV[ 2][15] = 294; aartREV[ 3][15] = 136; aartREV[ 4][15] =  75;
16439     aartREV[ 5][15] = 225; aartREV[ 6][15] =  95; aartREV[ 7][15] = 152; aartREV[ 8][15] = 183; aartREV[ 9][15] =   4;
16440     aartREV[10][15] =  24; aartREV[11][15] =  77; aartREV[12][15] =   1; aartREV[13][15] =  20; aartREV[14][15] = 134;
16441     aartREV[15][15] =   0; aartREV[16][15] = 671; aartREV[17][15] =  14; aartREV[18][15] =  31; aartREV[19][15] =  39;
16442     aartREV[ 0][16] = 258; aartREV[ 1][16] =  64; aartREV[ 2][16] = 148; aartREV[ 3][16] =  55; aartREV[ 4][16] = 117;
16443     aartREV[ 5][16] = 146; aartREV[ 6][16] =  82; aartREV[ 7][16] =   7; aartREV[ 8][16] =  49; aartREV[ 9][16] =  72;
16444     aartREV[10][16] =  25; aartREV[11][16] = 110; aartREV[12][16] = 131; aartREV[13][16] =  69; aartREV[14][16] =  62;
16445     aartREV[15][16] = 671; aartREV[16][16] =   0; aartREV[17][16] =   1; aartREV[18][16] =  34; aartREV[19][16] = 196;
16446     aartREV[ 0][17] =   5; aartREV[ 1][17] =  13; aartREV[ 2][17] =  16; aartREV[ 3][17] =   1; aartREV[ 4][17] =  55;
16447     aartREV[ 5][17] =  10; aartREV[ 6][17] =  17; aartREV[ 7][17] =  23; aartREV[ 8][17] =  48; aartREV[ 9][17] =  39;
16448     aartREV[10][17] =  47; aartREV[11][17] =   6; aartREV[12][17] = 111; aartREV[13][17] = 182; aartREV[14][17] =   9;
16449     aartREV[15][17] =  14; aartREV[16][17] =   1; aartREV[17][17] =   0; aartREV[18][17] = 176; aartREV[19][17] =  26;
16450     aartREV[ 0][18] =  55; aartREV[ 1][18] =  47; aartREV[ 2][18] =  28; aartREV[ 3][18] =   1; aartREV[ 4][18] = 131;
16451     aartREV[ 5][18] =  45; aartREV[ 6][18] =   1; aartREV[ 7][18] =  21; aartREV[ 8][18] = 307; aartREV[ 9][18] =  26;
16452     aartREV[10][18] =  64; aartREV[11][18] =   1; aartREV[12][18] =  74; aartREV[13][18] =1017; aartREV[14][18] =  14;
16453     aartREV[15][18] =  31; aartREV[16][18] =  34; aartREV[17][18] = 176; aartREV[18][18] =   0; aartREV[19][18] =  59;
16454     aartREV[ 0][19] = 197; aartREV[ 1][19] =  29; aartREV[ 2][19] =  21; aartREV[ 3][19] =   6; aartREV[ 4][19] = 295;
16455     aartREV[ 5][19] =  36; aartREV[ 6][19] =  35; aartREV[ 7][19] =   3; aartREV[ 8][19] =   1; aartREV[ 9][19] =1048;
16456     aartREV[10][19] = 112; aartREV[11][19] =  19; aartREV[12][19] = 236; aartREV[13][19] =  92; aartREV[14][19] =  25;
16457     aartREV[15][19] =  39; aartREV[16][19] = 196; aartREV[17][19] =  26; aartREV[18][19] =  59; aartREV[19][19] =   0;
16458     rtrevPi[ 0] = 0.0646;
16459     rtrevPi[ 1] = 0.0453;
16460     rtrevPi[ 2] = 0.0376;
16461     rtrevPi[ 3] = 0.0422;
16462     rtrevPi[ 4] = 0.0114;
16463     rtrevPi[ 5] = 0.0606;
16464     rtrevPi[ 6] = 0.0607;
16465     rtrevPi[ 7] = 0.0639;
16466     rtrevPi[ 8] = 0.0273;
16467     rtrevPi[ 9] = 0.0679;
16468     rtrevPi[10] = 0.1018;
16469     rtrevPi[11] = 0.0751;
16470     rtrevPi[12] = 0.0150;
16471     rtrevPi[13] = 0.0287;
16472     rtrevPi[14] = 0.0681;
16473     rtrevPi[15] = 0.0488;
16474     rtrevPi[16] = 0.0622;
16475     rtrevPi[17] = 0.0251;
16476     rtrevPi[18] = 0.0318;
16477     rtrevPi[19] = 0.0619;
16478 
16479     /* wag */
16480     aaWAG[ 0][ 0] = 0.0000000; aaWAG[ 1][ 0] = 0.5515710; aaWAG[ 2][ 0] = 0.5098480; aaWAG[ 3][ 0] = 0.7389980; aaWAG[ 4][ 0] = 1.0270400;
16481     aaWAG[ 5][ 0] = 0.9085980; aaWAG[ 6][ 0] = 1.5828500; aaWAG[ 7][ 0] = 1.4167200; aaWAG[ 8][ 0] = 0.3169540; aaWAG[ 9][ 0] = 0.1933350;
16482     aaWAG[10][ 0] = 0.3979150; aaWAG[11][ 0] = 0.9062650; aaWAG[12][ 0] = 0.8934960; aaWAG[13][ 0] = 0.2104940; aaWAG[14][ 0] = 1.4385500;
16483     aaWAG[15][ 0] = 3.3707900; aaWAG[16][ 0] = 2.1211100; aaWAG[17][ 0] = 0.1131330; aaWAG[18][ 0] = 0.2407350; aaWAG[19][ 0] = 2.0060100;
16484     aaWAG[ 0][ 1] = 0.5515710; aaWAG[ 1][ 1] = 0.0000000; aaWAG[ 2][ 1] = 0.6353460; aaWAG[ 3][ 1] = 0.1473040; aaWAG[ 4][ 1] = 0.5281910;
16485     aaWAG[ 5][ 1] = 3.0355000; aaWAG[ 6][ 1] = 0.4391570; aaWAG[ 7][ 1] = 0.5846650; aaWAG[ 8][ 1] = 2.1371500; aaWAG[ 9][ 1] = 0.1869790;
16486     aaWAG[10][ 1] = 0.4976710; aaWAG[11][ 1] = 5.3514200; aaWAG[12][ 1] = 0.6831620; aaWAG[13][ 1] = 0.1027110; aaWAG[14][ 1] = 0.6794890;
16487     aaWAG[15][ 1] = 1.2241900; aaWAG[16][ 1] = 0.5544130; aaWAG[17][ 1] = 1.1639200; aaWAG[18][ 1] = 0.3815330; aaWAG[19][ 1] = 0.2518490;
16488     aaWAG[ 0][ 2] = 0.5098480; aaWAG[ 1][ 2] = 0.6353460; aaWAG[ 2][ 2] = 0.0000000; aaWAG[ 3][ 2] = 5.4294200; aaWAG[ 4][ 2] = 0.2652560;
16489     aaWAG[ 5][ 2] = 1.5436400; aaWAG[ 6][ 2] = 0.9471980; aaWAG[ 7][ 2] = 1.1255600; aaWAG[ 8][ 2] = 3.9562900; aaWAG[ 9][ 2] = 0.5542360;
16490     aaWAG[10][ 2] = 0.1315280; aaWAG[11][ 2] = 3.0120100; aaWAG[12][ 2] = 0.1982210; aaWAG[13][ 2] = 0.0961621; aaWAG[14][ 2] = 0.1950810;
16491     aaWAG[15][ 2] = 3.9742300; aaWAG[16][ 2] = 2.0300600; aaWAG[17][ 2] = 0.0719167; aaWAG[18][ 2] = 1.0860000; aaWAG[19][ 2] = 0.1962460;
16492     aaWAG[ 0][ 3] = 0.7389980; aaWAG[ 1][ 3] = 0.1473040; aaWAG[ 2][ 3] = 5.4294200; aaWAG[ 3][ 3] = 0.0000000; aaWAG[ 4][ 3] = 0.0302949;
16493     aaWAG[ 5][ 3] = 0.6167830; aaWAG[ 6][ 3] = 6.1741600; aaWAG[ 7][ 3] = 0.8655840; aaWAG[ 8][ 3] = 0.9306760; aaWAG[ 9][ 3] = 0.0394370;
16494     aaWAG[10][ 3] = 0.0848047; aaWAG[11][ 3] = 0.4798550; aaWAG[12][ 3] = 0.1037540; aaWAG[13][ 3] = 0.0467304; aaWAG[14][ 3] = 0.4239840;
16495     aaWAG[15][ 3] = 1.0717600; aaWAG[16][ 3] = 0.3748660; aaWAG[17][ 3] = 0.1297670; aaWAG[18][ 3] = 0.3257110; aaWAG[19][ 3] = 0.1523350;
16496     aaWAG[ 0][ 4] = 1.0270400; aaWAG[ 1][ 4] = 0.5281910; aaWAG[ 2][ 4] = 0.2652560; aaWAG[ 3][ 4] = 0.0302949; aaWAG[ 4][ 4] = 0.0000000;
16497     aaWAG[ 5][ 4] = 0.0988179; aaWAG[ 6][ 4] = 0.0213520; aaWAG[ 7][ 4] = 0.3066740; aaWAG[ 8][ 4] = 0.2489720; aaWAG[ 9][ 4] = 0.1701350;
16498     aaWAG[10][ 4] = 0.3842870; aaWAG[11][ 4] = 0.0740339; aaWAG[12][ 4] = 0.3904820; aaWAG[13][ 4] = 0.3980200; aaWAG[14][ 4] = 0.1094040;
16499     aaWAG[15][ 4] = 1.4076600; aaWAG[16][ 4] = 0.5129840; aaWAG[17][ 4] = 0.7170700; aaWAG[18][ 4] = 0.5438330; aaWAG[19][ 4] = 1.0021400;
16500     aaWAG[ 0][ 5] = 0.9085980; aaWAG[ 1][ 5] = 3.0355000; aaWAG[ 2][ 5] = 1.5436400; aaWAG[ 3][ 5] = 0.6167830; aaWAG[ 4][ 5] = 0.0988179;
16501     aaWAG[ 5][ 5] = 0.0000000; aaWAG[ 6][ 5] = 5.4694700; aaWAG[ 7][ 5] = 0.3300520; aaWAG[ 8][ 5] = 4.2941100; aaWAG[ 9][ 5] = 0.1139170;
16502     aaWAG[10][ 5] = 0.8694890; aaWAG[11][ 5] = 3.8949000; aaWAG[12][ 5] = 1.5452600; aaWAG[13][ 5] = 0.0999208; aaWAG[14][ 5] = 0.9333720;
16503     aaWAG[15][ 5] = 1.0288700; aaWAG[16][ 5] = 0.8579280; aaWAG[17][ 5] = 0.2157370; aaWAG[18][ 5] = 0.2277100; aaWAG[19][ 5] = 0.3012810;
16504     aaWAG[ 0][ 6] = 1.5828500; aaWAG[ 1][ 6] = 0.4391570; aaWAG[ 2][ 6] = 0.9471980; aaWAG[ 3][ 6] = 6.1741600; aaWAG[ 4][ 6] = 0.0213520;
16505     aaWAG[ 5][ 6] = 5.4694700; aaWAG[ 6][ 6] = 0.0000000; aaWAG[ 7][ 6] = 0.5677170; aaWAG[ 8][ 6] = 0.5700250; aaWAG[ 9][ 6] = 0.1273950;
16506     aaWAG[10][ 6] = 0.1542630; aaWAG[11][ 6] = 2.5844300; aaWAG[12][ 6] = 0.3151240; aaWAG[13][ 6] = 0.0811339; aaWAG[14][ 6] = 0.6823550;
16507     aaWAG[15][ 6] = 0.7049390; aaWAG[16][ 6] = 0.8227650; aaWAG[17][ 6] = 0.1565570; aaWAG[18][ 6] = 0.1963030; aaWAG[19][ 6] = 0.5887310;
16508     aaWAG[ 0][ 7] = 1.4167200; aaWAG[ 1][ 7] = 0.5846650; aaWAG[ 2][ 7] = 1.1255600; aaWAG[ 3][ 7] = 0.8655840; aaWAG[ 4][ 7] = 0.3066740;
16509     aaWAG[ 5][ 7] = 0.3300520; aaWAG[ 6][ 7] = 0.5677170; aaWAG[ 7][ 7] = 0.0000000; aaWAG[ 8][ 7] = 0.2494100; aaWAG[ 9][ 7] = 0.0304501;
16510     aaWAG[10][ 7] = 0.0613037; aaWAG[11][ 7] = 0.3735580; aaWAG[12][ 7] = 0.1741000; aaWAG[13][ 7] = 0.0499310; aaWAG[14][ 7] = 0.2435700;
16511     aaWAG[15][ 7] = 1.3418200; aaWAG[16][ 7] = 0.2258330; aaWAG[17][ 7] = 0.3369830; aaWAG[18][ 7] = 0.1036040; aaWAG[19][ 7] = 0.1872470;
16512     aaWAG[ 0][ 8] = 0.3169540; aaWAG[ 1][ 8] = 2.1371500; aaWAG[ 2][ 8] = 3.9562900; aaWAG[ 3][ 8] = 0.9306760; aaWAG[ 4][ 8] = 0.2489720;
16513     aaWAG[ 5][ 8] = 4.2941100; aaWAG[ 6][ 8] = 0.5700250; aaWAG[ 7][ 8] = 0.2494100; aaWAG[ 8][ 8] = 0.0000000; aaWAG[ 9][ 8] = 0.1381900;
16514     aaWAG[10][ 8] = 0.4994620; aaWAG[11][ 8] = 0.8904320; aaWAG[12][ 8] = 0.4041410; aaWAG[13][ 8] = 0.6793710; aaWAG[14][ 8] = 0.6961980;
16515     aaWAG[15][ 8] = 0.7401690; aaWAG[16][ 8] = 0.4733070; aaWAG[17][ 8] = 0.2625690; aaWAG[18][ 8] = 3.8734400; aaWAG[19][ 8] = 0.1183580;
16516     aaWAG[ 0][ 9] = 0.1933350; aaWAG[ 1][ 9] = 0.1869790; aaWAG[ 2][ 9] = 0.5542360; aaWAG[ 3][ 9] = 0.0394370; aaWAG[ 4][ 9] = 0.1701350;
16517     aaWAG[ 5][ 9] = 0.1139170; aaWAG[ 6][ 9] = 0.1273950; aaWAG[ 7][ 9] = 0.0304501; aaWAG[ 8][ 9] = 0.1381900; aaWAG[ 9][ 9] = 0.0000000;
16518     aaWAG[10][ 9] = 3.1709700; aaWAG[11][ 9] = 0.3238320; aaWAG[12][ 9] = 4.2574600; aaWAG[13][ 9] = 1.0594700; aaWAG[14][ 9] = 0.0999288;
16519     aaWAG[15][ 9] = 0.3194400; aaWAG[16][ 9] = 1.4581600; aaWAG[17][ 9] = 0.2124830; aaWAG[18][ 9] = 0.4201700; aaWAG[19][ 9] = 7.8213000;
16520     aaWAG[ 0][10] = 0.3979150; aaWAG[ 1][10] = 0.4976710; aaWAG[ 2][10] = 0.1315280; aaWAG[ 3][10] = 0.0848047; aaWAG[ 4][10] = 0.3842870;
16521     aaWAG[ 5][10] = 0.8694890; aaWAG[ 6][10] = 0.1542630; aaWAG[ 7][10] = 0.0613037; aaWAG[ 8][10] = 0.4994620; aaWAG[ 9][10] = 3.1709700;
16522     aaWAG[10][10] = 0.0000000; aaWAG[11][10] = 0.2575550; aaWAG[12][10] = 4.8540200; aaWAG[13][10] = 2.1151700; aaWAG[14][10] = 0.4158440;
16523     aaWAG[15][10] = 0.3447390; aaWAG[16][10] = 0.3266220; aaWAG[17][10] = 0.6653090; aaWAG[18][10] = 0.3986180; aaWAG[19][10] = 1.8003400;
16524     aaWAG[ 0][11] = 0.9062650; aaWAG[ 1][11] = 5.3514200; aaWAG[ 2][11] = 3.0120100; aaWAG[ 3][11] = 0.4798550; aaWAG[ 4][11] = 0.0740339;
16525     aaWAG[ 5][11] = 3.8949000; aaWAG[ 6][11] = 2.5844300; aaWAG[ 7][11] = 0.3735580; aaWAG[ 8][11] = 0.8904320; aaWAG[ 9][11] = 0.3238320;
16526     aaWAG[10][11] = 0.2575550; aaWAG[11][11] = 0.0000000; aaWAG[12][11] = 0.9342760; aaWAG[13][11] = 0.0888360; aaWAG[14][11] = 0.5568960;
16527     aaWAG[15][11] = 0.9671300; aaWAG[16][11] = 1.3869800; aaWAG[17][11] = 0.1375050; aaWAG[18][11] = 0.1332640; aaWAG[19][11] = 0.3054340;
16528     aaWAG[ 0][12] = 0.8934960; aaWAG[ 1][12] = 0.6831620; aaWAG[ 2][12] = 0.1982210; aaWAG[ 3][12] = 0.1037540; aaWAG[ 4][12] = 0.3904820;
16529     aaWAG[ 5][12] = 1.5452600; aaWAG[ 6][12] = 0.3151240; aaWAG[ 7][12] = 0.1741000; aaWAG[ 8][12] = 0.4041410; aaWAG[ 9][12] = 4.2574600;
16530     aaWAG[10][12] = 4.8540200; aaWAG[11][12] = 0.9342760; aaWAG[12][12] = 0.0000000; aaWAG[13][12] = 1.1906300; aaWAG[14][12] = 0.1713290;
16531     aaWAG[15][12] = 0.4939050; aaWAG[16][12] = 1.5161200; aaWAG[17][12] = 0.5157060; aaWAG[18][12] = 0.4284370; aaWAG[19][12] = 2.0584500;
16532     aaWAG[ 0][13] = 0.2104940; aaWAG[ 1][13] = 0.1027110; aaWAG[ 2][13] = 0.0961621; aaWAG[ 3][13] = 0.0467304; aaWAG[ 4][13] = 0.3980200;
16533     aaWAG[ 5][13] = 0.0999208; aaWAG[ 6][13] = 0.0811339; aaWAG[ 7][13] = 0.0499310; aaWAG[ 8][13] = 0.6793710; aaWAG[ 9][13] = 1.0594700;
16534     aaWAG[10][13] = 2.1151700; aaWAG[11][13] = 0.0888360; aaWAG[12][13] = 1.1906300; aaWAG[13][13] = 0.0000000; aaWAG[14][13] = 0.1614440;
16535     aaWAG[15][13] = 0.5459310; aaWAG[16][13] = 0.1719030; aaWAG[17][13] = 1.5296400; aaWAG[18][13] = 6.4542800; aaWAG[19][13] = 0.6498920;
16536     aaWAG[ 0][14] = 1.4385500; aaWAG[ 1][14] = 0.6794890; aaWAG[ 2][14] = 0.1950810; aaWAG[ 3][14] = 0.4239840; aaWAG[ 4][14] = 0.1094040;
16537     aaWAG[ 5][14] = 0.9333720; aaWAG[ 6][14] = 0.6823550; aaWAG[ 7][14] = 0.2435700; aaWAG[ 8][14] = 0.6961980; aaWAG[ 9][14] = 0.0999288;
16538     aaWAG[10][14] = 0.4158440; aaWAG[11][14] = 0.5568960; aaWAG[12][14] = 0.1713290; aaWAG[13][14] = 0.1614440; aaWAG[14][14] = 0.0000000;
16539     aaWAG[15][14] = 1.6132800; aaWAG[16][14] = 0.7953840; aaWAG[17][14] = 0.1394050; aaWAG[18][14] = 0.2160460; aaWAG[19][14] = 0.3148870;
16540     aaWAG[ 0][15] = 3.3707900; aaWAG[ 1][15] = 1.2241900; aaWAG[ 2][15] = 3.9742300; aaWAG[ 3][15] = 1.0717600; aaWAG[ 4][15] = 1.4076600;
16541     aaWAG[ 5][15] = 1.0288700; aaWAG[ 6][15] = 0.7049390; aaWAG[ 7][15] = 1.3418200; aaWAG[ 8][15] = 0.7401690; aaWAG[ 9][15] = 0.3194400;
16542     aaWAG[10][15] = 0.3447390; aaWAG[11][15] = 0.9671300; aaWAG[12][15] = 0.4939050; aaWAG[13][15] = 0.5459310; aaWAG[14][15] = 1.6132800;
16543     aaWAG[15][15] = 0.0000000; aaWAG[16][15] = 4.3780200; aaWAG[17][15] = 0.5237420; aaWAG[18][15] = 0.7869930; aaWAG[19][15] = 0.2327390;
16544     aaWAG[ 0][16] = 2.1211100; aaWAG[ 1][16] = 0.5544130; aaWAG[ 2][16] = 2.0300600; aaWAG[ 3][16] = 0.3748660; aaWAG[ 4][16] = 0.5129840;
16545     aaWAG[ 5][16] = 0.8579280; aaWAG[ 6][16] = 0.8227650; aaWAG[ 7][16] = 0.2258330; aaWAG[ 8][16] = 0.4733070; aaWAG[ 9][16] = 1.4581600;
16546     aaWAG[10][16] = 0.3266220; aaWAG[11][16] = 1.3869800; aaWAG[12][16] = 1.5161200; aaWAG[13][16] = 0.1719030; aaWAG[14][16] = 0.7953840;
16547     aaWAG[15][16] = 4.3780200; aaWAG[16][16] = 0.0000000; aaWAG[17][16] = 0.1108640; aaWAG[18][16] = 0.2911480; aaWAG[19][16] = 1.3882300;
16548     aaWAG[ 0][17] = 0.1131330; aaWAG[ 1][17] = 1.1639200; aaWAG[ 2][17] = 0.0719167; aaWAG[ 3][17] = 0.1297670; aaWAG[ 4][17] = 0.7170700;
16549     aaWAG[ 5][17] = 0.2157370; aaWAG[ 6][17] = 0.1565570; aaWAG[ 7][17] = 0.3369830; aaWAG[ 8][17] = 0.2625690; aaWAG[ 9][17] = 0.2124830;
16550     aaWAG[10][17] = 0.6653090; aaWAG[11][17] = 0.1375050; aaWAG[12][17] = 0.5157060; aaWAG[13][17] = 1.5296400; aaWAG[14][17] = 0.1394050;
16551     aaWAG[15][17] = 0.5237420; aaWAG[16][17] = 0.1108640; aaWAG[17][17] = 0.0000000; aaWAG[18][17] = 2.4853900; aaWAG[19][17] = 0.3653690;
16552     aaWAG[ 0][18] = 0.2407350; aaWAG[ 1][18] = 0.3815330; aaWAG[ 2][18] = 1.0860000; aaWAG[ 3][18] = 0.3257110; aaWAG[ 4][18] = 0.5438330;
16553     aaWAG[ 5][18] = 0.2277100; aaWAG[ 6][18] = 0.1963030; aaWAG[ 7][18] = 0.1036040; aaWAG[ 8][18] = 3.8734400; aaWAG[ 9][18] = 0.4201700;
16554     aaWAG[10][18] = 0.3986180; aaWAG[11][18] = 0.1332640; aaWAG[12][18] = 0.4284370; aaWAG[13][18] = 6.4542800; aaWAG[14][18] = 0.2160460;
16555     aaWAG[15][18] = 0.7869930; aaWAG[16][18] = 0.2911480; aaWAG[17][18] = 2.4853900; aaWAG[18][18] = 0.0000000; aaWAG[19][18] = 0.3147300;
16556     aaWAG[ 0][19] = 2.0060100; aaWAG[ 1][19] = 0.2518490; aaWAG[ 2][19] = 0.1962460; aaWAG[ 3][19] = 0.1523350; aaWAG[ 4][19] = 1.0021400;
16557     aaWAG[ 5][19] = 0.3012810; aaWAG[ 6][19] = 0.5887310; aaWAG[ 7][19] = 0.1872470; aaWAG[ 8][19] = 0.1183580; aaWAG[ 9][19] = 7.8213000;
16558     aaWAG[10][19] = 1.8003400; aaWAG[11][19] = 0.3054340; aaWAG[12][19] = 2.0584500; aaWAG[13][19] = 0.6498920; aaWAG[14][19] = 0.3148870;
16559     aaWAG[15][19] = 0.2327390; aaWAG[16][19] = 1.3882300; aaWAG[17][19] = 0.3653690; aaWAG[18][19] = 0.3147300; aaWAG[19][19] = 0.0000000;
16560     wagPi[ 0] = 0.08662790;
16561     wagPi[ 1] = 0.04397200;
16562     wagPi[ 2] = 0.03908940;
16563     wagPi[ 3] = 0.05704510;
16564     wagPi[ 4] = 0.01930780;
16565     wagPi[ 5] = 0.03672810;
16566     wagPi[ 6] = 0.05805890;
16567     wagPi[ 7] = 0.08325180;
16568     wagPi[ 8] = 0.02443130;
16569     wagPi[ 9] = 0.04846600;
16570     wagPi[10] = 0.08620970;
16571     wagPi[11] = 0.06202860;
16572     wagPi[12] = 0.01950273;
16573     wagPi[13] = 0.03843190;
16574     wagPi[14] = 0.04576310;
16575     wagPi[15] = 0.06951790;
16576     wagPi[16] = 0.06101270;
16577     wagPi[17] = 0.01438590;
16578     wagPi[18] = 0.03527420;
16579     wagPi[19] = 0.07089560;
16580 
16581     /* cpRev */
16582     aacpREV[ 0][ 0] =    0; aacpREV[ 0][ 1] =  105; aacpREV[ 0][ 2] =  227; aacpREV[ 0][ 3] =  175; aacpREV[ 0][ 4] =  669;
16583     aacpREV[ 0][ 5] =  157; aacpREV[ 0][ 6] =  499; aacpREV[ 0][ 7] =  665; aacpREV[ 0][ 8] =   66; aacpREV[ 0][ 9] =  145;
16584     aacpREV[ 0][10] =  197; aacpREV[ 0][11] =  236; aacpREV[ 0][12] =  185; aacpREV[ 0][13] =   68; aacpREV[ 0][14] =  490;
16585     aacpREV[ 0][15] = 2440; aacpREV[ 0][16] = 1340; aacpREV[ 0][17] =   14; aacpREV[ 0][18] =   56; aacpREV[ 0][19] =  968;
16586     aacpREV[ 1][ 0] =  105; aacpREV[ 1][ 1] =    0; aacpREV[ 1][ 2] =  357; aacpREV[ 1][ 3] =   43; aacpREV[ 1][ 4] =  823;
16587     aacpREV[ 1][ 5] = 1745; aacpREV[ 1][ 6] =  152; aacpREV[ 1][ 7] =  243; aacpREV[ 1][ 8] =  715; aacpREV[ 1][ 9] =  136;
16588     aacpREV[ 1][10] =  203; aacpREV[ 1][11] = 4482; aacpREV[ 1][12] =  125; aacpREV[ 1][13] =   53; aacpREV[ 1][14] =   87;
16589     aacpREV[ 1][15] =  385; aacpREV[ 1][16] =  314; aacpREV[ 1][17] =  230; aacpREV[ 1][18] =  323; aacpREV[ 1][19] =   92;
16590     aacpREV[ 2][ 0] =  227; aacpREV[ 2][ 1] =  357; aacpREV[ 2][ 2] =    0; aacpREV[ 2][ 3] = 4435; aacpREV[ 2][ 4] =  538;
16591     aacpREV[ 2][ 5] =  768; aacpREV[ 2][ 6] = 1055; aacpREV[ 2][ 7] =  653; aacpREV[ 2][ 8] = 1405; aacpREV[ 2][ 9] =  168;
16592     aacpREV[ 2][10] =  113; aacpREV[ 2][11] = 2430; aacpREV[ 2][12] =   61; aacpREV[ 2][13] =   97; aacpREV[ 2][14] =  173;
16593     aacpREV[ 2][15] = 2085; aacpREV[ 2][16] = 1393; aacpREV[ 2][17] =   40; aacpREV[ 2][18] =  754; aacpREV[ 2][19] =   83;
16594     aacpREV[ 3][ 0] =  175; aacpREV[ 3][ 1] =   43; aacpREV[ 3][ 2] = 4435; aacpREV[ 3][ 3] =    0; aacpREV[ 3][ 4] =   10;
16595     aacpREV[ 3][ 5] =  400; aacpREV[ 3][ 6] = 3691; aacpREV[ 3][ 7] =  431; aacpREV[ 3][ 8] =  331; aacpREV[ 3][ 9] =   10;
16596     aacpREV[ 3][10] =   10; aacpREV[ 3][11] =  412; aacpREV[ 3][12] =   47; aacpREV[ 3][13] =   22; aacpREV[ 3][14] =  170;
16597     aacpREV[ 3][15] =  590; aacpREV[ 3][16] =  266; aacpREV[ 3][17] =   18; aacpREV[ 3][18] =  281; aacpREV[ 3][19] =   75;
16598     aacpREV[ 4][ 0] =  669; aacpREV[ 4][ 1] =  823; aacpREV[ 4][ 2] =  538; aacpREV[ 4][ 3] =   10; aacpREV[ 4][ 4] =    0;
16599     aacpREV[ 4][ 5] =   10; aacpREV[ 4][ 6] =   10; aacpREV[ 4][ 7] =  303; aacpREV[ 4][ 8] =  441; aacpREV[ 4][ 9] =  280;
16600     aacpREV[ 4][10] =  396; aacpREV[ 4][11] =   48; aacpREV[ 4][12] =  159; aacpREV[ 4][13] =  726; aacpREV[ 4][14] =  285;
16601     aacpREV[ 4][15] = 2331; aacpREV[ 4][16] =  576; aacpREV[ 4][17] =  435; aacpREV[ 4][18] = 1466; aacpREV[ 4][19] =  592;
16602     aacpREV[ 5][ 0] =  157; aacpREV[ 5][ 1] = 1745; aacpREV[ 5][ 2] =  768; aacpREV[ 5][ 3] =  400; aacpREV[ 5][ 4] =   10;
16603     aacpREV[ 5][ 5] =    0; aacpREV[ 5][ 6] = 3122; aacpREV[ 5][ 7] =  133; aacpREV[ 5][ 8] = 1269; aacpREV[ 5][ 9] =   92;
16604     aacpREV[ 5][10] =  286; aacpREV[ 5][11] = 3313; aacpREV[ 5][12] =  202; aacpREV[ 5][13] =   10; aacpREV[ 5][14] =  323;
16605     aacpREV[ 5][15] =  396; aacpREV[ 5][16] =  241; aacpREV[ 5][17] =   53; aacpREV[ 5][18] =  391; aacpREV[ 5][19] =   54;
16606     aacpREV[ 6][ 0] =  499; aacpREV[ 6][ 1] =  152; aacpREV[ 6][ 2] = 1055; aacpREV[ 6][ 3] = 3691; aacpREV[ 6][ 4] =   10;
16607     aacpREV[ 6][ 5] = 3122; aacpREV[ 6][ 6] =    0; aacpREV[ 6][ 7] =  379; aacpREV[ 6][ 8] =  162; aacpREV[ 6][ 9] =  148;
16608     aacpREV[ 6][10] =   82; aacpREV[ 6][11] = 2629; aacpREV[ 6][12] =  113; aacpREV[ 6][13] =  145; aacpREV[ 6][14] =  185;
16609     aacpREV[ 6][15] =  568; aacpREV[ 6][16] =  369; aacpREV[ 6][17] =   63; aacpREV[ 6][18] =  142; aacpREV[ 6][19] =  200;
16610     aacpREV[ 7][ 0] =  665; aacpREV[ 7][ 1] =  243; aacpREV[ 7][ 2] =  653; aacpREV[ 7][ 3] =  431; aacpREV[ 7][ 4] =  303;
16611     aacpREV[ 7][ 5] =  133; aacpREV[ 7][ 6] =  379; aacpREV[ 7][ 7] =    0; aacpREV[ 7][ 8] =   19; aacpREV[ 7][ 9] =   40;
16612     aacpREV[ 7][10] =   20; aacpREV[ 7][11] =  263; aacpREV[ 7][12] =   21; aacpREV[ 7][13] =   25; aacpREV[ 7][14] =   28;
16613     aacpREV[ 7][15] =  691; aacpREV[ 7][16] =   92; aacpREV[ 7][17] =   82; aacpREV[ 7][18] =   10; aacpREV[ 7][19] =   91;
16614     aacpREV[ 8][ 0] =   66; aacpREV[ 8][ 1] =  715; aacpREV[ 8][ 2] = 1405; aacpREV[ 8][ 3] =  331; aacpREV[ 8][ 4] =  441;
16615     aacpREV[ 8][ 5] = 1269; aacpREV[ 8][ 6] =  162; aacpREV[ 8][ 7] =   19; aacpREV[ 8][ 8] =    0; aacpREV[ 8][ 9] =   29;
16616     aacpREV[ 8][10] =   66; aacpREV[ 8][11] =  305; aacpREV[ 8][12] =   10; aacpREV[ 8][13] =  127; aacpREV[ 8][14] =  152;
16617     aacpREV[ 8][15] =  303; aacpREV[ 8][16] =   32; aacpREV[ 8][17] =   69; aacpREV[ 8][18] = 1971; aacpREV[ 8][19] =   25;
16618     aacpREV[ 9][ 0] =  145; aacpREV[ 9][ 1] =  136; aacpREV[ 9][ 2] =  168; aacpREV[ 9][ 3] =   10; aacpREV[ 9][ 4] =  280;
16619     aacpREV[ 9][ 5] =   92; aacpREV[ 9][ 6] =  148; aacpREV[ 9][ 7] =   40; aacpREV[ 9][ 8] =   29; aacpREV[ 9][ 9] =    0;
16620     aacpREV[ 9][10] = 1745; aacpREV[ 9][11] =  345; aacpREV[ 9][12] = 1772; aacpREV[ 9][13] =  454; aacpREV[ 9][14] =  117;
16621     aacpREV[ 9][15] =  216; aacpREV[ 9][16] = 1040; aacpREV[ 9][17] =   42; aacpREV[ 9][18] =   89; aacpREV[ 9][19] = 4797;
16622     aacpREV[10][ 0] =  197; aacpREV[10][ 1] =  203; aacpREV[10][ 2] =  113; aacpREV[10][ 3] =   10; aacpREV[10][ 4] =  396;
16623     aacpREV[10][ 5] =  286; aacpREV[10][ 6] =   82; aacpREV[10][ 7] =   20; aacpREV[10][ 8] =   66; aacpREV[10][ 9] = 1745;
16624     aacpREV[10][10] =    0; aacpREV[10][11] =  218; aacpREV[10][12] = 1351; aacpREV[10][13] = 1268; aacpREV[10][14] =  219;
16625     aacpREV[10][15] =  516; aacpREV[10][16] =  156; aacpREV[10][17] =  159; aacpREV[10][18] =  189; aacpREV[10][19] =  865;
16626     aacpREV[11][ 0] =  236; aacpREV[11][ 1] = 4482; aacpREV[11][ 2] = 2430; aacpREV[11][ 3] =  412; aacpREV[11][ 4] =   48;
16627     aacpREV[11][ 5] = 3313; aacpREV[11][ 6] = 2629; aacpREV[11][ 7] =  263; aacpREV[11][ 8] =  305; aacpREV[11][ 9] =  345;
16628     aacpREV[11][10] =  218; aacpREV[11][11] =    0; aacpREV[11][12] =  193; aacpREV[11][13] =   72; aacpREV[11][14] =  302;
16629     aacpREV[11][15] =  868; aacpREV[11][16] =  918; aacpREV[11][17] =   10; aacpREV[11][18] =  247; aacpREV[11][19] =  249;
16630     aacpREV[12][ 0] =  185; aacpREV[12][ 1] =  125; aacpREV[12][ 2] =   61; aacpREV[12][ 3] =   47; aacpREV[12][ 4] =  159;
16631     aacpREV[12][ 5] =  202; aacpREV[12][ 6] =  113; aacpREV[12][ 7] =   21; aacpREV[12][ 8] =   10; aacpREV[12][ 9] = 1772;
16632     aacpREV[12][10] = 1351; aacpREV[12][11] =  193; aacpREV[12][12] =    0; aacpREV[12][13] =  327; aacpREV[12][14] =  100;
16633     aacpREV[12][15] =   93; aacpREV[12][16] =  645; aacpREV[12][17] =   86; aacpREV[12][18] =  215; aacpREV[12][19] =  475;
16634     aacpREV[13][ 0] =   68; aacpREV[13][ 1] =   53; aacpREV[13][ 2] =   97; aacpREV[13][ 3] =   22; aacpREV[13][ 4] =  726;
16635     aacpREV[13][ 5] =   10; aacpREV[13][ 6] =  145; aacpREV[13][ 7] =   25; aacpREV[13][ 8] =  127; aacpREV[13][ 9] =  454;
16636     aacpREV[13][10] = 1268; aacpREV[13][11] =   72; aacpREV[13][12] =  327; aacpREV[13][13] =    0; aacpREV[13][14] =   43;
16637     aacpREV[13][15] =  487; aacpREV[13][16] =  148; aacpREV[13][17] =  468; aacpREV[13][18] = 2370; aacpREV[13][19] =  317;
16638     aacpREV[14][ 0] =  490; aacpREV[14][ 1] =   87; aacpREV[14][ 2] =  173; aacpREV[14][ 3] =  170; aacpREV[14][ 4] =  285;
16639     aacpREV[14][ 5] =  323; aacpREV[14][ 6] =  185; aacpREV[14][ 7] =   28; aacpREV[14][ 8] =  152; aacpREV[14][ 9] =  117;
16640     aacpREV[14][10] =  219; aacpREV[14][11] =  302; aacpREV[14][12] =  100; aacpREV[14][13] =   43; aacpREV[14][14] =    0;
16641     aacpREV[14][15] = 1202; aacpREV[14][16] =  260; aacpREV[14][17] =   49; aacpREV[14][18] =   97; aacpREV[14][19] =  122;
16642     aacpREV[15][ 0] = 2440; aacpREV[15][ 1] =  385; aacpREV[15][ 2] = 2085; aacpREV[15][ 3] =  590; aacpREV[15][ 4] = 2331;
16643     aacpREV[15][ 5] =  396; aacpREV[15][ 6] =  568; aacpREV[15][ 7] =  691; aacpREV[15][ 8] =  303; aacpREV[15][ 9] =  216;
16644     aacpREV[15][10] =  516; aacpREV[15][11] =  868; aacpREV[15][12] =   93; aacpREV[15][13] =  487; aacpREV[15][14] = 1202;
16645     aacpREV[15][15] =    0; aacpREV[15][16] = 2151; aacpREV[15][17] =   73; aacpREV[15][18] =  522; aacpREV[15][19] =  167;
16646     aacpREV[16][ 0] = 1340; aacpREV[16][ 1] =  314; aacpREV[16][ 2] = 1393; aacpREV[16][ 3] =  266; aacpREV[16][ 4] =  576;
16647     aacpREV[16][ 5] =  241; aacpREV[16][ 6] =  369; aacpREV[16][ 7] =   92; aacpREV[16][ 8] =   32; aacpREV[16][ 9] = 1040;
16648     aacpREV[16][10] =  156; aacpREV[16][11] =  918; aacpREV[16][12] =  645; aacpREV[16][13] =  148; aacpREV[16][14] =  260;
16649     aacpREV[16][15] = 2151; aacpREV[16][16] =    0; aacpREV[16][17] =   29; aacpREV[16][18] =   71; aacpREV[16][19] =  760;
16650     aacpREV[17][ 0] =   14; aacpREV[17][ 1] =  230; aacpREV[17][ 2] =   40; aacpREV[17][ 3] =   18; aacpREV[17][ 4] =  435;
16651     aacpREV[17][ 5] =   53; aacpREV[17][ 6] =   63; aacpREV[17][ 7] =   82; aacpREV[17][ 8] =   69; aacpREV[17][ 9] =   42;
16652     aacpREV[17][10] =  159; aacpREV[17][11] =   10; aacpREV[17][12] =   86; aacpREV[17][13] =  468; aacpREV[17][14] =   49;
16653     aacpREV[17][15] =   73; aacpREV[17][16] =   29; aacpREV[17][17] =    0; aacpREV[17][18] =  346; aacpREV[17][19] =   10;
16654     aacpREV[18][ 0] =   56; aacpREV[18][ 1] =  323; aacpREV[18][ 2] =  754; aacpREV[18][ 3] =  281; aacpREV[18][ 4] = 1466;
16655     aacpREV[18][ 5] =  391; aacpREV[18][ 6] =  142; aacpREV[18][ 7] =   10; aacpREV[18][ 8] = 1971; aacpREV[18][ 9] =   89;
16656     aacpREV[18][10] =  189; aacpREV[18][11] =  247; aacpREV[18][12] =  215; aacpREV[18][13] = 2370; aacpREV[18][14] =   97;
16657     aacpREV[18][15] =  522; aacpREV[18][16] =   71; aacpREV[18][17] =  346; aacpREV[18][18] =    0; aacpREV[18][19] =  119;
16658     aacpREV[19][ 0] =  968; aacpREV[19][ 1] =   92; aacpREV[19][ 2] =   83; aacpREV[19][ 3] =   75; aacpREV[19][ 4] =  592;
16659     aacpREV[19][ 5] =   54; aacpREV[19][ 6] =  200; aacpREV[19][ 7] =   91; aacpREV[19][ 8] =   25; aacpREV[19][ 9] = 4797;
16660     aacpREV[19][10] =  865; aacpREV[19][11] =  249; aacpREV[19][12] =  475; aacpREV[19][13] =  317; aacpREV[19][14] =  122;
16661     aacpREV[19][15] =  167; aacpREV[19][16] =  760; aacpREV[19][17] =   10; aacpREV[19][18] =  119; aacpREV[19][19] =    0;
16662 
16663     cprevPi[0] = 0.076;
16664     cprevPi[1] = 0.062;
16665     cprevPi[2] = 0.041;
16666     cprevPi[3] = 0.037;
16667     cprevPi[4] = 0.009;
16668     cprevPi[5] = 0.038;
16669     cprevPi[6] = 0.049;
16670     cprevPi[7] = 0.084;
16671     cprevPi[8] = 0.025;
16672     cprevPi[9] = 0.081;
16673     cprevPi[10] = 0.101;
16674     cprevPi[11] = 0.050;
16675     cprevPi[12] = 0.022;
16676     cprevPi[13] = 0.051;
16677     cprevPi[14] = 0.043;
16678     cprevPi[15] = 0.062;
16679     cprevPi[16] = 0.054;
16680     cprevPi[17] = 0.018;
16681     cprevPi[18] = 0.031;
16682     cprevPi[19] = 0.066;
16683 
16684     /* VT model */
16685     aaVt[ 0][ 0] = 0.000000; aaVt[ 0][ 1] = 0.233108; aaVt[ 0][ 2] = 0.199097; aaVt[ 0][ 3] = 0.265145; aaVt[ 0][ 4] = 0.227333;
16686     aaVt[ 0][ 5] = 0.310084; aaVt[ 0][ 6] = 0.567957; aaVt[ 0][ 7] = 0.876213; aaVt[ 0][ 8] = 0.078692; aaVt[ 0][ 9] = 0.222972;
16687     aaVt[ 0][10] = 0.424630; aaVt[ 0][11] = 0.393245; aaVt[ 0][12] = 0.211550; aaVt[ 0][13] = 0.116646; aaVt[ 0][14] = 0.399143;
16688     aaVt[ 0][15] = 1.817198; aaVt[ 0][16] = 0.877877; aaVt[ 0][17] = 0.030309; aaVt[ 0][18] = 0.087061; aaVt[ 0][19] = 1.230985;
16689     aaVt[ 1][ 0] = 0.233108; aaVt[ 1][ 1] = 0.000000; aaVt[ 1][ 2] = 0.210797; aaVt[ 1][ 3] = 0.105191; aaVt[ 1][ 4] = 0.031726;
16690     aaVt[ 1][ 5] = 0.493763; aaVt[ 1][ 6] = 0.255240; aaVt[ 1][ 7] = 0.156945; aaVt[ 1][ 8] = 0.213164; aaVt[ 1][ 9] = 0.081510;
16691     aaVt[ 1][10] = 0.192364; aaVt[ 1][11] = 1.755838; aaVt[ 1][12] = 0.087930; aaVt[ 1][13] = 0.042569; aaVt[ 1][14] = 0.128480;
16692     aaVt[ 1][15] = 0.292327; aaVt[ 1][16] = 0.204109; aaVt[ 1][17] = 0.046417; aaVt[ 1][18] = 0.097010; aaVt[ 1][19] = 0.113146;
16693     aaVt[ 2][ 0] = 0.199097; aaVt[ 2][ 1] = 0.210797; aaVt[ 2][ 2] = 0.000000; aaVt[ 2][ 3] = 0.883422; aaVt[ 2][ 4] = 0.027495;
16694     aaVt[ 2][ 5] = 0.275700; aaVt[ 2][ 6] = 0.270417; aaVt[ 2][ 7] = 0.362028; aaVt[ 2][ 8] = 0.290006; aaVt[ 2][ 9] = 0.087225;
16695     aaVt[ 2][10] = 0.069245; aaVt[ 2][11] = 0.503060; aaVt[ 2][12] = 0.057420; aaVt[ 2][13] = 0.039769; aaVt[ 2][14] = 0.083956;
16696     aaVt[ 2][15] = 0.847049; aaVt[ 2][16] = 0.471268; aaVt[ 2][17] = 0.010459; aaVt[ 2][18] = 0.093268; aaVt[ 2][19] = 0.049824;
16697     aaVt[ 3][ 0] = 0.265145; aaVt[ 3][ 1] = 0.105191; aaVt[ 3][ 2] = 0.883422; aaVt[ 3][ 3] = 0.000000; aaVt[ 3][ 4] = 0.010313;
16698     aaVt[ 3][ 5] = 0.205842; aaVt[ 3][ 6] = 1.599461; aaVt[ 3][ 7] = 0.311718; aaVt[ 3][ 8] = 0.134252; aaVt[ 3][ 9] = 0.011720;
16699     aaVt[ 3][10] = 0.060863; aaVt[ 3][11] = 0.261101; aaVt[ 3][12] = 0.012182; aaVt[ 3][13] = 0.016577; aaVt[ 3][14] = 0.160063;
16700     aaVt[ 3][15] = 0.461519; aaVt[ 3][16] = 0.178197; aaVt[ 3][17] = 0.011393; aaVt[ 3][18] = 0.051664; aaVt[ 3][19] = 0.048769;
16701     aaVt[ 4][ 0] = 0.227333; aaVt[ 4][ 1] = 0.031726; aaVt[ 4][ 2] = 0.027495; aaVt[ 4][ 3] = 0.010313; aaVt[ 4][ 4] = 0.000000;
16702     aaVt[ 4][ 5] = 0.004315; aaVt[ 4][ 6] = 0.005321; aaVt[ 4][ 7] = 0.050876; aaVt[ 4][ 8] = 0.016695; aaVt[ 4][ 9] = 0.046398;
16703     aaVt[ 4][10] = 0.091709; aaVt[ 4][11] = 0.004067; aaVt[ 4][12] = 0.023690; aaVt[ 4][13] = 0.051127; aaVt[ 4][14] = 0.011137;
16704     aaVt[ 4][15] = 0.175270; aaVt[ 4][16] = 0.079511; aaVt[ 4][17] = 0.007732; aaVt[ 4][18] = 0.042823; aaVt[ 4][19] = 0.163831;
16705     aaVt[ 5][ 0] = 0.310084; aaVt[ 5][ 1] = 0.493763; aaVt[ 5][ 2] = 0.275700; aaVt[ 5][ 3] = 0.205842; aaVt[ 5][ 4] = 0.004315;
16706     aaVt[ 5][ 5] = 0.000000; aaVt[ 5][ 6] = 0.960976; aaVt[ 5][ 7] = 0.128660; aaVt[ 5][ 8] = 0.315521; aaVt[ 5][ 9] = 0.054602;
16707     aaVt[ 5][10] = 0.243530; aaVt[ 5][11] = 0.738208; aaVt[ 5][12] = 0.120801; aaVt[ 5][13] = 0.026235; aaVt[ 5][14] = 0.156570;
16708     aaVt[ 5][15] = 0.358017; aaVt[ 5][16] = 0.248992; aaVt[ 5][17] = 0.021248; aaVt[ 5][18] = 0.062544; aaVt[ 5][19] = 0.112027;
16709     aaVt[ 6][ 0] = 0.567957; aaVt[ 6][ 1] = 0.255240; aaVt[ 6][ 2] = 0.270417; aaVt[ 6][ 3] = 1.599461; aaVt[ 6][ 4] = 0.005321;
16710     aaVt[ 6][ 5] = 0.960976; aaVt[ 6][ 6] = 0.000000; aaVt[ 6][ 7] = 0.250447; aaVt[ 6][ 8] = 0.104458; aaVt[ 6][ 9] = 0.046589;
16711     aaVt[ 6][10] = 0.151924; aaVt[ 6][11] = 0.888630; aaVt[ 6][12] = 0.058643; aaVt[ 6][13] = 0.028168; aaVt[ 6][14] = 0.205134;
16712     aaVt[ 6][15] = 0.406035; aaVt[ 6][16] = 0.321028; aaVt[ 6][17] = 0.018844; aaVt[ 6][18] = 0.055200; aaVt[ 6][19] = 0.205868;
16713     aaVt[ 7][ 0] = 0.876213; aaVt[ 7][ 1] = 0.156945; aaVt[ 7][ 2] = 0.362028; aaVt[ 7][ 3] = 0.311718; aaVt[ 7][ 4] = 0.050876;
16714     aaVt[ 7][ 5] = 0.128660; aaVt[ 7][ 6] = 0.250447; aaVt[ 7][ 7] = 0.000000; aaVt[ 7][ 8] = 0.058131; aaVt[ 7][ 9] = 0.051089;
16715     aaVt[ 7][10] = 0.087056; aaVt[ 7][11] = 0.193243; aaVt[ 7][12] = 0.046560; aaVt[ 7][13] = 0.050143; aaVt[ 7][14] = 0.124492;
16716     aaVt[ 7][15] = 0.612843; aaVt[ 7][16] = 0.136266; aaVt[ 7][17] = 0.023990; aaVt[ 7][18] = 0.037568; aaVt[ 7][19] = 0.082579;
16717     aaVt[ 8][ 0] = 0.078692; aaVt[ 8][ 1] = 0.213164; aaVt[ 8][ 2] = 0.290006; aaVt[ 8][ 3] = 0.134252; aaVt[ 8][ 4] = 0.016695;
16718     aaVt[ 8][ 5] = 0.315521; aaVt[ 8][ 6] = 0.104458; aaVt[ 8][ 7] = 0.058131; aaVt[ 8][ 8] = 0.000000; aaVt[ 8][ 9] = 0.020039;
16719     aaVt[ 8][10] = 0.103552; aaVt[ 8][11] = 0.153323; aaVt[ 8][12] = 0.021157; aaVt[ 8][13] = 0.079807; aaVt[ 8][14] = 0.078892;
16720     aaVt[ 8][15] = 0.167406; aaVt[ 8][16] = 0.101117; aaVt[ 8][17] = 0.020009; aaVt[ 8][18] = 0.286027; aaVt[ 8][19] = 0.068575;
16721     aaVt[ 9][ 0] = 0.222972; aaVt[ 9][ 1] = 0.081510; aaVt[ 9][ 2] = 0.087225; aaVt[ 9][ 3] = 0.011720; aaVt[ 9][ 4] = 0.046398;
16722     aaVt[ 9][ 5] = 0.054602; aaVt[ 9][ 6] = 0.046589; aaVt[ 9][ 7] = 0.051089; aaVt[ 9][ 8] = 0.020039; aaVt[ 9][ 9] = 0.000000;
16723     aaVt[ 9][10] = 2.089890; aaVt[ 9][11] = 0.093181; aaVt[ 9][12] = 0.493845; aaVt[ 9][13] = 0.321020; aaVt[ 9][14] = 0.054797;
16724     aaVt[ 9][15] = 0.081567; aaVt[ 9][16] = 0.376588; aaVt[ 9][17] = 0.034954; aaVt[ 9][18] = 0.086237; aaVt[ 9][19] = 3.654430;
16725     aaVt[10][ 0] = 0.424630; aaVt[10][ 1] = 0.192364; aaVt[10][ 2] = 0.069245; aaVt[10][ 3] = 0.060863; aaVt[10][ 4] = 0.091709;
16726     aaVt[10][ 5] = 0.243530; aaVt[10][ 6] = 0.151924; aaVt[10][ 7] = 0.087056; aaVt[10][ 8] = 0.103552; aaVt[10][ 9] = 2.089890;
16727     aaVt[10][10] = 0.000000; aaVt[10][11] = 0.201204; aaVt[10][12] = 1.105667; aaVt[10][13] = 0.946499; aaVt[10][14] = 0.169784;
16728     aaVt[10][15] = 0.214977; aaVt[10][16] = 0.243227; aaVt[10][17] = 0.083439; aaVt[10][18] = 0.189842; aaVt[10][19] = 1.337571;
16729     aaVt[11][ 0] = 0.393245; aaVt[11][ 1] = 1.755838; aaVt[11][ 2] = 0.503060; aaVt[11][ 3] = 0.261101; aaVt[11][ 4] = 0.004067;
16730     aaVt[11][ 5] = 0.738208; aaVt[11][ 6] = 0.888630; aaVt[11][ 7] = 0.193243; aaVt[11][ 8] = 0.153323; aaVt[11][ 9] = 0.093181;
16731     aaVt[11][10] = 0.201204; aaVt[11][11] = 0.000000; aaVt[11][12] = 0.096474; aaVt[11][13] = 0.038261; aaVt[11][14] = 0.212302;
16732     aaVt[11][15] = 0.400072; aaVt[11][16] = 0.446646; aaVt[11][17] = 0.023321; aaVt[11][18] = 0.068689; aaVt[11][19] = 0.144587;
16733     aaVt[12][ 0] = 0.211550; aaVt[12][ 1] = 0.087930; aaVt[12][ 2] = 0.057420; aaVt[12][ 3] = 0.012182; aaVt[12][ 4] = 0.023690;
16734     aaVt[12][ 5] = 0.120801; aaVt[12][ 6] = 0.058643; aaVt[12][ 7] = 0.046560; aaVt[12][ 8] = 0.021157; aaVt[12][ 9] = 0.493845;
16735     aaVt[12][10] = 1.105667; aaVt[12][11] = 0.096474; aaVt[12][12] = 0.000000; aaVt[12][13] = 0.173052; aaVt[12][14] = 0.010363;
16736     aaVt[12][15] = 0.090515; aaVt[12][16] = 0.184609; aaVt[12][17] = 0.022019; aaVt[12][18] = 0.073223; aaVt[12][19] = 0.307309;
16737     aaVt[13][ 0] = 0.116646; aaVt[13][ 1] = 0.042569; aaVt[13][ 2] = 0.039769; aaVt[13][ 3] = 0.016577; aaVt[13][ 4] = 0.051127;
16738     aaVt[13][ 5] = 0.026235; aaVt[13][ 6] = 0.028168; aaVt[13][ 7] = 0.050143; aaVt[13][ 8] = 0.079807; aaVt[13][ 9] = 0.321020;
16739     aaVt[13][10] = 0.946499; aaVt[13][11] = 0.038261; aaVt[13][12] = 0.173052; aaVt[13][13] = 0.000000; aaVt[13][14] = 0.042564;
16740     aaVt[13][15] = 0.138119; aaVt[13][16] = 0.085870; aaVt[13][17] = 0.128050; aaVt[13][18] = 0.898663; aaVt[13][19] = 0.247329;
16741     aaVt[14][ 0] = 0.399143; aaVt[14][ 1] = 0.128480; aaVt[14][ 2] = 0.083956; aaVt[14][ 3] = 0.160063; aaVt[14][ 4] = 0.011137;
16742     aaVt[14][ 5] = 0.156570; aaVt[14][ 6] = 0.205134; aaVt[14][ 7] = 0.124492; aaVt[14][ 8] = 0.078892; aaVt[14][ 9] = 0.054797;
16743     aaVt[14][10] = 0.169784; aaVt[14][11] = 0.212302; aaVt[14][12] = 0.010363; aaVt[14][13] = 0.042564; aaVt[14][14] = 0.000000;
16744     aaVt[14][15] = 0.430431; aaVt[14][16] = 0.207143; aaVt[14][17] = 0.014584; aaVt[14][18] = 0.032043; aaVt[14][19] = 0.129315;
16745     aaVt[15][ 0] = 1.817198; aaVt[15][ 1] = 0.292327; aaVt[15][ 2] = 0.847049; aaVt[15][ 3] = 0.461519; aaVt[15][ 4] = 0.175270;
16746     aaVt[15][ 5] = 0.358017; aaVt[15][ 6] = 0.406035; aaVt[15][ 7] = 0.612843; aaVt[15][ 8] = 0.167406; aaVt[15][ 9] = 0.081567;
16747     aaVt[15][10] = 0.214977; aaVt[15][11] = 0.400072; aaVt[15][12] = 0.090515; aaVt[15][13] = 0.138119; aaVt[15][14] = 0.430431;
16748     aaVt[15][15] = 0.000000; aaVt[15][16] = 1.767766; aaVt[15][17] = 0.035933; aaVt[15][18] = 0.121979; aaVt[15][19] = 0.127700;
16749     aaVt[16][ 0] = 0.877877; aaVt[16][ 1] = 0.204109; aaVt[16][ 2] = 0.471268; aaVt[16][ 3] = 0.178197; aaVt[16][ 4] = 0.079511;
16750     aaVt[16][ 5] = 0.248992; aaVt[16][ 6] = 0.321028; aaVt[16][ 7] = 0.136266; aaVt[16][ 8] = 0.101117; aaVt[16][ 9] = 0.376588;
16751     aaVt[16][10] = 0.243227; aaVt[16][11] = 0.446646; aaVt[16][12] = 0.184609; aaVt[16][13] = 0.085870; aaVt[16][14] = 0.207143;
16752     aaVt[16][15] = 1.767766; aaVt[16][16] = 0.000000; aaVt[16][17] = 0.020437; aaVt[16][18] = 0.094617; aaVt[16][19] = 0.740372;
16753     aaVt[17][ 0] = 0.030309; aaVt[17][ 1] = 0.046417; aaVt[17][ 2] = 0.010459; aaVt[17][ 3] = 0.011393; aaVt[17][ 4] = 0.007732;
16754     aaVt[17][ 5] = 0.021248; aaVt[17][ 6] = 0.018844; aaVt[17][ 7] = 0.023990; aaVt[17][ 8] = 0.020009; aaVt[17][ 9] = 0.034954;
16755     aaVt[17][10] = 0.083439; aaVt[17][11] = 0.023321; aaVt[17][12] = 0.022019; aaVt[17][13] = 0.128050; aaVt[17][14] = 0.014584;
16756     aaVt[17][15] = 0.035933; aaVt[17][16] = 0.020437; aaVt[17][17] = 0.000000; aaVt[17][18] = 0.124746; aaVt[17][19] = 0.022134;
16757     aaVt[18][ 0] = 0.087061; aaVt[18][ 1] = 0.097010; aaVt[18][ 2] = 0.093268; aaVt[18][ 3] = 0.051664; aaVt[18][ 4] = 0.042823;
16758     aaVt[18][ 5] = 0.062544; aaVt[18][ 6] = 0.055200; aaVt[18][ 7] = 0.037568; aaVt[18][ 8] = 0.286027; aaVt[18][ 9] = 0.086237;
16759     aaVt[18][10] = 0.189842; aaVt[18][11] = 0.068689; aaVt[18][12] = 0.073223; aaVt[18][13] = 0.898663; aaVt[18][14] = 0.032043;
16760     aaVt[18][15] = 0.121979; aaVt[18][16] = 0.094617; aaVt[18][17] = 0.124746; aaVt[18][18] = 0.000000; aaVt[18][19] = 0.125733;
16761     aaVt[19][ 0] = 1.230985; aaVt[19][ 1] = 0.113146; aaVt[19][ 2] = 0.049824; aaVt[19][ 3] = 0.048769; aaVt[19][ 4] = 0.163831;
16762     aaVt[19][ 5] = 0.112027; aaVt[19][ 6] = 0.205868; aaVt[19][ 7] = 0.082579; aaVt[19][ 8] = 0.068575; aaVt[19][ 9] = 3.654430;
16763     aaVt[19][10] = 1.337571; aaVt[19][11] = 0.144587; aaVt[19][12] = 0.307309; aaVt[19][13] = 0.247329; aaVt[19][14] = 0.129315;
16764     aaVt[19][15] = 0.127700; aaVt[19][16] = 0.740372; aaVt[19][17] = 0.022134; aaVt[19][18] = 0.125733; aaVt[19][19] = 0.000000;
16765 
16766     vtPi[ 0] = 0.078837;
16767     vtPi[ 1] = 0.051238;
16768     vtPi[ 2] = 0.042313;
16769     vtPi[ 3] = 0.053066;
16770     vtPi[ 4] = 0.015175;
16771     vtPi[ 5] = 0.036713;
16772     vtPi[ 6] = 0.061924;
16773     vtPi[ 7] = 0.070852;
16774     vtPi[ 8] = 0.023082;
16775     vtPi[ 9] = 0.062056;
16776     vtPi[10] = 0.096371;
16777     vtPi[11] = 0.057324;
16778     vtPi[12] = 0.023771;
16779     vtPi[13] = 0.043296;
16780     vtPi[14] = 0.043911;
16781     vtPi[15] = 0.063403;
16782     vtPi[16] = 0.055897;
16783     vtPi[17] = 0.013272;
16784     vtPi[18] = 0.034399;
16785     vtPi[19] = 0.073101;
16786 
16787     /* Blosum62 */
16788     aaBlosum[ 0][ 0] = 0.000000000000; aaBlosum[ 0][ 1] = 0.735790389698; aaBlosum[ 0][ 2] = 0.485391055466; aaBlosum[ 0][ 3] = 0.543161820899; aaBlosum[ 0][ 4] = 1.459995310470;
16789     aaBlosum[ 0][ 5] = 1.199705704602; aaBlosum[ 0][ 6] = 1.170949042800; aaBlosum[ 0][ 7] = 1.955883574960; aaBlosum[ 0][ 8] = 0.716241444998; aaBlosum[ 0][ 9] = 0.605899003687;
16790     aaBlosum[ 0][10] = 0.800016530518; aaBlosum[ 0][11] = 1.295201266783; aaBlosum[ 0][12] = 1.253758266664; aaBlosum[ 0][13] = 0.492964679748; aaBlosum[ 0][14] = 1.173275900924;
16791     aaBlosum[ 0][15] = 4.325092687057; aaBlosum[ 0][16] = 1.729178019485; aaBlosum[ 0][17] = 0.465839367725; aaBlosum[ 0][18] = 0.718206697586; aaBlosum[ 0][19] = 2.187774522005;
16792     aaBlosum[ 1][ 0] = 0.735790389698; aaBlosum[ 1][ 1] = 0.000000000000; aaBlosum[ 1][ 2] = 1.297446705134; aaBlosum[ 1][ 3] = 0.500964408555; aaBlosum[ 1][ 4] = 0.227826574209;
16793     aaBlosum[ 1][ 5] = 3.020833610064; aaBlosum[ 1][ 6] = 1.360574190420; aaBlosum[ 1][ 7] = 0.418763308518; aaBlosum[ 1][ 8] = 1.456141166336; aaBlosum[ 1][ 9] = 0.232036445142;
16794     aaBlosum[ 1][10] = 0.622711669692; aaBlosum[ 1][11] = 5.411115141489; aaBlosum[ 1][12] = 0.983692987457; aaBlosum[ 1][13] = 0.371644693209; aaBlosum[ 1][14] = 0.448133661718;
16795     aaBlosum[ 1][15] = 1.122783104210; aaBlosum[ 1][16] = 0.914665954563; aaBlosum[ 1][17] = 0.426382310122; aaBlosum[ 1][18] = 0.720517441216; aaBlosum[ 1][19] = 0.438388343772;
16796     aaBlosum[ 2][ 0] = 0.485391055466; aaBlosum[ 2][ 1] = 1.297446705134; aaBlosum[ 2][ 2] = 0.000000000000; aaBlosum[ 2][ 3] = 3.180100048216; aaBlosum[ 2][ 4] = 0.397358949897;
16797     aaBlosum[ 2][ 5] = 1.839216146992; aaBlosum[ 2][ 6] = 1.240488508640; aaBlosum[ 2][ 7] = 1.355872344485; aaBlosum[ 2][ 8] = 2.414501434208; aaBlosum[ 2][ 9] = 0.283017326278;
16798     aaBlosum[ 2][10] = 0.211888159615; aaBlosum[ 2][11] = 1.593137043457; aaBlosum[ 2][12] = 0.648441278787; aaBlosum[ 2][13] = 0.354861249223; aaBlosum[ 2][14] = 0.494887043702;
16799     aaBlosum[ 2][15] = 2.904101656456; aaBlosum[ 2][16] = 1.898173634533; aaBlosum[ 2][17] = 0.191482046247; aaBlosum[ 2][18] = 0.538222519037; aaBlosum[ 2][19] = 0.312858797993;
16800     aaBlosum[ 3][ 0] = 0.543161820899; aaBlosum[ 3][ 1] = 0.500964408555; aaBlosum[ 3][ 2] = 3.180100048216; aaBlosum[ 3][ 3] = 0.000000000000; aaBlosum[ 3][ 4] = 0.240836614802;
16801     aaBlosum[ 3][ 5] = 1.190945703396; aaBlosum[ 3][ 6] = 3.761625208368; aaBlosum[ 3][ 7] = 0.798473248968; aaBlosum[ 3][ 8] = 0.778142664022; aaBlosum[ 3][ 9] = 0.418555732462;
16802     aaBlosum[ 3][10] = 0.218131577594; aaBlosum[ 3][11] = 1.032447924952; aaBlosum[ 3][12] = 0.222621897958; aaBlosum[ 3][13] = 0.281730694207; aaBlosum[ 3][14] = 0.730628272998;
16803     aaBlosum[ 3][15] = 1.582754142065; aaBlosum[ 3][16] = 0.934187509431; aaBlosum[ 3][17] = 0.145345046279; aaBlosum[ 3][18] = 0.261422208965; aaBlosum[ 3][19] = 0.258129289418;
16804     aaBlosum[ 4][ 0] = 1.459995310470; aaBlosum[ 4][ 1] = 0.227826574209; aaBlosum[ 4][ 2] = 0.397358949897; aaBlosum[ 4][ 3] = 0.240836614802; aaBlosum[ 4][ 4] = 0.000000000000;
16805     aaBlosum[ 4][ 5] = 0.329801504630; aaBlosum[ 4][ 6] = 0.140748891814; aaBlosum[ 4][ 7] = 0.418203192284; aaBlosum[ 4][ 8] = 0.354058109831; aaBlosum[ 4][ 9] = 0.774894022794;
16806     aaBlosum[ 4][10] = 0.831842640142; aaBlosum[ 4][11] = 0.285078800906; aaBlosum[ 4][12] = 0.767688823480; aaBlosum[ 4][13] = 0.441337471187; aaBlosum[ 4][14] = 0.356008498769;
16807     aaBlosum[ 4][15] = 1.197188415094; aaBlosum[ 4][16] = 1.119831358516; aaBlosum[ 4][17] = 0.527664418872; aaBlosum[ 4][18] = 0.470237733696; aaBlosum[ 4][19] = 1.116352478606;
16808     aaBlosum[ 5][ 0] = 1.199705704602; aaBlosum[ 5][ 1] = 3.020833610064; aaBlosum[ 5][ 2] = 1.839216146992; aaBlosum[ 5][ 3] = 1.190945703396; aaBlosum[ 5][ 4] = 0.329801504630;
16809     aaBlosum[ 5][ 5] = 0.000000000000; aaBlosum[ 5][ 6] = 5.528919177928; aaBlosum[ 5][ 7] = 0.609846305383; aaBlosum[ 5][ 8] = 2.435341131140; aaBlosum[ 5][ 9] = 0.236202451204;
16810     aaBlosum[ 5][10] = 0.580737093181; aaBlosum[ 5][11] = 3.945277674515; aaBlosum[ 5][12] = 2.494896077113; aaBlosum[ 5][13] = 0.144356959750; aaBlosum[ 5][14] = 0.858570575674;
16811     aaBlosum[ 5][15] = 1.934870924596; aaBlosum[ 5][16] = 1.277480294596; aaBlosum[ 5][17] = 0.758653808642; aaBlosum[ 5][18] = 0.958989742850; aaBlosum[ 5][19] = 0.530785790125;
16812     aaBlosum[ 6][ 0] = 1.170949042800; aaBlosum[ 6][ 1] = 1.360574190420; aaBlosum[ 6][ 2] = 1.240488508640; aaBlosum[ 6][ 3] = 3.761625208368; aaBlosum[ 6][ 4] = 0.140748891814;
16813     aaBlosum[ 6][ 5] = 5.528919177928; aaBlosum[ 6][ 6] = 0.000000000000; aaBlosum[ 6][ 7] = 0.423579992176; aaBlosum[ 6][ 8] = 1.626891056982; aaBlosum[ 6][ 9] = 0.186848046932;
16814     aaBlosum[ 6][10] = 0.372625175087; aaBlosum[ 6][11] = 2.802427151679; aaBlosum[ 6][12] = 0.555415397470; aaBlosum[ 6][13] = 0.291409084165; aaBlosum[ 6][14] = 0.926563934846;
16815     aaBlosum[ 6][15] = 1.769893238937; aaBlosum[ 6][16] = 1.071097236007; aaBlosum[ 6][17] = 0.407635648938; aaBlosum[ 6][18] = 0.596719300346; aaBlosum[ 6][19] = 0.524253846338;
16816     aaBlosum[ 7][ 0] = 1.955883574960; aaBlosum[ 7][ 1] = 0.418763308518; aaBlosum[ 7][ 2] = 1.355872344485; aaBlosum[ 7][ 3] = 0.798473248968; aaBlosum[ 7][ 4] = 0.418203192284;
16817     aaBlosum[ 7][ 5] = 0.609846305383; aaBlosum[ 7][ 6] = 0.423579992176; aaBlosum[ 7][ 7] = 0.000000000000; aaBlosum[ 7][ 8] = 0.539859124954; aaBlosum[ 7][ 9] = 0.189296292376;
16818     aaBlosum[ 7][10] = 0.217721159236; aaBlosum[ 7][11] = 0.752042440303; aaBlosum[ 7][12] = 0.459436173579; aaBlosum[ 7][13] = 0.368166464453; aaBlosum[ 7][14] = 0.504086599527;
16819     aaBlosum[ 7][15] = 1.509326253224; aaBlosum[ 7][16] = 0.641436011405; aaBlosum[ 7][17] = 0.508358924638; aaBlosum[ 7][18] = 0.308055737035; aaBlosum[ 7][19] = 0.253340790190;
16820     aaBlosum[ 8][ 0] = 0.716241444998; aaBlosum[ 8][ 1] = 1.456141166336; aaBlosum[ 8][ 2] = 2.414501434208; aaBlosum[ 8][ 3] = 0.778142664022; aaBlosum[ 8][ 4] = 0.354058109831;
16821     aaBlosum[ 8][ 5] = 2.435341131140; aaBlosum[ 8][ 6] = 1.626891056982; aaBlosum[ 8][ 7] = 0.539859124954; aaBlosum[ 8][ 8] = 0.000000000000; aaBlosum[ 8][ 9] = 0.252718447885;
16822     aaBlosum[ 8][10] = 0.348072209797; aaBlosum[ 8][11] = 1.022507035889; aaBlosum[ 8][12] = 0.984311525359; aaBlosum[ 8][13] = 0.714533703928; aaBlosum[ 8][14] = 0.527007339151;
16823     aaBlosum[ 8][15] = 1.117029762910; aaBlosum[ 8][16] = 0.585407090225; aaBlosum[ 8][17] = 0.301248600780; aaBlosum[ 8][18] = 4.218953969389; aaBlosum[ 8][19] = 0.201555971750;
16824     aaBlosum[ 9][ 0] = 0.605899003687; aaBlosum[ 9][ 1] = 0.232036445142; aaBlosum[ 9][ 2] = 0.283017326278; aaBlosum[ 9][ 3] = 0.418555732462; aaBlosum[ 9][ 4] = 0.774894022794;
16825     aaBlosum[ 9][ 5] = 0.236202451204; aaBlosum[ 9][ 6] = 0.186848046932; aaBlosum[ 9][ 7] = 0.189296292376; aaBlosum[ 9][ 8] = 0.252718447885; aaBlosum[ 9][ 9] = 0.000000000000;
16826     aaBlosum[ 9][10] = 3.890963773304; aaBlosum[ 9][11] = 0.406193586642; aaBlosum[ 9][12] = 3.364797763104; aaBlosum[ 9][13] = 1.517359325954; aaBlosum[ 9][14] = 0.388355409206;
16827     aaBlosum[ 9][15] = 0.357544412460; aaBlosum[ 9][16] = 1.179091197260; aaBlosum[ 9][17] = 0.341985787540; aaBlosum[ 9][18] = 0.674617093228; aaBlosum[ 9][19] = 8.311839405458;
16828     aaBlosum[10][ 0] = 0.800016530518; aaBlosum[10][ 1] = 0.622711669692; aaBlosum[10][ 2] = 0.211888159615; aaBlosum[10][ 3] = 0.218131577594; aaBlosum[10][ 4] = 0.831842640142;
16829     aaBlosum[10][ 5] = 0.580737093181; aaBlosum[10][ 6] = 0.372625175087; aaBlosum[10][ 7] = 0.217721159236; aaBlosum[10][ 8] = 0.348072209797; aaBlosum[10][ 9] = 3.890963773304;
16830     aaBlosum[10][10] = 0.000000000000; aaBlosum[10][11] = 0.445570274261; aaBlosum[10][12] = 6.030559379572; aaBlosum[10][13] = 2.064839703237; aaBlosum[10][14] = 0.374555687471;
16831     aaBlosum[10][15] = 0.352969184527; aaBlosum[10][16] = 0.915259857694; aaBlosum[10][17] = 0.691474634600; aaBlosum[10][18] = 0.811245856323; aaBlosum[10][19] = 2.231405688913;
16832     aaBlosum[11][ 0] = 1.295201266783; aaBlosum[11][ 1] = 5.411115141489; aaBlosum[11][ 2] = 1.593137043457; aaBlosum[11][ 3] = 1.032447924952; aaBlosum[11][ 4] = 0.285078800906;
16833     aaBlosum[11][ 5] = 3.945277674515; aaBlosum[11][ 6] = 2.802427151679; aaBlosum[11][ 7] = 0.752042440303; aaBlosum[11][ 8] = 1.022507035889; aaBlosum[11][ 9] = 0.406193586642;
16834     aaBlosum[11][10] = 0.445570274261; aaBlosum[11][11] = 0.000000000000; aaBlosum[11][12] = 1.073061184332; aaBlosum[11][13] = 0.266924750511; aaBlosum[11][14] = 1.047383450722;
16835     aaBlosum[11][15] = 1.752165917819; aaBlosum[11][16] = 1.303875200799; aaBlosum[11][17] = 0.332243040634; aaBlosum[11][18] = 0.717993486900; aaBlosum[11][19] = 0.498138475304;
16836     aaBlosum[12][ 0] = 1.253758266664; aaBlosum[12][ 1] = 0.983692987457; aaBlosum[12][ 2] = 0.648441278787; aaBlosum[12][ 3] = 0.222621897958; aaBlosum[12][ 4] = 0.767688823480;
16837     aaBlosum[12][ 5] = 2.494896077113; aaBlosum[12][ 6] = 0.555415397470; aaBlosum[12][ 7] = 0.459436173579; aaBlosum[12][ 8] = 0.984311525359; aaBlosum[12][ 9] = 3.364797763104;
16838     aaBlosum[12][10] = 6.030559379572; aaBlosum[12][11] = 1.073061184332; aaBlosum[12][12] = 0.000000000000; aaBlosum[12][13] = 1.773855168830; aaBlosum[12][14] = 0.454123625103;
16839     aaBlosum[12][15] = 0.918723415746; aaBlosum[12][16] = 1.488548053722; aaBlosum[12][17] = 0.888101098152; aaBlosum[12][18] = 0.951682162246; aaBlosum[12][19] = 2.575850755315;
16840     aaBlosum[13][ 0] = 0.492964679748; aaBlosum[13][ 1] = 0.371644693209; aaBlosum[13][ 2] = 0.354861249223; aaBlosum[13][ 3] = 0.281730694207; aaBlosum[13][ 4] = 0.441337471187;
16841     aaBlosum[13][ 5] = 0.144356959750; aaBlosum[13][ 6] = 0.291409084165; aaBlosum[13][ 7] = 0.368166464453; aaBlosum[13][ 8] = 0.714533703928; aaBlosum[13][ 9] = 1.517359325954;
16842     aaBlosum[13][10] = 2.064839703237; aaBlosum[13][11] = 0.266924750511; aaBlosum[13][12] = 1.773855168830; aaBlosum[13][13] = 0.000000000000; aaBlosum[13][14] = 0.233597909629;
16843     aaBlosum[13][15] = 0.540027644824; aaBlosum[13][16] = 0.488206118793; aaBlosum[13][17] = 2.074324893497; aaBlosum[13][18] = 6.747260430801; aaBlosum[13][19] = 0.838119610178;
16844     aaBlosum[14][ 0] = 1.173275900924; aaBlosum[14][ 1] = 0.448133661718; aaBlosum[14][ 2] = 0.494887043702; aaBlosum[14][ 3] = 0.730628272998; aaBlosum[14][ 4] = 0.356008498769;
16845     aaBlosum[14][ 5] = 0.858570575674; aaBlosum[14][ 6] = 0.926563934846; aaBlosum[14][ 7] = 0.504086599527; aaBlosum[14][ 8] = 0.527007339151; aaBlosum[14][ 9] = 0.388355409206;
16846     aaBlosum[14][10] = 0.374555687471; aaBlosum[14][11] = 1.047383450722; aaBlosum[14][12] = 0.454123625103; aaBlosum[14][13] = 0.233597909629; aaBlosum[14][14] = 0.000000000000;
16847     aaBlosum[14][15] = 1.169129577716; aaBlosum[14][16] = 1.005451683149; aaBlosum[14][17] = 0.252214830027; aaBlosum[14][18] = 0.369405319355; aaBlosum[14][19] = 0.496908410676;
16848     aaBlosum[15][ 0] = 4.325092687057; aaBlosum[15][ 1] = 1.122783104210; aaBlosum[15][ 2] = 2.904101656456; aaBlosum[15][ 3] = 1.582754142065; aaBlosum[15][ 4] = 1.197188415094;
16849     aaBlosum[15][ 5] = 1.934870924596; aaBlosum[15][ 6] = 1.769893238937; aaBlosum[15][ 7] = 1.509326253224; aaBlosum[15][ 8] = 1.117029762910; aaBlosum[15][ 9] = 0.357544412460;
16850     aaBlosum[15][10] = 0.352969184527; aaBlosum[15][11] = 1.752165917819; aaBlosum[15][12] = 0.918723415746; aaBlosum[15][13] = 0.540027644824; aaBlosum[15][14] = 1.169129577716;
16851     aaBlosum[15][15] = 0.000000000000; aaBlosum[15][16] = 5.151556292270; aaBlosum[15][17] = 0.387925622098; aaBlosum[15][18] = 0.796751520761; aaBlosum[15][19] = 0.561925457442;
16852     aaBlosum[16][ 0] = 1.729178019485; aaBlosum[16][ 1] = 0.914665954563; aaBlosum[16][ 2] = 1.898173634533; aaBlosum[16][ 3] = 0.934187509431; aaBlosum[16][ 4] = 1.119831358516;
16853     aaBlosum[16][ 5] = 1.277480294596; aaBlosum[16][ 6] = 1.071097236007; aaBlosum[16][ 7] = 0.641436011405; aaBlosum[16][ 8] = 0.585407090225; aaBlosum[16][ 9] = 1.179091197260;
16854     aaBlosum[16][10] = 0.915259857694; aaBlosum[16][11] = 1.303875200799; aaBlosum[16][12] = 1.488548053722; aaBlosum[16][13] = 0.488206118793; aaBlosum[16][14] = 1.005451683149;
16855     aaBlosum[16][15] = 5.151556292270; aaBlosum[16][16] = 0.000000000000; aaBlosum[16][17] = 0.513128126891; aaBlosum[16][18] = 0.801010243199; aaBlosum[16][19] = 2.253074051176;
16856     aaBlosum[17][ 0] = 0.465839367725; aaBlosum[17][ 1] = 0.426382310122; aaBlosum[17][ 2] = 0.191482046247; aaBlosum[17][ 3] = 0.145345046279; aaBlosum[17][ 4] = 0.527664418872;
16857     aaBlosum[17][ 5] = 0.758653808642; aaBlosum[17][ 6] = 0.407635648938; aaBlosum[17][ 7] = 0.508358924638; aaBlosum[17][ 8] = 0.301248600780; aaBlosum[17][ 9] = 0.341985787540;
16858     aaBlosum[17][10] = 0.691474634600; aaBlosum[17][11] = 0.332243040634; aaBlosum[17][12] = 0.888101098152; aaBlosum[17][13] = 2.074324893497; aaBlosum[17][14] = 0.252214830027;
16859     aaBlosum[17][15] = 0.387925622098; aaBlosum[17][16] = 0.513128126891; aaBlosum[17][17] = 0.000000000000; aaBlosum[17][18] = 4.054419006558; aaBlosum[17][19] = 0.266508731426;
16860     aaBlosum[18][ 0] = 0.718206697586; aaBlosum[18][ 1] = 0.720517441216; aaBlosum[18][ 2] = 0.538222519037; aaBlosum[18][ 3] = 0.261422208965; aaBlosum[18][ 4] = 0.470237733696;
16861     aaBlosum[18][ 5] = 0.958989742850; aaBlosum[18][ 6] = 0.596719300346; aaBlosum[18][ 7] = 0.308055737035; aaBlosum[18][ 8] = 4.218953969389; aaBlosum[18][ 9] = 0.674617093228;
16862     aaBlosum[18][10] = 0.811245856323; aaBlosum[18][11] = 0.717993486900; aaBlosum[18][12] = 0.951682162246; aaBlosum[18][13] = 6.747260430801; aaBlosum[18][14] = 0.369405319355;
16863     aaBlosum[18][15] = 0.796751520761; aaBlosum[18][16] = 0.801010243199; aaBlosum[18][17] = 4.054419006558; aaBlosum[18][18] = 0.000000000000; aaBlosum[18][19] = 1.000000000000;
16864     aaBlosum[19][ 0] = 2.187774522005; aaBlosum[19][ 1] = 0.438388343772; aaBlosum[19][ 2] = 0.312858797993; aaBlosum[19][ 3] = 0.258129289418; aaBlosum[19][ 4] = 1.116352478606;
16865     aaBlosum[19][ 5] = 0.530785790125; aaBlosum[19][ 6] = 0.524253846338; aaBlosum[19][ 7] = 0.253340790190; aaBlosum[19][ 8] = 0.201555971750; aaBlosum[19][ 9] = 8.311839405458;
16866     aaBlosum[19][10] = 2.231405688913; aaBlosum[19][11] = 0.498138475304; aaBlosum[19][12] = 2.575850755315; aaBlosum[19][13] = 0.838119610178; aaBlosum[19][14] = 0.496908410676;
16867     aaBlosum[19][15] = 0.561925457442; aaBlosum[19][16] = 2.253074051176; aaBlosum[19][17] = 0.266508731426; aaBlosum[19][18] = 1.000000000000; aaBlosum[19][19] = 0.000000000000;
16868 
16869     blosPi[ 0] = 0.074;
16870     blosPi[ 1] = 0.052;
16871     blosPi[ 2] = 0.045;
16872     blosPi[ 3] = 0.054;
16873     blosPi[ 4] = 0.025;
16874     blosPi[ 5] = 0.034;
16875     blosPi[ 6] = 0.054;
16876     blosPi[ 7] = 0.074;
16877     blosPi[ 8] = 0.026;
16878     blosPi[ 9] = 0.068;
16879     blosPi[10] = 0.099;
16880     blosPi[11] = 0.058;
16881     blosPi[12] = 0.025;
16882     blosPi[13] = 0.047;
16883     blosPi[14] = 0.039;
16884     blosPi[15] = 0.057;
16885     blosPi[16] = 0.051;
16886     blosPi[17] = 0.013;
16887     blosPi[18] = 0.032;
16888     blosPi[19] = 0.073;
16889 
16890     /* LG */
16891     aaLG[ 0][ 0] = 0.000000; aaLG[ 0][ 1] = 0.425093; aaLG[ 0][ 2] = 0.276818; aaLG[ 0][ 3] = 0.395144; aaLG[ 0][ 4] = 2.489084;
16892     aaLG[ 0][ 5] = 0.969894; aaLG[ 0][ 6] = 1.038545; aaLG[ 0][ 7] = 2.066040; aaLG[ 0][ 8] = 0.358858; aaLG[ 0][ 9] = 0.149830;
16893     aaLG[ 0][10] = 0.395337; aaLG[ 0][11] = 0.536518; aaLG[ 0][12] = 1.124035; aaLG[ 0][13] = 0.253701; aaLG[ 0][14] = 1.177651;
16894     aaLG[ 0][15] = 4.727182; aaLG[ 0][16] = 2.139501; aaLG[ 0][17] = 0.180717; aaLG[ 0][18] = 0.218959; aaLG[ 0][19] = 2.547870;
16895     aaLG[ 1][ 0] = 0.425093; aaLG[ 1][ 1] = 0.000000; aaLG[ 1][ 2] = 0.751878; aaLG[ 1][ 3] = 0.123954; aaLG[ 1][ 4] = 0.534551;
16896     aaLG[ 1][ 5] = 2.807908; aaLG[ 1][ 6] = 0.363970; aaLG[ 1][ 7] = 0.390192; aaLG[ 1][ 8] = 2.426601; aaLG[ 1][ 9] = 0.126991;
16897     aaLG[ 1][10] = 0.301848; aaLG[ 1][11] = 6.326067; aaLG[ 1][12] = 0.484133; aaLG[ 1][13] = 0.052722; aaLG[ 1][14] = 0.332533;
16898     aaLG[ 1][15] = 0.858151; aaLG[ 1][16] = 0.578987; aaLG[ 1][17] = 0.593607; aaLG[ 1][18] = 0.314440; aaLG[ 1][19] = 0.170887;
16899     aaLG[ 2][ 0] = 0.276818; aaLG[ 2][ 1] = 0.751878; aaLG[ 2][ 2] = 0.000000; aaLG[ 2][ 3] = 5.076149; aaLG[ 2][ 4] = 0.528768;
16900     aaLG[ 2][ 5] = 1.695752; aaLG[ 2][ 6] = 0.541712; aaLG[ 2][ 7] = 1.437645; aaLG[ 2][ 8] = 4.509238; aaLG[ 2][ 9] = 0.191503;
16901     aaLG[ 2][10] = 0.068427; aaLG[ 2][11] = 2.145078; aaLG[ 2][12] = 0.371004; aaLG[ 2][13] = 0.089525; aaLG[ 2][14] = 0.161787;
16902     aaLG[ 2][15] = 4.008358; aaLG[ 2][16] = 2.000679; aaLG[ 2][17] = 0.045376; aaLG[ 2][18] = 0.612025; aaLG[ 2][19] = 0.083688;
16903     aaLG[ 3][ 0] = 0.395144; aaLG[ 3][ 1] = 0.123954; aaLG[ 3][ 2] = 5.076149; aaLG[ 3][ 3] = 0.000000; aaLG[ 3][ 4] = 0.062556;
16904     aaLG[ 3][ 5] = 0.523386; aaLG[ 3][ 6] = 5.243870; aaLG[ 3][ 7] = 0.844926; aaLG[ 3][ 8] = 0.927114; aaLG[ 3][ 9] = 0.010690;
16905     aaLG[ 3][10] = 0.015076; aaLG[ 3][11] = 0.282959; aaLG[ 3][12] = 0.025548; aaLG[ 3][13] = 0.017416; aaLG[ 3][14] = 0.394456;
16906     aaLG[ 3][15] = 1.240275; aaLG[ 3][16] = 0.425860; aaLG[ 3][17] = 0.029890; aaLG[ 3][18] = 0.135107; aaLG[ 3][19] = 0.037967;
16907     aaLG[ 4][ 0] = 2.489084; aaLG[ 4][ 1] = 0.534551; aaLG[ 4][ 2] = 0.528768; aaLG[ 4][ 3] = 0.062556; aaLG[ 4][ 4] = 0.000000;
16908     aaLG[ 4][ 5] = 0.084808; aaLG[ 4][ 6] = 0.003499; aaLG[ 4][ 7] = 0.569265; aaLG[ 4][ 8] = 0.640543; aaLG[ 4][ 9] = 0.320627;
16909     aaLG[ 4][10] = 0.594007; aaLG[ 4][11] = 0.013266; aaLG[ 4][12] = 0.893680; aaLG[ 4][13] = 1.105251; aaLG[ 4][14] = 0.075382;
16910     aaLG[ 4][15] = 2.784478; aaLG[ 4][16] = 1.143480; aaLG[ 4][17] = 0.670128; aaLG[ 4][18] = 1.165532; aaLG[ 4][19] = 1.959291;
16911     aaLG[ 5][ 0] = 0.969894; aaLG[ 5][ 1] = 2.807908; aaLG[ 5][ 2] = 1.695752; aaLG[ 5][ 3] = 0.523386; aaLG[ 5][ 4] = 0.084808;
16912     aaLG[ 5][ 5] = 0.000000; aaLG[ 5][ 6] = 4.128591; aaLG[ 5][ 7] = 0.267959; aaLG[ 5][ 8] = 4.813505; aaLG[ 5][ 9] = 0.072854;
16913     aaLG[ 5][10] = 0.582457; aaLG[ 5][11] = 3.234294; aaLG[ 5][12] = 1.672569; aaLG[ 5][13] = 0.035855; aaLG[ 5][14] = 0.624294;
16914     aaLG[ 5][15] = 1.223828; aaLG[ 5][16] = 1.080136; aaLG[ 5][17] = 0.236199; aaLG[ 5][18] = 0.257336; aaLG[ 5][19] = 0.210332;
16915     aaLG[ 6][ 0] = 1.038545; aaLG[ 6][ 1] = 0.363970; aaLG[ 6][ 2] = 0.541712; aaLG[ 6][ 3] = 5.243870; aaLG[ 6][ 4] = 0.003499;
16916     aaLG[ 6][ 5] = 4.128591; aaLG[ 6][ 6] = 0.000000; aaLG[ 6][ 7] = 0.348847; aaLG[ 6][ 8] = 0.423881; aaLG[ 6][ 9] = 0.044265;
16917     aaLG[ 6][10] = 0.069673; aaLG[ 6][11] = 1.807177; aaLG[ 6][12] = 0.173735; aaLG[ 6][13] = 0.018811; aaLG[ 6][14] = 0.419409;
16918     aaLG[ 6][15] = 0.611973; aaLG[ 6][16] = 0.604545; aaLG[ 6][17] = 0.077852; aaLG[ 6][18] = 0.120037; aaLG[ 6][19] = 0.245034;
16919     aaLG[ 7][ 0] = 2.066040; aaLG[ 7][ 1] = 0.390192; aaLG[ 7][ 2] = 1.437645; aaLG[ 7][ 3] = 0.844926; aaLG[ 7][ 4] = 0.569265;
16920     aaLG[ 7][ 5] = 0.267959; aaLG[ 7][ 6] = 0.348847; aaLG[ 7][ 7] = 0.000000; aaLG[ 7][ 8] = 0.311484; aaLG[ 7][ 9] = 0.008705;
16921     aaLG[ 7][10] = 0.044261; aaLG[ 7][11] = 0.296636; aaLG[ 7][12] = 0.139538; aaLG[ 7][13] = 0.089586; aaLG[ 7][14] = 0.196961;
16922     aaLG[ 7][15] = 1.739990; aaLG[ 7][16] = 0.129836; aaLG[ 7][17] = 0.268491; aaLG[ 7][18] = 0.054679; aaLG[ 7][19] = 0.076701;
16923     aaLG[ 8][ 0] = 0.358858; aaLG[ 8][ 1] = 2.426601; aaLG[ 8][ 2] = 4.509238; aaLG[ 8][ 3] = 0.927114; aaLG[ 8][ 4] = 0.640543;
16924     aaLG[ 8][ 5] = 4.813505; aaLG[ 8][ 6] = 0.423881; aaLG[ 8][ 7] = 0.311484; aaLG[ 8][ 8] = 0.000000; aaLG[ 8][ 9] = 0.108882;
16925     aaLG[ 8][10] = 0.366317; aaLG[ 8][11] = 0.697264; aaLG[ 8][12] = 0.442472; aaLG[ 8][13] = 0.682139; aaLG[ 8][14] = 0.508851;
16926     aaLG[ 8][15] = 0.990012; aaLG[ 8][16] = 0.584262; aaLG[ 8][17] = 0.597054; aaLG[ 8][18] = 5.306834; aaLG[ 8][19] = 0.119013;
16927     aaLG[ 9][ 0] = 0.149830; aaLG[ 9][ 1] = 0.126991; aaLG[ 9][ 2] = 0.191503; aaLG[ 9][ 3] = 0.010690; aaLG[ 9][ 4] = 0.320627;
16928     aaLG[ 9][ 5] = 0.072854; aaLG[ 9][ 6] = 0.044265; aaLG[ 9][ 7] = 0.008705; aaLG[ 9][ 8] = 0.108882; aaLG[ 9][ 9] = 0.000000;
16929     aaLG[ 9][10] = 4.145067; aaLG[ 9][11] = 0.159069; aaLG[ 9][12] = 4.273607; aaLG[ 9][13] = 1.112727; aaLG[ 9][14] = 0.078281;
16930     aaLG[ 9][15] = 0.064105; aaLG[ 9][16] = 1.033739; aaLG[ 9][17] = 0.111660; aaLG[ 9][18] = 0.232523; aaLG[ 9][19] = 10.649107;
16931     aaLG[10][ 0] = 0.395337; aaLG[10][ 1] = 0.301848; aaLG[10][ 2] = 0.068427; aaLG[10][ 3] = 0.015076; aaLG[10][ 4] = 0.594007;
16932     aaLG[10][ 5] = 0.582457; aaLG[10][ 6] = 0.069673; aaLG[10][ 7] = 0.044261; aaLG[10][ 8] = 0.366317; aaLG[10][ 9] = 4.145067;
16933     aaLG[10][10] = 0.000000; aaLG[10][11] = 0.137500; aaLG[10][12] = 6.312358; aaLG[10][13] = 2.592692; aaLG[10][14] = 0.249060;
16934     aaLG[10][15] = 0.182287; aaLG[10][16] = 0.302936; aaLG[10][17] = 0.619632; aaLG[10][18] = 0.299648; aaLG[10][19] = 1.702745;
16935     aaLG[11][ 0] = 0.536518; aaLG[11][ 1] = 6.326067; aaLG[11][ 2] = 2.145078; aaLG[11][ 3] = 0.282959; aaLG[11][ 4] = 0.013266;
16936     aaLG[11][ 5] = 3.234294; aaLG[11][ 6] = 1.807177; aaLG[11][ 7] = 0.296636; aaLG[11][ 8] = 0.697264; aaLG[11][ 9] = 0.159069;
16937     aaLG[11][10] = 0.137500; aaLG[11][11] = 0.000000; aaLG[11][12] = 0.656604; aaLG[11][13] = 0.023918; aaLG[11][14] = 0.390322;
16938     aaLG[11][15] = 0.748683; aaLG[11][16] = 1.136863; aaLG[11][17] = 0.049906; aaLG[11][18] = 0.131932; aaLG[11][19] = 0.185202;
16939     aaLG[12][ 0] = 1.124035; aaLG[12][ 1] = 0.484133; aaLG[12][ 2] = 0.371004; aaLG[12][ 3] = 0.025548; aaLG[12][ 4] = 0.893680;
16940     aaLG[12][ 5] = 1.672569; aaLG[12][ 6] = 0.173735; aaLG[12][ 7] = 0.139538; aaLG[12][ 8] = 0.442472; aaLG[12][ 9] = 4.273607;
16941     aaLG[12][10] = 6.312358; aaLG[12][11] = 0.656604; aaLG[12][12] = 0.000000; aaLG[12][13] = 1.798853; aaLG[12][14] = 0.099849;
16942     aaLG[12][15] = 0.346960; aaLG[12][16] = 2.020366; aaLG[12][17] = 0.696175; aaLG[12][18] = 0.481306; aaLG[12][19] = 1.898718;
16943     aaLG[13][ 0] = 0.253701; aaLG[13][ 1] = 0.052722; aaLG[13][ 2] = 0.089525; aaLG[13][ 3] = 0.017416; aaLG[13][ 4] = 1.105251;
16944     aaLG[13][ 5] = 0.035855; aaLG[13][ 6] = 0.018811; aaLG[13][ 7] = 0.089586; aaLG[13][ 8] = 0.682139; aaLG[13][ 9] = 1.112727;
16945     aaLG[13][10] = 2.592692; aaLG[13][11] = 0.023918; aaLG[13][12] = 1.798853; aaLG[13][13] = 0.000000; aaLG[13][14] = 0.094464;
16946     aaLG[13][15] = 0.361819; aaLG[13][16] = 0.165001; aaLG[13][17] = 2.457121; aaLG[13][18] = 7.803902; aaLG[13][19] = 0.654683;
16947     aaLG[14][ 0] = 1.177651; aaLG[14][ 1] = 0.332533; aaLG[14][ 2] = 0.161787; aaLG[14][ 3] = 0.394456; aaLG[14][ 4] = 0.075382;
16948     aaLG[14][ 5] = 0.624294; aaLG[14][ 6] = 0.419409; aaLG[14][ 7] = 0.196961; aaLG[14][ 8] = 0.508851; aaLG[14][ 9] = 0.078281;
16949     aaLG[14][10] = 0.249060; aaLG[14][11] = 0.390322; aaLG[14][12] = 0.099849; aaLG[14][13] = 0.094464; aaLG[14][14] = 0.000000;
16950     aaLG[14][15] = 1.338132; aaLG[14][16] = 0.571468; aaLG[14][17] = 0.095131; aaLG[14][18] = 0.089613; aaLG[14][19] = 0.296501;
16951     aaLG[15][ 0] = 4.727182; aaLG[15][ 1] = 0.858151; aaLG[15][ 2] = 4.008358; aaLG[15][ 3] = 1.240275; aaLG[15][ 4] = 2.784478;
16952     aaLG[15][ 5] = 1.223828; aaLG[15][ 6] = 0.611973; aaLG[15][ 7] = 1.739990; aaLG[15][ 8] = 0.990012; aaLG[15][ 9] = 0.064105;
16953     aaLG[15][10] = 0.182287; aaLG[15][11] = 0.748683; aaLG[15][12] = 0.346960; aaLG[15][13] = 0.361819; aaLG[15][14] = 1.338132;
16954     aaLG[15][15] = 0.000000; aaLG[15][16] = 6.472279; aaLG[15][17] = 0.248862; aaLG[15][18] = 0.400547; aaLG[15][19] = 0.098369;
16955     aaLG[16][ 0] = 2.139501; aaLG[16][ 1] = 0.578987; aaLG[16][ 2] = 2.000679; aaLG[16][ 3] = 0.425860; aaLG[16][ 4] = 1.143480;
16956     aaLG[16][ 5] = 1.080136; aaLG[16][ 6] = 0.604545; aaLG[16][ 7] = 0.129836; aaLG[16][ 8] = 0.584262; aaLG[16][ 9] = 1.033739;
16957     aaLG[16][10] = 0.302936; aaLG[16][11] = 1.136863; aaLG[16][12] = 2.020366; aaLG[16][13] = 0.165001; aaLG[16][14] = 0.571468;
16958     aaLG[16][15] = 6.472279; aaLG[16][16] = 0.000000; aaLG[16][17] = 0.140825; aaLG[16][18] = 0.245841; aaLG[16][19] = 2.188158;
16959     aaLG[17][ 0] = 0.180717; aaLG[17][ 1] = 0.593607; aaLG[17][ 2] = 0.045376; aaLG[17][ 3] = 0.029890; aaLG[17][ 4] = 0.670128;
16960     aaLG[17][ 5] = 0.236199; aaLG[17][ 6] = 0.077852; aaLG[17][ 7] = 0.268491; aaLG[17][ 8] = 0.597054; aaLG[17][ 9] = 0.111660;
16961     aaLG[17][10] = 0.619632; aaLG[17][11] = 0.049906; aaLG[17][12] = 0.696175; aaLG[17][13] = 2.457121; aaLG[17][14] = 0.095131;
16962     aaLG[17][15] = 0.248862; aaLG[17][16] = 0.140825; aaLG[17][17] = 0.000000; aaLG[17][18] = 3.151815; aaLG[17][19] = 0.189510;
16963     aaLG[18][ 0] = 0.218959; aaLG[18][ 1] = 0.314440; aaLG[18][ 2] = 0.612025; aaLG[18][ 3] = 0.135107; aaLG[18][ 4] = 1.165532;
16964     aaLG[18][ 5] = 0.257336; aaLG[18][ 6] = 0.120037; aaLG[18][ 7] = 0.054679; aaLG[18][ 8] = 5.306834; aaLG[18][ 9] = 0.232523;
16965     aaLG[18][10] = 0.299648; aaLG[18][11] = 0.131932; aaLG[18][12] = 0.481306; aaLG[18][13] = 7.803902; aaLG[18][14] = 0.089613;
16966     aaLG[18][15] = 0.400547; aaLG[18][16] = 0.245841; aaLG[18][17] = 3.151815; aaLG[18][18] = 0.000000; aaLG[18][19] = 0.249313;
16967     aaLG[19][ 0] = 2.547870; aaLG[19][ 1] = 0.170887; aaLG[19][ 2] = 0.083688; aaLG[19][ 3] = 0.037967; aaLG[19][ 4] = 1.959291;
16968     aaLG[19][ 5] = 0.210332; aaLG[19][ 6] = 0.245034; aaLG[19][ 7] = 0.076701; aaLG[19][ 8] = 0.119013; aaLG[19][ 9] = 10.649107;
16969     aaLG[19][10] = 1.702745; aaLG[19][11] = 0.185202; aaLG[19][12] = 1.898718; aaLG[19][13] = 0.654683; aaLG[19][14] = 0.296501;
16970     aaLG[19][15] = 0.098369; aaLG[19][16] = 2.188158; aaLG[19][17] = 0.189510; aaLG[19][18] = 0.249313; aaLG[19][19] = 0.000000;
16971 
16972     lgPi[0] = 0.079066;  lgPi[1] = 0.055941;  lgPi[2] = 0.041977;  lgPi[3] = 0.053052;
16973     lgPi[4] = 0.012937;  lgPi[5] = 0.040767;  lgPi[6] = 0.071586;  lgPi[7] = 0.057337;
16974     lgPi[8] = 0.022355;  lgPi[9] = 0.062157;  lgPi[10] = 0.099081; lgPi[11] = 0.064600;
16975     lgPi[12] = 0.022951; lgPi[13] = 0.042302; lgPi[14] = 0.044040; lgPi[15] = 0.061197;
16976     lgPi[16] = 0.053287; lgPi[17] = 0.012066; lgPi[18] = 0.034155; lgPi[19] = 0.069147;
16977 
16978     /* now, check that the matrices are symmetrical */
16979     for (i=0; i<20; i++)
16980         {
16981         for (j=i+1; j<20; j++)
16982             {
16983             diff = aaJones[i][j] - aaJones[j][i];
16984             if (diff < 0.0)
16985                 diff = -diff;
16986             if (diff > 0.001)
16987                 {
16988                 MrBayesPrint ("%s   ERROR: Jones model is not symmetrical.\n");
16989                 return (ERROR);
16990                 }
16991             }
16992         }
16993     for (i=0; i<20; i++)
16994         {
16995         for (j=i+1; j<20; j++)
16996             {
16997             diff = aaDayhoff[i][j] - aaDayhoff[j][i];
16998             if (diff < 0.0)
16999                 diff = -diff;
17000             if (diff > 0.001)
17001                 {
17002                 MrBayesPrint ("%s   ERROR: Dayhoff model is not symmetrical.\n");
17003                 return (ERROR);
17004                 }
17005             }
17006         }
17007     for (i=0; i<20; i++)
17008         {
17009         for (j=i+1; j<20; j++)
17010             {
17011             diff = aaMtrev24[i][j] - aaMtrev24[j][i];
17012             if (diff < 0.0)
17013                 diff = -diff;
17014             if (diff > 0.001)
17015                 {
17016                 MrBayesPrint ("%s   ERROR: mtrev24 model is not symmetrical.\n");
17017                 return (ERROR);
17018                 }
17019             }
17020         }
17021     for (i=0; i<20; i++)
17022         {
17023         for (j=i+1; j<20; j++)
17024             {
17025             diff = aaMtmam[i][j] - aaMtmam[j][i];
17026             if (diff < 0.0)
17027                 diff = -diff;
17028             if (diff > 0.001)
17029                 {
17030                 MrBayesPrint ("%s   ERROR: mtmam model is not symmetrical.\n");
17031                 return (ERROR);
17032                 }
17033             }
17034         }
17035     for (i=0; i<20; i++)
17036         {
17037         for (j=i+1; j<20; j++)
17038             {
17039             diff = aartREV[i][j] - aartREV[j][i];
17040             if (diff < 0.0)
17041                 diff = -diff;
17042             if (diff > 0.001)
17043                 {
17044                 MrBayesPrint ("%s   ERROR: aartREV model is not symmetrical.\n");
17045                 return (ERROR);
17046                 }
17047             }
17048         }
17049     for (i=0; i<20; i++)
17050         {
17051         for (j=i+1; j<20; j++)
17052             {
17053             diff = aaWAG[i][j] - aaWAG[j][i];
17054             if (diff < 0.0)
17055                 diff = -diff;
17056             if (diff > 0.001)
17057                 {
17058                 MrBayesPrint ("%s   ERROR: aaWAG model is not symmetrical.\n");
17059                 return (ERROR);
17060                 }
17061             }
17062         }
17063     for (i=0; i<20; i++)
17064         {
17065         for (j=i+1; j<20; j++)
17066             {
17067             diff = aacpREV[i][j] - aacpREV[j][i];
17068             if (diff < 0.0)
17069                 diff = -diff;
17070             if (diff > 0.001)
17071                 {
17072                 MrBayesPrint ("%s   ERROR: cpREV model is not symmetrical.\n");
17073                 return (ERROR);
17074                 }
17075             }
17076         }
17077     for (i=0; i<20; i++)
17078         {
17079         for (j=i+1; j<20; j++)
17080             {
17081             diff = aaVt[i][j] - aaVt[j][i];
17082             if (diff < 0.0)
17083                 diff = -diff;
17084             if (diff > 0.001)
17085                 {
17086                 MrBayesPrint ("%s   ERROR: Vt model is not symmetrical.\n");
17087                 return (ERROR);
17088                 }
17089             }
17090         }
17091     for (i=0; i<20; i++)
17092         {
17093         for (j=i+1; j<20; j++)
17094             {
17095             diff = aaBlosum[i][j] - aaBlosum[j][i];
17096             if (diff < 0.0)
17097                 diff = -diff;
17098             if (diff > 0.001)
17099                 {
17100                 MrBayesPrint ("%s   ERROR: Blosum model is not symmetrical.\n");
17101                 return (ERROR);
17102                 }
17103             }
17104         }
17105     for (i=0; i<20; i++)
17106         {
17107         for (j=i+1; j<20; j++)
17108             {
17109             diff = aaLG[i][j] - aaLG[j][i];
17110             if (diff < 0.0)
17111                 diff = -diff;
17112             if (diff > 0.001)
17113                 {
17114                 MrBayesPrint ("%s   ERROR: LG model is not symmetrical.\n");
17115                 return (ERROR);
17116                 }
17117             }
17118         }
17119 
17120     /* rescale stationary frequencies, to make certain they sum to 1.0 */
17121     sum = 0.0;
17122     for (i=0; i<20; i++)
17123         sum += jonesPi[i];
17124     for (i=0; i<20; i++)
17125         jonesPi[i] /= sum;
17126     sum = 0.0;
17127     for (i=0; i<20; i++)
17128         sum += dayhoffPi[i];
17129     for (i=0; i<20; i++)
17130         dayhoffPi[i] /= sum;
17131     sum = 0.0;
17132     for (i=0; i<20; i++)
17133         sum += mtrev24Pi[i];
17134     for (i=0; i<20; i++)
17135         mtrev24Pi[i] /= sum;
17136     sum = 0.0;
17137     for (i=0; i<20; i++)
17138         sum += mtmamPi[i];
17139     for (i=0; i<20; i++)
17140         mtmamPi[i] /= sum;
17141     sum = 0.0;
17142     for (i=0; i<20; i++)
17143         sum += rtrevPi[i];
17144     for (i=0; i<20; i++)
17145         rtrevPi[i] /= sum;
17146     sum = 0.0;
17147     for (i=0; i<20; i++)
17148         sum += wagPi[i];
17149     for (i=0; i<20; i++)
17150         wagPi[i] /= sum;
17151     sum = 0.0;
17152     for (i=0; i<20; i++)
17153         sum += cprevPi[i];
17154     for (i=0; i<20; i++)
17155         cprevPi[i] /= sum;
17156     sum = 0.0;
17157     for (i=0; i<20; i++)
17158         sum += vtPi[i];
17159     for (i=0; i<20; i++)
17160         vtPi[i] /= sum;
17161     sum = 0.0;
17162     for (i=0; i<20; i++)
17163         sum += blosPi[i];
17164     for (i=0; i<20; i++)
17165         blosPi[i] /= sum;
17166     sum = 0.0;
17167     for (i=0; i<20; i++)
17168         sum += lgPi[i];
17169     for (i=0; i<20; i++)
17170         lgPi[i] /= sum;
17171 
17172     /* multiply entries by amino acid frequencies */
17173     for (i=0; i<20; i++)
17174         {
17175         for (j=0; j<20; j++)
17176             {
17177             aaJones[i][j]   *= jonesPi[j];
17178             aaDayhoff[i][j] *= dayhoffPi[j];
17179             aaMtrev24[i][j] *= mtrev24Pi[j];
17180             aaMtmam[i][j]   *= mtmamPi[j];
17181             aartREV[i][j]   *= rtrevPi[j];
17182             aaWAG[i][j]     *= wagPi[j];
17183             aacpREV[i][j]   *= cprevPi[j];
17184             aaVt[i][j]      *= vtPi[j];
17185             aaBlosum[i][j]  *= blosPi[j];
17186             aaLG[i][j]      *= lgPi[j];
17187             }
17188         }
17189 
17190     /* rescale, so branch lengths are in terms of expected number of
17191        amino acid substitutions per site */
17192     scaler = 0.0;
17193     for (i=0; i<20; i++)
17194         {
17195         for (j=i+1; j<20; j++)
17196             {
17197             scaler += jonesPi[i] * aaJones[i][j];
17198             scaler += jonesPi[j] * aaJones[j][i];
17199             }
17200         }
17201     scaler = 1.0 / scaler;
17202     for (i=0; i<20; i++)
17203         for (j=0; j<20; j++)
17204             aaJones[i][j] *= scaler;
17205     scaler = 0.0;
17206     for (i=0; i<20; i++)
17207         {
17208         for (j=i+1; j<20; j++)
17209             {
17210             scaler += dayhoffPi[i] * aaDayhoff[i][j];
17211             scaler += dayhoffPi[j] * aaDayhoff[j][i];
17212             }
17213         }
17214     scaler = 1.0 / scaler;
17215     for (i=0; i<20; i++)
17216         for (j=0; j<20; j++)
17217             aaDayhoff[i][j] *= scaler;
17218     scaler = 0.0;
17219     for (i=0; i<20; i++)
17220         {
17221         for (j=i+1; j<20; j++)
17222             {
17223             scaler += mtrev24Pi[i] * aaMtrev24[i][j];
17224             scaler += mtrev24Pi[j] * aaMtrev24[j][i];
17225             }
17226         }
17227     scaler = 1.0 / scaler;
17228     for (i=0; i<20; i++)
17229         for (j=0; j<20; j++)
17230             aaMtrev24[i][j] *= scaler;
17231     scaler = 0.0;
17232     for (i=0; i<20; i++)
17233         {
17234         for (j=i+1; j<20; j++)
17235             {
17236             scaler += mtmamPi[i] * aaMtmam[i][j];
17237             scaler += mtmamPi[j] * aaMtmam[j][i];
17238             }
17239         }
17240     scaler = 1.0 / scaler;
17241     for (i=0; i<20; i++)
17242         for (j=0; j<20; j++)
17243             aaMtmam[i][j] *= scaler;
17244     scaler = 0.0;
17245     for (i=0; i<20; i++)
17246         {
17247         for (j=i+1; j<20; j++)
17248             {
17249             scaler += rtrevPi[i] * aartREV[i][j];
17250             scaler += rtrevPi[j] * aartREV[j][i];
17251             }
17252         }
17253     scaler = 1.0 / scaler;
17254     for (i=0; i<20; i++)
17255         for (j=0; j<20; j++)
17256             aartREV[i][j] *= scaler;
17257     scaler = 0.0;
17258     for (i=0; i<20; i++)
17259         {
17260         for (j=i+1; j<20; j++)
17261             {
17262             scaler += wagPi[i] * aaWAG[i][j];
17263             scaler += wagPi[j] * aaWAG[j][i];
17264             }
17265         }
17266     scaler = 1.0 / scaler;
17267     for (i=0; i<20; i++)
17268         for (j=0; j<20; j++)
17269             aaWAG[i][j] *= scaler;
17270     scaler = 0.0;
17271     for (i=0; i<20; i++)
17272         {
17273         for (j=i+1; j<20; j++)
17274             {
17275             scaler += cprevPi[i] * aacpREV[i][j];
17276             scaler += cprevPi[j] * aacpREV[j][i];
17277             }
17278         }
17279     scaler = 1.0 / scaler;
17280     for (i=0; i<20; i++)
17281         for (j=0; j<20; j++)
17282             aacpREV[i][j] *= scaler;
17283     scaler = 0.0;
17284     for (i=0; i<20; i++)
17285         {
17286         for (j=i+1; j<20; j++)
17287             {
17288             scaler += vtPi[i] * aaVt[i][j];
17289             scaler += vtPi[j] * aaVt[j][i];
17290             }
17291         }
17292     scaler = 1.0 / scaler;
17293     for (i=0; i<20; i++)
17294         for (j=0; j<20; j++)
17295             aaVt[i][j] *= scaler;
17296     scaler = 0.0;
17297     for (i=0; i<20; i++)
17298         {
17299         for (j=i+1; j<20; j++)
17300             {
17301             scaler += blosPi[i] * aaBlosum[i][j];
17302             scaler += blosPi[j] * aaBlosum[j][i];
17303             }
17304         }
17305     scaler = 1.0 / scaler;
17306     for (i=0; i<20; i++)
17307         for (j=0; j<20; j++)
17308             aaBlosum[i][j] *= scaler;
17309     scaler = 0.0;
17310     for (i=0; i<20; i++)
17311         {
17312         for (j=i+1; j<20; j++)
17313             {
17314             scaler += lgPi[i] * aaLG[i][j];
17315             scaler += lgPi[j] * aaLG[j][i];
17316             }
17317         }
17318     scaler = 1.0 / scaler;
17319     for (i=0; i<20; i++)
17320         for (j=0; j<20; j++)
17321             aaLG[i][j] *= scaler;
17322 
17323     /* set diagonal of matrix */
17324     for (i=0; i<20; i++)
17325         {
17326         sum = 0.0;
17327         for (j=0; j<20; j++)
17328             {
17329             if (i != j)
17330                 sum += aaJones[i][j];
17331             }
17332         aaJones[i][i] = -sum;
17333         }
17334     for (i=0; i<20; i++)
17335         {
17336         sum = 0.0;
17337         for (j=0; j<20; j++)
17338             {
17339             if (i != j)
17340                 sum += aaDayhoff[i][j];
17341             }
17342         aaDayhoff[i][i] = -sum;
17343         }
17344     for (i=0; i<20; i++)
17345         {
17346         sum = 0.0;
17347         for (j=0; j<20; j++)
17348             {
17349             if (i != j)
17350                 sum += aaMtrev24[i][j];
17351             }
17352         aaMtrev24[i][i] = -sum;
17353         }
17354     for (i=0; i<20; i++)
17355         {
17356         sum = 0.0;
17357         for (j=0; j<20; j++)
17358             {
17359             if (i != j)
17360                 sum += aaMtmam[i][j];
17361             }
17362         aaMtmam[i][i] = -sum;
17363         }
17364     for (i=0; i<20; i++)
17365         {
17366         sum = 0.0;
17367         for (j=0; j<20; j++)
17368             {
17369             if (i != j)
17370                 sum += aartREV[i][j];
17371             }
17372         aartREV[i][i] = -sum;
17373         }
17374     for (i=0; i<20; i++)
17375         {
17376         sum = 0.0;
17377         for (j=0; j<20; j++)
17378             {
17379             if (i != j)
17380                 sum += aaWAG[i][j];
17381             }
17382         aaWAG[i][i] = -sum;
17383         }
17384     for (i=0; i<20; i++)
17385         {
17386         sum = 0.0;
17387         for (j=0; j<20; j++)
17388             {
17389             if (i != j)
17390                 sum += aacpREV[i][j];
17391             }
17392         aacpREV[i][i] = -sum;
17393         }
17394     for (i=0; i<20; i++)
17395         {
17396         sum = 0.0;
17397         for (j=0; j<20; j++)
17398             {
17399             if (i != j)
17400                 sum += aaVt[i][j];
17401             }
17402         aaVt[i][i] = -sum;
17403         }
17404     for (i=0; i<20; i++)
17405         {
17406         sum = 0.0;
17407         for (j=0; j<20; j++)
17408             {
17409             if (i != j)
17410                 sum += aaBlosum[i][j];
17411             }
17412         aaBlosum[i][i] = -sum;
17413         }
17414     for (i=0; i<20; i++)
17415         {
17416         sum = 0.0;
17417         for (j=0; j<20; j++)
17418             {
17419             if (i != j)
17420                 sum += aaLG[i][j];
17421             }
17422         aaLG[i][i] = -sum;
17423         }
17424 
17425 #   if 0
17426     for (i=0; i<20; i++)
17427         {
17428         MrBayesPrint ("%s   ", spacer);
17429         for (j=0; j<20; j++)
17430             {
17431             if (aaLG[i][j] < 0.0)
17432                 MrBayesPrint ("%1.3lf ", aaLG[i][j]);
17433             else
17434                 MrBayesPrint (" %1.3lf ", aaLG[i][j]);
17435             }
17436         MrBayesPrint ("\n");
17437         }
17438 #   endif
17439 
17440     return (NO_ERROR);
17441 }
17442 
17443 
SetCode(int part)17444 void SetCode (int part)
17445 {
17446     int     i, s, s1, s2, s3, ns;
17447 
17448     modelParams[part].codon[ 0] = 12; /* AAA Lys */
17449     modelParams[part].codon[ 1] =  3; /* AAC Asn */
17450     modelParams[part].codon[ 2] = 12; /* AAG Lys */
17451     modelParams[part].codon[ 3] =  3; /* AAT Asn */
17452     modelParams[part].codon[ 4] = 17; /* ACA Thr */
17453     modelParams[part].codon[ 5] = 17; /* ACC Thr */
17454     modelParams[part].codon[ 6] = 17; /* ACG Thr */
17455     modelParams[part].codon[ 7] = 17; /* ACT Thr */
17456     modelParams[part].codon[ 8] =  2; /* AGA Arg */
17457     modelParams[part].codon[ 9] = 16; /* AGC Ser */
17458     modelParams[part].codon[10] =  2; /* AGG Arg */
17459     modelParams[part].codon[11] = 16; /* AGT Ser */
17460     modelParams[part].codon[12] = 10; /* ATA Ile */
17461     modelParams[part].codon[13] = 10; /* ATC Ile */
17462     modelParams[part].codon[14] = 13; /* ATG Met */
17463     modelParams[part].codon[15] = 10; /* ATT Ile */
17464     modelParams[part].codon[16] =  6; /* CAA Gln */
17465     modelParams[part].codon[17] =  9; /* CAC His */
17466     modelParams[part].codon[18] =  6; /* CAG Gln */
17467     modelParams[part].codon[19] =  9; /* CAT His */
17468     modelParams[part].codon[20] = 15; /* CCA Pro */
17469     modelParams[part].codon[21] = 15; /* CCC Pro */
17470     modelParams[part].codon[22] = 15; /* CCG Pro */
17471     modelParams[part].codon[23] = 15; /* CCT Pro */
17472     modelParams[part].codon[24] =  2; /* CGA Arg */
17473     modelParams[part].codon[25] =  2; /* CGC Arg */
17474     modelParams[part].codon[26] =  2; /* CGG Arg */
17475     modelParams[part].codon[27] =  2; /* CGT Arg */
17476     modelParams[part].codon[28] = 11; /* CTA Leu */
17477     modelParams[part].codon[29] = 11; /* CTC Leu */
17478     modelParams[part].codon[30] = 11; /* CTG Leu */
17479     modelParams[part].codon[31] = 11; /* CTT Leu */
17480     modelParams[part].codon[32] =  7; /* GAA Glu */
17481     modelParams[part].codon[33] =  4; /* GAC Asp */
17482     modelParams[part].codon[34] =  7; /* GAG Glu */
17483     modelParams[part].codon[35] =  4; /* GAT Asp */
17484     modelParams[part].codon[36] =  1; /* GCA Ala */
17485     modelParams[part].codon[37] =  1; /* GCC Ala */
17486     modelParams[part].codon[38] =  1; /* GCG Ala */
17487     modelParams[part].codon[39] =  1; /* GCT Ala */
17488     modelParams[part].codon[40] =  8; /* GGA Gly */
17489     modelParams[part].codon[41] =  8; /* GGC Gly */
17490     modelParams[part].codon[42] =  8; /* GGG Gly */
17491     modelParams[part].codon[43] =  8; /* GGT Gly */
17492     modelParams[part].codon[44] = 20; /* GTA Val */
17493     modelParams[part].codon[45] = 20; /* GTC Val */
17494     modelParams[part].codon[46] = 20; /* GTG Val */
17495     modelParams[part].codon[47] = 20; /* GTT Val */
17496     modelParams[part].codon[48] = 21; /* TAA Stop*/
17497     modelParams[part].codon[49] = 19; /* TAC Tyr */
17498     modelParams[part].codon[50] = 21; /* TAG Stop*/
17499     modelParams[part].codon[51] = 19; /* TAT Tyr */
17500     modelParams[part].codon[52] = 16; /* TCA Ser */
17501     modelParams[part].codon[53] = 16; /* TCC Ser */
17502     modelParams[part].codon[54] = 16; /* TCG Ser */
17503     modelParams[part].codon[55] = 16; /* TCT Ser */
17504     modelParams[part].codon[56] = 21; /* TGA Stop*/
17505     modelParams[part].codon[57] =  5; /* TGC Cys */
17506     modelParams[part].codon[58] = 18; /* TGG Trp */
17507     modelParams[part].codon[59] =  5; /* TGT Cys */
17508     modelParams[part].codon[60] = 11; /* TTA Leu */
17509     modelParams[part].codon[61] = 14; /* TTC Phe */
17510     modelParams[part].codon[62] = 11; /* TTG Leu */
17511     modelParams[part].codon[63] = 14; /* TTT Phe */
17512 
17513     if (!strcmp(modelParams[part].geneticCode, "Vertmt"))
17514         {
17515         /* UGA: Ter -> Trp
17516            AUA: Ile -> Met
17517            AGA: Arg -> Ter
17518            AGG: Arg -> Ter */
17519         modelParams[part].codon[ 8] = 21; /* AGA Stop */
17520         modelParams[part].codon[10] = 21; /* AGG Stop */
17521         modelParams[part].codon[12] = 13; /* ATA Met  */
17522         modelParams[part].codon[56] = 18; /* TGA Trp  */
17523         }
17524     if (!strcmp(modelParams[part].geneticCode, "Invermt"))
17525         {
17526         /* UGA: Ter -> Trp
17527            AUA: Ile -> Met
17528            AGA: Arg -> Ser
17529            AGG: Arg -> Ser */
17530         modelParams[part].codon[ 8] = 16; /* AGA Ser */
17531         modelParams[part].codon[10] = 16; /* AGG Ser */
17532         modelParams[part].codon[12] = 13; /* ATA Met */
17533         modelParams[part].codon[56] = 18; /* TGA Trp */
17534         }
17535     else if (!strcmp(modelParams[part].geneticCode, "Mycoplasma"))
17536         {
17537         /* UGA: Ter -> Trp */
17538         modelParams[part].codon[56] = 18; /* TGA Trp */
17539         }
17540     else if (!strcmp(modelParams[part].geneticCode, "Yeast"))
17541         {
17542         /* UGA: Ter -> Trp
17543            AUA: Ile -> Met
17544            CUA: Leu -> Thr
17545            CUC: Leu -> Thr
17546            CUG: Leu -> Thr
17547            CUU: Leu -> Thr */
17548         modelParams[part].codon[12] = 13; /* ATA Met */
17549         modelParams[part].codon[28] = 17; /* CTA Thr */
17550         modelParams[part].codon[29] = 17; /* CTC Thr */
17551         modelParams[part].codon[30] = 17; /* CTG Thr */
17552         modelParams[part].codon[31] = 17; /* CTT Thr */
17553         modelParams[part].codon[56] = 18; /* TGA Trp */
17554         }
17555     else if (!strcmp(modelParams[part].geneticCode, "Ciliate"))
17556         {
17557         /* UAA: Ter -> Gln
17558            UAG: Ter -> Gln */
17559         modelParams[part].codon[48] =  6; /* TAA Gln */
17560         modelParams[part].codon[50] =  6; /* TAG Gln */
17561         }
17562     else if (!strcmp(modelParams[part].geneticCode, "Echinoderm"))
17563         {
17564         /* AAA: Lys -> Asn
17565            AGA: Arg -> Ser
17566            AGG: Arg -> Ser
17567            UGA: Ter -> Trp */
17568         modelParams[part].codon[ 0] = 3;  /* AAA Asn */
17569         modelParams[part].codon[ 8] = 16; /* AGA Ser */
17570         modelParams[part].codon[10] = 16; /* AGG Ser */
17571         modelParams[part].codon[56] = 18; /* TGA Trp */
17572         }
17573     else if (!strcmp(modelParams[part].geneticCode, "Euplotid"))
17574         {
17575         /* UGA: Ter -> Cys */
17576         modelParams[part].codon[56] = 5;  /* TGA Cys */
17577         }
17578     else if (!strcmp(modelParams[part].geneticCode, "Metmt"))
17579         {
17580         /* UGA: Ter -> Trp
17581            AUA: Ile -> Met
17582            AGA: Arg -> Ser
17583            AGG: Arg -> Ser */
17584         modelParams[part].codon[ 8] = 16; /* AGA Ser */
17585         modelParams[part].codon[10] = 16; /* AGG Ser */
17586         modelParams[part].codon[12] = 13; /* ATA Met */
17587         modelParams[part].codon[56] = 18; /* TGA Trp */
17588         }
17589     else
17590         {
17591         }
17592 
17593     ns = 0;
17594     for (i=0; i<64; i++)
17595         {
17596         if (modelParams[part].codon[i] != 21)
17597             ns++;
17598         }
17599     /* printf ("ns = %d\n", ns); */
17600 
17601     s = 0;
17602     for (s1=0; s1<4; s1++)
17603         for (s2=0; s2<4; s2++)
17604             for (s3=0; s3<4; s3++)
17605                 if (modelParams[part].codon[s1*16 + s2*4 + s3] != 21)
17606                     {
17607                     modelParams[part].codonNucs[s][0] = s1;
17608                     modelParams[part].codonNucs[s][1] = s2;
17609                     modelParams[part].codonNucs[s][2] = s3;
17610                     modelParams[part].codonAAs[s] = modelParams[part].codon[s1*16 + s2*4 + s3];
17611                     s++;
17612                     }
17613 }
17614 
17615 
SetLocalTaxa(void)17616 int SetLocalTaxa (void)
17617 {
17618     int         i, j;
17619 
17620     /* free memory if allocated */
17621     if (memAllocs[ALLOC_LOCTAXANAMES] == YES)
17622         {
17623         free (localTaxonNames);
17624         localTaxonNames = NULL;
17625         memAllocs[ALLOC_LOCTAXANAMES] = NO;
17626         }
17627     if (memAllocs[ALLOC_LOCALTAXONCALIBRATION] == YES)
17628         {
17629         free (localTaxonCalibration);
17630         localTaxonCalibration = NULL;
17631         memAllocs[ALLOC_LOCALTAXONCALIBRATION] = NO;
17632         }
17633 
17634     /* count number of non-excluded taxa */
17635     numLocalTaxa = 0;
17636     for (i=0; i<numTaxa; i++)
17637         {
17638         if (taxaInfo[i].isDeleted == NO)
17639             numLocalTaxa++;
17640         }
17641 
17642     /* allocate memory */
17643     localTaxonNames = (char **)SafeCalloc((size_t)numLocalTaxa, sizeof(char *));
17644     if (!localTaxonNames)
17645         return (ERROR);
17646     memAllocs[ALLOC_LOCTAXANAMES] = YES;
17647 
17648     localTaxonCalibration = (Calibration **)SafeCalloc((size_t)numLocalTaxa, sizeof(Calibration *));
17649     if (!localTaxonCalibration)
17650         return (ERROR);
17651     memAllocs[ALLOC_LOCALTAXONCALIBRATION] = YES;
17652 
17653     /* point to names and calibrations of non-excluded taxa */
17654     localOutGroup = 0;
17655     for (i=j=0; i<numTaxa; i++)
17656         {
17657         if (taxaInfo[i].isDeleted == NO)
17658             {
17659             localTaxonNames[j] = taxaNames[i];
17660             localTaxonCalibration[j] = &tipCalibration[i];
17661             if (i == outGroupNum)
17662                 localOutGroup = j;
17663             j++;
17664             }
17665         }
17666 
17667 #   if 0
17668     /* show non-excluded taxa */
17669     for (i=0; i<numLocalTaxa; i++)
17670         MrBayesPrint ("%s   %4d %s\n", spacer, i+1, localTaxonNames[i]);
17671 #   endif
17672 
17673     return (NO_ERROR);
17674 }
17675 
17676 
17677 /*----------------------------------------------------------------------------
17678 |
17679 |   SetModelDefaults: This function will set up model defaults in modelParams.
17680 |       It will also initialize parameters and moves by calling SetUpAnalysis.
17681 |
17682 -----------------------------------------------------------------------------*/
SetModelDefaults(void)17683 int SetModelDefaults (void)
17684 {
17685     int         j;
17686 
17687     MrBayesPrint ("%s   Setting model defaults\n", spacer);
17688     MrBayesPrint ("%s   Seed (for generating default start values) = %d\n", spacer, globalSeed);
17689 
17690     if (InitializeLinks () == ERROR)
17691         {
17692         MrBayesPrint ("%s   Problem initializing link table\n", spacer);
17693         return (ERROR);
17694         }
17695 
17696     /* Check that models are allocated */
17697     if (memAllocs[ALLOC_MODEL] == NO)
17698         {
17699         MrBayesPrint ("%s   Model not allocated in SetModelDefaults\n", spacer);
17700         return (ERROR);
17701         }
17702 
17703     /* model parameters */
17704     for (j=0; j<numCurrentDivisions; j++)
17705         {
17706         modelParams[j] = defaultModel;                      /* start with default settings */
17707 
17708         modelParams[j].dataType = DataType (j);             /* data type for partition                      */
17709 
17710         if (modelParams[j].dataType == STANDARD)
17711             {   /* set default ascertainment bias for partition */
17712             modelParams[j].coding = VARIABLE;
17713             strcpy(modelParams[j].codingString, "Variable");
17714             }
17715         else if (modelParams[j].dataType == RESTRICTION)
17716             {
17717             modelParams[j].coding = NOABSENCESITES;
17718             strcpy(modelParams[j].codingString, "Noabsencesites");
17719             }
17720         else
17721             {
17722             modelParams[j].coding = ALL;
17723             strcpy(modelParams[j].codingString, "All");
17724             }
17725 
17726         SetCode (j);
17727         modelParams[j].nStates = NumStates (j);             /* number of states for partition             */
17728 
17729         if (numDefinedConstraints > 0)
17730             modelParams[j].activeConstraints = (int *) SafeCalloc((size_t)(numDefinedConstraints), sizeof(int));  /* allocate space for active constraints (yes/no) */
17731         }
17732 
17733     return (NO_ERROR);
17734 }
17735 
17736 
17737 /*----------------------------------------------------------------------------
17738 |
17739 |   SetModelInfo: This function will set up model info using model
17740 |       params
17741 |
17742 -----------------------------------------------------------------------------*/
SetModelInfo(void)17743 int SetModelInfo (void)
17744 {
17745     int             i, j, chn, ts;
17746     ModelParams     *mp;
17747     ModelInfo       *m;
17748 
17749     /* wipe all model settings */
17750     inferSiteRates = NO;
17751     inferAncStates = NO;
17752     inferSiteOmegas = NO;
17753 
17754     for (i=0; i<numCurrentDivisions; i++)
17755         {
17756         m = &modelSettings[i];
17757 
17758         /* make certain that we set this intentionally to "NO" so we
17759            calculate cijk information and calculate cond likes when needed */
17760         m->upDateCijk = YES;
17761         m->upDateCl = YES;
17762         m->upDateAll = YES;
17763 
17764         /* make certain that we start with a parsimony branch length of zero */
17765         for (j=0; j<MAX_CHAINS; j++)
17766             m->parsTreeLength[j*2] = m->parsTreeLength[j*2+1] = 0.0;
17767 
17768         m->tRatio = NULL;
17769         m->revMat = NULL;
17770         m->omega = NULL;
17771         m->stateFreq = NULL;
17772         m->mixtureRates = NULL;
17773         m->shape = NULL;
17774         m->pInvar = NULL;
17775         m->correlation = NULL;
17776         m->switchRates = NULL;
17777         m->rateMult = NULL;
17778         m->topology = NULL;
17779         m->brlens = NULL;
17780         m->speciationRates = NULL;
17781         m->extinctionRates = NULL;
17782         m->fossilizationRates = NULL;
17783         m->popSize = NULL;
17784         m->aaModel = NULL;
17785         m->cppRate = NULL;
17786         m->cppEvents = NULL;
17787         m->cppMultDev = NULL;
17788         m->tk02var = NULL;
17789         m->tk02BranchRates = NULL;
17790         m->igrvar = NULL;
17791         m->igrBranchRates = NULL;
17792         m->mixedvar = NULL;
17793         m->mixedBrchRates = NULL;
17794         m->clockRate = NULL;
17795 
17796         m->CondLikeDown = NULL;
17797         m->CondLikeRoot = NULL;
17798         m->CondLikeScaler = NULL;
17799         m->Likelihood = NULL;
17800         m->TiProbs = NULL;
17801 
17802         m->CondLikeUp = NULL;
17803         m->StateCode = NULL;
17804         m->PrintAncStates = NULL;
17805         m->PrintSiteRates = NULL;
17806 
17807         m->printPosSel = NO;
17808         m->printAncStates = NO;
17809         m->printSiteRates = NO;
17810 
17811         m->nStates = NULL;
17812         m->bsIndex = NULL;
17813         m->cType = NULL;
17814         m->tiIndex = NULL;
17815 
17816         m->gibbsGamma = NO;
17817         m->gibbsFreq = 0;
17818 
17819         m->parsimonyBasedMove = NO;
17820 
17821 #   if defined (BEAGLE_ENABLED)
17822         m->beagleInstance = -1;               /* beagle instance                              */
17823         m->logLikelihoods = NULL;             /* array of log likelihoods from Beagle         */
17824         m->inRates = NULL;                    /* array of category rates for Beagle           */
17825         m->branchLengths = NULL;              /* array of branch lengths for Beagle           */
17826         m->tiProbIndices = NULL;              /* array of trans prob indices for Beagle       */
17827         m->inWeights = NULL;                  /* array of weights for Beagle root likelihood  */
17828         m->bufferIndices = NULL;              /* array of partial indices for root likelihood */
17829         m->childBufferIndices = NULL;         /* array of child partial indices (unrooted)    */
17830         m->childTiProbIndices = NULL;         /* array of child ti prob indices (unrooted)    */
17831         m->cumulativeScaleIndices = NULL;     /* array of cumulative scale indices            */
17832         m->divisionIndex = i;                 /* division index number                        */
17833         m->operations = NULL;                 /* array of operations to be sent to Beagle     */
17834         m->opCount = 0;                       /* partial likelihood operations count          */
17835 #   if defined (BEAGLE_V3_ENABLED)
17836         m->numCharsAll               = 0;     /* number of compressed chars for all divisions */
17837         m->logLikelihoodsAll         = NULL;  /* array of log likelihoods for all divisions   */
17838         m->cijkIndicesAll            = NULL;  /* cijk array for all divisions                 */
17839         m->categoryRateIndicesAll    = NULL;  /* category rate array for all divisions        */
17840         m->operationsAll             = NULL;  /* array of all operations across divisions     */
17841         m->operationsByPartition     = NULL;  /* array of division operations to be sent to Beagle */
17842 #   endif /* BEAGLE_V3_ENABLED */
17843 #   endif /* BEAGLE_ENABLED */
17844 
17845         /* likelihood calculator flags */
17846         m->useVec = VEC_NONE;                 /* use SIMD code for this partition?            */
17847         m->useBeagle = NO;                    /* use Beagle for this partition?               */
17848         m->useBeagleMultiPartitions = NO;     /* use one Beagle instance for all partitions?  */
17849 
17850 #if defined (SSE_ENABLED)
17851         m->numVecChars = 0;
17852         m->numFloatsPerVec = 0;
17853         m->lnL_Vec = NULL;
17854         m->lnLI_Vec = NULL;
17855         m->clP_SSE = NULL;
17856 #if defined (AVX_ENABLED)
17857         m->clP_AVX = NULL;
17858 #endif
17859 #endif
17860 
17861         /* set all memory pointers to NULL */
17862         m->parsSets = NULL;
17863         m->numParsSets = 0;
17864         m->parsNodeLens = NULL;
17865         m->numParsNodeLens = 0;
17866 
17867         m->condLikes = NULL;
17868         m->tiProbs = NULL;
17869         m->scalers = NULL;
17870         m->numCondLikes = 0;
17871         m->numTiProbs = 0;
17872         m->numScalers = 0;
17873 
17874         m->condLikeIndex = NULL;
17875         m->condLikeScratchIndex = NULL;
17876         m->tiProbsIndex = NULL;
17877         m->tiProbsScratchIndex = NULL;
17878         m->nodeScalerIndex = NULL;
17879         m->nodeScalerScratchIndex = NULL;
17880         m->siteScalerIndex = NULL;
17881         m->siteScalerScratchIndex = -1;
17882 
17883         m->cijks = NULL;
17884         m->nCijkParts = 0;
17885         m->cijkIndex = NULL;
17886         m->cijkScratchIndex = -1;
17887         }
17888 
17889     /* set state of all chains to zero */
17890     for (chn=0; chn<numGlobalChains; chn++)
17891         state[chn] = 0;
17892 
17893     /* fill in modelSettings info with some basic model characteristics */
17894     for (i=0; i<numCurrentDivisions; i++)
17895         {
17896         mp = &modelParams[i];
17897         m = &modelSettings[i];
17898 
17899         if (!strcmp(mp->nucModel,"Protein") && (mp->dataType == DNA || mp->dataType == RNA))
17900             m->dataType = PROTEIN;
17901         else
17902             m->dataType = mp->dataType;
17903 
17904         /* nuc model structure */
17905         if (!strcmp(mp->nucModel, "4by4"))
17906             m->nucModelId = NUCMODEL_4BY4;
17907         else if (!strcmp(mp->nucModel, "Doublet"))
17908             m->nucModelId = NUCMODEL_DOUBLET;
17909         else if (!strcmp(mp->nucModel, "Protein"))
17910             m->nucModelId = NUCMODEL_AA;
17911         else /* if (!strcmp(mp->nucModelId, "Codon")) */
17912             m->nucModelId = NUCMODEL_CODON;
17913 
17914         /* model nst */
17915         if (!strcmp(mp->nst, "1"))
17916             m->nst = 1;
17917         else if (!strcmp(mp->nst, "2"))
17918             m->nst = 2;
17919         else if (!strcmp(mp->nst, "6"))
17920             m->nst = 6;
17921         else
17922             m->nst = NST_MIXED;
17923 
17924         /* We set the aa model here. We have two options. First, the model
17925            could be fixed, in which case mp->aaModel has been set. We then
17926            go ahead and also set the model settings. Second, the model
17927            could be mixed. In this case, the amino acid matrix is considered
17928            a parameter, and we will deal with it below. It doesn't hurt
17929            to set it here anyway (it will be overwritten later). */
17930         if (!strcmp(mp->aaModelPr, "Fixed"))
17931             {
17932             if (!strcmp(mp->aaModel, "Poisson"))
17933                 m->aaModelId = AAMODEL_POISSON;
17934             else if (!strcmp(mp->aaModel, "Equalin"))
17935                 m->aaModelId = AAMODEL_EQ;
17936             else if (!strcmp(mp->aaModel, "Jones"))
17937                 m->aaModelId = AAMODEL_JONES;
17938             else if (!strcmp(mp->aaModel, "Dayhoff"))
17939                 m->aaModelId = AAMODEL_DAY;
17940             else if (!strcmp(mp->aaModel, "Mtrev"))
17941                 m->aaModelId = AAMODEL_MTREV;
17942             else if (!strcmp(mp->aaModel, "Mtmam"))
17943                 m->aaModelId = AAMODEL_MTMAM;
17944             else if (!strcmp(mp->aaModel, "Wag"))
17945                 m->aaModelId = AAMODEL_WAG;
17946             else if (!strcmp(mp->aaModel, "Rtrev"))
17947                 m->aaModelId = AAMODEL_RTREV;
17948             else if (!strcmp(mp->aaModel, "Cprev"))
17949                 m->aaModelId = AAMODEL_CPREV;
17950             else if (!strcmp(mp->aaModel, "Vt"))
17951                 m->aaModelId = AAMODEL_VT;
17952             else if (!strcmp(mp->aaModel, "Blosum"))
17953                 m->aaModelId = AAMODEL_BLOSUM;
17954             else if (!strcmp(mp->aaModel, "LG"))
17955                 m->aaModelId = AAMODEL_LG;
17956             else if (!strcmp(mp->aaModel, "Gtr"))
17957                 m->aaModelId = AAMODEL_GTR;
17958             else
17959                 {
17960                 MrBayesPrint ("%s   Uncertain amino acid model\n", spacer);
17961                 return (ERROR);
17962                 }
17963             }
17964         else
17965             m->aaModelId = -1;
17966 
17967         /* parsimony model? */
17968         if (!strcmp(mp->parsModel, "Yes"))
17969             m->parsModelId = YES;
17970         else
17971             m->parsModelId = NO;
17972 
17973         /* number of rate categories */
17974         if (activeParams[P_SHAPE][i] > 0)
17975             {
17976             if (!strcmp(mp->ratesModel, "Lnorm"))
17977                 m->numRateCats = mp->numLnormCats;
17978             else
17979                 m->numRateCats = mp->numGammaCats;
17980             }
17981         else if (activeParams[P_MIXTURE_RATES][i] > 0)
17982             m->numRateCats = mp->numMixtCats;
17983         else
17984             m->numRateCats = 1;
17985 
17986         /* number of beta categories */
17987         if (mp->dataType == STANDARD && !(AreDoublesEqual(mp->symBetaFix, -1.0, 0.00001) == YES && !strcmp(mp->symPiPr,"Fixed")))
17988             m->numBetaCats = mp->numBetaCats;
17989         else
17990             m->numBetaCats = 1;
17991 
17992         /* number of omega categories */
17993         if ((mp->dataType == DNA || mp->dataType == RNA) && (!strcmp(mp->omegaVar, "Ny98") || !strcmp(mp->omegaVar, "M3")) && !strcmp(mp->nucModel, "Codon"))
17994             {
17995             m->numOmegaCats = 3;
17996             m->numRateCats = 1; /* if we are here, then we cannot have gamma or beta variation */
17997             m->numBetaCats = 1;
17998             }
17999         else if ((mp->dataType == DNA || mp->dataType == RNA) && !strcmp(mp->omegaVar, "M10") && !strcmp(mp->nucModel, "Codon"))
18000             {
18001             m->numOmegaCats = mp->numM10BetaCats + mp->numM10GammaCats;
18002             m->numRateCats = 1; /* if we are here, then we cannot have gamma or beta variation */
18003             m->numBetaCats = 1;
18004             }
18005         else
18006             m->numOmegaCats = 1;
18007 
18008         /* number of transition matrices depends on numGammaCats, numBetaCats, and numOmegaCats */
18009         m->numTiCats = m->numRateCats * m->numBetaCats * m->numOmegaCats;
18010 
18011         /* TODO: check that numStates and numModelStates are set
18012             appropriately for codon and doublet models */
18013 
18014         /* number of observable states */
18015         if (m->dataType == STANDARD)
18016             m->numStates = 0;   /* zero, meaining variable */
18017         else if (!strcmp(mp->nucModel,"Protein") && (mp->dataType == DNA || mp->dataType == RNA))
18018             m->numStates = 20;
18019         else
18020             m->numStates = mp->nStates;
18021 
18022         /* number of model states including hidden ones */
18023         if ((mp->dataType == DNA || mp->dataType == RNA) && !strcmp (mp->covarionModel, "Yes") && !strcmp(mp->nucModel, "4by4"))
18024             m->numModelStates = mp->nStates * 2;
18025         else if (m->dataType == PROTEIN && !strcmp (mp->covarionModel, "Yes"))
18026             m->numModelStates = mp->nStates * 2;
18027         else if ((mp->dataType == DNA || mp->dataType == RNA) && !strcmp(mp->nucModel,"Protein") && !strcmp (mp->covarionModel, "Yes"))
18028             m->numModelStates = 20 * 2;
18029         else if (mp->dataType == CONTINUOUS)
18030             m->numModelStates = 0;
18031         else if (mp->dataType == STANDARD)
18032             {
18033             /* use max possible for now; we don't know what chars will be included */
18034             m->numModelStates = 10;
18035             }
18036         else
18037             m->numModelStates = m->numStates;
18038 
18039         /* Fill in some information for calculating cijk. We will use m->cijkLength to
18040            figure out if we need to diagonalize Q to calculate transition probabilities.
18041            If cijkLength = 0, then we won't bother. We use cijkLength later in this function. */
18042         m->cijkLength = 0;
18043         m->nCijkParts = 1;
18044         if (m->dataType == PROTEIN)
18045             {
18046             ts = m->numModelStates;
18047             m->cijkLength = (ts * ts * ts) + (2 * ts);
18048             if (!strcmp (mp->covarionModel, "Yes"))
18049                 {
18050                 m->cijkLength *= m->numRateCats;
18051                 m->nCijkParts = m->numRateCats;
18052                 }
18053             }
18054         else if (m->dataType == STANDARD)
18055             {
18056             /* set to 0 for now, update in ProcessStdChars */
18057             m->nCijkParts = 0;
18058             }
18059         else if (m->dataType == DNA || m->dataType == RNA)
18060             {
18061             if (m->nucModelId == NUCMODEL_4BY4)
18062                 {
18063                 if (!strcmp (mp->covarionModel, "No") && m->nst != 6 && m->nst != 203)
18064                     m->cijkLength = 0;
18065                 else
18066                     {
18067                     ts = m->numModelStates;
18068                     m->cijkLength = (ts * ts * ts) + (2 * ts);
18069                     }
18070                 if (!strcmp (mp->covarionModel, "Yes"))
18071                     {
18072                     m->cijkLength *= m->numRateCats;
18073                     m->nCijkParts = m->numRateCats;
18074                     }
18075                 }
18076             else if (m->nucModelId == NUCMODEL_DOUBLET)
18077                 {
18078                 ts = m->numModelStates;
18079                 m->cijkLength = (ts * ts * ts) + (2 * ts);
18080                 }
18081             else if (m->nucModelId == NUCMODEL_CODON)
18082                 {
18083                 ts = m->numModelStates;
18084                 m->cijkLength = (ts * ts * ts) + (2 * ts);
18085                 m->cijkLength *= m->numOmegaCats;
18086                 m->nCijkParts = m->numOmegaCats;
18087                 }
18088             else
18089                 {
18090                 MrBayesPrint ("%s   BUG: Inconsistent model. Please report this as a bug.\n");
18091                 return ERROR;
18092                 }
18093             }
18094 
18095         /* check if we should calculate ancestral states */
18096         if (!strcmp(mp->inferAncStates,"Yes"))
18097             {
18098             if (m->dataType == PROTEIN && !strcmp(mp->covarionModel, "No"))
18099                 m->printAncStates = YES;
18100             else if (m->dataType == DNA || m->dataType == RNA)
18101                 {
18102                 if (!strcmp(mp->nucModel,"4by4") && !strcmp(mp->covarionModel, "No"))
18103                     m->printAncStates = YES;
18104                 if (!strcmp(mp->nucModel,"Doublet"))
18105                     m->printAncStates = YES;
18106                 if (!strcmp(mp->nucModel,"Codon") && !strcmp(mp->omegaVar,"Equal"))
18107                     m->printAncStates = YES;
18108                 }
18109             else if (m->dataType == STANDARD || m->dataType == RESTRICTION)
18110                 m->printAncStates = YES;
18111             if (m->printAncStates == YES)
18112                 inferAncStates = YES;
18113             else
18114                 MrBayesPrint ("%s   Print out of ancestral states is not applicable for devision %d.\n",spacer,i);
18115             }
18116 
18117         /* check if we should calculate site rates */
18118         if (!strcmp(mp->inferSiteRates,"Yes"))
18119             {
18120             if (m->numRateCats > 1)
18121                 {
18122                 m->printSiteRates = YES;
18123                 inferSiteRates = YES;
18124                 }
18125             }
18126 
18127         /* check if we should calculate positive selection */
18128         if (!strcmp(mp->inferPosSel, "Yes"))
18129             {
18130             if (m->numOmegaCats > 1)
18131                 {
18132                 m->printPosSel = YES;
18133                 inferPosSel = YES;
18134                 }
18135             }
18136 
18137         /* check if we should calculate site omegas */
18138         if (!strcmp(mp->inferSiteOmegas, "Yes"))
18139             {
18140             if (m->numOmegaCats > 1)
18141                 {
18142                 m->printSiteOmegas = YES;
18143                 inferSiteOmegas = YES;
18144                 }
18145             }
18146         /* check if we should use gibbs sampling of gamma (don't use it with pinvar or invgamma) */
18147         if (!strcmp(mp->useGibbs,"Yes") && (m->numRateCats > 1))
18148             {
18149             if (m->dataType == DNA || m->dataType == RNA || m->dataType == PROTEIN)
18150                 {
18151                 if (activeParams[P_CORREL][i] <= 0 && m->printSiteRates == NO && activeParams[P_PINVAR][i] <= 0)
18152                     {
18153                     m->gibbsGamma = YES;
18154                     m->gibbsFreq = mp->gibbsFreq;
18155                     }
18156                 }
18157             }
18158         }
18159 
18160     return (NO_ERROR);
18161 }
18162 
18163 
18164 /*-----------------------------------------------------------------
18165 |
18166 |   SetModelParams: Set up parameter structs for all model
18167 |       parameters, including trees
18168 |
18169 |----------------------------------------------------------------*/
SetModelParams(void)18170 int SetModelParams (void)
18171 {
18172     int             c, i, j, k, n, n1, n2, *isPartTouched, numRelParts, nRelParts, areAllPartsParsimony,
18173                     nClockBrlens, nRelaxedBrlens, nCalibratedBrlens;
18174     char            tempCodon[15], tempMult[15], *tempStr,temp[30];
18175     char static     *partString=NULL; /* mad static to avoid posible memory leak on return ERROR if it would be introduced later */
18176     Param           *p;
18177     ModelParams     *mp;
18178     ModelInfo       *m;
18179     int             tempStrSize = 300;
18180 
18181     tempStr = (char *) SafeMalloc((size_t)tempStrSize * sizeof(char));
18182     isPartTouched = (int *) SafeMalloc ((size_t)numCurrentDivisions * sizeof (int));
18183     if (!tempStr || !isPartTouched)
18184         {
18185         MrBayesPrint ("%s   Problem allocating tempString (%d) or isPartTouched (%d)\n", spacer,
18186             tempStrSize * sizeof(char), numCurrentDivisions * sizeof(int));
18187         return (ERROR);
18188         }
18189 
18190 #   if defined DEBUG_SETCHAINPARAMS
18191     /* only for debugging */
18192     MrBFlt      lnPriorRatio = 0.0, lnProposalRatio = 0.0;
18193 #   endif
18194 
18195     /* allocate space for parameters */
18196     if (memAllocs[ALLOC_PARAMS] == YES)
18197         {
18198         for (i=0; i<numParams; i++)
18199             {
18200             SAFEFREE (params[i].name);
18201             if (params[i].paramHeader)
18202                 {
18203                 free (params[i].paramHeader);
18204                 params[i].paramHeader = NULL;
18205                 }
18206             }
18207         free (params);
18208         free (relevantParts);
18209         params = NULL;
18210         relevantParts = NULL;
18211         memAllocs[ALLOC_PARAMS] = NO;
18212         }
18213 
18214     /* wipe all chain parameter information */
18215     numParams = 0;
18216     numTrees = 0;
18217     chainHasAdgamma = NO;
18218 
18219     /* figure out number of parameters */
18220     /* this relies on activeParams[j][i] being set to 1, 2, ..., numParams */
18221     /* which is taken care of in SetUpLinkTable () */
18222     nRelParts = 0;
18223     for (j=0; j<NUM_LINKED; j++)
18224         {
18225         for (i=0; i<numCurrentDivisions; i++)
18226             {
18227             if (activeParams[j][i] > numParams)
18228                 numParams = activeParams[j][i];
18229             if (activeParams[j][i] > 0)
18230                 nRelParts++;
18231             }
18232         }
18233 
18234     params = (Param *) SafeMalloc (numParams * sizeof(Param));
18235     relevantParts = (int *) SafeMalloc (nRelParts * sizeof(int));
18236     if (!params || !relevantParts)
18237         {
18238         MrBayesPrint ("%s   Problem allocating params and relevantParts\n", spacer);
18239         if (params)
18240             free (params);
18241         if (relevantParts)
18242             free (relevantParts);
18243         free (tempStr);
18244         return ERROR;
18245         }
18246     else
18247         memAllocs[ALLOC_PARAMS] = YES;
18248 
18249     /* fill in info on each parameter */
18250     nRelParts = 0;  /* now cumulative number of relevant partitions */
18251     for (k=0; k<numParams; k++)
18252         {
18253         p = &params[k];
18254 
18255         /* find affected partitions */
18256         numRelParts = 0;
18257         for (j=0; j<NUM_LINKED; j++)
18258             {
18259             for (i=0; i<numCurrentDivisions; i++)
18260                 {
18261                 if (activeParams[j][i] == k + 1)
18262                     {
18263                     numRelParts++;
18264                     isPartTouched[i] = YES;
18265                     }
18266                 else
18267                     isPartTouched[i] = NO;
18268                 }
18269             if (numRelParts > 0)
18270                 break;
18271             }
18272 
18273         /* find pointer to modelParams and modelSettings of first relevant partition */
18274         /* this will be handy later on */
18275         for (i=0; i<numCurrentDivisions; i++)
18276             if (isPartTouched[i] == YES)
18277                 break;
18278         mp = &modelParams[i];
18279         m  = &modelSettings[i];
18280 
18281         /* Set default min and max */
18282         p->min = p->max = NEG_INFINITY;
18283 
18284         /* Parameter nValues and nSubValues, which are needed for memory allocation
18285            are calculated for each case in the code below. nSympi, however, is
18286            only used for one special type of parameter and it therefore makes
18287            sense to initialize it to 0 here. The same applies to hasBinaryStd
18288            and nIntValues. To be safe, we set all to 0 here. */
18289         p->nValues = 0;
18290         p->nSubValues = 0;
18291         p->nIntValues = 0;
18292         p->nSympi = 0;
18293         p->hasBinaryStd = NO;
18294 
18295         /* should this parameter be printed to a file? */
18296         p->printParam = NO;
18297 
18298         /* set print subparams to 0 */
18299         p->nPrintSubParams = 0;
18300 
18301         /* check constraints for tree parameter ? */
18302         p->checkConstraints = NO;
18303 
18304         /* set index number of parameter */
18305         p->index = k;
18306 
18307         /* set prior function to NULL */
18308         p->LnPriorRatio = NULL;
18309 
18310         /* set prior paramters to NULL */
18311         p->priorParams = NULL;
18312 
18313         /* set affectsLikelihood to NO */
18314         p->affectsLikelihood = NO;
18315 
18316         /* set cpp event pointers to NULL */
18317         p->nEvents = NULL;
18318         p->position = NULL;
18319         p->rateMult = NULL;
18320 
18321         /* set header and name to NULL */
18322         p->paramHeader = NULL;
18323         p->name = NULL;
18324 
18325         /* set up relevant partitions */
18326         p->nRelParts = numRelParts;
18327         p->relParts = relevantParts + nRelParts;
18328         nRelParts += numRelParts;
18329         for (i=n=0; i<numCurrentDivisions; i++)
18330             if (isPartTouched[i] == YES)
18331                 p->relParts[n++] = i;
18332 
18333         /* get partition descriptor */
18334         SafeStrcat(&partString,"");
18335         FillRelPartsString (p, &partString);
18336 
18337         /* set up information for parameter */
18338         if (j == P_TRATIO)
18339             {
18340             /* Set up tratio ****************************************************************************************/
18341             p->paramType = P_TRATIO;
18342             p->nValues = 1;         /* we store only the ratio */
18343             p->nSubValues = 0;
18344             p->min = 0.0;
18345             p->max = POS_INFINITY;
18346             for (i=0; i<numCurrentDivisions; i++)
18347                 if (isPartTouched[i] == YES)
18348                     modelSettings[i].tRatio = p;
18349 
18350             p->paramTypeName = "Transition and transversion rates";
18351             SafeStrcat(&p->name, "Tratio");
18352             SafeStrcat(&p->name, partString);
18353 
18354             /* find the parameter x prior type */
18355             if (!strcmp(mp->tRatioPr,"Beta"))
18356                 {
18357                 p->paramId = TRATIO_DIR;
18358                 }
18359             else
18360                 p->paramId = TRATIO_FIX;
18361 
18362             if (p->paramId != TRATIO_FIX)
18363                 p->printParam = YES;
18364             if (!strcmp(mp->tratioFormat,"Ratio"))
18365                 {
18366                 /* report ti/tv ratio */
18367                 SafeStrcat (&p->paramHeader,"kappa");
18368                 SafeStrcat (&p->paramHeader, partString);
18369                 }
18370             else
18371                 {
18372                 /* report prop. of ratesum (Dirichlet) */
18373                 SafeStrcat (&p->paramHeader,"ti");
18374                 SafeStrcat (&p->paramHeader, partString);
18375                 SafeStrcat (&p->paramHeader, "\ttv");
18376                 SafeStrcat (&p->paramHeader, partString);
18377                 }
18378             }
18379         else if (j == P_REVMAT)
18380             {
18381             /* Set up revMat ****************************************************************************************/
18382             p->paramType = P_REVMAT;
18383             if (m->dataType == PROTEIN)
18384                 p->nValues = 190;
18385             else
18386                 p->nValues = 6;
18387             p->nSubValues = 0;
18388             if (!strcmp(mp->nst, "Mixed"))
18389                 p->nIntValues = 6;
18390             else
18391                 p->nIntValues = 0;
18392             p->min = 0.0;
18393             p->max = 1.0;       /* adjust later for REVMAT_MIX, see a few lines below */
18394             for (i=0; i<numCurrentDivisions; i++)
18395                 if (isPartTouched[i] == YES)
18396                     modelSettings[i].revMat = p;
18397 
18398             p->paramTypeName = "Rates of reversible rate matrix";
18399             SafeStrcat(&p->name, "Revmat");
18400             SafeStrcat(&p->name, partString);
18401 
18402             /* find the parameter x prior type */
18403             if (m->dataType == PROTEIN)
18404                 {
18405                 if (!strcmp(mp->aaRevMatPr,"Dirichlet"))
18406                     p->paramId = REVMAT_DIR;
18407                 else
18408                     p->paramId = REVMAT_FIX;
18409                 if (p->paramId != REVMAT_FIX)
18410                     p->printParam = YES;
18411 
18412                 for (n1=0; n1<20; n1++)
18413                     {
18414                     for (n2=n1+1; n2<20; n2++)
18415                         {
18416                         if (n1==0 && n2==1)
18417                             {
18418                             sprintf (temp, "r(%c<->%c)", StateCode_AA(n1), StateCode_AA(n2));
18419                             SafeStrcat (&p->paramHeader, temp);
18420                             SafeStrcat (&p->paramHeader, partString);
18421                             }
18422                         else
18423                             {
18424                             sprintf (temp, "\tr(%c<->%c)", StateCode_AA(n1), StateCode_AA(n2));
18425                             SafeStrcat (&p->paramHeader, temp);
18426                             SafeStrcat (&p->paramHeader, partString);
18427                             }
18428                         }
18429                     }
18430                 }
18431             else
18432                 {
18433                 if (!strcmp(mp->nst, "Mixed"))
18434                     {
18435                     p->paramId = REVMAT_MIX;
18436                     p->max = 1E6;   /* some large value */
18437                     }
18438                 else if (!strcmp(mp->revMatPr,"Dirichlet"))
18439                     p->paramId = REVMAT_DIR;
18440                 else
18441                     p->paramId = REVMAT_FIX;
18442                 if (p->paramId != REVMAT_FIX)
18443                     p->printParam = YES;
18444 
18445                 for (n1=0; n1<4; n1++)
18446                     {
18447                     for (n2=n1+1; n2<4; n2++)
18448                         {
18449                         if (n1==0 && n2==1)
18450                             {
18451                             sprintf (temp, "r(%c<->%c)", StateCode_NUC4(n1), StateCode_NUC4(n2));
18452                             SafeStrcat (&p->paramHeader, temp);
18453                             SafeStrcat (&p->paramHeader, partString);
18454                             }
18455                         else
18456                             {
18457                             sprintf (temp, "\tr(%c<->%c)", StateCode_NUC4(n1), StateCode_NUC4(n2));
18458                             SafeStrcat (&p->paramHeader, temp);
18459                             SafeStrcat (&p->paramHeader, partString);
18460                             }
18461                         }
18462                     }
18463                 if (p->paramId == REVMAT_MIX)
18464                     {
18465                     sprintf (temp, "\tgtrsubmodel");
18466                     SafeStrcat (&p->paramHeader, temp);
18467                     SafeStrcat (&p->paramHeader, partString);
18468                     sprintf (temp, "\tk_revmat");
18469                     SafeStrcat (&p->paramHeader, temp);
18470                     SafeStrcat (&p->paramHeader, partString);
18471                     }
18472                 }
18473             }
18474         else if (j == P_OMEGA)
18475             {
18476             /* Set up omega *****************************************************************************************/
18477             p->paramType = P_OMEGA;
18478             p->min = 0.0;
18479             p->max = POS_INFINITY;
18480             if (!strcmp(mp->omegaVar, "M3"))
18481                 {
18482                 p->nValues = 3;         /* omega values */
18483                 p->nSubValues = 6;      /* category frequencies plus cache */
18484                 for (i=0; i<numCurrentDivisions; i++)
18485                     if (isPartTouched[i] == YES)
18486                         modelSettings[i].omega = p;
18487 
18488                 /* find the parameter x prior type */
18489                 if (!strcmp(mp->m3omegapr, "Exponential")      && !strcmp(mp->codonCatFreqPr, "Fixed"))
18490                     p->paramId = OMEGA_EF;
18491                 else if (!strcmp(mp->m3omegapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18492                     p->paramId = OMEGA_ED;
18493                 else if (!strcmp(mp->m3omegapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18494                     p->paramId = OMEGA_FF;
18495                 else if (!strcmp(mp->m3omegapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18496                     p->paramId = OMEGA_FD;
18497 
18498                 if (p->paramId != OMEGA_FF)
18499                     p->printParam = YES;
18500 
18501                 SafeStrcat (&p->paramHeader, "omega(1)");
18502                 SafeStrcat (&p->paramHeader, partString);
18503                 SafeStrcat (&p->paramHeader, "\tomega(2)");
18504                 SafeStrcat (&p->paramHeader, partString);
18505                 SafeStrcat (&p->paramHeader, "\tomega(3)");
18506                 SafeStrcat (&p->paramHeader, partString);
18507 
18508                 SafeStrcat (&p->paramHeader, "\tpi(1)");
18509                 SafeStrcat (&p->paramHeader, partString);
18510                 SafeStrcat (&p->paramHeader, "\tpi(2)");
18511                 SafeStrcat (&p->paramHeader, partString);
18512                 SafeStrcat (&p->paramHeader, "\tpi(3)");
18513                 SafeStrcat (&p->paramHeader, partString);
18514                 }
18515             else if (!strcmp(mp->omegaVar, "M10"))
18516                 {
18517                 p->nValues = mp->numM10BetaCats + mp->numM10GammaCats;
18518                 p->nSubValues = mp->numM10BetaCats + mp->numM10GammaCats + 8;
18519                 for (i=0; i<numCurrentDivisions; i++)
18520                     if (isPartTouched[i] == YES)
18521                         modelSettings[i].omega = p;
18522 
18523                 /* find the parameter x prior type */
18524                 if      (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18525                     p->paramId = OMEGA_10UUB;
18526                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18527                     p->paramId = OMEGA_10UUF;
18528                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18529                     p->paramId = OMEGA_10UEB;
18530                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18531                     p->paramId = OMEGA_10UEF;
18532                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18533                     p->paramId = OMEGA_10UFB;
18534                 else if (!strcmp(mp->m10betapr, "Uniform")     && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18535                     p->paramId = OMEGA_10UFF;
18536                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18537                     p->paramId = OMEGA_10EUB;
18538                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18539                     p->paramId = OMEGA_10EUF;
18540                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18541                     p->paramId = OMEGA_10EEB;
18542                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18543                     p->paramId = OMEGA_10EEF;
18544                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18545                     p->paramId = OMEGA_10EFB;
18546                 else if (!strcmp(mp->m10betapr, "Exponential") && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18547                     p->paramId = OMEGA_10EFF;
18548                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18549                     p->paramId = OMEGA_10FUB;
18550                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18551                     p->paramId = OMEGA_10FUF;
18552                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18553                     p->paramId = OMEGA_10FEB;
18554                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18555                     p->paramId = OMEGA_10FEF;
18556                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18557                     p->paramId = OMEGA_10FFB;
18558                 else if (!strcmp(mp->m10betapr, "Fixed")       && !strcmp(mp->m10gammapr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18559                     p->paramId = OMEGA_10FFF;
18560 
18561                 if (p->paramId != OMEGA_10FFF)
18562                     p->printParam = YES;
18563                 for (i=0; i<p->nValues; i++)
18564                     {
18565                     if (i==0)
18566                         sprintf (temp, "omega(%d)", i+1);
18567                     else
18568                         sprintf (temp, "\tomega(%d)", i+1);
18569                     SafeStrcat (&p->paramHeader, temp);
18570                     SafeStrcat (&p->paramHeader, partString);
18571                     }
18572                 SafeStrcat (&p->paramHeader, "\tbeta(alpha)");
18573                 SafeStrcat (&p->paramHeader, partString);
18574                 SafeStrcat (&p->paramHeader, "\tbeta(beta)");
18575                 SafeStrcat (&p->paramHeader, partString);
18576                 SafeStrcat (&p->paramHeader, "\tgamma(alpha)");
18577                 SafeStrcat (&p->paramHeader, partString);
18578                 SafeStrcat (&p->paramHeader, "\tgamma(beta)");
18579                 SafeStrcat (&p->paramHeader, partString);
18580                 SafeStrcat (&p->paramHeader, "\tpi(1)");
18581                 SafeStrcat (&p->paramHeader, partString);
18582                 SafeStrcat (&p->paramHeader, "\tpi(2)");
18583                 SafeStrcat (&p->paramHeader, partString);
18584                 }
18585             else if (!strcmp(mp->omegaVar, "Ny98"))
18586                 {
18587                 p->nValues = 3;     /* omega values */
18588                 p->nSubValues = 6;  /* omega category frequencies plus cache */
18589                 for (i=0; i<numCurrentDivisions; i++)
18590                     if (isPartTouched[i] == YES)
18591                         modelSettings[i].omega = p;
18592 
18593                 /* find the parameter x prior type */
18594                 if      (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18595                     p->paramId = OMEGA_BUD;
18596                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18597                     p->paramId = OMEGA_BUF;
18598                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18599                     p->paramId = OMEGA_BED;
18600                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18601                     p->paramId = OMEGA_BEF;
18602                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18603                     p->paramId = OMEGA_BFD;
18604                 else if (!strcmp(mp->ny98omega1pr, "Beta")  && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18605                     p->paramId = OMEGA_BFF;
18606                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18607                     p->paramId = OMEGA_FUD;
18608                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Uniform")     && !strcmp(mp->codonCatFreqPr, "Fixed"))
18609                     p->paramId = OMEGA_FUF;
18610                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18611                     p->paramId = OMEGA_FED;
18612                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Exponential") && !strcmp(mp->codonCatFreqPr, "Fixed"))
18613                     p->paramId = OMEGA_FEF;
18614                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Dirichlet"))
18615                     p->paramId = OMEGA_FFD;
18616                 else if (!strcmp(mp->ny98omega1pr, "Fixed") && !strcmp(mp->ny98omega3pr, "Fixed")       && !strcmp(mp->codonCatFreqPr, "Fixed"))
18617                     p->paramId = OMEGA_FFF;
18618 
18619                 if (p->paramId != OMEGA_FFF)
18620                     p->printParam = YES;
18621                 SafeStrcat (&p->paramHeader, "omega(-)");
18622                 SafeStrcat (&p->paramHeader, partString);
18623                 SafeStrcat (&p->paramHeader, "\tomega(N)");
18624                 SafeStrcat (&p->paramHeader, partString);
18625                 SafeStrcat (&p->paramHeader, "\tomega(+)");
18626                 SafeStrcat (&p->paramHeader, partString);
18627 
18628                 SafeStrcat (&p->paramHeader, "\tpi(-)");
18629                 SafeStrcat (&p->paramHeader, partString);
18630                 SafeStrcat (&p->paramHeader, "\tpi(N)");
18631                 SafeStrcat (&p->paramHeader, partString);
18632                 SafeStrcat (&p->paramHeader, "\tpi(+)");
18633                 SafeStrcat (&p->paramHeader, partString);
18634                 }
18635             else
18636                 {
18637                 p->nValues = 1;
18638                 p->nSubValues = 0;
18639                 for (i=0; i<numCurrentDivisions; i++)
18640                     if (isPartTouched[i] == YES)
18641                         modelSettings[i].omega = p;
18642 
18643                 /* find the parameter x prior type */
18644                 if (!strcmp(mp->omegaPr,"Dirichlet"))
18645                     p->paramId = OMEGA_DIR;
18646                 else
18647                     p->paramId = OMEGA_FIX;
18648 
18649                 if (p->paramId != OMEGA_FIX)
18650                     p->printParam = YES;
18651                 SafeStrcat (&p->paramHeader, "omega");
18652                 SafeStrcat (&p->paramHeader, partString);
18653                 }
18654             p->paramTypeName = "Positive selection (omega) model";
18655             SafeStrcat(&p->name, "Omega");
18656             SafeStrcat(&p->name, partString);
18657             }
18658         else if (j == P_PI)
18659             {
18660             /* Set up state frequencies *****************************************************************************/
18661             p->paramType = P_PI;
18662             p->min = 0.0;
18663             p->max = 1.0;
18664             for (i=0; i<numCurrentDivisions; i++)
18665                 if (isPartTouched[i] == YES)
18666                     modelSettings[i].stateFreq = p;
18667 
18668             if (mp->dataType == STANDARD)
18669                 {
18670                 p->paramTypeName = "Symmetric diricihlet/beta distribution alpha_i parameter";
18671                 SafeStrcat(&p->name, "Alpha_symdir");
18672                 /* boundaries for alpha_i */
18673                 p->min = ETA;
18674                 p->max = POS_INFINITY;
18675                 }
18676             else
18677                 {
18678                 p->paramTypeName = "Stationary state frequencies";
18679                 SafeStrcat(&p->name, "Pi");
18680                 }
18681             SafeStrcat(&p->name, partString);
18682 
18683             /* find the parameter x prior type */
18684             /* and the number of values and subvalues needed */
18685             if (mp->dataType == STANDARD)
18686                 {
18687                 /* find number of model states */
18688                 m->numModelStates = 2;
18689                 for (c=0; c<numChar; c++)
18690                     {
18691                     for (i=0; i<p->nRelParts; i++)
18692                         {
18693                         if (partitionId[c][partitionNum] == p->relParts[i] + 1 && charInfo[c].numStates > m->numModelStates)
18694                             m->numModelStates = charInfo[c].numStates;
18695                         }
18696                     }
18697                 for (i=0; i<p->nRelParts; i++)
18698                     modelSettings[p->relParts[i]].numModelStates = m->numModelStates;
18699 
18700                 /* symmetric hyperprior with only one variable (0 if equal) */
18701                 p->nValues = 1;     /* set to 0 below for the SYMPI_EQUAL model */
18702                 if (!strcmp(mp->symPiPr,"Uniform"))
18703                     {
18704                     if (m->numModelStates > 2)
18705                         p->paramId = SYMPI_UNI_MS;
18706                     else
18707                         p->paramId = SYMPI_UNI;
18708                     }
18709                 else if (!strcmp(mp->symPiPr,"Exponential"))
18710                     {
18711                     if (m->numModelStates > 2)
18712                         p->paramId = SYMPI_EXP_MS;
18713                     else
18714                         p->paramId = SYMPI_EXP;
18715                     }
18716                 else if (!strcmp(mp->symPiPr,"Fixed"))
18717                     {
18718                     if (AreDoublesEqual(mp->symBetaFix, -1.0, 0.00001) == YES)
18719                         {
18720                         p->paramId = SYMPI_EQUAL;
18721                         p->nValues = 0;
18722                         }
18723                     else
18724                         {
18725                         if (m->numModelStates > 2)
18726                             p->paramId = SYMPI_FIX_MS;
18727                         else
18728                             p->paramId = SYMPI_FIX;
18729                         }
18730                     }
18731                 p->nSubValues = 0;  /* store state frequencies in p->stdStateFreqs */
18732                 if (p->paramId == SYMPI_EXP || p->paramId == SYMPI_EXP_MS || p->paramId == SYMPI_UNI || p->paramId == SYMPI_UNI_MS)
18733                     p->printParam = YES;
18734                 SafeStrcat (&p->paramHeader, "alpha_symdir");
18735                 SafeStrcat (&p->paramHeader, partString);
18736                 /* further processing done in ProcessStdChars */
18737                 }
18738             else
18739                 {
18740                 /* deal with all models except standard */
18741                 /* no hyperprior or fixed to one value, set default to 0  */
18742                 p->nValues = 0;
18743                 /* one subvalue for each state */
18744                 p->nSubValues = mp->nStates;    /* mp->nStates is set to 20 if DNA || RNA && nucmodel==PROTEIN */
18745                 if (!strcmp(mp->stateFreqPr, "Dirichlet"))
18746                     {
18747                     p->paramId = PI_DIR;
18748                     p->nValues = mp->nStates;
18749                     }
18750                 else if (!strcmp(mp->stateFreqPr, "Fixed") && !strcmp(mp->stateFreqsFixType,"User"))
18751                     p->paramId = PI_USER;
18752                 else if (!strcmp(mp->stateFreqPr, "Fixed") && !strcmp(mp->stateFreqsFixType,"Empirical"))
18753                     p->paramId = PI_EMPIRICAL;
18754                 else if (!strcmp(mp->stateFreqPr, "Fixed") && !strcmp(mp->stateFreqsFixType,"Equal"))
18755                     {
18756                     p->paramId = PI_EQUAL;
18757                     }
18758 
18759                 if (m->dataType == PROTEIN)
18760                     {
18761                     if (!strcmp(mp->aaModelPr, "Fixed"))
18762                         {
18763                         if (!strcmp(mp->aaModel, "Poisson"))
18764                             p->paramId = PI_EQUAL;
18765                         else if (!strcmp(mp->aaModel, "Equalin") || !strcmp(mp->aaModel, "Gtr"))
18766                             {
18767                             /* p->paramId stays to what it was set to above */
18768                             }
18769                         else
18770                             p->paramId = PI_FIXED;
18771                         }
18772                     else
18773                         p->paramId = PI_FIXED;
18774                     }
18775 
18776                 if (p->paramId == PI_DIR)
18777                     p->printParam = YES;
18778                 if (m->dataType == DNA || m->dataType == RNA)
18779                     {
18780                     if (!strcmp(mp->nucModel, "4by4"))
18781                         {
18782                         sprintf (temp, "pi(%c)", StateCode_NUC4(0));
18783                         SafeStrcat (&p->paramHeader,temp);
18784                         SafeStrcat (&p->paramHeader,partString);
18785                         for (n1=1; n1<4; n1++)
18786                             {
18787                             sprintf (temp, "\tpi(%c)", StateCode_NUC4(n1));
18788                             SafeStrcat (&p->paramHeader,temp);
18789                             SafeStrcat (&p->paramHeader,partString);
18790                             }
18791                         }
18792                     else if (!strcmp(mp->nucModel, "Doublet"))
18793                         {
18794                         State_DOUBLET(tempCodon,0);
18795                         sprintf (temp, "pi(%s)", tempCodon);
18796                         SafeStrcat (&p->paramHeader,temp);
18797                         SafeStrcat (&p->paramHeader,partString);
18798                         for (n1=1; n1<16; n1++)
18799                             {
18800                             State_DOUBLET(tempCodon,n1);
18801                             sprintf (temp, "\tpi(%s)", tempCodon);
18802                             SafeStrcat (&p->paramHeader,temp);
18803                             SafeStrcat (&p->paramHeader,partString);
18804                             }
18805                         }
18806                     else if (!strcmp(mp->nucModel, "Codon"))
18807                         {
18808                         for (c=0; c<p->nSubValues; c++)
18809                             {
18810                             if (mp->codonNucs[c][0] == 0)
18811                                 strcpy (tempCodon, "pi(A");
18812                             else if (mp->codonNucs[c][0] == 1)
18813                                 strcpy (tempCodon, "pi(C");
18814                             else if (mp->codonNucs[c][0] == 2)
18815                                 strcpy (tempCodon, "pi(G");
18816                             else
18817                                 strcpy (tempCodon, "pi(T");
18818                             if (mp->codonNucs[c][1] == 0)
18819                                 strcat (tempCodon, "A");
18820                             else if (mp->codonNucs[c][1] == 1)
18821                                 strcat (tempCodon, "C");
18822                             else if (mp->codonNucs[c][1] == 2)
18823                                 strcat (tempCodon, "G");
18824                             else
18825                                 strcat (tempCodon, "T");
18826                             if (mp->codonNucs[c][2] == 0)
18827                                 strcat (tempCodon, "A)");
18828                             else if (mp->codonNucs[c][2] == 1)
18829                                 strcat (tempCodon, "C)");
18830                             else if (mp->codonNucs[c][2] == 2)
18831                                 strcat (tempCodon, "G)");
18832                             else
18833                                 strcat (tempCodon, "T)");
18834                             if (c == 0)
18835                                 {
18836                                 SafeStrcat (&p->paramHeader, tempCodon);
18837                                 SafeStrcat (&p->paramHeader, partString);
18838                                 }
18839                             else
18840                                 {
18841                                 SafeStrcat (&p->paramHeader, "\t");
18842                                 SafeStrcat (&p->paramHeader, tempCodon);
18843                                 SafeStrcat (&p->paramHeader, partString);
18844                                 }
18845                             }
18846                         }
18847                     }
18848                 else if (m->dataType == PROTEIN)
18849                     {
18850                     if (FillRelPartsString (p, &partString) == YES)
18851                         {
18852                         SafeSprintf (&tempStr, &tempStrSize, "pi(Ala)%s\tpi(Arg)%s\tpi(Asn)%s\tpi(Asp)%s\tpi(Cys)%s\tpi(Gln)%s\tpi(Glu)%s\tpi(Gly)%s\tpi(His)%s\tpi(Ile)%s\tpi(Leu)%s\tpi(Lys)%s\tpi(Met)%s\tpi(Phe)%s\tpi(Pro)%s\tpi(Ser)%s\tpi(Thr)%s\tpi(Trp)%s\tpi(Tyr)%s\tpi(Val)%s",
18853                         partString, partString, partString, partString, partString, partString, partString, partString, partString, partString,
18854                         partString, partString, partString, partString, partString, partString, partString, partString, partString, partString);
18855                         SafeStrcat (&p->paramHeader, tempStr);
18856                         }
18857                     else
18858                         SafeStrcat (&p->paramHeader, "pi(Ala)\tpi(Arg)\tpi(Asn)\tpi(Asp)\tpi(Cys)\tpi(Gln)\tpi(Glu)\tpi(Gly)\tpi(His)\tpi(Ile)\tpi(Leu)\tpi(Lys)\tpi(Met)\tpi(Phe)\tpi(Pro)\tpi(Ser)\tpi(Thr)\tpi(Trp)\tpi(Tyr)\tpi(Val)");
18859                     }
18860                 else if (mp->dataType == RESTRICTION)
18861                     {
18862                     if (FillRelPartsString (p, &partString) == YES)
18863                         {
18864                         SafeSprintf (&tempStr, &tempStrSize, "pi(0)%s\tpi(1)%s", partString, partString);
18865                         SafeStrcat (&p->paramHeader, tempStr);
18866                         }
18867                     else
18868                         SafeStrcat (&p->paramHeader, "pi(0)\tpi(1)");
18869                     }
18870                 else
18871                     {
18872                     MrBayesPrint ("%s   Unknown data type in SetModelParams\n", spacer);
18873                     }
18874                 }
18875             }
18876         else if (j == P_MIXTURE_RATES)
18877             {
18878             /* Set up mixture of site rates *****************************************************************/
18879             p->paramType = P_MIXTURE_RATES;
18880             p->nValues = mp->numMixtCats;   /* used for the Dirichlet prior parameters */
18881             p->nSubValues = mp->numMixtCats;
18882             p->min = 1E-5;
18883             p->max = 100;
18884             for (i=0; i<numCurrentDivisions; i++)
18885                 if (isPartTouched[i] == YES)
18886                     modelSettings[i].mixtureRates = p;
18887             p->paramTypeName = "Rates of site rate mixture";
18888             SafeStrcpy(&p->name, "Mixturerates");
18889             SafeStrcat(&p->name, partString);
18890             for (i=0; i<p->nValues; ++i)
18891                 {
18892                 if (i!=0)
18893                     SafeStrcat(&p->paramHeader, "\t");
18894                 SafeSprintf(&tempStr, &tempStrSize, "mixturerates%s[%d]", partString, i+1);
18895                 SafeStrcat(&p->paramHeader, tempStr);
18896                 }
18897 
18898             /* find the parameter x prior type */
18899             p->paramId = MIXTURE_RATES;
18900 
18901             /* always print */
18902             p->printParam = YES;
18903             }
18904         else if (j == P_SHAPE)
18905             {
18906             /* Set up shape parameter of gamma/lnorm *****************************************************************/
18907             p->paramType = P_SHAPE;
18908             p->nValues = 1;
18909             if(!strcmp(mp->ratesModel, "Lnorm"))
18910                 p->nSubValues = mp->numLnormCats;
18911             else
18912                 p->nSubValues = mp->numGammaCats;
18913             p->min = 1E-5;
18914             p->max = 100;
18915             for (i=0; i<numCurrentDivisions; i++)
18916                 if (isPartTouched[i] == YES)
18917                     modelSettings[i].shape = p;
18918             if(!strcmp(mp->ratesModel, "LNorm"))
18919                 {
18920                 p->paramTypeName = "SD of scaled lognormal distribution of site rates";
18921                 SafeStrcat(&p->name, "Sigma");
18922                 SafeStrcat (&p->paramHeader, "sigma");
18923                 }
18924             else
18925                 {
18926                 p->paramTypeName = "Shape of scaled gamma distribution of site rates";
18927                 SafeStrcat(&p->name, "Alpha");
18928                 SafeStrcat (&p->paramHeader, "alpha");
18929                 }
18930             SafeStrcat(&p->name, partString);
18931             SafeStrcat (&p->paramHeader, partString);
18932 
18933             /* find the parameter x prior type */
18934             mp = &modelParams[p->relParts[0]];
18935             if (!strcmp(mp->shapePr,"Uniform"))
18936                 p->paramId = SHAPE_UNI;
18937             else if (!strcmp(mp->shapePr,"Exponential"))
18938                 p->paramId = SHAPE_EXP;
18939             else
18940                 p->paramId = SHAPE_FIX;
18941 
18942             if (p->paramId != SHAPE_FIX)
18943                 p->printParam = YES;
18944             }
18945        else if (j == P_PINVAR)
18946             {
18947             /* Set up proportion of invariable sites ****************************************************************/
18948             p->paramType = P_PINVAR;
18949             p->nValues = 1;
18950             p->nSubValues = 0;
18951             p->min = 0.0;
18952             p->max = 1.0;
18953             for (i=0; i<numCurrentDivisions; i++)
18954                 if (isPartTouched[i] == YES)
18955                     modelSettings[i].pInvar = p;
18956 
18957             p->paramTypeName = "Proportion of invariable sites";
18958             SafeStrcat(&p->name, "Pinvar");
18959             SafeStrcat(&p->name, partString);
18960 
18961             /* find the parameter x prior type */
18962             if (!strcmp(mp->pInvarPr,"Uniform"))
18963                 p->paramId = PINVAR_UNI;
18964             else
18965                 p->paramId = PINVAR_FIX;
18966 
18967             if (p->paramId != PINVAR_FIX)
18968                 p->printParam = YES;
18969             SafeStrcat (&p->paramHeader, "pinvar");
18970             SafeStrcat (&p->paramHeader, partString);
18971             }
18972         else if (j == P_CORREL)
18973             {
18974             /* Set up correlation parameter of adgamma model ********************************************************/
18975             p->paramType = P_CORREL;
18976             p->nValues = 1;
18977             p->nSubValues = mp->numGammaCats * mp->numGammaCats;
18978             p->min = -1.0;
18979             p->max = 1.0;
18980             for (i=0; i<numCurrentDivisions; i++)
18981                 if (isPartTouched[i] == YES)
18982                     modelSettings[i].correlation = p;
18983 
18984             p->paramTypeName = "Autocorrelation of gamma distribution of site rates";
18985             SafeStrcat(&p->name, "Rho");
18986             SafeStrcat(&p->name, partString);
18987             chainHasAdgamma = YES;
18988 
18989             /* find the parameter x prior type */
18990             if (!strcmp(mp->adGammaCorPr,"Uniform"))
18991                 p->paramId = CORREL_UNI;
18992             else
18993                 p->paramId = CORREL_FIX;
18994 
18995             if (p->paramId != CORREL_FIX)
18996                 p->printParam = YES;
18997             SafeStrcat (&p->paramHeader, "rho");
18998             SafeStrcat (&p->paramHeader, partString);
18999             }
19000         else if (j == P_SWITCH)
19001             {
19002             /* Set up switchRates for covarion model ****************************************************************/
19003             p->paramType = P_SWITCH;
19004             p->nValues = 2;
19005             p->nSubValues = mp->numGammaCats * mp->numGammaCats;
19006             p->min = 0.0;
19007             p->max = POS_INFINITY;
19008             for (i=0; i<numCurrentDivisions; i++)
19009                 if (isPartTouched[i] == YES)
19010                     modelSettings[i].switchRates = p;
19011 
19012             p->paramTypeName = "Switch rates of covarion model";
19013             SafeStrcat(&p->name, "s_cov");
19014             SafeStrcat(&p->name, partString);
19015 
19016             /* find the parameter x prior type */
19017             if (!strcmp(mp->covSwitchPr,"Uniform"))
19018                 p->paramId = SWITCH_UNI;
19019             else if (!strcmp(mp->covSwitchPr,"Exponential"))
19020                 p->paramId = SWITCH_EXP;
19021             else
19022                 p->paramId = SWITCH_FIX;
19023 
19024             if (p->paramId != SWITCH_FIX)
19025                 p->printParam = YES;
19026 
19027             SafeStrcat (&p->paramHeader, "s(off->on)");
19028             SafeStrcat (&p->paramHeader, partString);
19029             SafeStrcat (&p->paramHeader, "\ts(on->off)");
19030             SafeStrcat (&p->paramHeader, partString);
19031             }
19032         else if (j == P_RATEMULT)
19033             {
19034             /* Set up rateMult for partition specific rates ***********************************************************/
19035             p->paramType = P_RATEMULT;
19036             if (!strcmp(mp->ratePr,"Fixed"))
19037                 {
19038                 p->nValues = 1;
19039                 p->nSubValues = 0;
19040                 }
19041             else
19042                 {
19043                 p->nValues = p->nRelParts = numRelParts; /* keep scaled division rates in value                        */
19044                 p->nSubValues = p->nValues * 2;          /* keep number of uncompressed chars for scaling in subValue  */
19045                 }                                        /* also keep Dirichlet prior parameters here                  */
19046             p->min = POS_MIN;
19047             p->max = POS_INFINITY;
19048             for (i=0; i<numCurrentDivisions; i++)
19049                 if (isPartTouched[i] == YES)
19050                     modelSettings[i].rateMult = p;
19051 
19052             p->paramTypeName = "Partition-specific rate multiplier";
19053             SafeStrcat(&p->name, "Ratemultiplier");
19054             SafeStrcat(&p->name, partString);
19055 
19056             /* find the parameter x prior type */
19057             if (p->nSubValues == 0)
19058                 p->paramId = RATEMULT_FIX;
19059             else
19060                 p->paramId = RATEMULT_DIR;
19061 
19062             if (p->paramId != RATEMULT_FIX)
19063                 p->printParam = YES;
19064             for (i=0; i<numCurrentDivisions; i++)
19065                 {
19066                 if (isPartTouched[i] == YES)
19067                     {
19068                     sprintf (tempMult, "m{%d}", i+1);
19069                     if (i == 0)
19070                         SafeStrcat (&p->paramHeader, tempMult);
19071                     else
19072                         {
19073                         SafeStrcat (&p->paramHeader, "\t");
19074                         SafeStrcat (&p->paramHeader, tempMult);
19075                         }
19076                     }
19077                 }
19078             }
19079         else if (j == P_GENETREERATE)
19080             {
19081             /* Set up rateMult for gene specific rates ****************************************************************/
19082             p->paramType = P_GENETREERATE;
19083             p->nValues = p->nRelParts = numRelParts;    /* keep scaled division rates in value                        */
19084             p->nSubValues = p->nValues * 2;             /* keep number of uncompressed chars for scaling in subValue  */
19085                                                         /* also keep Dirichlet prior parameters here                  */
19086             p->min = POS_MIN;
19087             p->max = POS_INFINITY;
19088             for (i=0; i<numCurrentDivisions; i++)
19089                 if (isPartTouched[i] == YES)
19090                     modelSettings[i].geneTreeRateMult = p;
19091 
19092             p->paramTypeName = "Gene-specific rate multiplier";
19093             SafeStrcat(&p->name, "Generatemult");
19094             SafeStrcat(&p->name, partString);
19095 
19096             /* find the parameter x prior type */
19097             if (strcmp(mp->generatePr,"Fixed") == 0)
19098                 p->paramId = GENETREERATEMULT_FIX;
19099             else
19100                 p->paramId = GENETREERATEMULT_DIR;
19101 
19102             if (p->paramId == GENETREERATEMULT_FIX)
19103                 p->printParam = NO;
19104             else
19105                 p->printParam = YES;
19106 
19107             for (i=0; i<numCurrentDivisions; i++)
19108                 {
19109                 if (isPartTouched[i] == YES)
19110                     {
19111                     sprintf (tempMult, "g_m{%d}", i+1);
19112                     if (i == 0)
19113                         SafeStrcat (&p->paramHeader, tempMult);
19114                     else
19115                         {
19116                         SafeStrcat (&p->paramHeader, "\t");
19117                         SafeStrcat (&p->paramHeader, tempMult);
19118                         }
19119                     }
19120                 }
19121             }
19122         else if (j == P_TOPOLOGY)
19123             {
19124             /* Set up topology **************************************************************************************/
19125             p->paramType = P_TOPOLOGY;
19126             p->nValues = 0;
19127             p->nSubValues = 0;
19128             p->min = NEG_INFINITY;  /* NA */
19129             p->max = NEG_INFINITY;  /* NA */
19130             for (i=0; i<numCurrentDivisions; i++)
19131                 if (isPartTouched[i] == YES)
19132                     modelSettings[i].topology = p;
19133 
19134             p->paramTypeName = "Topology";
19135             SafeStrcat(&p->name, "Tau");
19136             SafeStrcat(&p->name, partString);
19137 
19138             /* check that the model is not parsimony for all of the relevant partitions */
19139             areAllPartsParsimony = YES;
19140             for (i=0; i<p->nRelParts; i++)
19141                 {
19142                 if (modelSettings[p->relParts[i]].parsModelId == NO)
19143                     areAllPartsParsimony = NO;
19144                 }
19145 
19146             /* check if topology is clock or nonclock */
19147             nClockBrlens = 0;
19148             nCalibratedBrlens = 0;
19149             nRelaxedBrlens = 0;
19150             if (areAllPartsParsimony == NO)
19151                 {
19152                 for (i=0; i<p->nRelParts; i++)
19153                     {
19154                     if (!strcmp(modelParams[p->relParts[i]].brlensPr, "Clock"))
19155                         {
19156                         nClockBrlens++;
19157                         if (strcmp(modelParams[p->relParts[i]].clockVarPr,"Strict") != 0)  /* not strict */
19158                             nRelaxedBrlens++;
19159                         if (!strcmp(modelParams[p->relParts[i]].nodeAgePr,"Calibrated"))
19160                             nCalibratedBrlens++;
19161                         }
19162                     }
19163                 }
19164 
19165             /* now find the parameter x prior type */
19166             if (areAllPartsParsimony == YES)
19167                 {
19168                 if (!strcmp(mp->topologyPr, "Uniform"))
19169                     p->paramId = TOPOLOGY_PARSIMONY_UNIFORM;
19170                 else if (!strcmp(mp->topologyPr,"Constraints"))
19171                     p->paramId = TOPOLOGY_PARSIMONY_CONSTRAINED;
19172                 else
19173                     p->paramId = TOPOLOGY_PARSIMONY_FIXED;
19174                 /* For this case, we also need to set the brlens ptr of the relevant partitions
19175                    so that it points to the topology parameter, since the rest of the
19176                    program will try to access the tree through this pointer. In FillTreeParams,
19177                    we will make sure that a pure parsimony topology parameter contains a pointer
19178                    to the relevant tree (like a brlens parameter would normally) */
19179                 for (i=0; i<p->nRelParts; i++)
19180                     modelSettings[p->relParts[i]].brlens = p;
19181                 }
19182             else
19183                 {
19184                 /* we assume for now that there is only one branch length; we will correct this
19185                    later in AllocateTreeParams if there are more than one set of branch lengths,
19186                    which is only possible for non-clock trees */
19187                 if (!strcmp(mp->topologyPr, "Speciestree"))
19188                     p->paramId = TOPOLOGY_SPECIESTREE;
19189                 else if (!strcmp(mp->topologyPr, "Uniform") && nClockBrlens == 0)
19190                     p->paramId = TOPOLOGY_NCL_UNIFORM_HOMO;
19191                 else if (!strcmp(mp->topologyPr,"Constraints") && nClockBrlens == 0)
19192                     p->paramId = TOPOLOGY_NCL_CONSTRAINED_HOMO;
19193                 else if (!strcmp(mp->topologyPr,"Fixed") && nClockBrlens == 0)
19194                     p->paramId = TOPOLOGY_NCL_FIXED_HOMO;
19195                 /* all below have clock branch lengths */
19196                 else if (!strcmp(mp->topologyPr, "Uniform") && nRelaxedBrlens == 0)
19197                     {
19198                     if (nCalibratedBrlens >= 1)
19199                         p->paramId = TOPOLOGY_CCL_UNIFORM;
19200                     else
19201                         p->paramId = TOPOLOGY_CL_UNIFORM;
19202                     }
19203                 else if (!strcmp(mp->topologyPr,"Constraints") && nRelaxedBrlens == 0)
19204                     {
19205                     if (nCalibratedBrlens >= 1)
19206                         p->paramId = TOPOLOGY_CCL_CONSTRAINED;
19207                     else
19208                         p->paramId = TOPOLOGY_CL_CONSTRAINED;
19209                     }
19210                 else if (!strcmp(mp->topologyPr,"Fixed") && nRelaxedBrlens == 0)
19211                     {
19212                     if (nCalibratedBrlens >= 1)
19213                         p->paramId = TOPOLOGY_CCL_FIXED;
19214                     else
19215                         p->paramId = TOPOLOGY_CL_FIXED;
19216                     }
19217                 /* all below have relaxed clock branch lengths */
19218                 else if (!strcmp(mp->topologyPr, "Uniform"))
19219                     {
19220                     if (nCalibratedBrlens >= 1)
19221                         p->paramId = TOPOLOGY_RCCL_UNIFORM;
19222                     else
19223                         p->paramId = TOPOLOGY_RCL_UNIFORM;
19224                     }
19225                 else if (!strcmp(mp->topologyPr,"Constraints"))
19226                     {
19227                     if (nCalibratedBrlens >= 1)
19228                         p->paramId = TOPOLOGY_RCCL_CONSTRAINED;
19229                     else
19230                         p->paramId = TOPOLOGY_RCL_CONSTRAINED;
19231                     }
19232                 else if (!strcmp(mp->topologyPr,"Fixed"))
19233                     {
19234                     if (nCalibratedBrlens >= 1)
19235                         p->paramId = TOPOLOGY_RCCL_FIXED;
19236                     else
19237                         p->paramId = TOPOLOGY_RCL_FIXED;
19238                     }
19239                 }
19240 
19241             /* should we print the topology? */
19242             for (i=0; i<p->nRelParts; i++)
19243                 if (strcmp(modelParams[p->relParts[i]].treeFormat,"Topology") != 0)
19244                     break;
19245             if (i == p->nRelParts)
19246                 p->printParam = YES;
19247             else
19248                 p->printParam = NO;
19249             /* but always print parsimony topology */
19250             if (areAllPartsParsimony == YES)
19251                 p->printParam = YES;
19252             /* and never print fixed topologies */
19253             if (p->paramId == TOPOLOGY_RCL_FIXED ||
19254                 p->paramId == TOPOLOGY_RCCL_FIXED ||
19255                 p->paramId == TOPOLOGY_CL_FIXED ||
19256                 p->paramId == TOPOLOGY_CCL_FIXED ||
19257                 p->paramId == TOPOLOGY_NCL_FIXED ||
19258                 p->paramId == TOPOLOGY_PARSIMONY_FIXED)
19259                 p->printParam = NO;
19260             }
19261         else if (j == P_BRLENS)
19262             {
19263             /* Set up branch lengths ********************************************************************************/
19264             p->paramType = P_BRLENS;
19265             p->nValues = 0;
19266             p->nSubValues = 0;
19267             p->min = 0.0;
19268             p->max = POS_INFINITY;
19269             for (i=0; i<numCurrentDivisions; i++)
19270                 if (isPartTouched[i] == YES)
19271                     modelSettings[i].brlens = p;
19272 
19273             p->paramTypeName = "Branch lengths";
19274             SafeStrcat(&p->name, "V");
19275             SafeStrcat(&p->name, partString);
19276 
19277             /* find the parameter x prior type */
19278             if (modelSettings[p->relParts[0]].parsModelId == YES)
19279                 p->paramId = BRLENS_PARSIMONY;
19280             else
19281                 {
19282                 if (!strcmp(mp->brlensPr, "Clock"))
19283                     {
19284                     if (!strcmp(mp->clockPr,"Uniform"))
19285                         p->paramId = BRLENS_CLOCK_UNI;
19286                     else if (!strcmp(mp->clockPr,"Coalescence"))
19287                         p->paramId = BRLENS_CLOCK_COAL;
19288                     else if (!strcmp(mp->clockPr,"Birthdeath"))
19289                         p->paramId = BRLENS_CLOCK_BD;
19290                     else if (!strcmp(mp->clockPr,"Speciestreecoalescence"))
19291                         p->paramId = BRLENS_CLOCK_SPCOAL;
19292                     else if (!strcmp(mp->clockPr,"Fossilization"))
19293                         p->paramId = BRLENS_CLOCK_FOSSIL;
19294                     else if (!strcmp(mp->clockPr,"Fixed"))
19295                         p->paramId = BRLENS_CLOCK_FIXED;
19296                     }
19297                 else if (!strcmp(mp->brlensPr, "Unconstrained"))
19298                     {
19299                     if (!strcmp(mp->unconstrainedPr,"Uniform"))
19300                         p->paramId = BRLENS_UNI;
19301                     else if (!strcmp(mp->unconstrainedPr,"Exponential"))
19302                         p->paramId = BRLENS_EXP;
19303                     else if (!strcmp(mp->unconstrainedPr,"GammaDir"))
19304                         p->paramId = BRLENS_GamDir;
19305                     else if (!strcmp(mp->unconstrainedPr,"invGamDir"))
19306                         p->paramId = BRLENS_iGmDir;
19307                     else if (!strcmp(mp->unconstrainedPr,"twoExp"))
19308                         p->paramId = BRLENS_twoExp;
19309                     }
19310                 else if (!strcmp(mp->brlensPr,"Fixed"))
19311                     {
19312                     p->paramId = BRLENS_FIXED;
19313                     }
19314                 }
19315 
19316             /* should we print the branch lengths? */
19317             for (i=0; i<p->nRelParts; i++)
19318                 if (strcmp(modelParams[p->relParts[i]].treeFormat,"Topology") != 0)
19319                     break;
19320             if (i < p->nRelParts)
19321                 p->printParam = YES;
19322             else
19323                 p->printParam = NO;
19324             }
19325         else if (j == P_SPECIESTREE)
19326             {
19327             /* Set up species tree **************************************************************************************/
19328             p->paramType = P_SPECIESTREE;
19329             p->nValues = 0;
19330             p->nSubValues = 0;
19331             p->min = NEG_INFINITY;  /* NA */
19332             p->max = NEG_INFINITY;  /* NA */
19333             for (i=0; i<numCurrentDivisions; i++)
19334                 if (isPartTouched[i] == YES)
19335                     modelSettings[i].speciesTree = p;
19336 
19337             p->paramTypeName = "Species tree";
19338             SafeStrcat(&p->name, "Spt");
19339             SafeStrcat(&p->name, partString);
19340 
19341             /* check that the model is not parsimony for all of the relevant partitions */
19342             areAllPartsParsimony = YES; /* FIXME: Not used (from clang static analyzer) */
19343             for (i=0; i<p->nRelParts; i++)
19344                 {
19345                 if (modelSettings[p->relParts[i]].parsModelId == NO)
19346                     areAllPartsParsimony = NO; /* FIXME: Not used (from clang static analyzer) */
19347                 }
19348 
19349             /* find the parameter x prior type */
19350             p->paramId = SPECIESTREE_UNIFORM;
19351 
19352             /* should we print the tree? */
19353             p->printParam = YES;
19354             }
19355         else if (j == P_SPECRATE)
19356             {
19357             /* Set up speciation rate ******************************************************************************/
19358             p->paramType = P_SPECRATE;
19359             if (!strcmp(mp->clockPr,"Fossilization"))
19360                 p->nValues = mp->birthRateShiftNum +1;  // rate in each time interval
19361             else
19362                 p->nValues = 1;
19363             p->nSubValues = 0;
19364             p->min = POS_MIN;
19365             p->max = POS_INFINITY;
19366             for (i=0; i<numCurrentDivisions; i++)
19367                 if (isPartTouched[i] == YES)
19368                     modelSettings[i].speciationRates = p;
19369 
19370             p->paramTypeName = "Speciation rate";
19371             SafeStrcat(&p->name, "Net_speciation");
19372             SafeStrcat(&p->name, partString);
19373 
19374             /* find the parameter x prior type */
19375             if (!strcmp(mp->speciationPr,"Uniform"))
19376                 p->paramId = SPECRATE_UNI;
19377             else if (!strcmp(mp->speciationPr,"Exponential"))
19378                 p->paramId = SPECRATE_EXP;
19379             else
19380                 p->paramId = SPECRATE_FIX;
19381 
19382             if (p->paramId != SPECRATE_FIX)
19383                 p->printParam = YES;
19384 
19385             if (p->nValues == 1)
19386                 {
19387                 SafeStrcat (&p->paramHeader, "net_speciation");
19388                 SafeStrcat (&p->paramHeader, partString);
19389                 }
19390             else for (i = 0; i < p->nValues; i++)
19391                 {
19392                 sprintf (tempStr, "\tnet_speciation_%d", i+1);
19393                 SafeStrcat (&p->paramHeader, tempStr);
19394                 SafeStrcat (&p->paramHeader, partString);
19395                 }
19396             }
19397         else if (j == P_EXTRATE)
19398             {
19399             /* Set up extinction rates ******************************************************************************/
19400             p->paramType = P_EXTRATE;
19401             if (!strcmp(mp->clockPr,"Fossilization"))
19402                 p->nValues = mp->deathRateShiftNum +1;  // rate in each time interval
19403             else
19404                 p->nValues = 1;
19405             p->nSubValues = 0;
19406             p->min = 0.0;
19407             p->max = 1.0;
19408             for (i=0; i<numCurrentDivisions; i++)
19409                 if (isPartTouched[i] == YES)
19410                     modelSettings[i].extinctionRates = p;
19411 
19412             p->paramTypeName = "Extinction rate";
19413             SafeStrcat(&p->name, "Relative_extinction");
19414             SafeStrcat(&p->name, partString);
19415 
19416             /* find the parameter x prior type */
19417             if (!strcmp(mp->extinctionPr,"Beta"))
19418                 p->paramId = EXTRATE_BETA;
19419             else
19420                 p->paramId = EXTRATE_FIX;
19421 
19422             if (p->paramId != EXTRATE_FIX)
19423                 p->printParam = YES;
19424 
19425             if (p->nValues == 1)
19426                 {
19427                 SafeStrcat (&p->paramHeader, "relative_extinction");
19428                 SafeStrcat (&p->paramHeader, partString);
19429                 }
19430             else for (i = 0; i < p->nValues; i++)
19431                 {
19432                 sprintf (tempStr, "\trelative_extinction_%d", i+1);
19433                 SafeStrcat (&p->paramHeader, tempStr);
19434                 SafeStrcat (&p->paramHeader, partString);
19435                 }
19436             }
19437         else if (j == P_FOSLRATE)
19438             {
19439             /* Set up fossilization rates */
19440             p->paramType = P_FOSLRATE;
19441             p->nValues = mp->fossilSamplingNum +1;  // rate in each time interval
19442             p->nSubValues = 0;
19443             p->min = 0.0;
19444             p->max = 1.0;
19445             for (i=0; i<numCurrentDivisions; i++)
19446                 if (isPartTouched[i] == YES)
19447                     modelSettings[i].fossilizationRates = p;
19448 
19449             p->paramTypeName = "Fossilization rate";
19450             SafeStrcat(&p->name, "Relative_fossilization");
19451             SafeStrcat(&p->name, partString);
19452 
19453             /* find the parameter x prior type */
19454             if (!strcmp(mp->fossilizationPr,"Beta"))
19455                 p->paramId = FOSLRATE_BETA;
19456             else
19457                 p->paramId = FOSLRATE_FIX;
19458 
19459             if (p->paramId != FOSLRATE_FIX)
19460                 p->printParam = YES;
19461 
19462             if (p->nValues == 1)
19463                 {
19464                 SafeStrcat (&p->paramHeader, "relative_fossilization");
19465                 SafeStrcat (&p->paramHeader, partString);
19466                 }
19467             else for (i = 0; i < p->nValues; i++)
19468                 {
19469                 sprintf (tempStr, "\trelative_fossilization_%d", i+1);
19470                 SafeStrcat (&p->paramHeader, tempStr);
19471                 SafeStrcat (&p->paramHeader, partString);
19472                 }
19473             }
19474         else if (j == P_POPSIZE)
19475             {
19476             /* Set up population size *****************************************************************************************/
19477             p->paramType = P_POPSIZE;
19478             if (!strcmp(mp->topologyPr,"Speciestree") && !strcmp(mp->popVarPr, "Variable"))
19479                 p->nValues = 2 * numSpecies;
19480             else
19481                 p->nValues = 1;
19482             p->nSubValues = 0;
19483             p->min = POS_MIN;
19484             p->max = POS_INFINITY;
19485             for (i=0; i<numCurrentDivisions; i++)
19486                 if (isPartTouched[i] == YES)
19487                     modelSettings[i].popSize = p;
19488 
19489             p->paramTypeName = "Coalescent process population size parameter";
19490             SafeStrcat(&p->name, "Popsize");
19491             SafeStrcat(&p->name, partString);
19492 
19493             /* find the parameter x prior type */
19494             if (!strcmp(mp->popSizePr,"Uniform"))
19495                 {
19496                 p->paramId      = POPSIZE_UNI;
19497                 p->LnPriorRatio = &LnProbRatioUniform;
19498                 p->priorParams  = mp->popSizeUni;
19499                 p->LnPriorProb  = &LnPriorProbUniform;
19500                 }
19501             else if (!strcmp(mp->popSizePr,"Normal"))
19502                 {
19503                 p->paramId      = POPSIZE_NORMAL;
19504                 p->LnPriorRatio = &LnProbRatioTruncatedNormal;
19505                 p->priorParams  = mp->popSizeNormal;
19506                 p->LnPriorProb  = &LnPriorProbTruncatedNormal;
19507                 }
19508             else if (!strcmp(mp->popSizePr,"Lognormal"))
19509                 {
19510                 p->paramId      = POPSIZE_LOGNORMAL;
19511                 p->LnPriorRatio = &LnProbRatioLognormal;
19512                 p->priorParams  = mp->popSizeLognormal;
19513                 p->LnPriorProb  = &LnPriorProbLognormal;
19514                 }
19515             else if (!strcmp(mp->popSizePr,"Gamma"))
19516                 {
19517                 p->paramId      = POPSIZE_GAMMA;
19518                 p->LnPriorRatio = &LnProbRatioGamma;
19519                 p->priorParams  = mp->popSizeGamma;
19520                 p->LnPriorProb  = &LnPriorProbGamma;
19521                 }
19522             else
19523                 {
19524                 p->paramId      = POPSIZE_FIX;
19525                 p->LnPriorRatio = NULL;
19526                 p->priorParams  = &mp->popSizeFix;
19527                 p->LnPriorProb  = &LnPriorProbFix;
19528                 }
19529 
19530             if (p->paramId != POPSIZE_FIX && p->nValues == 1)
19531                 p->printParam = YES;
19532             SafeStrcat (&p->paramHeader, "popsize");
19533             SafeStrcat (&p->paramHeader, partString);
19534             }
19535         else if (j == P_GROWTH)
19536             {
19537             /* Set up growth rate ************************************************************************************/
19538             p->paramType = P_GROWTH;
19539             p->nValues = 1;
19540             p->nSubValues = 0;
19541             p->min = 0.0;
19542             p->max = POS_INFINITY;
19543             for (i=0; i<numCurrentDivisions; i++)
19544                 if (isPartTouched[i] == YES)
19545                     modelSettings[i].growthRate = p;
19546 
19547             p->paramTypeName = "Population growth rate";
19548             SafeStrcat(&p->name, "R_pop");
19549             SafeStrcat(&p->name, partString);
19550 
19551             /* find the parameter x prior type */
19552             if (!strcmp(mp->growthPr,"Uniform"))
19553                 {
19554                 p->paramId = GROWTH_UNI;
19555                 p->priorParams = mp->growthUni;
19556                 p->min = mp->growthUni[0];
19557                 p->max = mp->growthUni[1];
19558                 p->LnPriorRatio = &LnProbRatioUniform;
19559                 p->LnPriorProb = &LnPriorProbUniform;
19560                 }
19561             else if (!strcmp(mp->growthPr,"Exponential"))
19562                 {
19563                 p->paramId = GROWTH_EXP;
19564                 p->priorParams = &mp->growthExp;
19565                 p->min = GROWTH_MIN;
19566                 p->max = GROWTH_MAX;
19567                 p->LnPriorRatio = &LnProbRatioExponential;
19568                 p->LnPriorProb = &LnPriorProbExponential;
19569                 }
19570             else if (!strcmp(mp->growthPr,"Normal"))
19571                 {
19572                 p->paramId = GROWTH_NORMAL;
19573                 p->priorParams = mp->growthNorm;
19574                 p->min = GROWTH_MIN;
19575                 p->max = GROWTH_MAX;
19576                 p->LnPriorRatio = &LnProbRatioTruncatedNormal;
19577                 p->LnPriorProb = &LnPriorProbTruncatedNormal;
19578                 }
19579             else
19580                 {
19581                 p->paramId = GROWTH_FIX;
19582                 p->priorParams = &mp->growthFix;
19583                 p->min = p->max = mp->growthFix;
19584                 p->LnPriorRatio = &LnProbRatioFix;
19585                 p->LnPriorProb = &LnPriorProbFix;
19586                 }
19587 
19588             if (p->paramId != GROWTH_FIX)
19589                 p->printParam = YES;
19590             SafeStrcat (&p->paramHeader, "growthRate");
19591             SafeStrcat (&p->paramHeader, partString);
19592             }
19593         else if (j == P_AAMODEL)
19594             {
19595             /* Set up aamodel *****************************************************************************************/
19596             p->paramType = P_AAMODEL;
19597             p->nValues = 1;
19598             p->nSubValues = 10;
19599             p->min = 0;
19600             p->max = 9;
19601             for (i=0; i<numCurrentDivisions; i++)
19602                 if (isPartTouched[i] == YES)
19603                     modelSettings[i].aaModel = p;
19604 
19605             p->paramTypeName = "Aminoacid model";
19606             SafeStrcat(&p->name, "Aamodel");
19607             SafeStrcat(&p->name, partString);
19608 
19609             /* find the parameter x prior type */
19610             if (!strcmp(mp->aaModelPr,"Mixed"))
19611                 p->paramId = AAMODEL_MIX;
19612             else
19613                 p->paramId = AAMODEL_FIX;
19614 
19615             if (p->paramId != AAMODEL_FIX)
19616                 p->printParam = YES;
19617             SafeStrcat (&p->paramHeader, "aamodel");
19618             SafeStrcat (&p->paramHeader, partString);
19619             }
19620         else if (j == P_CPPRATE)
19621             {
19622             /* Set up cpprate *****************************************************************************************/
19623             p->paramType = P_CPPRATE;
19624             p->nValues = 1;
19625             p->nSubValues = 0;
19626             p->min = 0.0;
19627             p->max = POS_INFINITY;
19628             for (i=0; i<numCurrentDivisions; i++)
19629                 if (isPartTouched[i] == YES)
19630                     modelSettings[i].cppRate = p;
19631 
19632             p->paramTypeName = "Rate of rate-multiplying compound Poisson process";
19633             SafeStrcat(&p->name, "Lambda_cpp");
19634             SafeStrcat(&p->name, partString);
19635 
19636             /* find the parameter x prior type */
19637             if (!strcmp(mp->cppRatePr,"Exponential"))
19638                 p->paramId = CPPRATE_EXP;
19639             else
19640                 p->paramId = CPPRATE_FIX;
19641 
19642             if (p->paramId != CPPRATE_FIX)
19643                 p->printParam = YES;
19644             SafeStrcat (&p->paramHeader, "cppRate");
19645             SafeStrcat (&p->paramHeader, partString);
19646             }
19647         else if (j == P_CPPMULTDEV)
19648             {
19649             /* Set up sigma of cpp rate multipliers *****************************************************************************************/
19650             p->paramType = P_CPPMULTDEV;
19651             p->nValues = 1;
19652             p->nSubValues = 0;
19653             p->min = 0.0;
19654             p->max = POS_INFINITY;
19655             for (i=0; i<numCurrentDivisions; i++)
19656                 if (isPartTouched[i] == YES)
19657                     modelSettings[i].cppMultDev = p;
19658 
19659             p->paramTypeName = "Standard deviation (log) of CPP rate multipliers";
19660             SafeStrcat(&p->name, "Sigma_cpp");
19661             SafeStrcat(&p->name, partString);
19662 
19663             /* find the parameter x prior type */
19664             if (!strcmp(mp->cppMultDevPr,"Fixed"))
19665                 p->paramId = CPPMULTDEV_FIX;
19666 
19667             if (p->paramId != CPPMULTDEV_FIX)
19668                 p->printParam = YES;
19669             SafeStrcat (&p->paramHeader, "sigma_cpp");
19670             SafeStrcat (&p->paramHeader, partString);
19671             }
19672         else if (j == P_CPPEVENTS)
19673             {
19674             /* Set up cpp events parameter *****************************************************************************************/
19675             p->paramType = P_CPPEVENTS;
19676             p->nValues = 0;
19677             p->nSubValues = 2*numLocalTaxa;     /* keep effective branch lengths here (for all nodes to be on the safe side) */
19678             p->min = 1E-6;
19679             p->max = POS_INFINITY;
19680             for (i=0; i<numCurrentDivisions; i++)
19681                 if (isPartTouched[i] == YES)
19682                     modelSettings[i].cppEvents = p;
19683 
19684             p->paramTypeName = "Events of rate-multiplying compound Poisson process";
19685             SafeStrcat(&p->name, "CppEvents");
19686             SafeStrcat(&p->name, partString);
19687 
19688             /* find the parameter x prior type */
19689             p->paramId = CPPEVENTS;
19690 
19691             /* should we print values to .p file? */
19692             p->printParam = NO;
19693 
19694             SafeStrcat (&p->paramHeader, "cppEvents");
19695             SafeStrcat (&p->paramHeader, partString);
19696             }
19697         else if (j == P_TK02VAR)
19698             {
19699             /* Set up tk02 relaxed clock variance parameter *****************************************************************************************/
19700             p->paramType = P_TK02VAR;
19701             p->nValues = 1;
19702             p->nSubValues = 0;
19703             p->min = 1E-6;
19704             p->max = POS_INFINITY;
19705             for (i=0; i<numCurrentDivisions; i++)
19706                 if (isPartTouched[i] == YES)
19707                     modelSettings[i].tk02var = p;
19708 
19709             p->paramTypeName = "Variance of lognormal distribution of branch rates";
19710             SafeStrcat(&p->name, "TK02var");
19711             SafeStrcat(&p->name, partString);
19712 
19713             /* find the parameter x prior type */
19714             if (!strcmp(mp->tk02varPr,"Uniform"))
19715                 p->paramId = TK02VAR_UNI;
19716             else if (!strcmp(mp->tk02varPr,"Exponential"))
19717                 p->paramId = TK02VAR_EXP;
19718             else
19719                 p->paramId = TK02VAR_FIX;
19720 
19721             if (p->paramId != TK02VAR_FIX)
19722                 p->printParam = YES;
19723             SafeStrcat (&p->paramHeader, "tk02var");
19724             SafeStrcat (&p->paramHeader, partString);
19725             }
19726         else if (j == P_TK02BRANCHRATES)
19727             {
19728             /* Set up tk02 relaxed clock rates parameter *****************************************************************************************/
19729             p->paramType = P_TK02BRANCHRATES;
19730             p->nValues = 2*numLocalTaxa;     /* use to hold the branch rates; we need one rate for the root */
19731             p->nSubValues = 2*numLocalTaxa;  /* use to hold the effective branch lengths */
19732             p->min = RATE_MIN;
19733             p->max = RATE_MAX;
19734             for (i=0; i<numCurrentDivisions; i++)
19735                 if (isPartTouched[i] == YES)
19736                     modelSettings[i].tk02BranchRates = p;
19737 
19738             p->paramTypeName = "Branch rates of TK02 relaxed clock";
19739             SafeStrcat(&p->name, "TK02Brlens");
19740             SafeStrcat(&p->name, partString);
19741 
19742             /* find the parameter x prior type */
19743             p->paramId = TK02BRANCHRATES;
19744 
19745             /* should we print values to .p file? */
19746             p->printParam = NO;
19747 
19748             SafeStrcat (&p->paramHeader, "tk02_brlens");
19749             SafeStrcat (&p->paramHeader, partString);
19750             }
19751         else if (j == P_IGRVAR)
19752             {
19753             /* Set up igr relaxed clock variance parameter *****************************************************************************************/
19754             p->paramType = P_IGRVAR;
19755             p->nValues = 1;
19756             p->nSubValues = 0;
19757             p->min = 1E-6;
19758             p->max = POS_INFINITY;
19759             for (i=0; i<numCurrentDivisions; i++)
19760                 if (isPartTouched[i] == YES)
19761                     modelSettings[i].igrvar = p;
19762 
19763             p->paramTypeName = "Variance increase of igr model branch lenths";
19764             SafeStrcat(&p->name, "Igrvar");
19765             SafeStrcat(&p->name, partString);
19766 
19767             /* find the parameter x prior type */
19768             if (!strcmp(mp->igrvarPr,"Uniform"))
19769                 p->paramId = IGRVAR_UNI;
19770             else if (!strcmp(mp->igrvarPr,"Exponential"))
19771                 p->paramId = IGRVAR_EXP;
19772             else
19773                 p->paramId = IGRVAR_FIX;
19774 
19775             if (p->paramId != IGRVAR_FIX)
19776                 p->printParam = YES;
19777             SafeStrcat (&p->paramHeader, "igrvar");
19778             SafeStrcat (&p->paramHeader, partString);
19779             }
19780         else if (j == P_IGRBRANCHRATES)
19781             {
19782             /* Set up igr relaxed clock rates parameter *****************************************************************************************/
19783             p->paramType = P_IGRBRANCHRATES;
19784             p->nValues = 2*numLocalTaxa;     /* use to hold the branch rates; we need one rate for the root */
19785             p->nSubValues = 2*numLocalTaxa;  /* use to hold the effective branch lengths */
19786             p->min = RATE_MIN;
19787             p->max = RATE_MAX;
19788             for (i=0; i<numCurrentDivisions; i++)
19789                 if (isPartTouched[i] == YES)
19790                     modelSettings[i].igrBranchRates = p;
19791 
19792             p->paramTypeName = "Branch lengths of IGR relaxed clock";
19793             SafeStrcat(&p->name, "IgrBrlens");
19794             SafeStrcat(&p->name, partString);
19795 
19796             /* find the parameter x prior type */
19797             p->paramId = IGRBRANCHRATES;
19798 
19799             /* should we print values to .p file? */
19800             p->printParam = NO;
19801 
19802             SafeStrcat (&p->paramHeader, "igr_brlens");
19803             SafeStrcat (&p->paramHeader, partString);
19804             }
19805         else if (j == P_MIXEDVAR)
19806             {
19807             /* Set up mixed relaxed clock variance parameter *****************************************************************************************/
19808             p->paramType = P_MIXEDVAR;
19809             p->nValues = 1;
19810             p->nSubValues = 0;
19811             p->min = 1E-6;
19812             p->max = POS_INFINITY;
19813             for (i=0; i<numCurrentDivisions; i++)
19814                 if (isPartTouched[i] == YES)
19815                     modelSettings[i].mixedvar = p;
19816 
19817             p->paramTypeName = "Variance shared for mixed relaxed clock moodel";
19818             SafeStrcat(&p->name, "Mixedvar");
19819             SafeStrcat(&p->name, partString);
19820 
19821             /* find the parameter x prior type */
19822             if (!strcmp(mp->mixedvarPr,"Uniform"))
19823                 p->paramId = MIXEDVAR_UNI;
19824             else if (!strcmp(mp->mixedvarPr,"Exponential"))
19825                 p->paramId = MIXEDVAR_EXP;
19826             else
19827                 p->paramId = MIXEDVAR_FIX;
19828 
19829             if (p->paramId != MIXEDVAR_FIX)
19830                 p->printParam = YES;
19831             SafeStrcat (&p->paramHeader, "mixedvar");
19832             SafeStrcat (&p->paramHeader, partString);
19833             }
19834         else if (j == P_MIXEDBRCHRATES)
19835             {
19836             /* Set up mixed relaxed clock rates parameter *****************************************************************************************/
19837             p->paramType = P_MIXEDBRCHRATES;
19838             p->nValues = 2*numLocalTaxa;     /* use to hold the branch rates; we need one rate for the root */
19839             p->nSubValues = 2*numLocalTaxa;  /* use to hold the effective branch lengths */
19840             p->nIntValues = 1;               /* use to hold the model indicator: TK02 or IGR */
19841             p->min = RATE_MIN;
19842             p->max = RATE_MAX;
19843             for (i=0; i<numCurrentDivisions; i++)
19844                 if (isPartTouched[i] == YES)
19845                     modelSettings[i].mixedBrchRates = p;
19846 
19847             p->paramTypeName = "Branch rates of mixed relaxed clock";
19848             SafeStrcat(&p->name, "MixedBrlens");
19849             SafeStrcat(&p->name, partString);
19850 
19851             /* find the parameter x prior type */
19852             p->paramId = MIXEDBRCHRATES;
19853 
19854             /* how to print model indicator (0 or 1) to .p file? */
19855             p->printParam = NO;
19856 
19857             SafeStrcat (&p->paramHeader, "mixed_brlens");
19858             SafeStrcat (&p->paramHeader, partString);
19859             }
19860         else if (j == P_CLOCKRATE)
19861             {
19862             /* Set up clockRate ****************************************************************************************/
19863             p->paramType = P_CLOCKRATE;
19864             p->nValues = 1;
19865             p->nSubValues = 0;
19866             p->min = POS_MIN;
19867             p->max = POS_INFINITY;
19868             for (i=0; i<numCurrentDivisions; i++)
19869                 if (isPartTouched[i] == YES)
19870                     modelSettings[i].clockRate = p;
19871 
19872             p->paramTypeName = "Base rate of clock";
19873             SafeStrcat(&p->name, "Clockrate");
19874             SafeStrcat(&p->name, partString);
19875 
19876             /* parameter does affect likelihoods */
19877             p->affectsLikelihood = YES;
19878 
19879             /* find the parameter x prior type */
19880             if (!strcmp(mp->clockRatePr,"Normal"))
19881                 {
19882                 p->paramId      = CLOCKRATE_NORMAL;
19883                 p->LnPriorRatio = &LnProbRatioTruncatedNormal;
19884                 p->priorParams  = mp->clockRateNormal;
19885                 p->LnPriorProb  = &LnPriorProbTruncatedNormal;
19886                 }
19887             else if (!strcmp(mp->clockRatePr,"Lognormal"))
19888                 {
19889                 p->paramId      = CLOCKRATE_LOGNORMAL;
19890                 p->LnPriorRatio = &LnProbRatioLognormal;
19891                 p->priorParams  = mp->clockRateLognormal;
19892                 p->LnPriorProb  = &LnPriorProbLognormal;
19893                 }
19894             else if (!strcmp(mp->clockRatePr,"Exponential"))
19895                 {
19896                 p->paramId      = CLOCKRATE_EXP;
19897                 p->LnPriorRatio = &LnProbRatioExponential;
19898                 p->priorParams  = &mp->clockRateExp;
19899                 p->LnPriorProb  = &LnPriorProbExponential;
19900                 }
19901             else if (!strcmp(mp->clockRatePr,"Gamma"))
19902                 {
19903                 p->paramId      = CLOCKRATE_GAMMA;
19904                 p->LnPriorRatio = &LnProbRatioGamma;
19905                 p->priorParams  = mp->clockRateGamma;
19906                 p->LnPriorProb  = &LnPriorProbGamma;
19907                 }
19908             else
19909                 {
19910                 p->paramId      = CLOCKRATE_FIX;
19911                 p->LnPriorRatio = NULL;
19912                 p->priorParams  = &mp->clockRateFix;
19913                 p->LnPriorProb  = &LnPriorProbFix;
19914                 }
19915 
19916             SafeStrcat (&p->paramHeader, "clockrate");
19917             SafeStrcat (&p->paramHeader, partString);
19918             if (p->paramId != CLOCKRATE_FIX)
19919                 p->printParam = YES;
19920             }
19921         }
19922     free (tempStr);
19923     free (isPartTouched);
19924     SAFEFREE (partString);
19925 
19926     return (NO_ERROR);
19927 }
19928 
19929 
19930 /*----------------------------------------------------------------------------
19931 |
19932 |   SetMoves: This function will set up the applicable moves that could
19933 |       potentially be used in updating the model parameters
19934 |
19935 -----------------------------------------------------------------------------*/
SetMoves(void)19936 int SetMoves (void)
19937 {
19938     int         i, j, k, moveIndex;
19939     Param       *param;
19940 
19941     /* free up previous moves if any */
19942     if (memAllocs[ALLOC_MOVES] == YES)
19943         {
19944         for (i=0; i<numApplicableMoves; i++)
19945             FreeMove (moves[i]);
19946         free (moves);
19947         moves = NULL;
19948         memAllocs[ALLOC_MOVES] = NO;
19949         }
19950 
19951     /* set up applicable moves                                   */
19952     /* each combination of moveType and param is a separate move */
19953 
19954     /* first count applicable moves */
19955     numApplicableMoves = 0;
19956     for (k=0; k<numParams; k++)
19957         {
19958         param = &params[k];
19959         for (i=0; i<NUM_MOVE_TYPES; i++)
19960             {
19961             if (moveTypes[i].level > userLevel)
19962                 continue;
19963             if (moveTypes[i].isApplicable(param) == NO)
19964                 continue;
19965             for (j=0; j<moveTypes[i].nApplicable; j++)
19966                 {
19967                 if (moveTypes[i].applicableTo[j] == param->paramId)
19968                     {
19969                     numApplicableMoves++;
19970                     break;
19971                     }
19972                 }
19973             }
19974         }
19975 
19976     /* then allocate space for move pointers */
19977     moves = (MCMCMove **) SafeMalloc (numApplicableMoves * sizeof (MCMCMove *));
19978     if (!moves && numApplicableMoves > 0)   /* in the middle of defining a model, numApplicableMoves can be 0 */
19979         {
19980         MrBayesPrint ("%s   Problem allocating moves\n", spacer);
19981         return (ERROR);
19982         }
19983     memAllocs[ALLOC_MOVES] = YES;
19984 
19985     /* finally allocate space for and set move defaults */
19986     moveIndex = 0;
19987     for (k=0; k<numParams; k++)
19988         {
19989         param = &params[k];
19990         for (i=0; i<NUM_MOVE_TYPES; i++)
19991             {
19992             if (moveTypes[i].level > userLevel)
19993                 continue;
19994             if (moveTypes[i].isApplicable(param) == NO)
19995                 continue;
19996             for (j=0; j<moveTypes[i].nApplicable; j++)
19997                 {
19998                 if (moveTypes[i].applicableTo[j] == param->paramId)
19999                     {
20000                     if ((moves[moveIndex] = AllocateMove (&moveTypes[i], param)) == NULL)
20001                         break;
20002                     else
20003                         {
20004                         moves[moveIndex]->parm = param;
20005                         moveIndex++;
20006                         break;
20007                         }
20008                     }
20009                 }
20010             }
20011         }
20012 
20013     if (moveIndex < numApplicableMoves)
20014         {
20015         for (i=0; i<moveIndex; i++)
20016             FreeMove (moves[i]);
20017         free (moves);
20018         memAllocs[ALLOC_MOVES] = NO;
20019         MrBayesPrint ("%s   Problem setting moves\n", spacer);
20020         return (ERROR);
20021         }
20022 
20023     return (NO_ERROR);
20024 }
20025 
20026 
20027 /** SetPopSizeParam: Set population size values for a species tree from an input tree */
SetPopSizeParam(Param * param,int chn,int state,PolyTree * pt)20028 int SetPopSizeParam (Param *param, int chn, int state, PolyTree *pt)
20029 {
20030     int         i, j, k, nLongsNeeded;
20031     MrBFlt      *values;
20032     Tree        *speciesTree;
20033     PolyNode    *pp;
20034     TreeNode    *p=NULL;
20035 
20036     nLongsNeeded = 1 + (pt->nNodes - pt->nIntNodes - 1) / nBitsInALong;
20037 
20038     /* Get pointer to values to be set */
20039     values = GetParamVals (param, chn, state);
20040 
20041     /* Get species tree */
20042     speciesTree = GetTree (modelSettings[param->relParts[0]].speciesTree, chn, state);
20043 
20044     /* Set them based on index of matching partitions */
20045     AllocatePolyTreePartitions(pt);
20046     AllocateTreePartitions(speciesTree);
20047     for (i=0; i<pt->nNodes; i++)
20048         {
20049         pp = pt->allDownPass[i];
20050         for (j=0; j<speciesTree->nNodes-1; j++)
20051             {
20052             p = speciesTree->allDownPass[j];
20053             for (k=0; k<nLongsNeeded; k++)
20054                 {
20055                 if (pp->partition[k] != p->partition[k])
20056                     break;
20057                 }
20058             if (k == nLongsNeeded)
20059                 break;
20060             }
20061         if (j == speciesTree->nNodes - 1)
20062             {
20063             MrBayesPrint ("%s   Non-matching partitions when setting population size parameter", spacer);
20064             FreePolyTreePartitions(pt);
20065             FreeTreePartitions(speciesTree);
20066             return (ERROR);
20067             }
20068         values[p->index] = pt->popSize[pp->index];
20069     }
20070 
20071     FreePolyTreePartitions(pt);
20072     FreeTreePartitions(speciesTree);
20073 
20074     return (NO_ERROR);
20075 }
20076 
20077 
20078 /* SetRelaxedClockParam: set values for a relaxed clock param from an input tree */
SetRelaxedClockParam(Param * param,int chn,int state,PolyTree * pt)20079 int SetRelaxedClockParam (Param *param, int chn, int state, PolyTree *pt)
20080 {
20081     int         i, j, k, *nEvents=NULL, *nEventsP=NULL, nLongsNeeded, isEventSet;
20082     MrBFlt       *effectiveBranchLengthP=NULL, *branchRate=NULL,
20083                 **position=NULL, **rateMult=NULL, **positionP=NULL, **rateMultP=NULL,
20084                 baseRate;
20085     Tree        *t;
20086     PolyNode    *pp;
20087     TreeNode    *p=NULL, *q;
20088 
20089     nLongsNeeded = 1 + (numLocalTaxa - 1) / nBitsInALong;
20090 
20091     /* set pointers to the right set of values */
20092     isEventSet = NO;
20093     if (param->paramType == P_CPPEVENTS)
20094         {
20095         /* find the right event set */
20096         for (i=0; i<pt->nESets; i++)
20097             {
20098             if (!strcmp(param->name,pt->eSetName[i]))
20099                 break;
20100             }
20101         if (i == pt->nESets)
20102             {
20103             for (i=0; i<pt->nBSets; i++)
20104                 if (!strcmp(param->name,pt->bSetName[i]))
20105                     break;
20106 
20107             if (i == pt->nBSets)
20108                 return (NO_ERROR);
20109             else
20110                 isEventSet = NO;
20111             }
20112         else
20113             isEventSet = YES;
20114 
20115         if (isEventSet == YES)
20116             {
20117             nEventsP  = pt->nEvents[i];
20118             positionP = pt->position[i];
20119             rateMultP = pt->rateMult[i];
20120             }
20121         else
20122             effectiveBranchLengthP = pt->effectiveBrLen[i];
20123 
20124         nEvents  = param->nEvents[2*chn+state];
20125         position = param->position[2*chn+state];
20126         rateMult = param->rateMult[2*chn+state];
20127         }
20128     else if (param->paramType == P_TK02BRANCHRATES || param->paramType == P_IGRBRANCHRATES || param->paramType == P_MIXEDBRCHRATES)
20129         {
20130         /* find the right effective branch length set */
20131         for (i=0; i<pt->nBSets; i++)
20132             if (!strcmp(param->name,pt->bSetName[i]))
20133                 break;
20134         if (i == pt->nBSets)
20135             return (NO_ERROR);
20136 
20137         effectiveBranchLengthP = pt->effectiveBrLen[i];
20138         branchRate = GetParamVals (param, chn, state);
20139         }
20140 
20141     t = GetTree (param, chn, state);
20142     AllocatePolyTreePartitions (pt);
20143     AllocateTreePartitions (t);
20144 
20145     for (i=pt->nNodes-1; i>=0; i--)
20146         {
20147         pp = pt->allDownPass[i];
20148         for (j=0; j<t->nNodes; j++)
20149             {
20150             p = t->allDownPass[j];
20151             for (k=0; k<nLongsNeeded; k++)
20152                 if (p->partition[k] != pp->partition[k])
20153                     break;
20154             if (k == nLongsNeeded)
20155                 break;  /* match */
20156             }
20157         if (param->paramType == P_CPPEVENTS)
20158             {
20159             if (isEventSet == NO)
20160                 {
20161                 if (nEvents[p->index] != 1)
20162                     {
20163                     position[p->index] = (MrBFlt *) SafeRealloc ((void *) position[p->index], 1*sizeof(MrBFlt));
20164                     rateMult[p->index] = (MrBFlt *) SafeRealloc ((void *) rateMult[p->index], 1*sizeof(MrBFlt));
20165                     nEvents [p->index] = 1;
20166                     }
20167                 position[p->index][0] = 0.5;
20168                 if (p->anc->anc == NULL)
20169                     rateMult[p->index][0] = 1.0;
20170                 else
20171                     {
20172                     baseRate = 1.0;
20173                     q = p->anc;
20174                     while (q->anc != NULL)
20175                         {
20176                         baseRate *= rateMult[q->index][0];
20177                         q = q->anc;
20178                         }
20179                     rateMult[p->index][0] = 2.0 * effectiveBranchLengthP[pp->index] / (p->length * baseRate) - 1.0;
20180                     }
20181                 }
20182             else
20183                 {
20184                 if (nEvents[p->index] != nEventsP[pp->index])
20185                     {
20186                     if (nEventsP[pp->index] == 0)
20187                         {
20188                         free (position[p->index]);
20189                         free (rateMult[p->index]);
20190                         }
20191                     else
20192                         {
20193                         position[p->index] = (MrBFlt *) SafeRealloc ((void *) position[p->index], nEventsP[pp->index]*sizeof(MrBFlt));
20194                         rateMult[p->index] = (MrBFlt *) SafeRealloc ((void *) rateMult[p->index], nEventsP[pp->index]*sizeof(MrBFlt));
20195                         }
20196                     nEvents[p->index] = nEventsP[pp->index];
20197                     }
20198                 for (j=0; j<nEventsP[pp->index]; j++)
20199                     {
20200                     position[p->index][j] = positionP[pp->index][j];
20201                     rateMult[p->index][j] = rateMultP[pp->index][j];
20202                     }
20203                 }
20204             }
20205         else if (param->paramType == P_TK02BRANCHRATES ||
20206                  (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_TK02))
20207             {
20208             if (p->anc->anc == NULL)
20209                 branchRate[p->index] = 1.0;
20210             else if (p->length > 0.0)
20211                 branchRate[p->index] = 2.0 * effectiveBranchLengthP[pp->index] / p->length - branchRate[p->anc->index];
20212             else
20213                 branchRate[p->index] = branchRate[p->anc->index];
20214             }
20215         else if (param->paramType == P_IGRBRANCHRATES ||
20216                  (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_IGR))
20217             {
20218             if (p->length > 0.0)
20219                 branchRate[p->index] = effectiveBranchLengthP[pp->index] / p->length;
20220             else
20221                 branchRate[p->index] = branchRate[p->anc->index];
20222             }  // we are now reading effective branch length for TK02 and IGR
20223         }
20224 
20225     if (param->paramType == P_CPPEVENTS)
20226         {
20227         if (UpdateCppEvolLengths (param, t->root->left, chn) == ERROR)
20228             return (ERROR);
20229         }
20230     else if (param->paramType == P_TK02BRANCHRATES ||
20231              (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_TK02))
20232         {
20233         if (UpdateTK02EvolLengths (param, t, chn) == ERROR)
20234             return (ERROR);
20235         }
20236     else if (param->paramType == P_IGRBRANCHRATES ||
20237              (param->paramType == P_MIXEDBRCHRATES && *GetParamIntVals(param, chn, state) == RCL_IGR))
20238         {
20239         if (UpdateIgrBrachLengths (param, t, chn) == ERROR)
20240             return (ERROR);
20241         }
20242 
20243     FreePolyTreePartitions (pt);
20244     FreeTreePartitions (t);
20245 
20246     return (NO_ERROR);
20247 }
20248 
20249 
20250 /*------------------------------------------------------------------------
20251 |
20252 |   SetUpAnalysis: Set parameters and moves
20253 |
20254 ------------------------------------------------------------------------*/
SetUpAnalysis(RandLong * seed)20255 int SetUpAnalysis (RandLong *seed)
20256 {
20257     setUpAnalysisSuccess=NO;
20258 
20259     /* calculate number of characters and taxa */
20260     numLocalChar = NumNonExcludedChar ();
20261 
20262     /* we are checking later to make sure no partition is without characters */
20263     SetLocalTaxa ();
20264     if (numLocalTaxa <= 2)
20265         {
20266         MrBayesPrint ("%s   There must be at least two included taxa, now there is %s\n", spacer,
20267             numLocalTaxa == 0 ? "none" : "only one");
20268         return (ERROR);
20269         }
20270 
20271     /* calculate number of global chains */
20272     numGlobalChains = chainParams.numRuns * chainParams.numChains;
20273 
20274     /* Set up link table */
20275     if (SetUpLinkTable () == ERROR)
20276         return (ERROR);
20277 
20278     /* Check that the settings for doublet or codon models are correct. */
20279     if (CheckExpandedModels() == ERROR)
20280         return (ERROR);
20281 
20282     /* Set up model info */
20283     if (SetModelInfo() == ERROR)
20284         return (ERROR);
20285 
20286     /* Calculate number of (uncompressed) characters for each division */
20287     if (GetNumDivisionChars() == ERROR)
20288         return (ERROR);
20289 
20290     /* Compress data and calculate some things needed for setting up params. */
20291     if (CompressData() == ERROR)
20292         return (ERROR);
20293 
20294     /* Add dummy characters, if needed. */
20295     if (AddDummyChars() == ERROR)
20296         return (ERROR);
20297 
20298     /* Set up parameters for the chain. */
20299     if (SetModelParams () == ERROR)
20300         return (ERROR);
20301 
20302     /* Allocate normal params */
20303     if (AllocateNormalParams () == ERROR)
20304         return (ERROR);
20305 
20306     /* Allocate tree params */
20307     if (AllocateTreeParams () == ERROR)
20308         return (ERROR);
20309 
20310     /* Set default number of trees for sumt to appropriate number */
20311     sumtParams.numTrees = numTrees;
20312 
20313     /* Fill in normal parameters */
20314     if (FillNormalParams (seed, 0, numGlobalChains) == ERROR)
20315         return (ERROR);
20316 
20317     /* Process standard characters (calculates bsIndex, tiIndex, and more). */
20318     if (ProcessStdChars(seed) == ERROR)
20319         return (ERROR);
20320 
20321     /* Fill in trees */
20322     if (FillTreeParams (seed, 0, numGlobalChains) == ERROR)
20323         return (ERROR);
20324 
20325     /* Set the applicable moves that could be used by the chain. */
20326     if (SetMoves () == ERROR)
20327         return (ERROR);
20328 
20329     setUpAnalysisSuccess=YES;
20330 
20331     return (NO_ERROR);
20332 }
20333 
20334 
SetUpLinkTable(void)20335 int SetUpLinkTable (void)
20336 {
20337     int         i, j, k, m, paramCount, isApplicable1, isApplicable2,
20338                 isFirst, isSame;
20339     int         *check, *modelId;
20340 
20341     check = (int *) SafeMalloc (2 * (size_t)numCurrentDivisions * sizeof (int));
20342     if (!check)
20343         {
20344         MrBayesPrint ("%s   Problem allocating check (%d)\n", spacer, 2 * numCurrentDivisions * sizeof(int));
20345         return (ERROR);
20346         }
20347     modelId = check + numCurrentDivisions;
20348 
20349     for (j=0; j<NUM_LINKED; j++)
20350         for (i=0; i<numCurrentDivisions; i++)
20351             activeParams[j][i] = 0;
20352 
20353     if (numCurrentDivisions > 1)
20354         {
20355         paramCount = 0;
20356         for (j=0; j<NUM_LINKED; j++) /* loop over parameters */
20357             {
20358             isFirst = YES;
20359             for (i=0; i<numCurrentDivisions; i++)
20360                 modelId[i] = 0;
20361             for (i=0; i<numCurrentDivisions-1; i++) /* loop over partitions */
20362                 {
20363                 for (k=i+1; k<numCurrentDivisions; k++)
20364                     {
20365                     if (IsModelSame (j, i, k, &isApplicable1, &isApplicable2) == NO || linkTable[j][i] != linkTable[j][k])
20366                         {
20367                         /* we cannot link the parameters */
20368                         if (isApplicable1 == NO)
20369                             modelId[i] = -1;
20370                         if (isApplicable2 == NO)
20371                             modelId[k] = -1;
20372                         if (isApplicable1 == YES)
20373                             {
20374                             if (isFirst == YES && modelId[i] == 0)
20375                                 {
20376                                 modelId[i] = ++paramCount;
20377                                 isFirst = NO;
20378                                 }
20379                             else
20380                                 {
20381                                 if (modelId[i] == 0)
20382                                     modelId[i] = ++paramCount;
20383                                 }
20384                             }
20385                         if (modelId[k] == 0 && isApplicable2 == YES)
20386                             modelId[k] = ++paramCount;
20387                         }
20388                     else
20389                         {
20390                         /* we can link the parameters */
20391                         if (isFirst == YES)
20392                             {
20393                             if (modelId[i] == 0)
20394                                 modelId[i] = ++paramCount;
20395                             isFirst = NO;
20396                             }
20397                         else
20398                             {
20399                             if (modelId[i] == 0)
20400                                 modelId[i] = ++paramCount;
20401                             }
20402                         modelId[k] = modelId[i];
20403                         }
20404                     }
20405                 }
20406             for (i=0; i<numCurrentDivisions; i++)
20407                 activeParams[j][i] = modelId[i];
20408             }
20409         }
20410     else
20411         {
20412         /* if we have only one partition, then we do things a bit differently */
20413         paramCount = 0;
20414         for (j=0; j<NUM_LINKED; j++) /* loop over parameters */
20415             {
20416             IsModelSame (j, 0, 0, &isApplicable1, &isApplicable2);
20417             if (isApplicable1 == YES)
20418                 activeParams[j][0] = ++paramCount;
20419             else
20420                 activeParams[j][0] = -1;
20421             }
20422         }
20423 
20424     /* Check that the same report format is specified for all partitions with the same rate multiplier */
20425     for (i=0; i<numCurrentDivisions; i++)
20426         check[i] = NO;
20427     for (i=0; i<numCurrentDivisions; i++)
20428         {
20429         m = activeParams[P_RATEMULT][i];
20430         if (m == -1 || check[i] == YES)
20431             continue;
20432         isSame = YES;
20433         for (j=i+1; j<numCurrentDivisions; j++)
20434             {
20435             if (activeParams[P_RATEMULT][j] == m)
20436                 {
20437                 check[i] = YES;
20438                 if (strcmp(modelParams[i].ratemultFormat,modelParams[j].ratemultFormat)!= 0)
20439                     {
20440                     isSame = NO;
20441                     strcpy (modelParams[j].ratemultFormat, modelParams[i].ratemultFormat);
20442                     }
20443                 }
20444             }
20445         if (isSame == NO)
20446             {
20447             MrBayesPrint ("%s   WARNING: Report format for ratemult (parameter %d) varies across partitions.\n", spacer);
20448             MrBayesPrint ("%s      MrBayes will use the format for the first partition, which is %s.\n", spacer, modelParams[i].ratemultFormat);
20449             }
20450         }
20451 
20452     /* probably a good idea to clean up link table here */
20453     paramCount = 0;
20454     for (j=0; j<NUM_LINKED; j++)
20455         {
20456         for (i=0; i<numCurrentDivisions; i++)
20457             check[i] = NO;
20458         for (i=0; i<numCurrentDivisions; i++)
20459             {
20460             if (check[i] == NO && activeParams[j][i] > 0)
20461                 {
20462                 m = activeParams[j][i];
20463                 paramCount++;
20464                 for (k=i; k<numCurrentDivisions; k++)
20465                     {
20466                     if (check[k] == NO && activeParams[j][k] == m)
20467                         {
20468                         activeParams[j][k] = paramCount;
20469                         check[k] = YES;
20470                         }
20471                     }
20472                 }
20473             }
20474         }
20475 
20476     free (check);
20477 
20478     return (NO_ERROR);
20479 }
20480 
20481 
20482 /*------------------------------------------------------------------------
20483 |
20484 |   SetUpMoveTypes: Set up structs holding info on each move type
20485 |
20486 ------------------------------------------------------------------------*/
SetUpMoveTypes(void)20487 void SetUpMoveTypes (void)
20488 {
20489     /* Register the move type here when new move functions are added
20490        Remember to check that the number of move types does not exceed NUM_MOVE_TYPES
20491        defined in bayes.h.         */
20492     int         i;
20493     MoveType    *mt;
20494 
20495     /* reset move types */
20496     for (i=0; i<NUM_MOVE_TYPES; i++)
20497         {
20498         mt = &moveTypes[i];
20499         mt->level = DEVELOPER;
20500         mt->numTuningParams = 0;
20501         mt->minimum[0] = mt->minimum[1] = -1000000000.0;
20502         mt->maximum[0] = mt->maximum[1] =  1000000000.0;
20503         mt->tuningParam[0] = mt->tuningParam[1] = 0.0;
20504         mt->nApplicable = 0;
20505         mt->name = mt->tuningName[0] = mt->tuningName[1] = "";
20506         mt->paramName = "";
20507         mt->subParams = NO;
20508         mt->relProposalProb = 0.0;
20509         mt->parsimonyBased = NO;
20510         mt->isApplicable = &IsApplicable;
20511         mt->Autotune = NULL;
20512         mt->targetRate = -1.0;
20513         }
20514 
20515     /* Moves are in alphabetic order after parameter name, which matches the name of a move function if
20516        there is a separate move function for the parameter. See proposal.h for declaration of move functions.
20517        Since 2010-10-04, some parameters use generalized move functions and do not have their own. */
20518 
20519     i = 0;
20520 
20521     /* Move_Aamodel */
20522     mt = &moveTypes[i++];
20523     mt->name = "Uniform random pick";
20524     mt->shortName = "Uniform";
20525     mt->applicableTo[0] = AAMODEL_MIX;
20526     mt->nApplicable = 1;
20527     mt->moveFxn = &Move_Aamodel;
20528     mt->relProposalProb = 1.0;
20529     mt->numTuningParams = 0;
20530     mt->parsimonyBased = NO;
20531     mt->level = STANDARD_USER;
20532 
20533     /* Move_Adgamma */
20534     mt = &moveTypes[i++];
20535     mt->name = "Sliding window";
20536     mt->shortName = "Slider";
20537     mt->tuningName[0] = "Sliding window size";
20538     mt->shortTuningName[0] = "delta";
20539     mt->applicableTo[0] = CORREL_UNI;
20540     mt->nApplicable = 1;
20541     mt->moveFxn = &Move_Adgamma;
20542     mt->relProposalProb = 1.0;
20543     mt->numTuningParams = 1;
20544     mt->tuningParam[0] = 0.5;  /* window size */
20545     mt->minimum[0] = 0.001;
20546     mt->maximum[0] = 1.999;
20547     mt->parsimonyBased = NO;
20548     mt->level = STANDARD_USER;
20549     mt->Autotune = &AutotuneSlider;
20550     mt->targetRate = 0.25;
20551 
20552     /* Move_Beta */
20553     mt = &moveTypes[i++];
20554     mt->name = "Multiplier";
20555     mt->shortName = "Multiplier";
20556     mt->tuningName[0] = "Multiplier tuning parameter";
20557     mt->shortTuningName[0] = "lambda";
20558     mt->applicableTo[0] = SYMPI_UNI;
20559     mt->applicableTo[1] = SYMPI_EXP;
20560     mt->applicableTo[2] = SYMPI_UNI_MS;
20561     mt->applicableTo[3] = SYMPI_EXP_MS;
20562     mt->nApplicable = 4;
20563     mt->moveFxn = &Move_Beta;
20564     mt->relProposalProb = 1.0;
20565     mt->numTuningParams = 1;
20566     mt->tuningParam[0] = 2.0 * log (1.5);  /* so-called lambda */
20567     mt->minimum[0] = 0.0001;
20568     mt->maximum[0] = 20.0;
20569     mt->parsimonyBased = NO;
20570     mt->level = STANDARD_USER;
20571     mt->Autotune = &AutotuneMultiplier;
20572     mt->targetRate = 0.25;
20573 
20574     /* Move_BrLen */
20575     mt = &moveTypes[i++];
20576     mt->name = "Random brlen hit with multiplier";
20577     mt->shortName = "Multiplier";
20578     mt->tuningName[0] = "Multiplier tuning parameter";
20579     mt->shortTuningName[0] = "lambda";
20580     mt->applicableTo[0] = BRLENS_UNI;
20581     mt->applicableTo[1] = BRLENS_EXP;
20582     mt->applicableTo[2] = BRLENS_GamDir;
20583     mt->applicableTo[3] = BRLENS_iGmDir;
20584     mt->applicableTo[4] = BRLENS_twoExp;
20585     mt->nApplicable = 5;  // was 2
20586     mt->moveFxn = &Move_BrLen;
20587     mt->relProposalProb = 20.0;
20588     mt->numTuningParams = 1;
20589     mt->tuningParam[0] = 2.0 * log (2.0);  /* lambda */
20590     mt->minimum[0] = 0.0001;
20591     mt->maximum[0] = 20.0;  /* change it smaller to avoid overflow in the exp function, same for following "smaller" */
20592     mt->parsimonyBased = NO;
20593     mt->level = STANDARD_USER;
20594     mt->Autotune = &AutotuneMultiplier;
20595     mt->targetRate = 0.25;
20596 
20597     /* Move_ClockRate_M */
20598     mt = &moveTypes[i++];
20599     mt->name = "Multiplier";
20600     mt->shortName = "Multiplier";
20601     mt->tuningName[0] = "Multiplier tuning parameter";
20602     mt->shortTuningName[0] = "lambda";
20603     mt->applicableTo[0] = CLOCKRATE_NORMAL;
20604     mt->applicableTo[1] = CLOCKRATE_LOGNORMAL;
20605     mt->applicableTo[2] = CLOCKRATE_GAMMA;
20606     mt->applicableTo[3] = CLOCKRATE_EXP;
20607     mt->nApplicable = 4;
20608     mt->moveFxn = &Move_ClockRate_M;
20609     mt->relProposalProb = 3.0;
20610     mt->numTuningParams = 1;
20611     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
20612     mt->minimum[0] = 0.0001;
20613     mt->maximum[0] = 20.0;                 /* smaller */
20614     mt->parsimonyBased = NO;
20615     mt->level = STANDARD_USER;
20616     mt->Autotune = &AutotuneMultiplier;
20617     mt->targetRate = 0.25;
20618 
20619     /* Move_Extinction */
20620     mt = &moveTypes[i++];
20621     mt->name = "Sliding window";
20622     mt->shortName = "Slider";
20623     mt->tuningName[0] = "Sliding window size";
20624     mt->shortTuningName[0] = "delta";
20625     mt->applicableTo[0] = EXTRATE_BETA;
20626     mt->nApplicable = 1;
20627     mt->moveFxn = &Move_Extinction;
20628     mt->relProposalProb = 3.0;
20629     mt->numTuningParams = 1;
20630     mt->tuningParam[0] = 0.1;  /* window size */
20631     mt->minimum[0] = 0.00001;
20632     mt->maximum[0] = 20.0;
20633     mt->parsimonyBased = NO;
20634     mt->level = STANDARD_USER;
20635     mt->Autotune = &AutotuneSlider;
20636     mt->targetRate = 0.25;
20637 
20638     /* Move_Fossilization */
20639     mt = &moveTypes[i++];
20640     mt->name = "Sliding window";
20641     mt->shortName = "Slider";
20642     mt->tuningName[0] = "Sliding window size";
20643     mt->shortTuningName[0] = "delta";
20644     mt->applicableTo[0] = FOSLRATE_BETA;
20645     mt->nApplicable = 1;
20646     mt->moveFxn = &Move_Fossilization;
20647     mt->relProposalProb = 3.0;
20648     mt->numTuningParams = 1;
20649     mt->tuningParam[0] = 0.1;  /* window size */
20650     mt->minimum[0] = 0.00001;
20651     mt->maximum[0] = 20.0;
20652     mt->parsimonyBased = NO;
20653     mt->level = STANDARD_USER;
20654     mt->Autotune = &AutotuneSlider;
20655     mt->targetRate = 0.25;
20656 
20657     /* Move_AddBranch, for fossilization prior */
20658     mt = &moveTypes[i++];
20659     mt->name = "Add branch for FossilizedBD";
20660     mt->shortName = "AddBranch";
20661     // mt->subParams = YES;
20662     mt->applicableTo[0] = BRLENS_CLOCK_FOSSIL;
20663     mt->nApplicable = 1;
20664     mt->moveFxn = &Move_AddBranch;
20665     mt->relProposalProb = 15.0;
20666     mt->numTuningParams = 0;
20667     mt->parsimonyBased = NO;
20668     mt->level =STANDARD_USER;
20669     mt->isApplicable = &IsApplicable_AncestralFossil;
20670 
20671     /* Move_DelBranch, for fossilization prior */
20672     mt = &moveTypes[i++];
20673     mt->name = "Delete branch for FossilizedBD";
20674     mt->shortName = "DelBranch";
20675     // mt->subParams = YES;
20676     mt->applicableTo[0] = BRLENS_CLOCK_FOSSIL;
20677     mt->nApplicable = 1;
20678     mt->moveFxn = &Move_DelBranch;
20679     mt->relProposalProb = 15.0;
20680     mt->numTuningParams = 0;
20681     mt->parsimonyBased = NO;
20682     mt->level =STANDARD_USER;
20683     mt->isApplicable = &IsApplicable_AncestralFossil;
20684 
20685     /* Move_ExtFossilSPRClock */
20686     mt = &moveTypes[i++];
20687     mt->name = "Extending fossil SPR for clock trees";
20688     mt->shortName = "ExtFossilSprClock";
20689     mt->subParams = YES;
20690     mt->tuningName[0] = "Extension probability";
20691     mt->shortTuningName[0] = "p_ext";
20692     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20693     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20694     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20695     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20696     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
20697     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
20698     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
20699     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
20700     mt->nApplicable = 8;
20701     mt->moveFxn = &Move_ExtFossilSPRClock;
20702     mt->relProposalProb = 0.0;
20703     mt->numTuningParams = 1;
20704     mt->tuningParam[0] = 0.5; /* extension probability */
20705     mt->minimum[0] = 0.00001;
20706     mt->maximum[0] = 0.99999;
20707     mt->parsimonyBased = NO;
20708     mt->level = STANDARD_USER;
20709     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
20710 
20711     /* Move_ExtSPR */
20712     mt = &moveTypes[i++];
20713     mt->name = "Extending SPR";
20714     mt->shortName = "ExtSPR";
20715     mt->subParams = YES;
20716     mt->tuningName[0] = "Extension probability";
20717     mt->shortTuningName[0] = "p_ext";
20718     mt->tuningName[1] = "Multiplier tuning parameter";
20719     mt->shortTuningName[1] = "lambda";
20720     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20721     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20722     mt->nApplicable = 2;
20723     mt->moveFxn = &Move_ExtSPR;
20724     mt->relProposalProb = 5.0;
20725     mt->numTuningParams = 2;
20726     mt->tuningParam[0] = 0.5; /* extension probability */
20727     mt->tuningParam[1] = 2.0 * log (1.05);   /* lambda */
20728     mt->minimum[0] = 0.00001;
20729     mt->maximum[0] = 0.99999;
20730     mt->minimum[1] = 0.00001;
20731     mt->maximum[1] = 100.0;
20732     mt->parsimonyBased = NO;
20733     mt->level = STANDARD_USER;
20734     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20735 
20736     /* Move_ExtSPR1 */
20737     mt = &moveTypes[i++];
20738     mt->name = "Extending SPR variant 1";
20739     mt->shortName = "ExtSPR1";
20740     mt->subParams = YES;
20741     mt->tuningName[0] = "Extension probability";
20742     mt->shortTuningName[0] = "p_ext";
20743     mt->tuningName[1] = "Multiplier tuning parameter";
20744     mt->shortTuningName[1] = "lambda";
20745     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20746     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20747     mt->nApplicable = 2;
20748     mt->moveFxn = &Move_ExtSPR1;
20749     mt->relProposalProb = 0.0;
20750     mt->numTuningParams = 2;
20751     mt->tuningParam[0] = 0.5; /* extension probability */
20752     mt->tuningParam[1] = 2.0 * log (1.05);   /* lambda */
20753     mt->minimum[0] = 0.00001;
20754     mt->maximum[0] = 0.99999;
20755     mt->minimum[1] = 0.00001;
20756     mt->maximum[1] = 100.0;
20757     mt->parsimonyBased = NO;
20758     mt->level = DEVELOPER;
20759     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
20760 
20761     /* Move_ExtSPRClock */
20762     mt = &moveTypes[i++];
20763     mt->name = "Extending SPR for clock trees";
20764     mt->shortName = "ExtSprClock";
20765     mt->subParams = YES;
20766     mt->tuningName[0] = "Extension probability";
20767     mt->shortTuningName[0] = "p_ext";
20768     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20769     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20770     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20771     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20772     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
20773     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
20774     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
20775     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
20776     mt->nApplicable = 8;
20777     mt->moveFxn = &Move_ExtSPRClock;
20778     mt->relProposalProb = 10.0;
20779     mt->numTuningParams = 1;
20780     mt->tuningParam[0] = 0.5; /* extension probability */
20781     mt->minimum[0] = 0.00001;
20782     mt->maximum[0] = 0.99999;
20783     mt->parsimonyBased = NO;
20784     mt->level = STANDARD_USER;
20785     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
20786 
20787     /* Move_ExtSS */
20788     mt = &moveTypes[i++];
20789     mt->name = "Extending subtree swapper";
20790     mt->shortName = "ExtSS";
20791     mt->subParams = YES;
20792     mt->tuningName[0] = "Extension probability";
20793     mt->shortTuningName[0] = "p_ext";
20794     mt->tuningName[1] = "Multiplier tuning parameter";
20795     mt->shortTuningName[1] = "lambda";
20796     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20797     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20798     mt->nApplicable = 2;
20799     mt->moveFxn = &Move_ExtSS;
20800     mt->relProposalProb = 0.0;
20801     mt->numTuningParams = 2;
20802     mt->tuningParam[0] = 0.5; /* extension probability */
20803     mt->tuningParam[1] = 2.0 * log (1.05); /* lambda */
20804     mt->minimum[0] = 0.00001;
20805     mt->maximum[0] = 0.99999;
20806     mt->minimum[1] = 0.00001;
20807     mt->maximum[1] = 100.0;
20808     mt->parsimonyBased = NO;
20809     mt->level = STANDARD_USER;
20810     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20811 
20812     /* Move_ExtSSClock */
20813     mt = &moveTypes[i++];
20814     mt->name = "Extending subtree swapper";
20815     mt->shortName = "ExtSsClock";
20816     mt->subParams = YES;
20817     mt->tuningName[0] = "Extension probability";
20818     mt->shortTuningName[0] = "p_ext";
20819     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20820     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20821     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20822     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20823     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
20824     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
20825     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
20826     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
20827     mt->nApplicable = 8;
20828     mt->moveFxn = &Move_ExtSSClock;
20829     mt->relProposalProb = 0.0;
20830     mt->numTuningParams = 1;
20831     mt->tuningParam[0] = 0.5; /* extension probability */
20832     mt->minimum[0] = 0.00001;
20833     mt->maximum[0] = 0.99999;
20834     mt->parsimonyBased = NO;
20835     mt->level = STANDARD_USER;
20836     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
20837 
20838     /* Move_ExtTBR */
20839     mt = &moveTypes[i++];
20840     mt->name = "Extending TBR";
20841     mt->shortName = "ExtTBR";
20842     mt->subParams = YES;
20843     mt->tuningName[0] = "Extension probability";
20844     mt->shortTuningName[0] = "p_ext";
20845     mt->tuningName[1] = "Multiplier tuning parameter";
20846     mt->shortTuningName[1] = "lambda";
20847     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20848     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20849     mt->nApplicable = 2;
20850     mt->moveFxn = &Move_ExtTBR;
20851     mt->relProposalProb = 5.0;
20852     mt->numTuningParams = 2;
20853     mt->tuningParam[0] = 0.5; /* extension probability */
20854     mt->tuningParam[1] = 2.0 * log (1.05);   /* lambda */
20855     mt->minimum[0] = 0.00001;
20856     mt->maximum[0] = 0.99999;
20857     mt->minimum[1] = 0.00001;
20858     mt->maximum[1] = 100.0;
20859     mt->parsimonyBased = NO;
20860     mt->level = STANDARD_USER;
20861     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
20862 
20863     /* Move_GeneRate_Dir */
20864     mt = &moveTypes[i++];
20865     mt->name = "Dirichlet proposal";
20866     mt->shortName = "Dirichlet";
20867     mt->tuningName[0] = "Dirichlet parameter";
20868     mt->shortTuningName[0] = "alpha";
20869     mt->applicableTo[0] = GENETREERATEMULT_DIR;
20870     mt->nApplicable = 1;
20871     mt->moveFxn = &Move_GeneRate_Dir;
20872     mt->relProposalProb = 1.0;
20873     mt->numTuningParams = 1;
20874     mt->tuningParam[0] = 1000.0; /* alphaPi */
20875     mt->minimum[0] = 0.001;
20876     mt->maximum[0] = 1000000.0;
20877     mt->parsimonyBased = NO;
20878     mt->level = STANDARD_USER;
20879     mt->Autotune = &AutotuneDirichlet;
20880     mt->targetRate = 0.25;
20881 
20882     /* Move_GeneTree1 */
20883     mt = &moveTypes[i++];
20884     mt->name = "Extending SPR move for gene trees in species trees";
20885     mt->shortName = "ExtSPRClockGS";
20886     mt->tuningName[0] = "Extension probability";
20887     mt->shortTuningName[0] = "prob";
20888     mt->applicableTo[0] = TOPOLOGY_SPECIESTREE;
20889     mt->nApplicable = 1;
20890     mt->moveFxn = &Move_GeneTree1;
20891     mt->relProposalProb = 10.0;
20892     mt->numTuningParams = 1;
20893     mt->tuningParam[0] = 0.5;       /* Tuning parameter value */
20894     mt->minimum[0] = 0.00001;       /* Minimum value of tuning param */
20895     mt->maximum[0] = 0.99999;       /* Maximum value of tuning param */
20896     mt->parsimonyBased = NO;        /* It does not use parsimony scores */
20897     mt->level = STANDARD_USER;
20898 
20899     /* Move_GeneTree2 */
20900     mt = &moveTypes[i++];
20901     mt->name = "NNI move for gene trees in species trees";
20902     mt->shortName = "NNIClockGS";
20903     mt->applicableTo[0] = TOPOLOGY_SPECIESTREE;
20904     mt->nApplicable = 1;
20905     mt->moveFxn = &Move_GeneTree2;
20906     mt->relProposalProb = 10.0;
20907     mt->numTuningParams = 0;        /* No tuning parameters */
20908     mt->parsimonyBased = NO;        /* It does not use parsimony scores */
20909     mt->level = STANDARD_USER;
20910 
20911     /* Move_GeneTree3 */
20912     mt = &moveTypes[i++];
20913     mt->name = "Parsimony-biased SPR for gene trees in species trees";
20914     mt->shortName = "ParsSPRClockGS";
20915     mt->subParams = YES;
20916     mt->tuningName[0] = "parsimony warp factor";
20917     mt->shortTuningName[0] = "warp";
20918     mt->tuningName[1] = "reweighting probability";
20919     mt->shortTuningName[1] = "r";
20920     mt->tuningName[2] = "typical branch length";
20921     mt->shortTuningName[2] = "v_t";
20922     mt->applicableTo[0] = TOPOLOGY_SPECIESTREE;
20923     mt->nApplicable = 1;
20924     mt->moveFxn = &Move_GeneTree3;
20925     mt->relProposalProb = 5.0;
20926     mt->numTuningParams = 3;
20927     mt->tuningParam[0] = 0.1;  /* warp */
20928     mt->tuningParam[1] = 0.05; /* upweight and downweight probability */
20929     mt->tuningParam[2] = 0.05; /* typical branch length */
20930     mt->minimum[0] = 0.0;
20931     mt->maximum[0] = 1.0;
20932     mt->minimum[1] = 0.0;
20933     mt->maximum[1] = 0.3;
20934     mt->minimum[2] = 0.0001;
20935     mt->maximum[2] = 0.5;
20936     mt->parsimonyBased = YES;
20937     mt->level = STANDARD_USER;
20938 
20939     /* Move_Growth_M */
20940     mt = &moveTypes[i++];
20941     mt->name = "Multiplier";
20942     mt->shortName = "Multiplier";
20943     mt->tuningName[0] = "Multiplier tuning parameter";
20944     mt->shortTuningName[0] = "lambda";
20945     mt->applicableTo[0] = GROWTH_UNI;
20946     mt->applicableTo[1] = GROWTH_EXP;
20947     mt->applicableTo[2] = GROWTH_NORMAL;
20948     mt->nApplicable = 3;
20949     mt->moveFxn = &Move_Growth_M;
20950     mt->relProposalProb = 1.0;
20951     mt->numTuningParams = 1;
20952     mt->tuningParam[0] = 2.0 * log(1.5);  /* lambda */
20953     mt->minimum[0] = 0.0001;
20954     mt->maximum[0] = 20.0;
20955     mt->parsimonyBased = NO;
20956     mt->level = STANDARD_USER;
20957     mt->Autotune = &AutotuneMultiplier;
20958     mt->targetRate = 0.25;
20959 
20960     /* Move_Local */
20961     mt = &moveTypes[i++];
20962     mt->name = "BAMBE's LOCAL";
20963     mt->shortName = "Local";
20964     mt->subParams = YES;
20965     mt->tuningName[0] = "Multiplier tuning parameter";
20966     mt->shortTuningName[0] = "lambda";
20967     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
20968     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
20969     mt->nApplicable = 2;
20970     mt->moveFxn = &Move_Local;
20971     mt->relProposalProb = 0.0;
20972     mt->numTuningParams = 1;
20973     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
20974     mt->minimum[0] = 0.00001;
20975     mt->maximum[0] = 100.0;
20976     mt->parsimonyBased = NO;
20977     mt->level = STANDARD_USER;
20978     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
20979 
20980     /* Move_LocalClock */
20981     mt = &moveTypes[i++];
20982     mt->name = "Modified LOCAL for clock trees";
20983     mt->shortName = "LocalClock";
20984     mt->subParams = YES;
20985     mt->tuningName[0] = "Multiplier tuning parameter";
20986     mt->shortTuningName[0] = "lambda";
20987     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
20988     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
20989     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
20990     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
20991     mt->nApplicable = 4;
20992     mt->moveFxn = &Move_LocalClock;
20993     mt->relProposalProb = 0.0;
20994     mt->numTuningParams = 1;
20995     mt->tuningParam[0] = 2.0 * log (2.0);  /* lambda */
20996     mt->minimum[0] = 0.00001;
20997     mt->maximum[0] = 100.0;
20998     mt->parsimonyBased = NO;
20999     mt->level = STANDARD_USER;
21000     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
21001 
21002     /* Move_MixtureRates */
21003     mt = &moveTypes[i++];
21004     mt->name = "Dirichlet proposal";
21005     mt->shortName = "Dirichlet";
21006     mt->tuningName[0] = "Dirichlet parameter";
21007     mt->shortTuningName[0] = "alpha";
21008     mt->applicableTo[0] = MIXTURE_RATES;
21009     mt->nApplicable = 1;
21010     mt->moveFxn = &Move_MixtureRates;
21011     mt->relProposalProb = 0.5;
21012     mt->numTuningParams = 1;
21013     mt->tuningParam[0] = 100.0; /* alphaPi per rate */
21014     mt->minimum[0] = 0.001;
21015     mt->maximum[0] = 10000.0;
21016     mt->parsimonyBased = NO;
21017     mt->level = STANDARD_USER;
21018     mt->Autotune = &AutotuneDirichlet;
21019     mt->targetRate = 0.25;
21020 
21021     /* Move_MixtureRates_Slider */
21022     mt = &moveTypes[i++];
21023     mt->name = "Sliding window";
21024     mt->shortName = "Slider";
21025     mt->tuningName[0] = "Sliding window size";
21026     mt->shortTuningName[0] = "delta";
21027     mt->applicableTo[0] = MIXTURE_RATES;
21028     mt->nApplicable = 1;
21029     mt->moveFxn = &Move_MixtureRates_Slider;
21030     mt->relProposalProb = 0.5;
21031     mt->numTuningParams = 1;
21032     mt->tuningParam[0] = 0.20;  /* window size (change in proportions) */
21033     mt->minimum[0] = 0.00001;
21034     mt->maximum[0] = 1.0;
21035     mt->parsimonyBased = NO;
21036     mt->level = STANDARD_USER;
21037     mt->Autotune = &AutotuneSlider;
21038     mt->targetRate = 0.25;
21039 
21040     /* Move_NNI */
21041     mt = &moveTypes[i++];
21042     mt->name = "NNI move for parsimony trees";
21043     mt->shortName = "ParsNNI";
21044     mt->applicableTo[0] = TOPOLOGY_PARSIMONY_UNIFORM;
21045     mt->applicableTo[1] = TOPOLOGY_PARSIMONY_CONSTRAINED;
21046     mt->nApplicable = 2;
21047     mt->moveFxn = &Move_NNI;
21048     mt->relProposalProb = 10.0;
21049     mt->numTuningParams = 0;
21050     mt->parsimonyBased = NO;    /* no extra parsimony scores are needed */
21051     mt->level = STANDARD_USER;
21052     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21053 
21054     /* Move_NNIClock */
21055     mt = &moveTypes[i++];
21056     mt->name = "NNI move for clock trees";
21057     mt->shortName = "NNIClock";
21058     mt->subParams = YES;
21059     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
21060     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
21061     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
21062     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
21063     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
21064     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
21065     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
21066     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
21067     mt->nApplicable = 8;
21068     mt->moveFxn = &Move_NNIClock;
21069     mt->relProposalProb = 12.0;
21070     mt->numTuningParams = 0;
21071     mt->parsimonyBased = NO;
21072     mt->level = STANDARD_USER;
21073     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
21074 
21075     /* Move_NNI */
21076     mt = &moveTypes[i++];
21077     mt->name = "NNI move";
21078     mt->shortName = "NNI";
21079     mt->subParams = YES;
21080     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21081     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21082     mt->nApplicable = 2;
21083     mt->moveFxn = &Move_NNI;
21084     mt->relProposalProb = 5.0;
21085     mt->numTuningParams = 0;
21086     mt->minimum[0] = 0.00001;
21087     mt->maximum[0] = 100.0;
21088     mt->parsimonyBased = NO;
21089     mt->level = STANDARD_USER;
21090     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21091 
21092     /* Move_NNI_Hetero */
21093     mt = &moveTypes[i++];
21094     mt->name = "NNI move for trees with independent brlens";
21095     mt->shortName = "MultNNI";
21096     mt->subParams = YES;
21097     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HETERO;
21098     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HETERO;
21099     mt->nApplicable = 2; /* 3; */
21100     mt->moveFxn = &Move_NNI_Hetero;
21101     mt->relProposalProb = 15.0;
21102     mt->numTuningParams = 0;
21103     mt->minimum[0] = 0.00001;
21104     mt->maximum[0] = 100.0;
21105     mt->parsimonyBased = NO;
21106     mt->level = STANDARD_USER;
21107     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21108 
21109     /* Move_NodeSlider */
21110     mt = &moveTypes[i++];
21111     mt->name = "Node slider (uniform on possible positions)";
21112     mt->shortName = "Nodeslider";
21113     mt->tuningName[0] = "Multiplier tuning parameter";
21114     mt->shortTuningName[0] = "lambda";
21115     mt->applicableTo[0] = BRLENS_UNI;
21116     mt->applicableTo[1] = BRLENS_EXP;
21117     mt->applicableTo[2] = BRLENS_GamDir;
21118     mt->applicableTo[3] = BRLENS_iGmDir;
21119     mt->applicableTo[4] = BRLENS_twoExp;
21120     mt->nApplicable = 5;  // was 2
21121     mt->moveFxn = &Move_NodeSlider;
21122     mt->relProposalProb = 7.0;
21123     mt->numTuningParams = 1;
21124     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21125     mt->minimum[0] = 0.00001;
21126     mt->maximum[0] = 100.0;
21127     mt->parsimonyBased = NO;
21128     mt->level = STANDARD_USER;
21129 
21130     /* Move_NodeSliderClock */
21131     mt = &moveTypes[i++];
21132     mt->name = "Node depth window slider (clock-constrained)";
21133     mt->shortName = "NodesliderClock";
21134     mt->tuningName[0] = "Window size";
21135     mt->shortTuningName[0] = "delta";
21136     mt->applicableTo[0] = BRLENS_CLOCK_UNI;
21137     mt->applicableTo[1] = BRLENS_CLOCK_COAL;
21138     mt->applicableTo[2] = BRLENS_CLOCK_BD;
21139     mt->applicableTo[3] = BRLENS_CLOCK_FOSSIL;
21140     mt->nApplicable = 4;
21141     mt->moveFxn = &Move_NodeSliderClock;
21142     mt->relProposalProb = 20.0;
21143     mt->numTuningParams = 1;
21144     mt->tuningParam[0] = 0.05; /* window size */
21145     mt->minimum[0] = 0.000001;
21146     mt->maximum[0] = 1.0;
21147     mt->parsimonyBased = NO;
21148     mt->level = STANDARD_USER;
21149     mt->Autotune = &AutotuneSlider;
21150     mt->targetRate = 0.25;
21151 
21152     /* Move_NodeSliderGeneTree */
21153     mt = &moveTypes[i++];
21154     mt->name = "Node depth slider for gene trees";
21155     mt->shortName = "NodesliderGenetree";
21156     mt->tuningName[0] = "Window size";
21157     mt->shortTuningName[0] = "delta";
21158     mt->applicableTo[0] = BRLENS_CLOCK_SPCOAL;
21159     mt->nApplicable = 1;
21160     mt->moveFxn = &Move_NodeSliderGeneTree;
21161     mt->relProposalProb = 20.0;
21162     mt->numTuningParams = 1;
21163     mt->tuningParam[0] = 0.05; /* window size */
21164     mt->minimum[0] = 0.000001;
21165     mt->maximum[0] = 100.0;
21166     mt->parsimonyBased = NO;
21167     mt->level = STANDARD_USER;
21168     mt->Autotune = &AutotuneSlider;
21169     mt->targetRate = 0.25;
21170 
21171     /* Move_Omega */
21172     mt = &moveTypes[i++];
21173     mt->name = "Sliding window";
21174     mt->shortName = "Slider";
21175     mt->tuningName[0] = "Sliding window size";
21176     mt->shortTuningName[0] = "delta";
21177     mt->applicableTo[0] = OMEGA_DIR;
21178     mt->nApplicable = 1;
21179     mt->moveFxn = &Move_Omega;
21180     mt->relProposalProb = 1.0;
21181     mt->numTuningParams = 1;
21182     mt->tuningParam[0] = 1.0; /* sliding window size */
21183     mt->minimum[0] = 0.000001;
21184     mt->maximum[0] = 100.0;
21185     mt->parsimonyBased = NO;
21186     mt->level = STANDARD_USER;
21187     mt->Autotune = &AutotuneSlider;
21188     mt->targetRate = 0.25;
21189 
21190     /* Move_Omega_M */
21191     mt = &moveTypes[i++];
21192     mt->name = "Multiplier";
21193     mt->shortName = "Multiplier";
21194     mt->tuningName[0] = "Multiplier tuning parameter";
21195     mt->shortTuningName[0] = "lambda";
21196     mt->applicableTo[0] = OMEGA_DIR;
21197     mt->nApplicable = 1;
21198     mt->moveFxn = &Move_Omega_M;
21199     mt->relProposalProb = 0.0;
21200     mt->numTuningParams = 1;
21201     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
21202     mt->minimum[0] = 0.0001;
21203     mt->maximum[0] = 20.0;                 /* smaller */
21204     mt->parsimonyBased = NO;
21205     mt->level = STANDARD_USER;
21206     mt->Autotune = &AutotuneMultiplier;
21207     mt->targetRate = 0.25;
21208 
21209     /* Move_OmegaBeta_M */
21210     mt = &moveTypes[i++];
21211     mt->name = "Multiplier";
21212     mt->shortName = "Multiplier";
21213     mt->paramName = "Omega_beta_M10";
21214     mt->tuningName[0] = "Multiplier tuning parameter";
21215     mt->shortTuningName[0] = "lambda";
21216     mt->applicableTo[0] = OMEGA_10UUB;
21217     mt->applicableTo[1] = OMEGA_10UUF;
21218     mt->applicableTo[2] = OMEGA_10UEB;
21219     mt->applicableTo[3] = OMEGA_10UEF;
21220     mt->applicableTo[4] = OMEGA_10UFB;
21221     mt->applicableTo[5] = OMEGA_10UFF;
21222     mt->applicableTo[6] = OMEGA_10EUB;
21223     mt->applicableTo[7] = OMEGA_10EUF;
21224     mt->applicableTo[8] = OMEGA_10EEB;
21225     mt->applicableTo[9] = OMEGA_10EEF;
21226     mt->applicableTo[10] = OMEGA_10EFB;
21227     mt->applicableTo[11] = OMEGA_10EFF;
21228     mt->nApplicable = 12;
21229     mt->moveFxn = &Move_OmegaBeta_M;
21230     mt->relProposalProb = 1.0;
21231     mt->numTuningParams = 1;
21232     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21233     mt->minimum[0] = 0.0001;
21234     mt->maximum[0] = 20.0;                 /* smaller */
21235     mt->parsimonyBased = NO;
21236     mt->level = STANDARD_USER;
21237     mt->Autotune = &AutotuneMultiplier;
21238     mt->targetRate = 0.25;
21239 
21240     /* Move_OmegaCat */
21241     mt = &moveTypes[i++];
21242     mt->name = "Dirichlet proposal";
21243     mt->shortName = "Dirichlet";
21244     mt->paramName = "Omega_pi";
21245     mt->tuningName[0] = "Dirichlet parameter";
21246     mt->shortTuningName[0] = "alpha";
21247     mt->applicableTo[0] = OMEGA_BUD;
21248     mt->applicableTo[1] = OMEGA_BED;
21249     mt->applicableTo[2] = OMEGA_BFD;
21250     mt->applicableTo[3] = OMEGA_FUD;
21251     mt->applicableTo[4] = OMEGA_FED;
21252     mt->applicableTo[5] = OMEGA_FFD;
21253     mt->applicableTo[6] = OMEGA_ED;
21254     mt->applicableTo[7] = OMEGA_FD;
21255     mt->applicableTo[8] = OMEGA_10UUB;
21256     mt->applicableTo[9] = OMEGA_10UEB;
21257     mt->applicableTo[10] = OMEGA_10UFB;
21258     mt->applicableTo[11] = OMEGA_10EUB;
21259     mt->applicableTo[12] = OMEGA_10EEB;
21260     mt->applicableTo[13] = OMEGA_10EFB;
21261     mt->applicableTo[14] = OMEGA_10FUB;
21262     mt->applicableTo[15] = OMEGA_10FEB;
21263     mt->applicableTo[16] = OMEGA_10FFB;
21264     mt->nApplicable = 17;
21265     mt->moveFxn = &Move_OmegaCat;
21266     mt->relProposalProb = 1.0;
21267     mt->numTuningParams = 1;
21268     mt->tuningParam[0] = 300.0;  /* alpha-pi */
21269     mt->minimum[0] = 0.001;
21270     mt->maximum[0] = 10000.0;
21271     mt->parsimonyBased = NO;
21272     mt->level = STANDARD_USER;
21273     mt->Autotune = &AutotuneDirichlet;
21274     mt->targetRate = 0.25;
21275 
21276     /* Move_OmegaGamma_M */
21277     mt = &moveTypes[i++];
21278     mt->name = "Multiplier";
21279     mt->shortName = "Multiplier";
21280     mt->paramName = "Omega_shape_M10";
21281     mt->tuningName[0] = "Multiplier tuning parameter";
21282     mt->shortTuningName[0] = "lambda";
21283     mt->applicableTo[0] = OMEGA_10UUB;
21284     mt->applicableTo[1] = OMEGA_10UUF;
21285     mt->applicableTo[2] = OMEGA_10UEB;
21286     mt->applicableTo[3] = OMEGA_10UEF;
21287     mt->applicableTo[4] = OMEGA_10EUB;
21288     mt->applicableTo[5] = OMEGA_10EUF;
21289     mt->applicableTo[6] = OMEGA_10EEB;
21290     mt->applicableTo[7] = OMEGA_10EEF;
21291     mt->applicableTo[8] = OMEGA_10FUB;
21292     mt->applicableTo[9] = OMEGA_10FUF;
21293     mt->applicableTo[10] = OMEGA_10FEB;
21294     mt->applicableTo[11] = OMEGA_10FEF;
21295     mt->nApplicable = 12;
21296     mt->moveFxn = &Move_OmegaGamma_M;
21297     mt->relProposalProb = 1.0;
21298     mt->numTuningParams = 1;
21299     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21300     mt->minimum[0] = 0.0001;
21301     mt->maximum[0] = 20.0;                 /* smaller */
21302     mt->parsimonyBased = NO;
21303     mt->level = STANDARD_USER;
21304     mt->Autotune = &AutotuneMultiplier;
21305     mt->targetRate = 0.25;
21306 
21307     /* Move_OmegaM3 */
21308     mt = &moveTypes[i++];
21309     mt->name = "Sliding window";
21310     mt->shortName = "Slider";
21311     mt->tuningName[0] = "Sliding window size";
21312     mt->shortTuningName[0] = "delta";
21313     mt->applicableTo[0] = OMEGA_ED;
21314     mt->applicableTo[1] = OMEGA_EF;
21315     mt->nApplicable = 2;
21316     mt->moveFxn = &Move_OmegaM3;
21317     mt->relProposalProb = 1.0;
21318     mt->numTuningParams = 1;
21319     mt->tuningParam[0] = 0.1;  /* window size */
21320     mt->minimum[0] = 0.00001;
21321     mt->maximum[0] = 1.0;
21322     mt->parsimonyBased = NO;
21323     mt->level = STANDARD_USER;
21324     mt->Autotune = &AutotuneSlider;
21325     mt->targetRate = 0.25;
21326 
21327     /* Move_OmegaPur : Let it be here so that omega moves are listed in logical order! */
21328     mt = &moveTypes[i++];
21329     mt->name = "Sliding window";
21330     mt->shortName = "Slider";
21331     mt->paramName = "Omega_pur";
21332     mt->tuningName[0] = "Sliding window size";
21333     mt->shortTuningName[0] = "delta";
21334     mt->applicableTo[0] = OMEGA_BUD;
21335     mt->applicableTo[1] = OMEGA_BUF;
21336     mt->applicableTo[2] = OMEGA_BED;
21337     mt->applicableTo[3] = OMEGA_BEF;
21338     mt->applicableTo[4] = OMEGA_BFD;
21339     mt->applicableTo[5] = OMEGA_BFF;
21340     mt->nApplicable = 6;
21341     mt->moveFxn = &Move_OmegaPur;
21342     mt->relProposalProb = 1.0;
21343     mt->numTuningParams = 1;
21344     mt->tuningParam[0] = 0.1;  /* window size */
21345     mt->minimum[0] = 0.00001;
21346     mt->maximum[0] = 1.0;
21347     mt->parsimonyBased = NO;
21348     mt->level = STANDARD_USER;
21349     mt->Autotune = &AutotuneSlider;
21350     mt->targetRate = 0.25;
21351 
21352     /* Move_OmegaPos */
21353     mt = &moveTypes[i++];
21354     mt->name = "Sliding window";
21355     mt->shortName = "Slider";
21356     mt->paramName = "Omega_pos";
21357     mt->tuningName[0] = "Sliding window size";
21358     mt->shortTuningName[0] = "delta";
21359     mt->applicableTo[0] = OMEGA_BUD;
21360     mt->applicableTo[1] = OMEGA_BUF;
21361     mt->applicableTo[2] = OMEGA_BED;
21362     mt->applicableTo[3] = OMEGA_BEF;
21363     mt->applicableTo[4] = OMEGA_FUD;
21364     mt->applicableTo[5] = OMEGA_FUF;
21365     mt->applicableTo[6] = OMEGA_FED;
21366     mt->applicableTo[7] = OMEGA_FEF;
21367     mt->nApplicable = 8;
21368     mt->moveFxn = &Move_OmegaPos;
21369     mt->relProposalProb = 1.0;
21370     mt->numTuningParams = 1;
21371     mt->tuningParam[0] = 1.0;  /* window size */
21372     mt->minimum[0] = 0.00001;
21373     mt->maximum[0] = 100.0;
21374     mt->parsimonyBased = NO;
21375     mt->level = STANDARD_USER;
21376     mt->Autotune = &AutotuneSlider;
21377     mt->targetRate = 0.25;
21378 
21379     /* Move_ParsEraser1 */
21380     mt = &moveTypes[i++];
21381     mt->name = "Parsimony-biased eraser version 1";
21382     mt->shortName = "pEraser1";
21383     mt->subParams = YES;
21384     mt->tuningName[0] = "Dirichlet parameter";
21385     mt->shortTuningName[0] = "alpha";
21386     mt->tuningName[1] = "parsimony warp factor";
21387     mt->shortTuningName[1] = "warp";
21388     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21389     mt->nApplicable = 1;
21390     mt->moveFxn = &Move_ParsEraser1;
21391     mt->relProposalProb = 0.0;
21392     mt->numTuningParams = 2;
21393     mt->tuningParam[0] = 0.5; /* alphaPi */
21394     mt->tuningParam[1] = 0.1; /* warp */
21395     mt->minimum[0] = 0.00001;
21396     mt->maximum[0] = 10000.0;
21397     mt->minimum[1] = 0.00001;
21398     mt->maximum[1] = 0.99999;
21399     mt->parsimonyBased = YES;
21400     mt->level = DEVELOPER;
21401     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
21402 
21403     /* Move_ParsFossilSPRClock */
21404     mt = &moveTypes[i++];
21405     mt->name = "Parsimony-biased fossil SPR for clock trees";
21406     mt->shortName = "ParsFossilSPRClock";
21407     mt->subParams = YES;
21408     mt->tuningName[0] = "parsimony warp factor";
21409     mt->shortTuningName[0] = "warp";
21410     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
21411     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
21412     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
21413     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
21414     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
21415     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
21416     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
21417     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
21418     mt->nApplicable = 8;
21419     mt->moveFxn = &Move_ParsFossilSPRClock;
21420     mt->relProposalProb = 0.0;
21421     mt->numTuningParams = 1;
21422     mt->tuningParam[0] = 0.1;  /* warp */
21423     mt->minimum[0] = 0.0;
21424     mt->maximum[0] = 1.0;
21425     mt->parsimonyBased = YES;
21426     mt->level = STANDARD_USER;
21427     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
21428 
21429     /* Move_ParsSPR asym */
21430     mt = &moveTypes[i++];
21431     mt->name = "Parsimony-biased SPR";
21432     mt->shortName = "ParsSPR";
21433     mt->subParams = YES;
21434     mt->tuningName[0] = "parsimony warp factor";
21435     mt->shortTuningName[0] = "warp";
21436     mt->tuningName[1] = "reweighting probability";
21437     mt->shortTuningName[1] = "r";
21438     mt->tuningName[2] = "typical branch length";
21439     mt->shortTuningName[2] = "v_t";
21440     mt->tuningName[3] = "multiplier tuning parameter";
21441     mt->shortTuningName[3] = "lambda";
21442     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21443     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21444     mt->nApplicable = 2;
21445     mt->moveFxn = &Move_ParsSPR;
21446     mt->relProposalProb = 5.0;
21447     mt->numTuningParams = 4;
21448     mt->tuningParam[0] = 0.1;              /* warp */
21449     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21450     mt->tuningParam[2] = 0.03;             /* typical branch length */
21451     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21452     mt->minimum[0] = 0.0;
21453     mt->maximum[0] = 1.0;
21454     mt->minimum[1] = 0.0;
21455     mt->maximum[1] = 0.3;
21456     mt->minimum[2] = 0.0001;
21457     mt->maximum[2] = 0.5;
21458     mt->minimum[3] = 2.0 * log (0.001);
21459     mt->maximum[3] = 2.0 * log (1000.);
21460     mt->parsimonyBased = YES;
21461     mt->level = STANDARD_USER;
21462     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21463 
21464     /* Move_ParsSPR1 e^{-S} */
21465     mt = &moveTypes[i++];
21466     mt->name = "Parsimony-biased SPR variant 1";
21467     mt->shortName = "ParsSPR1";
21468     mt->subParams = YES;
21469     mt->tuningName[0] = "parsimony warp factor";
21470     mt->shortTuningName[0] = "warp";
21471     mt->tuningName[1] = "reweighting probability";
21472     mt->shortTuningName[1] = "r";
21473     mt->tuningName[2] = "typical branch length";
21474     mt->shortTuningName[2] = "v_t";
21475     mt->tuningName[3] = "multiplier tuning parameter";
21476     mt->shortTuningName[3] = "lambda";
21477     mt->tuningName[4] = "moving distance";
21478     mt->shortTuningName[4] = "d";
21479     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21480     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21481     mt->nApplicable = 2;
21482     mt->moveFxn = &Move_ParsSPR1;
21483     mt->relProposalProb = 0.0;
21484     mt->numTuningParams = 5;
21485     mt->tuningParam[0] = 0.5;              /* warp */
21486     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21487     mt->tuningParam[2] = 0.03;             /* typical branch length */
21488     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21489     mt->tuningParam[4] = 10.0;             /* distance to move picked branch */
21490     mt->minimum[0] = 0.0;
21491     mt->maximum[0] = 5.0;
21492     mt->minimum[1] = 0.0;
21493     mt->maximum[1] = 0.3;
21494     mt->minimum[2] = 0.0001;
21495     mt->maximum[2] = 0.5;
21496     mt->minimum[3] = 2.0 * log (0.001);
21497     mt->maximum[3] = 2.0 * log (1000.);
21498     mt->minimum[4] = 2.0;
21499     mt->maximum[4] = 1000.0;
21500     mt->parsimonyBased = YES;
21501     mt->level = DEVELOPER;
21502     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21503 
21504     /* Move_ParsSPR2 S/N */
21505     mt = &moveTypes[i++];
21506     mt->name = "Parsimony-biased SPR variant 2";
21507     mt->shortName = "ParsSPR2";
21508     mt->subParams = YES;
21509     mt->tuningName[0] = "parsimony warp factor";
21510     mt->shortTuningName[0] = "warp";
21511     mt->tuningName[1] = "reweighting probability";
21512     mt->shortTuningName[1] = "r";
21513     mt->tuningName[2] = "typical branch length";
21514     mt->shortTuningName[2] = "v_t";
21515     mt->tuningName[3] = "multiplier tuning parameter";
21516     mt->shortTuningName[3] = "lambda";
21517     mt->tuningName[4] = "moving distance";
21518     mt->shortTuningName[4] = "d";
21519     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21520     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21521     mt->nApplicable = 2;
21522     mt->moveFxn = &Move_ParsSPR2;
21523     mt->relProposalProb = 0.0;
21524     mt->numTuningParams = 5;
21525     mt->tuningParam[0] = 0.1;              /* warp */
21526     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21527     mt->tuningParam[2] = 0.03;             /* typical branch length */
21528     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21529     mt->tuningParam[4] = 10.0;             /* distance to move picked branch */
21530     mt->minimum[0] = 0.0;
21531     mt->maximum[0] = 1.0;
21532     mt->minimum[1] = 0.0;
21533     mt->maximum[1] = 0.3;
21534     mt->minimum[2] = 0.0001;
21535     mt->maximum[2] = 0.5;
21536     mt->minimum[3] = 2.0 * log (0.001);
21537     mt->maximum[3] = 2.0 * log (1000.);
21538     mt->minimum[4] = 2.0;
21539     mt->maximum[4] = 1000.0;
21540     mt->parsimonyBased = YES;
21541     mt->level = DEVELOPER;
21542     mt->isApplicable = &IsApplicable_FourTaxaOrMore;
21543 
21544     /* Move_ParsSPRClock */
21545     mt = &moveTypes[i++];
21546     mt->name = "Parsimony-biased SPR for clock trees";
21547     mt->shortName = "ParsSPRClock";
21548     mt->subParams = YES;
21549     mt->tuningName[0] = "parsimony warp factor";
21550     mt->shortTuningName[0] = "warp";
21551     mt->applicableTo[0] = TOPOLOGY_CL_UNIFORM;
21552     mt->applicableTo[1] = TOPOLOGY_CCL_UNIFORM;
21553     mt->applicableTo[2] = TOPOLOGY_CL_CONSTRAINED;
21554     mt->applicableTo[3] = TOPOLOGY_CCL_CONSTRAINED;
21555     mt->applicableTo[4] = TOPOLOGY_RCL_UNIFORM;
21556     mt->applicableTo[5] = TOPOLOGY_RCL_CONSTRAINED;
21557     mt->applicableTo[6] = TOPOLOGY_RCCL_UNIFORM;
21558     mt->applicableTo[7] = TOPOLOGY_RCCL_CONSTRAINED;
21559     mt->nApplicable = 8;
21560     mt->moveFxn = &Move_ParsSPRClock;
21561     mt->relProposalProb = 8.0;
21562     mt->numTuningParams = 1;
21563     mt->tuningParam[0] = 0.1;  /* warp */
21564     mt->minimum[0] = 0.0;
21565     mt->maximum[0] = 1.0;
21566     mt->parsimonyBased = YES;
21567     mt->level = STANDARD_USER;
21568     mt->isApplicable = &IsApplicable_ThreeTaxaOrMore;
21569 
21570     /* Move_ParsTBR1 e^{-S} */
21571     mt = &moveTypes[i++];
21572     mt->name = "Parsimony-biased TBR variant 1";
21573     mt->shortName = "ParsTBR1";
21574     mt->subParams = YES;
21575     mt->tuningName[0] = "parsimony warp factor";
21576     mt->shortTuningName[0] = "warp";
21577     mt->tuningName[1] = "reweighting probability";
21578     mt->shortTuningName[1] = "r";
21579     mt->tuningName[2] = "typical branch length";
21580     mt->shortTuningName[2] = "v_t";
21581     mt->tuningName[3] = "multiplier tuning parameter";
21582     mt->shortTuningName[3] = "lambda";
21583     mt->tuningName[4] = "moving distance";
21584     mt->shortTuningName[4] = "d";
21585     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21586     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21587     mt->nApplicable = 2;
21588     mt->moveFxn = &Move_ParsTBR1;
21589     mt->relProposalProb = 0.0;
21590     mt->numTuningParams = 5;
21591     mt->tuningParam[0] = 0.5;              /* warp */
21592     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21593     mt->tuningParam[2] = 0.05;             /* typical branch length */
21594     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21595     mt->tuningParam[4] = 5.0;              /* distance to move picked branch */
21596     mt->minimum[0] = 0.0;
21597     mt->maximum[0] = 5.0;
21598     mt->minimum[1] = 0.0;
21599     mt->maximum[1] = 0.3;
21600     mt->minimum[2] = 0.0001;
21601     mt->maximum[2] = 0.5;
21602     mt->minimum[3] = 2.0 * log (0.001);
21603     mt->maximum[3] = 2.0 * log (1000.);
21604     mt->minimum[4] = 2.0;
21605     mt->maximum[4] = 1000.0;
21606     mt->parsimonyBased = YES;
21607     mt->level = DEVELOPER;
21608     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
21609 
21610     /* Move_ParsTBR2 S/N */
21611     mt = &moveTypes[i++];
21612     mt->name = "Parsimony-biased TBR variant 2";
21613     mt->shortName = "ParsTBR2";
21614     mt->subParams = YES;
21615     mt->tuningName[0] = "parsimony warp factor";
21616     mt->shortTuningName[0] = "warp";
21617     mt->tuningName[1] = "reweighting probability";
21618     mt->shortTuningName[1] = "r";
21619     mt->tuningName[2] = "typical branch length";
21620     mt->shortTuningName[2] = "v_t";
21621     mt->tuningName[3] = "multiplier tuning parameter";
21622     mt->shortTuningName[3] = "lambda";
21623     mt->tuningName[4] = "moving distance";
21624     mt->shortTuningName[4] = "d";
21625     mt->applicableTo[0] = TOPOLOGY_NCL_UNIFORM_HOMO;
21626     mt->applicableTo[1] = TOPOLOGY_NCL_CONSTRAINED_HOMO;
21627     mt->nApplicable = 2;
21628     mt->moveFxn = &Move_ParsTBR2;
21629     mt->relProposalProb = 0.0;
21630     mt->numTuningParams = 5;
21631     mt->tuningParam[0] = 0.1;              /* warp */
21632     mt->tuningParam[1] = 0.05;             /* upweight and downweight probability */
21633     mt->tuningParam[2] = 0.05;             /* typical branch length */
21634     mt->tuningParam[3] = 2.0 * log (1.05); /* multiplier tuning parameter lambda */
21635     mt->tuningParam[4] = 5.0;              /* distance to move picked branch */
21636     mt->minimum[0] = 0.0;
21637     mt->maximum[0] = 1.0;
21638     mt->minimum[1] = 0.0;
21639     mt->maximum[1] = 0.3;
21640     mt->minimum[2] = 0.0001;
21641     mt->maximum[2] = 0.5;
21642     mt->minimum[3] = 2.0 * log (0.001);
21643     mt->maximum[3] = 2.0 * log (1000.);
21644     mt->minimum[4] = 2.0;
21645     mt->maximum[4] = 1000.0;
21646     mt->parsimonyBased = YES;
21647     mt->level = DEVELOPER;
21648     mt->isApplicable = &IsApplicable_FiveTaxaOrMore;
21649 
21650     /* Move_Pinvar */
21651     mt = &moveTypes[i++];
21652     mt->name = "Sliding window";
21653     mt->shortName = "Slider";
21654     mt->tuningName[0] = "Sliding window size";
21655     mt->shortTuningName[0] = "delta";
21656     mt->applicableTo[0] = PINVAR_UNI;
21657     mt->nApplicable = 1;
21658     mt->moveFxn = &Move_Pinvar;
21659     mt->relProposalProb = 1.0;
21660     mt->numTuningParams = 1;
21661     mt->tuningParam[0] = 0.1;  /* window size */
21662     mt->minimum[0] = 0.001;
21663     mt->maximum[0] = 0.999;
21664     mt->parsimonyBased = NO;
21665     mt->level = STANDARD_USER;
21666     mt->Autotune = &AutotuneSlider;
21667     mt->targetRate = 0.25;
21668 
21669     /* Move_Popsize_M */
21670     mt = &moveTypes[i++];
21671     mt->name = "Multiplier";
21672     mt->shortName = "Multiplier";
21673     mt->tuningName[0] = "Multiplier tuning parameter";
21674     mt->shortTuningName[0] = "lambda";
21675     mt->applicableTo[0] = POPSIZE_UNI;
21676     mt->applicableTo[1] = POPSIZE_LOGNORMAL;
21677     mt->applicableTo[2] = POPSIZE_NORMAL;
21678     mt->applicableTo[3] = POPSIZE_GAMMA;
21679     mt->nApplicable = 4;
21680     mt->moveFxn = &Move_PopSize_M;
21681     mt->relProposalProb = 1.0;
21682     mt->numTuningParams = 1;
21683     mt->tuningParam[0] = 2.0 * log(1.5);  /* lambda */
21684     mt->minimum[0] = 0.00001;
21685     mt->maximum[0] = 100.0;
21686     mt->parsimonyBased = NO;
21687     mt->level = STANDARD_USER;
21688     mt->Autotune = &AutotuneSlider;
21689     mt->targetRate = 0.25;
21690 
21691     /* Move_RateMult_Dir */
21692     mt = &moveTypes[i++];
21693     mt->name = "Dirichlet proposal";
21694     mt->shortName = "Dirichlet";
21695     mt->tuningName[0] = "Dirichlet parameter";
21696     mt->shortTuningName[0] = "alpha";
21697     mt->applicableTo[0] = RATEMULT_DIR;
21698     mt->nApplicable = 1;
21699     mt->moveFxn = &Move_RateMult_Dir;
21700     mt->relProposalProb = 0.75;
21701     mt->numTuningParams = 1;
21702     mt->tuningParam[0] = 50.0; /* alphaPi per site */
21703     mt->minimum[0] = 0.001;
21704     mt->maximum[0] = 10000.0;
21705     mt->parsimonyBased = NO;
21706     mt->level = STANDARD_USER;
21707     mt->Autotune = &AutotuneDirichlet;
21708     mt->targetRate = 0.25;
21709 
21710     /* Move_RateMult_Slider */
21711     mt = &moveTypes[i++];
21712     mt->name = "Sliding window";
21713     mt->shortName = "Slider";
21714     mt->tuningName[0] = "Sliding window size";
21715     mt->shortTuningName[0] = "delta";
21716     mt->applicableTo[0] = RATEMULT_DIR;
21717     mt->nApplicable = 1;
21718     mt->moveFxn = &Move_RateMult_Slider;
21719     mt->relProposalProb = 0.75;
21720     mt->numTuningParams = 1;
21721     mt->tuningParam[0] = 0.05;  /* window size */
21722     mt->minimum[0] = 0.00001;
21723     mt->maximum[0] = 1.0;
21724     mt->parsimonyBased = NO;
21725     mt->level = STANDARD_USER;
21726     mt->Autotune = &AutotuneSlider;
21727     mt->targetRate = 0.25;
21728 
21729     /* Move_RateShape_M */
21730     mt = &moveTypes[i++];
21731     mt->name = "Multiplier";
21732     mt->shortName = "Multiplier";
21733     mt->tuningName[0] = "Multiplier tuning parameter";
21734     mt->shortTuningName[0] = "lambda";
21735     mt->applicableTo[0] = SHAPE_UNI;
21736     mt->applicableTo[1] = SHAPE_EXP;
21737     mt->nApplicable = 2;
21738     mt->moveFxn = &Move_RateShape_M;
21739     mt->relProposalProb = 1.0;
21740     mt->numTuningParams = 1;
21741     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
21742     mt->minimum[0] = 0.0001;
21743     mt->maximum[0] = 10.0;                 /* smaller */
21744     mt->parsimonyBased = NO;
21745     mt->level = STANDARD_USER;
21746     mt->Autotune = &AutotuneMultiplier;
21747     mt->targetRate = 0.25;
21748 
21749     /* Move_Revmat_Dir */
21750     mt = &moveTypes[i++];
21751     mt->name = "Dirichlet proposal";
21752     mt->shortName = "Dirichlet";
21753     mt->tuningName[0] = "Dirichlet parameter";
21754     mt->shortTuningName[0] = "alpha";
21755     mt->applicableTo[0] = REVMAT_DIR;
21756     mt->nApplicable = 1;
21757     mt->moveFxn = &Move_Revmat_Dir;
21758     mt->relProposalProb = 0.5;
21759     mt->numTuningParams = 1;
21760     mt->tuningParam[0] = 100.0;  /* alphaPi per rate */
21761     mt->minimum[0] = 0.001;
21762     mt->maximum[0] = 10000.0;
21763     mt->parsimonyBased = NO;
21764     mt->level = STANDARD_USER;
21765     mt->Autotune = &AutotuneDirichlet;
21766     mt->targetRate = 0.25;
21767 
21768     /* Move_Revmat_Slider */
21769     mt = &moveTypes[i++];
21770     mt->name = "Sliding window";
21771     mt->shortName = "Slider";
21772     mt->tuningName[0] = "Sliding window size";
21773     mt->shortTuningName[0] = "delta";
21774     mt->applicableTo[0] = REVMAT_DIR;
21775     mt->nApplicable = 1;
21776     mt->moveFxn = &Move_Revmat_Slider;
21777     mt->relProposalProb = 0.5;
21778     mt->numTuningParams = 1;
21779     mt->tuningParam[0] = 0.15;  /* window size */
21780     mt->minimum[0] = 0.00001;
21781     mt->maximum[0] = 1.0;
21782     mt->parsimonyBased = NO;
21783     mt->level = STANDARD_USER;
21784     mt->Autotune = &AutotuneSlider;
21785     mt->targetRate = 0.25;
21786 
21787     /* Move_Revmat_DirMix */
21788     mt = &moveTypes[i++];
21789     mt->name = "Dirichlet proposal";
21790     mt->shortName = "Dirichlet";
21791     mt->tuningName[0] = "Dirichlet parameter";
21792     mt->shortTuningName[0] = "alpha";
21793     mt->applicableTo[0] = REVMAT_MIX;
21794     mt->nApplicable = 1;
21795     mt->moveFxn = &Move_Revmat_DirMix;
21796     mt->relProposalProb = 1.0;
21797     mt->numTuningParams = 1;
21798     mt->tuningParam[0] = 100.0;  /* alphaPi per rate */
21799     mt->minimum[0] = 0.01;
21800     mt->maximum[0] = 10000.0;
21801     mt->parsimonyBased = NO;
21802     mt->level = STANDARD_USER;
21803     mt->Autotune = &AutotuneDirichlet;
21804     mt->targetRate = 0.25;
21805 
21806     /* Move_Revmat_SplitMerge1 */
21807     mt = &moveTypes[i++];
21808     mt->name = "Split-merge move 1";
21809     mt->shortName = "Splitmerge1";
21810     mt->tuningName[0] = "Dirichlet parameter";
21811     mt->shortTuningName[0] = "alpha";
21812     mt->applicableTo[0] = REVMAT_MIX;
21813     mt->nApplicable = 1;
21814     mt->moveFxn = &Move_Revmat_SplitMerge1;
21815     mt->relProposalProb = 1.0;
21816     mt->numTuningParams = 1;
21817     mt->tuningParam[0] = 10.0;  /* alphaPi per rate */
21818     mt->minimum[0] = 0.5;
21819     mt->maximum[0] = 100.0;
21820     mt->parsimonyBased = NO;
21821     mt->level = STANDARD_USER;
21822     mt->Autotune = &AutotuneDirichlet;
21823     mt->targetRate = 0.25;
21824 
21825     /* Move_Revmat_SplitMerge2 */
21826     mt = &moveTypes[i++];
21827     mt->name = "Split-merge move 2";
21828     mt->shortName = "Splitmerge2";
21829     mt->tuningName[0] = "Dirichlet parameter";
21830     mt->shortTuningName[0] = "alpha";
21831     mt->applicableTo[0] = REVMAT_MIX;
21832     mt->nApplicable = 1;
21833     mt->moveFxn = &Move_Revmat_SplitMerge2;
21834     mt->relProposalProb = 1.0;
21835     mt->numTuningParams = 1;
21836     mt->tuningParam[0] = 10.0;  /* alphaPi per rate */
21837     mt->minimum[0] = 0.5;
21838     mt->maximum[0] = 100.0;
21839     mt->parsimonyBased = NO;
21840     mt->level = STANDARD_USER;
21841     mt->Autotune = &AutotuneDirichlet;
21842     mt->targetRate = 0.25;
21843 
21844     /* Move_Speciation */
21845     mt = &moveTypes[i++];
21846     mt->name = "Sliding window";
21847     mt->shortName = "Slider";
21848     mt->tuningName[0] = "Sliding window size";
21849     mt->shortTuningName[0] = "delta";
21850     mt->applicableTo[0] = SPECRATE_UNI;
21851     mt->applicableTo[1] = SPECRATE_EXP;
21852     mt->nApplicable = 2;
21853     mt->moveFxn = &Move_Speciation;
21854     mt->relProposalProb = 0.0;
21855     mt->numTuningParams = 1;
21856     mt->tuningParam[0] = 1.0;  /* window size */
21857     mt->minimum[0] = 0.00001;
21858     mt->maximum[0] = 100.0;
21859     mt->parsimonyBased = NO;
21860     mt->level = STANDARD_USER;
21861     mt->Autotune = &AutotuneSlider;
21862     mt->targetRate = 0.25;
21863 
21864     /* Move_Speciation_M */
21865     mt = &moveTypes[i++];
21866     mt->name = "Multiplier";
21867     mt->shortName = "Multiplier";
21868     mt->tuningName[0] = "Multiplier tuning parameter";
21869     mt->shortTuningName[0] = "lambda";
21870     mt->applicableTo[0] = SPECRATE_UNI;
21871     mt->applicableTo[1] = SPECRATE_EXP;
21872     mt->nApplicable = 2;
21873     mt->moveFxn = &Move_Speciation_M;
21874     mt->relProposalProb = 3.0;
21875     mt->numTuningParams = 1;
21876     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
21877     mt->minimum[0] = 0.00001;
21878     mt->maximum[0] = 20.0;                 /* smaller */
21879     mt->parsimonyBased = NO;
21880     mt->level = STANDARD_USER;
21881     mt->Autotune = &AutotuneMultiplier;
21882     mt->targetRate = 0.25;
21883 
21884     /* Move_SpeciesTree */
21885     mt = &moveTypes[i++];
21886     mt->name = "Species tree move";
21887     mt->shortName = "Distmatrixmove";
21888     mt->tuningName[0] = "Divider of rate of truncated exponential";
21889     mt->shortTuningName[0] = "lambdadiv";
21890     mt->applicableTo[0] = SPECIESTREE_UNIFORM;
21891     mt->nApplicable = 1;
21892     mt->moveFxn = &Move_SpeciesTree;
21893     mt->relProposalProb = 10.0;
21894     mt->numTuningParams = 1;
21895     mt->tuningParam[0] = 1.2;       /* Default tuning parameter value */
21896     mt->minimum[0] = 0.00001;       /* Minimum value of tuning param */
21897     mt->maximum[0] = 1000.0;        /* Maximum value of tuning param */
21898     mt->parsimonyBased = NO;        /* It does not use parsimony scores */
21899     mt->level = STANDARD_USER;
21900     mt->Autotune = &AutotuneMultiplier; /* Autotune this move as a mutliplier move (larger is more bold) */
21901     mt->targetRate = 0.25;              /* Target acceptance rate */
21902 
21903     /* Move_Statefreqs */
21904     mt = &moveTypes[i++];
21905     mt->name = "Dirichlet proposal";
21906     mt->shortName = "Dirichlet";
21907     mt->tuningName[0] = "Dirichlet parameter";
21908     mt->shortTuningName[0] = "alpha";
21909     mt->applicableTo[0] = PI_DIR;
21910     mt->nApplicable = 1;
21911     mt->moveFxn = &Move_Statefreqs;
21912     mt->relProposalProb = 0.5;
21913     mt->numTuningParams = 1;
21914     mt->tuningParam[0] = 100.0; /* alphaPi per state */
21915     mt->minimum[0] = 0.001;
21916     mt->maximum[0] = 10000.0;
21917     mt->parsimonyBased = NO;
21918     mt->level = STANDARD_USER;
21919     mt->Autotune = &AutotuneDirichlet;
21920     mt->targetRate = 0.25;
21921 
21922     /* Move_Statefreqs_Slider */
21923     mt = &moveTypes[i++];
21924     mt->name = "Sliding window";
21925     mt->shortName = "Slider";
21926     mt->tuningName[0] = "Sliding window size";
21927     mt->shortTuningName[0] = "delta";
21928     mt->applicableTo[0] = PI_DIR;
21929     mt->nApplicable = 1;
21930     mt->moveFxn = &Move_Statefreqs_Slider;
21931     mt->relProposalProb = 0.5;
21932     mt->numTuningParams = 1;
21933     mt->tuningParam[0] = 0.20;  /* window size (change in proportions) */
21934     mt->minimum[0] = 0.00001;
21935     mt->maximum[0] = 1.0;
21936     mt->parsimonyBased = NO;
21937     mt->level = STANDARD_USER;
21938     mt->Autotune = &AutotuneSlider;
21939     mt->targetRate = 0.25;
21940 
21941     /* Move_StatefreqsSymDirMultistate */
21942     mt = &moveTypes[i++];
21943     mt->name = "Dirichlet proposal";
21944     mt->shortName = "Dirichlet";
21945     mt->paramName = "Pi_symdir";
21946     mt->tuningName[0] = "Dirichlet parameter";
21947     mt->shortTuningName[0] = "alpha";
21948     mt->applicableTo[0] = SYMPI_FIX_MS;
21949     mt->applicableTo[1] = SYMPI_UNI_MS;
21950     mt->applicableTo[2] = SYMPI_EXP_MS;
21951     mt->nApplicable = 3;
21952     mt->moveFxn = &Move_StatefreqsSymDirMultistate;
21953     mt->relProposalProb = 5.0;
21954     mt->numTuningParams = 1;
21955     mt->tuningParam[0] = 50.0; /* alphaPi */
21956     mt->minimum[0] = 0.001;
21957     mt->maximum[0] = 10000.0;
21958     mt->parsimonyBased = NO;
21959     mt->level = STANDARD_USER;
21960     mt->Autotune = &AutotuneDirichlet;
21961     mt->targetRate = 0.25;
21962 
21963     /* Move_SwitchRate */
21964     mt = &moveTypes[i++];
21965     mt->name = "Sliding window";
21966     mt->shortName = "Slider";
21967     mt->tuningName[0] = "Sliding window size";
21968     mt->shortTuningName[0] = "delta";
21969     mt->applicableTo[0] = SWITCH_UNI;
21970     mt->applicableTo[1] = SWITCH_EXP;
21971     mt->nApplicable = 2;
21972     mt->moveFxn = &Move_SwitchRate;
21973     mt->relProposalProb = 1.0;
21974     mt->numTuningParams = 1;
21975     mt->tuningParam[0] = 1.0;  /* window size */
21976     mt->minimum[0] = 0.00001;
21977     mt->maximum[0] = 100.0;
21978     mt->parsimonyBased = NO;
21979     mt->level = STANDARD_USER;
21980     mt->Autotune = &AutotuneSlider;
21981     mt->targetRate = 0.25;
21982 
21983     /* Move_SwitchRate_M */
21984     mt = &moveTypes[i++];
21985     mt->name = "Multiplier";
21986     mt->shortName = "Multiplier";
21987     mt->tuningName[0] = "Multiplier tuning parameter";
21988     mt->shortTuningName[0] = "lambda";
21989     mt->applicableTo[0] = SWITCH_UNI;
21990     mt->applicableTo[1] = SWITCH_EXP;
21991     mt->nApplicable = 2;
21992     mt->moveFxn = &Move_SwitchRate_M;
21993     mt->relProposalProb = 0.0;
21994     mt->numTuningParams = 1;
21995     mt->tuningParam[0] = 2.0 * log (1.5);  /* lambda */
21996     mt->minimum[0] = 0.0001;
21997     mt->maximum[0] = 20.0;                 /* smaller */
21998     mt->parsimonyBased = NO;
21999     mt->level = STANDARD_USER;
22000     mt->Autotune = &AutotuneMultiplier;
22001     mt->targetRate = 0.25;
22002 
22003     /* Move_Tratio_Dir */
22004     mt = &moveTypes[i++];
22005     mt->name = "Dirichlet proposal";
22006     mt->shortName = "Dirichlet";
22007     mt->tuningName[0] = "Dirichlet parameter";
22008     mt->shortTuningName[0] = "alpha";
22009     mt->applicableTo[0] = TRATIO_DIR;
22010     mt->nApplicable = 1;
22011     mt->moveFxn = &Move_Tratio_Dir;
22012     mt->relProposalProb = 1.0;
22013     mt->numTuningParams = 1;
22014     mt->tuningParam[0] = 50.0;  /* alphaPi */
22015     mt->minimum[0] = 0.001;
22016     mt->maximum[0] = 10000.0;
22017     mt->parsimonyBased = NO;
22018     mt->level = STANDARD_USER;
22019     mt->Autotune = &AutotuneDirichlet;
22020     mt->targetRate = 0.25;
22021 
22022     /* Move_TreeStretch */
22023     mt = &moveTypes[i++];
22024     mt->name = "Tree stretch";
22025     mt->shortName = "TreeStretch";
22026     mt->tuningName[0] = "Multiplier tuning parameter";
22027     mt->shortTuningName[0] = "lambda";
22028     mt->applicableTo[0] = BRLENS_CLOCK_UNI;
22029     mt->applicableTo[1] = BRLENS_CLOCK_BD;
22030     mt->applicableTo[2] = BRLENS_CLOCK_COAL;
22031     mt->applicableTo[3] = BRLENS_CLOCK_FOSSIL;
22032     mt->nApplicable = 4;
22033     mt->moveFxn = &Move_TreeStretch;
22034     mt->relProposalProb = 3.0;
22035     mt->numTuningParams = 1;
22036     mt->tuningParam[0] = 2.0 * log(1.01); /* lambda */
22037     mt->minimum[0] = 0.0001;
22038     mt->maximum[0] = 2.0 * log(2.0);
22039     mt->parsimonyBased = NO;
22040     mt->level = STANDARD_USER;
22041     mt->Autotune = &AutotuneMultiplier;
22042     mt->targetRate = 0.25;
22043 
22044     /* Move_TreeLen, by Jeremy Brown */
22045     mt = &moveTypes[i++];
22046     mt->name = "Whole treelength hit with multiplier";
22047     mt->shortName = "TLMultiplier";
22048     mt->tuningName[0] = "Multiplier tuning parameter";
22049     mt->shortTuningName[0] = "lambda";
22050     mt->applicableTo[0] = BRLENS_UNI;
22051     mt->applicableTo[1] = BRLENS_EXP;
22052     mt->applicableTo[2] = BRLENS_GamDir;
22053     mt->applicableTo[3] = BRLENS_iGmDir;
22054     mt->applicableTo[4] = BRLENS_twoExp;
22055     mt->nApplicable = 5;  // was 2
22056     mt->moveFxn = &Move_TreeLen;
22057     mt->relProposalProb = 3.0;
22058     mt->numTuningParams = 1;
22059     mt->tuningParam[0] = 2.0 * log (2.0);  /* lambda */
22060     mt->minimum[0] = 0.0001;
22061     mt->maximum[0] = 100.0;                /* smaller */
22062     mt->parsimonyBased = NO;
22063     mt->level = STANDARD_USER;
22064     mt->Autotune = &AutotuneMultiplier;
22065     mt->targetRate = 0.25;
22066 
22067     /* Move_AddDeleteCPPEvent */
22068     mt = &moveTypes[i++];
22069     mt->name = "Random addition/deletion of CPP event";
22070     mt->shortName = "Add_delete";
22071     mt->applicableTo[0] = CPPEVENTS;
22072     mt->nApplicable = 1;
22073     mt->moveFxn = &Move_AddDeleteCPPEvent;
22074     mt->relProposalProb = 1.0;
22075     mt->numTuningParams = 0;
22076     mt->parsimonyBased = NO;
22077     mt->level = STANDARD_USER;
22078 
22079     /* Move_CPPEventPosition */
22080     mt = &moveTypes[i++];
22081     mt->name = "Random draw of CPP event position from prior";
22082     mt->shortName = "Prior_draw_pos";
22083     mt->applicableTo[0] = CPPEVENTS;
22084     mt->nApplicable = 1;
22085     mt->moveFxn = &Move_CPPEventPosition;
22086     mt->relProposalProb = 2.0;
22087     mt->numTuningParams = 0;
22088     mt->parsimonyBased = NO;
22089     mt->level = STANDARD_USER;
22090 
22091     /* Move_CPPRate */
22092     mt = &moveTypes[i++];
22093     mt->name = "Multiplier";
22094     mt->shortName = "Multiplier";
22095     mt->tuningName[0] = "Multiplier tuning parameter";
22096     mt->shortTuningName[0] = "lambda";
22097     mt->applicableTo[0] = CPPRATE_EXP;
22098     mt->nApplicable = 1;
22099     mt->moveFxn = &Move_CPPRate;
22100     mt->relProposalProb = 2.0;
22101     mt->numTuningParams = 1;
22102     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22103     mt->minimum[0] = 0.0001;
22104     mt->maximum[0] = 20.0;                 /* smaller */
22105     mt->parsimonyBased = NO;
22106     mt->level = STANDARD_USER;
22107     mt->Autotune = &AutotuneMultiplier;
22108     mt->targetRate = 0.25;
22109 
22110     /* Move_CPPRateMultiplier_M */
22111     mt = &moveTypes[i++];
22112     mt->name = "Random CPP rate multiplier hit with multiplier";
22113     mt->shortName = "Multiplier";
22114     mt->tuningName[0] = "Multiplier tuning parameter";
22115     mt->shortTuningName[0] = "lambda";
22116     mt->applicableTo[0] = CPPEVENTS;
22117     mt->nApplicable = 1;
22118     mt->moveFxn = &Move_CPPRateMultiplier_M;
22119     mt->relProposalProb = 0.0;
22120     mt->numTuningParams = 1;
22121     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22122     mt->minimum[0] = 0.0001;
22123     mt->maximum[0] = 20.0;                 /* smaller */
22124     mt->parsimonyBased = NO;
22125     mt->level = STANDARD_USER;
22126     mt->Autotune = &AutotuneMultiplier;
22127     mt->targetRate = 0.25;
22128 
22129     /* Move_CPPRateMultiplierRnd */
22130     mt = &moveTypes[i++];
22131     mt->name = "Random draw of CPP rate multiplier from prior";
22132     mt->shortName = "Prior_draw_mult";
22133     mt->applicableTo[0] = CPPEVENTS;
22134     mt->nApplicable = 1;
22135     mt->moveFxn = &Move_CPPRateMultiplierRnd;
22136     mt->relProposalProb = 2.0;
22137     mt->numTuningParams = 0;
22138     mt->parsimonyBased = NO;
22139     mt->level = STANDARD_USER;
22140 
22141     /* Move_Nu */
22142     mt = &moveTypes[i++];
22143     mt->name = "Multiplier";
22144     mt->shortName = "Multiplier";
22145     mt->tuningName[0] = "Multiplier tuning parameter";
22146     mt->shortTuningName[0] = "lambda";
22147     mt->applicableTo[0] = TK02VAR_EXP;
22148     mt->applicableTo[1] = TK02VAR_UNI;
22149     mt->nApplicable = 2;
22150     mt->moveFxn = &Move_Nu;
22151     mt->relProposalProb = 2.0;
22152     mt->numTuningParams = 1;
22153     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22154     mt->minimum[0] = 0.0001;
22155     mt->maximum[0] = 20.0;                 /* smaller */
22156     mt->parsimonyBased = NO;
22157     mt->level = STANDARD_USER;
22158     mt->Autotune = &AutotuneMultiplier;
22159     mt->targetRate = 0.25;
22160 
22161     /* Move_TK02BranchRate */
22162     mt = &moveTypes[i++];
22163     mt->name = "Multiplier";
22164     mt->shortName = "Multiplier";
22165     mt->tuningName[0] = "Multiplier tuning parameter";
22166     mt->shortTuningName[0] = "lambda";
22167     mt->applicableTo[0] = TK02BRANCHRATES;
22168     mt->nApplicable = 1;
22169     mt->moveFxn = &Move_TK02BranchRate;
22170     mt->relProposalProb = 15.0;
22171     mt->numTuningParams = 1;
22172     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22173     mt->minimum[0] = 0.0001;
22174     mt->maximum[0] = 20.0;
22175     mt->parsimonyBased = NO;
22176     mt->level = STANDARD_USER;
22177     mt->Autotune = &AutotuneMultiplier;
22178     mt->targetRate = 0.25;
22179 
22180     /* Move_IgrVar */
22181     mt = &moveTypes[i++];
22182     mt->name = "Multiplier";
22183     mt->shortName = "Multiplier";
22184     mt->tuningName[0] = "Multiplier tuning parameter";
22185     mt->shortTuningName[0] = "lambda";
22186     mt->applicableTo[0] = IGRVAR_EXP;
22187     mt->applicableTo[1] = IGRVAR_UNI;
22188     mt->nApplicable = 2;
22189     mt->moveFxn = &Move_IgrVar;
22190     mt->relProposalProb = 2.0;
22191     mt->numTuningParams = 1;
22192     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22193     mt->minimum[0] = 0.0001;
22194     mt->maximum[0] = 20.0;                 /* smaller */
22195     mt->parsimonyBased = NO;
22196     mt->level = STANDARD_USER;
22197     mt->Autotune = &AutotuneMultiplier;
22198     mt->targetRate = 0.25;
22199 
22200     /* Move_IgrBranchRate */
22201     mt = &moveTypes[i++];
22202     mt->name = "Multiplier";
22203     mt->shortName = "Multiplier";
22204     mt->tuningName[0] = "Multiplier tuning parameter";
22205     mt->shortTuningName[0] = "lambda";
22206     mt->applicableTo[0] = IGRBRANCHRATES;
22207     mt->nApplicable = 1;
22208     mt->moveFxn = &Move_IgrBranchRate;
22209     mt->relProposalProb = 15.0;
22210     mt->numTuningParams = 1;
22211     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22212     mt->minimum[0] = 0.0001;
22213     mt->maximum[0] = 20.0;
22214     mt->parsimonyBased = NO;
22215     mt->level = STANDARD_USER;
22216     mt->Autotune = &AutotuneMultiplier;
22217     mt->targetRate = 0.25;
22218 
22219     /* Move_MixedVar */
22220     mt = &moveTypes[i++];
22221     mt->name = "Multiplier";
22222     mt->shortName = "Multiplier";
22223     mt->tuningName[0] = "Multiplier tuning parameter";
22224     mt->shortTuningName[0] = "lambda";
22225     mt->applicableTo[0] = MIXEDVAR_EXP;
22226     mt->applicableTo[1] = MIXEDVAR_UNI;
22227     mt->nApplicable = 2;
22228     mt->moveFxn = &Move_MixedVar;
22229     mt->relProposalProb = 2.0;
22230     mt->numTuningParams = 1;
22231     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22232     mt->minimum[0] = 0.0001;
22233     mt->maximum[0] = 20.0;                 /* smaller */
22234     mt->parsimonyBased = NO;
22235     mt->level = STANDARD_USER;
22236     mt->Autotune = &AutotuneMultiplier;
22237     mt->targetRate = 0.25;
22238 
22239     /* Move_MixedBranchRate */
22240     mt = &moveTypes[i++];
22241     mt->name = "Multiplier";
22242     mt->shortName = "Multiplier";
22243     mt->tuningName[0] = "Multiplier tuning parameter";
22244     mt->shortTuningName[0] = "lambda";
22245     mt->applicableTo[0] = MIXEDBRCHRATES;
22246     mt->nApplicable = 1;
22247     mt->moveFxn = &Move_MixedBranchRate;
22248     mt->relProposalProb = 15.0;
22249     mt->numTuningParams = 1;
22250     mt->tuningParam[0] = 2.0 * log (1.1);  /* lambda */
22251     mt->minimum[0] = 0.0001;
22252     mt->maximum[0] = 20.0;
22253     mt->parsimonyBased = NO;
22254     mt->level = STANDARD_USER;
22255     mt->Autotune = &AutotuneMultiplier;
22256     mt->targetRate = 0.25;
22257 
22258     /* Move_RelaxedClockModel */
22259     mt = &moveTypes[i++];
22260     mt->name = "rjMCMC among Relaxed Clock Models";
22261     mt->shortName = "rjMCMC_RCL";
22262     mt->tuningName[0] = "sigma_TK over sigma_IGR";
22263     mt->shortTuningName[0] = "ratio";
22264     mt->tuningName[1] = "Sliding window size";
22265     mt->shortTuningName[1] = "delta";
22266     mt->applicableTo[0] = MIXEDBRCHRATES;
22267     mt->nApplicable = 1;
22268     mt->moveFxn = &Move_RelaxedClockModel;
22269     mt->relProposalProb = 5.0;
22270     mt->numTuningParams = 2;
22271     mt->tuningParam[0] = 100.0; /* TK/IGR var ratio */
22272     mt->tuningParam[1] = 10.0;  /* window size */
22273     mt->minimum[0] = 0.0001;
22274     mt->maximum[0] = 10000.0;
22275     mt->minimum[1] = 0.0001;
22276     mt->maximum[1] = 1000.0;
22277     mt->parsimonyBased = NO;
22278     mt->level = STANDARD_USER;
22279 
22280     numMoveTypes = i;
22281 
22282     assert(numMoveTypes < NUM_MOVE_TYPES);
22283 }
22284 
22285 
22286 /* ShowModel: Display model on screen */
ShowModel(void)22287 int ShowModel (void)
22288 {
22289     int         i, j, ns;
22290 
22291     MrBayesPrint ("%s   Model settings:\n\n", spacer);
22292     for (i=0; i<numCurrentDivisions; i++)
22293         {
22294         ns = 0;
22295 
22296         if (numCurrentDivisions > 1)
22297             MrBayesPrint ("%s      Settings for partition %d --\n", spacer, i+1);
22298         else
22299             MrBayesPrint ("%s      Data not partitioned --\n", spacer);
22300 
22301         if (modelParams[i].dataType == DNA)
22302             {
22303             MrBayesPrint ("%s         Datatype  = DNA\n", spacer);
22304             ns = 4;
22305             }
22306         else if (modelParams[i].dataType == RNA)
22307             {
22308             MrBayesPrint ("%s         Datatype  = RNA\n", spacer);
22309             ns = 4;
22310             }
22311         else if (modelParams[i].dataType == PROTEIN)
22312             {
22313             MrBayesPrint ("%s         Datatype  = Protein\n", spacer);
22314             ns = 20;
22315             }
22316         else if (modelParams[i].dataType == RESTRICTION)
22317             {
22318             MrBayesPrint ("%s         Datatype  = Restriction\n", spacer);
22319             ns = 2;
22320             }
22321         else if (modelParams[i].dataType == STANDARD)
22322             {
22323             MrBayesPrint ("%s         Datatype  = Standard\n", spacer);
22324             ns = 10;
22325             }
22326         else if (modelParams[i].dataType == CONTINUOUS)
22327             {
22328             MrBayesPrint ("%s         Datatype  = Continuous\n", spacer);
22329             }
22330 
22331         if (modelSettings[i].dataType == CONTINUOUS)
22332             {
22333             /* begin description of continuous models */
22334               if (!strcmp(modelParams[i].brownCorPr, "Fixed") && AreDoublesEqual(modelParams[i].brownCorrFix, 0.0, ETA)==YES)
22335                 MrBayesPrint ("%s         Model     = Independent Brownian motion\n", spacer);
22336             else
22337                 MrBayesPrint ("%s         Model     = Correlated Brownian motion\n", spacer);
22338             /* end description of continuous models */
22339             }
22340         else
22341             {
22342             /* begin description of discrete models */
22343             if (!strcmp(modelParams[i].parsModel, "Yes"))
22344                 {
22345                 MrBayesPrint ("%s         Parsmodel = %s\n", spacer, modelParams[i].parsModel);
22346                 }
22347             else
22348                 {
22349                 /* dna characters in this partition */
22350                 if (modelSettings[i].dataType == DNA || modelSettings[i].dataType == RNA)
22351                     {
22352                     /* general form of the rate matrix */
22353                     MrBayesPrint ("%s         Nucmodel  = %s\n", spacer, modelParams[i].nucModel);
22354 
22355                     /* constraints on rates of substitution */
22356                     MrBayesPrint ("%s         Nst       = %s\n", spacer, modelParams[i].nst);
22357                     if (!strcmp(modelParams[i].nst, "2"))
22358                         {
22359                         if (!strcmp(modelParams[i].tRatioPr,"Beta"))
22360                             {
22361                             MrBayesPrint ("%s                     Transition and transversion  rates, expressed\n", spacer);
22362                             MrBayesPrint ("%s                     as proportions of the rate sum, have a\n", spacer);
22363                             MrBayesPrint ("%s                     Beta(%1.2lf,%1.2lf) prior\n", spacer, modelParams[i].tRatioDir[0], modelParams[i].tRatioDir[1]);
22364                             }
22365                         else
22366                             {
22367                             MrBayesPrint ("%s                     Transition/transversion rate ratio is fixed to %1.2lf.\n", spacer, modelParams[i].tRatioFix);
22368                             }
22369                         }
22370                     else if (!strcmp(modelParams[i].nst, "6"))
22371                         {
22372                         if (!strcmp(modelParams[i].revMatPr,"Dirichlet"))
22373                             {
22374                             MrBayesPrint ("%s                     Substitution rates, expressed as proportions\n", spacer);
22375                             MrBayesPrint ("%s                     of the rate sum, have a Dirichlet prior\n", spacer);
22376                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
22377                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
22378                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5]);
22379                             }
22380                         else
22381                             {
22382                             MrBayesPrint ("%s                     Substitution rates are fixed to be \n", spacer);
22383                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf).\n", spacer,
22384                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
22385                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5]);
22386                             }
22387                         }
22388                     else if (!strcmp(modelParams[i].nst, "Mixed"))
22389                         {
22390                         if (!strcmp(modelParams[i].revMatPr,"Dirichlet"))
22391                             {
22392                             MrBayesPrint ("%s                     Substitution rates, expressed as proportions\n", spacer);
22393                             MrBayesPrint ("%s                     of the rate sum, have a Dirichlet prior\n", spacer);
22394                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
22395                                 modelParams[i].revMatDir[0], modelParams[i].revMatDir[1], modelParams[i].revMatDir[2],
22396                                 modelParams[i].revMatDir[3], modelParams[i].revMatDir[4], modelParams[i].revMatDir[5]);
22397                             }
22398                         else
22399                             {
22400                             MrBayesPrint ("%s                     Substitution rates are fixed to be \n", spacer);
22401                             MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf).\n", spacer,
22402                                 modelParams[i].revMatFix[0], modelParams[i].revMatFix[1], modelParams[i].revMatFix[2],
22403                                 modelParams[i].revMatFix[3], modelParams[i].revMatFix[4], modelParams[i].revMatFix[5]);
22404                             }
22405                         }
22406 
22407                     if (!strcmp(modelParams[i].nucModel,"Codon"))
22408                         {
22409                         /* what is the distribution on the nonsyn./syn. rate ratio */
22410                         if (!strcmp(modelParams[i].omegaVar, "Equal"))
22411                             {
22412                             if (!strcmp(modelParams[i].omegaPr,"Dirichlet"))
22413                                 {
22414                                 MrBayesPrint ("%s                     Nonsynonymous and synonymous rates, expressed\n", spacer);
22415                                 MrBayesPrint ("%s                     as proportions of the rate sum, have a\n", spacer);
22416                                 MrBayesPrint ("%s                     Dirichlet(%1.2lf,%1.2lf) prior\n", spacer, modelParams[i].omegaDir[0], modelParams[i].omegaDir[1]);
22417                                 }
22418                             else
22419                                 {
22420                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio is fixed to %1.2lf.\n", spacer, modelParams[i].omegaFix);
22421                                 }
22422                             }
22423                         else if (!strcmp(modelParams[i].omegaVar, "Ny98"))
22424                             {
22425                             if (!strcmp(modelParams[i].ny98omega1pr, "Beta"))
22426                                 {
22427                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for purifying selection\n", spacer);
22428                                 MrBayesPrint ("%s                     (class 1) has a Beta(%1.2lf,%1.2lf) on the interval (0,1).\n", spacer, modelParams[i].ny98omega1Beta[0], modelParams[i].ny98omega1Beta[1]);
22429                                 }
22430                             else
22431                                 {
22432                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for purifying selection\n", spacer);
22433                                 MrBayesPrint ("%s                     (class 1) is fixed to %1.2lf.\n", spacer, modelParams[i].ny98omega1Fixed);
22434                                 }
22435                             MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for neutral selection\n", spacer);
22436                             MrBayesPrint ("%s                     (class 2) is fixed to 1.0.\n", spacer);
22437                             if (!strcmp(modelParams[i].ny98omega3pr, "Uniform"))
22438                                 {
22439                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for positive selection\n", spacer);
22440                                 MrBayesPrint ("%s                     is uniformly distributed on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].ny98omega3Uni[0], modelParams[i].ny98omega3Uni[1]);
22441                                 }
22442                             else if (!strcmp(modelParams[i].ny98omega3pr, "Exponential"))
22443                                 {
22444                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for positive selection\n", spacer);
22445                                 MrBayesPrint ("%s                     is exponentially distributed with parameter (%1.2lf).\n", spacer, modelParams[i].ny98omega3Exp);
22446                                 }
22447                             else
22448                                 {
22449                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for positive \n", spacer);
22450                                 MrBayesPrint ("%s                     selection is fixed to %1.2lf.\n", spacer, modelParams[i].ny98omega3Fixed);
22451                                 }
22452                             }
22453                         else if (!strcmp(modelParams[i].omegaVar, "M3"))
22454                             {
22455                             if (!strcmp(modelParams[i].m3omegapr, "Exponential"))
22456                                 {
22457                                 MrBayesPrint ("%s                     Nonsynonymous and synonymous rates for the tree classes of\n", spacer);
22458                                 MrBayesPrint ("%s                     omega are exponentially distributed random variables.\n", spacer);
22459                                 }
22460                             else if (!strcmp(modelParams[i].m3omegapr, "Fixed"))
22461                                 {
22462                                 MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for the three omega\n", spacer);
22463                                 MrBayesPrint ("%s                     are fixed to %1.2lf, %1.2lf, and %1.2lf.\n", spacer, modelParams[i].m3omegaFixed[0], modelParams[i].m3omegaFixed[1], modelParams[i].m3omegaFixed[2]);
22464                                 }
22465                             }
22466                         else if (!strcmp(modelParams[i].omegaVar, "M10"))
22467                             {
22468                             MrBayesPrint ("%s                     Nonsynonymous/synonymous rate ratio for purifying \n", spacer);
22469                             MrBayesPrint ("%s                     selection (class 1) has a Beta(alpha1,beta1) on the \n", spacer);
22470                             MrBayesPrint ("%s                     interval (0,1). Nonsynonymous/synonymous rate ratio \n", spacer);
22471                             MrBayesPrint ("%s                     for positive selection (class 2) has an offset \n", spacer);
22472                             MrBayesPrint ("%s                     Gamma(alpha2,beta2) on the interval (1,Infinity).\n", spacer);
22473                             }
22474 
22475                         /* genetic code that is used (if nucmodel=codon) */
22476                         MrBayesPrint ("%s         Code      = %s\n", spacer, modelParams[i].geneticCode);
22477                         }
22478                     }
22479                 /* amino acid characters in this partition */
22480                 else if (modelSettings[i].dataType == PROTEIN)
22481                     {
22482                     if (modelParams[i].dataType == DNA || modelParams[i].dataType == RNA)
22483                         MrBayesPrint ("%s         Nucmodel  = %s\n", spacer, modelParams[i].nucModel);
22484                     /* constraints on rates of substitution in 20 X 20 matrix */
22485                     if (!strcmp(modelParams[i].aaModelPr, "Mixed"))
22486                         MrBayesPrint ("%s         Aamodel   = Mixture of models with fixed rate matrices\n", spacer);
22487                     else
22488                         MrBayesPrint ("%s         Aamodel   = %s\n", spacer, modelParams[i].aaModel);
22489                     /* revmat rates */
22490                     if (!strcmp(modelParams[i].aaModelPr, "Mixed"))
22491                         MrBayesPrint ("%s                     Substitution rates come from the mixture of models\n", spacer);
22492                     else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && (!strcmp(modelParams[i].aaModel, "Poisson") ||
22493                                 !strcmp(modelParams[i].aaModel, "Equalin")))
22494                         MrBayesPrint ("%s                     Substitution rates are fixed to be equal\n", spacer);
22495                     else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && strcmp(modelParams[i].aaModel, "Gtr")!=0)
22496                         MrBayesPrint ("%s                     Substitution rates are fixed to the %s rates\n", spacer, modelParams[i].aaModel);
22497                     else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && !strcmp(modelParams[i].aaModel, "Gtr"))
22498                         {
22499                         if (!strcmp(modelParams[i].aaRevMatPr,"Dirichlet"))
22500                             {
22501                             for (j=0; j<190; j++)
22502                                 if (AreDoublesEqual(modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[j], 0.00001) == NO)
22503                                     break;
22504                             if (j == 190)
22505                                 {
22506                                 MrBayesPrint ("%s                     Substitution rates have a Dirichlet(%1.2lf,%1.2lf,...) prior\n",
22507                                     spacer, modelParams[i].aaRevMatDir[0], modelParams[i].aaRevMatDir[0]);
22508                                 }
22509                             else
22510                                 {
22511                                 MrBayesPrint ("%s                     Substitution rates have a Dirichlet(\n", spacer);
22512                                 for (j=0; j<190; j++)
22513                                     {
22514                                     if (j % 10 == 0)
22515                                         MrBayesPrint ("%s                        ", spacer);
22516                                     MrBayesPrint ("%1.2lf", modelParams[i].aaRevMatDir[j]);
22517                                     if (j == 189)
22518                                         MrBayesPrint (") prior\n");
22519                                     else if ((j+1) % 10 == 0)
22520                                         MrBayesPrint (",\n");
22521                                     else
22522                                         MrBayesPrint (",");
22523                                     }
22524                                 }
22525                             }
22526                         else /* if (!strcmp(modelParams[i].aaRevMatPr,"Fixed")) */
22527                             {
22528                             for (j=0; j<190; j++)
22529                                 if (AreDoublesEqual(modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[j], 0.00001) == NO)
22530                                     break;
22531                             if (j == 190)
22532                                 {
22533                                 MrBayesPrint ("%s                     Substitution rates are fixed to (%1.1lf,%1.1lf,...)\n",
22534                                     spacer, modelParams[i].aaRevMatFix[0], modelParams[i].aaRevMatFix[0]);
22535                                 }
22536                             else
22537                                 {
22538                                 MrBayesPrint ("%s                     Substitution rates are fixed to (\n", spacer);
22539                                 for (j=0; j<190; j++)
22540                                     {
22541                                     if (j % 10 == 0)
22542                                         MrBayesPrint ("%s                        ", spacer);
22543                                     MrBayesPrint ("%1.1lf", modelParams[i].aaRevMatFix[j]);
22544                                     if (j == 189)
22545                                         MrBayesPrint (") prior\n");
22546                                     else if ((j+1) % 10 == 0)
22547                                         MrBayesPrint (",\n");
22548                                     else
22549                                         MrBayesPrint (",");
22550                                     }
22551                                 }
22552                             }
22553                         }
22554                     }
22555                 /* restriction site or morphological characters in this partition */
22556                 else if (modelSettings[i].dataType == RESTRICTION || modelSettings[i].dataType == STANDARD)
22557                     {
22558                     /* what type of characters are sampled? */
22559                     MrBayesPrint ("%s         Coding    = %s\n", spacer, modelParams[i].codingString);
22560                     }
22561 
22562                 /* is there rate variation in a single site across the tree? */
22563                 if (((modelSettings[i].dataType == DNA || modelSettings[i].dataType == RNA) && !strcmp(modelParams[i].nucModel, "4by4")) || modelSettings[i].dataType == PROTEIN)
22564                     {
22565                     /* do rates change on tree accoding to covarion model? */
22566                     MrBayesPrint ("%s         Covarion  = %s\n", spacer, modelParams[i].covarionModel);
22567                     if (!strcmp(modelParams[i].covarionModel, "Yes"))
22568                         {
22569                         /* distribution on switching parameters, if appropriate */
22570                         if (!strcmp(modelParams[i].covSwitchPr,"Uniform"))
22571                             {
22572                             MrBayesPrint ("%s                     Switching rates have independent uniform dist-\n", spacer);
22573                             MrBayesPrint ("%s                     ributions on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].covswitchUni[0], modelParams[i].covswitchUni[1]);
22574                             }
22575                         else if (!strcmp(modelParams[i].covSwitchPr,"Exponential"))
22576                             {
22577                             MrBayesPrint ("%s                     Switching rates have independent exponential\n", spacer);
22578                             MrBayesPrint ("%s                     distributions with parameters (%1.2lf).\n", spacer, modelParams[i].covswitchExp);
22579                             }
22580                         else
22581                             {
22582                             MrBayesPrint ("%s                     Switching rates are fixed to %1.2lf and %1.2lf.\n", spacer, modelParams[i].covswitchFix[0], modelParams[i].covswitchFix[0]);
22583                             }
22584                         ns *= 2;
22585                         }
22586                     }
22587 
22588                 /* now, let's deal with variation in omega */
22589                 if ((modelParams[i].dataType == DNA || modelParams[i].dataType == RNA) && !strcmp(modelParams[i].nucModel,"Codon"))
22590                     {
22591                     MrBayesPrint ("%s         Omegavar  = %s\n", spacer, modelParams[i].omegaVar);
22592                     if (!strcmp(modelParams[i].geneticCode, "Universal"))
22593                         ns = 61;
22594                     else if (!strcmp(modelParams[i].geneticCode, "Vertmt"))
22595                         ns = 60;
22596                     else if (!strcmp(modelParams[i].geneticCode, "Invermt"))
22597                         ns = 62;
22598                     else if (!strcmp(modelParams[i].geneticCode, "Mycoplasma"))
22599                         ns = 62;
22600                     else if (!strcmp(modelParams[i].geneticCode, "Yeast"))
22601                         ns = 62;
22602                     else if (!strcmp(modelParams[i].geneticCode, "Ciliate"))
22603                         ns = 63;
22604                     else if (!strcmp(modelParams[i].geneticCode, "Echinoderm"))
22605                         ns = 62;
22606                     else if (!strcmp(modelParams[i].geneticCode, "Euplotid"))
22607                         ns = 62;
22608                     else if (!strcmp(modelParams[i].geneticCode, "Metmt"))
22609                         ns = 62;
22610                     }
22611 
22612                 /* what assumptions are made about the state frequencies? */
22613                 if (modelParams[i].dataType != CONTINUOUS)
22614                     {
22615                     if (modelParams[i].dataType == STANDARD)
22616                         MrBayesPrint ("%s         # States  = Variable, up to 10\n", spacer);
22617                     else if (modelSettings[i].numStates != modelSettings[i].numModelStates)
22618                         MrBayesPrint ("%s         # States  = %d (in the model)\n", spacer, modelSettings[i].numModelStates);
22619                     else
22620                         MrBayesPrint ("%s         # States  = %d\n", spacer, ns);
22621                     if (modelSettings[i].dataType == STANDARD)
22622                         {
22623                         if (!strcmp(modelParams[i].symPiPr,"Fixed"))
22624                             {
22625                             if (AreDoublesEqual(modelParams[i].symBetaFix, -1.0, ETA)==YES)
22626                                 MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22627                             else
22628                                 MrBayesPrint ("%s                     Symmetric Dirichlet alpha is fixed to %1.2lf\n", spacer, modelParams[i].symBetaFix);
22629                             }
22630                         else if (!strcmp(modelParams[i].symPiPr,"Uniform"))
22631                             {
22632                             MrBayesPrint ("%s                     Symmetric Dirichlet alpha has a Uniform(%1.2lf,%1.2lf) prior\n", spacer, modelParams[i].symBetaUni[0], modelParams[i].symBetaUni[1]);
22633                             }
22634                         else
22635                             {
22636                             MrBayesPrint ("%s                     Symmetric Dirichlet alpha has a Exponential(%1.2lf) prior\n", spacer, modelParams[i].symBetaExp);
22637                             }
22638                         }
22639                     else if (modelSettings[i].dataType == RESTRICTION)
22640                         {
22641                         /* distribution on state frequencies for restriction site model */
22642                         if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
22643                             {
22644                             MrBayesPrint ("%s                     State frequencies have a Dirichlet (%1.2lf,%1.2lf) prior\n", spacer,
22645                                 modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1]);
22646                             }
22647                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Equal"))
22648                             {
22649                             MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22650                             }
22651                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"User"))
22652                             {
22653                             MrBayesPrint ("%s                     State frequencies have been fixed by the user\n", spacer);
22654                             }
22655                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Empirical"))
22656                             {
22657                             MrBayesPrint ("%s                     State frequencies have been fixed to the empirical frequencies in the data\n", spacer);
22658                             }
22659                         }
22660                     else if (modelSettings[i].dataType == PROTEIN)
22661                         {
22662                         /* distribution on state frequencies for aminoacid model */
22663                         if (!strcmp(modelParams[i].aaModelPr, "Fixed") && (strcmp(modelParams[i].aaModel, "Equalin")==0 ||
22664                             strcmp(modelParams[i].aaModel, "Gtr")==0))
22665                             {
22666                             if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
22667                                 {
22668                                 MrBayesPrint ("%s                     State frequencies have a Dirichlet prior\n", spacer);
22669                                 MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,", spacer,
22670                                     modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1], modelParams[i].stateFreqsDir[2],
22671                                     modelParams[i].stateFreqsDir[3], modelParams[i].stateFreqsDir[4]);
22672                                 MrBayesPrint ("%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,\n",
22673                                     modelParams[i].stateFreqsDir[5], modelParams[i].stateFreqsDir[6], modelParams[i].stateFreqsDir[7],
22674                                     modelParams[i].stateFreqsDir[8], modelParams[i].stateFreqsDir[9]);
22675                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,", spacer,
22676                                     modelParams[i].stateFreqsDir[10], modelParams[i].stateFreqsDir[11], modelParams[i].stateFreqsDir[12],
22677                                     modelParams[i].stateFreqsDir[13], modelParams[i].stateFreqsDir[14]);
22678                                 MrBayesPrint ("%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n",
22679                                     modelParams[i].stateFreqsDir[15], modelParams[i].stateFreqsDir[16], modelParams[i].stateFreqsDir[17],
22680                                     modelParams[i].stateFreqsDir[18], modelParams[i].stateFreqsDir[19]);
22681                                 }
22682                             else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Equal"))
22683                                 {
22684                                 MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22685                                 }
22686                             else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"User"))
22687                                 {
22688                                 MrBayesPrint ("%s                     State frequencies have been fixed by the user\n", spacer);
22689                                 }
22690                             else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Empirical"))
22691                                 {
22692                                 MrBayesPrint ("%s                     State frequencies have been fixed to the empirical frequencies in the data\n", spacer);
22693                                 }
22694                             }
22695                         else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && !strcmp(modelParams[i].aaModel, "Poisson"))
22696                             {
22697                             MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22698                             }
22699                         else if (!strcmp(modelParams[i].aaModelPr, "Fixed") && strcmp(modelParams[i].aaModel, "Equalin") && strcmp(modelParams[i].aaModel, "Poisson"))
22700                             {
22701                             MrBayesPrint ("%s                     State frequencies are fixed to the %s frequencies\n", spacer, modelParams[i].aaModel);
22702                             }
22703                         else
22704                             {
22705                             MrBayesPrint ("%s                     State frequencies come from the mixture of models\n", spacer);
22706                             }
22707                         }
22708                     else
22709                         {
22710                         /* distribution on state frequencies for all other models */
22711                         if (!strcmp(modelParams[i].stateFreqPr,"Dirichlet"))
22712                             {
22713                             MrBayesPrint ("%s                     State frequencies have a Dirichlet prior\n", spacer);
22714                             if (!strcmp(modelParams[i].nucModel, "Doublet"))
22715                                 {
22716                                 MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf,\n", spacer,
22717                                     modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1], modelParams[i].stateFreqsDir[2],
22718                                     modelParams[i].stateFreqsDir[3]);
22719                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf,\n", spacer,
22720                                     modelParams[i].stateFreqsDir[4], modelParams[i].stateFreqsDir[5], modelParams[i].stateFreqsDir[6],
22721                                     modelParams[i].stateFreqsDir[7]);
22722                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf,\n", spacer,
22723                                     modelParams[i].stateFreqsDir[8], modelParams[i].stateFreqsDir[9], modelParams[i].stateFreqsDir[10],
22724                                     modelParams[i].stateFreqsDir[11]);
22725                                 MrBayesPrint ("%s                     %1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
22726                                     modelParams[i].stateFreqsDir[12], modelParams[i].stateFreqsDir[13], modelParams[i].stateFreqsDir[14],
22727                                     modelParams[i].stateFreqsDir[15]);
22728                                 }
22729                             else if (!strcmp(modelParams[i].nucModel, "4by4"))
22730                                 {
22731                                 MrBayesPrint ("%s                     (%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
22732                                     modelParams[i].stateFreqsDir[0], modelParams[i].stateFreqsDir[1], modelParams[i].stateFreqsDir[2],
22733                                     modelParams[i].stateFreqsDir[3]);
22734                                 }
22735                             }
22736                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Equal"))
22737                             {
22738                             MrBayesPrint ("%s                     State frequencies are fixed to be equal\n", spacer);
22739                             }
22740                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"User"))
22741                             {
22742                             MrBayesPrint ("%s                     State frequencies have been fixed by the user\n", spacer);
22743                             }
22744                         else if (!strcmp(modelParams[i].stateFreqPr,"Fixed") && !strcmp(modelParams[i].stateFreqsFixType,"Empirical"))
22745                             {
22746                             MrBayesPrint ("%s                     State frequencies have been fixed to the empirical frequencies in the data\n", spacer);
22747                             }
22748                         }
22749                     }
22750                 else
22751                     MrBayesPrint ("%s         # States  = Infinity\n", spacer);
22752 
22753                 /* now, let's deal with rate variation across sites */
22754                 if (modelSettings[i].dataType != CONTINUOUS)
22755                     {
22756                     if (((modelSettings[i].dataType == DNA || modelSettings[i].dataType == RNA) && strcmp(modelParams[i].nucModel,"Codon")!=0) ||
22757                           modelSettings[i].dataType == PROTEIN || modelSettings[i].dataType == RESTRICTION || modelSettings[i].dataType == STANDARD)
22758                         {
22759                         if (!strcmp(modelParams[i].covarionModel, "No"))
22760                             MrBayesPrint ("%s         Rates     = %s\n", spacer, modelParams[i].ratesModel);
22761                         else
22762                             {
22763                             if (!strcmp(modelParams[i].ratesModel, "Propinv"))
22764                                 MrBayesPrint ("%s         Rates     = Equal ", spacer);
22765                             else if (!strcmp(modelParams[i].ratesModel, "Invgamma"))
22766                                 MrBayesPrint ("%s         Rates     = Gamma ", spacer);
22767                             else
22768                                 MrBayesPrint ("%s         Rates     = %s ", spacer, modelParams[i].ratesModel);
22769                             MrBayesPrint ("(+ Propinv induced by covarion model)\n");
22770                             }
22771 
22772                         if ((modelParams[i].dataType == RESTRICTION || modelParams[i].dataType == STANDARD) && !strcmp(modelParams[i].ratesModel, "Adgamma"))
22773                             {
22774 
22775                             }
22776                         else
22777                             {
22778                             if (!strcmp(modelParams[i].ratesModel, "Gamma") || !strcmp(modelParams[i].ratesModel, "Invgamma") ||
22779                                 !strcmp(modelParams[i].ratesModel, "LNorm") || !strcmp(modelParams[i].ratesModel, "Adgamma") ||
22780                                 !strcmp(modelParams[i].ratesModel, "Kmixture"))
22781                                 {
22782                                 /* how many categories is the continuous gamma/lnorm approximated by? or how many components are there in the mixture? */
22783                                 if (!strcmp(modelParams[i].ratesModel, "Kmixture"))
22784                                     MrBayesPrint ("%s                     There are %d components in the mixture.\n", spacer, modelParams[i].numMixtCats);
22785                                 else if (!strcmp(modelParams[i].ratesModel, "Lnorm"))
22786                                     MrBayesPrint ("%s                     The distribution is approximated using %d categories.\n", spacer, modelParams[i].numLnormCats);
22787                                 else
22788                                     MrBayesPrint ("%s                     The distribution is approximated using %d categories.\n", spacer, modelParams[i].numGammaCats);
22789                                 /* distribution on shape parameter, if appropriate */
22790                                 if (!strcmp(modelParams[i].shapePr,"Uniform"))
22791                                     {
22792                                     MrBayesPrint ("%s                     Shape parameter is uniformly distributed\n", spacer);
22793                                     MrBayesPrint ("%s                     on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].shapeUni[0], modelParams[i].shapeUni[1]);
22794                                     }
22795                                 else if (!strcmp(modelParams[i].shapePr,"Exponential"))
22796                                     {
22797                                     MrBayesPrint ("%s                     Shape parameter is exponentially\n", spacer);
22798                                     MrBayesPrint ("%s                     distributed with parameter (%1.2lf).\n", spacer, modelParams[i].shapeExp);
22799                                     }
22800                                 else
22801                                     {
22802                                     MrBayesPrint ("%s                     Shape parameter is fixed to %1.2lf.\n", spacer, modelParams[i].shapeFix);
22803                                     }
22804                                 }
22805 
22806                             if ((!strcmp(modelParams[i].ratesModel, "Propinv") || !strcmp(modelParams[i].ratesModel, "Invgamma")) && !strcmp(modelParams[i].covarionModel, "No"))
22807                                 {
22808                                 /* distribution on pInvar parameter, if appropriate */
22809                                 if (!strcmp(modelParams[i].pInvarPr,"Uniform"))
22810                                     {
22811                                     MrBayesPrint ("%s                     Proportion of invariable sites is uniformly dist-\n", spacer);
22812                                     MrBayesPrint ("%s                     ributed on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].pInvarUni[0], modelParams[i].pInvarUni[1]);
22813                                     }
22814                                 else
22815                                     {
22816                                     MrBayesPrint ("%s                     Proportion of invariable sites is fixed to %1.2lf.\n", spacer, modelParams[i].pInvarFix);
22817                                     }
22818                                 }
22819                             if (!strcmp(modelParams[i].ratesModel, "Adgamma"))
22820                                 {
22821                                 /* distribution on correlation parameter, if appropriate */
22822                                 if (!strcmp(modelParams[i].adGammaCorPr,"Uniform"))
22823                                     {
22824                                     MrBayesPrint ("%s                     Rate correlation parameter is uniformly dist-\n", spacer);
22825                                     MrBayesPrint ("%s                     ributed on the interval (%1.2lf,%1.2lf).\n", spacer, modelParams[i].corrUni[0], modelParams[i].corrUni[1]);
22826                                     }
22827                                 else
22828                                     {
22829                                     MrBayesPrint ("%s                     Rate correlation parameter is fixed to %1.2lf.\n", spacer, modelParams[i].corrFix);
22830                                     }
22831                                 }
22832                             }
22833                         }
22834                     }
22835                 }
22836             /* end description of discrete models */
22837             }
22838 
22839         if (i != numCurrentDivisions - 1)
22840             MrBayesPrint ("\n");
22841 
22842         }
22843 
22844     MrBayesPrint ("\n");
22845     ShowParameters (NO, NO, NO);
22846 
22847     return (NO_ERROR);
22848 }
22849 
22850 
22851 /*------------------------------------------------------------------------------
22852 |
22853 |   ShowMoves: Show applicable moves
22854 |
22855 ------------------------------------------------------------------------------*/
ShowMoves(int used)22856 int ShowMoves (int used)
22857 {
22858     int             i, k, run, chain, chainIndex, areRunsSame, areChainsSame, numPrintedMoves;
22859     MCMCMove        *mv;
22860 
22861     numPrintedMoves = 0;
22862     for (i=0; i<numApplicableMoves; i++)
22863         {
22864         mv = moves[i];
22865 
22866         for (k=0; k<numGlobalChains; k++)
22867             {
22868             if (mv->relProposalProb[k] > 0.000001)
22869                 break;
22870             }
22871 
22872         if (k == numGlobalChains && used == YES)
22873             continue;
22874 
22875         if (k < numGlobalChains && used == NO)
22876             continue;
22877 
22878         numPrintedMoves++;
22879 
22880         /* print move number and name */
22881         MrBayesPrint ("%s   %4d -- Move        = %s\n", spacer, numPrintedMoves, mv->name);
22882 
22883         /* print move type */
22884         MrBayesPrint ("%s           Type        = %s\n", spacer, mv->moveType->name);
22885 
22886         /* print parameter */
22887         if (mv->parm->nSubParams > 0)
22888             MrBayesPrint ("%s           Parameters  = %s [param. %d] (%s)\n", spacer, mv->parm->name,
22889                 mv->parm->index+1, mv->parm->paramTypeName);
22890         else
22891             MrBayesPrint ("%s           Parameter   = %s [param. %d] (%s)\n", spacer, mv->parm->name,
22892                 mv->parm->index+1, mv->parm->paramTypeName);
22893         for (k=0; k<mv->parm->nSubParams; k++)
22894             MrBayesPrint ("%s                         %s [param. %d] (%s)\n", spacer, mv->parm->subParams[k]->name,
22895                 mv->parm->subParams[k]->index+1, mv->parm->subParams[k]->paramTypeName);
22896 
22897         /* print tuning parameters */
22898         for (k=0; k<mv->moveType->numTuningParams; k++)
22899             {
22900             if (k==0)
22901                 MrBayesPrint ("%s           Tuningparam = %s (%s)\n", spacer, mv->moveType->shortTuningName[k], mv->moveType->tuningName[k]);
22902             else
22903                 MrBayesPrint ("%s                         %s (%s)\n", spacer, mv->moveType->shortTuningName[k], mv->moveType->tuningName[k]);
22904             }
22905 
22906         /* loop over tuning parameters */
22907         for (k=0; k<mv->moveType->numTuningParams; k++)
22908             {
22909             /* find if tuning parameters are different for different runs */
22910             areRunsSame = YES;
22911             for (run=1; run<chainParams.numRuns; run++)
22912                 {
22913                 for (chain=0; chain<chainParams.numChains; chain++)
22914                     {
22915                     chainIndex = run*chainParams.numChains + chain;
22916                     if (AreDoublesEqual (mv->tuningParam[chainIndex][k], mv->tuningParam[chain][k], 0.000001) == NO)
22917                         {
22918                         areRunsSame = NO;
22919                         break;
22920                         }
22921                     }
22922                 if (areRunsSame == NO)
22923                     break;
22924                 }
22925 
22926             /* now print values */
22927             for (run=0; run<chainParams.numRuns; run++)
22928                 {
22929                 if (areRunsSame == YES && run >= 1)
22930                     break;
22931 
22932                 /* find out if chains are different within this run */
22933                 areChainsSame = YES;
22934                 for (chain=1; chain<chainParams.numChains; chain++)
22935                     {
22936                     chainIndex = run*chainParams.numChains + chain;
22937                     if (AreDoublesEqual (mv->tuningParam[chainIndex][k], mv->tuningParam[chainIndex-chain][k],0.000001) == NO)
22938                         {
22939                         areChainsSame = NO;
22940                         break;
22941                         }
22942                     }
22943                 /* now we can print the values */
22944                 for (chain=0; chain<chainParams.numChains; chain++)
22945                     {
22946                     chainIndex = run*chainParams.numChains + chain;
22947                     if (areChainsSame == YES && chain >= 1)
22948                         break;
22949 
22950                     if (run == 0 && chain == 0)
22951                         MrBayesPrint ("%s%22s = %1.3lf", spacer, mv->moveType->shortTuningName[k], mv->tuningParam[chainIndex][k]);
22952                     else
22953                         MrBayesPrint ("%s                         %1.3lf", spacer, mv->tuningParam[chainIndex][k]);
22954 
22955                     if (areChainsSame == NO && areRunsSame == YES)
22956                         MrBayesPrint ("  [chain %d]\n", chain+1);
22957                     else if (areChainsSame == YES && areRunsSame == NO)
22958                         MrBayesPrint ("  [run %d]\n", run+1);
22959                     else if (areChainsSame == NO && areRunsSame == NO)
22960                         MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
22961                     else
22962                         MrBayesPrint ("\n");
22963                     }
22964                 }
22965             }   /* next tuning parameter */
22966 
22967         /* print target acceptance rate for autotuning */
22968         if (mv->moveType->targetRate > 0.0 && mv->moveType->targetRate < 1.0)
22969             {
22970 
22971             /* first find out if the targets are different in different runs */
22972             areRunsSame = YES;
22973             for (run=1; run<chainParams.numRuns; run++)
22974                 {
22975                 for (chain=0; chain<chainParams.numChains; chain++)
22976                     {
22977                     chainIndex = run*chainParams.numChains + chain;
22978                     if (AreDoublesEqual (mv->targetRate[chainIndex], mv->targetRate[chain], 0.000001) == NO)
22979                         {
22980                         areRunsSame = NO;
22981                         break;
22982                         }
22983                     }
22984                 if (areRunsSame == NO)
22985                     break;
22986                 }
22987 
22988             /* now print values */
22989             for (run=0; run<chainParams.numRuns; run++)
22990                 {
22991                 if (areRunsSame == YES && run >= 1)
22992                     break;
22993 
22994                 /* find out if chains are different within this run */
22995                 areChainsSame = YES;
22996                 for (chain=1; chain<chainParams.numChains; chain++)
22997                     {
22998                     chainIndex = run*chainParams.numChains + chain;
22999                     if (AreDoublesEqual (mv->targetRate[chainIndex], mv->targetRate[chainIndex-chain], 0.000001) == NO)
23000                         {
23001                         areChainsSame = NO;
23002                         break;
23003                         }
23004                     }
23005                 /* now we can print the values */
23006                 for (chain=0; chain<chainParams.numChains; chain++)
23007                     {
23008                     chainIndex = run*chainParams.numChains + chain;
23009                     if (areChainsSame == YES && chain >= 1)
23010                         break;
23011 
23012                     if (run == 0 && chain == 0)
23013                         MrBayesPrint ("%s           Targetrate  = %1.3lf", spacer, mv->targetRate[chainIndex]);
23014                     else
23015                         MrBayesPrint ("%s                         %1.3lf", spacer, mv->targetRate[chainIndex]);
23016 
23017                     if (areChainsSame == NO && areRunsSame == YES)
23018                         MrBayesPrint ("  [chain %d]\n", chain+1);
23019                     else if (areChainsSame == YES && areRunsSame == NO)
23020                         MrBayesPrint ("  [run %d]\n", run+1);
23021                     else if (areChainsSame == NO && areRunsSame == NO)
23022                         MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
23023                     else
23024                         MrBayesPrint ("\n");
23025                     }
23026                 }
23027             }
23028 
23029 
23030         /* finally print the relative proposal probability */
23031 
23032         /* first find out if the probabilities are different in different runs */
23033         areRunsSame = YES;
23034         for (run=1; run<chainParams.numRuns; run++)
23035             {
23036             for (chain=0; chain<chainParams.numChains; chain++)
23037                 {
23038                 chainIndex = run*chainParams.numChains + chain;
23039                 if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[chain], 0.000001) == NO)
23040                     {
23041                     areRunsSame = NO;
23042                     break;
23043                     }
23044                 }
23045             if (areRunsSame == NO)
23046                 break;
23047             }
23048 
23049         /* now print values */
23050         for (run=0; run<chainParams.numRuns; run++)
23051             {
23052             if (areRunsSame == YES && run >= 1)
23053                 break;
23054 
23055             /* find out if chains are different within this run */
23056             areChainsSame = YES;
23057             for (chain=1; chain<chainParams.numChains; chain++)
23058                 {
23059                 chainIndex = run*chainParams.numChains + chain;
23060                 if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[chainIndex-chain], 0.000001) == NO)
23061                     {
23062                     areChainsSame = NO;
23063                     break;
23064                     }
23065                 }
23066             /* now we can print the values */
23067             for (chain=0; chain<chainParams.numChains; chain++)
23068                 {
23069                 chainIndex = run*chainParams.numChains + chain;
23070                 if (areChainsSame == YES && chain >= 1)
23071                     break;
23072 
23073                 if (run == 0 && chain == 0)
23074                     MrBayesPrint ("%s           Rel. prob.  = %1.1lf", spacer, mv->relProposalProb[chainIndex]);
23075                 else
23076                     MrBayesPrint ("%s                         %1.1lf", spacer, mv->relProposalProb[chainIndex]);
23077 
23078                 if (areChainsSame == NO && areRunsSame == YES)
23079                     MrBayesPrint ("  [chain %d]\n", chain+1);
23080                 else if (areChainsSame == YES && areRunsSame == NO)
23081                     MrBayesPrint ("  [run %d]\n", run+1);
23082                 else if (areChainsSame == NO && areRunsSame == NO)
23083                     MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
23084                 else
23085                     MrBayesPrint ("\n");
23086                 }
23087             }
23088         MrBayesPrint ("\n");
23089         }   /* next move */
23090 
23091     if (numPrintedMoves == 0)
23092         {
23093         if (used == YES)
23094             {
23095             MrBayesPrint ("%s      No moves currently used for this analysis. All parameters\n", spacer);
23096             MrBayesPrint ("%s      will be fixed to their starting values.\n\n", spacer);
23097             }
23098         else
23099             {
23100             MrBayesPrint ("%s      No additional moves available for this model.\n\n", spacer);
23101             }
23102         }
23103 
23104     return (NO_ERROR);
23105 }
23106 
23107 
23108 /*------------------------------------------------------------------------------
23109 |
23110 |   ShowParameters: Show parameter table and parameter info
23111 |
23112 ------------------------------------------------------------------------------*/
ShowParameters(int showStartVals,int showMoves,int showAllAvailable)23113 int ShowParameters (int showStartVals, int showMoves, int showAllAvailable)
23114 {
23115     int             a, b, d, i, j, k, m, n, run, chain, shouldPrint, isSame, areRunsSame, areChainsSame, nValues,
23116                     chainIndex, refIndex, numPrinted, numMovedChains, printedCol, screenWidth=100;
23117     Param           *p;
23118     Model           *mp;
23119     ModelInfo       *ms;
23120     MrBFlt          *value, *refValue, *subValue;
23121     MCMCMove        *mv;
23122 
23123     MrBayesPrint ("%s   Active parameters: \n\n", spacer);
23124     if (numCurrentDivisions > 1)
23125         {
23126         MrBayesPrint ("%s                          Partition(s)\n", spacer);
23127         MrBayesPrint ("%s      Parameters        ", spacer);
23128         for (i=0; i<numCurrentDivisions; i++)
23129             MrBayesPrint (" %2d", i+1);
23130         MrBayesPrint ("\n");
23131         MrBayesPrint ("%s      ------------------", spacer);
23132         for (i=0; i<numCurrentDivisions; i++)
23133             MrBayesPrint ("---");
23134         MrBayesPrint ("\n");
23135         }
23136     else
23137         {
23138         MrBayesPrint ("%s      Parameters\n", spacer);
23139         MrBayesPrint ("%s      ---------------------\n", spacer);
23140         }
23141     for (j=0; j<NUM_LINKED; j++)
23142         {
23143         shouldPrint = NO;
23144         for (i=0; i<numCurrentDivisions; i++)
23145             {
23146             if (activeParams[j][i] == -1)
23147                 {}
23148             else
23149                 shouldPrint = YES;
23150             }
23151         if (shouldPrint == NO)
23152             continue;
23153 
23154         if (j == P_TRATIO)
23155             {
23156             MrBayesPrint ("%s      Tratio            ", spacer);
23157             }
23158         else if (j == P_REVMAT)
23159             {
23160             MrBayesPrint ("%s      Revmat            ", spacer);
23161             }
23162         else if (j == P_OMEGA)
23163             {
23164             MrBayesPrint ("%s      Omega             ", spacer);
23165             }
23166         else if (j == P_PI)
23167             {
23168             MrBayesPrint ("%s      Statefreq         ", spacer);
23169             }
23170         else if (j == P_MIXTURE_RATES)
23171         {
23172             MrBayesPrint ("%s      Mixturerates      ", spacer);
23173         }
23174         else if (j == P_SHAPE)
23175             {
23176             MrBayesPrint ("%s      Shape             ", spacer);
23177             }
23178         else if (j == P_PINVAR)
23179             {
23180             MrBayesPrint ("%s      Pinvar            ", spacer);
23181             }
23182         else if (j == P_CORREL)
23183             {
23184             MrBayesPrint ("%s      Correlation       ", spacer);
23185             }
23186         else if (j == P_SWITCH)
23187             {
23188             MrBayesPrint ("%s      Switchrates       ", spacer);
23189             }
23190         else if (j == P_RATEMULT)
23191             {
23192             MrBayesPrint ("%s      Ratemultiplier    ", spacer);
23193             }
23194         else if (j == P_GENETREERATE)
23195             {
23196             MrBayesPrint ("%s      Generatemult      ", spacer);
23197             }
23198         else if (j == P_TOPOLOGY)
23199             {
23200             MrBayesPrint ("%s      Topology          ", spacer);
23201             }
23202         else if (j == P_BRLENS)
23203             {
23204             MrBayesPrint ("%s      Brlens            ", spacer);
23205             }
23206         else if (j == P_SPECRATE)
23207             {
23208             MrBayesPrint ("%s      Speciationrate    ", spacer);
23209             }
23210         else if (j == P_EXTRATE)
23211             {
23212             MrBayesPrint ("%s      Extinctionrate    ", spacer);
23213             }
23214         else if (j == P_FOSLRATE)
23215             {
23216             MrBayesPrint ("%s      Fossilizationrate ", spacer);
23217             }
23218         else if (j == P_POPSIZE)
23219             {
23220             MrBayesPrint ("%s      Popsize           ", spacer);
23221             }
23222         else if (j == P_GROWTH)
23223             {
23224             MrBayesPrint ("%s      Growthrate        ", spacer);
23225             }
23226         else if (j == P_AAMODEL)
23227             {
23228             MrBayesPrint ("%s      Aamodel           ", spacer);
23229             }
23230         else if (j == P_BRCORR)
23231             {
23232             MrBayesPrint ("%s      Brownian corr.    ", spacer);
23233             }
23234         else if (j == P_BRSIGMA)
23235             {
23236             MrBayesPrint ("%s      Brownian sigma    ", spacer);
23237             }
23238         else if (j == P_CPPRATE)
23239             {
23240             MrBayesPrint ("%s      Cpprate           ", spacer);
23241             }
23242         else if (j == P_CPPMULTDEV)
23243             {
23244             MrBayesPrint ("%s      Cppmultdev        ", spacer);
23245             }
23246         else if (j == P_CPPEVENTS)
23247             {
23248             MrBayesPrint ("%s      Cppevents         ", spacer);
23249             }
23250         else if (j == P_TK02VAR)
23251             {
23252             MrBayesPrint ("%s      TK02var           ", spacer);
23253             }
23254         else if (j == P_TK02BRANCHRATES)
23255             {
23256             MrBayesPrint ("%s      TK02branchrates   ", spacer);
23257             }
23258         else if (j == P_IGRVAR)
23259             {
23260             MrBayesPrint ("%s      Igrvar            ", spacer);
23261             }
23262         else if (j == P_IGRBRANCHRATES)
23263             {
23264             MrBayesPrint ("%s      Igrbranchrates    ", spacer);
23265             }
23266         else if (j == P_MIXEDVAR)
23267             {
23268             MrBayesPrint ("%s      Mixedvar          ", spacer);
23269             }
23270         else if (j == P_MIXEDBRCHRATES)
23271             {
23272             MrBayesPrint ("%s      Mixedbranchrates  ", spacer);
23273             }
23274         else if (j == P_CLOCKRATE)
23275             {
23276             MrBayesPrint ("%s      Clockrate         ", spacer);
23277             }
23278         else if (j == P_SPECIESTREE)
23279             {
23280             MrBayesPrint ("%s      Speciestree       ", spacer);
23281             }
23282         else
23283             {
23284             MrBayesPrint ("%s      ERROR: Someone forgot to name parameter type %d", spacer, j);
23285             return (ERROR);
23286             }
23287 
23288         for (i=0; i<numCurrentDivisions; i++)
23289             {
23290             if (activeParams[j][i] == -1)
23291                 MrBayesPrint ("  .");
23292             else
23293                 MrBayesPrint (" %2d", activeParams[j][i]);
23294             }
23295         MrBayesPrint ("\n");
23296         }
23297     if (numCurrentDivisions > 1)
23298         {
23299         MrBayesPrint ("%s      ------------------", spacer);
23300         for (i=0; i<numCurrentDivisions; i++)
23301             MrBayesPrint ("---");
23302         MrBayesPrint ("\n");
23303         }
23304     else
23305         {
23306         MrBayesPrint ("%s      ---------------------\n", spacer);
23307         }
23308 
23309     MrBayesPrint ("\n");
23310 
23311     if (numCurrentDivisions > 1)
23312         MrBayesPrint ("%s      Parameters can be linked or unlinked across partitions using 'link' and 'unlink'\n\n", spacer);
23313 
23314     for (i=0; i<numParams; i++)
23315         {
23316         p = &params[i];
23317         j = p->paramType;
23318 
23319         mp = &modelParams[p->relParts[0]];
23320         ms = &modelSettings[p->relParts[0]];
23321 
23322         /* print parameter number and name */
23323         MrBayesPrint ("%s   %4d --  Parameter  = %s\n", spacer, i+1, p->name);
23324         MrBayesPrint ("%s            Type       = %s\n", spacer, p->paramTypeName);
23325         /* print prior */
23326         if (j == P_TRATIO)
23327             {
23328             if (!strcmp(mp->tRatioPr,"Beta"))
23329                 MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf)\n", spacer, mp->tRatioDir[0], modelParams[i].tRatioDir[1]);
23330             else
23331                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->tRatioFix);
23332             }
23333         else if (j == P_REVMAT)
23334             {
23335             if (ms->numModelStates != 20)
23336                 {
23337                 if (!strcmp(mp->nst,"Mixed"))
23338                     {
23339                     MrBayesPrint ("%s            Prior      = All GTR submodels have equal probability\n", spacer);
23340                     MrBayesPrint ("%s                         All revmat rates have a Symmetric Dirichlet(%1.2lf) prior\n", spacer, mp->revMatSymDir);
23341                     }
23342                 else if (!strcmp(mp->revMatPr,"Dirichlet"))
23343                     {
23344                     MrBayesPrint ("%s            Prior      = Dirichlet(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
23345                     mp->revMatDir[0], mp->revMatDir[1], mp->revMatDir[2],
23346                     mp->revMatDir[3], mp->revMatDir[4], mp->revMatDir[5]);
23347                     }
23348                 else
23349                     MrBayesPrint ("%s            Prior      = Fixed(%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf,%1.2lf)\n", spacer,
23350                     mp->revMatFix[0], mp->revMatFix[1], mp->revMatFix[2],
23351                     mp->revMatFix[3], mp->revMatFix[4], mp->revMatFix[5]);
23352                 }
23353             else if (ms->numModelStates == 20)
23354                 {
23355                 if (!strcmp(mp->aaRevMatPr,"Dirichlet"))
23356                     MrBayesPrint ("%s            Prior      = Dirichlet\n", spacer);
23357                 else
23358                     MrBayesPrint ("%s            Prior      = Fixed(user-specified)\n", spacer);
23359                 }
23360             }
23361         else if (j == P_OMEGA)
23362             {
23363             if (!strcmp(mp->omegaVar,"Equal"))
23364                 {
23365                 if (!strcmp(mp->omegaPr,"Dirichlet"))
23366                     MrBayesPrint ("%s            Prior      = Dirichlet(%1.2lf,%1.2lf)\n", spacer, mp->omegaDir[0], mp->omegaDir[1]);
23367                 else
23368                     MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->omegaFix);
23369                 }
23370             else if (!strcmp(mp->omegaVar,"Ny98"))
23371                 {
23372                 if (!strcmp(mp->ny98omega1pr,"Beta"))
23373                     MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf) on omega(1)\n", spacer, mp->ny98omega1Beta[0], mp->ny98omega1Beta[1]);
23374                 else
23375                     MrBayesPrint ("%s            Prior      = Fixed(%1.2lf) on omega(1)\n", spacer, mp->ny98omega1Fixed);
23376                 MrBayesPrint ("%s                         Fixed(1.00) on omega(2)\n", spacer);
23377                 if (!strcmp(mp->ny98omega3pr,"Uniform"))
23378                     MrBayesPrint ("%s                         Uniform(%1.2lf,%1.2lf) on omega(3)\n", spacer, mp->ny98omega3Uni[0], mp->ny98omega3Uni[1]);
23379                 else if (!strcmp(mp->ny98omega3pr,"Exponential"))
23380                     MrBayesPrint ("%s                         Exponential(%1.2lf) on omega(3)\n", spacer, mp->ny98omega3Exp);
23381                 else
23382                     MrBayesPrint ("%s                         Fixed(%1.2lf) on omega(3)\n", spacer, mp->ny98omega3Fixed);
23383                 if (!strcmp(mp->codonCatFreqPr,"Dirichlet"))
23384                     MrBayesPrint ("%s                         Dirichlet(%1.2lf,%1.2lf,%1.2lf) on pi(-), pi(N), and pi(+)\n", spacer, mp->codonCatDir[0], mp->codonCatDir[1], mp->codonCatDir[2]);
23385                 else
23386                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf,%1.2lf) on pi(-), pi(N), and pi(+)\n", spacer, mp->codonCatFreqFix[0], mp->codonCatFreqFix[1], mp->codonCatFreqFix[2]);
23387                 }
23388             else if (!strcmp(mp->omegaVar,"M3"))
23389                 {
23390                 if (!strcmp(mp->m3omegapr,"Exponential"))
23391                     MrBayesPrint ("%s                         dN1, dN2, dN3, and dS are all exponential random variables\n", spacer);
23392                 else
23393                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf,%1.2lf) for the three selection categories\n", spacer, mp->m3omegaFixed[0], mp->m3omegaFixed[1], mp->m3omegaFixed[2]);
23394                 if (!strcmp(mp->codonCatFreqPr,"Dirichlet"))
23395                     MrBayesPrint ("%s                         Dirichlet(%1.2lf,%1.2lf,%1.2lf) on pi(1), pi(2), and pi(3)\n", spacer, mp->codonCatDir[0], mp->codonCatDir[1], mp->codonCatDir[2]);
23396                 else
23397                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf,%1.2lf) on pi(1), pi(2), and pi(3)\n", spacer, mp->codonCatFreqFix[0], mp->codonCatFreqFix[1], mp->codonCatFreqFix[2]);
23398                 }
23399             else if (!strcmp(mp->omegaVar,"M10"))
23400                 {
23401                 MrBayesPrint ("%s                         With probability pi(1), omega is drawn from a Beta(alpha1,beta1) \n", spacer);
23402                 MrBayesPrint ("%s                         distribution and with probability pi(2), omega is drawn from\n", spacer);
23403                 MrBayesPrint ("%s                         a Gamma(alpha2,beta2) distribution.\n", spacer);
23404                 if (!strcmp(mp->m10betapr,"Uniform"))
23405                     {
23406                     MrBayesPrint ("%s                         The parameters of the beta distribution each follow \n", spacer);
23407                     MrBayesPrint ("%s                         independent Uniform(%1.2lf,%1.2lf) priors\n", spacer, mp->m10betaUni[0], mp->m10betaUni[1]);
23408                     }
23409                 else if (!strcmp(mp->m10betapr,"Exponential"))
23410                     {
23411                     MrBayesPrint ("%s                         The parameters of the beta distribution each follow \n", spacer);
23412                     MrBayesPrint ("%s                         independent Exponential(%1.2lf) priors\n", spacer, mp->m10betaExp);
23413                     }
23414                 else
23415                     {
23416                     MrBayesPrint ("%s                         The parameters of the beta distribution are fixed to \n", spacer);
23417                     MrBayesPrint ("%s                         %1.2lf and %1.2lf\n", spacer, mp->m10betaFix[0], mp->m10betaFix[0]);
23418                     }
23419 
23420                 if (!strcmp(mp->m10gammapr,"Uniform"))
23421                     {
23422                     MrBayesPrint ("%s                         The parameters of the gamma distribution each follow  \n", spacer);
23423                     MrBayesPrint ("%s                         independent Uniform(%1.2lf,%1.2lf) priors\n", spacer, mp->m10gammaUni[0], mp->m10gammaUni[1]);
23424                     }
23425                 else if (!strcmp(mp->m10gammapr,"Exponential"))
23426                     {
23427                     MrBayesPrint ("%s                         The parameters of the gamma distribution each follow \n", spacer);
23428                     MrBayesPrint ("%s                         independent Exponential(%1.2lf) priors\n", spacer, mp->m10gammaExp);
23429                     }
23430                 else
23431                     {
23432                     MrBayesPrint ("%s                         The parameters of the gamma distribution are fixed to \n", spacer);
23433                     MrBayesPrint ("%s                         %1.2lf and %1.2lf\n", spacer, mp->m10gammaFix[0], mp->m10gammaFix[0]);
23434                     }
23435 
23436                 if (!strcmp(mp->codonCatFreqPr,"Dirichlet"))
23437                     MrBayesPrint ("%s                         Dirichlet(%1.2lf,%1.2lf) on pi(1) and pi(2)\n", spacer, mp->codonCatDir[0], mp->codonCatDir[1]);
23438                 else
23439                     MrBayesPrint ("%s                         Fixed(%1.2lf,%1.2lf) on pi(1) and pi(2)\n", spacer, mp->codonCatFreqFix[0], mp->codonCatFreqFix[1]);
23440                 }
23441             }
23442         else if (j == P_PI)
23443             {
23444             if (ms->dataType == STANDARD)
23445                 {
23446                 if (!strcmp(mp->symPiPr, "Uniform"))
23447                     MrBayesPrint ("%s            Prior      = Symmetric dirichlet with uniform(%1.2lf,%1.2lf) variance parameter\n", spacer, mp->symBetaUni[0], mp->symBetaUni[1]);
23448                 else if (!strcmp(mp->symPiPr, "Exponential"))
23449                     MrBayesPrint ("%s            Prior      = Symmetric dirichlet with exponential(%1.2lf) variance parameter\n", spacer, mp->symBetaExp);
23450                 else
23451                     { /* mp->symBetaFix == -1 */
23452                     if (AreDoublesEqual(mp->symBetaFix, -1.0, ETA)==YES)
23453                         MrBayesPrint ("%s            Prior      = Symmetric dirichlet with all parameters equal to infinity\n", spacer);
23454                     else
23455                         MrBayesPrint ("%s            Prior      = Symmetric dirichlet with all parameters equal to %1.2lf\n", spacer, mp->symBetaFix);
23456                     }
23457                 }
23458             else if (ms->dataType == PROTEIN)
23459                 {
23460                 if (!strcmp(mp->aaModelPr, "Fixed") && (!strcmp(mp->aaModel, "Equalin") || !strcmp(mp->aaModel, "Gtr")))
23461                     {
23462                     if (!strcmp(mp->stateFreqPr,"Dirichlet"))
23463                         {
23464                         MrBayesPrint ("%s            Prior      = Dirichlet\n", spacer);
23465                         }
23466                     else if (!strcmp(mp->stateFreqPr,"Fixed") && !strcmp(mp->stateFreqsFixType,"Equal"))
23467                         {
23468                         MrBayesPrint ("%s            Prior      = Fixed (equal frequencies)\n", spacer);
23469                         }
23470                     else if (!strcmp(mp->stateFreqPr,"Fixed") && !strcmp(mp->stateFreqsFixType,"User"))
23471                         {
23472                         MrBayesPrint ("%s            Prior      = Fixed (user-specified)\n", spacer);
23473                         }
23474                     else if (!strcmp(mp->stateFreqPr,"Fixed") && !strcmp(mp->stateFreqsFixType,"Empirical"))
23475                         {
23476                         MrBayesPrint ("%s            Prior      = Fixed (empirical frequencies)\n", spacer);
23477                         }
23478                     }
23479                 else if (!strcmp(mp->aaModelPr, "Fixed") && !strcmp(mp->aaModel, "Poisson"))
23480                     {
23481                     MrBayesPrint ("%s            Prior      = Fixed (equal frequencies)\n", spacer);
23482                     }
23483                 else if (!strcmp(mp->aaModelPr, "Fixed") && strcmp(mp->aaModel, "Equalin") && strcmp(mp->aaModel, "Poisson"))
23484                     {
23485                     MrBayesPrint ("%s            Prior      = Fixed (%s frequencies)\n", spacer, mp->aaModel);
23486                     }
23487                 else
23488                     {
23489                     MrBayesPrint ("%s            Prior      = Fixed (from mixture of models)\n", spacer);
23490                     }
23491                 }
23492             else
23493                 {
23494                 if (!strcmp(mp->stateFreqPr,"Dirichlet"))
23495                     MrBayesPrint ("%s            Prior      = Dirichlet\n", spacer);
23496                 else
23497                     MrBayesPrint ("%s            Prior      = Fixed\n", spacer);
23498                 }
23499             }
23500         else if (j == P_MIXTURE_RATES)
23501             {
23502             MrBayesPrint ("%s            Prior      = Ordered flat Dirichlet distribution\n", spacer);
23503             }
23504         else if (j == P_SHAPE)
23505             {
23506             if (!strcmp(mp->shapePr,"Uniform"))
23507                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->shapeUni[0], mp->shapeUni[1]);
23508             else if (!strcmp(mp->shapePr,"Exponential"))
23509                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->shapeExp);
23510             else
23511                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->shapeFix);
23512             }
23513         else if (j == P_PINVAR)
23514             {
23515             if (!strcmp(mp->pInvarPr,"Uniform"))
23516                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->pInvarUni[0], mp->pInvarUni[1]);
23517             else
23518                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->pInvarFix);
23519             }
23520         else if (j == P_CORREL)
23521             {
23522             if (!strcmp(mp->adGammaCorPr,"Uniform"))
23523                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->corrUni[0], mp->corrUni[1]);
23524             else
23525                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->corrFix);
23526             }
23527         else if (j == P_SWITCH)
23528             {
23529             if (!strcmp(mp->covSwitchPr,"Uniform"))
23530                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->covswitchUni[0], mp->covswitchUni[1]);
23531             else if (!strcmp(mp->covSwitchPr,"Exponential"))
23532                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->covswitchExp);
23533             else
23534                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf,%1.2lf)\n", spacer, mp->covswitchFix[0], mp->covswitchFix[1]);
23535             }
23536         else if (j == P_RATEMULT)
23537             {
23538             if (!strcmp(mp->ratePr,"Fixed"))
23539                 MrBayesPrint ("%s            Prior      = Fixed(1.0)\n", spacer);
23540             else
23541                 {
23542                 MrBayesPrint ("%s            Prior      = Dirichlet(", spacer);
23543                 for (d=n=0; d<numCurrentDivisions; d++)
23544                     {
23545                     if (activeParams[j][d] == i+1)
23546                         n++;
23547                     }
23548                 for (d=m=0; d<numCurrentDivisions; d++)
23549                     {
23550                     if (activeParams[j][d] == i+1)
23551                         {
23552                         m++;
23553                         if (m < n)
23554                             MrBayesPrint ("%1.2lf,", modelParams[d].ratePrDir);
23555                         else
23556                             MrBayesPrint ("%1.2lf)\n", modelParams[d].ratePrDir);
23557                         }
23558                     }
23559                 }
23560             }
23561         else if (j == P_GENETREERATE)
23562             {
23563             if (!strcmp(mp->generatePr,"Fixed"))
23564                 MrBayesPrint ("%s            Prior      = Fixed(1.0)\n", spacer);
23565             else
23566                 {
23567                 MrBayesPrint ("%s            Prior      = Dirichlet(", spacer);
23568                 printedCol = (int)(strlen(spacer)) + 25 + 10;
23569                 for (n=0; n<numTrees-1; n++)
23570                     {
23571                     if (printedCol + 5 > screenWidth)
23572                         {
23573                         MrBayesPrint("\n%s                                   ", spacer);
23574                         printedCol = (int)(strlen(spacer)) + 25 + 10;
23575                         }
23576                     if (n == numTrees-2)
23577                         MrBayesPrint ("1.00)\n");
23578                     else
23579                         MrBayesPrint ("1.00,");
23580                     printedCol += 5;
23581                     }
23582                 }
23583             }
23584         else if (j == P_TOPOLOGY)
23585             {
23586             if (!strcmp(mp->topologyPr,"Uniform"))
23587                 MrBayesPrint ("%s            Prior      = All topologies equally probable a priori\n", spacer);
23588             else if (!strcmp(mp->topologyPr,"Speciestree"))
23589                 MrBayesPrint ("%s            Prior      = Topology constrained to fold within species tree\n", spacer);
23590             else if (!strcmp(mp->topologyPr,"Constraints"))
23591                 MrBayesPrint ("%s            Prior      = Prior on topology obeys the following constraints:\n", spacer);
23592             else
23593                 MrBayesPrint ("%s            Prior      = Prior is fixed to the topology of user tree '%s'\n", spacer,
23594                                                     userTree[mp->topologyFix]->name);
23595             if (!strcmp(mp->topologyPr,"Constraints"))
23596                 {
23597                 for (a=0; a<numDefinedConstraints; ++a)
23598                     {
23599                     if (mp->activeConstraints[a] == NO)
23600                         continue;
23601                     if (definedConstraintsType[a] == HARD)
23602                         MrBayesPrint ("%s                         -- Hard constraint \"%s\"\n", spacer, constraintNames[a]);
23603                     else if (definedConstraintsType[a] == PARTIAL)
23604                         MrBayesPrint ("%s                         -- Partial constraint \"%s\"\n", spacer, constraintNames[a]);
23605                     else /* if (true) */
23606                         MrBayesPrint ("%s                         -- Negative constraint \"%s\"\n", spacer, constraintNames[a]);
23607                     }
23608                 }
23609             }
23610         else if (j == P_BRLENS)
23611             {
23612             if (!strcmp(mp->parsModel, "Yes"))
23613                 MrBayesPrint ("%s            Prior      = Reconstructed using parsimony\n", spacer);
23614             else
23615                 {
23616                 if (!strcmp(mp->brlensPr,"Unconstrained"))
23617                     {
23618                     MrBayesPrint ("%s            Prior      = Unconstrained:%s", spacer, mp->unconstrainedPr);
23619                     if (!strcmp(mp->unconstrainedPr, "Uniform"))
23620                         MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->brlensUni[0], mp->brlensUni[1]);
23621                     else if (!strcmp(mp->unconstrainedPr, "Exponential"))
23622                         MrBayesPrint ("(%1.1lf)\n", mp->brlensExp);
23623                     else if (!strcmp(mp->unconstrainedPr, "twoExp"))
23624                         MrBayesPrint ("(%1.1lf,%1.1lf)\n", mp->brlens2Exp[0], mp->brlens2Exp[1]);
23625                     else
23626                         MrBayesPrint ("(%1.1lf,%1.4lf,%1.1lf,%1.1lf)\n", mp->brlensDir[0], mp->brlensDir[1], mp->brlensDir[2], mp->brlensDir[3]);
23627                     }
23628                 else if (!strcmp(mp->brlensPr, "Clock"))
23629                     {
23630                     MrBayesPrint ("%s            Prior      = Clock:%s\n", spacer, mp->clockPr);
23631                     if ((!strcmp(mp->clockPr, "Uniform") ||
23632                          !strcmp(mp->clockPr, "Birthdeath") ||
23633                          !strcmp(mp->clockPr, "Fossilization")) && !strcmp(mp->nodeAgePr, "Unconstrained"))
23634                         {
23635                         MrBayesPrint ("%s                         Tree age has a %s distribution\n", spacer, mp->treeAgePr.name);
23636                         }
23637                     if (!strcmp(mp->nodeAgePr,"Calibrated"))
23638                         {
23639                         b = 0;
23640                         for (a=0; a<numTaxa; a++)
23641                             {
23642                             if (taxaInfo[a].isDeleted == NO && tipCalibration[a].prior != unconstrained)
23643                                 b++;
23644                             }
23645                         for (a=0; a<numDefinedConstraints; a++)
23646                             {
23647                             if (mp->activeConstraints[a] == YES && nodeCalibration[a].prior != unconstrained)
23648                                 b++;
23649                             }
23650                         if (b > 1)
23651                             MrBayesPrint ("%s                         Node depths are constrained by the following age constraints:\n", spacer);
23652                         else
23653                             MrBayesPrint ("%s                         Node depths are calibrated by the following age constraint:\n", spacer);
23654                         for (a=0; a<numTaxa; a++)
23655                             {
23656                             if (taxaInfo[a].isDeleted == NO && tipCalibration[a].prior != unconstrained)
23657                                 {
23658                                 MrBayesPrint ("%s                         -- The age of terminal \"%s\" is %s\n", spacer, taxaNames[a],
23659                                     tipCalibration[a].name);
23660                                 }
23661                             }
23662                         for (a=b=0; a<numDefinedConstraints; a++)
23663                             {
23664                             if (mp->activeConstraints[a] == YES && nodeCalibration[a].prior != unconstrained)
23665                                 {
23666                                 MrBayesPrint ("%s                         -- The age of node '%s' is %s\n", spacer,
23667                                     constraintNames[a], nodeCalibration[a].name);
23668                                 for (k=0; k<numTaxa; k++)
23669                                     if (taxaInfo[k].isDeleted == NO && IsBitSet(k,definedConstraint[a]) == NO)
23670                                         break;
23671                                 if (k == numTaxa)
23672                                     b = 1;          /* root is calibrated */
23673                                 }
23674                             }
23675                         if (b == 0) /* we need to use default calibration for root for uniform and birthdeath */
23676                             {
23677                             if (!strcmp(mp->clockPr,"Uniform") || !strcmp(mp->clockPr, "Birthdeath") || !strcmp(mp->clockPr,"Fossilization"))
23678                                 {
23679                                 MrBayesPrint ("%s                         -- Tree age has a %s distribution\n", spacer, mp->treeAgePr.name);
23680                                 }
23681                             }
23682                         }
23683                     else
23684                         MrBayesPrint ("%s                         Node ages are not constrained\n", spacer);
23685                     }
23686                 else
23687                     {
23688                     assert (!strcmp(mp->brlensPr, "Fixed"));
23689                     MrBayesPrint ("%s            Prior      = Fixed, branch lengths are fixed to the ones of the user tree '%s'\n", spacer,
23690                                                     userTree[mp->topologyFix]->name);
23691                     }
23692                 }
23693             }
23694         else if (j == P_SPECRATE)
23695             {
23696             if (!strcmp(mp->speciationPr,"Uniform"))
23697                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->speciationUni[0], mp->speciationUni[1]);
23698             else if (!strcmp(mp->speciationPr,"Exponential"))
23699                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->speciationExp);
23700             else
23701                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->speciationFix);
23702             }
23703         else if (j == P_EXTRATE)
23704             {
23705             if (!strcmp(mp->extinctionPr,"Beta"))
23706                 MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf)\n", spacer, mp->extinctionBeta[0], mp->extinctionBeta[1]);
23707             else
23708                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->extinctionFix);
23709             }
23710         else if (j == P_FOSLRATE)
23711             {
23712             if (!strcmp(mp->fossilizationPr,"Beta"))
23713                 MrBayesPrint ("%s            Prior      = Beta(%1.2lf,%1.2lf)\n", spacer, mp->fossilizationBeta[0], mp->fossilizationBeta[1]);
23714             else
23715                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->fossilizationFix);
23716             }
23717         else if (j == P_POPSIZE)
23718             {
23719             if (!strcmp(mp->popSizePr,"Uniform"))
23720                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->popSizeUni[0], mp->popSizeUni[1]);
23721             else if (!strcmp(mp->popSizePr,"Lognormal"))
23722                 MrBayesPrint ("%s            Prior      = Lognormal(%1.2lf,%1.2lf)\n", spacer, mp->popSizeLognormal[0], mp->popSizeLognormal[1]);
23723             else if (!strcmp(mp->popSizePr,"Normal"))
23724                 MrBayesPrint ("%s            Prior      = Truncated Normal(%1.2lf,%1.2lf)\n", spacer, mp->popSizeNormal[0], mp->popSizeNormal[1]);
23725             else if (!strcmp(mp->popSizePr,"Gamma"))
23726                 MrBayesPrint ("%s            Prior      = Gamma(%1.2lf,%1.2lf)\n", spacer, mp->popSizeGamma[0], mp->popSizeGamma[1]);
23727             else
23728                 MrBayesPrint ("%s            Prior      = Fixed(%1.5lf)\n", spacer, mp->popSizeFix);
23729             if (!strcmp(mp->topologyPr,"Speciestree"))
23730                 {
23731                 if (!strcmp(mp->popVarPr,"Equal") || !strcmp(mp->popSizePr,"Fixed"))
23732                     MrBayesPrint ("%s                         Population size the same across species tree\n", spacer);
23733                 else
23734                     MrBayesPrint ("%s                         Population size varies across branches in species tree\n", spacer);
23735                 }
23736             }
23737         else if (j == P_GROWTH)
23738             {
23739             if (!strcmp(mp->growthPr,"Uniform"))
23740                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->growthUni[0], mp->growthUni[1]);
23741             else if (!strcmp(mp->growthPr,"Exponential"))
23742                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->growthExp);
23743             else if (!strcmp(mp->growthPr,"Normal"))
23744                 MrBayesPrint ("%s            Prior      = Normal(%1.2lf,%1.2lf)\n", spacer, mp->growthNorm[0], mp->growthNorm[1]);
23745             else
23746                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->growthFix);
23747             }
23748         else if (j == P_AAMODEL)
23749             {
23750             if (!strcmp(mp->aaModelPr,"Mixed"))
23751                 {
23752                 /* check to see if you have a uniform prior */
23753                 isSame = YES;
23754                 for (a=0; a<9; a++)
23755                     for (b=a+1; b<10; b++)
23756                         /* mp->aaModelPrProbs[a] != mp->aaModelPrProbs[b] */
23757                         if (AreDoublesEqual(mp->aaModelPrProbs[a], mp->aaModelPrProbs[b], ETA)==FALSE)
23758                             isSame = NO;
23759                 MrBayesPrint ("%s            Prior      = Poisson, Jones, Dayhoff, Mtrev, Mtmam, Wag, Rtrev,\n", spacer);
23760                 if (isSame == YES)
23761                     MrBayesPrint ("%s                         Cprev, Vt, and Blosum models have equal prior probability\n", spacer);
23762                 else
23763                     MrBayesPrint ("%s                         Cprev, Vt, and Blosum models have unequal prior probability\n", spacer);
23764                 }
23765             else
23766                 MrBayesPrint ("%s            Prior      = Fixed(%s)\n", spacer, mp->aaModel);
23767             }
23768         else if (j == P_BRCORR)
23769             {
23770             if (!strcmp(mp->brownCorPr,"Uniform"))
23771                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->brownCorrUni[0], mp->brownCorrUni[1]);
23772             else
23773                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->brownCorrFix);
23774             }
23775         else if (j == P_BRSIGMA)
23776             {
23777             if (!strcmp(mp->brownScalesPr,"Uniform"))
23778                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->brownScalesUni[0], mp->brownScalesUni[1]);
23779             else if (!strcmp(mp->brownScalesPr,"Gammamean"))
23780                 MrBayesPrint ("%s            Prior      = Gamma Mean=<char. ave.> Var=%1.2lf\n", spacer, mp->brownScalesGammaMean);
23781             else if (!strcmp(mp->brownScalesPr,"Gamma"))
23782                 MrBayesPrint ("%s            Prior      = Gamma Mean=%lf Var=%1.2lf\n", spacer, mp->brownScalesGamma[0], mp->brownScalesGamma[1]);
23783             else
23784                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->brownScalesFix);
23785             }
23786         else if (j == P_CPPRATE)
23787             {
23788             if (!strcmp(mp->cppRatePr,"Exponential"))
23789                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->cppRateExp);
23790             else
23791                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->cppRateFix);
23792             }
23793         else if (j == P_CPPMULTDEV)
23794             {
23795             if (!strcmp(mp->cppMultDevPr,"Fixed"))
23796                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->cppMultDevFix);
23797             }
23798         else if (j == P_CPPEVENTS)
23799             {
23800             MrBayesPrint ("%s            Prior      = Poisson (%s) [Events]\n", spacer, modelSettings[p->relParts[0]].cppRate->name);
23801             MrBayesPrint ("%s                         Lognormal (0.00,%1.2lf) [Rate multipliers]\n", spacer, mp->cppMultDevFix);
23802             }
23803         else if (j == P_TK02VAR)
23804             {
23805             if (!strcmp(mp->tk02varPr,"Uniform"))
23806                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->tk02varUni[0], mp->tk02varUni[1]);
23807             else if (!strcmp(mp->tk02varPr,"Exponential"))
23808                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->tk02varExp);
23809             else
23810                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->tk02varFix);
23811             }
23812         else if (j == P_TK02BRANCHRATES)
23813             {
23814             MrBayesPrint ("%s            Prior      = LogNormal (expectation = r_0, variance = %s * v) \n", spacer, modelSettings[p->relParts[0]].tk02var->name);
23815             MrBayesPrint ("%s                            [r_0 is beginning rate of branch, v is branch length]\n", spacer);
23816             }
23817         else if (j == P_IGRVAR)
23818             {
23819             if (!strcmp(mp->igrvarPr,"Uniform"))
23820                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->igrvarUni[0], mp->igrvarUni[1]);
23821             else if (!strcmp(mp->igrvarPr,"Exponential"))
23822                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->igrvarExp);
23823             else
23824                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->igrvarFix);
23825             }
23826         else if (j == P_IGRBRANCHRATES)
23827             {
23828             MrBayesPrint ("%s            Prior      = Gamma (expectation = v, variance = %s * v) \n", spacer, modelSettings[p->relParts[0]].igrvar->name);
23829             MrBayesPrint ("%s                            [where v is branch length]\n", spacer);
23830             }
23831         else if (j == P_MIXEDVAR)
23832             {
23833             if (!strcmp(mp->mixedvarPr,"Uniform"))
23834                 MrBayesPrint ("%s            Prior      = Uniform(%1.2lf,%1.2lf)\n", spacer, mp->mixedvarUni[0], mp->mixedvarUni[1]);
23835             else if (!strcmp(mp->mixedvarPr,"Exponential"))
23836                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->mixedvarExp);
23837             else
23838                 MrBayesPrint ("%s            Prior      = Fixed(%1.2lf)\n", spacer, mp->mixedvarFix);
23839             }
23840         else if (j == P_MIXEDBRCHRATES)
23841             {
23842             MrBayesPrint ("%s            Prior      = Mixed TK02 and IGR (variance = %s * v)\n", spacer, modelSettings[p->relParts[0]].mixedvar->name);
23843             MrBayesPrint ("%s                            [where v is branch length]\n", spacer);
23844             MrBayesPrint ("%s                         Uniform prior on relaxed clock models [Pr(TK02)=Pr(IGR)=1/2]\n", spacer);
23845             }
23846         else if (j == P_CLOCKRATE)
23847             {
23848             if (!strcmp(mp->clockRatePr,"Normal"))
23849                 MrBayesPrint ("%s            Prior      = Normal(%1.6lf,%1.6lf)\n", spacer, mp->clockRateNormal[0], mp->clockRateNormal[1]);
23850             else if (!strcmp(mp->clockRatePr,"Lognormal"))
23851                 MrBayesPrint ("%s            Prior      = Lognormal(%1.2lf,%1.2lf)\n", spacer, mp->clockRateLognormal[0], mp->clockRateLognormal[1]);
23852             else if (!strcmp(mp->clockRatePr,"Gamma"))
23853                 MrBayesPrint ("%s            Prior      = Gamma(%1.2lf,%1.2lf)\n", spacer, mp->clockRateGamma[0], mp->clockRateGamma[1]);
23854             else if (!strcmp(mp->clockRatePr,"Exponential"))
23855                 MrBayesPrint ("%s            Prior      = Exponential(%1.2lf)\n", spacer, mp->clockRateExp);
23856             else
23857                 MrBayesPrint ("%s            Prior      = Fixed(%1.6lf)\n", spacer, mp->clockRateFix);
23858             if (!strcmp(mp->clockVarPr,"Strict"))
23859                 MrBayesPrint ("%s                         The clock rate is constant (strict clock)\n", spacer);
23860             else if (!strcmp(mp->clockVarPr,"Cpp"))
23861                 MrBayesPrint ("%s                         The clock rate varies according to a CPP model\n", spacer);
23862             else if (!strcmp(mp->clockVarPr,"TK02"))
23863                 MrBayesPrint ("%s                         The clock rate varies according to a Brownian motion model\n", spacer);
23864             else if (!strcmp(mp->clockVarPr,"Igr"))
23865                 MrBayesPrint ("%s                         The clock rate varies according to an independent gamma (white noise) model\n", spacer);
23866             else /* if (!strcmp(mp->clockVarPr,"Mixed")) */
23867                 MrBayesPrint ("%s                         The clock rate varies according to mixed TK02 and IGR models\n", spacer);
23868             }
23869         else if (j == P_SPECIESTREE)
23870             {
23871             MrBayesPrint ("%s            Prior      = Uniform on topologies and branch lengths\n", spacer);
23872             }
23873 
23874         /* print partitions */
23875         if (numCurrentDivisions > 1)
23876             {
23877             if (p->nRelParts == 1)
23878                 MrBayesPrint ("%s            Partition  = %d\n", spacer, p->relParts[0]+1);
23879             else if (p->nRelParts == 2)
23880                 {
23881                 MrBayesPrint ("%s            Partitions = %d and %d\n", spacer, p->relParts[0]+1, p->relParts[1]+1);
23882                 }
23883             else if (p->nRelParts == numCurrentDivisions)
23884                 {
23885                 MrBayesPrint ("%s            Partitions = All\n", spacer);
23886                 }
23887             else /* if (p->nRelParts > 2) */
23888                 {
23889                 MrBayesPrint ("%s            Partitions = ", spacer);
23890                 for (j=0; j<p->nRelParts; j++)
23891                     {
23892                     if (j == p->nRelParts - 2)
23893                         MrBayesPrint ("%d, and ", p->relParts[j]+1);
23894                     else if (j == p->nRelParts - 1)
23895                         MrBayesPrint ("%d\n", p->relParts[j]+1);
23896                     else
23897                         MrBayesPrint ("%d, ", p->relParts[j]+1);
23898                     }
23899                 }
23900             }
23901 
23902         /* show subparams */
23903         if (p->nSubParams > 0)
23904             {
23905             if (p->nSubParams == 1)
23906                 MrBayesPrint ("%s            Subparam.  = %s\n", spacer, p->subParams[0]->name);
23907             else
23908                 {
23909                 printedCol = 0;
23910                 for (k=0; k<p->nSubParams; k++)
23911                     {
23912                     if (k == 0)
23913                         {
23914                         MrBayesPrint ("%s            Subparams  = %s", spacer, p->subParams[k]->name);
23915                         printedCol = (int)(strlen(spacer)) + 25 + (int)(strlen(p->subParams[k]->name));
23916                         }
23917                     else if (k == p->nSubParams - 1)
23918                         {
23919                         if (printedCol + 5 > screenWidth)
23920                             MrBayesPrint ("\n%s                         and ", spacer);
23921                         else if (printedCol + (int)(strlen(p->subParams[k]->name)) + 5 > screenWidth)
23922                             MrBayesPrint (" and \n%s                         ", spacer);
23923                         else
23924                             MrBayesPrint (" and ");
23925                         MrBayesPrint ("%s\n", p->subParams[k]->name);
23926                         }
23927                     else
23928                         {
23929                         if (printedCol + (int)(strlen(p->subParams[k]->name)) + 2 > screenWidth)
23930                             {
23931                             MrBayesPrint (", \n%s                         ", spacer);
23932                             printedCol = (int)(strlen(spacer)) + 25;
23933                             }
23934                         else
23935                             {
23936                             MrBayesPrint(", ");
23937                             printedCol += 2;
23938                             }
23939                         MrBayesPrint ("%s", p->subParams[k]->name);
23940                         printedCol += (int)strlen(p->subParams[k]->name);
23941                         }
23942                     }
23943                 }
23944             }
23945 
23946         /* show used moves */
23947         if (showMoves == YES && (p->printParam == YES || p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS))
23948             {
23949             /* check if runs are same */
23950             areRunsSame = YES;
23951             for (run=1; run<chainParams.numRuns; run++)
23952                 {
23953                 for (chain=0; chain<chainParams.numChains; chain++)
23954                     {
23955                     for (k=0; k<numApplicableMoves; k++)
23956                         {
23957                         mv = moves[k];
23958                         if (mv->parm != p)
23959                             continue;
23960                         chainIndex = run*chainParams.numChains + chain;
23961                         refIndex = chain;
23962                         if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[refIndex], 0.000001) == NO)
23963                             areRunsSame = NO;
23964                         }
23965                     }
23966                 }
23967 
23968             for (run=0; run<chainParams.numRuns; run++)
23969                 {
23970                 if (run > 0 && areRunsSame == YES)
23971                     continue;
23972 
23973                 /* check if chains are same */
23974                 areChainsSame = YES;
23975                 for (chain=1; chain<chainParams.numChains; chain++)
23976                     {
23977                     for (k=0; k<numApplicableMoves; k++)
23978                         {
23979                         mv = moves[k];
23980                         if (mv->parm != p)
23981                             continue;
23982                         chainIndex = run*chainParams.numChains + chain;
23983                         refIndex = run*chainParams.numChains;
23984                         if (AreDoublesEqual (mv->relProposalProb[chainIndex], mv->relProposalProb[refIndex], 0.000001) == NO)
23985                             areChainsSame = NO;
23986                         }
23987                     }
23988 
23989                 /* now print moves */
23990                 for (chain=0; chain<chainParams.numChains; chain++)
23991                     {
23992                     if (chain > 0 && areChainsSame == YES)
23993                         continue;
23994                     if (run==0 && chain==0)
23995                         MrBayesPrint ("%s            Moves      = ", spacer);
23996                     else
23997                         MrBayesPrint ("%s                         ", spacer);
23998                     numPrinted = 0;
23999                     printedCol = (int)(strlen(spacer)) + 25;
24000                     for (k=0; k<numApplicableMoves; k++)
24001                         {
24002                         mv = moves[k];
24003                         if (mv->parm != p)
24004                             continue;
24005                         chainIndex = run*chainParams.numChains + chain;
24006                         if (mv->relProposalProb[chainIndex] <= 0.000001)
24007                             continue;
24008                         if (numPrinted == 0)
24009                             {
24010                             MrBayesPrint ("%s <prob %.1f>", mv->name, mv->relProposalProb[chainIndex]);
24011                             printedCol += 9 + (int)strlen(mv->name) + (int)(log10(mv->relProposalProb[chainIndex])) + 3;
24012                             }
24013                         else
24014                             {
24015                             if (printedCol + 11 + (int)(strlen(mv->name)) + (int)(log10(mv->relProposalProb[chainIndex])) + 3 > screenWidth)
24016                                 {
24017                                 MrBayesPrint(", \n%s                         ", spacer);
24018                                 printedCol = 25 + (int)(strlen(spacer));
24019                                 }
24020                             else
24021                                 {
24022                                 MrBayesPrint(", ");
24023                                 printedCol += 2;
24024                                 }
24025                             MrBayesPrint ("%s <prob %.1f>", mv->name, mv->relProposalProb[chainIndex]);
24026                             printedCol += (9 + (int)(strlen(mv->name)) + (int)(log10(mv->relProposalProb[chainIndex])) + 3);
24027                             }
24028                         numPrinted++;
24029                         }
24030 
24031                     if (numPrinted == 0 && p->paramType == P_BRLENS)
24032                         {
24033                         for (k=0; k<numParams; k++)
24034                             if (params[k].tree == p->tree)
24035                                 break;
24036                         MrBayesPrint ("For moves, see param. '%s'", params[k].name);
24037                         }
24038                     else if (numPrinted == 0)
24039                         MrBayesPrint ("WARNING! No moves -- param. fixed to startvals");
24040 
24041                     if (areRunsSame == YES && areChainsSame == YES)
24042                         MrBayesPrint ("\n");
24043                     else if (areRunsSame == YES && areChainsSame == NO)
24044                         MrBayesPrint (" [chain %d]\n", chain+1);
24045                     else if (areRunsSame == NO && areChainsSame == YES)
24046                         MrBayesPrint (" [run %d]\n", run+1);
24047                     else /* if (areRunsSame == NO && areChainsSame == NO) */
24048                             MrBayesPrint (" [run %d, chain %d]\n", run+1, chain+1);
24049                     }
24050                 }
24051             }
24052 
24053         /* show available moves */
24054         if (showAllAvailable == YES && (p->printParam == YES || p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS))
24055             {
24056             /* loop over moves */
24057             numPrinted = 0;
24058             printedCol = 0;
24059             for (k=0; k<numApplicableMoves; k++)
24060                 {
24061                 mv = moves[k];
24062                 if (mv->parm != p)
24063                     continue;
24064                 numMovedChains = 0;
24065                 for (run=0; run<chainParams.numRuns; run++)
24066                     {
24067                     for (chain=0; chain<chainParams.numChains; chain++)
24068                         {
24069                         chainIndex = run*chainParams.numChains + chain;
24070                         if (mv->relProposalProb[chainIndex] > 0.000001)
24071                             numMovedChains++;
24072                         }
24073                     }
24074                 if (numMovedChains == 0)
24075                     {
24076                     if (numPrinted == 0)
24077                         {
24078                         MrBayesPrint ("%s            Not used   = ", spacer);
24079                         printedCol = (int)(strlen(spacer)) + 25;
24080                         }
24081                     else if (printedCol + 2 + (int)(strlen(mv->moveType->shortName)) > screenWidth)
24082                         {
24083                         MrBayesPrint (", \n%s                         ", spacer);
24084                         printedCol = (int)(strlen(spacer)) + 25;
24085                         }
24086                     else
24087                         {
24088                         MrBayesPrint (", ");
24089                         printedCol += 2;
24090                         }
24091                     MrBayesPrint("%s", mv->moveType->shortName);
24092                     printedCol += (int)strlen(mv->moveType->shortName);
24093                     numPrinted++;
24094                     }
24095                 }
24096                 if (numPrinted > 0)
24097                     MrBayesPrint ("\n");
24098             }
24099 
24100         /* show startvals */
24101         if (showStartVals == YES && (p->printParam == YES || p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS || p->paramType == P_SPECIESTREE || p->paramType == P_POPSIZE))
24102             {
24103             if (p->paramType == P_TOPOLOGY || p->paramType == P_BRLENS || p->paramType == P_SPECIESTREE)
24104                 {
24105                 /* check if they are the same */
24106                 areRunsSame = YES;
24107                 if (p->paramType == P_TOPOLOGY)
24108                     {
24109                     for (run=1; run<chainParams.numRuns; run++)
24110                         {
24111                         for (chain=0; chain<chainParams.numChains; chain++)
24112                             {
24113                             if (AreTopologiesSame (GetTree (p, run*chainParams.numChains + chain, 0), GetTree (p, chain, 0)) == NO)
24114                                 {
24115                                 areRunsSame = NO;
24116                                 break;
24117                                 }
24118                             }
24119                         }
24120                     }
24121                 else if (p->paramType == P_BRLENS)
24122                     {
24123                     for (run=1; run<chainParams.numRuns; run++)
24124                         {
24125                         for (chain=0; chain<chainParams.numChains; chain++)
24126                             {
24127                             if (AreTreesSame (GetTree (p, run*chainParams.numChains + chain, 0), GetTree (p, chain, 0)) == NO)
24128                                 {
24129                                 areRunsSame = NO;
24130                                 break;
24131                                 }
24132                             }
24133                         }
24134                     }
24135                 else if (p->paramType == P_SPECIESTREE)
24136                     {
24137                     for (run=1; run<chainParams.numRuns; run++)
24138                         {
24139                         for (chain=0; chain<chainParams.numChains; chain++)
24140                             {
24141                             if (AreTreesSame (GetTree (p, run*chainParams.numChains + chain, 0), GetTree (p, chain, 0)) == NO)
24142                                 {
24143                                 areRunsSame = NO;
24144                                 break;
24145                                 }
24146                             }
24147                         }
24148                     }
24149 
24150                 /* print trees */
24151                 for (run=0; run<chainParams.numRuns; run++)
24152                     {
24153                     if (run > 0 && areRunsSame == YES)
24154                         break;
24155                     for (chain=0; chain<chainParams.numChains; chain++)
24156                         {
24157                         if (run == 0 && chain == 0)
24158                             MrBayesPrint ("%s            Startvals  = tree '%s'", spacer, GetTree (p, run*chainParams.numChains+chain, 0)->name);
24159                         else
24160                             MrBayesPrint ("%s                         tree '%s'", spacer, GetTree (p, run*chainParams.numChains+chain, 0)->name);
24161                         if (chainParams.numChains > 1 && areRunsSame == YES)
24162                             MrBayesPrint ("  [chain %d]", chain+1);
24163                         else if (chainParams.numChains == 1 && areRunsSame == NO)
24164                             MrBayesPrint ("  [run %d]", run+1);
24165                         else if (areRunsSame == NO)
24166                             MrBayesPrint ("  [run %d, chain %d]", run+1, chain+1);
24167                         MrBayesPrint ("\n");
24168                         }
24169                     }
24170                 }   /* end topology and brlens parameters */
24171 
24172             else if (p->paramType == P_OMEGA && p->paramId != OMEGA_DIR && p->paramId != OMEGA_FIX &&
24173                      p->paramId != OMEGA_FFF && p->paramId != OMEGA_FF && p->paramId != OMEGA_10FFF)
24174                 {
24175                 /* we need to print values and subvalues for the category frequencies in a NY98-like model. */
24176                 areRunsSame = YES;
24177                 for (run=1; run<chainParams.numRuns; run++)
24178                     {
24179                     for (chain=0; chain<chainParams.numChains; chain++)
24180                         {
24181                         value = GetParamVals (p, run*chainParams.numRuns+chain, 0);
24182                         refValue = GetParamVals (p, chain, 0);
24183                         nValues = p->nValues;
24184                         for (k=0; k<nValues; k++)
24185                             {
24186                             if (AreDoublesEqual (value[k], refValue[k], 0.000001) == NO)
24187                                 {
24188                                 areRunsSame = NO;
24189                                 break;
24190                                 }
24191                             }
24192                         value = GetParamSubVals (p, run*chainParams.numRuns+chain, 0);
24193                         refValue = GetParamSubVals (p, chain, 0);
24194                         if (!strcmp(modelParams[p->relParts[0]].omegaVar, "M10"))
24195                             {
24196                             value += (mp->numM10BetaCats + mp->numM10GammaCats);
24197                             refValue += (mp->numM10BetaCats + mp->numM10GammaCats);
24198                             for (k=0; k<4; k++)
24199                                 {
24200                                 if (AreDoublesEqual (value[k + 4], refValue[k + 4], 0.000001) == NO)
24201                                     {
24202                                     areRunsSame = NO;
24203                                     break;
24204                                     }
24205                                 }
24206                             for (k=0; k<2; k++)
24207                                 {
24208                                 if (AreDoublesEqual (value[k], refValue[k], 0.000001) == NO)
24209                                     {
24210                                     areRunsSame = NO;
24211                                     break;
24212                                     }
24213                                 }
24214                             }
24215                         else
24216                             {
24217                             for (k=0; k<3; k++)
24218                                 {
24219                                 if (AreDoublesEqual (value[k], refValue[k], 0.000001) == NO)
24220                                     {
24221                                     areRunsSame = NO;
24222                                     break;
24223                                     }
24224                                 }
24225                             }
24226                         if (areRunsSame == NO)
24227                             break;
24228                         }
24229                     if (areRunsSame == NO)
24230                         break;
24231                     }
24232 
24233                 /* now print values */
24234                 for (run=0; run<chainParams.numRuns; run++)
24235                     {
24236                     for (chain=0; chain<chainParams.numChains; chain++)
24237                         {
24238                         value = GetParamVals (p, run*chainParams.numRuns+chain, 0);
24239                         subValue = GetParamSubVals (p, run*chainParams.numRuns+chain, 0);
24240                         nValues = p->nValues;
24241                         if (run == 0 && chain == 0)
24242                             MrBayesPrint ("%s            Startvals  = (%1.3lf", spacer, value[0]);
24243                         else
24244                             MrBayesPrint ("%s                         (%1.3lf", spacer, value[0]);
24245                         for (k=1; k<nValues; k++)
24246                             {
24247                             MrBayesPrint (",%1.3lf", value[k]);
24248                             }
24249 
24250                         if (!strcmp(modelParams[p->relParts[0]].omegaVar, "M10"))
24251                             {
24252                             for (k=0; k<4; k++)
24253                                 {
24254                                 MrBayesPrint (",%1.3lf", subValue[k + mp->numM10BetaCats+mp->numM10GammaCats+4]);
24255                                 }
24256                             for (k=0; k<2; k++)
24257                                 {
24258                                 MrBayesPrint (",%1.3lf", subValue[k + mp->numM10BetaCats+mp->numM10GammaCats]);
24259                                 }
24260                             }
24261                         else
24262                             {
24263                             for (k=0; k<3; k++)
24264                                 {
24265                                 MrBayesPrint (",%1.3lf", subValue[k]);
24266                                 }
24267                             }
24268                         MrBayesPrint (")");
24269                         if (chainParams.numChains > 1 && areRunsSame == YES)
24270                             MrBayesPrint ("  [chain %d]\n", chain+1);
24271                         else if (chainParams.numChains == 1 && areRunsSame == NO)
24272                             MrBayesPrint ("  [run %d]\n", run+1);
24273                         else if (areRunsSame == NO)
24274                             MrBayesPrint ("  [run %d, chain %d]\n", run+1, chain+1);
24275                         }
24276                     }
24277                 }
24278             else
24279                 {
24280                 /* run of the mill parameter */
24281                 if (p->paramType == P_CLOCKRATE)
24282                     {
24283                      for (j=0; j<numGlobalChains; j++)
24284                         {
24285                         if (UpdateClockRate(-1.0, j) == ERROR)
24286                             {
24287                             MrBayesPrint ("%s            Warning: There is no appropriate clock rate that would satisfy all calibrated trees for run:%d chain%d. Some of calibration, trees or clockprior needs to be changed. ", spacer, j/chainParams.numChains, j%chainParams.numChains);
24288                             }
24289                         }
24290                     }
24291                 areRunsSame = YES;
24292                 for (run=1; run<chainParams.numRuns; run++)
24293                     {
24294                     for (chain=0; chain<chainParams.numChains; chain++)
24295                         {
24296                         if ((p->paramType == P_PI && modelParams[p->relParts[0]].dataType != STANDARD))
24297                             {
24298                             nValues = p->nSubValues;
24299                             value = GetParamSubVals (p, run*chainParams.numChains+chain, 0);
24300                             refValue = GetParamSubVals (p, chain, 0);
24301                             }
24302                         else
24303                             {
24304                             nValues = p->nValues;
24305                             value = GetParamVals (p, run*chainParams.numChains+chain, 0);
24306                             refValue = GetParamVals (p, chain, 0);
24307                             }
24308                         for (k=0; k<nValues; k++)
24309                             {
24310                             if (AreDoublesEqual(value[k], refValue[k], 0.000001) == NO)
24311                                 {
24312                                 areRunsSame = NO;
24313                                 break;
24314                                 }
24315                             }
24316                         if (areRunsSame == NO)
24317                             break;
24318                         }
24319                     if (areRunsSame == NO)
24320                         break;
24321                     }
24322 
24323                 /* print values */
24324                 for (run=0; run<chainParams.numRuns; run++)
24325                     {
24326                     if (run > 0 && areRunsSame == YES)
24327                         break;
24328                     areChainsSame = YES;
24329                     for (chain=1; chain<chainParams.numChains; chain++)
24330                         {
24331                         if ((p->paramType == P_PI && modelParams[p->relParts[0]].dataType != STANDARD))
24332                             {
24333                             nValues = p->nSubValues;
24334                             value = GetParamSubVals (p, run*chainParams.numChains+chain, 0);
24335                             refValue = GetParamSubVals (p, run*chainParams.numChains, 0);
24336                             }
24337                         else
24338                             {
24339                             nValues = p->nValues;
24340                             value = GetParamVals (p, run*chainParams.numChains+chain, 0);
24341                             refValue = GetParamVals (p, run*chainParams.numChains, 0);
24342                             }
24343                         for (k=0; k<nValues; k++)
24344                             {
24345                             if (AreDoublesEqual(value[k], refValue[k], 0.000001) == NO)
24346                                 {
24347                                 areChainsSame = NO;
24348                                 break;
24349                                 }
24350                             }
24351                         }
24352                     for (chain=0; chain<chainParams.numChains; chain++)
24353                         {
24354                         if (areChainsSame == YES && chain > 0)
24355                             continue;
24356 
24357                         if ((p->paramType == P_PI && modelParams[p->relParts[0]].dataType != STANDARD))
24358                             {
24359                             nValues = p->nSubValues;
24360                             value = GetParamSubVals (p, run*chainParams.numChains+chain, 0);
24361                             }
24362                         else
24363                             {
24364                             nValues = p->nValues;
24365                             value = GetParamVals (p, run*chainParams.numChains+chain, 0);
24366                             }
24367 
24368                         if (run == 0 && chain == 0)
24369                             MrBayesPrint ("%s            Startvals  = (%1.3lf", spacer, value[0]);
24370                         else
24371                             MrBayesPrint ("%s                         (%1.3lf", spacer, value[0]);
24372 
24373                         for (k=1; k<nValues; k++)
24374                             {
24375                             if (k%10==0)
24376                                 MrBayesPrint (",\n%s                          %1.3lf", spacer, value[k]);
24377                             else
24378                                 MrBayesPrint (",%1.3lf", value[k]);
24379                             }
24380                         MrBayesPrint (")");
24381 
24382                         if (areChainsSame == YES && areRunsSame == NO)
24383                             MrBayesPrint ("  [run %d]", run+1);
24384                         else if (areChainsSame == NO && areRunsSame == YES)
24385                             MrBayesPrint ("  [chain %d]", chain+1);
24386                         else if (areChainsSame == NO && areRunsSame == NO)
24387                             MrBayesPrint ("  [run %d, chain %d]", run+1, chain+1);
24388                         MrBayesPrint ("\n");
24389                         }
24390                     }
24391                 }
24392             }   /* end print start values */
24393 
24394         MrBayesPrint ("\n");
24395         }   /* next parameter */
24396 
24397     return (NO_ERROR);
24398 }
24399 
24400 
Unlink(void)24401 int Unlink (void)
24402 {
24403     return (NO_ERROR);
24404 }
24405 
24406 
24407 /*-------------------------------------------------
24408 |
24409 |   UpdateClockRate:    Update clockRate of the given chain. Above all it will enforce fixed clockrate prior if it is set.
24410 |                       Error will be returned if fixed clockrate prior may not be respected.
24411 |   @param clockRate    is the new clockRate to setup. Clock rate value could be set as positive, 0.0 or negative value.
24412 |                       The function does the fallowing depending on one of this three values:
24413 |                        positive    - check that this 'positive' value is suitable rate. At the end re-enforce (update) the 'positive' value as clock rate on all trees.
24414 |                        0.0         - check if current rate is suitable, if not update it with minimal suitable value. At the end re-enforce (update) the resulting clock rate on all trees.
24415 |                        negative    - check if current rate is suitable, if not update it with minimal suitable value. At the end re-enforce (update) the resulting clock rate ONLY if clock rate was changed
24416 |   @return             ERROR if clockRate can not be set up, NO_ERROR otherwise.
24417 |
24418 --------------------------------------------------*/
UpdateClockRate(MrBFlt clockRate,int chain)24419 int UpdateClockRate (MrBFlt clockRate, int chain)
24420 {
24421     int         i, updateTrees;
24422     MrBFlt      *clockRatep;
24423     Tree        *t, *t_calibrated=NULL;
24424     MrBFlt      mintmp,maxtmp,minClockRate,maxClockRate;
24425 
24426     clockRatep=NULL;
24427     minClockRate = 0.0;
24428     maxClockRate = MRBFLT_MAX;
24429 
24430     for (i=0; i<numTrees; i++)
24431         {
24432         t = GetTreeFromIndex(i, chain, 0);
24433         if (t->isCalibrated == NO)
24434             continue;
24435 
24436         if (clockRatep == NULL)
24437             {
24438             clockRatep = GetParamVals(modelSettings[t->relParts[0]].clockRate, chain, 0);
24439             t_calibrated = t;
24440             assert (clockRatep);
24441             }
24442 
24443         findAllowedClockrate (t, &mintmp, &maxtmp);
24444 
24445         if (minClockRate < mintmp)
24446             minClockRate = mintmp;
24447 
24448         if (maxClockRate > maxtmp)
24449             maxClockRate = maxtmp;
24450 
24451         }
24452     /* clock rate is the same for all trees of a given chain */
24453     if (clockRatep != NULL)
24454         {
24455         if (minClockRate > maxClockRate)
24456             {
24457             MrBayesPrint ("%s   ERROR: Calibrated trees require compatible clockrates but they are incompatible for run %d, chain %d.\n",
24458                           spacer, chain/chainParams.numChains + 1, chain%chainParams.numChains + 1);
24459             *clockRatep=0;
24460             return (ERROR);
24461             }
24462 
24463         if (!strcmp(modelParams[t_calibrated->relParts[0]].clockRatePr, "Fixed"))
24464             {
24465             if (clockRate < 0.0 && AreDoublesEqual (*clockRatep, modelParams[t_calibrated->relParts[0]].clockRateFix, 0.0001) == YES)
24466                 {
24467                 updateTrees = NO;
24468                 }
24469             else
24470                 {
24471                 updateTrees = YES;
24472                 }
24473             *clockRatep = modelParams[t_calibrated->relParts[0]].clockRateFix;
24474             if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24475                 (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24476                 {
24477                 MrBayesPrint ("%s   ERROR: Calibrated trees require clockrate in range from %f to %f, while clockrate prior is fixed to %f for run %d chain %d.\n",
24478                               spacer, minClockRate, maxClockRate, *clockRatep, chain/chainParams.numChains + 1, chain%chainParams.numChains + 1);
24479                 *clockRatep=0;
24480                 return (ERROR);
24481                 }
24482             if (clockRate > 0.0)
24483                 {
24484                 if (AreDoublesEqual (*clockRatep, clockRate, 0.0001) == NO)
24485                     {
24486                     MrBayesPrint ("%s   ERROR: Requested clockrate:%f does not match fixed clockrate prior:%f.\n", spacer, clockRate, *clockRatep);
24487                     *clockRatep=0;
24488                     return (ERROR);
24489                     }
24490                 }
24491             }
24492         else {
24493             /* clock prior is not fixed */
24494             updateTrees = YES;
24495             if (clockRate > 0.0)
24496                 {
24497                 *clockRatep = clockRate;
24498                 if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24499                     (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24500                     {
24501                     MrBayesPrint ("%s   ERROR: Calibrated trees require clockrate in range from %f to %f, while requested clockrate is %f for run %d chain %d.\n",
24502                                   spacer, minClockRate, maxClockRate, clockRate, chain/chainParams.numChains + 1, chain%chainParams.numChains + 1);
24503                     *clockRatep=0;
24504                     return (ERROR);
24505                     }
24506                 }
24507             else if (clockRate == 0.0)
24508                 {
24509                 if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24510                     (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24511                     {
24512                     *clockRatep = minClockRate;
24513                     }
24514                 }
24515             else // if (clockRate < 0.0)
24516                 {
24517                 if ((*clockRatep < minClockRate && AreDoublesEqual (*clockRatep, minClockRate, 0.0001) == NO) ||
24518                     (*clockRatep > maxClockRate && AreDoublesEqual (*clockRatep, maxClockRate, 0.0001) == NO))
24519                     {
24520                     *clockRatep = minClockRate;
24521                     }
24522                 else
24523                     {
24524                     updateTrees = NO;
24525                     }
24526                 }
24527             }
24528 
24529 
24530         if (updateTrees == YES)
24531             {
24532             for (i=0; i<numTrees; i++)
24533                 {
24534                 t = GetTreeFromIndex(i, chain, 0);
24535                 if (t->isCalibrated == NO)
24536                     continue;
24537                 UpdateTreeWithClockrate (t,*clockRatep);
24538                 }
24539             }
24540         }
24541 
24542     return (NO_ERROR);
24543 }
24544 
24545 
24546 /*----------------------------------------------
24547 |
24548 |   UpdateCppEvolLength: Recursive function to
24549 |      update evolLength of one node for Cpp
24550 |      relaxed clock model
24551 |
24552 -----------------------------------------------*/
UpdateCppEvolLength(int * nEvents,MrBFlt ** pos,MrBFlt ** rateMult,MrBFlt * evolLength,TreeNode * p,MrBFlt baseRate)24553 int UpdateCppEvolLength (int *nEvents, MrBFlt **pos, MrBFlt **rateMult, MrBFlt *evolLength, TreeNode *p, MrBFlt baseRate)
24554 {
24555     int     i;
24556     MrBFlt  endRate;
24557 
24558     if (p != NULL)
24559         {
24560 #   ifdef DEBUG_CPP
24561         if (baseRate < POS_MIN || baseRate > POS_INFINITY)
24562             {
24563             printf ("baseRate out of bounds (%.15e for node %d\n", baseRate, p->index);
24564             return (ERROR);
24565             }
24566 #   endif
24567         p->upDateTi = YES;
24568         p->upDateCl = YES;
24569         if (nEvents[p->index] == 0)
24570             {
24571             evolLength[p->index] = p->length * baseRate;
24572             }
24573         else
24574             {
24575             /* note that event positions are from the top of the branch (more recent)
24576                to the bottom of the branch (older) */
24577             /* The algorithm below successively multiplies in the more basal rate multipliers,
24578                starting from the top of the branch. The length of the branch is first assumed
24579                to be 1.0; at the end we multiply the result with the true length of the branch. */
24580             evolLength[p->index] = pos[p->index][0] * rateMult[p->index][0];
24581             for (i=1; i<nEvents[p->index]; i++)
24582                 {
24583                 evolLength[p->index] += (pos[p->index][i] - pos[p->index][i-1]);
24584                 evolLength[p->index] *= rateMult[p->index][i];
24585                 }
24586             evolLength[p->index] += (1.0 - pos[p->index][nEvents[p->index]-1]);
24587             evolLength[p->index] *= baseRate;
24588             evolLength[p->index] *= p->length;
24589             }
24590 
24591         /* calculate end rate; we can do this in any order */
24592         endRate = baseRate;
24593         for (i=0; i<nEvents[p->index]; i++)
24594             endRate *= rateMult[p->index][i];
24595 
24596 #   ifdef DEBUG_CPP
24597         if (endRate < POS_MIN || endRate > POS_INFINITY)
24598             {
24599             printf ("endRate out of bounds (%.15e for node %d)\n", endRate, p->index);
24600             return (ERROR);
24601             }
24602         if (p->anc != NULL && p->anc->anc != NULL && (evolLength[p->index] < POS_MIN || evolLength[p->index] > POS_INFINITY))
24603             {
24604             printf ("Effective branch length out of bounds (%.15e for node %d)\n", evolLength[p->index], p->index);
24605             return (ERROR);
24606             }
24607 #   endif
24608         /* call left and right descendants */
24609         if (UpdateCppEvolLength (nEvents, pos, rateMult, evolLength, p->left, endRate)==ERROR)
24610             return (ERROR);
24611         if (UpdateCppEvolLength (nEvents, pos, rateMult, evolLength, p->right, endRate)==ERROR)
24612             return (ERROR);
24613         }
24614 
24615     return (NO_ERROR);
24616 }
24617 
24618 
24619 /*-------------------------------------------------
24620  |
24621  |  UpdateCppEvolLengths: Recalculate effective
24622  |      evolutionary lengths and set update flags
24623  |      for Cpp relaxed clock model
24624  |
24625  --------------------------------------------------*/
UpdateCppEvolLengths(Param * param,TreeNode * p,int chain)24626 int UpdateCppEvolLengths (Param *param, TreeNode *p, int chain)
24627 {
24628     int         i, *nEvents;
24629     TreeNode    *q;
24630     MrBFlt      baseRate = 1.0, **pos, **rateMult, *evolLength;
24631 
24632     i = 2*chain + state[chain];
24633     nEvents = param->nEvents[i];
24634     pos = param->position[i];
24635     rateMult = param->rateMult[i];
24636     evolLength = GetParamSubVals (param, chain, state[chain]);
24637 
24638     q = p->anc;
24639     while (q->anc != NULL)
24640         {
24641         for (i=0; i<nEvents[q->index]; i++)
24642             baseRate *= rateMult[q->index][i];
24643         q = q->anc;
24644         }
24645 
24646     if (UpdateCppEvolLength (nEvents, pos, rateMult, evolLength, p, baseRate)==ERROR)
24647         return (ERROR);
24648 
24649     return(NO_ERROR);
24650 }
24651 
24652 
24653 /* UpdateTK02EvolLengths: update branch lengths for tk02 model */
UpdateTK02EvolLengths(Param * param,Tree * t,int chain)24654 int UpdateTK02EvolLengths (Param *param, Tree *t, int chain)
24655 {
24656     int         i;
24657     MrBFlt      *tk02Rate, *brlens;
24658     TreeNode    *p;
24659 
24660     tk02Rate = GetParamVals (param, chain, state[chain]);
24661     brlens = GetParamSubVals (param, chain, state[chain]);
24662     for (i=0; i<t->nNodes-2; i++)
24663         {
24664         p = t->allDownPass[i];
24665         brlens[p->index] = p->length * (tk02Rate[p->index] + tk02Rate[p->anc->index]) / 2.0;
24666         }
24667 
24668     return (NO_ERROR);
24669 }
24670 
24671 
24672 /* UpdateIgrBranchLengths: update branch lengths for igr model */
UpdateIgrBrachLengths(Param * param,Tree * t,int chain)24673 int UpdateIgrBrachLengths (Param *param, Tree *t, int chain)
24674 {
24675     int         i;
24676     MrBFlt      *igrRate, *brlens;
24677     TreeNode    *p;
24678 
24679     igrRate = GetParamVals (param, chain, state[chain]);
24680     brlens = GetParamSubVals (param, chain, state[chain]);
24681     for (i=0; i<t->nNodes-2; i++)
24682         {
24683         p = t->allDownPass[i];
24684         brlens[p->index] = p->length * igrRate[p->index];
24685         }
24686 
24687     return (NO_ERROR);
24688 }
24689 
24690